basically working version, but still problems
authorOthmar Gsenger <otti@realraum.at>
Wed, 14 Dec 2011 02:31:24 +0000 (02:31 +0000)
committerOthmar Gsenger <otti@realraum.at>
Wed, 14 Dec 2011 02:31:24 +0000 (02:31 +0000)
rf433rcv/pc/rawhid_test.c
rf433rcv/teensy/example.c

index 38f3401..8b1f757 100644 (file)
@@ -42,16 +42,22 @@ int main (int argc, char *argv[])
       return -3;
     printf("Clearing Buffer\n");  
     sendstr("c"); // clear the buffer  
-    buf[0]='f';  
-    while ( fread(buf+1, 1, 63, f) )
+    buf[0]='f'; 
+    size_t len;
+    while ( ( len = fread(buf+1, 1, 63, f)  ) )
     {
       
       rawhid_send(0, buf, 64, 1000); //fill the buffer
-      printf("Sending Buffer\n");
+      printf("Sending Buffer %d bytes\n",len);
+      for(i=0;i<len+1;i++)
+      {
+        printf("%02x ",(unsigned char) buf[i]);
+      }  
+      printf("\n");
     }
     printf("Executing Send command\n");
     sendstr("s\x10"); // send 4 times
-    size_t len = rawhid_recv(0, buf, 64, 255);
+    len = rawhid_recv(0, buf, 64, 255);
     for(i=0;i<len;i++)
     {
       printf("%02x ",(unsigned char) buf[i]);
index 063e26a..0e06e08 100644 (file)
 
 #define CPU_PRESCALE(n)        (CLKPR = 0x80, CLKPR = (n))
 #define RF_SEND_BUFFER_LEN_MAX 502
+
+union multiint {
+  uint16_t u16;
+  uint8_t u8[2];
+} __attribute__((packed));
+
 volatile uint16_t output_count=0;
 volatile uint8_t active_buffer=0;
 volatile uint16_t send_buffer=0;
 volatile uint8_t capture=0;
 volatile uint16_t rf_send_buf_pos=0; //count of bits in rf_send_buffer that should be sent
-volatile uint16_t rf_send_buf_len=0; //count of bits in rf_send_buffer that should be sent
+volatile union multiint rf_send_buf_len; //count of bits in rf_send_buffer that should be sent
 volatile uint8_t rf_send_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
@@ -115,7 +121,8 @@ int main(void)
       {
         int8_t buffer_pos = 1;
         if(!rf_send_buf_offset) {
-          rf_send_buf_len=read_buffer[2] | (read_buffer[1]<<8);   //rf_send_buf_offset*8;
+          rf_send_buf_len.u8[1]=read_buffer[1];
+          rf_send_buf_len.u8[0]=read_buffer[2];
           buffer_pos+=2;
         }
         while(buffer_pos < r && rf_send_buf_offset<RF_SEND_BUFFER_LEN_MAX)
@@ -131,6 +138,9 @@ int main(void)
       }
       else if (read_buffer[0]=='s') //send
       {
+        write_buffer[0][0]=rf_send_buf_len.u8[1];
+        write_buffer[0][1]=rf_send_buf_len.u8[0];
+        usb_rawhid_send(write_buffer, 23);
         capture=0;
         rf_send_buf_pos=0;
         rf_send_count=read_buffer[1]+1;  
@@ -148,7 +158,7 @@ int main(void)
 ISR(TIMER0_COMPA_vect)
 {
   PORTF^=2;
-  if (rf_send_count && rf_send_buf_pos<rf_send_buf_len)
+  if (rf_send_count && rf_send_buf_pos<rf_send_buf_len.u16)
   {
     if ( rf_send_buffer[rf_send_buf_pos/8] & (1<< (rf_send_buf_pos%8)))
     {