~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to drivers/everups.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-07-20 19:48:50 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050720194850-oo61wjr33rrx2mre
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
19
19
 
20
20
#include "main.h"
 
21
#include "serial.h"
21
22
#include <sys/ioctl.h>
22
23
 
23
 
 
24
 
        unsigned char   upstype = 0;
25
 
 
26
 
void init_serial(void)
 
24
#define DRV_VERSION "0.02"
 
25
 
 
26
 
 
27
static  unsigned char   upstype = 0;
 
28
 
 
29
static void init_serial(void)
27
30
{
28
31
        int     clr_bit = TIOCM_DTR | TIOCM_RTS;
29
32
        ioctl(upsfd, TIOCMBIC, &clr_bit);
30
33
}
31
34
 
32
 
int Code(int tries)
 
35
static int Code(int tries)
33
36
{
34
37
        unsigned char cRecv;
35
38
        do {
36
 
                upssendchar(208);
37
 
                upsrecvchars((char*) &cRecv,1);
 
39
                ser_send_char(upsfd, 208);
 
40
                ser_get_char(upsfd, &cRecv, 3, 0);
38
41
                if (cRecv==208)
39
42
                        return 1;
40
43
        } while (--tries>0);
41
44
        return 0;
42
45
}
43
46
 
44
 
int InitUpsType()
 
47
static int InitUpsType(void)
45
48
{
46
49
        if (Code(1)) {
47
 
                upssendchar(173);
48
 
                upsrecvchars((char*) &upstype,1);
 
50
                ser_send_char(upsfd, 173);
 
51
                ser_get_char(upsfd, &upstype, 3, 0);
49
52
                return 1;
50
53
        } else
51
54
                return 0;
52
55
}
53
56
 
54
 
char *GetTypeUpsName()
 
57
static const char *GetTypeUpsName(void)
55
58
{
56
59
        switch(upstype)
57
60
        {
60
63
                case 69: return "NET 1000-DPC";
61
64
                case 70: return "NET 1400-DPC";
62
65
                case 71: return "NET 2200-DPC";
 
66
                case 73: return "NET 700-DPC (new)";
 
67
                case 74: return "NET 1000-DPC (new)";
 
68
                case 75: return "NET 1400-DPC (new)";
 
69
                case 76: return "NET 500-DPC (new)";
63
70
                case 81: return "AP 450-PRO";
64
71
                case 82: return "AP 650-PRO";
65
72
                default:
87
94
                return;
88
95
        }
89
96
        /*Line status*/
90
 
        upssendchar(175);
91
 
        upsrecvchars((char*)recBuf,1);
 
97
        ser_send_char(upsfd, 175);
 
98
        ser_get_char(upsfd, recBuf, 3, 0);
92
99
        if ((recBuf[0] & 1) !=0)
93
100
                standby=1;
94
101
        else 
95
102
                battery=(recBuf[0] &4) !=0;
96
103
        if (Code(1)) {  /*Accumulator voltage value*/
97
 
                upssendchar(189);
98
 
                upsrecvchars((char*)recBuf,1);
 
104
                ser_send_char(upsfd, 189);
 
105
                ser_get_char(upsfd, recBuf, 3, 0);
99
106
                acuV=((unsigned long)recBuf[0])*150;
100
107
                acuV/=255;
101
108
        } else {
104
111
                return;
105
112
        }
106
113
        if (Code(1)) {  /*Line voltage*/
107
 
                upssendchar(245);
108
 
                upsrecvchars((char*) recBuf,2);
109
 
                lineV=(recBuf[0]*100+recBuf[1]*25600)/372;
 
114
                ser_send_char(upsfd, 245);
 
115
                ser_get_buf_len(upsfd, recBuf, 2, 3, 0);
 
116
                if ( upstype > 72 && upstype < 77)
 
117
                        lineV=(recBuf[0]*100+recBuf[1]*25600)/352;
 
118
                else
 
119
                        lineV=(recBuf[0]*100+recBuf[1]*25600)/372;
110
120
        } else {
111
121
                upslog(LOG_INFO, "Code failed");
112
122
                dstate_datastale();
149
159
                upslogx(LOG_INFO, "Code failed: %m\n");
150
160
                return;
151
161
        }
152
 
        upssendchar(28);
153
 
        upssendchar(1);  /* 1.28 sec */
 
162
        ser_send_char(upsfd, 28);
 
163
        ser_send_char(upsfd, 1);  /* 1.28 sec */
154
164
        if (!Code(1)) {
155
165
                upslogx(LOG_INFO, "Code failed: %m\n");
156
166
                return;
157
167
        }
158
 
        upssendchar(13);
159
 
        upssendchar(8);
 
168
        ser_send_char(upsfd, 13);
 
169
        ser_send_char(upsfd, 8);
160
170
}
161
171
 
162
172
void upsdrv_help(void)
166
176
/* list flags and values that you want to receive via -x */
167
177
void upsdrv_makevartable(void)
168
178
{
169
 
        /* allow '-x xyzzy' */
170
 
        /* addvar(ARG_FLAG, "xyzzy", "Enable xyzzy mode"); */
171
 
 
172
 
        /* allow '-x foo=<some value>' */
173
 
        /* addvar(ARG_VALUE, "foo", "Override foo setting"); */
174
179
}
175
180
 
176
181
void upsdrv_banner(void)
177
182
{
178
 
        printf("Network UPS Tools - Ever UPS driver 0.01 (%s)\n\n", UPS_VERSION);
 
183
        printf("Network UPS Tools - Ever UPS driver %s (%s)\n\n", 
 
184
                DRV_VERSION, UPS_VERSION);
179
185
}
180
186
 
181
187
void upsdrv_initups(void)
182
188
{
183
 
        open_serial (device_path,B300);
 
189
        upsfd = ser_open(device_path);
 
190
        ser_set_speed(upsfd, device_path, B300);
 
191
 
184
192
        init_serial();
185
193
        InitUpsType();
186
194
}
187
195
 
188
196
void upsdrv_cleanup(void)
189
197
{
 
198
        ser_close(upsfd, device_path);
190
199
}