1
/* everups.c - support for Ever UPS models
3
Copyright (C) 2001 Bartek Szady <bszx@bszxdomain.edu.eu.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#define DRIVER_NAME "Ever UPS driver"
24
#define DRIVER_VERSION "0.03"
26
/* driver description structure */
27
upsdrv_info_t upsdrv_info = {
30
"Bartek Szady <bszx@bszxdomain.edu.eu.org>",
35
static unsigned char upstype = 0;
37
static void init_serial(void)
39
ser_set_dtr(upsfd, 0);
40
ser_set_rts(upsfd, 0);
43
static int Code(int tries)
47
ser_send_char(upsfd, 208);
48
ser_get_char(upsfd, &cRecv, 3, 0);
55
static int InitUpsType(void)
58
ser_send_char(upsfd, 173);
59
ser_get_char(upsfd, &upstype, 3, 0);
65
static const char *GetTypeUpsName(void)
69
case 67: return "NET 500-DPC";
70
case 68: return "NET 700-DPC";
71
case 69: return "NET 1000-DPC";
72
case 70: return "NET 1400-DPC";
73
case 71: return "NET 2200-DPC";
74
case 73: return "NET 700-DPC (new)";
75
case 74: return "NET 1000-DPC (new)";
76
case 75: return "NET 1400-DPC (new)";
77
case 76: return "NET 500-DPC (new)";
78
case 81: return "AP 450-PRO";
79
case 82: return "AP 650-PRO";
85
void upsdrv_initinfo(void)
87
dstate_setinfo("ups.mfr", "Ever");
88
dstate_setinfo("ups.model", "%s", GetTypeUpsName());
91
void upsdrv_updateinfo(void)
93
int battery=0,standby=0;
94
unsigned char recBuf[2];
100
upslog_with_errno(LOG_INFO, "Code failed");
105
ser_send_char(upsfd, 175);
106
ser_get_char(upsfd, recBuf, 3, 0);
107
if ((recBuf[0] & 1) !=0)
110
battery=(recBuf[0] &4) !=0;
111
if (Code(1)) { /*Accumulator voltage value*/
112
ser_send_char(upsfd, 189);
113
ser_get_char(upsfd, recBuf, 3, 0);
114
acuV=((unsigned long)recBuf[0])*150;
117
upslog_with_errno(LOG_INFO, "Code failed");
121
if (Code(1)) { /*Line voltage*/
122
ser_send_char(upsfd, 245);
123
ser_get_buf_len(upsfd, recBuf, 2, 3, 0);
124
if ( upstype > 72 && upstype < 77)
125
lineV=(recBuf[0]*100+recBuf[1]*25600)/352;
127
lineV=(recBuf[0]*100+recBuf[1]*25600)/372;
129
upslog_with_errno(LOG_INFO, "Code failed");
136
if (battery && acuV<105)
137
status_set("LB"); /* low battery */
140
status_set("OB"); /* on battery */
142
status_set("OL"); /* on line */
146
dstate_setinfo("input.voltage", "%03ld", lineV);
147
dstate_setinfo("battery.voltage", "%03.2f", (double)acuV /10.0);
149
fVal=((double)acuV-95.0)*100.0;
159
dstate_setinfo("battery.charge", "%03.1f", fVal);
164
void upsdrv_shutdown(void)
167
upslog_with_errno(LOG_INFO, "Code failed");
170
ser_send_char(upsfd, 28);
171
ser_send_char(upsfd, 1); /* 1.28 sec */
173
upslog_with_errno(LOG_INFO, "Code failed");
176
ser_send_char(upsfd, 13);
177
ser_send_char(upsfd, 8);
180
void upsdrv_help(void)
184
/* list flags and values that you want to receive via -x */
185
void upsdrv_makevartable(void)
189
void upsdrv_initups(void)
191
upsfd = ser_open(device_path);
192
ser_set_speed(upsfd, device_path, B300);
198
void upsdrv_cleanup(void)
200
ser_close(upsfd, device_path);