Skip to content

Commit

Permalink
Print serial number on check
Browse files Browse the repository at this point in the history
  • Loading branch information
xychen committed Jun 16, 2022
1 parent c446e24 commit dd692d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions cp2102/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ main(int argc, char **argv)
ret = -1;
goto err_open;
} else {
LOGI("%s", cp2102_get_serial_number(dev));
ret = 0;
goto err_io;
}
Expand Down
2 changes: 2 additions & 0 deletions libcp2102_usb/include/cp2102.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ typedef struct _cp2102_dev_t cp2102_dev_t;
cp2102_dev_t *cp2102_open(const char *dev_name);
void cp2102_close(cp2102_dev_t **dev);

const char *cp2102_get_serial_number(cp2102_dev_t *dev);

bool cp2102_set_value(cp2102_dev_t *dev, uint8_t state, uint8_t mask);
bool cp2102_get_value(cp2102_dev_t *dev, uint8_t *state);

Expand Down
12 changes: 12 additions & 0 deletions libcp2102_usb/src/cp2102_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ cp2102_open(const char *dev_name)
cp2102_dev_t *dev = malloc(sizeof(cp2102_dev_t));
dev->handle = handle;

dev->serial_number = malloc(strlen(serial) + 1);
strcpy(dev->serial_number, serial);

return dev;
}

Expand All @@ -133,10 +136,19 @@ cp2102_close(cp2102_dev_t **dev)
if ((*dev)->handle != NULL) {
libusb_close((*dev)->handle);
}
if ((*dev)->serial_number != NULL) {
free((*dev)->serial_number);
}
free(*dev);
*dev = NULL;
}

const char *
cp2102_get_serial_number(cp2102_dev_t *dev)
{
return (const char *)dev->serial_number;
}

bool
cp2102_set_value(cp2102_dev_t *dev, uint8_t state, uint8_t mask)
{
Expand Down
1 change: 1 addition & 0 deletions libcp2102_usb/src/cp2102_libusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

struct _cp2102_dev_t {
libusb_device_handle *handle;
char *serial_number;
};

#endif // __LIB_CP2102_LIBUSB_H__

0 comments on commit dd692d3

Please sign in to comment.