]> mj.ucw.cz Git - home-hw.git/commitdiff
Clock host: Remove testing code
authorMartin Mares <mj@ucw.cz>
Sun, 14 May 2023 10:39:20 +0000 (12:39 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 14 May 2023 10:39:20 +0000 (12:39 +0200)
clock/host/Makefile
clock/host/test.c [deleted file]

index d99cfd4e9e2777cc26514a75ed7bda4393f52f06..18c9d412fc7015aee9cb1afe0da10501eafd7e8e 100644 (file)
@@ -4,9 +4,7 @@ UCWLF:=$(shell PKG_CONFIG_PATH=$(LIBUCW)/lib/pkgconfig pkg-config --libs libucw)
 CFLAGS=-std=gnu99 -O2 -Wall -Wextra -Wno-parentheses $(UCWCF)
 LDLIBS=-lusb-1.0 $(UCWLF)
 
-all: test burrow-clock
-
-test: test.c
+all: burrow-clock
 
 burrow-clock: burrow-clock.c
 burrow-clock: LDLIBS += -lmosquitto
@@ -15,4 +13,4 @@ install: all
        install burrow-clock /usr/local/sbin/
 
 clean:
-       rm -f burrow-clock test
+       rm -f burrow-clock
diff --git a/clock/host/test.c b/clock/host/test.c
deleted file mode 100644 (file)
index 30426fb..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-#include <ucw/lib.h>
-#include <ucw/unaligned.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <time.h>
-#include <libusb-1.0/libusb.h>
-
-struct libusb_context *usb_ctxt;
-struct libusb_device_handle *devh;
-
-static libusb_device *find_device(void)
-{
-  libusb_device **devlist;
-  ssize_t devn = libusb_get_device_list(usb_ctxt, &devlist);
-  if (devn < 0)
-    {
-      fprintf(stderr, "Cannot enumerate USB devices: error %d\n", (int) devn);
-      exit(1);
-    }
-
-  for (ssize_t i=0; i<devn; i++)
-    {
-      struct libusb_device_descriptor desc;
-      libusb_device *dev = devlist[i];
-      if (!libusb_get_device_descriptor(dev, &desc))
-       {
-         if (desc.idVendor == 0x4242 && desc.idProduct == 0x0001)
-           {
-             printf("Found device at usb%d.%d\n", libusb_get_bus_number(dev), libusb_get_device_address(dev));
-             // FIXME: Free device list
-             return dev;
-           }
-       }
-    }
-
-  libusb_free_device_list(devlist, 1);
-  fprintf(stderr, "Device not found\n");
-  exit(1);
-}
-
-int main(void)
-{
-  int err;
-  if (err = libusb_init(&usb_ctxt))
-    {
-      fprintf(stderr, "Cannot initialize libusb: error %d\n", err);
-      exit(1);
-    }
-  // libusb_set_debug(usb_ctxt, 3);
-
-  libusb_device *dev = find_device();
-
-  if (err = libusb_open(dev, &devh))
-    {
-      fprintf(stderr, "Cannot open device: error %d\n", err);
-      exit(1);
-    }
-  libusb_reset_device(devh);
-  if (err = libusb_claim_interface(devh, 0))
-    {
-      fprintf(stderr, "Cannot claim interface: error %d\n", err);
-      exit(1);
-    }
-
-  for (;;)
-    {
-      time_t t = time(NULL);
-      struct tm *tm = localtime(&t);
-
-      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", err);
-      // printf("Transferred %d bytes\n", transferred);
-
-      unsigned char resp[64];
-      int received;
-      if (err = libusb_bulk_transfer(devh, 0x82, resp, 64, &received, 2000))
-       die("Receive failed: error %d", err);
-      // printf("Received %d bytes\n", received);
-      if (received >= 12)
-       {
-         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);
-       }
-
-      sleep(1);
-    }
-
-  return 0;
-}