cake
/
libcasio
Archived
1
1
Fork 0

Added usb bus and device address filtering

This commit is contained in:
Thomas Touhey 2018-05-06 19:08:28 +02:00
parent c3a3b05917
commit 6836e1d542
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
9 changed files with 51 additions and 18 deletions

View File

@ -219,7 +219,8 @@ define get-util-source
U_SRC_$1 := $(patsubst $(U_SRCDIR)/$1/%,%,$(wildcard $(U_SRCDIR)/$1/*.c \
$(U_SRCDIR)/$1/**/*.c))
U_INC_$1 := $(patsubst $(U_INCDIR)/$1/%,%,$(wildcard $(U_SRCDIR)/$1/*.h \
$(U_SRCDIR)/$1/**/*.h))
$(U_SRCDIR)/$1/**/*.h)) \
$(if $(filter libcasio,$(U_DEPS_$1)),$(L_INCp:%=$(L_INCDIR)/%))
U_CFLAGS_$1 := $(CFLAGS) $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_CFLAGS)) \
-D BIN="\"$1$(if $(FOR_WINDOWS),.exe)\"" \

View File

@ -61,7 +61,8 @@ CASIO_EXTERN int CASIO_EXPORT casio_open_stream_fd
# ifndef LIBCASIO_DISABLED_LIBUSB
CASIO_EXTERN int CASIO_EXPORT casio_openusb_libusb
OF((casio_stream_t **casio__stream));
OF((casio_stream_t **casio__stream,
int casio__bus, int casio__address));
# endif
/* Make a stream using the Microsoft Windows API. */
@ -69,7 +70,8 @@ CASIO_EXTERN int CASIO_EXPORT casio_openusb_libusb
# if defined(_WIN16) || defined(_WIN32) || defined(_WIN64) \
|| defined(__WINDOWS__)
CASIO_EXTERN int CASIO_EXPORT casio_openusb_windows
OF((casio_stream_t **casio__stream));
OF((casio_stream_t **casio__stream,
int casio__bus, int casio__address));
CASIO_EXTERN int CASIO_EXPORT casio_opencom_windows
OF((casio_stream_t **casio__stream, const char *casio__path));
# else

View File

@ -134,7 +134,8 @@ CASIO_BEGIN_DECLS
/* Cross-platform initialization. */
CASIO_EXTERN int CASIO_EXPORT casio_open_usb
OF((casio_link_t **casio__h, unsigned long casio__flags));
OF((casio_link_t **casio__h, unsigned long casio__flags,
int casio__bus, int casio__address));
CASIO_EXTERN int CASIO_EXPORT casio_open_com
OF((casio_link_t **casio__h, unsigned long casio__flags,
const char *casio__path,

View File

@ -445,21 +445,27 @@ CASIO_EXTERN int CASIO_EXPORT casio_add_default_comlist
typedef int casio_opencomstream_t
OF((casio_stream_t **casio__stream, const char *casio__path));
CASIO_EXTERN int CASIO_EXPORT casio_add_default_com_stream
OF((casio_opencomstream_t *casio__function));
CASIO_EXTERN int CASIO_EXPORT casio_open_com_stream
OF((casio_stream_t **casio__stream,
const char *casio__path));
CASIO_EXTERN int CASIO_EXPORT casio_add_default_com_stream
OF((casio_opencomstream_t *casio__function));
/* USB stream opening. */
/* USB stream opening.
* The `bus` argument is set to -1 if we ought to find the first appropriate
* argument.
* The `address` argument is set to -1 if we ought to find any device on
* the given bus. */
typedef int CASIO_EXPORT casio_openusbstream_t
OF((casio_stream_t **casio__stream));
OF((casio_stream_t **casio__stream,
int casio__bus, int casio__address));
CASIO_EXTERN int CASIO_EXPORT casio_open_usb_stream
OF((casio_stream_t **casio__stream));
CASIO_EXTERN int CASIO_EXPORT casio_add_default_usb_stream
OF((casio_openusbstream_t *casio__function));
CASIO_EXTERN int CASIO_EXPORT casio_open_usb_stream
OF((casio_stream_t **casio__stream,
int casio__bus, int casio__address));
CASIO_END_DECLS
CASIO_END_NAMESPACE

View File

@ -24,10 +24,13 @@
*
* @arg handle the link handle to make.
* @arg flags the link flags.
* @arg bus the bus number.
* @arg address the device number.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_open_usb(casio_link_t **handle, unsigned long flags)
int CASIO_EXPORT casio_open_usb(casio_link_t **handle, unsigned long flags,
int bus, int address)
{
int err, failed = 0, tries = 3;
casio_stream_t *stream, *ns;
@ -42,7 +45,7 @@ int CASIO_EXPORT casio_open_usb(casio_link_t **handle, unsigned long flags)
casio_sleep(1000);
}
err = casio_open_usb_stream(&stream);
err = casio_open_usb_stream(&stream, bus, address);
if (err == casio_error_op)
return (casio_error_nocalc);
if (!err)

View File

@ -35,11 +35,13 @@ CASIO_LOCAL const casio_streamfuncs_t casio_libusb_callbacks = {
* Initialize a stream with USB device using libusb.
*
* @arg handle the handle to create.
* @arg flags the flags.
* @arg bus the bus number (-1 if both bus and address aren't set).
* @arg address the address on the bus (-1 if any address).
* @return the error code (0 if you're a knoop).
*/
int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream,
int bus, int address)
{
int err = 0, uerr, id, device_count;
libusb_context *context = NULL;
@ -69,6 +71,16 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
for (id = 0; id < device_count; id++) {
struct libusb_device_descriptor descriptor;
/* Check the position on the bus. */
if (bus >= 0) {
if (libusb_get_bus_number(device_list[id]) != bus)
continue;
if (address >= 0
&& libusb_get_device_address(device_list[id]) != address)
continue;
}
/* Get the device descriptor. */
if (libusb_get_device_descriptor(device_list[id], &descriptor))

View File

@ -62,17 +62,25 @@ int CASIO_EXPORT casio_add_default_usb_stream(casio_openusbstream_t *function)
* Open the USB stream.
*
* @arg stream the stream to make.
* @arg bus the USB bus on which to find the device.
* -1 if any device on any bus (and address is not read).
* @arg address the address on the bus of the device.
* -1 if any device on the bus.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_open_usb_stream(casio_stream_t **stream)
int CASIO_EXPORT casio_open_usb_stream(casio_stream_t **stream,
int bus, int address)
{
int err; struct corresp *c = openusbs;
if (bus < -1 || bus > 255 || address < -1 || address > 255)
return (casio_error_op);
if (!c->_valid)
return (casio_error_op);
for (; c->_valid; c++) {
err = (*c->_openusb)(stream);
err = (*c->_openusb)(stream, bus, address);
if (!err)
return (0);

View File

@ -212,7 +212,7 @@ int main(int ac, char **av)
if (args.com)
err = casio_open_com(&handle, args.initflags, args.com, args.use);
else
err = casio_open_usb(&handle, args.initflags);
err = casio_open_usb(&handle, args.initflags, -1, -1);
if (err) {
switch (err) {
case casio_error_nocalc:

View File

@ -211,7 +211,7 @@ int main(int ac, char **av)
/* Make the libcasio link handle. */
if ((err = casio_open_usb(&handle, 0))) {
if ((err = casio_open_usb(&handle, 0, -1, -1))) {
switch (err) {
case casio_error_nocalc:
fprintf(stderr, error_noconnexion);