GitHub issues can also be used to report HCL updates
[networkupstools/kirr.git] / drivers / everups.c
blob7cd93287436fc6b43cf6748e5c6ff586cb9c81bf
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
20 #include "main.h"
21 #include "serial.h"
23 #define DRIVER_NAME "Ever UPS driver"
24 #define DRIVER_VERSION "0.03"
26 /* driver description structure */
27 upsdrv_info_t upsdrv_info = {
28 DRIVER_NAME,
29 DRIVER_VERSION,
30 "Bartek Szady <bszx@bszxdomain.edu.eu.org>",
31 DRV_STABLE,
32 { NULL }
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)
45 unsigned char cRecv;
46 do {
47 ser_send_char(upsfd, 208);
48 ser_get_char(upsfd, &cRecv, 3, 0);
49 if (cRecv==208)
50 return 1;
51 } while (--tries>0);
52 return 0;
55 static int InitUpsType(void)
57 if (Code(1)) {
58 ser_send_char(upsfd, 173);
59 ser_get_char(upsfd, &upstype, 3, 0);
60 return 1;
61 } else
62 return 0;
65 static const char *GetTypeUpsName(void)
67 switch(upstype)
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";
80 default:
81 return "Unknown";
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];
95 unsigned long acuV;
96 unsigned long lineV;
97 double fVal;
99 if (!Code(2)) {
100 upslog_with_errno(LOG_INFO, "Code failed");
101 dstate_datastale();
102 return;
104 /*Line status*/
105 ser_send_char(upsfd, 175);
106 ser_get_char(upsfd, recBuf, 3, 0);
107 if ((recBuf[0] & 1) !=0)
108 standby=1;
109 else
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;
115 acuV/=255;
116 } else {
117 upslog_with_errno(LOG_INFO, "Code failed");
118 dstate_datastale();
119 return;
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;
126 else
127 lineV=(recBuf[0]*100+recBuf[1]*25600)/372;
128 } else {
129 upslog_with_errno(LOG_INFO, "Code failed");
130 dstate_datastale();
131 return;
134 status_init();
136 if (battery && acuV<105)
137 status_set("LB"); /* low battery */
139 if (battery)
140 status_set("OB"); /* on battery */
141 else
142 status_set("OL"); /* on line */
144 status_commit();
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;
150 if (standby)
151 fVal/=(135.5-95.0);
152 else
153 fVal/=(124.5-95.0);
154 if (fVal>100)
155 fVal=100;
156 else if (fVal<0)
157 fVal=0;
159 dstate_setinfo("battery.charge", "%03.1f", fVal);
161 dstate_dataok();
164 void upsdrv_shutdown(void)
166 if (!Code(2)) {
167 upslog_with_errno(LOG_INFO, "Code failed");
168 return;
170 ser_send_char(upsfd, 28);
171 ser_send_char(upsfd, 1); /* 1.28 sec */
172 if (!Code(1)) {
173 upslog_with_errno(LOG_INFO, "Code failed");
174 return;
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);
194 init_serial();
195 InitUpsType();
198 void upsdrv_cleanup(void)
200 ser_close(upsfd, device_path);