neerly working version of rf433rcv
authorOthmar Gsenger <otti@realraum.at>
Tue, 13 Dec 2011 23:33:38 +0000 (23:33 +0000)
committerOthmar Gsenger <otti@realraum.at>
Tue, 13 Dec 2011 23:33:38 +0000 (23:33 +0000)
rf433rcv/pc/compress.c [new file with mode: 0644]
rf433rcv/pc/decode.pl
rf433rcv/pc/decode2.pl [new file with mode: 0755]
rf433rcv/pc/rawhid_test.c
rf433rcv/teensy/example.c

diff --git a/rf433rcv/pc/compress.c b/rf433rcv/pc/compress.c
new file mode 100644 (file)
index 0000000..1e211d5
--- /dev/null
@@ -0,0 +1,24 @@
+#include <unistd.h>
+
+
+void main()
+{
+  unsigned char c,out=0;
+  int count =0;
+  while (read(0,&c,1))
+  {
+    out<<=1;
+    if (c=='1')
+      out |=1;
+    count++;  
+    if (count ==8)
+    {
+      write(1,&out,1);
+      count=0;
+      out=0;
+    }
+  }
+  out<<=8-count;
+  out |= 0xff>>count;
+  write(1,&out,1);
+}
index 685a283..8a0a4d6 100755 (executable)
@@ -61,7 +61,7 @@ if (my $delemiter = $ARGV[0])
     $binarydata[int($bitcount/8)]|=$bits;
     $bitcount++;
   }
-  $binarydata[int($bitcount/8)]<<= 7 - ($bitcount % 8);
+  $binarydata[int($bitcount/8)]<<= 8 - ($bitcount % 8) if $bitcount % 8;
   my @chars = map { chr($_) } @binarydata; 
   print STDERR join '',@chars;
 #  print STDERR "\ns\x04"; # send 4 times
diff --git a/rf433rcv/pc/decode2.pl b/rf433rcv/pc/decode2.pl
new file mode 100755 (executable)
index 0000000..4d81139
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/perl
+use strict;
+print $ARGV[2]-$ARGV[1], "samples\n";
+my @data =  split /,/,<>;
+my @samples = $ARGV[0]..$ARGV[1];
+print join ',', @data[@samples];
+print "\n";
index 3bccde4..eaef389 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <string.h>
 
 #if defined(OS_LINUX) || defined(OS_MACOSX)
 #include <sys/ioctl.h>
 
 static char get_keystroke(void);
 
+void sendstr(char * tosend)
+{
+  rawhid_send(0, tosend, strlen(tosend),100);
+}
 
 int main (int argc, char *argv[])
 {
        int i, r, num;
        char c, buf[64];
-
        // C-based example is 16C0:0480:FFAB:0200
        r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
        if (r <= 0) {
@@ -36,12 +40,19 @@ int main (int argc, char *argv[])
     FILE * f = fopen (argv[1], "r");
     if (!f)
       return -3;
+    sendstr("c"); // clear the buffer  
     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);
+    size_t len= fread(buf+1, 1, 63, f);
+    for(i=len+1;i<64;i++)
+      buf[i]=0xff;
+    rawhid_send(0, buf, 64, 100); //fill the buffer
+    sendstr("s\x10"); // send 4 times
+    len = rawhid_recv(0, buf, 64, 255);
+    for(i=0;i<len;i++)
+    {
+      printf("%02x ",(unsigned char) buf[i]);
+    }  
+    printf("\n");
     return 0;
   } else {
     while (1) {
index ebf77e2..649f6de 100644 (file)
@@ -33,13 +33,13 @@ volatile uint16_t output_count=0;
 volatile uint8_t active_buffer=0;
 volatile uint16_t send_buffer=0;
 volatile uint8_t capture=0;
-volatile uint8_t rf_send=0; //count of bits in rf_send_buffer that should be sent
-volatile uint8_t rf_send_reload=0; //count of bits in rf_send_buffer that should be sent
+volatile uint16_t rf_send=0; //count of bits in rf_send_buffer that should be sent
+volatile uint16_t rf_send_reload=0; //count of bits in rf_send_buffer that should be sent
 volatile uint8_t rf_send_reload_count=0; // number of repetitions (times rf_send gets reloaded;
 uint8_t read_buffer[64]; // buffer for reading usb signals
 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;
+volatile uint16_t rf_send_buffer_len=0;
 
 
 void reset()
@@ -113,12 +113,12 @@ int main(void)
         capture=0;
       else if (read_buffer[0]=='f') //fill send buffer
       {
-        int8_t byte_rem = r-1;
-        while(byte_rem && rf_send_buffer_len<RF_SEND_BUFFER_LEN_MAX)
+        int8_t buffer_pos = 1;
+        while(buffer_pos < r && rf_send_buffer_len<RF_SEND_BUFFER_LEN_MAX)
         {
-          rf_send_buffer[rf_send_buffer_len]=read_buffer[r-byte_rem];
+          rf_send_buffer[rf_send_buffer_len]=read_buffer[buffer_pos];
           rf_send_buffer_len++;
-          byte_rem--;
+          buffer_pos++;
         }
       }
       else if (read_buffer[0]=='c') // clear send buffer
@@ -128,11 +128,16 @@ int main(void)
       else if (read_buffer[0]=='s') //send
       {
         capture=0;
-        if (r>2)
-          rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset
-        else
-          rf_send_reload=rf_send_buffer_len*8;
+        //if (r>2)
+        //  rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset
+        //else
+        usb_rawhid_send(rf_send_buffer, 145);
+        rf_send=0;
+        rf_send_reload=rf_send_buffer_len*8;
         rf_send_reload_count=read_buffer[1];  
+        //read_buffer[0]=rf_send_reload;
+        //read_buffer[1]=rf_send_reload>>8;
+        //read_buffer[2]=0;
       }
     }
     if (send_buffer)
@@ -149,18 +154,19 @@ ISR(TIMER0_COMPA_vect)
   PORTF^=2;
   if (rf_send)
   {
-    if (rf_send_buffer[rf_send/8] & 0x80)
+    if ( ( rf_send_buffer[rf_send/8] >> ( (rf_send%8)?8-(rf_send%8):0 ) ) & 1)
     {
-     PORTF|=1;
-    } else {
      PORTF&=~1;
+    } else {
+     PORTF|=1;
     }
-    rf_send_buffer[rf_send/8]<<=1;
+    //rf_send_buffer[rf_send/8]>>=1;
     rf_send--;
   } else if (rf_send_reload_count) {
     rf_send=rf_send_reload;
+    rf_send_reload_count--;
   } else {
-    PORTF&=~1; 
+    PORTF&=~1;
     if (capture) {
       write_buffer[active_buffer][output_count/8]<<=1;
       write_buffer[active_buffer][output_count++/8]|=PINB&1;