Avionics
Dropship Simulator
apcupsd.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Bus.h"
4 
5 namespace Devices
6 {
7  struct ApcupsdParam
8  {
9  std::string field;
11  std::string guid;
12  float* guidPtrFloat = nullptr;
14  };
15 
17  {
18  bool enable;
19  unsigned short port;
22  std::vector<ApcupsdParam> params;
23  std::string datadumpfile = "apcupsd.data";
24 
26  float timeToWarn = 3600.0f; // 1 hour
27  float loadPctToWarn = 14.5f; // about 1 amp
28  float elapsedToWarn = 0.0f;
29  };
30 
32  class Apcupsd
33  {
34  private:
35  int datafile = 0;
36  float timeSinceLastUpdate = 0.0f;
37 
38  SOCKET tcp = static_cast<SOCKET>(SOCKET_ERROR);
39  bool connected = false;
40  char buf[4096];
41 
42  Logger* logger = nullptr;
43  ApcupsdConfig* config = nullptr;
44  Bus* bus = nullptr;
45 
46  float* avionicsBayTemp = nullptr;
47 
48  enum cable
49  {
52  };
53 
54  enum driver
55  {
58  };
59 
60  enum upsmode
61  {
63  };
64 
65  enum status1
66  {
67  ONLINE_ = 0,
69  NoSignal = 1,
70  ONBATT_ = 2,
74  };
75 
76  enum sense
77  {
81  };
82 
83  enum selftest
84  {
86  OK,
88  BT,
90  NG,
93  };
94 
95  struct STATUS
96  {
98  char APC[13];
100  //time_t DATE;
101  char HOSTNAME[9];
103  char VERSION[34];
104 
106  char UPSNAME[9];
107 
112  time_t STARTTIME;
113  char MODEL[17];
115  float LINEV;
116  float LOADPCT;
118  float BCHARGE;
120  float TIMELEFT;
121 
123  int MBATTCHG;
125  int MINTIMEL;
127  int MAXTIME;
128 
130  float MAXLINEV;
132  float MINLINEV;
134  float OUTPUTV;
135 
139  int DWAKE;
141  int DSHUTD;
143  int DLOWBATT;
145  float LOTRANS;
147  float HITRANS;
149  float RETPCT;
151  int ALARMDEL;
152 
153  float BATTV;
154  float LINEFREQ;
156  char LASTXFER[32];
158  int NUMXFERS;
160  time_t XONBATT;
162  int TONBATT;
166  time_t XOFFBATT;
169  int STESTI;
171  char STATFLAG[23];
173  char REG1[16];
175  char REG2[16];
177  char REG3[16];
178 
180  time_t MANDATE;
182  char SERIALNO[13];
184  time_t BATTDATE;
186  int NOMOUTV;
188  float NOMBATTV;
190  char FIRMWARE[8];
192  time_t END_APC;
193 
195  char expansion[144];
196  };
197 
198  static bool ReadText(std::string, const char*, char*, size_t);
199  static bool ReadDateTime(std::string, const char*, time_t*);
200  static bool ReadDate(std::string, const char*, time_t*);
201  static bool ReadFloat(std::string, const char*, float*);
202  static bool ReadInt(std::string, const char*, int*);
203 
204  void Log(char* msg, Logger::Level level, int errorno) const;
205  void Connect();
206 
207  public:
209 
210  Apcupsd();;
212  void FrameMove(float fElapsed);
213  ~Apcupsd();
214  };
215 }
float LOTRANS
EEPROM go on battery below this voltage.
Definition: apcupsd.h:145
sense SENSE
EEPROM sense.
Definition: apcupsd.h:137
static bool ReadInt(std::string, const char *, int *)
Definition: apcupsd.cpp:100
static bool ReadDateTime(std::string, const char *, time_t *)
Definition: apcupsd.cpp:109
int MAXTIME
EEPROM maximum time on battery in seconds before shutdown.
Definition: apcupsd.h:127
int NUMXFERS
since daemon startup
Definition: apcupsd.h:158
char buf[4096]
Definition: apcupsd.h:40
int DWAKE
EEPROM wake delay in seconds.
Definition: apcupsd.h:139
time_t XONBATT
time and date since last transfer TO batteries
Definition: apcupsd.h:160
std::string field
Definition: apcupsd.h:9
time_t STARTTIME
daemon start time
Definition: apcupsd.h:112
char HOSTNAME[9]
status update timestamp
Definition: apcupsd.h:101
Definition: Logger.h:5
float * avionicsBayTemp
Definition: apcupsd.h:46
std::vector< ApcupsdParam > params
Definition: apcupsd.h:22
bool connected
Definition: apcupsd.h:39
int DLOWBATT
EEPROM The remaining runtime below which the UPS sends the low battery signal. At this point apcupsd ...
Definition: apcupsd.h:143
char FIRMWARE[8]
EEPROM.
Definition: apcupsd.h:190
okay, the portable keyboard numbers don&#39;t work like the outside keypad because the outside keypad is ...
Definition: Analog.cpp:3
self test indicates good battery
Definition: apcupsd.h:86
static bool ReadDate(std::string, const char *, time_t *)
Definition: apcupsd.cpp:131
float HITRANS
EEPROM go on battery above this voltage.
Definition: apcupsd.h:147
void Initialize(Logger *logger, ApcupsdConfig *config, Bus *bus)
Definition: apcupsd.cpp:24
No results (i.e. no self test performed in the last 5 minutes)
Definition: apcupsd.h:92
char LASTXFER[32]
The reason for the last transfer to batteries.
Definition: apcupsd.h:156
char SERIALNO[13]
EEPROM.
Definition: apcupsd.h:182
int MINTIMEL
EEPROM time remaining in minutes that triggers shutdown.
Definition: apcupsd.h:125
Definition: Bus.h:12
int STESTI
EEPROM The interval in hours between automatic self tests.
Definition: apcupsd.h:169
float MINLINEV
since last reading (apcupsd documentation is in error)
Definition: apcupsd.h:132
ApcupsdConfig * config
Definition: apcupsd.h:43
float timeToWarn
keep me from leaving display computer on again
Definition: apcupsd.h:26
float OUTPUTV
The voltage the UPS is supplying to your equipment.
Definition: apcupsd.h:134
C++ monitoring implementation of http://www.apcupsd.org.
Definition: apcupsd.h:32
std::string datadumpfile
Definition: apcupsd.h:23
time_t XOFFBATT
time and date since last transfer FROM batteries
Definition: apcupsd.h:166
Not a real APC status, reserved for compatibility across the board.
Definition: apcupsd.h:69
char UPSNAME[9]
EEPROM.
Definition: apcupsd.h:106
int CUMONBATT
cumulative time on battery (since daemon started) in seconds
Definition: apcupsd.h:164
int ALARMDEL
EEPROM The delay period for the UPS alarm.
Definition: apcupsd.h:151
Nullable< float > modulate
Definition: apcupsd.h:10
static bool ReadFloat(std::string, const char *, float *)
Definition: apcupsd.cpp:91
STATUS status
Definition: apcupsd.h:208
time_t END_APC
More accurate poll date.
Definition: apcupsd.h:192
Systems::Fault * guidPtrInt
Definition: apcupsd.h:13
time_t BATTDATE
EEPROM.
Definition: apcupsd.h:184
time_t MANDATE
EEPROM.
Definition: apcupsd.h:180
float timeSinceLastUpdate
Definition: apcupsd.h:36
void FrameMove(float fElapsed)
Definition: apcupsd.cpp:163
char APC[13]
Header record indicating the STATUS format revision level, the number of records that follow the APC ...
Definition: apcupsd.h:98
std::string guid
Definition: apcupsd.h:11
static bool ReadText(std::string, const char *, char *, size_t)
Definition: apcupsd.cpp:76
float TIMELEFT
remaining runtime in minutes
Definition: apcupsd.h:120
float BCHARGE
battery charge percentage
Definition: apcupsd.h:118
int TONBATT
time on battery this transfer seconds
Definition: apcupsd.h:162
SOCKET tcp
Definition: apcupsd.h:38
float MAXLINEV
since last reading (apcupsd documentation is in error)
Definition: apcupsd.h:130
Logger * logger
Definition: apcupsd.h:42
float RETPCT
EEPROM The percentage charge that the batteries must have after a power off condition before the UPS ...
Definition: apcupsd.h:149
char expansion[144]
padding to make the struct 512 bytes
Definition: apcupsd.h:195
int DSHUTD
EEPROM shutdown delay in seconds after getting command to shutdown.
Definition: apcupsd.h:141
Level
Definition: Logger.h:11
int NOMOUTV
EEPROM.
Definition: apcupsd.h:186
int MBATTCHG
EEPROM percent battery that triggers shutdown.
Definition: apcupsd.h:123
unsigned short port
Definition: apcupsd.h:19
float * guidPtrFloat
Definition: apcupsd.h:12
self test failed due to overload
Definition: apcupsd.h:90
char VERSION[34]
APCUPSD.
Definition: apcupsd.h:103
self test failed due to insufficient battery capacity
Definition: apcupsd.h:88
void Log(char *msg, Logger::Level level, int errorno) const
Definition: apcupsd.cpp:12
float NOMBATTV
EEPROM.
Definition: apcupsd.h:188