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

« back to all changes in this revision

Viewing changes to drivers/skel.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Quette
  • Date: 2004-05-28 13:10:01 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040528131001-yj2m9qcez4ya2w14
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        anything commented is optional
 
3
        anything else is mandatory
 
4
*/
 
5
 
 
6
#include "main.h"
 
7
 
 
8
/* #define ENDCHAR      '\r'    */
 
9
/* #define IGNCHARS     ""      */
 
10
 
 
11
#define DRV_VERSION     "0.01"
 
12
 
 
13
void upsdrv_initinfo(void)
 
14
{
 
15
        dstate_setinfo("driver.version.internal", "%s", DRV_VERSION);
 
16
        /* dstate_setinfo("ups.mfr", "skel driver"); */
 
17
        /* dstate_setinfo("ups.model", "longrun 15000"); */
 
18
 
 
19
        /* upsh.instcmd = instcmd; */
 
20
}
 
21
 
 
22
void upsdrv_updateinfo(void)
 
23
{
 
24
        /* int flags; */
 
25
        /* char temp[256]; */
 
26
 
 
27
        /* upssendchar(''); */
 
28
        /* upssend(""); */
 
29
 
 
30
        /* 
 
31
         * ret = upsrecv(temp, sizeof(temp), ENDCHAR, IGNCHARS);
 
32
         *
 
33
         * if (ret < STATUS_LEN) {
 
34
         *      upslogx(LOG_ERR, "Short read from UPS");
 
35
         *      dstate_datastale();
 
36
         *      return;
 
37
         * }
 
38
         */
 
39
         */
 
40
 
 
41
        /* dstate_setinfo("var.name", ""); */
 
42
 
 
43
        /* if (ioctl(upsfd, TIOCMGET, &flags)) {
 
44
         *      upslog(LOG_ERR, "TIOCMGET");
 
45
         *      dstate_datastale();
 
46
         *      return;
 
47
         * }
 
48
         */
 
49
 
 
50
        /* status_init();
 
51
         *
 
52
         * if (ol)
 
53
         *      status_set("OL");
 
54
         * else
 
55
         *      status_set("OB");
 
56
         * ...
 
57
         *
 
58
         * status_commit();
 
59
         *
 
60
         * dstate_dataok();
 
61
         */
 
62
}
 
63
 
 
64
void upsdrv_shutdown(void)
 
65
{
 
66
        /* replace with a proper shutdown function */
 
67
        fatalx("shutdown not supported");
 
68
}
 
69
 
 
70
/*
 
71
int instcmd(const char *cmdname, const char *extra)
 
72
{
 
73
        if (!strcasecmp(cmdname, "test.battery.stop")) {
 
74
                upssend("???");
 
75
                return STAT_INSTCMD_HANDLED;
 
76
        }
 
77
 
 
78
        upslogx(LOG_NOTICE, "instcmd: unknown command [%s]", cmdname);
 
79
        return STAT_INSTCMD_UNKNOWN;
 
80
}
 
81
*/
 
82
 
 
83
void upsdrv_help(void)
 
84
{
 
85
}
 
86
 
 
87
/* list flags and values that you want to receive via -x */
 
88
void upsdrv_makevartable(void)
 
89
{
 
90
        /* allow '-x xyzzy' */
 
91
        /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */
 
92
 
 
93
        /* allow '-x foo=<some value>' */
 
94
        /* addvar(VAR_VALUE, "foo", "Override foo setting"); */
 
95
}
 
96
 
 
97
void upsdrv_banner(void)
 
98
{
 
99
        printf("Network UPS Tools - Skeleton UPS driver %s (%s)\n\n", 
 
100
                DRV_VERSION, UPS_VERSION);
 
101
}
 
102
 
 
103
void upsdrv_initups(void)
 
104
{
 
105
        /* upssend_delay = 100; */
 
106
        /* open_serial(port, B1200); */
 
107
        /* probe ups type */
 
108
 
 
109
        /* to get variables and flags from the command line, use this:
 
110
         *
 
111
         * first populate with upsdrv_buildvartable above, then...
 
112
         *
 
113
         *                   set flag foo : /bin/driver -x foo
 
114
         * set variable 'cable' to '1234' : /bin/driver -x cable=1234
 
115
         *
 
116
         * to test flag foo in your code:
 
117
         *
 
118
         *      if (testvar("foo"))
 
119
         *              do_something();
 
120
         *
 
121
         * to show the value of cable:
 
122
         *
 
123
         *      if ((cable == getval("cable")))
 
124
         *              printf("cable is set to %s\n", getval("cable"));
 
125
         *      else
 
126
         *              printf("cable is not set!\n");
 
127
         *
 
128
         * don't use NULL pointers - test the return result first!
 
129
         */
 
130
 
 
131
        /* the upsh handlers can't be done here, as they get initialized
 
132
         * shortly after upsdrv_initups returns to main.
 
133
         */
 
134
}
 
135
 
 
136
void upsdrv_cleanup(void)
 
137
{
 
138
        /* free(dynamic_mem); */
 
139
}