Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions docs/man/bcmxcp_usb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,10 @@ linkman:ups.conf[5].
The number of seconds that the UPS should wait between receiving the
shutdown command and actually shutting off.

NOTE: This driver does not currently support USB-matching settings common
to other drivers, such as *vendor*, *vendorid*, *product*, *productid*,
*serial*, *device* or *bus*.

////////
The note above may be addressed by
https://github.com/networkupstools/nut/issues/1764
When that happens, replace it by the following lines:

USB INTERFACE ONLY
~~~~~~~~~~~~~~~~~~

include::nut_usb_addvars.txt[]
////////

DEFAULT VALUES FOR THE EXTRA ARGUMENTS
--------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions drivers/bcmxcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ TODO List:
#include "bcmxcp.h"

#define DRIVER_NAME "BCMXCP UPS driver"
#define DRIVER_VERSION "0.39"
#define DRIVER_VERSION "0.40"

#define MAX_NUT_NAME_LENGTH 128
#define NUT_OUTLET_POSITION 7
Expand All @@ -135,7 +135,7 @@ upsdrv_info_t upsdrv_info = {
"Alf Høgemark <alf@i100>\n" \
"Gavrilov Igor",
DRV_STABLE,
{ &comm_upsdrv_info, NULL }
{ &bcmxcp_comm_upsdrv_info, NULL }
};

static uint16_t get_word(const unsigned char*);
Expand Down Expand Up @@ -2226,15 +2226,16 @@ void upsdrv_tweak_prognames(void)
{
}

/* list flags and values that you want to receive via -x */
void upsdrv_makevartable(void)
/* list flags and values that you want to receive via -x
* or ups.conf to all bcmxcp* family of drivers
*/
void bcmxcp_makevartable(void)
{
/* NOTE: The USB variant of this driver currently does not
* involve nut_usb_addvars() method like others do. When
* fixing, see also tools/nut-scanner/scan_usb.c "exceptions".
*/
addvar(VAR_VALUE, "shutdown_delay", "Specify shutdown delay (seconds)");
addvar(VAR_VALUE, "baud_rate", "Specify communication speed (ex: 9600)");
}

int setvar (const char *varname, const char *val)
Expand Down
2 changes: 2 additions & 0 deletions drivers/bcmxcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,6 @@ typedef enum ebool { FALSE, TRUE } bool_t;
typedef int bool_t;
#endif

void bcmxcp_makevartable(void);

#endif /* NUT_BCMXCP_H_SEEN */
2 changes: 1 addition & 1 deletion drivers/bcmxcp_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ void upsdrv_cleanup(void);
void upsdrv_reconnect(void);
void upsdrv_comm_good(void);

extern upsdrv_info_t comm_upsdrv_info;
extern upsdrv_info_t bcmxcp_comm_upsdrv_info;

#endif /* BCMXCP_IO__ */
11 changes: 9 additions & 2 deletions drivers/bcmxcp_ser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include "nut_stdint.h"

#define SUBDRIVER_NAME "RS-232 communication subdriver"
#define SUBDRIVER_VERSION "0.22"
#define SUBDRIVER_VERSION "0.23"

/* communication driver description structure */
upsdrv_info_t comm_upsdrv_info = {
upsdrv_info_t bcmxcp_comm_upsdrv_info = {
SUBDRIVER_NAME,
SUBDRIVER_VERSION,
NULL,
Expand Down Expand Up @@ -410,6 +410,13 @@ static void pw_comm_setup(const char *port)
# pragma GCC diagnostic pop
#endif

void upsdrv_makevartable(void)
{
bcmxcp_makevartable();

addvar(VAR_VALUE, "baud_rate", "Specify communication speed (ex: 9600)");
}

void upsdrv_initups(void)
{
upsfd = ser_open(device_path);
Expand Down
18 changes: 15 additions & 3 deletions drivers/bcmxcp_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "bcmxcp.h"
#include "bcmxcp_io.h"
#include "common.h"
#include "nut_libusb.h"
#include "usb-common.h"
#include "timehead.h"
#include "nut_stdint.h" /* for uint16_t */
Expand All @@ -11,10 +12,13 @@
#include <unistd.h>

#define SUBDRIVER_NAME "USB communication subdriver"
#define SUBDRIVER_VERSION "0.28"
#define SUBDRIVER_VERSION "0.29"

/* communication driver description structure */
upsdrv_info_t comm_upsdrv_info = {
/* communication driver description structure
* NOTE: Renamed from comm_upsdrv_info to avoid conflict
* with that defined in libusb{0,1}.c
*/
upsdrv_info_t bcmxcp_comm_upsdrv_info = {
SUBDRIVER_NAME,
SUBDRIVER_VERSION,
NULL,
Expand Down Expand Up @@ -367,6 +371,14 @@ void upsdrv_comm_good(void)
nutusb_comm_good();
}

void upsdrv_makevartable(void)
{
bcmxcp_makevartable();

/* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */
nut_usb_addvars();
}

void upsdrv_initups(void)
{
upsdev = nutusb_open("USB");
Expand Down
13 changes: 13 additions & 0 deletions drivers/usb-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,39 @@ int is_usb_device_supported(usb_device_id_t *usb_device_id_list, USBDevice_t *de
int retval = NOT_SUPPORTED;
usb_device_id_t *usbdev;

upsdebugx(3, "%s: checking if this driver can support USB device VID:PID 0x%04X:0x%04X",
__func__, (unsigned int)device->VendorID, (unsigned int)device->ProductID);

for (usbdev = usb_device_id_list;
(usbdev->vendorID != 0 || usbdev->productID != 0 || usbdev->fun != NULL);
usbdev++
) {
upsdebugx(4, "%s: checking table entry for VID:PID 0x%04X:0x%04X "
"(custom init handler is%s available)",
__func__, (unsigned int)usbdev->vendorID,
(unsigned int)usbdev->productID,
(usbdev->fun == NULL ? " NOT" : ""));

if (usbdev->vendorID != device->VendorID) {
upsdebugx(4, "%s: NOT_SUPPORTED: vendor ID mismatch", __func__);
continue;
}

/* flag as possibly supported if we see a known vendor */
retval = POSSIBLY_SUPPORTED;

upsdebugx(4, "%s: POSSIBLY_SUPPORTED: known vendor ID at least", __func__);
if (usbdev->productID != device->ProductID) {
continue;
}

/* call the specific handler, if it exists */
if (usbdev->fun != NULL) {
upsdebugx(4, "%s: call the custom init handler", __func__);
(*usbdev->fun)(device);
}

upsdebugx(4, "%s: SUPPORTED: known vendor and product IDs", __func__);
return SUPPORTED;
}

Expand Down
17 changes: 17 additions & 0 deletions tools/nut-scanner/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ lib_LTLIBRARIES =
include_HEADERS =
dist_noinst_HEADERS =

# Separate the .deps of other dirs from this one
# NOTE: Not using "$<" due to a legacy Sun/illumos dmake bug with resolver
# of dynamic vars, see e.g. https://man.omnios.org/man1/make#BUGS
LINKED_SOURCE_FILES = serial.c
serial.c: $(top_srcdir)/drivers/serial.c
test -s "$@" || ln -s -f "$(top_srcdir)/drivers/serial.c" "$@"

LINKED_SOURCE_FILES += bcmxcp_ser.c bcmxcp.c
bcmxcp_ser.c: $(top_srcdir)/drivers/bcmxcp_ser.c
test -s "$@" || ln -s -f "$(top_srcdir)/drivers/bcmxcp_ser.c" "$@"

bcmxcp.c: $(top_srcdir)/drivers/bcmxcp.c
test -s "$@" || ln -s -f "$(top_srcdir)/drivers/bcmxcp.c" "$@"

CLEANFILES += $(LINKED_SOURCE_FILES)
BUILT_SOURCES += $(LINKED_SOURCE_FILES)

# Note: we only build nut-scanner, and its library, if libltdl was found (required ATM!)
if WITH_NUT_SCANNER
bin_PROGRAMS += nut-scanner
Expand Down
8 changes: 8 additions & 0 deletions tools/nut-scanner/scan_eaton_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ unsigned char calc_checksum(const unsigned char *buf)
return c;
}

void addvar(int vartype, const char *name, const char *desc) {
NUT_UNUSED_VARIABLE(vartype);
NUT_UNUSED_VARIABLE(name);
NUT_UNUSED_VARIABLE(desc);
}

void bcmxcp_makevartable(void) {}

/*******************************************************************************
* SHUT functions (MGE legacy, but Eaton path forward)
******************************************************************************/
Expand Down
Loading