44
48
#define VICTRON_OB 2
45
49
#define VICTRON_LB 4
51
#define VICTRON_NO_TEST 1
52
#define VICTRON_ABORT_TEST 2
53
#define VICTRON_SYSTEM_TEST 3
54
#define VICTRON_BATTERY_TEST 4
55
#define VICTRON_CALIBRATION 5
56
#define VICTRON_BYPASS_TEST 101
47
58
#define LENGTH_TEMP 256
49
60
int sdwdelay = 0; /* shutdown after 0 second */
51
extern int sddelay; /* doba po kterou ceka driver po vypnuti ups */
52
extern char upssend_endchar;
53
extern int upsc_debug;
64
static int start_is_datastale = 1;
66
static int exist_ups_serial = 0;
67
static int exist_ups_temperature = 0;
68
static int exist_output_current = 0;
69
static int exist_battery_charge = 0;
70
static int exist_battery_current = 0;
71
static int exist_battery_temperature = 0;
72
static int exist_battery_runtime = 0;
74
static int test_in_progress = VICTRON_NO_TEST;
76
static int get_data (const char *out_string, char *in_string)
79
ser_send(upsfd, "%s%c", out_string, ENDCHAR);
81
ret_code = ser_get_line(upsfd, in_string, LENGTH_TEMP, ENDCHAR,
90
static int instcmd(const char *cmdname, const char *extra)
92
char temp[ LENGTH_TEMP ];
94
if(!strcasecmp(cmdname, "calibrate.start"))
96
if(get_data("vTi5!",temp))
98
upsdebugx(1, "instcmd: ser_send calibrate.start failed");
99
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
103
upsdebugx(1, "instcmd: calibrate.start returned: %s", temp);
104
test_in_progress = VICTRON_CALIBRATION;
105
return STAT_INSTCMD_HANDLED;
108
else if(!strcasecmp(cmdname, "calibrate.stop"))
110
if(get_data("vTi2!",temp))
112
upsdebugx(1, "instcmd: ser_send calibrate.stop failed");
113
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
117
upsdebugx(1, "instcmd: calibrate.stop returned: %s", temp);
118
return STAT_INSTCMD_HANDLED;
121
else if(!strcasecmp(cmdname, "test.battery.stop"))
123
if(get_data("vTi2!",temp))
125
upsdebugx(1, "instcmd: ser_send test.battery.stop failed");
126
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
130
upsdebugx(1, "instcmd: test.battery.stop returned: %s", temp);
131
return STAT_INSTCMD_HANDLED;
134
else if(!strcasecmp(cmdname, "test.battery.start"))
136
if(get_data("vTi4!",temp))
138
upsdebugx(1, "instcmd: ser_send test.battery.start failed");
139
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
143
upsdebugx(1, "instcmd: test.battery.start returned: %s", temp);
144
test_in_progress = VICTRON_BATTERY_TEST;
145
return STAT_INSTCMD_HANDLED;
148
else if(!strcasecmp(cmdname, "test.panel.stop"))
150
if(get_data("vTi2!",temp))
152
upsdebugx(1, "instcmd: ser_send test.panel.stop failed");
153
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
157
upsdebugx(1, "instcmd: test.panel.stop returned: %s", temp);
158
return STAT_INSTCMD_HANDLED;
161
else if(!strcasecmp(cmdname, "test.panel.start"))
163
if(get_data("vTi3!",temp))
165
upsdebugx(1, "instcmd: ser_send test.panel.start failed");
166
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
170
upsdebugx(1, "instcmd: test.panel.start returned: %s", temp);
171
test_in_progress = VICTRON_SYSTEM_TEST;
172
return STAT_INSTCMD_HANDLED;
175
else if(!strcasecmp(cmdname, "bypass.stop"))
177
if(get_data("vTi2!",temp))
179
upsdebugx(1, "instcmd: ser_send bypass.stop failed");
180
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
184
upsdebugx(1, "instcmd: bypass.stop returned: %s", temp);
185
return STAT_INSTCMD_HANDLED;
188
else if(!strcasecmp(cmdname, "bypass.start"))
190
if(get_data("vTi101!",temp))
192
upsdebugx(1, "instcmd: ser_send bypass.start failed");
193
return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */
197
upsdebugx(1, "instcmd: bypass.start returned: %s", temp);
198
test_in_progress = VICTRON_BYPASS_TEST;
199
return STAT_INSTCMD_HANDLED;
204
upsdebugx(1, "instcmd: unknown command: %s", cmdname);
205
return STAT_INSTCMD_UNKNOWN;
57
209
void upsdrv_initinfo(void)
59
212
dstate_setinfo("driver.version.internal", "%s", DRV_VERSION);
61
214
dstate_setinfo("ups.model", "%s", model_name);
65
int get_data (const char *out_string, char *in_string)
70
ret_code = upsrecv (in_string, LENGTH_TEMP, ENDCHAR, IGNCHARS);
216
upsh.instcmd = instcmd;
218
dstate_addcmd("test.battery.start");
219
dstate_addcmd("test.battery.stop");
220
dstate_addcmd("calibrate.start");
221
dstate_addcmd("calibrate.stop");
222
dstate_addcmd("test.panel.start"); /* We need a GeneralSystemTest, but use this one instead */
223
dstate_addcmd("test.panel.stop"); /* We need a GeneralSystemTest, but use this one instead */
224
dstate_addcmd("bypass.start");
225
dstate_addcmd("bypass.stop");
79
229
void upsdrv_updateinfo(void)
82
232
char temp[ LENGTH_TEMP ];
233
char test_result[ 255 ];
234
int runtime_sec = -1;
236
if (start_is_datastale)
238
if (get_data("vDS?",temp)) return;
239
if (strcmp(temp+3,"NA"))
242
if (get_data("vBT?",temp)) return;
243
if (strcmp(temp+3,"NA"))
244
exist_ups_temperature =1;
246
if (get_data("vO0I?",temp)) return;
247
if (strcmp(temp+4,"NA"))
248
exist_output_current =1;
250
if (get_data("vBC?",temp)) return;
251
if (strcmp(temp+3,"NA"))
252
exist_battery_charge = 1;
254
if (get_data("vBI?",temp)) return;
255
if (strcmp(temp+3,"NA"))
256
exist_battery_charge = 1;
258
if (get_data("vBT?",temp)) return;
259
if (strcmp(temp+3,"NA"))
260
exist_battery_temperature = 1;
262
if (get_data("vBt?",temp)) return;
263
if (strcmp(temp+3,"NA"))
264
exist_battery_runtime = 1;
266
start_is_datastale = 0;
85
273
if (get_data("vAa?",temp)) return;
86
274
flags = atoi (temp+3);
100
288
status_set("OB");
102
290
status_set("OL");
292
/* Get UPS test results */
293
if (get_data("vTr?",temp)) return;
294
if (get_data("vTd?",test_result)) return;
299
upsdebugx(1, "upsdrv_updateinfo: test %i result = Done, Passed: %s",test_in_progress,test_result+3);
300
test_in_progress = VICTRON_NO_TEST;
304
upsdebugx(1, "upsdrv_updateinfo: test %i result = Done, Warning: %s",test_in_progress,test_result+3);
305
test_in_progress = VICTRON_NO_TEST;
309
upsdebugx(1, "upsdrv_updateinfo: test %i result = Done, Error: %s",test_in_progress,test_result+3);
310
test_in_progress = VICTRON_NO_TEST;
314
upsdebugx(1, "upsdrv_updateinfo: test %i result = Aborted: %s",test_in_progress,test_result+3);
315
test_in_progress = VICTRON_NO_TEST;
319
if(test_in_progress==VICTRON_CALIBRATION)
320
status_set("CAL"); /* calibration in progress*/
321
upsdebugx(1, "upsdrv_updateinfo: test %i result = In Progress: %s",
322
test_in_progress,test_result+3);
326
upsdebugx(1, "upsdrv_updateinfo: test result = No test initiated: %s",
331
upsdebugx(1, "upsdrv_updateinfo: unknown test result: %s / %s",temp+3,test_result+3);
105
336
/* dstate_dataok(); */
107
upsdebugx(1, "ups.status = %s\n", dstate_getinfo("ups.status"));
338
upsdebugx(1, "upsdrv_updateinfo: ups.status = %s\n", dstate_getinfo("ups.status"));
110
341
/************** ups.x ***************************/
221
460
/* battery.current */
222
if (get_data("vBI?",temp)) return;
223
if (strcmp(temp+3,"NA"))
461
if (exist_battery_current)
463
if (get_data("vBI?",temp)) return;
224
464
dstate_setinfo("battery.current", "%2.1f", atof(temp+3) / 10.0);
225
466
upsdebugx(1, "battery.current >%s<>%s<\n",temp,temp+3);
227
468
/* battery.temperature */
228
if (get_data("vBT?",temp)) return;
229
if (strcmp(temp+3,"NA"))
469
if (exist_battery_temperature)
471
if (get_data("vBT?",temp)) return;
230
472
dstate_setinfo("battery.temperature", "%s", temp+3);
231
474
upsdebugx(1, "battery.temperature >%s<>%s<\n",temp,temp+3);
233
477
/* battery.runtime */
234
if (get_data("vBt?",temp)) return;
235
if (strcmp(temp+3,"NA"))
236
dstate_setinfo("battery.runtime", "%s", temp+3);
237
upsdebugx(1, "battery.runtime >%s<>%s<\n",temp,temp+3);
478
if (exist_battery_runtime)
480
if (get_data("vBt?",temp)) return;
481
runtime_sec = strtol(temp+3, NULL, 10)*60;
482
snprintf(temp, sizeof(temp), "%d", runtime_sec);
483
dstate_setinfo("battery.runtime", "%s", temp);
485
upsdebugx(1, "battery.runtime >%s<>%d<\n",temp,runtime_sec);
242
490
void upsdrv_shutdown(void)
247
upssend ("vCb%i!",sdwdelay);
251
void instcmd (int auxcmd, int dlen, char *data)
253
/* TODO: reply to upsd? */
256
/* case test.battery.stop: * stop battery test *
259
* case test.battery.start: * start battery test *
262
* case calibrate.stop: * stop calibration *
265
* case calibrate.start: * start calibration *
270
upslogx(LOG_INFO, "instcmd: unknown type 0x%04x", auxcmd);
492
ser_send(upsfd, "vCc0!%c", ENDCHAR);
495
ser_send(upsfd, "vCb%i!%c", sdwdelay, ENDCHAR);
275
498
void upsdrv_help(void)
310
531
/* inicializace a synchronizace UPS */
312
upssendchar (ENDCHAR);
313
usleep (UPS_LONG_DELAY);
315
usleep (UPS_LONG_DELAY);
316
upsrecv (temp, sizeof(temp), ENDCHAR, IGNCHARS);
318
usleep (UPS_LONG_DELAY);
319
upsrecv (temp, sizeof(temp), ENDCHAR, IGNCHARS);
533
ser_send_char(upsfd, ENDCHAR);
534
usleep (UPS_LONG_DELAY);
535
ser_send(upsfd, "?%c", ENDCHAR);
536
usleep (UPS_LONG_DELAY);
537
ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, 3, 0);
538
ser_send(upsfd, "?%c", ENDCHAR);
539
usleep (UPS_LONG_DELAY);
540
ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, 3, 0);
541
ser_send(upsfd, "?%c", ENDCHAR);
321
542
usleep (UPS_DELAY);
322
upsrecv (temp, sizeof(temp), ENDCHAR, IGNCHARS);
543
ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, 3, 0);
325
546
/* the upsh handlers can't be done here, as they get initialized