static struct libusb_device_handle *devh;
typedef unsigned char byte;
+typedef uint32_t u32;
typedef unsigned int uint;
+#include "../firmware/interface.h"
+
static void die(const char *msg, ...)
{
va_list args;
struct libusb_device_descriptor desc;
libusb_device *dev = devlist[i];
if (!libusb_get_device_descriptor(dev, &desc)) {
- if (desc.idVendor == 0x4242 && desc.idProduct == 0x0003) {
+ if (desc.idVendor == BSB_USB_VENDOR && desc.idProduct == BSB_USB_PRODUCT) {
fprintf(stderr, "Found device at usb%d.%d\n", libusb_get_bus_number(dev), libusb_get_device_address(dev));
if (err = libusb_open(dev, &devh)) {
}
static const char * const stat_names[] = {
- "rx_noise",
- "rx_errors",
- "rx_invalid",
- "rx_overruns",
- "rx_timeouts",
- "rx_bad_crc",
- "rx_ok",
+#define P(x) #x,
+ BSB_STATS
+#undef P
};
static void show_stats(byte *resp, uint len)
static void show_packet(byte *pkt, uint len)
{
+ if (!len) {
+ printf("ERROR: Received empty frame!\n");
+ return;
+ }
+
+ byte status = *pkt++;
+ len--;
+
+ if (!len) {
+ printf("Transmit status: %u\n", status);
+ return;
+ }
+
#if 1
- printf(":");
+ printf(": [%d]", status);
for (uint i=0; i<len; i++)
printf(" %02x", pkt[i]);
putchar('\n');
#endif
- printf("%02x -> %02x: ", pkt[1] ^ 0x80, pkt[2]);
+ printf("%02x -> %02x: ", pkt[BF_SRC] ^ 0x80, pkt[BF_DEST]);
+ if (status)
+ printf("[REPLY] ");
switch (pkt[4]) {
case 2:
printf("INFO %04x:%04x =", (pkt[5]<<8) | pkt[6], (pkt[7]<<8) | pkt[8]);
// libusb_set_debug(usb_ctxt, 3);
open_device();
+ time_t now = time(NULL);
time_t last_stats = 0;
+ time_t last_query = now;
int received;
byte resp[64];
}
}
- time_t now = time(NULL);
+ now = time(NULL);
if (last_stats + 60 < now) {
if ((received = libusb_control_transfer(devh, 0xc0, 0x00, 0, 0, resp, sizeof(resp), 1000)) < 0) {
usb_error("Receive failed: error %d", received);
last_stats = now;
}
+ if (last_query + 10 < now) {
+ byte pkt[] = { 0xdc, 0xc2, 0x00, 0x0b, 0x06, 0x3d, 0x2e, 0x11, 0x25, 0x00, 0x00 };
+ if (err = libusb_bulk_transfer(devh, 0x01, pkt, sizeof(pkt), &received, 2000)) {
+ printf("Send failed: error %d\n", err);
+ // usb_error("Receive failed: error %d", received);
+ // continue;
+ } else {
+ printf("Send OK: %d bytes\n", received);
+ }
+ last_query = now;
+ }
+
#if 0
if (err = libusb_bulk_transfer(devh, 0x81, resp, 64, &received, 2000)) {
usb_error("Receive failed: error %d", err);