Imported Upstream version 2.6.0

This commit is contained in:
arnaud.quette@free.fr 2011-01-26 10:35:08 +01:00
parent 26fb71b504
commit 459aaf9392
510 changed files with 40508 additions and 18859 deletions

View file

@ -64,7 +64,7 @@
/* --------------------------------------------------------------- */
#define DRIVER_NAME "MGE UPS SYSTEMS/U-Talk driver"
#define DRIVER_VERSION "0.89"
#define DRIVER_VERSION "0.92"
/* driver description structure */
@ -130,7 +130,6 @@ static const char *info_variable_cmd(const char *type);
static bool_t info_variable_ok(const char *type);
static int get_ups_status(void);
static int mge_command(char *reply, int replylen, const char *fmt, ...);
static void format_model_name(char *model);
/* --------------------------------------------------------------- */
/* UPS Driver Functions */
@ -218,17 +217,18 @@ void upsdrv_initups(void)
void upsdrv_initinfo(void)
{
char buf[BUFFLEN];
char *model = NULL;
const char *model = NULL;
char *firmware = NULL;
char *p;
char *v = NULL; /* for parsing Si output, get Version ID */
int table;
int tries;
int status_ok;
int status_ok = 0;
int bytes_rcvd;
int si_data1 = 0;
int si_data2 = 0;
mge_info_item_t *item;
models_name_t *model_info;
mge_model_info_t *legacy_model;
char infostr[32];
int chars_rcvd;
@ -247,10 +247,10 @@ void upsdrv_initinfo(void)
if(bytes_rcvd > 0 && buf[0] != '?') {
dstate_setinfo("ups.id", "%s", buf); /* raw id */
model = buf;
p = strrchr(buf, ' ');
model = buf;
p = strrchr(buf, ' ');
if ( p != NULL ) {
*p = '\0';
firmware = p+1;
@ -258,6 +258,16 @@ void upsdrv_initinfo(void)
if( firmware && strlen(firmware) < 1 )
firmware = NULL; /* no firmware information */
/* Parsing model names table */
for ( model_info = Si1_models_names ; model_info->basename != NULL ; model_info++ ) {
if(!strcasecmp(model_info->basename, model))
{
model = model_info->finalname;
upsdebugx(1, "initinfo: UPS model == >%s<", model);
break;
}
}
}
else
{
@ -286,12 +296,12 @@ void upsdrv_initinfo(void)
si_data2 = atoi(v);
}
/* Parsing legacy model table in order to found it */
for ( legacy_model = mge_model ; legacy_model->name != NULL ; legacy_model++ ) {
if(legacy_model->Data1 == si_data1 && legacy_model->Data2 == si_data2){
model = (char *)legacy_model->name;
upsdebugx(1, "initinfo: UPS model == >%s<", model);
break;
/* Parsing legacy model table in order to find it */
for ( legacy_model = mge_model ; legacy_model->name != NULL ; legacy_model++ ) {
if(legacy_model->Data1 == si_data1 && legacy_model->Data2 == si_data2){
model = legacy_model->name;
upsdebugx(1, "initinfo: UPS model == >%s<", model);
break;
}
}
@ -302,8 +312,14 @@ void upsdrv_initinfo(void)
}
if ( model ) {
format_model_name(model);
dstate_setinfo("ups.model", "%s", model);
upsdebugx(2, "Got model name: %s", model);
/* deal with truncated model names */
if (!strncmp(model, "Evolutio", 8)) {
dstate_setinfo("ups.model", "Evolution %i", atoi(strchr(model, ' ')));
} else {
dstate_setinfo("ups.model", "%s", model);
}
}
if ( firmware && strcmp(firmware, ""))
@ -328,8 +344,8 @@ void upsdrv_initinfo(void)
* information (OL, OB, LB); all else is added later by updateinfo */
status_ok = get_ups_status();
} while ( (!status_ok) && (tries++ < MAXTRIES) && (exit_flag != 0) );
} while ( (!status_ok) && (tries++ < MAXTRIES) && (exit_flag != 1) );
if ( tries == MAXTRIES && !status_ok )
fatalx(EXIT_FAILURE, "Could not get status from UPS.");
@ -398,13 +414,15 @@ void upsdrv_updateinfo(void)
/* update status */
status_ok = get_ups_status(); /* only sys status is critical */
if ( !status_ok ) {
dstate_datastale();
if ( !status_ok )
{
upslogx(LOG_NOTICE, "updateinfo: Cannot update system status");
/* try to re enable communication */
disable_ups_comm();
enable_ups_comm();
} else {
}
else
{
dstate_dataok();
}
@ -427,8 +445,8 @@ void upsdrv_updateinfo(void)
dstate_setinfo(item->type, "%s", infostr);
upsdebugx(2, "updateinfo: %s == >%s<", item->type, infostr);
dstate_dataok();
} else {
dstate_datastale();
} else
{
upslogx(LOG_NOTICE, "updateinfo: Cannot update %s", item->type);
/* try to re enable communication */
disable_ups_comm();
@ -479,17 +497,6 @@ void upsdrv_help(void)
/* Internal Functions */
/* --------------------------------------------------------------- */
/* deal with truncated model names */
void format_model_name(char *model)
{
upsdebugx(2, "Got model name: %s", model);
if(!strncmp(model, "Evolutio", 8))
sprintf(model, "Evolution %i", atoi(strchr(model, ' ')));
}
/* --------------------------------------------------------------- */
/* handler for commands to be sent to UPS */
int instcmd(const char *cmdname, const char *extra)
{