forked from networkupstools/nut
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request networkupstools#2480 from chbgdn/powercom-shutdown…
…-fix drivers/powercom-hid.c: fix bytes order in shutdown commands
- Loading branch information
Showing
6 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* 2003 - 2009 Arnaud Quette <[email protected]> | ||
* 2005 - 2006 Peter Selinger <[email protected]> | ||
* 2008 - 2009 Arjen de Korte <[email protected]> | ||
* 2020 - 2022 Jim Klimov <[email protected]> | ||
* 2020 - 2024 Jim Klimov <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -26,7 +26,7 @@ | |
#include "powercom-hid.h" | ||
#include "usb-common.h" | ||
|
||
#define POWERCOM_HID_VERSION "PowerCOM HID 0.7" | ||
#define POWERCOM_HID_VERSION "PowerCOM HID 0.71" | ||
/* FIXME: experimental flag to be put in upsdrv_info */ | ||
|
||
/* PowerCOM */ | ||
|
@@ -54,6 +54,14 @@ static usb_device_id_t powercom_usb_device_table[] = { | |
|
||
static char powercom_scratch_buf[32]; | ||
|
||
/* Original subdriver code until version 0.7 sent shutdown commands | ||
* in a wrong byte order than is needed by devices seen in the field | ||
* in 2024. Just in case there are different firmwares, we provide | ||
* a toggle to use old behavior. Maybe it was just a bug and nobody | ||
* needs this fall-back... | ||
*/ | ||
static char powercom_sdcmd_byte_order_fallback = 0; | ||
|
||
static const char *powercom_startup_fun(double value) | ||
{ | ||
uint16_t i = value; | ||
|
@@ -93,7 +101,14 @@ static const char *powercom_shutdown_fun(double value) | |
{ | ||
uint16_t i = value; | ||
|
||
snprintf(powercom_scratch_buf, sizeof(powercom_scratch_buf), "%d", 60 * (i & 0x00FF) + (i >> 8)); | ||
if (powercom_sdcmd_byte_order_fallback) { | ||
/* Legacy behavior */ | ||
snprintf(powercom_scratch_buf, sizeof(powercom_scratch_buf), "%d", 60 * (i & 0x00FF) + (i >> 8)); | ||
} else { | ||
/* New default */ | ||
snprintf(powercom_scratch_buf, sizeof(powercom_scratch_buf), "%d", 60 * (i >> 8) + (i & 0x00FF)); | ||
} | ||
|
||
upsdebugx(3, "%s: value = %.0f, buf = %s", __func__, value, powercom_scratch_buf); | ||
|
||
return powercom_scratch_buf; | ||
|
@@ -113,8 +128,16 @@ static double powercom_shutdown_nuf(const char *value) | |
|
||
val = (uint16_t)iv; | ||
val = val ? val : 1; /* 0 sets the maximum delay */ | ||
command = ((uint16_t)((val % 60) << 8)) + (uint16_t)(val / 60); | ||
command |= 0x4000; /* AC RESTART NORMAL ENABLE */ | ||
if (powercom_sdcmd_byte_order_fallback) { | ||
/* Legacy behavior */ | ||
command = ((uint16_t)((val % 60) << 8)) + (uint16_t)(val / 60); | ||
command |= 0x4000; /* AC RESTART NORMAL ENABLE */ | ||
} else { | ||
/* New default */ | ||
command = ((uint16_t)((val / 60) << 8)) + (uint16_t)(val % 60); | ||
command |= 0x0040; /* AC RESTART NORMAL ENABLE */ | ||
} | ||
|
||
upsdebugx(3, "%s: value = %s, command = %04X", __func__, value, command); | ||
|
||
return command; | ||
|
@@ -138,8 +161,16 @@ static double powercom_stayoff_nuf(const char *value) | |
|
||
val = (uint16_t)iv; | ||
val = val ? val : 1; /* 0 sets the maximum delay */ | ||
command = ((uint16_t)((val % 60) << 8)) + (uint16_t)(val / 60); | ||
command |= 0x8000; /* AC RESTART NORMAL DISABLE */ | ||
if (powercom_sdcmd_byte_order_fallback) { | ||
/* Legacy behavior */ | ||
command = ((uint16_t)((val % 60) << 8)) + (uint16_t)(val / 60); | ||
command |= 0x8000; /* AC RESTART NORMAL DISABLE */ | ||
} else { | ||
/* New default */ | ||
command = ((uint16_t)((val / 60) << 8)) + (uint16_t)(val % 60); | ||
command |= 0x0080; /* AC RESTART NORMAL DISABLE */ | ||
} | ||
|
||
upsdebugx(3, "%s: value = %s, command = %04X", __func__, value, command); | ||
|
||
return command; | ||
|
@@ -541,8 +572,9 @@ static int powercom_claim(HIDDevice_t *hd) | |
} | ||
/* by default, reject, unless the productid option is given */ | ||
if (getval("productid")) { | ||
return 1; | ||
goto accept; | ||
} | ||
/* report and reject */ | ||
possibly_supported("PowerCOM", hd); | ||
return 0; | ||
|
||
|
@@ -551,12 +583,17 @@ static int powercom_claim(HIDDevice_t *hd) | |
interrupt_only = 1; | ||
interrupt_size = 8; | ||
} | ||
return 1; | ||
goto accept; | ||
|
||
case NOT_SUPPORTED: | ||
default: | ||
return 0; | ||
} | ||
|
||
accept: | ||
powercom_sdcmd_byte_order_fallback = testvar("powercom_sdcmd_byte_order_fallback"); | ||
|
||
return 1; | ||
} | ||
|
||
subdriver_t powercom_subdriver = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters