Leaked source code of windows server 2003
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.

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