From: Othmar Gsenger Date: Tue, 13 Dec 2011 19:14:19 +0000 (+0000) Subject: first version with sending X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=02293cb00639b97ca422619ee15f5981a5b3ffd0;p=svn42.git first version with sending --- diff --git a/rf433rcv/pc/decode.pl b/rf433rcv/pc/decode.pl index fc7f92e..685a283 100755 --- a/rf433rcv/pc/decode.pl +++ b/rf433rcv/pc/decode.pl @@ -55,7 +55,7 @@ if (my $delemiter = $ARGV[0]) # print "$seq\n"; my $bitcount=0; my @binarydata; - for my $bits (split /,/,$seq) + for my $bits (reverse split /,/,$seq) { $binarydata[int($bitcount/8)]<<=1; $binarydata[int($bitcount/8)]|=$bits; @@ -64,5 +64,9 @@ if (my $delemiter = $ARGV[0]) $binarydata[int($bitcount/8)]<<= 7 - ($bitcount % 8); my @chars = map { chr($_) } @binarydata; print STDERR join '',@chars; +# print STDERR "\ns\x04"; # send 4 times +# print STDERR chr(8-($bitcount % 8)) if $bitcount % 8; + print "$bitcount total, offset ".($bitcount % 8)." bits\n"; + print ($bitcount/8 ," bytes (must be <= 63)\n"); } diff --git a/rf433rcv/pc/rawhid_test.c b/rf433rcv/pc/rawhid_test.c index 1b1b2c3..3bccde4 100644 --- a/rf433rcv/pc/rawhid_test.c +++ b/rf433rcv/pc/rawhid_test.c @@ -15,7 +15,7 @@ static char get_keystroke(void); -int main() +int main (int argc, char *argv[]) { int i, r, num; char c, buf[64]; @@ -31,38 +31,51 @@ int main() } } // printf("found rawhid device\n"); - - while (1) { - // check if any Raw HID packet has arrived - num = rawhid_recv(0, buf, 64, 220); - if (num < 0) { - printf("\nerror reading, device went offline\n"); - rawhid_close(0); - return 0; - } - if (num == 64) { - // printf("\nrecv %d bytes:\n", num); - for (i=0; i<64*8; i++) { - if (buf[i/8] & 0x80) - { - printf("1"); - } else { - printf("0"); + if (argc>1) + { + FILE * f = fopen (argv[1], "r"); + if (!f) + return -3; + buf[0]='f'; + size_t len= fread(buf+1, 63, 1, f); + rawhid_send(0, buf, 1+len, 100); + buf[0]='s'; + buf[1]=4; + rawhid_send(0, buf, 2, 100); + return 0; + } else { + while (1) { + // check if any Raw HID packet has arrived + num = rawhid_recv(0, buf, 64, 220); + if (num < 0) { + printf("\nerror reading, device went offline\n"); + rawhid_close(0); + return 0; + } + if (num == 64) { + // printf("\nrecv %d bytes:\n", num); + for (i=0; i<64*8; i++) { + if (buf[i/8] & 0x80) + { + printf("1"); + } else { + printf("0"); + } + printf(","); + buf[i/8]<<=1; } - printf(","); - buf[i/8]<<=1; + } + // check if any input on stdin + while ((c = get_keystroke()) >= 32) { + printf("\ngot key '%c', sending...\n", c); + buf[0] = c; + for (i=1; i<64; i++) { + buf[i] = 0; } - } - // check if any input on stdin - while ((c = get_keystroke()) >= 32) { - printf("\ngot key '%c', sending...\n", c); - buf[0] = c; - for (i=1; i<64; i++) { - buf[i] = 0; - } - rawhid_send(0, buf, 64, 100); - } - } + rawhid_send(0, buf, 64, 100); + } + } + } } #if defined(OS_LINUX) || defined(OS_MACOSX) diff --git a/rf433rcv/teensy/Makefile b/rf433rcv/teensy/Makefile index 8bd5973..cf36fbd 100644 --- a/rf433rcv/teensy/Makefile +++ b/rf433rcv/teensy/Makefile @@ -444,6 +444,7 @@ gccversion : # Program the device. program: $(TARGET).hex $(TARGET).eep + echo -n r | ../pc/rawhid_test ~/teensy_loader_cli/teensy_loader_cli -mmcu=atmega32u4 -w $(TARGET).hex diff --git a/rf433rcv/teensy/example.c b/rf433rcv/teensy/example.c index 282e0bc..ebf77e2 100644 --- a/rf433rcv/teensy/example.c +++ b/rf433rcv/teensy/example.c @@ -41,6 +41,43 @@ uint8_t write_buffer[2][64]; // buffer for writing usb signals uint8_t rf_send_buffer[RF_SEND_BUFFER_LEN_MAX]; // buffer for sending rf433 signals uint8_t rf_send_buffer_len=0; + +void reset() +{ + cli(); + // disable watchdog, if enabled + // disable all peripherals + UDCON = 1; + USBCON = (1<0) { - if (read_buffer[0]=='b') //begin capture + if (read_buffer[0]=='r') //reset + reset(); + else if (read_buffer[0]=='b') //begin capture capture=1; else if (read_buffer[0]=='e') //end capture capture=0; @@ -120,16 +159,17 @@ ISR(TIMER0_COMPA_vect) rf_send--; } else if (rf_send_reload_count) { rf_send=rf_send_reload; - } else if (capture) { - write_buffer[active_buffer][output_count/8]<<=1; - write_buffer[active_buffer][output_count++/8]|=PINB&1; - if (output_count>=64*8) - { - output_count=0; - active_buffer=active_buffer?0:1; - send_buffer=1; + } else { + PORTF&=~1; + if (capture) { + write_buffer[active_buffer][output_count/8]<<=1; + write_buffer[active_buffer][output_count++/8]|=PINB&1; + if (output_count>=64*8) + { + output_count=0; + active_buffer=active_buffer?0:1; + send_buffer=1; + } } } } - -