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

« back to all changes in this revision

Viewing changes to drivers/powercom.h

  • 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
 * powercom.h - defines for the newpowercom.c driver
 
3
 *
 
4
 * Read docs/powercom.txt for other models and manufactures
 
5
 *
 
6
 * $Id: - will be filled in on next CVS add/update $
 
7
 *
 
8
 * Copyrights:
 
9
 * (C) 2002 Simon Rozman <simon@rozman.net>
 
10
 *  Added support for Egys
 
11
 *
 
12
 * (C) 2001 Peter Bieringer <pb@bieringer.de>
 
13
 *  Porting old style "powercom" to new style "newpowercom", cleanup header file
 
14
 *
 
15
 * (C) 2000  Shaul Karl <shaulk@israsrv.net.il>
 
16
 *  Creating old style "powercom"
 
17
 *   Heavily based on
 
18
 *    ups-trust425+625.c - model specific routines for Trust UPS 425/625
 
19
 *    Copyright (C) 1999  Peter Bieringer <pb@bieringer.de>
 
20
 *
 
21
 * This program is free software; you can redistribute it and/or modify
 
22
 * it under the terms of the GNU General Public License as published by
 
23
 * the Free Software Foundation; either version 2 of the License, or
 
24
 * (at your option) any later version.
 
25
 *
 
26
 * This program is distributed in the hope that it will be useful,
 
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
29
 * GNU General Public License for more details.
 
30
 *
 
31
 * You should have received a copy of the GNU General Public License
 
32
 * along with this program; if not, write to the Free Software
 
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
34
 *
 
35
 * Changes
 
36
 * 20011208/PB: add support for subtypes
 
37
 * 20020629/SR: add support for calc. parameters
 
38
 * 20020701/SK: subtypes as structures
 
39
 * 20030506/SK: replaced the previous validation method with
 
40
 *              validation_byte[] and replaced subtype by type.
 
41
 */
 
42
 
 
43
/* C-libary includes */
 
44
#include <sys/file.h>
 
45
#include <sys/stat.h>
 
46
#include <sys/ioctl.h>
 
47
#include <sys/types.h>
 
48
#include <sys/termios.h>
 
49
#include <limits.h>
 
50
 
 
51
/* nut includes */
 
52
#include "timehead.h"
 
53
#include "shared-tables.h"
 
54
 
 
55
/* general constants */
 
56
enum general {
 
57
        SEC_FOR_POWERKILL         = 10U,
 
58
        MAX_NUM_OF_BYTES_FROM_UPS = 16U,
 
59
};
 
60
 
 
61
/* values for sending to UPS */
 
62
enum commands {
 
63
        SEND_DATA    = '\x01',
 
64
        BATTERY_TEST = '\x03',
 
65
        SHUTDOWN     = '\xbc',
 
66
};
 
67
 
 
68
/* location of data in received string */
 
69
enum data {
 
70
        UPS_LOAD         = 0U,
 
71
        BATTERY_CHARGE   = 1U,
 
72
        INPUT_VOLTAGE    = 2U,
 
73
        OUTPUT_VOLTAGE   = 3U,
 
74
        INPUT_FREQUENCY  = 4U,
 
75
        OUTPUT_FREQUENCY = 6U,
 
76
};
 
77
 
 
78
/* status bits */
 
79
enum status {
 
80
        SUMMARY       = 0U,
 
81
        MAINS_FAILURE = 1U,
 
82
        LOW_BAT       = 2U, 
 
83
        BAD_BAT       = 2U,
 
84
        TEST          = 4U,
 
85
        AVR_ON        = 8U,
 
86
        OVERLOAD      = 32U,
 
87
        OFF           = 128U,
 
88
        STATUS_A      = 9U,
 
89
        STATUS_B      = 10U,
 
90
};
 
91
 
 
92
/* supported types */
 
93
struct type {
 
94
        char          *name;
 
95
        unsigned char num_of_bytes_from_ups;
 
96
        void          (*setup_flow_control)(void);
 
97
        
 
98
        struct validation_byte {
 
99
            unsigned char index_of_byte, required_value;
 
100
            /* An example might explain the intention better then prose.
 
101
             * Suppose we want to validate the data with:
 
102
             *     powercom_raw_data[5] == 0x80
 
103
             * then we will set index_of_byte to 5 and required_value to
 
104
             * 0x80: { 5, 0x80 }.
 
105
             */
 
106
        } validation[3];
 
107
        /* The validation array is of length 3 because 3 is longest 
 
108
         * validation sequence for any type.
 
109
         */
 
110
        
 
111
        /* parameters to calculate input and output freq., one pair for each
 
112
         * type:
 
113
         *  Each pair defines parameters for 1/(A*x+B) to calculate freq.
 
114
         *  from raw data
 
115
         */
 
116
        float         freq[2];
 
117
        
 
118
        /* parameters to calculate load %, two pairs for each type:
 
119
         *  First pair defines the parameters for A*x+B to calculate load
 
120
         *  from raw data when offline and the second pair is used when
 
121
         *  online
 
122
         */
 
123
        float         loadpct[4];
 
124
        
 
125
        /* parameters to calculate battery %, five parameters for each type:
 
126
         *  First three params defines the parameters for A*x+B*y+C to calculate
 
127
         *  battery % (x is raw data, y is load %) when offline.
 
128
         *  Fourth and fifth parameters are used to calculate D*y+E when online.
 
129
         */
 
130
        float         battpct[5];
 
131
 
 
132
        /* parameters to calculate utility and output voltage, two pairs for
 
133
         * each type:
 
134
         *  First pair defines the parameters for A*x+B to calculate utility
 
135
         *  from raw data when line voltage is >=220 and the second pair
 
136
         *  is used otherwise.
 
137
         */
 
138
        float         voltage[4];
 
139
};