datenformat vereinheitlicht
[svn42.git] / rf433rcv / pc / rawhid_test.c
index 3bccde4..2e0ac11 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),1000);
+}
 
 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,29 @@ int main (int argc, char *argv[])
     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);
+    printf("Clearing Buffer\n");  
+    sendstr("c"); // clear the buffer  
+    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 %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\x20"); // send 32 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) {
@@ -61,13 +82,13 @@ int main (int argc, char *argv[])
             } else {
               printf("0");
             }
-            printf(",");
+            // printf(",");
             buf[i/8]<<=1;
           }
       }
       // check if any input on stdin
       while ((c = get_keystroke()) >= 32) {
-        printf("\ngot key '%c', sending...\n", c);
+        fprintf(stderr,"\ngot key '%c', sending...\n", c);
         buf[0] = c;
         for (i=1; i<64; i++) {
           buf[i] = 0;