]> git.zerfleddert.de Git - fs20pcs/commitdiff
parse fs20pcs-response
authorMichael Gernoth <michael@gernoth.net>
Tue, 14 May 2013 20:31:52 +0000 (22:31 +0200)
committerMichael Gernoth <michael@gernoth.net>
Tue, 14 May 2013 20:31:52 +0000 (22:31 +0200)
fs20pcs.c

index 8bc28c7fc2d35e4b8684d991ea29907a7fbac651..2a4ec377fae0f3b7362d2c7692d4c54f87da8398 100644 (file)
--- a/fs20pcs.c
+++ b/fs20pcs.c
@@ -104,6 +104,7 @@ int fs20pcs_send(libusb_device_handle *devh, unsigned char* send_data)
        int err;
        int cnt;
        int i;
        int err;
        int cnt;
        int i;
+       int ret;
 
        err = libusb_interrupt_transfer(devh, 0x01, send_data, 11, &cnt, 5000);
        if (err) {
 
        err = libusb_interrupt_transfer(devh, 0x01, send_data, 11, &cnt, 5000);
        if (err) {
@@ -117,12 +118,50 @@ int fs20pcs_send(libusb_device_handle *devh, unsigned char* send_data)
                return 0;
        }
 
                return 0;
        }
 
-       for (i = 0; i < cnt; i++) {
-               printf("0x%02x ", recv_data[i]);
+       if ((recv_data[0] != 0x02) ||
+           (recv_data[1] != 0x03) ||
+           (recv_data[2] != 0xa0)) {
+           fprintf(stderr, "Unexpected response: ");
+           for (i = 0; i < cnt; i++) {
+                   fprintf(stderr, "0x%02x ", recv_data[i]);
+           }
+           fprintf(stderr, "\n");
+
+           return 0;
+       }
+
+       ret = 1;
+
+       switch(recv_data[3]) {
+               case 0x00:
+                       printf("Success");
+                       break;
+               case 0x01:
+                       printf("Firmware V%d.%d", ((recv_data[4] & 0xf0) >> 4) & 0x0f, recv_data[4] & 0x0f);
+                       break;
+               case 0x02:
+                       printf("Unknown command");
+                       ret = 0;
+                       break;
+               case 0x03:
+                       printf("Wrong length");
+                       ret = 0;
+                       break;
+               case 0x04:
+                       printf("Aborted sending long press");
+                       break;
+               case 0x05:
+                       printf("Nothing to stop");
+                       break;
+               default:
+                       printf("Unknown response: 0x%02x 0x%02x", recv_data[3], recv_data[4]);
+                       ret = 0;
+                       break;
        }
        }
+
        printf("\n");
 
        printf("\n");
 
-       return 1;
+       return ret;
 }
 
 int main(int argc, char **argv)
 }
 
 int main(int argc, char **argv)
Impressum, Datenschutz