diff options
author | Marc Schink <dev@zapb.de> | 2020-05-31 11:17:59 +0200 |
---|---|---|
committer | Marc Schink <dev@zapb.de> | 2020-05-31 11:20:48 +0200 |
commit | 109f984237be6c616c6248c1125bda429b8fdf3d (patch) | |
tree | 9506b3734569edf7e74613ad16805438654f4de8 | |
parent | 3322dfa5e7aa56f5b12b7f2197e3e6b850b7b66e (diff) | |
download | libjaylink-109f984237be6c616c6248c1125bda429b8fdf3d.zip libjaylink-109f984237be6c616c6248c1125bda429b8fdf3d.tar.gz libjaylink-109f984237be6c616c6248c1125bda429b8fdf3d.tar.bz2 |
Minor code cleanup
Signed-off-by: Marc Schink <dev@zapb.de>
-rw-r--r-- | libjaylink/buffer.c | 8 | ||||
-rw-r--r-- | libjaylink/device.c | 2 | ||||
-rw-r--r-- | libjaylink/discovery_tcp.c | 4 | ||||
-rw-r--r-- | libjaylink/discovery_usb.c | 65 | ||||
-rw-r--r-- | libjaylink/libjaylink-internal.h | 6 |
5 files changed, 44 insertions, 41 deletions
diff --git a/libjaylink/buffer.c b/libjaylink/buffer.c index 527c25e..1aa1389 100644 --- a/libjaylink/buffer.c +++ b/libjaylink/buffer.c @@ -74,7 +74,7 @@ JAYLINK_PRIV uint16_t buffer_get_u16(const uint8_t *buffer, size_t offset) * host byte order. */ #ifdef WORDS_BIGENDIAN - value = (((uint16_t)buffer[offset + 1])) | \ + value = (((uint16_t)buffer[offset + 1])) | (((uint16_t)buffer[offset + 0]) << 8); #else memcpy(&value, buffer + offset, sizeof(value)); @@ -128,9 +128,9 @@ JAYLINK_PRIV uint32_t buffer_get_u32(const uint8_t *buffer, size_t offset) * host byte order. */ #ifdef WORDS_BIGENDIAN - value = (((uint32_t)buffer[offset + 3])) | \ - (((uint32_t)buffer[offset + 2]) << 8) | \ - (((uint32_t)buffer[offset + 1]) << 16) | \ + value = (((uint32_t)buffer[offset + 3])) | + (((uint32_t)buffer[offset + 2]) << 8) | + (((uint32_t)buffer[offset + 1]) << 16) | (((uint32_t)buffer[offset + 0]) << 24); #else memcpy(&value, buffer + offset, sizeof(value)); diff --git a/libjaylink/device.c b/libjaylink/device.c index 5a87fcf..a7f7001 100644 --- a/libjaylink/device.c +++ b/libjaylink/device.c @@ -239,7 +239,7 @@ JAYLINK_API int jaylink_device_get_serial_number( if (!dev || !serial_number) return JAYLINK_ERR_ARG; - if (!dev->valid_serial_number) + if (!dev->has_serial_number) return JAYLINK_ERR_NOT_AVAILABLE; *serial_number = dev->serial_number; diff --git a/libjaylink/discovery_tcp.c b/libjaylink/discovery_tcp.c index 002fa67..a03fed8 100644 --- a/libjaylink/discovery_tcp.c +++ b/libjaylink/discovery_tcp.c @@ -129,7 +129,7 @@ static bool parse_adv_message(struct jaylink_device *dev, dev->has_mac_address = true; dev->serial_number = buffer_get_u32(buffer, 48); - dev->valid_serial_number = true; + dev->has_serial_number = true; tmp = buffer_get_u32(buffer, 52); dev->hw_version.type = (tmp / 1000000) % 100; @@ -205,7 +205,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, dev->iface = JAYLINK_HIF_TCP; dev->serial_number = tmp.serial_number; - dev->valid_serial_number = tmp.valid_serial_number; + dev->has_serial_number = tmp.has_serial_number; memcpy(dev->ipv4_address, tmp.ipv4_address, sizeof(dev->ipv4_address)); diff --git a/libjaylink/discovery_usb.c b/libjaylink/discovery_usb.c index 27e1b8c..12d35dd 100644 --- a/libjaylink/discovery_usb.c +++ b/libjaylink/discovery_usb.c @@ -43,27 +43,30 @@ #define USB_VENDOR_ID 0x1366 /* USB Product IDs (PID) and their corresponding USB addresses. */ -static const uint16_t pids[][2] = { - {0x0101, 0}, - {0x0102, 1}, - {0x0103, 2}, - {0x0104, 3}, - {0x0105, 0}, - {0x0107, 0}, - {0x0108, 0}, - {0x1010, 0}, - {0x1011, 0}, - {0x1012, 0}, - {0x1013, 0}, - {0x1014, 0}, - {0x1015, 0}, - {0x1016, 0}, - {0x1017, 0}, - {0x1018, 0}, - {0x1020, 0}, - {0x1051, 0}, - {0x1055, 0}, - {0x1061, 0} +static const struct { + uint16_t pid; + enum jaylink_usb_address usb_address; +} pids[] = { + {0x0101, JAYLINK_USB_ADDRESS_0}, + {0x0102, JAYLINK_USB_ADDRESS_1}, + {0x0103, JAYLINK_USB_ADDRESS_2}, + {0x0104, JAYLINK_USB_ADDRESS_3}, + {0x0105, JAYLINK_USB_ADDRESS_0}, + {0x0107, JAYLINK_USB_ADDRESS_0}, + {0x0108, JAYLINK_USB_ADDRESS_0}, + {0x1010, JAYLINK_USB_ADDRESS_0}, + {0x1011, JAYLINK_USB_ADDRESS_0}, + {0x1012, JAYLINK_USB_ADDRESS_0}, + {0x1013, JAYLINK_USB_ADDRESS_0}, + {0x1014, JAYLINK_USB_ADDRESS_0}, + {0x1015, JAYLINK_USB_ADDRESS_0}, + {0x1016, JAYLINK_USB_ADDRESS_0}, + {0x1017, JAYLINK_USB_ADDRESS_0}, + {0x1018, JAYLINK_USB_ADDRESS_0}, + {0x1020, JAYLINK_USB_ADDRESS_0}, + {0x1051, JAYLINK_USB_ADDRESS_0}, + {0x1055, JAYLINK_USB_ADDRESS_0}, + {0x1061, JAYLINK_USB_ADDRESS_0} }; /** Maximum length of the USB string descriptor for the serial number. */ @@ -136,9 +139,9 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, struct libusb_device_handle *usb_devh; struct jaylink_device *dev; char buf[USB_SERIAL_NUMBER_LENGTH + 1]; - uint8_t usb_address; + enum jaylink_usb_address usb_address; uint32_t serial_number; - bool valid_serial_number; + bool has_serial_number; bool found_device; ret = libusb_get_device_descriptor(usb_dev, &desc); @@ -155,9 +158,9 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, found_device = false; for (size_t i = 0; i < sizeof(pids) / sizeof(pids[0]); i++) { - if (pids[i][0] == desc.idProduct) { + if (pids[i].pid == desc.idProduct) { + usb_address = pids[i].usb_address; found_device = true; - usb_address = pids[i][1]; break; } } @@ -179,7 +182,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, if (dev) { log_dbg(ctx, "Device: USB address = %u.", dev->usb_address); - if (dev->valid_serial_number) + if (dev->has_serial_number) log_dbg(ctx, "Device: Serial number = %u.", dev->serial_number); else @@ -199,7 +202,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, } serial_number = 0; - valid_serial_number = true; + has_serial_number = true; ret = libusb_get_string_descriptor_ascii(usb_devh, desc.iSerialNumber, (unsigned char *)buf, USB_SERIAL_NUMBER_LENGTH + 1); @@ -209,10 +212,10 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, if (ret < 0) { log_warn(ctx, "Failed to retrieve serial number: %s.", libusb_error_name(ret)); - valid_serial_number = false; + has_serial_number = false; } - if (valid_serial_number) { + if (has_serial_number) { if (!parse_serial_number(buf, &serial_number)) { log_warn(ctx, "Failed to parse serial number."); return NULL; @@ -221,7 +224,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, log_dbg(ctx, "Device: USB address = %u.", usb_address); - if (valid_serial_number) + if (has_serial_number) log_dbg(ctx, "Device: Serial number = %u.", serial_number); else log_dbg(ctx, "Device: Serial number = N/A."); @@ -239,7 +242,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx, dev->usb_dev = libusb_ref_device(usb_dev); dev->usb_address = usb_address; dev->serial_number = serial_number; - dev->valid_serial_number = valid_serial_number; + dev->has_serial_number = has_serial_number; return dev; } diff --git a/libjaylink/libjaylink-internal.h b/libjaylink/libjaylink-internal.h index f97ec14..106bf46 100644 --- a/libjaylink/libjaylink-internal.h +++ b/libjaylink/libjaylink-internal.h @@ -95,13 +95,13 @@ struct jaylink_device { * real serial number of the device. */ uint32_t serial_number; - /** Indicates whether the serial number is valid. */ - bool valid_serial_number; + /** Indicates whether the serial number is available. */ + bool has_serial_number; #ifdef HAVE_LIBUSB /** libusb device instance. */ struct libusb_device *usb_dev; /** USB address of the device. */ - uint8_t usb_address; + enum jaylink_usb_address usb_address; #endif /** * IPv4 address. |