Skip to content

Commit

Permalink
drivers/optiups.c: rename global variables to not start with underscore
Browse files Browse the repository at this point in the history
clang-19: error: identifier '_pollv_ps' is reserved because it
starts with '_' at global scope [-Werror,-Wreserved-identifier]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jan 29, 2025
1 parent 10f6880 commit 5a4ad2b
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions drivers/optiups.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "nut_stdint.h"

#define DRIVER_NAME "Opti-UPS driver"
#define DRIVER_VERSION "1.06"
#define DRIVER_VERSION "1.07"

/* driver description structure */
upsdrv_info_t upsdrv_info = {
Expand Down Expand Up @@ -77,7 +77,7 @@ upsdrv_info_t upsdrv_info = {
#define OPTI_POWERUP "powerup"

/* All serial commands put their response in the same buffer space */
static char _buf[256];
static char opti_buf[256];

/* Model */
static int optimodel = 0;
Expand Down Expand Up @@ -108,14 +108,14 @@ typedef struct ezfill_s {

/* These can be polled right into a string usable by NUT.
* Others such as "AG" and "BV" require some transformation of the return value */
static ezfill_t _pollv[] = {
static ezfill_t opti_pollv[] = {
{ "NV", "input.voltage", 0 },
{ "OL", "ups.load", 1.0 },
{ "OV", "output.voltage", 0 },
{ "FF", "input.frequency", 0.1 },
{ "BT", "ups.temperature", 0 },
};
static ezfill_t _pollv_zinto[] = {
static ezfill_t opti_pollv_zinto[] = {
{ "NV", "input.voltage", 2.0 },
{ "OL", "ups.load", 1.0 },
{ "OV", "output.voltage", 2.0 },
Expand All @@ -131,14 +131,14 @@ static ezfill_t _pollv_zinto[] = {
* I suspect this will be the case for other Opti-UPS models, but as I can only
* test with a PS-1440RM at 230V the change is only applied to PowerSeries models.
*/
static ezfill_t _pollv_ps[] = {
static ezfill_t opti_pollv_ps[] = {
{ "OL", "ups.load", 1.0 },
{ "FF", "input.frequency", 0.1 },
{ "BT", "ups.temperature", 0 },
};

/* model "IO" is parsed differently in upsdrv_initinfo() */
static ezfill_t _initv[] = {
static ezfill_t opti_initv[] = {
{ "IM", "ups.mfr", 0 },
{ "IZ", "ups.serial", 0 },
{ "IS", "ups.firmware", 0 },
Expand All @@ -151,32 +151,32 @@ static inline ssize_t optireadline(void)
{
ssize_t r;
usleep(150000);
r = ser_get_line(upsfd, _buf, sizeof(_buf), ENDCHAR, IGNCHARS, 0, 500000 );
_buf[sizeof(_buf)-1] = 0;
r = ser_get_line(upsfd, opti_buf, sizeof(opti_buf), ENDCHAR, IGNCHARS, 0, 500000 );
opti_buf[sizeof(opti_buf)-1] = 0;
if ( r > 0 )
{
if ( r < (int)sizeof(_buf) )
_buf[r] = 0;
if ( _buf[0] == 0x15 )
if ( r < (int)sizeof(opti_buf) )
opti_buf[r] = 0;
if ( opti_buf[0] == 0x15 )
{
r=-2;
upsdebugx(1, "READ: <unsupported command>");
}
if ( _buf[0] == 0x06 )
if ( opti_buf[0] == 0x06 )
{
upsdebugx(2, "READ: <command done>");
}
else
{
upsdebugx(2, "READ: \"%s\"", _buf );
upsdebugx(2, "READ: \"%s\"", opti_buf );
}
}
else
upsdebugx(1, "READ ERROR: %" PRIiSIZE, r);
return r;
}

/* Send a command and read the response. Command response is in global _buf.
/* Send a command and read the response. Command response is in global opti_buf.
* Return
* > 0 implies success.
* -1 serial timeout
Expand Down Expand Up @@ -221,12 +221,12 @@ static void optifill( ezfill_t *a, size_t len )
}
if ( a[i].scale > 1e-20 )
{
float f = strtol( _buf, NULL, 10 ) * a[i].scale;
float f = strtol( opti_buf, NULL, 10 ) * a[i].scale;
dstate_setinfo( a[i].var, "%.1f", f );
}
else
{
dstate_setinfo( a[i].var, "%s", _buf);
dstate_setinfo( a[i].var, "%s", opti_buf);
}
}
}
Expand Down Expand Up @@ -340,8 +340,8 @@ void upsdrv_initinfo(void)
if ( testvar(OPTI_POWERUP) && optiquery( "AG" ) < 1 )
{
ser_send( upsfd, "AG\r\n" );
r = ser_get_char(upsfd, &_buf[0], 1, 0);
if ( r == 1 && _buf[0] == '2' )
r = ser_get_char(upsfd, &opti_buf[0], 1, 0);
if ( r == 1 && opti_buf[0] == '2' )
{
upslogx( LOG_WARNING, "ups was off, switching it on" );
optiquery( "Ct1" );
Expand All @@ -353,7 +353,7 @@ void upsdrv_initinfo(void)

/* Autodetect an Online-USV (only Zinto D is known to work) */
r = optiquery( "IM" );
if ( r > 0 && !strcasecmp(_buf, "ONLINE") )
if ( r > 0 && !strcasecmp(opti_buf, "ONLINE") )
{
optimodel = OPTIMODEL_ZINTO;
optiquery( "Om11" );
Expand All @@ -363,47 +363,47 @@ void upsdrv_initinfo(void)

/* Autodetect an Opti-UPS PS series */
r = optiquery( "IO" );
if ( r > 0 && !strncasecmp(_buf, "PS-", 3) )
if ( r > 0 && !strncasecmp(opti_buf, "PS-", 3) )
{
optimodel = OPTIMODEL_PS;
}

optifill( _initv, SIZEOF_ARRAY(_initv) );
optifill( opti_initv, SIZEOF_ARRAY(opti_initv) );

/* Parse out model into longer string -- is this really USEFUL??? */
r = optiquery( "IO" );
if ( r < 1 )
fatal_with_errno(EXIT_FAILURE, "can't retrieve model" );
else
{
switch ( _buf[r-1] )
switch ( opti_buf[r-1] )
{
case 'E':
case 'P':
case 'V':
dstate_setinfo("ups.model", "Power%cS %s", _buf[r-1], _buf );
dstate_setinfo("ups.model", "Power%cS %s", opti_buf[r-1], opti_buf );
break;
default:
dstate_setinfo("ups.model", "%s", _buf );
dstate_setinfo("ups.model", "%s", opti_buf );
break;
}
}

/* Parse out model into longer string */
r = optiquery( "IM" );
if ( r > 0 && !strcasecmp(_buf, "ONLINE") )
if ( r > 0 && !strcasecmp(opti_buf, "ONLINE") )
{
dstate_setinfo("ups.mfr", "ONLINE USV-Systeme AG");
r = optiquery( "IO" );
if ( r < 1 )
fatal_with_errno(EXIT_FAILURE, "can't retrieve model" );
switch ( _buf[0] )
switch ( opti_buf[0] )
{
case 'D':
dstate_setinfo("ups.model", "Zinto %s", _buf );
dstate_setinfo("ups.model", "Zinto %s", opti_buf );
break;
default:
dstate_setinfo("ups.model", "%s", _buf );
dstate_setinfo("ups.model", "%s", opti_buf );
break;
}
}
Expand Down Expand Up @@ -440,8 +440,8 @@ void upsdrv_updateinfo(void)
if ( r < 1 && optimodel == OPTIMODEL_ZINTO )
{
ser_send( upsfd, "AG\r\n" );
r = ser_get_char(upsfd, &_buf[0], 1, 0);
if ( r == 1 && _buf[0] == '2' )
r = ser_get_char(upsfd, &opti_buf[0], 1, 0);
if ( r == 1 && opti_buf[0] == '2' )
{
status_init();
status_set("OFF");
Expand All @@ -457,7 +457,7 @@ void upsdrv_updateinfo(void)
}
else
{
long s = strtol( _buf, NULL, 16 );
long s = strtol( opti_buf, NULL, 16 );
status_init();
if ( s & OPTISBIT_OVERLOAD )
status_set("OVER");
Expand All @@ -483,21 +483,21 @@ void upsdrv_updateinfo(void)

/* read some easy settings */
if ( optimodel == OPTIMODEL_ZINTO )
optifill( _pollv_zinto, SIZEOF_ARRAY(_pollv_zinto) );
optifill( opti_pollv_zinto, SIZEOF_ARRAY(opti_pollv_zinto) );
else if ( optimodel == OPTIMODEL_PS ) {
short inV, outV, fV;

optifill( _pollv_ps, SIZEOF_ARRAY(_pollv_ps) );
optifill( opti_pollv_ps, SIZEOF_ARRAY(opti_pollv_ps) );

r = optiquery( "NV" );
str_to_short ( _buf, &inV, 10 );
str_to_short ( opti_buf, &inV, 10 );
r = optiquery( "OV" );
str_to_short ( _buf, &outV, 10 );
str_to_short ( opti_buf, &outV, 10 );

r = optiquery( "FV" );
if ( r >= 1 )
{
str_to_short ( _buf, &fV, 10 );
str_to_short ( opti_buf, &fV, 10 );
if ( fV > 180 )
{
inV = inV * 2;
Expand All @@ -508,15 +508,15 @@ void upsdrv_updateinfo(void)
dstate_setinfo( "output.voltage", "%d", outV );
}
else
optifill( _pollv, SIZEOF_ARRAY(_pollv) );
optifill( opti_pollv, SIZEOF_ARRAY(opti_pollv) );

/* Battery voltage is harder */
r = optiquery( "BV" );
if ( r < 1 )
upslogx( LOG_WARNING, "cannot retrieve battery voltage" );
else
{
float p, v = strtol( _buf, NULL, 10 ) / 10.0;
float p, v = strtol( opti_buf, NULL, 10 ) / 10.0;
dstate_setinfo("battery.voltage", "%.1f", v );

if (v > 20)
Expand Down Expand Up @@ -553,7 +553,7 @@ void upsdrv_shutdown(void)
}
else
{
s = strtol( _buf, NULL, 16 );
s = strtol( opti_buf, NULL, 16 );
}

/* Turn output stage back on if power returns - but really means
Expand Down

0 comments on commit 5a4ad2b

Please sign in to comment.