From 2b257333a9b98e9696c64fc4e02d14a5fb1f00e8 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Tue, 14 May 2013 22:31:52 +0200 Subject: [PATCH 1/1] parse fs20pcs-response --- fs20pcs.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/fs20pcs.c b/fs20pcs.c index 8bc28c7..2a4ec37 100644 --- 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 ret; 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; } - 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"); - return 1; + return ret; } int main(int argc, char **argv) -- 2.39.5