15 sprintf_s(newmsg, 99,
"Apcupsd::%s", msg);
34 avionicsBayTemp =
bus->GetComponentCurrentStatePtr(
"721D4FC2-F13E-47B3-9A21-B7FE9A1C677C");
37 if (WSAStartup(MAKEWORD(2, 2), &data) != 0)
50 sprintf_s(msg, 99,
"Problem opening the UPS data log: %s",
config->
datadumpfile.c_str());
58 sprintf_s(msg, 199,
"MM-DD-YYYY,HH:MM,Status,LineV,Load%%,Batt%%,MinRm,MaxiV,MiniV,CurrV,BatV,Freq,CTOB,TTOB ,TempC\n");
76 bool Apcupsd::ReadText(std::string str,
const char* pattern,
char* output,
size_t outputsize)
78 size_t location = str.find(pattern, 0);
79 if (location == std::string::npos)
86 sscanf_s(&str[location],
"%[^\n]", output, outputsize);
93 size_t location = str.find(pattern, 0);
94 if (location == std::string::npos)
return false;
96 sscanf_s(&str[location],
"%f", retval);
102 size_t location = str.find(pattern, 0);
103 if (location == std::string::npos)
return false;
105 sscanf_s(&str[location],
"%d", retval);
111 size_t location = str.find(pattern, 0);
112 if (location == std::string::npos)
return false;
117 memset(&Tm, 0,
sizeof(Tm));
118 sscanf_s(&str[location],
"%d-%d-%d %d:%d:%d %d", &Tm.tm_year, &Tm.tm_mon, &Tm.tm_mday, &Tm.tm_hour, &Tm.tm_min, &Tm.tm_sec, &tz);
123 time_t newTime = mktime(&Tm);
124 if (newTime == -1)
return false;
133 size_t location = str.find(pattern, 0);
134 if (location == std::string::npos)
return false;
139 memset(&Tm, 0,
sizeof(Tm));
141 if (sscanf_s(&str[location],
"%d/%d/%d", &Tm.tm_mon, &Tm.tm_mday, &Tm.tm_year) == 3)
170 char bytes[8] = { 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73 };
171 if (send(
tcp, bytes, 8, 0) == SOCKET_ERROR)
173 int wsaerror = WSAGetLastError();
175 sprintf_s(msg, 99,
"FrameMove Send failed (error %i)", wsaerror);
178 if (wsaerror == WSAECONNABORTED || wsaerror == WSAECONNRESET)
182 Log(
"FrameMove Closing socket...");
183 if (closesocket(
tcp) == SOCKET_ERROR)
185 sprintf_s(msg, 99,
"FrameMove closesocket failed (error %i)", WSAGetLastError());
195 Log(
"FrameMove Error not handled here...");
202 unsigned long bytesWaiting = 0;
203 if (
connected && !ioctlsocket(
tcp, FIONREAD, &bytesWaiting) && bytesWaiting > 0)
205 int recvlen = recv(
tcp,
buf,
sizeof(
buf), 0);
206 if (recvlen == SOCKET_ERROR)
209 sprintf_s(msg, 99,
"FrameMove Recv failed (error %i)", WSAGetLastError());
212 else if (recvlen >= 4096)
215 sprintf_s(msg, 99,
"FrameMove Recv got too big a packet (size %i)", bytesWaiting);
222 for (
int i = 0; i < recvlen; i++)
249 if (_strcmpi(tmp,
"Custom Cable Smart") == 0)
251 else if (_strcmpi(tmp,
"USB Cable") == 0)
256 sprintf_s(errmsg, 99,
"Unrecognized cable enum: %s", tmp);
263 if (_strcmpi(tmp,
"APC Smart UPS (any)") == 0)
265 else if (_strcmpi(tmp,
"USB UPS Driver") == 0)
270 sprintf_s(errmsg, 99,
"Unrecognized driver enum: %s", tmp);
277 if (_strcmpi(tmp,
"Stand Alone") == 0)
282 sprintf_s(errmsg, 99,
"Unrecognized UPS mode enum: %s", tmp);
292 if (_strcmpi(tmp,
"ONLINE ") == 0)
294 else if (_strcmpi(tmp,
"ONBATT ") == 0)
296 else if (_strcmpi(tmp,
"BOOST ONLINE ") == 0)
298 else if (_strcmpi(tmp,
"CAL ONBATT ") == 0)
300 else if (_strcmpi(tmp,
"ONLINE LOWBATT ") == 0)
305 sprintf_s(errmsg, 99,
"Unrecognized UPS status1 enum: %s", tmp);
323 if (_strcmpi(tmp,
"High") == 0)
325 else if (_strcmpi(tmp,
"Medium") == 0)
327 else if (_strcmpi(tmp,
"Low") == 0)
332 sprintf_s(errmsg, 99,
"Unrecognized UPS sense enum: %s", tmp);
353 if (
ReadText(
buf,
"SELFTEST : ", tmp,
sizeof(tmp)))
355 if (_strcmpi(tmp,
"OK") == 0)
357 else if (_strcmpi(tmp,
"BT") == 0)
359 else if (_strcmpi(tmp,
"NG") == 0)
361 else if (_strcmpi(tmp,
"NO") == 0)
366 sprintf_s(errmsg, 99,
"Unrecognized UPS selftest enum: %s", tmp);
455 sprintf_s(stat, 7,
"VBOOST");
457 sprintf_s(stat, 7,
"ONBATT");
459 sprintf_s(stat, 7,
"ONLINE");
461 sprintf_s(stat, 7,
"RUNCAL");
463 sprintf_s(stat, 7,
"LOWBAT");
465 sprintf_s(dataline, 999,
467 "%02i-%02i-%04i,%02i:%02i,%s,%5.1f,%5.1f,%5.1f,%5.1f,%5.1f,%5.1f,%5.1f,%4.1f,%4.1f,%4i,%5i,%5.1f\n",
468 tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min,
469 stat,
status.
LINEV,
status.
LOADPCT,
status.
BCHARGE,
status.
TIMELEFT,
status.
MAXLINEV,
status.
MINLINEV,
status.
OUTPUTV,
status.
BATTV,
status.
LINEFREQ,
status.
TONBATT,
status.
CUMONBATT,
471 _write(
datafile, dataline, strlen(dataline));
475 logger->
Log(
"apcupsd::FrameMove Less than 5 minutes remaining on battery, shutting down!",
Logger::Warn);
476 system(
"shutdown -s -f");
477 logger->
Log(
"apcupsd::FrameMove Less than 5 minutes remaining on battery, shutting down!",
Logger::Fatal);
508 command.
name =
"SendEmail";
509 sprintf_s(command.
svalue, 64,
"Display computer ON?");
519 Log(
"Connecting...");
521 tcp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
522 if (
tcp == INVALID_SOCKET)
525 sprintf_s(msg, 99,
"Initialize Cannot create socket (error %i)", WSAGetLastError());
531 struct sockaddr_in myaddr;
532 memset(reinterpret_cast<char *>(&myaddr), 0,
sizeof(myaddr));
533 myaddr.sin_family = AF_INET;
534 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
537 if (connect(
tcp, reinterpret_cast<struct sockaddr *>(&myaddr),
sizeof(myaddr)) == SOCKET_ERROR)
540 sprintf_s(msg, 99,
"Connect Connect failed (error %i)", WSAGetLastError());
542 if (WSAGetLastError() == WSAEISCONN)
float LOTRANS
EEPROM go on battery below this voltage.
static bool ReadInt(std::string, const char *, int *)
static bool ReadDateTime(std::string, const char *, time_t *)
int MAXTIME
EEPROM maximum time on battery in seconds before shutdown.
int NUMXFERS
since daemon startup
int DWAKE
EEPROM wake delay in seconds.
time_t XONBATT
time and date since last transfer TO batteries
time_t STARTTIME
daemon start time
std::vector< Command > commandStream
char HOSTNAME[9]
status update timestamp
std::vector< ApcupsdParam > params
Systems::Fault * GetComponentFaultStatePtr(std::string guidStr)
int DLOWBATT
EEPROM The remaining runtime below which the UPS sends the low battery signal. At this point apcupsd ...
okay, the portable keyboard numbers don't work like the outside keypad because the outside keypad is ...
static bool ReadDate(std::string, const char *, time_t *)
float HITRANS
EEPROM go on battery above this voltage.
void Initialize(Logger *logger, ApcupsdConfig *config, Bus *bus)
char LASTXFER[32]
The reason for the last transfer to batteries.
int MINTIMEL
EEPROM time remaining in minutes that triggers shutdown.
std::string name
command name
int STESTI
EEPROM The interval in hours between automatic self tests.
float MINLINEV
since last reading (apcupsd documentation is in error)
float timeToWarn
keep me from leaving display computer on again
float OUTPUTV
The voltage the UPS is supplying to your equipment.
time_t XOFFBATT
time and date since last transfer FROM batteries
int CUMONBATT
cumulative time on battery (since daemon started) in seconds
int ALARMDEL
EEPROM The delay period for the UPS alarm.
static bool ReadFloat(std::string, const char *, float *)
time_t END_APC
More accurate poll date.
float timeSinceLastUpdate
void FrameMove(float fElapsed)
char APC[13]
Header record indicating the STATUS format revision level, the number of records that follow the APC ...
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
static bool ReadText(std::string, const char *, char *, size_t)
float TIMELEFT
remaining runtime in minutes
float BCHARGE
battery charge percentage
int TONBATT
time on battery this transfer seconds
float MAXLINEV
since last reading (apcupsd documentation is in error)
float RETPCT
EEPROM The percentage charge that the batteries must have after a power off condition before the UPS ...
float * GetComponentSetStatePtr(std::string guidStr)
char expansion[144]
padding to make the struct 512 bytes
int DSHUTD
EEPROM shutdown delay in seconds after getting command to shutdown.
int MBATTCHG
EEPROM percent battery that triggers shutdown.
void Log(char *msg, Logger::Level level, int errorno) const