]> mj.ucw.cz Git - home-hw.git/blobdiff - ssr/host/test.c
SSR: USB communitation including test client
[home-hw.git] / ssr / host / test.c
index 2d94a98ec8c9e31cba8341c7a8149a7b8fcf5415..402db87d37b4a07f1f1dbe107251a1a4ef5ec5ae 100644 (file)
@@ -27,7 +27,7 @@ static libusb_device *find_device(void)
       libusb_device *dev = devlist[i];
       if (!libusb_get_device_descriptor(dev, &desc))
        {
-         if (desc.idVendor == 0x4242 && desc.idProduct == 0x0001)
+         if (desc.idVendor == 0x4242 && desc.idProduct == 0x0002)
            {
              printf("Found device at usb%d.%d\n", libusb_get_bus_number(dev), libusb_get_device_address(dev));
              // FIXME: Free device list
@@ -65,18 +65,15 @@ int main(void)
       exit(1);
     }
 
+  uint tst = 0;
+
   for (;;)
     {
-      time_t t = time(NULL);
-      struct tm *tm = localtime(&t);
+      byte req[8];
+      put_u32_be(req, 1);
+      put_u32_be(req+4, (1 << tst));
+      tst = (tst+1) % 4;
 
-      unsigned char req[8] = {
-       tm->tm_hour / 10,
-       tm->tm_hour % 10,
-       (tm->tm_sec % 2 ? 10 : 0xff),
-       tm->tm_min / 10,
-       tm->tm_min % 10,
-      };
       int transferred;
       if (err = libusb_bulk_transfer(devh, 0x01, req, 8, &transferred, 2000))
        die("Transfer failed: error %d\n", err);
@@ -87,13 +84,15 @@ int main(void)
       if (err = libusb_bulk_transfer(devh, 0x82, resp, 64, &received, 2000))
        die("Receive failed: error %d\n", err);
       // printf("Received %d bytes\n", received);
-      if (received >= 12)
+
+      if (received >= 4)
        {
-         int t = get_u32_be(resp);
-         int p = get_u32_be(resp + 4);
-         uint cnt = get_u32_be(resp + 8);
-         msg(L_INFO, "Temperature %d ddegC, pressure %d Pa, cnt %u", t, p, cnt);
+         int status = get_u32_be(resp);
+         if (status)
+           msg(L_ERROR, "Received error status %08x", status);
        }
+      else
+       msg(L_ERROR, "Received short packet");
 
       sleep(1);
     }