Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2524 lines
70 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * pcy29Nov92: Used new defines from codes.h to fix 32 char name limit
  7. * jod28Jan93: Added new Pollparams to support the Q command
  8. * pcy02Jan93: Made sure all functions return values
  9. * ane03Feb93: Added destructors
  10. * pcy16Feb93: Move UPS_STATE_SET define to err.h to avoid conflicts
  11. * pcy16Feb93: Correctly declare static class member thePollSet
  12. * pcy16Feb93: Fix handling of UPS_STATE_SET so UpsState params are pollable
  13. * pcy16Feb93: Fix Q command handling so all bits generate events
  14. * pcy16Feb93: Put codes for battery test results in response
  15. * pcy16Feb93: Convert run time remaining to seconds
  16. * jod05Apr93: Added changes for Deep Discharge
  17. * jod14May93: Added Matrix changes.
  18. * pcy21May93: Moved define of NO_RECENT_TEST to codes.h
  19. * cad10Jun93: Added mups parms, fixed pontential bugs
  20. * cad23Jun93: made sure state was known-sized type
  21. * pcy15Sep93: Change dipswitch value from hex to int before returning
  22. * pcy24Sep93: Convert upslink responses to 9 command to codes
  23. * cad07Oct93: Plugging Memory Leaks
  24. * ajr17Feb94: Added some checking to see if getValue returns NULL
  25. * ajr09Mar94: Added some checking to see if getValue returns NULL
  26. * ajr20Jul94: Made sure we cleared eepromValues between usages. prevent core
  27. * jps28aug94: shorten EepromAllowedValues and BattCalibrationCond to prevent
  28. * link problems in os2 1.3
  29. * djs14Jun95: Added additional event to Smart Boost Off condition.
  30. * djs22Feb96: Added Smart Trim and IncrementPollParm
  31. * djs07May96: Added Dark Star parameters
  32. * pav22May96: Added init of DS statics, aded INT as return value of DS IsPollSet
  33. * srt23May96: Checking return of sscanf in EepromAllowedValuesPollParam::ProcessValue
  34. * tjg03Dec97: 1. Updated ModuleCountsandStatusPollParam (and all inherited
  35. * pollparams) to check for NA response before processing.
  36. * 2. Revamped AbnormalConditionPollParam to ensure it generates
  37. * all possible events.
  38. * 3. Added CurrentLoadCapabilityPollParam
  39. * 4. Updated RimInstallationStatusPollParam to report PC+ code
  40. * RIM_INSTALLED/RIM_NOT_INSTALLED instead of Y/N.
  41. * tjg02Mar98: BATTERY_DOESNT_NEED_REPLACING is now reported for each poll
  42. * mds31Jul98: In NullTest(), check value before performing a strlen on it
  43. * mholly12May1999: add TurnOffSmartModePollParam support
  44. *
  45. * v-stebe 29Jul2000 Fixed PREfix errors (bugs #46337-#46341, #112598-#112609)
  46. * v-stebe 05Sep2000 Fixed additional PREfix errors
  47. */
  48. #define INCL_BASE
  49. #define INCL_NOPM
  50. #include "cdefine.h"
  51. extern "C" {
  52. #include <string.h>
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. }
  56. #include "_defs.h"
  57. #include "apc.h"
  58. #include "ulinkdef.h"
  59. #include "list.h"
  60. #include "pollparm.h"
  61. #include "codes.h"
  62. #include "event.h"
  63. #include "utils.h"
  64. #include "err.h"
  65. // Static member of UPSStatePollParam initialization
  66. USHORT UPSStatePollParam::thePollSet = 0;
  67. USHORT StateRegisterPollParam::thePollSet = 0;
  68. USHORT TripRegisterPollParam::thePollSet = 0;
  69. USHORT Trip1RegisterPollParam::thePollSet = 0;
  70. USHORT AbnormalCondPollParam::thePollSet = 0;
  71. USHORT ModuleCountsStatusPollParam::thePollSet = 0;
  72. USHORT InputVoltageFrequencyPollParam::thePollSet = 0;
  73. USHORT OutputVoltageCurrentsPollParam::thePollSet = 0;
  74. PollParam :: PollParam(INT id, CHAR* query, INT time, INT poll, Type type)
  75. : Command(NULL), ID(id), SetType(type), RequestTime(time), Pollable(poll)
  76. {
  77. if (Command)
  78. {
  79. free(Command);
  80. Command = NULL;
  81. }
  82. if (query)
  83. {
  84. Command = _strdup(query);
  85. }
  86. else
  87. {
  88. Command = (CHAR*)NULL;
  89. }
  90. }
  91. PollParam::~PollParam()
  92. {
  93. if (Command) free(Command);
  94. }
  95. CHAR* PollParam:: Query()
  96. {
  97. if (Command)
  98. return _strdup(Command);
  99. return (CHAR*)NULL;
  100. }
  101. INT PollParam:: Equal(RObj comp) const
  102. {
  103. RPollParam item = (RPollParam)comp;
  104. if ( ID == item.GetID() )
  105. return TRUE;
  106. return FALSE;
  107. }
  108. INT SmartPollParam::ResponseLength()
  109. {
  110. return theResponseLength;
  111. }
  112. INT SmartPollParam::ProcessValue(PMessage value, PList eventList)
  113. {
  114. INT rval = ErrBAD_RESPONSE_VALUE;
  115. PCHAR response = value->getResponse();
  116. if (response) {
  117. if ((ResponseLength() == VARIABLE_LENGTH_RESPONSE) ||
  118. (strlen(response) == (size_t) ResponseLength()))
  119. rval=ErrNO_ERROR;
  120. }
  121. return rval;
  122. }
  123. INT SmartPollParam :: NullTest(CHAR* value)
  124. {
  125. if (value || strlen(value))
  126. return FALSE;
  127. return TRUE;
  128. }
  129. INT UPSStatePollParam:: IsPollSet()
  130. {
  131. if (!thePollSet)
  132. {
  133. thePollSet = TRUE;
  134. return ErrUPS_STATE_SET;
  135. }
  136. return ErrSAME_VALUE;
  137. }
  138. INT UPSStatePollParam:: ProcessValue(PMessage value, List* events)
  139. {
  140. int err = ErrCONTINUE;
  141. if ( NullTest(value->getResponse()) )
  142. return ErrREAD_FAILED;
  143. if (!events) {
  144. return ErrNO_VALUE;
  145. }
  146. USHORT cur_state = 0;
  147. if (sscanf(value->getResponse(),"%x",&cur_state) == EOF) {
  148. return ErrREAD_FAILED;
  149. }
  150. INT battery_calibration_in_progress = FALSE;
  151. if ( BATTERYCALIBRATIONMASK & cur_state)
  152. {
  153. PEvent tmp = new Event(BATTERY_CALIBRATION_CONDITION,
  154. BATTERY_CALIBRATION_IN_PROGRESS);
  155. battery_calibration_in_progress = TRUE;
  156. events->Append(tmp);
  157. }
  158. else if (BATTERYCALIBRATIONMASK & theCurrentState)
  159. {
  160. PEvent tmp = new Event(BATTERY_CALIBRATION_CONDITION,
  161. NO_BATTERY_CALIBRATION_IN_PROGRESS);
  162. events->Append(tmp);
  163. }
  164. if ( ONBATTERYMASK & cur_state )
  165. {
  166. if (! battery_calibration_in_progress)
  167. {
  168. PEvent tmp = new Event(UTILITY_LINE_CONDITION, LINE_BAD);
  169. events->Append(tmp);
  170. }
  171. }
  172. if ( ONLINEMASK & cur_state )
  173. {
  174. PEvent tmp = new Event(UTILITY_LINE_CONDITION, LINE_GOOD);
  175. events->Append(tmp);
  176. }
  177. if ( LOWBATTERYMASK & cur_state )
  178. {
  179. PEvent tmp = new Event(BATTERY_CONDITION, BATTERY_BAD);
  180. events->Append(tmp);
  181. }
  182. else if (LOWBATTERYMASK & theCurrentState)
  183. {
  184. PEvent tmp = new Event(BATTERY_CONDITION, BATTERY_GOOD);
  185. events->Append(tmp);
  186. }
  187. if ( REPLACEBATTERYMASK & cur_state )
  188. {
  189. PEvent tmp = new Event(BATTERY_REPLACEMENT_CONDITION,
  190. BATTERY_NEEDS_REPLACING);
  191. events->Append(tmp);
  192. }
  193. else if (REPLACEBATTERYMASK & theCurrentState)
  194. {
  195. PEvent tmp = new Event(BATTERY_REPLACEMENT_CONDITION,
  196. BATTERY_DOESNT_NEED_REPLACING);
  197. events->Append(tmp);
  198. }
  199. if ( OVERLOADMASK & cur_state )
  200. {
  201. PEvent tmp = new Event(OVERLOAD_CONDITION, UPS_OVERLOAD);
  202. events->Append(tmp);
  203. }
  204. else if (OVERLOADMASK & theCurrentState)
  205. {
  206. PEvent tmp = new Event(OVERLOAD_CONDITION, NO_UPS_OVERLOAD);
  207. events->Append(tmp);
  208. }
  209. if ( SMARTBOOSTMASK & cur_state )
  210. {
  211. PEvent tmp = new Event(SMART_BOOST_STATE, SMART_BOOST_ON);
  212. events->Append(tmp);
  213. }
  214. else if (SMARTBOOSTMASK & theCurrentState)
  215. {
  216. PEvent tmp = new Event(SMART_BOOST_STATE, SMART_BOOST_OFF);
  217. events->Append(tmp);
  218. }
  219. if ( SMARTTRIMMASK & cur_state )
  220. {
  221. PEvent tmp = new Event(SMART_TRIM_STATE, SMART_TRIM_ON);
  222. events->Append(tmp);
  223. }
  224. else if (SMARTTRIMMASK & theCurrentState)
  225. {
  226. PEvent tmp = new Event(SMART_TRIM_STATE, SMART_TRIM_OFF);
  227. events->Append(tmp);
  228. }
  229. // if ( UPSSHUTDOWNMASK & cur_state ) // Bitwise OR
  230. // {
  231. // PEvent tmp = new Event(UPS_STATE, UPS_SHUTDOWN);
  232. // events->Append(tmp);
  233. // }
  234. // else if (UPSSHUTDOWNMASK & theCurrentState)
  235. // {
  236. // PEvent tmp = new Event(UPS_STATE, UPS_NOT_SHUTDOWN);
  237. // events->Append(tmp);
  238. // }
  239. theCurrentState = cur_state;
  240. //
  241. // Convert value from HEX to decimal for every one else
  242. //
  243. CHAR int_value[32];
  244. sprintf(int_value, "%d", cur_state);
  245. value->setResponse(int_value);
  246. return err;
  247. }
  248. INT AbnormalCondPollParam:: IsPollSet()
  249. {
  250. if (!thePollSet)
  251. {
  252. thePollSet = TRUE;
  253. return ErrABNORMAL_CONDITION_SET;
  254. }
  255. return ErrSAME_VALUE;
  256. }
  257. INT AbnormalCondPollParam:: ProcessValue(PMessage value, List* events)
  258. {
  259. int err = ErrNO_ERROR;
  260. // Check for NULL
  261. if ( NullTest(value->getResponse()) )
  262. {
  263. err = ErrREAD_FAILED;
  264. }
  265. else if ((_strcmpi(value->getResponse(), "NA") == 0) || !events) {
  266. err = ErrNO_VALUE;
  267. }
  268. // If everything checks out OK
  269. if (err == ErrNO_ERROR)
  270. {
  271. USHORT condition = 0;
  272. if (sscanf(value->getResponse(),"%x",&condition) == EOF) {
  273. err = ErrREAD_FAILED;
  274. }
  275. // Check if RIM is in control
  276. if (RIM_IN_CONTROL_MASK & condition) {
  277. // If the RIM is in control, we know its current status is OK
  278. PEvent rim_ok_event = new Event(RIM_STATUS, RIM_OK);
  279. events->Append(rim_ok_event);
  280. // If so, check the IM failed bit. If the IM_FAILED bit is set,
  281. // the IM is installed and has failed.
  282. if (IM_FAILED_MASK & condition) {
  283. PEvent im_installed_event = new Event(IM_INSTALLATION_STATE, IM_INSTALLED);
  284. PEvent im_failed_event = new Event(IM_STATUS, IM_FAILED);
  285. events->Append(im_failed_event);
  286. events->Append(im_installed_event);
  287. }
  288. // If the RIM is in control and the IM failed bit is not set, then
  289. // the IM is not installed.
  290. else {
  291. PEvent im_not_installed_event = new Event(IM_INSTALLATION_STATE, IM_NOT_INSTALLED);
  292. events->Append(im_not_installed_event);
  293. }
  294. }
  295. // If RIM is not in control, IM must be in control
  296. else {
  297. // Since IM is in control, its current state must be OK
  298. PEvent im_ok_event = new Event(IM_STATUS, IM_OK);
  299. PEvent im_installed_event = new Event(IM_INSTALLATION_STATE, IM_INSTALLED);
  300. events->Append(im_ok_event);
  301. events->Append(im_installed_event);
  302. // Check if the RIM has failed ... NOTE that the RIM_INSTALLATION_STATE
  303. // events will be generated by the ModuleCountsStatusPollParam
  304. if (RIM_FAILED_MASK & condition) {
  305. PEvent rim_failed_event = new Event(RIM_STATUS, RIM_FAILED);
  306. events->Append(rim_failed_event);
  307. }
  308. else {
  309. PEvent rim_ok_event = new Event(RIM_STATUS, RIM_OK);
  310. events->Append(rim_ok_event);
  311. }
  312. }
  313. // Check to see if any UPS modules have failed. NOTE: the else is not
  314. // handled because we do not generate the UPS_MODULE_OK event ... this
  315. // condition is handled by the UPS module removed and added sequence.
  316. // (Bad modules must be removed before they will be OK again)
  317. if (FAILED_UPS_MASK & condition) {
  318. PEvent ups_module_failed_event = new Event(UPS_MODULE_FAILED, UPS_MODULE_FAILED);
  319. events->Append(ups_module_failed_event);
  320. }
  321. // Check Redundancy state
  322. if (REDUNDANCY_FAILED_MASK & condition) {
  323. PEvent redundancy_failed_event = new Event(REDUNDANCY_STATE, REDUNDANCY_FAILED);
  324. events->Append(redundancy_failed_event);
  325. }
  326. else {
  327. PEvent redundancy_ok_event = new Event(REDUNDANCY_STATE, REDUNDANCY_OK);
  328. events->Append(redundancy_ok_event);
  329. }
  330. // Check the Bypass contactor state
  331. if (BYPASS_STUCK_MASK & condition) {
  332. PEvent bypass_contactor_failed_event = new Event(BYPASS_CONTACTOR_STATE, BYPASS_CONTACTOR_FAILED);
  333. events->Append(bypass_contactor_failed_event);
  334. }
  335. else {
  336. PEvent bypass_contactor_ok_event = new Event(BYPASS_CONTACTOR_STATE, BYPASS_CONTACTOR_OK);
  337. events->Append(bypass_contactor_ok_event);
  338. }
  339. // Check the input circuit breaker state
  340. if (INPUT_BREAKER_TRIPPED_MASK & condition)
  341. {
  342. PEvent input_breaker_tripped_event = new Event(INPUT_BREAKER_STATE, BREAKER_OPEN);
  343. events->Append(input_breaker_tripped_event);
  344. }
  345. else {
  346. PEvent input_breaker_closed_event = new Event(INPUT_BREAKER_STATE, BREAKER_CLOSED);
  347. events->Append(input_breaker_closed_event);
  348. }
  349. // Check the system fan state
  350. if (SYSTEM_FAN_FAILED_MASK & condition)
  351. {
  352. PEvent fan_failed_event = new Event(SYSTEM_FAN_STATE, SYSTEM_FAN_FAILED);
  353. events->Append(fan_failed_event);
  354. }
  355. else {
  356. PEvent fan_ok_event = new Event(SYSTEM_FAN_STATE, SYSTEM_FAN_OK);
  357. events->Append(fan_ok_event);
  358. }
  359. theCurrentState = condition;
  360. //
  361. // Convert value from HEX to decimal for every one else
  362. //
  363. CHAR int_value[32];
  364. sprintf(int_value, "%d", condition);
  365. value->setResponse(int_value);
  366. }
  367. return err;
  368. }
  369. INT ModuleCountsStatusPollParam :: IsPollSet()
  370. {
  371. if (!thePollSet)
  372. {
  373. thePollSet = TRUE;
  374. return ErrMODULE_COUNTS_SET;
  375. }
  376. return ErrSAME_VALUE;
  377. }
  378. // ProcessValue
  379. //
  380. // This routine parses the UPS response containing module counts and status.
  381. // The response is assumed to be in the following format:
  382. // total UPS modules (dd)
  383. // bad UPS modules (dd)
  384. // fault tolerance level (d)
  385. // fault tolerance alarm threshold (d)
  386. // kVA capacity (dd.d)
  387. // kVA capacity alarm threshold (dd.d)
  388. // RIM present? (Y or N)
  389. //
  390. // All responses must be separated by a comma
  391. INT ModuleCountsStatusPollParam :: ProcessValue(PMessage value, List* events)
  392. {
  393. INT err = ErrNO_ERROR;
  394. if ( NullTest(value->getResponse()) )
  395. {
  396. err = ErrREAD_FAILED;
  397. }
  398. // Check for an NA response from the UPS. This will be returned
  399. // if the the RIM is in control, because the RIM responds to a limited
  400. // subset of the full Symmetra UPS-Link spec.
  401. else if ( (!events) || (_strcmpi(value->getResponse(), "NA") == 0)) {
  402. err = ErrNO_VALUE;
  403. }
  404. // If everything checks out OK
  405. if (err == ErrNO_ERROR)
  406. {
  407. PCHAR module_counts;
  408. // Be a good neighbor and don't destroy the input parameters.
  409. PCHAR ups_response = value->getResponse();
  410. module_counts = _strdup(ups_response);
  411. PCHAR number_of_inverters = strtok(module_counts, ",");
  412. PEvent Number_Of_UPS_Modules_Event =
  413. new Event(TOTAL_INVERTERS, number_of_inverters);
  414. events->Append(Number_Of_UPS_Modules_Event);
  415. PCHAR bad_inverters = strtok(NULL, ",");
  416. PEvent Bad_UPS_Modules_Event =
  417. new Event(NUMBER_BAD_INVERTERS, bad_inverters);
  418. events->Append(Bad_UPS_Modules_Event);
  419. PCHAR current_redundancy = strtok(NULL, ",");
  420. PEvent Current_Redundancy_Event =
  421. new Event(CURRENT_REDUNDANCY,current_redundancy);
  422. events->Append(Current_Redundancy_Event);
  423. PCHAR minimum_redundancy = strtok(NULL, ",");
  424. PEvent Minimum_Redundancy_Event =
  425. new Event(MINIMUM_REDUNDANCY,minimum_redundancy );
  426. events->Append(Minimum_Redundancy_Event);
  427. PCHAR current_load_capability = strtok(NULL, ",");
  428. PEvent Current_Load_Capability_Event =
  429. new Event(CURRENT_LOAD_CAPABILITY, current_load_capability);
  430. events->Append(Current_Load_Capability_Event);
  431. PCHAR maximum_load_capability = strtok(NULL, ",");
  432. PEvent Maximum_Load_Capability_Event =
  433. new Event(MAXIMUM_LOAD_CAPABILITY, maximum_load_capability);
  434. events->Append(Maximum_Load_Capability_Event);
  435. PCHAR rim_installation_state = strtok(NULL, ",");
  436. PEvent RIM_Installation_State_Event;
  437. if ((rim_installation_state != NULL) && (_strcmpi(rim_installation_state, "y") == 0)) {
  438. RIM_Installation_State_Event =
  439. new Event(RIM_INSTALLATION_STATE, RIM_INSTALLED);
  440. }
  441. else {
  442. RIM_Installation_State_Event =
  443. new Event(RIM_INSTALLATION_STATE, RIM_NOT_INSTALLED);
  444. }
  445. events->Append(RIM_Installation_State_Event);
  446. // free local memory allocations
  447. free (module_counts);
  448. }
  449. return err;
  450. }
  451. INT InputVoltageFrequencyPollParam :: IsPollSet()
  452. {
  453. if (!thePollSet)
  454. {
  455. thePollSet = TRUE;
  456. return ErrVOLTAGE_FREQUENCY_SET;
  457. }
  458. return ErrSAME_VALUE;
  459. }
  460. // ProcessValue
  461. //
  462. // This routine parses the UPS response containing the input
  463. // voltages and frequency.
  464. // The response is assumed to be in the following format:
  465. // utility input voltage for phase A
  466. // utility input voltage for phase B
  467. // utility input voltage for phase C
  468. // utility input frequency
  469. // All responses must be separated by a comma
  470. INT InputVoltageFrequencyPollParam :: ProcessValue(PMessage value, List* events)
  471. {
  472. INT err = ErrCONTINUE;
  473. if ( NullTest(value->getResponse()) )
  474. {
  475. err = ErrREAD_FAILED;
  476. }
  477. if (!events)
  478. {
  479. err = ErrNO_VALUE;
  480. }
  481. if (err==ErrCONTINUE)
  482. {
  483. PCHAR input_voltage_frequency;
  484. // Be a good neighbor and don't destroy the input parameters.
  485. PCHAR ups_response = value->getResponse();
  486. input_voltage_frequency = _strdup(ups_response);
  487. // At the minimum, there will always be a phase a voltage
  488. // and an input frequency. At most there will be three
  489. // input voltages and a frequency
  490. const PCHAR cVoltage_Frequency_Separator = ";";
  491. const PCHAR cVoltage_Parameter_Separator = ",";
  492. const PCHAR cZeroVoltage = "0.0";
  493. PCHAR input_voltages = strtok(input_voltage_frequency,cVoltage_Frequency_Separator);
  494. PCHAR input_frequency = strtok(NULL,cVoltage_Frequency_Separator );
  495. PCHAR phase_a_input_voltage = strtok(input_voltages,cVoltage_Parameter_Separator );
  496. PEvent Voltage_A_Event = new Event(INPUT_VOLTAGE_PHASE_A, phase_a_input_voltage );
  497. events->Append(Voltage_A_Event);
  498. PCHAR phase_b_input_voltage = strtok(NULL,cVoltage_Parameter_Separator );
  499. PCHAR phase_c_input_voltage;
  500. INT number_of_input_phases;
  501. if (phase_b_input_voltage == NULL)
  502. {
  503. phase_b_input_voltage = cZeroVoltage;
  504. phase_c_input_voltage = cZeroVoltage;
  505. number_of_input_phases = 1;
  506. }
  507. else
  508. {
  509. phase_c_input_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  510. number_of_input_phases = 3;
  511. if (phase_c_input_voltage == NULL)
  512. {
  513. phase_c_input_voltage = cZeroVoltage;
  514. number_of_input_phases = 2;
  515. }
  516. }
  517. PEvent Voltage_B_Event = new Event(INPUT_VOLTAGE_PHASE_B, phase_b_input_voltage );
  518. events->Append(Voltage_B_Event);
  519. PEvent Voltage_C_Event = new Event(INPUT_VOLTAGE_PHASE_C, phase_c_input_voltage );
  520. events->Append(Voltage_C_Event);
  521. PEvent Input_Frequency_Event = new Event(INPUT_FREQUENCY, input_frequency );
  522. events->Append(Input_Frequency_Event);
  523. CHAR input_phases[10];
  524. _itoa(number_of_input_phases,input_phases,10);
  525. PEvent Number_Of_Phases_Event = new Event(NUMBER_OF_INPUT_PHASES, input_phases );
  526. events->Append(Number_Of_Phases_Event);
  527. // free local memory allocations
  528. free (input_voltage_frequency);
  529. }
  530. return err;
  531. }
  532. INT OutputVoltageCurrentsPollParam :: IsPollSet()
  533. {
  534. if (!thePollSet)
  535. {
  536. thePollSet = TRUE;
  537. return ErrVOLTAGE_CURRENTS_SET;
  538. }
  539. return ErrSAME_VALUE;
  540. }
  541. // ProcessValue
  542. //
  543. // This routine parses the UPS response containing the output
  544. // voltages and currents.
  545. // The response is assumed to be in the following format:
  546. // output voltage for phase A
  547. // output voltage for phase B
  548. // output voltage for phase C
  549. // current for phase A
  550. // current for phase B
  551. // current for phase C
  552. // All responses must be separated by a comma
  553. INT OutputVoltageCurrentsPollParam :: ProcessValue(PMessage value, List* events)
  554. {
  555. INT err = ErrCONTINUE;
  556. if ( NullTest(value->getResponse()) )
  557. {
  558. err = ErrREAD_FAILED;
  559. }
  560. if (!events)
  561. {
  562. err = ErrNO_VALUE;
  563. }
  564. if (err==ErrCONTINUE)
  565. {
  566. PCHAR output_voltage_currents;
  567. // Be a good neighbor and don't destroy the input parameters.
  568. PCHAR ups_response = value->getResponse();
  569. output_voltage_currents = _strdup(ups_response);
  570. // Separate the voltages from the currents and then process.
  571. const PCHAR cVoltage_Currents_Separator = ";";
  572. PCHAR output_voltages = strtok(output_voltage_currents,cVoltage_Currents_Separator );
  573. // Extract phase voltages
  574. const PCHAR cParameter_Separator = ",";
  575. const PCHAR cZeroVoltage = "0.0";
  576. PCHAR phase_a_output_voltage = strtok(output_voltages,cParameter_Separator );
  577. PEvent Voltage_A_Event = new Event(OUTPUT_VOLTAGE_PHASE_A, phase_a_output_voltage );
  578. events->Append(Voltage_A_Event);
  579. PCHAR phase_b_output_voltage = strtok(NULL,cParameter_Separator );
  580. PCHAR phase_c_output_voltage;
  581. INT number_of_output_phases;
  582. if (phase_b_output_voltage == NULL)
  583. {
  584. phase_b_output_voltage = cZeroVoltage;
  585. phase_c_output_voltage = cZeroVoltage;
  586. number_of_output_phases = 1;
  587. }
  588. else
  589. {
  590. phase_c_output_voltage = strtok(NULL, cParameter_Separator);
  591. number_of_output_phases = 3;
  592. if (phase_c_output_voltage == NULL)
  593. {
  594. phase_c_output_voltage = cZeroVoltage;
  595. number_of_output_phases = 2;
  596. }
  597. }
  598. PEvent Voltage_B_Event = new Event(OUTPUT_VOLTAGE_PHASE_B, phase_b_output_voltage );
  599. events->Append(Voltage_B_Event);
  600. PEvent Voltage_C_Event = new Event(OUTPUT_VOLTAGE_PHASE_C, phase_c_output_voltage );
  601. events->Append(Voltage_C_Event);
  602. CHAR output_phases[10];
  603. _itoa(number_of_output_phases,output_phases,10);
  604. PEvent Number_Of_Phases_Event = new Event(NUMBER_OF_OUTPUT_PHASES, output_phases );
  605. events->Append(Number_Of_Phases_Event);
  606. // free local memory allocations
  607. free (output_voltage_currents);
  608. }
  609. return err;
  610. }
  611. //-------------------------------------------------------------
  612. // This handles the CTRL Z command for upss that support it
  613. //-------------------------------------------------------------
  614. #if (C_OS & C_OS2)
  615. INT EepromAllowedValsPollParam:: ProcessValue(PMessage value, List* )
  616. #else
  617. INT EepromAllowedValuesPollParam:: ProcessValue(PMessage value, List* )
  618. #endif
  619. {
  620. CHAR response[512];
  621. CHAR returnString[512];
  622. INT done = FALSE;
  623. if ( NullTest(value->getResponse()) )
  624. return ErrREAD_FAILED;
  625. strcpy (response, value->getResponse());
  626. CHAR *workString;
  627. CHAR command;
  628. CHAR commandString[7];
  629. CHAR upsType;
  630. CHAR numChoices;
  631. CHAR numCharPerChoice;
  632. INT index = 0;
  633. returnString[0] = 0;
  634. INT scanFlag;
  635. workString = &(response[0]);
  636. // Loop over all the parameters that have been return by CTRL Z
  637. //
  638. // The String is Formatted like this
  639. //
  640. // ##CTcSxxxyyyzzz... where ## is the delimiter
  641. // C is the command ex: u -- High Transfer Points
  642. // T is the Ups Type ex M for 208,
  643. // I for 240,
  644. // A for 100,
  645. // D for 120
  646. // c is Number of choices ex 3
  647. // S is the size of each choice 3
  648. // xxx is the first choice -- size = 3
  649. // yyy is the second choice -- size = 3
  650. // zzz is the third choice -- size = 3
  651. while (!done)
  652. {
  653. CHAR eepromValues[1024];
  654. memset(eepromValues,'\0',1024);
  655. //
  656. // Skip over #'s. Old Matrix use two # delimeters. 3G and beyond
  657. // want to use only 1 #.
  658. //
  659. while(*workString == '#') {
  660. workString++;
  661. }
  662. scanFlag = sscanf(workString, "%c%c%c%c%n", &command,&upsType, &numChoices,
  663. &numCharPerChoice, &index); //(SRT) can't rely on index to tell truth,
  664. // when response is trunc'd in middle of
  665. // command so I've added scanFlag instead.
  666. switch (scanFlag) {
  667. case 4: // normal process
  668. {
  669. INT choices = (int)numChoices - 48;
  670. INT charsPChoice = (int)numCharPerChoice - 48;
  671. workString = &(workString[index]);
  672. if (strlen(workString)< (size_t) (choices*charsPChoice)) {
  673. done = TRUE;
  674. break;
  675. }
  676. for (INT i = 0; i < choices; i++)
  677. {
  678. if (i != 0)
  679. strcat(eepromValues, ",");
  680. strncat(eepromValues, workString, charsPChoice);
  681. workString = &(workString[charsPChoice]);
  682. }
  683. // Convert command to the sensor id --
  684. // EX: u High trans voltage to -- HIGH_TRANSFER_VOLTAGE
  685. INT id;
  686. commandString[0] = command;
  687. commandString[1] = 0;
  688. if (!strcmp(commandString, OUTPUTVOLTAGEREPORT))
  689. {
  690. id = OUTPUT_VOLTAGE_REPORT;
  691. }
  692. else if (!strcmp(commandString, LANGUAGE))
  693. {
  694. id = UPS_LANGUAGE;
  695. }
  696. else if (!strcmp(commandString, AUTOSELFTEST))
  697. {
  698. id = UPS_SELF_TEST_SCHEDULE;
  699. }
  700. else if (!strcmp(commandString, HIGHTRANSFERPOINT))
  701. {
  702. id = HIGH_TRANSFER_VOLTAGE;
  703. }
  704. else if (!strcmp(commandString, LOWTRANSFERPOINT))
  705. {
  706. id = LOW_TRANSFER_VOLTAGE;
  707. }
  708. else if (!strcmp(commandString, MINIMUMCAPACITY))
  709. {
  710. id = MIN_RETURN_CAPACITY;
  711. }
  712. else if (!strcmp(commandString, OUTPUTVOLTAGESETTING))
  713. {
  714. id = RATED_OUTPUT_VOLTAGE;
  715. }
  716. else if (!strcmp(commandString, SENSETIVITY))
  717. {
  718. id = UPS_SENSITIVITY;
  719. }
  720. else if (!strcmp(commandString, LOWBATTERYRUNTIME))
  721. {
  722. id = LOW_BATTERY_DURATION;
  723. }
  724. else if (!strcmp(commandString, ALARMDELAY))
  725. {
  726. id = ALARM_DELAY;
  727. }
  728. else if (!strcmp(commandString, SHUTDOWNDELAY))
  729. {
  730. id = SHUTDOWN_DELAY;
  731. }
  732. else if (!strcmp(commandString, SYNCTURNBACKDELAY))
  733. {
  734. id = TURN_ON_DELAY;
  735. }
  736. else if (!strcmp(commandString, EARLYTURNOFF))
  737. {
  738. id = EARLY_TURN_OFF_POINTS;
  739. }
  740. CHAR tmp[124];
  741. sprintf(tmp, "#%d,%c,%s",id,upsType,eepromValues);
  742. strcat(returnString,tmp);
  743. break;
  744. }
  745. case 0: // end of string?
  746. case EOF: // can be end of strin gor error, we'll assume end of string.
  747. done = TRUE;
  748. break;
  749. default: // erroneous truncation
  750. done = TRUE;
  751. break;
  752. } //end switch
  753. } // end while
  754. strcat(returnString, "#");
  755. value->setResponse(returnString);
  756. return ErrNO_ERROR;
  757. }
  758. INT SmartModePollParam::ProcessValue(PMessage value, List* )
  759. {
  760. if ( NullTest(value->getResponse()) )
  761. return ErrREAD_FAILED;
  762. if (strcmp(value->getResponse(), SMARTMODE_OK))
  763. return ErrSMART_MODE_FAILED;
  764. return ErrNO_ERROR;
  765. }
  766. INT TurnOffSmartModePollParam::ProcessValue(PMessage value, List* )
  767. {
  768. return ErrNO_ERROR;
  769. }
  770. INT LineConditionPollParam::ProcessValue(PMessage value, List* events)
  771. {
  772. if ( NullTest(value->getResponse()) )
  773. return ErrREAD_FAILED;
  774. if (!events) {
  775. return ErrNO_VALUE;
  776. }
  777. //
  778. // Convert UPS Link responses to our codes and generate appropriate
  779. // event
  780. //
  781. CHAR code_value[32];
  782. INT code = 0;
  783. if (!strcmp(value->getResponse(), "FF" )) {
  784. code = NO_ABNORMAL_CONDITION;
  785. }
  786. else {
  787. code = ABNORMAL_CONDITION;
  788. }
  789. sprintf(code_value, "%d", code);
  790. value->setResponse(code_value);
  791. PEvent tmp = new Event(LINE_CONDITION_TEST, code);
  792. events->Append(tmp);
  793. return ErrCONTINUE;
  794. }
  795. INT LightsTestPollParam:: ProcessValue(PMessage value, List* )
  796. {
  797. if ( NullTest(value->getResponse()) )
  798. return ErrREAD_FAILED;
  799. if (strcmp(value->getResponse(), LIGHTSTEST_RESP))
  800. return ErrLIGHTSTEST_REQUEST_FAILED;
  801. return ErrNO_ERROR;
  802. }
  803. INT TurnOffAfterDelayPollParam::ProcessValue(PMessage value, List* )
  804. {
  805. PCHAR tmp_value = value->getResponse();
  806. if (tmp_value) {
  807. if (!strcmp(tmp_value, TURNOFFAFTERDELAY_NOT_AVAIL)) {
  808. return ErrTURNOFFAFTERDELAY_NOT_AVAIL;
  809. }
  810. }
  811. return ErrNO_ERROR;
  812. }
  813. INT ShutdownPollParam::ProcessValue(PMessage value, List* )
  814. {
  815. INT rval = ErrNO_ERROR;
  816. PCHAR response = value->getResponse();
  817. if (response) {
  818. if (strcmp(response,SHUTDOWN_RESP)) {
  819. if (!strcmp(response, SHUTDOWN_NOT_AVAIL))
  820. rval=ErrSHUTDOWN_NOT_AVAIL;
  821. }
  822. }
  823. return rval;
  824. }
  825. INT SimulatePowerFailurePollParam::ProcessValue(PMessage value, List* )
  826. {
  827. if ( NullTest(value->getResponse()) )
  828. return ErrREAD_FAILED;
  829. if (strcmp(value->getResponse(), SIMULATEPOWERFAILURE_OK))
  830. {
  831. if (!strcmp(value->getResponse(), SIMULATEPOWERFAILURE_NOT_AVAIL))
  832. return ErrSIMULATEPOWERFAILURE_NOT_AVAIL;
  833. }
  834. return ErrNO_ERROR;
  835. }
  836. INT BatteryTestPollParam:: ProcessValue(PMessage value, List* )
  837. {
  838. if (!strcmp(value->getResponse(), BATTERYTEST_NOT_AVAIL))
  839. {
  840. return ErrBATTERYTEST_NOT_AVAIL;
  841. }
  842. return ErrNO_ERROR;
  843. }
  844. INT TurnOffUpsPollParam:: ProcessValue(PMessage value, List* )
  845. {
  846. if (!strcmp(value->getResponse(), NOT_AVAIL))
  847. {
  848. return ErrREAD_FAILED; //This error should be ErrTURN_OFF_UPS_NOT_AVAIL
  849. }
  850. return ErrNO_ERROR;
  851. }
  852. INT ShutdownWakeupPollParam:: ProcessValue(PMessage value, List* )
  853. {
  854. if (!strcmp(value->getResponse(), NOT_AVAIL))
  855. {
  856. return ErrREAD_FAILED; //This error should be ErrSHUT_WAKE_NOT_AVAIL
  857. }
  858. return ErrNO_ERROR;
  859. }
  860. INT BatteryCalibrationPollParam:: ProcessValue(PMessage value, List* )
  861. {
  862. if ( NullTest(value->getResponse()) )
  863. return ErrREAD_FAILED;
  864. if (strcmp(value->getResponse(), BATTERYCALIBRATION_OK))
  865. {
  866. if (!strcmp(value->getResponse(), BATTERYCALIBRATION_CAP_TOO_LOW))
  867. return ErrBATTERYCALIBRATION_CAP_TOO_LOW;
  868. if (!strcmp(value->getResponse(), BATTERYCALIBRATION_NOT_AVAIL))
  869. return ErrBATTERYCALIBRATION_NOT_AVAIL;
  870. }
  871. return ErrNO_ERROR;
  872. }
  873. INT BatteryTestResultsPollParam:: ProcessValue(PMessage value, List* )
  874. {
  875. if ((value == NULL) || (NullTest(value->getResponse()) ))
  876. return ErrREAD_FAILED;
  877. char buffer[20], *val;
  878. val = value->getResponse();
  879. if (val == NULL)
  880. return ErrREAD_FAILED;
  881. if (!strcmp(val, BATTERYTEST_OK))
  882. value->setResponse(_itoa(SELF_TEST_PASSED,buffer,10));
  883. if (!strcmp(val, BATTERYTEST_BAD_BATTERY))
  884. value->setResponse(_itoa(SELF_TEST_FAILED,buffer,10));
  885. if (!strcmp(val, BATTERYTEST_NO_RECENT_TEST))
  886. value->setResponse(_itoa(SELF_TEST_NO_RECENT_TEST,buffer,10));
  887. if (!strcmp(val, BATTERYTEST_INVALID_TEST))
  888. value->setResponse(_itoa(SELF_TEST_INVALID,buffer,10));
  889. return ErrNO_ERROR;
  890. }
  891. INT TransferCausePollParam:: ProcessValue(PMessage value, List* )
  892. {
  893. if ((value == NULL) || (NullTest(value->getResponse())) )
  894. return ErrREAD_FAILED;
  895. char buffer[20], *val;
  896. val = value->getResponse();
  897. if (val == NULL)
  898. return ErrREAD_FAILED;
  899. if (!strcmp(val, TRANSFERCAUSE_NO_TRANSFERS))
  900. value->setResponse(_itoa(NO_TRANSFERS,buffer,10));
  901. if (!strcmp(val, TRANSFERCAUSE_SELF_TEST))
  902. value->setResponse(_itoa(SELF_TEST_TRANSFER,buffer,10));
  903. if (!strcmp(val, TRANSFERCAUSE_LINE_DETECTED))
  904. value->setResponse(_itoa(NOTCH_SPIKE_TRANSFER,buffer,10));
  905. if (!strcmp(val, TRANSFERCAUSE_LOW_LINE_VOLTAGE))
  906. value->setResponse(_itoa(LOW_LINE_TRANSFER,buffer,10));
  907. if (!strcmp(val, TRANSFERCAUSE_HIGH_LINE_VOLTAGE))
  908. value->setResponse(_itoa(HIGH_LINE_TRANSFER,buffer,10));
  909. if (!strcmp(val, TRANSFERCAUSE_RATE_VOLTAGE_CHANGE))
  910. value->setResponse(_itoa(RATE_TRANSFER,buffer,10));
  911. if (!strcmp(val, TRANSFERCAUSE_INPUT_BREAKER_TRIPPED))
  912. value->setResponse(_itoa(INPUT_BREAKER_TRIPPED_TRANSFER,buffer,10));
  913. return ErrNO_ERROR;
  914. }
  915. INT BatteryCapacityPollParam:: ProcessValue(PMessage value, List* aList)
  916. {
  917. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  918. {
  919. if ((*(value->getResponse()+3)) == '.')
  920. return ErrNO_ERROR;
  921. }
  922. return ErrBAD_RESPONSE_VALUE;
  923. }
  924. INT DipSwitchPollParam:: ProcessValue(PMessage value, List* )
  925. {
  926. int cur_state = 0;
  927. if (sscanf(value->getResponse(),"%x",&cur_state) == EOF) {
  928. return ErrREAD_FAILED;
  929. }
  930. //
  931. // Convert value from HEX to decimal for every one else
  932. //
  933. CHAR int_value[32];
  934. sprintf(int_value, "%d", cur_state);
  935. value->setResponse(int_value);
  936. return ErrNO_ERROR;
  937. }
  938. INT RuntimeRemainingPollParam:: ProcessValue(PMessage value, List* )
  939. {
  940. INT err = ErrNO_ERROR;
  941. PCHAR val = value->getResponse();
  942. INT len = strlen(val);
  943. if (len == 4) {
  944. if(strcmp(val, ">>>>") == 0) {
  945. value->setResponse("9999");
  946. }
  947. else {
  948. err = ErrBAD_RESPONSE_VALUE;
  949. }
  950. }
  951. else if(len == 5) {
  952. PCHAR time_in_minutes = strtok(value->getResponse(), ":");
  953. if(time_in_minutes) {
  954. LONG secs = atol(time_in_minutes) * 60;
  955. CHAR time_in_seconds[32];
  956. value->setResponse(_ltoa(secs, time_in_seconds, 10));
  957. }
  958. else {
  959. err = ErrBAD_RESPONSE_VALUE;
  960. }
  961. }
  962. else {
  963. err = ErrBAD_RESPONSE_VALUE;
  964. }
  965. return err;
  966. }
  967. INT CopyrightPollParam:: ProcessValue(PMessage value, List* )
  968. {
  969. if ( NullTest(value->getResponse()) )
  970. return ErrREAD_FAILED;
  971. if (strcmp(value->getResponse(), COPYRIGHT_RESP))
  972. {
  973. return ErrCOPYRIGHT_RESP_ERROR;
  974. }
  975. return ErrNO_ERROR;
  976. }
  977. INT BatteryVoltagePollParam:: ProcessValue(PMessage value, List* aList)
  978. {
  979. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  980. {
  981. if (((*(value->getResponse()+2)) == '.') || ((*(value->getResponse()+3)) == '.'))
  982. return ErrNO_ERROR;
  983. }
  984. return ErrBAD_RESPONSE_VALUE;
  985. }
  986. INT InternalTempPollParam:: ProcessValue(PMessage value, List* aList)
  987. {
  988. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  989. {
  990. if ((*(value->getResponse()+3)) == '.')
  991. return ErrNO_ERROR;
  992. }
  993. return ErrBAD_RESPONSE_VALUE;
  994. }
  995. INT OutputFreqPollParam:: ProcessValue(PMessage value, List* aList)
  996. {
  997. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  998. {
  999. if ((*(value->getResponse()+2)) == '.')
  1000. return ErrNO_ERROR;
  1001. }
  1002. return ErrBAD_RESPONSE_VALUE;
  1003. }
  1004. INT LineVoltagePollParam:: ProcessValue(PMessage value, List* aList)
  1005. {
  1006. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  1007. {
  1008. if ((*(value->getResponse()+3)) == '.')
  1009. return ErrNO_ERROR;
  1010. }
  1011. return ErrBAD_RESPONSE_VALUE;
  1012. }
  1013. INT MaxVoltagePollParam:: ProcessValue(PMessage value, List* aList)
  1014. {
  1015. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  1016. {
  1017. if ((*(value->getResponse()+3)) == '.')
  1018. return ErrNO_ERROR;
  1019. }
  1020. return ErrBAD_RESPONSE_VALUE;
  1021. }
  1022. INT MinVoltagePollParam:: ProcessValue(PMessage value, List* aList)
  1023. {
  1024. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  1025. {
  1026. if ((*(value->getResponse()+3)) == '.')
  1027. return ErrNO_ERROR;
  1028. }
  1029. return ErrBAD_RESPONSE_VALUE;
  1030. }
  1031. INT OutputVoltagePollParam:: ProcessValue(PMessage value, List* aList)
  1032. {
  1033. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  1034. {
  1035. if ((*(value->getResponse()+3)) == '.')
  1036. return ErrNO_ERROR;
  1037. }
  1038. return ErrBAD_RESPONSE_VALUE;
  1039. }
  1040. INT LoadPowerPollParam :: ProcessValue(PMessage value, List* aList)
  1041. {
  1042. if(SmartPollParam::ProcessValue(value, aList) == ErrNO_ERROR)
  1043. {
  1044. if ((*(value->getResponse()+3)) == '.')
  1045. return ErrNO_ERROR;
  1046. }
  1047. return ErrBAD_RESPONSE_VALUE;
  1048. }
  1049. INT DecrementPollParam:: ProcessValue(PMessage value, List* )
  1050. {
  1051. if ( NullTest(value->getResponse()) )
  1052. return ErrREAD_FAILED;
  1053. if (strcmp(value->getResponse(), DECREMENT_OK))
  1054. {
  1055. if (!strcmp(value->getResponse(), DECREMENT_NOT_AVAIL))
  1056. return ErrDECREMENT_NOT_AVAIL;
  1057. if (!strcmp(value->getResponse(), DECREMENT_NOT_ALLOWED))
  1058. return ErrDECREMENT_NOT_ALLOWED;
  1059. }
  1060. return ErrNO_ERROR;
  1061. }
  1062. INT IncrementPollParam:: ProcessValue(PMessage value, List* )
  1063. {
  1064. if ( NullTest(value->getResponse()) )
  1065. return ErrREAD_FAILED;
  1066. if (strcmp(value->getResponse(), INCREMENT_OK))
  1067. {
  1068. if (!strcmp(value->getResponse(), INCREMENT_NOT_AVAIL))
  1069. return ErrINCREMENT_NOT_AVAIL;
  1070. if (!strcmp(value->getResponse(), INCREMENT_NOT_ALLOWED))
  1071. return ErrINCREMENT_NOT_ALLOWED;
  1072. }
  1073. return ErrNO_ERROR;
  1074. }
  1075. INT UpsIdPollParam:: ProcessValue(PMessage value, List* )
  1076. {
  1077. // I had to do this because UPS don't always return a response without
  1078. // a significant delay after a data set. We get a response by asking
  1079. // for the EEPROM data param twice. The second one always works. pcy.
  1080. // The same is tru for the BatteryReplaceDate pollparam. pcy.
  1081. return ErrNO_ERROR;
  1082. }
  1083. INT BatteryReplaceDatePollParam:: ProcessValue(PMessage value, List* )
  1084. {
  1085. // I had to do this because UPS don't always return a response without
  1086. // a significant delay after a data set. We get a response by asking
  1087. // for the EEPROM data param twice. The second one always works.
  1088. // The same is tru for the UpsId pollparam. pcy.
  1089. return ErrNO_ERROR;
  1090. }
  1091. INT BatteryCondPollParam:: ProcessValue(PMessage value, List* )
  1092. {
  1093. char buffer[20];
  1094. int cur_state = UtilHexStringToInt(value->getResponse());
  1095. if ( LOWBATTERYMASK & cur_state ) // Bitwise OR
  1096. {
  1097. value->setResponse(_itoa(BATTERY_BAD,buffer,10));
  1098. theCurrentState = BATTERY_BAD;
  1099. }
  1100. else if (LOWBATTERYMASK & theCurrentState)
  1101. {
  1102. value->setResponse(_itoa(BATTERY_GOOD,buffer,10));
  1103. theCurrentState = BATTERY_GOOD;
  1104. }
  1105. return ErrNO_ERROR;
  1106. }
  1107. INT UtilLineCondPollParam:: ProcessValue(PMessage value, List* )
  1108. {
  1109. char buffer[20];
  1110. int cur_state = UtilHexStringToInt(value->getResponse());
  1111. if ( ONBATTERYMASK & cur_state ) // Bitwise OR
  1112. {
  1113. value->setResponse(_itoa(LINE_BAD,buffer,10));
  1114. theCurrentState = LINE_BAD;
  1115. }
  1116. if ( ONLINEMASK & cur_state ) // Bitwise OR
  1117. {
  1118. value->setResponse(_itoa(LINE_GOOD,buffer,10));
  1119. theCurrentState = LINE_GOOD;
  1120. }
  1121. return ErrNO_ERROR;
  1122. }
  1123. INT ReplaceBattCondPollParam:: ProcessValue(PMessage value, List* )
  1124. {
  1125. char buffer[20];
  1126. int cur_state = UtilHexStringToInt(value->getResponse());
  1127. if ( REPLACEBATTERYMASK & cur_state ) // Bitwise OR
  1128. {
  1129. value->setResponse(_itoa(BATTERY_NEEDS_REPLACING,buffer,10));
  1130. theCurrentState = BATTERY_NEEDS_REPLACING;
  1131. }
  1132. else
  1133. {
  1134. value->setResponse(_itoa(BATTERY_DOESNT_NEED_REPLACING,buffer,10));
  1135. theCurrentState = BATTERY_DOESNT_NEED_REPLACING;
  1136. }
  1137. return ErrNO_ERROR;
  1138. }
  1139. INT OverLoadCondPollParam:: ProcessValue(PMessage value, List* )
  1140. {
  1141. char buffer[20];
  1142. int cur_state = UtilHexStringToInt(value->getResponse());
  1143. if ( OVERLOADMASK & cur_state ) // Bitwise OR
  1144. {
  1145. value->setResponse(_itoa(UPS_OVERLOAD,buffer,10));
  1146. theCurrentState = UPS_OVERLOAD;
  1147. }
  1148. else if (OVERLOADMASK & theCurrentState)
  1149. {
  1150. value->setResponse(_itoa(NO_UPS_OVERLOAD,buffer,10));
  1151. theCurrentState = NO_UPS_OVERLOAD;
  1152. }
  1153. return ErrNO_ERROR;
  1154. }
  1155. INT SmartBoostCondPollParam:: ProcessValue(PMessage value, List* )
  1156. {
  1157. char buffer[20];
  1158. int cur_state = UtilHexStringToInt(value->getResponse());
  1159. if ( SMARTBOOSTMASK & cur_state ) // Bitwise OR
  1160. {
  1161. value->setResponse(_itoa(SMART_BOOST_ON,buffer,10));
  1162. theCurrentState = (USHORT) cur_state; // SMART_BOOST_ON;
  1163. }
  1164. else if (SMARTBOOSTMASK & theCurrentState)
  1165. {
  1166. value->setResponse(_itoa(SMART_BOOST_OFF,buffer,10));
  1167. theCurrentState = (USHORT) cur_state; // SMART_BOOST_OFF;
  1168. }
  1169. else
  1170. value->setResponse(_itoa(SMART_BOOST_OFF,buffer,10));
  1171. return ErrNO_ERROR;
  1172. }
  1173. INT SmartTrimCondPollParam:: ProcessValue(PMessage value, List* )
  1174. {
  1175. char buffer[20];
  1176. int cur_state = UtilHexStringToInt(value->getResponse());
  1177. if ( SMARTTRIMMASK & cur_state ) // Bitwise OR
  1178. {
  1179. value->setResponse(_itoa(SMART_TRIM_ON,buffer,10));
  1180. theCurrentState = (USHORT) cur_state; // SMART_TRIM_ON;
  1181. }
  1182. else if (SMARTTRIMMASK & theCurrentState)
  1183. {
  1184. value->setResponse(_itoa(SMART_TRIM_OFF,buffer,10));
  1185. theCurrentState = (USHORT) cur_state; // SMART_TRIM_OFF;
  1186. }
  1187. else
  1188. value->setResponse(_itoa(SMART_TRIM_OFF,buffer,10));
  1189. return ErrNO_ERROR;
  1190. }
  1191. INT RedundancyConditionPollParam :: ProcessValue(PMessage value, List* )
  1192. {
  1193. char buffer[20];
  1194. int cur_condition = UtilHexStringToInt(value->getResponse());
  1195. if ( REDUNDANCY_FAILED_MASK & cur_condition ) // Bitwise OR
  1196. {
  1197. value->setResponse(_itoa(REDUNDANCY_FAILED,buffer,10));
  1198. theCurrentState = (USHORT) cur_condition;
  1199. }
  1200. else if (REDUNDANCY_FAILED_MASK & theCurrentState)
  1201. {
  1202. value->setResponse(_itoa(REDUNDANCY_OK,buffer,10));
  1203. theCurrentState = (USHORT) cur_condition;
  1204. }
  1205. else
  1206. value->setResponse(_itoa(REDUNDANCY_OK,buffer,10));
  1207. return ErrNO_ERROR;
  1208. }
  1209. INT IMInstallationStatusPollParam :: ProcessValue(PMessage value, List* )
  1210. {
  1211. char buffer[20];
  1212. int cur_state = UtilHexStringToInt(value->getResponse());
  1213. if ( RIM_IN_CONTROL_MASK & cur_state ) // Bitwise OR
  1214. {
  1215. if (IM_FAILED_MASK & cur_state)
  1216. {
  1217. value->setResponse(_itoa(IM_INSTALLED,buffer,10));
  1218. theCurrentState = (USHORT) cur_state;
  1219. }
  1220. else
  1221. {
  1222. value->setResponse(_itoa(IM_NOT_INSTALLED,buffer,10));
  1223. theCurrentState = (USHORT) cur_state;
  1224. }
  1225. }
  1226. else
  1227. {
  1228. value->setResponse(_itoa(IM_INSTALLED,buffer,10));
  1229. }
  1230. return ErrNO_ERROR;
  1231. }
  1232. INT IMStatusPollParam :: ProcessValue(PMessage value, List* )
  1233. {
  1234. char buffer[20];
  1235. int cur_state = UtilHexStringToInt(value->getResponse());
  1236. if (IM_FAILED_MASK & cur_state) {
  1237. value->setResponse(_itoa(IM_FAILED,buffer,10));
  1238. }
  1239. else {
  1240. value->setResponse(_itoa(IM_OK,buffer,10));
  1241. }
  1242. return ErrNO_ERROR;
  1243. }
  1244. INT RIMStatusPollParam :: ProcessValue(PMessage value, List* )
  1245. {
  1246. char buffer[20];
  1247. int cur_state = UtilHexStringToInt(value->getResponse());
  1248. if ( RIM_FAILED_MASK & cur_state ) // Bitwise OR
  1249. {
  1250. value->setResponse(_itoa(RIM_FAILED,buffer,10));
  1251. theCurrentState = (USHORT) cur_state;
  1252. }
  1253. else {
  1254. value->setResponse(_itoa(RIM_OK,buffer,10));
  1255. }
  1256. return ErrNO_ERROR;
  1257. }
  1258. INT SystemFanStatusPollParam :: ProcessValue(PMessage value, List* )
  1259. {
  1260. char buffer[20];
  1261. int cur_state = UtilHexStringToInt(value->getResponse());
  1262. if ( SYSTEM_FAN_FAILED_MASK & cur_state ) // Bitwise OR
  1263. {
  1264. value->setResponse(_itoa(SYSTEM_FAN_FAILED,buffer,10));
  1265. theCurrentState = (USHORT) cur_state;
  1266. }
  1267. else if (SYSTEM_FAN_FAILED_MASK & theCurrentState)
  1268. {
  1269. value->setResponse(_itoa(SYSTEM_FAN_OK,buffer,10));
  1270. theCurrentState = (USHORT) cur_state;
  1271. }
  1272. else
  1273. value->setResponse(_itoa(SYSTEM_FAN_OK,buffer,10));
  1274. return ErrNO_ERROR;
  1275. }
  1276. INT BypassContactorStatusPollParam :: ProcessValue(PMessage value, List* )
  1277. {
  1278. char buffer[20];
  1279. int cur_state = UtilHexStringToInt(value->getResponse());
  1280. if (BYPASS_STUCK_MASK & cur_state ) // Bitwise OR
  1281. {
  1282. value->setResponse(_itoa(SYSTEM_FAN_FAILED,buffer,10));
  1283. theCurrentState = (USHORT) cur_state;
  1284. }
  1285. else if (SYSTEM_FAN_FAILED_MASK & theCurrentState)
  1286. {
  1287. value->setResponse(_itoa(BYPASS_CONTACTOR_FAILED,buffer,10));
  1288. theCurrentState = (USHORT) cur_state;
  1289. }
  1290. else
  1291. value->setResponse(_itoa(BYPASS_CONTACTOR_OK, buffer,10));
  1292. return ErrNO_ERROR;
  1293. }
  1294. INT InputBreakerTrippedStatusPollParam :: ProcessValue(PMessage value, List* )
  1295. {
  1296. char buffer[20];
  1297. int cur_state = UtilHexStringToInt(value->getResponse());
  1298. if (INPUT_BREAKER_TRIPPED_MASK & cur_state ) // Bitwise OR
  1299. {
  1300. value->setResponse(_itoa(BREAKER_OPEN,buffer,10));
  1301. theCurrentState = (USHORT) cur_state;
  1302. }
  1303. else if (INPUT_BREAKER_TRIPPED_MASK & theCurrentState)
  1304. {
  1305. value->setResponse(_itoa(BREAKER_CLOSED,buffer,10));
  1306. theCurrentState = (USHORT) cur_state;
  1307. }
  1308. else
  1309. value->setResponse(_itoa(BREAKER_CLOSED, buffer,10));
  1310. return ErrNO_ERROR;
  1311. }
  1312. INT UPSModuleStatusPollParam :: ProcessValue(PMessage value, List* )
  1313. {
  1314. char buffer[20];
  1315. int cur_state = UtilHexStringToInt(value->getResponse());
  1316. if ( FAILED_UPS_MASK & cur_state ) // Bitwise OR
  1317. {
  1318. value->setResponse(_itoa(UPS_MODULE_FAILED,buffer,10));
  1319. theCurrentState = (USHORT) cur_state;
  1320. }
  1321. else if (FAILED_UPS_MASK & theCurrentState)
  1322. {
  1323. value->setResponse(_itoa(UPS_MODULE_OK,buffer,10));
  1324. theCurrentState = (USHORT) cur_state;
  1325. }
  1326. else
  1327. value->setResponse(_itoa(UPS_MODULE_OK, buffer,10));
  1328. return ErrNO_ERROR;
  1329. }
  1330. INT NumberInstalledInvertersPollParam :: ProcessValue(PMessage value, List* )
  1331. {
  1332. INT err = ErrNO_ERROR;
  1333. PCHAR ups_response = value->getResponse();
  1334. if ( NullTest(value->getResponse()) )
  1335. {
  1336. err = ErrREAD_FAILED;
  1337. }
  1338. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1339. err = ErrNO_VALUE;
  1340. }
  1341. else {
  1342. PCHAR module_counts = _strdup(ups_response);
  1343. PCHAR number_of_inverters = strtok(module_counts, ",");
  1344. value->setResponse(number_of_inverters);
  1345. free (module_counts);
  1346. }
  1347. return err;
  1348. }
  1349. INT NumberBadInvertersPollParam :: ProcessValue(PMessage value, List* )
  1350. {
  1351. INT err = ErrNO_ERROR;
  1352. PCHAR ups_response = value->getResponse();
  1353. if ( NullTest(value->getResponse()) )
  1354. {
  1355. err = ErrREAD_FAILED;
  1356. }
  1357. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1358. err = ErrNO_VALUE;
  1359. }
  1360. else {
  1361. PCHAR module_counts = _strdup(ups_response);
  1362. // Number of bad inverters is the second parameter in list
  1363. PCHAR number_of_bad_inverters = strtok(module_counts, ",");
  1364. number_of_bad_inverters = strtok(NULL, ",");
  1365. value->setResponse(number_of_bad_inverters);
  1366. free (module_counts);
  1367. }
  1368. return err;
  1369. }
  1370. INT RedundancyLevelPollParam :: ProcessValue(PMessage value, List* )
  1371. {
  1372. INT err = ErrNO_ERROR;
  1373. PCHAR ups_response = value->getResponse();
  1374. if ( NullTest(value->getResponse()) )
  1375. {
  1376. err = ErrREAD_FAILED;
  1377. }
  1378. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1379. err = ErrNO_VALUE;
  1380. }
  1381. else {
  1382. PCHAR module_counts = _strdup(ups_response);
  1383. // Remove the first parameter.
  1384. // current redundancy is the second parameter
  1385. PCHAR current_redundancy = strtok(module_counts, ",");
  1386. current_redundancy = strtok(NULL, ",");
  1387. current_redundancy = strtok(NULL, ",");
  1388. value->setResponse(current_redundancy);
  1389. free (module_counts);
  1390. }
  1391. return err;
  1392. }
  1393. INT MinimumRedundancyPollParam :: ProcessValue(PMessage value, List* )
  1394. {
  1395. INT err = ErrNO_ERROR;
  1396. PCHAR ups_response = value->getResponse();
  1397. if ( NullTest(value->getResponse()) )
  1398. {
  1399. err = ErrREAD_FAILED;
  1400. }
  1401. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1402. err = ErrNO_VALUE;
  1403. }
  1404. else {
  1405. PCHAR module_counts = _strdup(ups_response);
  1406. // Remove unwanted parameters.
  1407. // minimum redundancy level is the third parameter
  1408. PCHAR minimum_redundancy = strtok(module_counts, ",");
  1409. minimum_redundancy = strtok(NULL, ",");
  1410. minimum_redundancy = strtok(NULL, ",");
  1411. minimum_redundancy = strtok(NULL, ",");
  1412. value->setResponse(minimum_redundancy);
  1413. free (module_counts);
  1414. }
  1415. return err;
  1416. }
  1417. INT CurrentLoadCapabilityPollParam :: ProcessValue(PMessage value, List* )
  1418. {
  1419. INT err = ErrNO_ERROR;
  1420. PCHAR ups_response = value->getResponse();
  1421. if ( NullTest(value->getResponse()) )
  1422. {
  1423. err = ErrREAD_FAILED;
  1424. }
  1425. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1426. err = ErrNO_VALUE;
  1427. }
  1428. else {
  1429. PCHAR module_counts = _strdup(ups_response);
  1430. // Remove unwanted parameters.
  1431. // current load capability is the fifth parameter
  1432. PCHAR current_load_capability = strtok(module_counts, ",");
  1433. current_load_capability = strtok(NULL, ",");
  1434. current_load_capability = strtok(NULL, ",");
  1435. current_load_capability = strtok(NULL, ",");
  1436. current_load_capability = strtok(NULL, ",");
  1437. value->setResponse(current_load_capability);
  1438. free (module_counts);
  1439. }
  1440. return err;
  1441. }
  1442. INT MaximumLoadCapabilityPollParam :: ProcessValue(PMessage value, List* )
  1443. {
  1444. INT err = ErrNO_ERROR;
  1445. PCHAR ups_response = value->getResponse();
  1446. if ( NullTest(value->getResponse()) )
  1447. {
  1448. err = ErrREAD_FAILED;
  1449. }
  1450. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1451. err = ErrNO_VALUE;
  1452. }
  1453. else {
  1454. PCHAR module_counts = _strdup(ups_response);
  1455. // Remove unwanted parameters.
  1456. // maximum load capability is the sixth parameter
  1457. PCHAR maximum_load_capability = strtok(module_counts, ",");
  1458. maximum_load_capability = strtok(NULL, ",");
  1459. maximum_load_capability = strtok(NULL, ",");
  1460. maximum_load_capability = strtok(NULL, ",");
  1461. maximum_load_capability = strtok(NULL, ",");
  1462. maximum_load_capability = strtok(NULL, ",");
  1463. value->setResponse(maximum_load_capability);
  1464. free (module_counts);
  1465. }
  1466. return err;
  1467. }
  1468. INT RIMInstallationStatusPollParam :: ProcessValue(PMessage value, List* )
  1469. {
  1470. INT err = ErrNO_ERROR;
  1471. PCHAR ups_response = value->getResponse();
  1472. if ( NullTest(value->getResponse()) )
  1473. {
  1474. err = ErrREAD_FAILED;
  1475. }
  1476. else if (_strcmpi(value->getResponse(), "NA") == 0) {
  1477. err = ErrNO_VALUE;
  1478. }
  1479. else {
  1480. PCHAR module_counts = _strdup(ups_response);
  1481. // Remove unwanted parameters.
  1482. // RIM installation state is the seventh parameter
  1483. PCHAR rim_installation_state = strtok(module_counts, ",");
  1484. rim_installation_state = strtok(NULL, ",");
  1485. rim_installation_state = strtok(NULL, ",");
  1486. rim_installation_state = strtok(NULL, ",");
  1487. rim_installation_state = strtok(NULL, ",");
  1488. rim_installation_state = strtok(NULL, ",");
  1489. rim_installation_state = strtok(NULL, ",");
  1490. CHAR buf[10];
  1491. if ((rim_installation_state != NULL) && (_strcmpi(rim_installation_state, "Y") == 0)) {
  1492. value->setResponse(_itoa(RIM_INSTALLED, buf, 10));
  1493. }
  1494. else {
  1495. value->setResponse(_itoa(RIM_NOT_INSTALLED, buf, 10));
  1496. }
  1497. free (module_counts);
  1498. }
  1499. return err;
  1500. }
  1501. INT PhaseAInputVoltagePollParam :: ProcessValue(PMessage value, List* )
  1502. {
  1503. PCHAR ups_response = value->getResponse();
  1504. PCHAR input_voltage_frequency = _strdup(ups_response);
  1505. // Phase A input voltage is the first parameter
  1506. const PCHAR cVoltage_Frequency_Separator = ";";
  1507. const PCHAR cVoltage_Separator = ",";
  1508. PCHAR input_voltages = strtok(input_voltage_frequency,cVoltage_Frequency_Separator);
  1509. PCHAR phase_a_input_voltage = strtok(input_voltages,cVoltage_Separator );
  1510. value->setResponse(phase_a_input_voltage);
  1511. free (input_voltage_frequency);
  1512. return ErrNO_ERROR;
  1513. }
  1514. INT PhaseBInputVoltagePollParam :: ProcessValue(PMessage value, List* )
  1515. {
  1516. PCHAR ups_response = value->getResponse();
  1517. PCHAR input_voltage_frequency = _strdup(ups_response);
  1518. const PCHAR cZeroVoltage = "0.0";
  1519. // Phase B input voltage is the second parameter before the
  1520. // the frequency separator. Phase B input voltage may not
  1521. // be provided in the case of single phase input.
  1522. const PCHAR cVoltage_Parameter_Separator = ",";
  1523. const PCHAR cVoltage_Frequency_Separator = ";";
  1524. PCHAR input_voltages = strtok(input_voltage_frequency,cVoltage_Frequency_Separator );
  1525. PCHAR phase_b_input_voltage = strtok(input_voltages, cVoltage_Parameter_Separator);
  1526. if (phase_b_input_voltage != NULL)
  1527. {
  1528. phase_b_input_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  1529. if (phase_b_input_voltage == NULL)
  1530. {
  1531. phase_b_input_voltage = cZeroVoltage;
  1532. }
  1533. }
  1534. else
  1535. {
  1536. phase_b_input_voltage = cZeroVoltage;
  1537. }
  1538. value->setResponse(phase_b_input_voltage);
  1539. free (input_voltage_frequency);
  1540. return ErrNO_ERROR;
  1541. }
  1542. INT PhaseCInputVoltagePollParam :: ProcessValue(PMessage value, List* )
  1543. {
  1544. PCHAR ups_response = value->getResponse();
  1545. PCHAR input_voltage_frequency = _strdup(ups_response);
  1546. const PCHAR cZeroVoltage = "0.0";
  1547. // Phase C input voltage is the third parameter before the
  1548. // the frequency separator. Phase C input voltage may not
  1549. // be provided in the case of single phase input.
  1550. const PCHAR cVoltage_Parameter_Separator = ",";
  1551. const PCHAR cFrequency_Parameter_Separator = ";";
  1552. PCHAR input_voltages = strtok(input_voltage_frequency,cFrequency_Parameter_Separator );
  1553. PCHAR phase_c_input_voltage = strtok(input_voltages, cVoltage_Parameter_Separator);
  1554. if (phase_c_input_voltage != NULL)
  1555. {
  1556. phase_c_input_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  1557. if (phase_c_input_voltage != NULL)
  1558. {
  1559. phase_c_input_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  1560. if (phase_c_input_voltage == NULL)
  1561. {
  1562. phase_c_input_voltage = cZeroVoltage;
  1563. }
  1564. }
  1565. else
  1566. {
  1567. phase_c_input_voltage = cZeroVoltage;
  1568. }
  1569. }
  1570. else
  1571. {
  1572. phase_c_input_voltage = cZeroVoltage;
  1573. }
  1574. value->setResponse(phase_c_input_voltage);
  1575. free (input_voltage_frequency);
  1576. return ErrNO_ERROR;
  1577. }
  1578. INT InputFrequencyPollParam :: ProcessValue(PMessage value, List* )
  1579. {
  1580. const PCHAR cFrequency_Parameter_Separator = ";";
  1581. PCHAR ups_response = value->getResponse();
  1582. PCHAR input_voltage_frequency = _strdup(ups_response);
  1583. PCHAR input_voltages = strtok(input_voltage_frequency,cFrequency_Parameter_Separator );
  1584. PCHAR input_frequency = strtok(NULL, cFrequency_Parameter_Separator);
  1585. value->setResponse(input_frequency);
  1586. free (input_voltage_frequency);
  1587. return ErrNO_ERROR;
  1588. }
  1589. INT NumberOfInputPhasesPollParam :: ProcessValue(PMessage value, List* )
  1590. {
  1591. const PCHAR cFrequency_Parameter_Separator = ";";
  1592. const PCHAR cVoltage_Parameter_Separator = ",";
  1593. PCHAR ups_response = value->getResponse();
  1594. PCHAR input_voltage_frequency = _strdup(ups_response);
  1595. PCHAR input_voltages = strtok(input_voltage_frequency,cFrequency_Parameter_Separator );
  1596. input_voltages = strtok(input_voltages, cVoltage_Parameter_Separator);
  1597. input_voltages = strtok(NULL, cVoltage_Parameter_Separator);
  1598. INT number_of_input_phases;
  1599. if (input_voltages != NULL)
  1600. {
  1601. input_voltages = strtok(NULL, cVoltage_Parameter_Separator);
  1602. if (input_voltages != NULL)
  1603. {
  1604. number_of_input_phases = 3;
  1605. }
  1606. else
  1607. {
  1608. number_of_input_phases = 2;
  1609. }
  1610. }
  1611. else
  1612. {
  1613. number_of_input_phases = 1;
  1614. }
  1615. CHAR phases_string[8];
  1616. _itoa(number_of_input_phases,phases_string,10);
  1617. value->setResponse(phases_string);
  1618. free (input_voltage_frequency);
  1619. return ErrNO_ERROR;
  1620. }
  1621. INT PhaseAOutputVoltagePollParam :: ProcessValue(PMessage value, List* )
  1622. {
  1623. PCHAR ups_response = value->getResponse();
  1624. PCHAR output_voltage_currents = _strdup(ups_response);
  1625. // Phase A output voltage is the first parameter
  1626. const PCHAR cVoltage_Current_Separator = ";";
  1627. const PCHAR cVoltage_Separator = ",";
  1628. PCHAR output_voltages = strtok(output_voltage_currents,cVoltage_Current_Separator);
  1629. PCHAR phase_a_output_voltage = strtok(output_voltages,cVoltage_Separator );
  1630. value->setResponse(phase_a_output_voltage);
  1631. free (output_voltage_currents);
  1632. return ErrNO_ERROR;
  1633. }
  1634. INT PhaseBOutputVoltagePollParam :: ProcessValue(PMessage value, List* )
  1635. {
  1636. PCHAR ups_response = value->getResponse();
  1637. PCHAR output_voltage_current = _strdup(ups_response);
  1638. const PCHAR cZeroVoltage = "0.0";
  1639. // Phase B output voltage is the second parameter
  1640. // Phase B output voltage may not be provided in
  1641. // the case of single phase input.
  1642. const PCHAR cVoltage_Parameter_Separator = ",";
  1643. const PCHAR cVoltage_Current_Separator = ";";
  1644. PCHAR output_voltages = strtok(output_voltage_current,cVoltage_Current_Separator );
  1645. PCHAR phase_b_output_voltage = strtok(output_voltages, cVoltage_Parameter_Separator);
  1646. if (phase_b_output_voltage != NULL)
  1647. {
  1648. phase_b_output_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  1649. if (phase_b_output_voltage == NULL)
  1650. {
  1651. phase_b_output_voltage = cZeroVoltage;
  1652. }
  1653. }
  1654. else
  1655. {
  1656. phase_b_output_voltage = cZeroVoltage;
  1657. }
  1658. value->setResponse(phase_b_output_voltage);
  1659. free (output_voltage_current);
  1660. return ErrNO_ERROR;
  1661. }
  1662. INT PhaseCOutputVoltagePollParam :: ProcessValue(PMessage value, List* )
  1663. {
  1664. PCHAR ups_response = value->getResponse();
  1665. PCHAR output_voltage_current = _strdup(ups_response);
  1666. // Phase C output voltage is the third parameter before the
  1667. // the current separator. Phase C output voltage may not
  1668. // be provided in the case of single phase output.
  1669. const PCHAR cVoltage_Parameter_Separator = ",";
  1670. const PCHAR cVoltage_Current_Separator = ";";
  1671. const PCHAR cZeroVoltage = "0.0";
  1672. PCHAR output_voltages = strtok(output_voltage_current, cVoltage_Current_Separator);
  1673. PCHAR phase_c_output_voltage = strtok(output_voltages, cVoltage_Parameter_Separator);
  1674. if (phase_c_output_voltage != NULL)
  1675. {
  1676. phase_c_output_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  1677. if (phase_c_output_voltage != NULL)
  1678. {
  1679. phase_c_output_voltage = strtok(NULL, cVoltage_Parameter_Separator);
  1680. if (phase_c_output_voltage == NULL)
  1681. {
  1682. phase_c_output_voltage = cZeroVoltage;
  1683. }
  1684. }
  1685. else
  1686. {
  1687. phase_c_output_voltage = cZeroVoltage;
  1688. }
  1689. }
  1690. else
  1691. {
  1692. phase_c_output_voltage = cZeroVoltage;
  1693. }
  1694. value->setResponse(phase_c_output_voltage);
  1695. free (output_voltage_current);
  1696. return ErrNO_ERROR;
  1697. }
  1698. INT NumberOfOutputPhasesPollParam :: ProcessValue(PMessage value, List* )
  1699. {
  1700. const PCHAR cCurrent_Parameter_Separator = ";";
  1701. const PCHAR cVoltage_Parameter_Separator = ",";
  1702. PCHAR ups_response = value->getResponse();
  1703. PCHAR output_voltage_current = _strdup(ups_response);
  1704. PCHAR output_voltages = strtok(output_voltage_current,cCurrent_Parameter_Separator );
  1705. output_voltages = strtok(output_voltages,cVoltage_Parameter_Separator);
  1706. output_voltages = strtok(NULL,cVoltage_Parameter_Separator);
  1707. INT number_of_output_phases;
  1708. if (output_voltages != NULL)
  1709. {
  1710. output_voltages = strtok(NULL,cVoltage_Parameter_Separator);
  1711. if (output_voltages != NULL)
  1712. {
  1713. number_of_output_phases = 3;
  1714. }
  1715. else
  1716. {
  1717. number_of_output_phases = 2;
  1718. }
  1719. }
  1720. else
  1721. {
  1722. number_of_output_phases = 1;
  1723. }
  1724. CHAR phases_string[8];
  1725. _itoa(number_of_output_phases,phases_string,10);
  1726. value->setResponse(phases_string);
  1727. free (output_voltage_current);
  1728. return ErrNO_ERROR;
  1729. }
  1730. #if (C_OS & C_OS2)
  1731. INT BattCalibrateCondPollParam:: ProcessValue(PMessage value, List* )
  1732. #else
  1733. INT BattCalibrationCondPollParam:: ProcessValue(PMessage value, List* )
  1734. #endif
  1735. {
  1736. char buffer[20];
  1737. int cur_state = UtilHexStringToInt(value->getResponse());
  1738. if ( BATTERYCALIBRATIONMASK & cur_state ) // Bitwise OR
  1739. {
  1740. value->setResponse(_itoa(BATTERY_CALIBRATION_IN_PROGRESS,buffer,10));
  1741. theCurrentState = BATTERY_CALIBRATED;
  1742. }
  1743. else if (BATTERYCALIBRATIONMASK & theCurrentState)
  1744. {
  1745. value->setResponse(_itoa(NO_BATTERY_CALIBRATION_IN_PROGRESS,buffer,10));
  1746. theCurrentState = NO_BATTERY_CALIBRATION;
  1747. }
  1748. return ErrNO_ERROR;
  1749. }
  1750. INT StateRegisterPollParam:: IsPollSet()
  1751. {
  1752. if (!thePollSet)
  1753. {
  1754. thePollSet = TRUE;
  1755. return ErrSTATE_SET;
  1756. }
  1757. return ErrSAME_VALUE;
  1758. }
  1759. INT StateRegisterPollParam:: ProcessValue(PMessage value, List* events)
  1760. {
  1761. int event_code = 0;
  1762. int event_value = 0;
  1763. int err = ErrCONTINUE;
  1764. if ( NullTest(value->getResponse()) )
  1765. return ErrREAD_FAILED;
  1766. if (!events) {
  1767. return ErrNO_VALUE;
  1768. }
  1769. int cur_state = 0;
  1770. if (sscanf(value->getResponse(),"%x",&cur_state) == EOF) {
  1771. return ErrREAD_FAILED;
  1772. }
  1773. CHAR cause[32];
  1774. if ( COMPSELECTBYPASSMASK & cur_state ) // Bitwise OR
  1775. {
  1776. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1777. if (tmp != NULL) {
  1778. sprintf(cause, "%d", BYPASS_BY_SOFTWARE);
  1779. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1780. events->Append(tmp);
  1781. }
  1782. }
  1783. else if (COMPSELECTBYPASSMASK & theCurrentState) {
  1784. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1785. if (tmp != NULL) {
  1786. sprintf(cause, "%d", BYPASS_BY_SOFTWARE);
  1787. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1788. events->Append(tmp);
  1789. }
  1790. }
  1791. if ( SWITCHEDBYPASSMASK & cur_state ) // Bitwise OR
  1792. {
  1793. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1794. if (tmp != NULL) {
  1795. sprintf(cause, "%d", BYPASS_BY_SWITCH);
  1796. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1797. events->Append(tmp);
  1798. }
  1799. }
  1800. else if (SWITCHEDBYPASSMASK & theCurrentState) {
  1801. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1802. if (tmp != NULL) {
  1803. sprintf(cause, "%d", BYPASS_BY_SWITCH);
  1804. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1805. events->Append(tmp);
  1806. }
  1807. }
  1808. theCurrentState = (USHORT) cur_state;
  1809. //
  1810. // Convert value from HEX to decimal for every one else
  1811. //
  1812. CHAR int_value[32];
  1813. sprintf(int_value, "%d", cur_state);
  1814. value->setResponse(int_value);
  1815. return err;
  1816. }
  1817. INT TripRegisterPollParam:: IsPollSet()
  1818. {
  1819. if (!thePollSet)
  1820. {
  1821. thePollSet = TRUE;
  1822. return ErrTRIP_SET;
  1823. }
  1824. return ErrSAME_VALUE;
  1825. }
  1826. INT TripRegisterPollParam:: ProcessValue(PMessage value, List* events)
  1827. {
  1828. int event_code = 0;
  1829. int event_value = 0;
  1830. int err = ErrCONTINUE;
  1831. if ( NullTest(value->getResponse()) )
  1832. return ErrREAD_FAILED;
  1833. if (!events) {
  1834. return ErrNO_VALUE;
  1835. }
  1836. int cur_state = 0;
  1837. if (sscanf(value->getResponse(),"%x",&cur_state) == EOF) {
  1838. return ErrREAD_FAILED;
  1839. }
  1840. CHAR cause[32];
  1841. if ( OVERTEMPMASK & cur_state ) // Bitwise OR
  1842. {
  1843. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1844. if (tmp != NULL) {
  1845. sprintf(cause, "%d", BYPASS_BY_INTERNAL_TEMP);
  1846. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1847. events->Append(tmp);
  1848. }
  1849. }
  1850. else if (OVERTEMPMASK & theCurrentState) {
  1851. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1852. if (tmp != NULL) {
  1853. sprintf(cause, "%d", BYPASS_BY_INTERNAL_TEMP);
  1854. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1855. events->Append(tmp);
  1856. }
  1857. }
  1858. if ( BATTERYCHARGERMASK & cur_state ) // Bitwise OR
  1859. {
  1860. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1861. if (tmp != NULL) {
  1862. sprintf(cause, "%d", BYPASS_BY_BATT_CHARGER_FAILED);
  1863. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1864. events->Append(tmp);
  1865. }
  1866. }
  1867. else if (BATTERYCHARGERMASK & theCurrentState) {
  1868. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1869. if (tmp != NULL) {
  1870. sprintf(cause, "%d", BYPASS_BY_BATT_CHARGER_FAILED);
  1871. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1872. events->Append(tmp);
  1873. }
  1874. }
  1875. theCurrentState = (USHORT) cur_state;
  1876. //
  1877. // Convert value from HEX to decimal for every one else
  1878. //
  1879. CHAR int_value[32];
  1880. sprintf(int_value, "%d", cur_state);
  1881. value->setResponse(int_value);
  1882. return err;
  1883. }
  1884. INT Trip1RegisterPollParam:: IsPollSet()
  1885. {
  1886. if (!thePollSet)
  1887. {
  1888. thePollSet = TRUE;
  1889. return ErrTRIP1_SET;
  1890. }
  1891. return ErrSAME_VALUE;
  1892. }
  1893. INT Trip1RegisterPollParam:: ProcessValue(PMessage value, List* events)
  1894. {
  1895. int err = ErrCONTINUE;
  1896. if ( NullTest(value->getResponse()) )
  1897. return ErrREAD_FAILED;
  1898. if (!events) {
  1899. return ErrNO_VALUE;
  1900. }
  1901. int cur_state = 0;
  1902. if (sscanf(value->getResponse(),"%x",&cur_state) == EOF) {
  1903. return ErrREAD_FAILED;
  1904. }
  1905. if ( BOTTOMFANFAILUREMASK & cur_state ) // Bitwise OR
  1906. {
  1907. PEvent tmp = new Event(MATRIX_FAN_STATE, FAN_FAILURE_IN_BOTTOM_BOX);
  1908. events->Append(tmp);
  1909. }
  1910. else if (BOTTOMFANFAILUREMASK & theCurrentState) {
  1911. PEvent tmp = new Event(MATRIX_FAN_STATE, FAN_OK);
  1912. events->Append(tmp);
  1913. }
  1914. if ( BYPASSPOWERSUPPLYMASK & cur_state ) // Bitwise OR
  1915. {
  1916. PEvent tmp = new Event(BYPASS_POWER_SUPPLY_CONDITION, BYPASS_POWER_SUPPLY_OK);
  1917. events->Append(tmp);
  1918. }
  1919. else if (BYPASSPOWERSUPPLYMASK & theCurrentState) {
  1920. PEvent tmp = new Event(BYPASS_POWER_SUPPLY_CONDITION, BYPASS_POWER_SUPPLY_FAULT);
  1921. events->Append(tmp);
  1922. }
  1923. CHAR cause[32];
  1924. if ( BYPASSDCIMBALANCEMASK & cur_state ) // Bitwise OR
  1925. {
  1926. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1927. if (tmp != NULL) {
  1928. sprintf(cause, "%d", BYPASS_BY_DC_IMBALANCE);
  1929. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1930. events->Append(tmp);
  1931. }
  1932. }
  1933. else if (BYPASSDCIMBALANCEMASK & theCurrentState) {
  1934. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1935. if (tmp != NULL) {
  1936. sprintf(cause, "%d", BYPASS_BY_DC_IMBALANCE);
  1937. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1938. events->Append(tmp);
  1939. }
  1940. }
  1941. if ( BYPASSOUTPUTLIMITSMASK & cur_state ) // Bitwise OR
  1942. {
  1943. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1944. if (tmp != NULL) {
  1945. sprintf(cause, "%d", BYPASS_BY_VOLTAGE_LIMITS);
  1946. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1947. events->Append(tmp);
  1948. }
  1949. }
  1950. else if (BYPASSOUTPUTLIMITSMASK & theCurrentState) {
  1951. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1952. if (tmp != NULL) {
  1953. sprintf(cause, "%d", BYPASS_BY_VOLTAGE_LIMITS);
  1954. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1955. events->Append(tmp);
  1956. }
  1957. }
  1958. if ( TOPFANFAILUREMASK & cur_state ) // Bitwise OR
  1959. {
  1960. PEvent tmp = new Event(BYPASS_MODE, UPS_ON_BYPASS);
  1961. if (tmp != NULL) {
  1962. sprintf(cause, "%d", BYPASS_BY_TOP_FAN_FAILURE);
  1963. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1964. events->Append(tmp);
  1965. }
  1966. }
  1967. else if (TOPFANFAILUREMASK & theCurrentState) {
  1968. PEvent tmp = new Event(BYPASS_MODE, UPS_NOT_ON_BYPASS);
  1969. if (tmp != NULL) {
  1970. sprintf(cause, "%d", BYPASS_BY_TOP_FAN_FAILURE);
  1971. tmp->AppendAttribute(BYPASS_CAUSE, cause);
  1972. events->Append(tmp);
  1973. }
  1974. }
  1975. theCurrentState = (USHORT) cur_state;
  1976. //
  1977. // Convert value from HEX to decimal for every one else
  1978. //
  1979. CHAR int_value[32];
  1980. sprintf(int_value, "%d", cur_state);
  1981. value->setResponse(int_value);
  1982. return err;
  1983. }
  1984. INT BypassPowerSupplyPollParam:: ProcessValue(PMessage value, List* )
  1985. {
  1986. char buffer[20];
  1987. int cur_state = UtilHexStringToInt(value->getResponse());
  1988. if ( BYPASSPOWERSUPPLYMASK & cur_state ) // Bitwise OR
  1989. {
  1990. value->setResponse(_itoa(BYPASS_POWER_SUPPLY_FAULT,buffer,10));
  1991. theCurrentState = BYPASSPOWERSUPPLYMASK;
  1992. }
  1993. else if (BYPASSPOWERSUPPLYMASK & theCurrentState)
  1994. {
  1995. value->setResponse(_itoa(BYPASS_POWER_SUPPLY_OK,buffer,10));
  1996. theCurrentState = 0;
  1997. }
  1998. return ErrNO_ERROR;
  1999. }
  2000. INT FanFailurePollParam:: ProcessValue(PMessage value, List* )
  2001. {
  2002. char buffer[20];
  2003. int cur_state = UtilHexStringToInt(value->getResponse());
  2004. if ( BOTTOMFANFAILUREMASK & cur_state ) // Bitwise OR
  2005. {
  2006. value->setResponse(_itoa(FAN_FAILURE_IN_BOTTOM_BOX,buffer,10));
  2007. theCurrentState = BOTTOMFANFAILUREMASK;
  2008. }
  2009. else if ( TOPFANFAILUREMASK & cur_state ) // Bitwise OR
  2010. {
  2011. value->setResponse(_itoa(FAN_FAILURE_IN_TOP_BOX,buffer,10));
  2012. theCurrentState = TOPFANFAILUREMASK;
  2013. }
  2014. else if (BYPASSPOWERSUPPLYMASK & theCurrentState)
  2015. {
  2016. value->setResponse(_itoa(FAN_OK,buffer,10));
  2017. theCurrentState = 0;
  2018. }
  2019. return ErrNO_ERROR;
  2020. }
  2021. INT BypassModePollParam:: ProcessValue(PMessage value, List* )
  2022. {
  2023. if ( NullTest(value->getResponse()) )
  2024. return ErrREAD_FAILED;
  2025. if ( (strcmp(value->getResponse(), BYPASS_IN_BYPASS)) &&
  2026. (strcmp(value->getResponse(), BYPASS_OUT_OF_BYPASS)) )
  2027. {
  2028. return ErrINVALID_VALUE;
  2029. }
  2030. return ErrNO_ERROR;
  2031. }
  2032. INT
  2033. MUpsTempPollParam::ProcessValue(
  2034. PMessage value,
  2035. List* )
  2036. {
  2037. INT err = ErrNO_ERROR;
  2038. if ( NullTest(value->getResponse()) ) {
  2039. err = ErrNO_MEASURE_UPS;
  2040. }
  2041. else if ( (strlen(value->getResponse()) != 5) ||
  2042. (((value->getResponse())[2]) != '.')) {
  2043. err = ErrBAD_RESPONSE_VALUE;
  2044. }
  2045. return( err );
  2046. }
  2047. INT
  2048. MUpsHumidityPollParam::ProcessValue(
  2049. PMessage value,
  2050. List* )
  2051. {
  2052. INT err = ErrNO_ERROR;
  2053. if ( NullTest(value->getResponse()) ) {
  2054. err = ErrNO_MEASURE_UPS;
  2055. }
  2056. else if ( (strlen(value->getResponse()) != 5) ||
  2057. (((value->getResponse())[3]) != '.')) {
  2058. err = ErrBAD_RESPONSE_VALUE;
  2059. }
  2060. return( err );
  2061. }
  2062. INT
  2063. MUpsContactPosPollParam::ProcessValue(
  2064. PMessage value,
  2065. List* )
  2066. {
  2067. INT err = ErrNO_ERROR;
  2068. if ( NullTest(value->getResponse()) ) {
  2069. err = ErrNO_MEASURE_UPS;
  2070. }
  2071. else if (strlen(value->getResponse()) != 2) {
  2072. err = ErrBAD_RESPONSE_VALUE;
  2073. }
  2074. return( err );
  2075. }
  2076. INT
  2077. MUpsFirmwareRevPollParam::ProcessValue(
  2078. PMessage value,
  2079. List* )
  2080. {
  2081. INT err = ErrNO_ERROR;
  2082. PCHAR resp = value->getResponse();
  2083. if ( NullTest(resp) ) {
  2084. err = ErrNO_MEASURE_UPS;
  2085. }
  2086. else if ((strlen(resp) != 3) || (resp[0] != '4') || (resp[2] != 'x')) {
  2087. err = ErrBAD_RESPONSE_VALUE;
  2088. }
  2089. #ifdef MUPSCLEANUPFIRMWAREREV
  2090. else {
  2091. char buffer[2];
  2092. buffer[0] = resp[1];
  2093. buffer[1] = '\0';
  2094. value->setResponse(buffer);
  2095. }
  2096. #endif
  2097. return( err );
  2098. }