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

« back to all changes in this revision

Viewing changes to drivers/isbmex.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:
20
20
 
21
21
*/
22
22
 
23
 
#define DRV_VERSION "0.02"
 
23
#define DRV_VERSION "0.03"
24
24
 
25
25
#define xDEBUG
26
26
 
31
31
#endif
32
32
 
33
33
#include "main.h"
34
 
#include <math.h>
 
34
#include "serial.h"
 
35
 
 
36
#include <math.h>               /* for sqrt */
35
37
#include <string.h>
36
38
 
37
39
/*#define ENDCHAR       '&'*/
55
57
        dstate_setinfo("driver.version.internal", "%s", DRV_VERSION);
56
58
}
57
59
 
58
 
static char *getpacket(int *we_know){
 
60
static const char *getpacket(int *we_know){
59
61
  fd_set readfds;
60
62
  struct timeval tv;
61
63
  int bytes_per_packet=0;
62
64
  int ret;
63
 
  static char *packet_id=NULL;
 
65
  static const char *packet_id=NULL;
64
66
  static char buf[256];
65
 
  char *s;
 
67
  const char *s;
66
68
  ssize_t r;
67
69
 
68
70
  
78
80
  ret=select(upsfd+1,  &readfds, NULL, NULL,&tv);
79
81
  if (!ret) {
80
82
        s="Nothing received from UPS. Check cable conexion";
81
 
        upslogx(LOG_ERR, s);
 
83
        upslogx(LOG_ERR, "%s", s);
82
84
        D(printf("%s\n",s);)
83
85
        return NULL;
84
86
  }
116
118
     /* check validity of packet */
117
119
 if (!s) {
118
120
        s="isbmex: no valid packet signature!";
119
 
        upslogx(LOG_ERR, s);
 
121
        upslogx(LOG_ERR, "%s", s);
120
122
        D(printf("%s\n",s);)
121
123
        *we_know=0;
122
124
        return NULL;
123
125
 }
124
126
 D(if (s != buf) printf("overlapping packet received\n");)
125
 
 if (strlen(s) < bytes_per_packet) {
 
127
 if ((int) strlen(s) < bytes_per_packet) {
126
128
                    D(printf("incomplete packet information\n");)
127
129
                    return NULL; 
128
130
 }
138
140
void upsdrv_updateinfo(void)
139
141
{
140
142
  static  float high_volt=-1, low_volt=999;
141
 
  char  *buf=NULL,buf2[17];
 
143
  const char    *buf=NULL;
 
144
  char buf2[17];
142
145
  int i;
143
146
  static int bytes_per_packet=0;
144
147
 
242
245
/* list flags and values that you want to receive via -x */
243
246
void upsdrv_makevartable(void)
244
247
{
245
 
        /* allow '-x xyzzy' */
246
 
        /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */
247
 
 
248
 
        /* allow '-x foo=<some value>' */
249
 
        /* addvar(VAR_VALUE, "foo", "Override foo setting"); */
250
248
}
251
249
 
252
250
void upsdrv_banner(void)
257
255
 
258
256
void upsdrv_initups(void)
259
257
{
260
 
         upssend_delay = 100; 
261
 
         open_serial(device_path, B9600);
262
 
         flag_timeoutfailure = -1;
 
258
        upsfd = ser_open(device_path);
 
259
        ser_set_speed(upsfd, device_path, B2400);
263
260
}
264
261
 
265
262
void upsdrv_cleanup(void)
266
263
{
 
264
        ser_close(upsfd, device_path);
267
265
}