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.

1465 lines
42 KiB

  1. /*
  2. * cad07Oct93: SU400 changes, added get codes for programming and load sens
  3. * cad12Oct93: Oops, missed one.
  4. * cad02Nov93: name changes
  5. * cad09Nov93: su250/400 fixes
  6. * cad09Nov93: Turn off eeprom access during calibration
  7. * cad11Nov93: Making sure all timers are cancelled on destruction
  8. * cad10Dec93: fix for dip switches changing on the fly
  9. * rct21Dec93: changed determineXferCause() & HandleLineCond...
  10. * cad08Jan94: fixes for sub-sensors, getting ups model from ini file
  11. * ajr15Feb94: fixed TIMED_RUN_TIME_REMAINING case in SmartUps
  12. * pcy04Mar94: fixed overload handling
  13. * cad04Mar94: fixed up eeprom access
  14. * ajr09Mar94: made HandleBatteryConditionEvent check for ErrUNSUPPORTED
  15. * pcy08Apr94: Trim size, use static iterators, dead code removal
  16. * pcy13Apr94: Use automatic variables decrease dynamic mem allocation
  17. * pcy19Apr94: port for SGI
  18. * ajr25Apr94: Some compilers balk at the auto array init....
  19. * ajr24May94: had to explicitly scope dip_sensor->Get for Unixware...
  20. * ajr10Aug94: Could not match with ^\0 in scanf. Had to go with ^# in
  21. * SmartUps::ParseValues
  22. * jps01Oct94: Commented out deepget of boost in reinit: was causing back end to
  23. * miss transitions to/from boost while no comm.
  24. * djs14Mar95: Added OverloadSensor
  25. * ajr03Jun95: Stopped carrying time around in milliseconds
  26. * djs05Feb96: Added firmware rev codes and smarttrim
  27. * cgm29Feb96: Test for Smart mode
  28. * cgm17Apr96: Test return value on GetAllowedValues for a fail
  29. * pcy28Jun96: Added IS_ stuff for menus
  30. * djs12Jul96: Added IS_ stuff for bar graphs
  31. * djs23Sep96: Added check for smart boost off without on battery condition
  32. * djs02Oct96: Added Duet UPS_TEMP check
  33. * jps14Oct96: Changed AUTO_REBOOT_ENABLED ->Get() to ->Set() in Set()
  34. * jps17Oct96: Added low battery event when LOW_BATTERY_DURATION changed to value
  35. * smaller than current run time remaining
  36. * jps15Nov96: Added LIGHTS_TEST test to HandleOverloadConditionEvent(), SIR 4536
  37. * djs19Nov96: Added Battery Calibration Test to Get
  38. * djs01Dec96: Cleaned up processing of Boost/Trim and lost comm
  39. * srt31Jan96: Fixed small bug w/ state test in HandleOverloadCondition.
  40. * srt11Jun97: Added IS_EXT_SLEEP_UPS case
  41. * dma26Nov97: Fixed bug with monitoring a 2G Smart-Ups.
  42. * dma15Dec97: Eliminated Update call in HandleSmartTrimEvent and
  43. * HandleSmartBoostEvent to eliminate duplicate logging
  44. * of SmartTrim/SmartBoost events. Update is now called in our
  45. * new DeepGet
  46. * dma06Jan98: Removed the restraint on UTILITY_LINE_CONDITION case of
  47. * Update which would not allow the battery line condition
  48. * to be updated during a self test.
  49. * clk11Feb98: Changed DeepGet to DeepGetWithoutUpdate in HandleLineCondition
  50. * and added Update to HandleSmartBoost/TrimEvent's
  51. * dma11Feb98: Fixed problem with detecting a battery that needed replacement.
  52. * tjg02Mar98: Added handling for LIGHTS_TEST code to Get
  53. *
  54. * v-stebe 29Jul2000 Fixed PREfix errors (bugs #112610, #112613)
  55. */
  56. #include "cdefine.h"
  57. #include "_defs.h"
  58. #include <stdlib.h>
  59. extern "C" {
  60. #include <stdio.h>
  61. }
  62. #include "smartups.h"
  63. #include "unssens.h"
  64. #include "smrtsens.h"
  65. #include "simpsens.h"
  66. #include "firmrevs.h"
  67. #include "dcfrmrev.h"
  68. #include "timerman.h"
  69. #include "dispatch.h"
  70. #include "cfgmgr.h"
  71. #include "cfgcodes.h"
  72. _CLASSDEF( DeviceController )
  73. _CLASSDEF( UnsupportedSensor )
  74. PList AllowedValuesList;
  75. SmartUps::SmartUps(PUpdateObj aDeviceController, PCommController aCommController)
  76. : BackUps(aDeviceController, aCommController),
  77. pendingEventTimerId(0)
  78. {
  79. INT err = ErrNO_ERROR;
  80. // Turn on Smart Mode
  81. if((err = theCommController->Set(TURN_ON_SMART_MODE, (CHAR*)NULL)) != ErrNO_ERROR) {
  82. theObjectStatus = ErrSMART_MODE_FAILED;
  83. theFirmwareRevSensor = (PFirmwareRevSensor)NULL;
  84. theDecimalFirmwareRevSensor = (PDecimalFirmwareRevSensor)NULL;
  85. theCopyrightSensor = (PSensor)NULL;
  86. theTripRegisterSensor = (PSensor)NULL;
  87. theLightsTestSensor = (PSensor)NULL;
  88. theBatteryReplacementManager = (PBatteryReplacementManager)NULL;
  89. theBatteryCapacitySensor = (PSensor)NULL;
  90. theSmartBoostSensor = (PSensor)NULL;
  91. theRunTimeRemainingSensor = (PSensor)NULL;
  92. theLowBatteryDurationSensor = (PSensor)NULL;
  93. theShutdownDelaySensor = (PSensor)NULL;
  94. theManufactureDateSensor = (PSensor)NULL;
  95. theUpsSerialNumberSensor = (PSensor)NULL;
  96. theTurnOffWithDelaySensor = (PSensor)NULL;
  97. thePutUpsToSleepSensor = (PSensor)NULL;
  98. }
  99. else {
  100. // NEW CODE
  101. theObjectStatus = ErrNO_ERROR;
  102. theFirmwareRevSensor = new FirmwareRevSensor(this, aCommController);
  103. theDecimalFirmwareRevSensor = new DecimalFirmwareRevSensor(this, aCommController);
  104. // New for CTRL Z processing --- JOD
  105. AllowedValuesList = new List();
  106. err = GetAllAllowedValues(AllowedValuesList);
  107. if (err != ErrNO_ERROR) {
  108. theObjectStatus = ErrSMART_MODE_FAILED;
  109. theUpsModelSensor = (PSensor)NULL;
  110. theNumberBatteryPacksSensor = (PSensor)NULL;
  111. theCopyrightSensor = (PSensor)NULL;
  112. theTripRegisterSensor = (PSensor)NULL;
  113. theLightsTestSensor = (PSensor)NULL;
  114. theBatteryReplacementManager = (PBatteryReplacementManager)NULL;
  115. theBatteryCapacitySensor = (PSensor)NULL;
  116. theSmartBoostSensor = (PSensor)NULL;
  117. theRunTimeRemainingSensor = (PSensor)NULL;
  118. theLowBatteryDurationSensor = (PSensor)NULL;
  119. theShutdownDelaySensor = (PSensor)NULL;
  120. theManufactureDateSensor = (PSensor)NULL;
  121. theUpsSerialNumberSensor = (PSensor)NULL;
  122. theTurnOffWithDelaySensor = (PSensor)NULL;
  123. thePutUpsToSleepSensor = (PSensor)NULL;
  124. }
  125. else
  126. {
  127. theUpsModelSensor = new UpsModelSensor(this, theCommController, theFirmwareRevSensor);
  128. theNumberBatteryPacksSensor = new NumberBatteryPacksSensor(this, aCommController,theFirmwareRevSensor);
  129. MakeCopyrightSensor( theFirmwareRevSensor );
  130. if ((theCopyrightSensor != NULL) && ((err = theCopyrightSensor->GetObjectStatus()) != ErrNO_ERROR)) {
  131. theObjectStatus = ErrCOPYRIGHT_RESP_ERROR;
  132. }
  133. theTripRegisterSensor = new TripRegisterSensor(this, aCommController );
  134. theLightsTestSensor = new LightsTestSensor(this, aCommController );
  135. theBatteryReplacementManager = new BatteryReplacementManager(this, aCommController, theFirmwareRevSensor );
  136. MakeBatteryCapacitySensor( theFirmwareRevSensor );
  137. MakeSmartBoostSensor( theFirmwareRevSensor );
  138. MakeSmartTrimSensor( theFirmwareRevSensor );
  139. MakeRunTimeRemainingSensor( theFirmwareRevSensor );
  140. MakeLowBatteryDurationSensor( theFirmwareRevSensor );
  141. MakeShutdownDelaySensor( theFirmwareRevSensor );
  142. MakeManufactureDateSensor( theFirmwareRevSensor );
  143. MakeUpsSerialNumberSensor( theFirmwareRevSensor );
  144. MakeTurnOffWithDelaySensor( theFirmwareRevSensor );
  145. MakePutUpsToSleepSensor();
  146. CHAR programmable[32];
  147. Get(IS_EEPROM_PROGRAMMABLE, programmable);
  148. setEepromAccess((_strcmpi(programmable, "YES") == 0) ? AREAD_WRITE : AREAD_ONLY);
  149. pendingEvent = (PEvent)NULL;
  150. }
  151. if (AllowedValuesList) {
  152. AllowedValuesList->FlushAll();
  153. delete AllowedValuesList;
  154. AllowedValuesList = (List*)NULL;
  155. }
  156. }
  157. }
  158. SmartUps::~SmartUps()
  159. {
  160. if (pendingEventTimerId) {
  161. _theTimerManager->CancelTimer(pendingEventTimerId);
  162. pendingEventTimerId = 0;
  163. }
  164. delete theNumberBatteryPacksSensor;
  165. theNumberBatteryPacksSensor = NULL;
  166. delete theFirmwareRevSensor;
  167. theFirmwareRevSensor = NULL;
  168. delete theDecimalFirmwareRevSensor;
  169. theDecimalFirmwareRevSensor = NULL;
  170. delete theTripRegisterSensor;
  171. theTripRegisterSensor = NULL;
  172. delete theLightsTestSensor;
  173. theLightsTestSensor = NULL;
  174. delete theBatteryReplacementManager;
  175. theBatteryReplacementManager = NULL;
  176. if (theCopyrightSensor && (theCopyrightSensor != &_theUnsupportedSensor)) {
  177. delete theCopyrightSensor;
  178. theCopyrightSensor = NULL;
  179. }
  180. if (theBatteryCapacitySensor && (theBatteryCapacitySensor != &_theUnsupportedSensor)) {
  181. delete theBatteryCapacitySensor;
  182. theBatteryCapacitySensor = NULL;
  183. }
  184. if (theSmartBoostSensor && (theSmartBoostSensor != &_theUnsupportedSensor)) {
  185. delete theSmartBoostSensor;
  186. theSmartBoostSensor = NULL;
  187. }
  188. if (theSmartTrimSensor && (theSmartTrimSensor != &_theUnsupportedSensor)) {
  189. delete theSmartTrimSensor;
  190. theSmartTrimSensor = NULL;
  191. }
  192. if (theRunTimeRemainingSensor && (theRunTimeRemainingSensor != &_theUnsupportedSensor)) {
  193. delete theRunTimeRemainingSensor;
  194. theRunTimeRemainingSensor = NULL;
  195. }
  196. if (theLowBatteryDurationSensor && (theLowBatteryDurationSensor != &_theUnsupportedSensor)) {
  197. delete theLowBatteryDurationSensor;
  198. theLowBatteryDurationSensor = NULL;
  199. }
  200. if (theShutdownDelaySensor && (theShutdownDelaySensor != &_theUnsupportedSensor)) {
  201. delete theShutdownDelaySensor;
  202. theShutdownDelaySensor = NULL;
  203. }
  204. if (theManufactureDateSensor && (theManufactureDateSensor != &_theUnsupportedSensor)) {
  205. delete theManufactureDateSensor;
  206. theManufactureDateSensor = NULL;
  207. }
  208. if (theUpsSerialNumberSensor && (theUpsSerialNumberSensor != &_theUnsupportedSensor)) {
  209. delete theUpsSerialNumberSensor;
  210. theUpsSerialNumberSensor = NULL;
  211. }
  212. if (theTurnOffWithDelaySensor && (theTurnOffWithDelaySensor != &_theUnsupportedSensor)) {
  213. delete theTurnOffWithDelaySensor;
  214. theTurnOffWithDelaySensor = NULL;
  215. }
  216. if (thePutUpsToSleepSensor && (thePutUpsToSleepSensor != &_theUnsupportedSensor)) {
  217. delete thePutUpsToSleepSensor;
  218. thePutUpsToSleepSensor = NULL;
  219. }
  220. delete theUpsModelSensor;
  221. theUpsModelSensor = NULL;
  222. }
  223. //-------------------------------------------------------------------------
  224. VOID SmartUps::registerForEvents()
  225. {
  226. BackUps::registerForEvents();
  227. theCommController->RegisterEvent(COMMUNICATION_STATE, this);
  228. theSmartBoostSensor->RegisterEvent(SMART_BOOST_STATE, this);
  229. theSmartTrimSensor->RegisterEvent(SMART_TRIM_STATE, this);
  230. theLightsTestSensor->RegisterEvent(LIGHTS_TEST, this);
  231. thePutUpsToSleepSensor->RegisterEvent(UPS_OFF_PENDING, this);
  232. theTurnOffWithDelaySensor->RegisterEvent(UPS_OFF_PENDING, this);
  233. theRunTimeRemainingSensor->RegisterEvent(RUN_TIME_REMAINING, this);
  234. theBatteryReplacementManager->RegisterEvent(BATTERY_REPLACEMENT_CONDITION, this);
  235. }
  236. //-------------------------------------------------------------------------
  237. INT SmartUps::Get(INT code, PCHAR aValue)
  238. {
  239. INT err = ErrNO_ERROR;
  240. switch(code)
  241. {
  242. case UTILITY_LINE_CONDITION:
  243. case BATTERY_CONDITION:
  244. case UPS_STATE:
  245. case MAX_BATTERY_RUN_TIME:
  246. case TIME_ON_BATTERY:
  247. err = BackUps::Get(code, aValue);
  248. break;
  249. case BATTERY_CALIBRATION_TEST:
  250. err = ErrUNSUPPORTED;
  251. break;
  252. case IS_UPS_LOAD:
  253. case IS_UTILITY_VOLTAGE:
  254. case IS_OUTPUT_VOLTAGE:
  255. strcpy(aValue,"Yes");
  256. break;
  257. case IS_ADMIN_SHUTDOWN:
  258. err = theFirmwareRevSensor->Get(code, aValue);
  259. break;
  260. case EXTERNAL_PACKS_CHANGEABLE:
  261. err = theFirmwareRevSensor->Get(code, aValue);
  262. break;
  263. case EXTERNAL_BATTERY_PACKS:
  264. err = theNumberBatteryPacksSensor->Get(code,aValue);
  265. break;
  266. case INTERNAL_BATTERY_PACKS:
  267. err = theNumberBatteryPacksSensor->Get(code,aValue);
  268. break;
  269. case TOTAL_BATTERY_PACKS:
  270. err = theNumberBatteryPacksSensor->Get(code, aValue);
  271. break;
  272. case DECIMAL_FIRMWARE_REV:
  273. err = theDecimalFirmwareRevSensor->Get(DECIMAL_FIRMWARE_REV, aValue);
  274. break;
  275. case LIGHTS_TEST:
  276. err = theLightsTestSensor->Get(code, aValue);
  277. break;
  278. case IS_UPS_TEMPERATURE:
  279. {
  280. err = theDecimalFirmwareRevSensor->Get(DECIMAL_FIRMWARE_REV, aValue);
  281. if (err == ErrNO_ERROR)
  282. {
  283. INT first_segment = atoi(strtok(aValue,"."));
  284. // Duet UPSs (b firmware response 10,11,12,21 and 22) do not support UPS temp
  285. if ((first_segment > 9 && first_segment < 13) ||
  286. (first_segment > 20 && first_segment < 23))
  287. {
  288. strcpy(aValue, "NO");
  289. }
  290. else
  291. {
  292. strcpy(aValue, "YES");
  293. }
  294. }
  295. else
  296. {
  297. strcpy(aValue, "YES");
  298. }
  299. err = ErrNO_ERROR;
  300. }
  301. break;
  302. case SELF_TEST_STATE:
  303. case SELF_TEST_DAY:
  304. case SELF_TEST_TIME:
  305. case SELF_TEST_SETTING:
  306. case SELF_TEST_RESULT:
  307. case SELF_TEST_LAST_DATE:
  308. case SELF_TEST_LAST_TIME:
  309. case SELFTEST_LIST:
  310. err = ErrUNSUPPORTED;
  311. break;
  312. case SMART_BOOST_STATE:
  313. err = theSmartBoostSensor->Get(code, aValue);
  314. break;
  315. case SMART_TRIM_STATE:
  316. err = theSmartTrimSensor->Get(code, aValue);
  317. break;
  318. case BATTERY_VOLTAGE:
  319. case RATED_BATTERY_VOLTAGE :
  320. case LOW_BATTERY_VOLTAGE_THRESHOLD:
  321. case HIGH_BATTERY_VOLTAGE_THRESHOLD:
  322. err = ErrUNSUPPORTED;
  323. break;
  324. case BATTERY_CAPACITY:
  325. err = theBatteryCapacitySensor->Get(code, aValue);
  326. break;
  327. case UPS_TEMPERATURE:
  328. err = ErrUNSUPPORTED;
  329. break;
  330. case LOW_UPS_TEMP_THRESHOLD:
  331. err = ErrUNSUPPORTED;
  332. break;
  333. case HIGH_UPS_TEMP_THRESHOLD:
  334. err = ErrUNSUPPORTED;
  335. break;
  336. case LOW_UPS_TEMP_THRESHOLD_ENABLED:
  337. err = ErrUNSUPPORTED;
  338. break;
  339. case HIGH_UPS_TEMP_THRESHOLD_ENABLED:
  340. err = ErrUNSUPPORTED;
  341. break;
  342. case OUTPUT_FREQUENCY:
  343. err = ErrUNSUPPORTED;
  344. break;
  345. case RATED_OUTPUT_VOLTAGE:
  346. case LINE_VOLTAGE:
  347. case MIN_LINE_VOLTAGE:
  348. case MAX_LINE_VOLTAGE:
  349. case OUTPUT_VOLTAGE:
  350. case HIGH_TRANSFER_VOLTAGE:
  351. case LOW_TRANSFER_VOLTAGE:
  352. case ALLOWED_RATED_OUTPUT_VOLTAGES:
  353. case ALLOWED_HIGH_TRANSFER_VOLTAGES:
  354. case ALLOWED_LOW_TRANSFER_VOLTAGES:
  355. err = ErrUNSUPPORTED;
  356. break;
  357. case UPS_LOAD:
  358. err = ErrUNSUPPORTED;
  359. break;
  360. case LOW_LOAD_THRESHOLD:
  361. err = ErrUNSUPPORTED;
  362. break;
  363. case HIGH_LOAD_THRESHOLD:
  364. err = ErrUNSUPPORTED;
  365. break;
  366. case TRIP_REGISTER:
  367. err = theTripRegisterSensor->Get(code, aValue);
  368. break;
  369. case RUN_TIME_REMAINING:
  370. err = theRunTimeRemainingSensor->Get(code, aValue);
  371. break;
  372. case BATTERY_REPLACEMENT_DATE:
  373. case BATTERY_AGE_LIMIT:
  374. err = theBatteryReplacementManager->Get(code, aValue);
  375. break;
  376. case UPS_ID:
  377. err = ErrUNSUPPORTED;
  378. break;
  379. case UPS_SENSITIVITY:
  380. err = ErrUNSUPPORTED;
  381. break;
  382. case ALLOWED_UPS_SENSITIVITIES:
  383. err = ErrUNSUPPORTED;
  384. break;
  385. case LOW_BATTERY_DURATION:
  386. err = theLowBatteryDurationSensor->Get(code, aValue);
  387. break;
  388. case ALLOWED_LOW_BATTERY_DURATIONS:
  389. err = theLowBatteryDurationSensor->Get(ALLOWED_VALUES, aValue);
  390. break;
  391. case ALARM_DELAY:
  392. err = ErrUNSUPPORTED;
  393. break;
  394. case ALLOWED_ALARM_DELAYS:
  395. err = ErrUNSUPPORTED;
  396. break;
  397. case SHUTDOWN_DELAY:
  398. err = theShutdownDelaySensor->Get(code, aValue);
  399. break;
  400. case ALLOWED_SHUTDOWN_DELAYS:
  401. err = theShutdownDelaySensor->Get(ALLOWED_VALUES, aValue);
  402. break;
  403. case TURN_ON_DELAY:
  404. err = ErrUNSUPPORTED;
  405. break;
  406. case ALLOWED_TURN_ON_DELAYS:
  407. err = ErrUNSUPPORTED;
  408. break;
  409. case MIN_RETURN_CAPACITY:
  410. err = ErrUNSUPPORTED;
  411. break;
  412. case ALLOWED_MIN_RETURN_CAPACITIES:
  413. err = ErrUNSUPPORTED;
  414. break;
  415. case DIP_SWITCH_POSITION :
  416. err = ErrUNSUPPORTED;
  417. break;
  418. case COPYRIGHT :
  419. err = theCopyrightSensor->Get(code, aValue);
  420. break;
  421. case MANUFACTURE_DATE :
  422. err = theManufactureDateSensor->Get(code, aValue);
  423. break;
  424. case UPS_SERIAL_NUMBER :
  425. err = theUpsSerialNumberSensor->Get(code, aValue);
  426. break;
  427. case UPS_MODEL :
  428. err = theUpsModelSensor->Get(UPS_MODEL_NAME, aValue);
  429. break;
  430. case TIMED_RUN_TIME_REMAINING:
  431. if(theRunTimeExpiration)
  432. {
  433. // some compilers balk at auto array initialization
  434. CHAR enabled[64];
  435. memset(enabled,(int)'\0',64);
  436. theDeviceController->Get(IS_LINE_FAIL_RUN_TIME_ENABLED,enabled);
  437. if (_strcmpi(enabled,"NO") == 0)
  438. {
  439. err =theRunTimeRemainingSensor->Get(RUN_TIME_REMAINING,
  440. aValue);
  441. }
  442. else
  443. {
  444. err = ErrUNSUPPORTED;
  445. }
  446. }
  447. else
  448. {
  449. err = ErrNO_VALUE;
  450. }
  451. break;
  452. case BATTERY_CALIBRATION_DAY:
  453. case BATTERY_CALIBRATION_TIME:
  454. case BATTERY_CALIBRATION_ENABLED:
  455. case BATTERY_CALIBRATION_LAST_DATE:
  456. case BATTERY_CALIBRATION_LIST:
  457. err = ErrUNSUPPORTED;
  458. break;
  459. case AUTO_REBOOT_ENABLED:
  460. err = theTurnOffUpsOnBatterySensor->Get(code, aValue);
  461. break;
  462. case IS_LOAD_SENSING_ON:
  463. {
  464. strcpy(aValue,"No");
  465. }
  466. break;
  467. case IS_EEPROM_PROGRAMMABLE:
  468. {
  469. strcpy(aValue, "Yes");
  470. }
  471. break;
  472. case TRANSFER_CAUSE:
  473. {
  474. CHAR buf[32];
  475. _itoa(theLastTransferCause, buf, 10);
  476. strcpy(aValue, buf);
  477. err = ErrNO_ERROR;
  478. }
  479. break;
  480. case NUMBER_OF_INPUT_PHASES:
  481. case NUMBER_OF_OUTPUT_PHASES:
  482. {
  483. CHAR buf[32];
  484. _itoa(1, buf, 10);
  485. strcpy(aValue, buf);
  486. err = ErrNO_ERROR;
  487. }
  488. break;
  489. default:
  490. case IS_THIRD_GEN:
  491. case IS_SECOND_GEN:
  492. case IS_FIRST_GEN:
  493. case IS_BACKUPS:
  494. case MAX_VOLTAGE_RANGE_VALUE:
  495. case MIN_VOLTAGE_RANGE_VALUE:
  496. case IS_SELF_TEST:
  497. case IS_LIGHTS_TEST:
  498. case IS_SIMULATE_POWER_FAIL:
  499. case IS_BATTERY_CALIBRATION:
  500. case IS_BYPASS:
  501. case FIRMWARE_REV:
  502. case IS_EXT_SLEEP_UPS:
  503. err = theFirmwareRevSensor->Get(code, aValue);
  504. break;
  505. }
  506. return err;
  507. }
  508. //-------------------------------------------------------------------------
  509. VOID SmartUps:: GetAllowedValue(INT code, CHAR *aValue)
  510. {
  511. FindAllowedValues(code, aValue, (PFirmwareRevSensor) theFirmwareRevSensor );
  512. }
  513. //-------------------------------------------------------------------------
  514. INT SmartUps::Set(INT code, const PCHAR aValue)
  515. {
  516. INT err = ErrNO_ERROR;
  517. switch(code) {
  518. case UPS_ID:
  519. err = ErrUNSUPPORTED;
  520. break;
  521. case BATTERY_REPLACEMENT_DATE:
  522. case BATTERY_AGE_LIMIT:
  523. err = theBatteryReplacementManager->Set(code, aValue);
  524. break;
  525. case HIGH_TRANSFER_VOLTAGE:
  526. case LOW_TRANSFER_VOLTAGE:
  527. case RATED_OUTPUT_VOLTAGE:
  528. err = ErrUNSUPPORTED;
  529. break;
  530. case LOW_LOAD_THRESHOLD:
  531. err = ErrUNSUPPORTED;
  532. break;
  533. case HIGH_LOAD_THRESHOLD:
  534. err = ErrUNSUPPORTED;
  535. break;
  536. case UPS_SENSITIVITY:
  537. err = ErrUNSUPPORTED;
  538. break;
  539. case LOW_BATTERY_DURATION:
  540. err = theLowBatteryDurationSensor->Set(code, aValue);
  541. // see if new low battery warning time is greater than the
  542. // current run time - if so, generate a low battery event
  543. char run_time_rem[32];
  544. if ((err = Get(RUN_TIME_REMAINING, run_time_rem)) == ErrNO_ERROR)
  545. {
  546. int run_time, low_battery;
  547. run_time = atoi(run_time_rem);
  548. low_battery = atoi(aValue) * 60;
  549. if (run_time <= low_battery)
  550. {
  551. PEvent tmp = new Event(BATTERY_CONDITION, BATTERY_BAD);
  552. Update(tmp);
  553. }
  554. }
  555. break;
  556. case ALARM_DELAY:
  557. err = ErrUNSUPPORTED;
  558. break;
  559. case MIN_RETURN_CAPACITY:
  560. err = ErrUNSUPPORTED;
  561. break;
  562. case SHUTDOWN_DELAY:
  563. err = theShutdownDelaySensor->Set(code, aValue);
  564. break;
  565. case TURN_ON_DELAY:
  566. err = ErrUNSUPPORTED;
  567. break;
  568. case SELF_TEST:
  569. if (isOnBattery()) {
  570. err = ErrBATTERYTEST_NOT_AVAIL;
  571. break;
  572. }
  573. // else drop through
  574. case SELF_TEST_DAY:
  575. case SELF_TEST_TIME:
  576. case SELF_TEST_SETTING:
  577. case RESCHEDULE_SELF_TEST:
  578. case SELFTEST_LIST:
  579. err = ErrUNSUPPORTED;
  580. break;
  581. case TURN_OFF_UPS_ON_BATTERY:
  582. err = theTurnOffUpsOnBatterySensor->Set(code, aValue);
  583. break;
  584. case TURN_OFF_UPS_AFTER_DELAY:
  585. err = theTurnOffWithDelaySensor->Set(code, aValue);
  586. break;
  587. case PUT_UPS_TO_SLEEP:
  588. err = thePutUpsToSleepSensor->Set(code, aValue);
  589. break;
  590. case LIGHTS_TEST:
  591. if (isOnBattery()) {
  592. err = ErrLIGHTSTEST_NOT_AVAIL;
  593. }
  594. else {
  595. err = theLightsTestSensor->Set(code, aValue);
  596. }
  597. break;
  598. case BATTERY_CALIBRATION_TEST:
  599. case BATTERY_CALIBRATION_DAY:
  600. case BATTERY_CALIBRATION_TIME:
  601. case BATTERY_CALIBRATION_ENABLED:
  602. case BATTERY_CALIBRATION_LAST_DATE:
  603. case BATTERY_CALIBRATION_LIST:
  604. err = ErrUNSUPPORTED;
  605. break;
  606. case SIMULATE_POWER_FAIL:
  607. err = ErrSIMULATEPOWERFAILURE_NOT_AVAIL;
  608. break;
  609. case AUTO_REBOOT_ENABLED:
  610. err = theTurnOffUpsOnBatterySensor->Set(code, aValue);
  611. break;
  612. case EXTERNAL_BATTERY_PACKS:
  613. err = theNumberBatteryPacksSensor->Set(code,aValue);
  614. break;
  615. default:
  616. err = BackUps::Set(code, aValue);
  617. break;
  618. }
  619. return err;
  620. }
  621. //-------------------------------------------------------------------------
  622. INT SmartUps::Update(PEvent anEvent)
  623. {
  624. switch(anEvent->GetCode())
  625. {
  626. case UTILITY_LINE_CONDITION:
  627. HandleLineConditionEvent(anEvent);
  628. break;
  629. case BATTERY_CONDITION:
  630. HandleBatteryConditionEvent(anEvent);
  631. break;
  632. case LIGHTS_TEST:
  633. HandleLightsTestEvent(anEvent);
  634. break;
  635. case BATTERY_CALIBRATION_CONDITION:
  636. HandleBatteryCalibrationEvent(anEvent);
  637. break;
  638. case SELF_TEST_STATE:
  639. case SELF_TEST_RESULT:
  640. HandleSelfTestEvent(anEvent);
  641. break;
  642. case SMART_BOOST_STATE:
  643. HandleSmartBoostEvent(anEvent);
  644. break;
  645. case SMART_TRIM_STATE:
  646. HandleSmartTrimEvent(anEvent);
  647. break;
  648. case OVERLOAD_CONDITION:
  649. HandleOverloadConditionEvent(anEvent);
  650. break;
  651. case DIP_SWITCH_POSITION:
  652. setEepromAccess((atoi(anEvent->GetValue()) == 0) ? AREAD_WRITE : AREAD_ONLY);
  653. break;
  654. case SIMULATE_POWER_FAIL:
  655. switch(atoi(anEvent->GetValue())) {
  656. case SIMULATE_POWER_FAIL:
  657. SET_BIT(theUpsState, SIMULATE_POWER_FAIL_BIT);
  658. break;
  659. case SIMULATE_POWER_FAIL_OVER:
  660. CLEAR_BIT(theUpsState, SIMULATE_POWER_FAIL_BIT);
  661. break;
  662. }
  663. UpdateObj::Update(anEvent);
  664. break;
  665. case BATTERY_REPLACEMENT_CONDITION:
  666. switch(atoi(anEvent->GetValue())) {
  667. case BATTERY_NEEDS_REPLACING :
  668. SET_BIT(theUpsState, BATTERY_REPLACEMENT_BIT);
  669. break;
  670. case BATTERY_DOESNT_NEED_REPLACING :
  671. CLEAR_BIT(theUpsState, BATTERY_REPLACEMENT_BIT);
  672. break;
  673. }
  674. UpdateObj::Update(anEvent);
  675. break;
  676. case COMMUNICATION_STATE:
  677. switch(atoi(anEvent->GetValue())) {
  678. case COMMUNICATION_ESTABLISHED:
  679. reinitialize();
  680. break;
  681. }
  682. break;
  683. default:
  684. BackUps::Update(anEvent);
  685. break;
  686. }
  687. return ErrNO_ERROR;
  688. }
  689. VOID SmartUps::reinitialize()
  690. {
  691. theFirmwareRevSensor->DeepGet();
  692. theNumberBatteryPacksSensor->DeepGet();
  693. theCopyrightSensor->DeepGet();
  694. theTripRegisterSensor->DeepGet();
  695. theBatteryReplacementManager->Reinitialize();
  696. theBatteryCapacitySensor->DeepGet();
  697. theRunTimeRemainingSensor->DeepGet();
  698. theLowBatteryDurationSensor->DeepGet();
  699. theShutdownDelaySensor->DeepGet();
  700. theManufactureDateSensor->DeepGet();
  701. theUpsSerialNumberSensor->DeepGet();
  702. theUpsModelSensor->DeepGet();
  703. CHAR programmable[32];
  704. Get(IS_EEPROM_PROGRAMMABLE, programmable);
  705. setEepromAccess((_strcmpi(programmable, "YES") == 0) ? AREAD_WRITE : AREAD_ONLY);
  706. }
  707. //-------------------------------------------------------------------------
  708. // Determine status of line and generate an event with this status
  709. //-------------------------------------------------------------------------
  710. VOID SmartUps::HandleLineConditionEvent(PEvent anEvent)
  711. {
  712. switch(atoi(anEvent->GetValue())) {
  713. case LINE_GOOD:
  714. {
  715. CHAR boost[32] = { NULL };
  716. CHAR trim[32] = { NULL };
  717. // Get status of boost and trim from the UPS and
  718. // determine the previous state of trim and boost
  719. INT err_boost = theSmartBoostSensor->DeepGetWithoutUpdate(boost);
  720. INT err_trim = theSmartTrimSensor->DeepGetWithoutUpdate(trim);
  721. INT we_were_on_trim = (IS_STATE(UPS_STATE_ON_TRIM));
  722. INT we_were_on_boost = (IS_STATE(UPS_STATE_ON_BOOST));
  723. //
  724. // Cancel a pending line fail event
  725. //
  726. if (isLineFailPending()) {
  727. _theTimerManager->CancelTimer(pendingEventTimerId);
  728. pendingEventTimerId = 0;
  729. }
  730. if ((err_boost != ErrUNSUPPORTED) &&
  731. (atoi(boost) == SMART_BOOST_ON)) {
  732. setLineGood();
  733. SET_BIT(theUpsState, SMART_BOOST_BIT);
  734. CLEAR_BIT(theUpsState, SMART_TRIM_BIT);
  735. Event boost_event(SMART_BOOST_STATE, SMART_BOOST_ON);
  736. UpdateObj::Update(&boost_event);
  737. theLastTransferCause = BROWNOUT;
  738. BackUps::HandleLineConditionEvent(anEvent);
  739. }
  740. else if ((err_trim != ErrUNSUPPORTED)
  741. && (atoi(trim) == SMART_TRIM_ON)) {
  742. setLineGood();
  743. SET_BIT(theUpsState, SMART_TRIM_BIT);
  744. CLEAR_BIT(theUpsState, SMART_BOOST_BIT);
  745. Event trim_event(SMART_TRIM_STATE, SMART_TRIM_ON);
  746. UpdateObj::Update(&trim_event);
  747. theLastTransferCause = HIGH_LINE_VOLTAGE;
  748. BackUps::HandleLineConditionEvent(anEvent);
  749. }
  750. else if (err_boost != ErrUNSUPPORTED && we_were_on_boost) {
  751. CLEAR_BIT(theUpsState, SMART_BOOST_BIT);
  752. BackUps::HandleLineConditionEvent(anEvent);
  753. }
  754. else if (err_trim != ErrUNSUPPORTED && we_were_on_trim) {
  755. CLEAR_BIT(theUpsState, SMART_TRIM_BIT);
  756. BackUps::HandleLineConditionEvent(anEvent);
  757. }
  758. else if (err_boost != ErrUNSUPPORTED) {
  759. if (pendingEvent) {
  760. UpdateObj::Update(pendingEvent);
  761. }
  762. BackUps::HandleLineConditionEvent(anEvent);
  763. }
  764. else {
  765. BackUps::HandleLineConditionEvent(anEvent);
  766. }
  767. // A LINE_GOOD will void all pending events (see comment in LINE_BAD)
  768. delete pendingEvent;
  769. pendingEvent = NULL;
  770. }
  771. break;
  772. case LINE_BAD:
  773. if(!isLineFailPending()) {
  774. // Start a LINE_BAD timer.
  775. // if the timer expires and the UPS status does not change from
  776. // on battery, then the pending event will handled
  777. pendingEvent = new Event(*anEvent);
  778. pendingEventTimerId = _theTimerManager->SetTheTimer((ULONG)5, anEvent, this);
  779. setLineFailPending();
  780. }
  781. else {
  782. delete pendingEvent;
  783. pendingEvent = (PEvent)NULL;
  784. BackUps::HandleLineConditionEvent(anEvent);
  785. }
  786. break;
  787. case ABNORMAL_CONDITION:
  788. BackUps::HandleLineConditionEvent(anEvent);
  789. break;
  790. default:
  791. break;
  792. }
  793. }
  794. //-------------------------------------------------------------------------
  795. VOID SmartUps::HandleBatteryConditionEvent(PEvent anEvent)
  796. {
  797. CHAR value[32];
  798. INT err = theBatteryCapacitySensor->DeepGet(value);
  799. if (err != ErrUNSUPPORTED) {
  800. anEvent->AppendAttribute(BATTERY_CAPACITY, value);
  801. }
  802. BackUps::HandleBatteryConditionEvent(anEvent);
  803. }
  804. //-------------------------------------------------------------------------
  805. VOID SmartUps::HandleLightsTestEvent(PEvent anEvent)
  806. {
  807. switch(atoi(anEvent->GetValue())) {
  808. case LIGHTS_TEST_IN_PROGRESS:
  809. SET_BIT(theUpsState, LIGHTS_TEST_BIT);
  810. break;
  811. case NO_LIGHTS_TEST_IN_PROGRESS:
  812. CLEAR_BIT(theUpsState, LIGHTS_TEST_BIT);
  813. break;
  814. default:
  815. break;
  816. }
  817. UpdateObj::Update(anEvent);
  818. }
  819. //-------------------------------------------------------------------------
  820. //-------------------------------------------------------------------------
  821. VOID SmartUps::HandleSelfTestEvent(PEvent anEvent)
  822. {
  823. switch(atoi(anEvent->GetValue())) {
  824. case SELF_TEST_IN_PROGRESS:
  825. SET_BIT(theUpsState, SELF_TEST_BIT);
  826. break;
  827. case NO_SELF_TEST_IN_PROGRESS:
  828. CLEAR_BIT(theUpsState, SELF_TEST_BIT);
  829. break;
  830. default:
  831. break;
  832. }
  833. UpdateObj::Update(anEvent);
  834. }
  835. //-------------------------------------------------------------------------
  836. VOID SmartUps::HandleBatteryCalibrationEvent(PEvent anEvent)
  837. {
  838. switch(atoi(anEvent->GetValue())) {
  839. case BATTERY_CALIBRATION_IN_PROGRESS:
  840. SET_BIT(theUpsState, BATTERY_CALIBRATION_BIT);
  841. break;
  842. case NO_BATTERY_CALIBRATION_IN_PROGRESS:
  843. case BATTERY_CALIBRATION_CANCELLED:
  844. // printf("Battery Calibration Cancelled/ended\n");
  845. CLEAR_BIT(theUpsState, BATTERY_CALIBRATION_BIT);
  846. break;
  847. default:
  848. break;
  849. }
  850. UpdateObj::Update(anEvent);
  851. }
  852. //-------------------------------------------------------------------------
  853. VOID SmartUps::HandleSmartBoostEvent(PEvent anEvent)
  854. {
  855. switch(atoi(anEvent->GetValue()))
  856. {
  857. case SMART_BOOST_ON:
  858. // If we're not already on boost, Send the event
  859. if (!(IS_STATE(UPS_STATE_ON_BOOST | UPS_STATE_IN_LIGHTS_TEST)))
  860. {
  861. SET_BIT(theUpsState, SMART_BOOST_BIT);
  862. UpdateObj::Update(anEvent);
  863. }
  864. break;
  865. case SMART_BOOST_OFF:
  866. if (IS_STATE(UPS_STATE_ON_BOOST)) {
  867. CLEAR_BIT(theUpsState, SMART_BOOST_BIT);
  868. UpdateObj::Update(anEvent);
  869. }
  870. break;
  871. // THIS WILL BE HANDLED BY THE HandleLineCondition
  872. default:
  873. break;
  874. }
  875. }
  876. //-------------------------------------------------------------------------
  877. VOID SmartUps::HandleSmartTrimEvent(PEvent anEvent)
  878. {
  879. switch(atoi(anEvent->GetValue()))
  880. {
  881. case SMART_TRIM_ON:
  882. // If we're not already on trim, Send the event
  883. if (!(IS_STATE(UPS_STATE_ON_TRIM | UPS_STATE_IN_LIGHTS_TEST)))
  884. {
  885. SET_BIT(theUpsState, SMART_TRIM_BIT);
  886. UpdateObj::Update(anEvent);
  887. }
  888. break;
  889. case SMART_TRIM_OFF:
  890. if (IS_STATE(UPS_STATE_ON_TRIM)) {
  891. CLEAR_BIT(theUpsState, SMART_TRIM_BIT);
  892. UpdateObj::Update(anEvent);
  893. }
  894. default:
  895. break;
  896. }
  897. }
  898. //-------------------------------------------------------------------------
  899. VOID SmartUps::HandleOverloadConditionEvent(PEvent anEvent)
  900. {
  901. switch(atoi(anEvent->GetValue())) {
  902. case UPS_OVERLOAD:
  903. if (!IS_STATE(UPS_STATE_IN_LIGHTS_TEST))
  904. SET_BIT(theUpsState, OVERLOAD_BIT);
  905. break;
  906. case NO_UPS_OVERLOAD:
  907. CLEAR_BIT(theUpsState, OVERLOAD_BIT);
  908. break;
  909. default:
  910. break;
  911. }
  912. UpdateObj::Update(anEvent);
  913. }
  914. //-------------------------------------------------------------------------
  915. INT SmartUps::MakeBatteryCapacitySensor(const PFirmwareRevSensor rev)
  916. {
  917. INT make_sensor = FALSE;
  918. CHAR Battery_Capacity_Capable[32];
  919. rev->Get(IS_BATTERY_CAPACITY,Battery_Capacity_Capable);
  920. if (_strcmpi(Battery_Capacity_Capable,"Yes") == 0)
  921. {
  922. make_sensor = TRUE;
  923. }
  924. if (make_sensor) {
  925. theBatteryCapacitySensor =
  926. new BatteryCapacitySensor(this, theCommController);
  927. }
  928. else {
  929. theBatteryCapacitySensor = &_theUnsupportedSensor;
  930. }
  931. return ErrNO_ERROR;
  932. }
  933. //-------------------------------------------------------------------------
  934. INT SmartUps::MakeSmartBoostSensor(const PFirmwareRevSensor rev)
  935. {
  936. CHAR Smart_Boost_Capable[32];
  937. rev->Get(IS_SMARTBOOST,Smart_Boost_Capable);
  938. if (_strcmpi(Smart_Boost_Capable, "Yes") == 0)
  939. {
  940. theSmartBoostSensor = new SmartBoostSensor(this, theCommController);
  941. }
  942. else
  943. {
  944. theSmartBoostSensor = &_theUnsupportedSensor;
  945. }
  946. return ErrNO_ERROR;
  947. }
  948. //-------------------------------------------------------------------------
  949. INT SmartUps::MakeSmartTrimSensor(const PFirmwareRevSensor rev)
  950. {
  951. CHAR Smart_Trim_Capable[32];
  952. rev->Get(IS_SMARTTRIM,Smart_Trim_Capable);
  953. if (_strcmpi(Smart_Trim_Capable, "Yes") == 0)
  954. {
  955. theSmartTrimSensor = new SmartTrimSensor (this, theCommController);
  956. }
  957. else
  958. {
  959. theSmartTrimSensor = &_theUnsupportedSensor;
  960. }
  961. return ErrNO_ERROR;
  962. }
  963. //-------------------------------------------------------------------------
  964. INT SmartUps::MakeCopyrightSensor(const PFirmwareRevSensor rev)
  965. {
  966. CHAR Copyright_Capable[32];
  967. rev->Get(IS_COPYRIGHT,Copyright_Capable);
  968. if (_strcmpi(Copyright_Capable, "No") == 0)
  969. {
  970. theCopyrightSensor = &_theUnsupportedSensor;
  971. }
  972. else
  973. {
  974. theCopyrightSensor = new CopyrightSensor(this, theCommController);
  975. }
  976. return ErrNO_ERROR;
  977. }
  978. //-------------------------------------------------------------------------
  979. INT SmartUps::MakeRunTimeRemainingSensor(const PFirmwareRevSensor rev)
  980. {
  981. CHAR Run_Time_Capable[32];
  982. rev->Get(IS_RUNTIME_REMAINING,Run_Time_Capable);
  983. if (_strcmpi(Run_Time_Capable, "No") == 0)
  984. {
  985. theRunTimeRemainingSensor = &_theUnsupportedSensor;
  986. }
  987. else
  988. {
  989. theRunTimeRemainingSensor = new RunTimeRemainingSensor(this, theCommController);
  990. }
  991. return ErrNO_ERROR;
  992. }
  993. //-------------------------------------------------------------------------
  994. INT SmartUps::MakeLowBatteryDurationSensor(const PFirmwareRevSensor rev)
  995. {
  996. CHAR Low_Battery_Duration_Capable[32];
  997. rev->Get(IS_LOW_BATTERY_DURATION,Low_Battery_Duration_Capable);
  998. if (_strcmpi(Low_Battery_Duration_Capable, "No") == 0)
  999. {
  1000. theLowBatteryDurationSensor = &_theUnsupportedSensor;
  1001. }
  1002. else
  1003. {
  1004. theLowBatteryDurationSensor = new LowBatteryDurationSensor(this, theCommController);
  1005. }
  1006. return ErrNO_ERROR;
  1007. }
  1008. //-------------------------------------------------------------------------
  1009. INT SmartUps::MakeShutdownDelaySensor(const PFirmwareRevSensor rev)
  1010. {
  1011. CHAR Shutdown_Delay_Capable[32];
  1012. rev->Get(IS_SHUTDOWN_DELAY,Shutdown_Delay_Capable);
  1013. if (_strcmpi(Shutdown_Delay_Capable, "No") == 0)
  1014. {
  1015. theShutdownDelaySensor = &_theUnsupportedSensor;
  1016. }
  1017. else
  1018. {
  1019. theShutdownDelaySensor = new ShutdownDelaySensor(this, theCommController);
  1020. }
  1021. return ErrNO_ERROR;
  1022. }
  1023. //-------------------------------------------------------------------------
  1024. INT SmartUps::MakeManufactureDateSensor(const PFirmwareRevSensor rev)
  1025. {
  1026. CHAR Manufacture_Date_Capable[32];
  1027. rev->Get(IS_MANUFACTURE_DATE,Manufacture_Date_Capable);
  1028. if (_strcmpi(Manufacture_Date_Capable, "No") == 0)
  1029. {
  1030. theManufactureDateSensor = &_theUnsupportedSensor;
  1031. }
  1032. else
  1033. {
  1034. theManufactureDateSensor = new ManufactureDateSensor(this, theCommController);
  1035. }
  1036. return ErrNO_ERROR;
  1037. }
  1038. //-------------------------------------------------------------------------
  1039. INT SmartUps::MakeUpsSerialNumberSensor(const PFirmwareRevSensor rev)
  1040. {
  1041. CHAR Serial_Number_Capable[32];
  1042. rev->Get(IS_SERIAL_NUMBER,Serial_Number_Capable);
  1043. if (_strcmpi(Serial_Number_Capable, "No") == 0)
  1044. {
  1045. theUpsSerialNumberSensor = &_theUnsupportedSensor;
  1046. }
  1047. else
  1048. {
  1049. theUpsSerialNumberSensor = new UpsSerialNumberSensor(this, theCommController);
  1050. }
  1051. return ErrNO_ERROR;
  1052. }
  1053. //-------------------------------------------------------------------------
  1054. INT SmartUps::MakeTurnOffWithDelaySensor(const PFirmwareRevSensor rev)
  1055. {
  1056. CHAR Turn_Off_Delay_Capable[32];
  1057. rev->Get(IS_TURN_OFF_WITH_DELAY,Turn_Off_Delay_Capable);
  1058. if (_strcmpi(Turn_Off_Delay_Capable, "No") == 0)
  1059. {
  1060. theTurnOffWithDelaySensor = &_theUnsupportedSensor;
  1061. }
  1062. else {
  1063. theTurnOffWithDelaySensor =
  1064. new TurnOffWithDelaySensor(this, theCommController);
  1065. }
  1066. return ErrNO_ERROR;
  1067. }
  1068. //-------------------------------------------------------------------------
  1069. INT SmartUps::MakePutUpsToSleepSensor()
  1070. {
  1071. // SU400/370 and SU250 don't support sleep mode if auto-on
  1072. // is enabled.
  1073. //
  1074. CHAR val[32];
  1075. Get(IS_LOAD_SENSING_ON, val);
  1076. if (_strcmpi(val, "YES") == 0) {
  1077. thePutUpsToSleepSensor = &_theUnsupportedSensor;
  1078. }
  1079. else {
  1080. thePutUpsToSleepSensor =
  1081. new PutUpsToSleepSensor(this, theCommController);
  1082. }
  1083. return ErrNO_ERROR;
  1084. }
  1085. VOID
  1086. SmartUps::setEepromAccess(INT anAccessCode)
  1087. {
  1088. ((PEepromChoiceSensor)theCopyrightSensor)->SetEepromAccess(anAccessCode);
  1089. ((PEepromChoiceSensor)theManufactureDateSensor)->SetEepromAccess(anAccessCode);
  1090. ((PEepromChoiceSensor)theLowBatteryDurationSensor)->SetEepromAccess(anAccessCode);
  1091. ((PEepromChoiceSensor)theShutdownDelaySensor)->SetEepromAccess(anAccessCode);
  1092. ((PEepromChoiceSensor)theUpsSerialNumberSensor)->SetEepromAccess(anAccessCode);
  1093. theBatteryReplacementManager->SetEepromAccess(anAccessCode);
  1094. }
  1095. //-------------------------------------------------------------------------
  1096. // This function is only used when the following function
  1097. // SmartUps:: AllowedValuesAreGettable returns TRUE. This
  1098. // function constructs the EepromAllowedValuesSensor and then
  1099. // parses all the information returned from the sensors DeepGet.
  1100. //
  1101. //-------------------------------------------------------------------------
  1102. INT SmartUps:: GetAllAllowedValues(PList ValueList)
  1103. {
  1104. // Check to see if CTRL Z is an option
  1105. INT cCode = ErrNO_ERROR;
  1106. if (AllowedValuesAreGettable(theFirmwareRevSensor))
  1107. {
  1108. // if CTRL Z load CTRL Z values into non Default values.
  1109. CHAR value[512];
  1110. cCode =theCommController->Get(UPS_ALLOWED_VALUES, value);
  1111. if (cCode == ErrNO_ERROR)
  1112. cCode = ParseValues(value, ValueList);
  1113. }
  1114. return cCode;
  1115. }
  1116. //-------------------------------------------------------------------------
  1117. //
  1118. //-------------------------------------------------------------------------
  1119. INT SmartUps:: ParseValues(CHAR* string, PList ValueList)
  1120. {
  1121. INT Done = FALSE;
  1122. CHAR sensorCode[56];
  1123. CHAR upsType[10];
  1124. CHAR allValues[128];
  1125. while (!Done)
  1126. {
  1127. CHAR value[128];
  1128. string = string+1; // skip the first "#" sign
  1129. INT valsize = strcspn(string,"#");
  1130. strncpy(value,string,valsize);
  1131. value[valsize] = 0;
  1132. if (sscanf(value, "%[^,],%1c,%[^#]",sensorCode, upsType, allValues) != EOF) {
  1133. AllowedValueItem* item = new AllowedValueItem(atoi(sensorCode),
  1134. upsType[0],
  1135. allValues);
  1136. ValueList->Append(item);
  1137. }
  1138. string = string + valsize;
  1139. if (string[1] == 0)
  1140. Done = TRUE;
  1141. }
  1142. return ErrNO_ERROR;
  1143. }
  1144. //-------------------------------------------------------------------------
  1145. // This function checks the firmware revision to determine if the CTRL Z
  1146. // command is valid to use on this UPS.
  1147. //
  1148. //-------------------------------------------------------------------------
  1149. INT SmartUps:: AllowedValuesAreGettable(PSensor theFirmwareRevSensor)
  1150. {
  1151. CHAR CTRL_Z_Capable[32];
  1152. theFirmwareRevSensor->Get(IS_CTRL_Z,CTRL_Z_Capable);
  1153. if (_strcmpi(CTRL_Z_Capable, "No") == 0)
  1154. return FALSE;
  1155. else
  1156. return TRUE;
  1157. }
  1158. VOID SmartUps:: FindAllowedValues(INT code, CHAR *aValue, PFirmwareRevSensor aFirmwareSensor )
  1159. {
  1160. INT Found = FALSE;
  1161. aValue[0] = 0;
  1162. if (AllowedValuesList)
  1163. {
  1164. AllowedValueItem* item = (AllowedValueItem*)AllowedValuesList->GetHead();
  1165. ListIterator iter((RList)*AllowedValuesList);
  1166. while(!Found && item)
  1167. {
  1168. if (item->GetUpsCode() == code)
  1169. {
  1170. CHAR Country_Code[32];
  1171. aFirmwareSensor->Get(COUNTRY_CODE,Country_Code);
  1172. INT cc = atoi(Country_Code);
  1173. if ( (item->GetUpsType() == '4') ||
  1174. ( (INT)item->GetUpsType() == cc) )
  1175. {
  1176. strcpy(aValue, item->GetValue());
  1177. Found = TRUE;
  1178. }
  1179. }
  1180. item = (AllowedValueItem*)iter.Next();
  1181. }
  1182. }
  1183. }
  1184. AllowedValueItem :: AllowedValueItem(INT Code,CHAR Type, CHAR* Value) :
  1185. theUpsType(0),
  1186. theValue((CHAR*)NULL)
  1187. {
  1188. theCode = Code;
  1189. theUpsType = Type;
  1190. theValue = _strdup(Value);
  1191. }
  1192. AllowedValueItem :: ~AllowedValueItem()
  1193. {
  1194. if (theValue)
  1195. free(theValue);
  1196. }