X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=rf433rcv%2Fpc%2Frawhid_test.c;h=eaef389ff30aa771ea785395b334aa13431739c2;hb=f505a1c37ea1c76897991f9882de765e34f0cc98;hp=1b1b2c31fa9370e47dd39f2b3db27f40e87949e2;hpb=a9d16c55e719dc0e80ab2c0a8135549e1a46ca52;p=svn42.git diff --git a/rf433rcv/pc/rawhid_test.c b/rf433rcv/pc/rawhid_test.c index 1b1b2c3..eaef389 100644 --- a/rf433rcv/pc/rawhid_test.c +++ b/rf433rcv/pc/rawhid_test.c @@ -1,6 +1,7 @@ #include #include #include +#include #if defined(OS_LINUX) || defined(OS_MACOSX) #include @@ -14,12 +15,15 @@ static char get_keystroke(void); +void sendstr(char * tosend) +{ + rawhid_send(0, tosend, strlen(tosend),100); +} -int main() +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) { @@ -31,38 +35,58 @@ 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; + sendstr("c"); // clear the buffer + buf[0]='f'; + 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= 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)