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.

297 lines
7.4 KiB

  1. /*
  2. *
  3. * REVISIONS:
  4. *
  5. * cad08Sep93: Fix for setting from front end
  6. * pcy13Sep93: Override SmartUps::HandleLineFail so we dont worry about boost
  7. * cad16Sep93: Fixed state check bug
  8. * pcy18Sep93: Cleaned up include files
  9. * pcy20Sep93: Add line condition to smrt cable event so we dont crash in host
  10. * cad02Nov93: name fix
  11. * cad11Nov93: Making sure all timers are cancelled on destruction
  12. * cad08Jan94: took out get for ups model (virtualized in smartups)
  13. * pcy08Apr94: Trim size, use static iterators, dead code removal
  14. * djs22Feb96: Removed smart trim sensor
  15. */
  16. #include <stdlib.h>
  17. #include "cdefine.h"
  18. #include "_defs.h"
  19. #include "matrix.h"
  20. #include "batpacks.h"
  21. #include "badbatts.h"
  22. #include "bypmodes.h"
  23. #include "timerman.h"
  24. #include "unssens.h"
  25. Matrix::Matrix(PUpdateObj aDeviceController, PCommController aCommController)
  26. : SmartUps(aDeviceController, aCommController),
  27. theIgnoreBattConditionOKFlag(FALSE),
  28. theTimerID(0)
  29. {
  30. theNumberBadBatteriesSensor = new NumberBadBatteriesSensor(this, aCommController);
  31. theBypassModeSensor = new BypassModeSensor(this, aCommController);
  32. }
  33. Matrix::~Matrix()
  34. {
  35. if (theTimerID) {
  36. _theTimerManager->CancelTimer(theTimerID);
  37. theTimerID = 0;
  38. }
  39. delete theNumberBadBatteriesSensor;
  40. theNumberBadBatteriesSensor = NULL;
  41. delete theBypassModeSensor;
  42. theBypassModeSensor = NULL;
  43. }
  44. //-------------------------------------------------------------------------
  45. VOID Matrix::registerForEvents()
  46. {
  47. SmartUps::registerForEvents();
  48. theBypassModeSensor->RegisterEvent(BYPASS_MODE, this);
  49. theNumberBatteryPacksSensor->RegisterEvent(SMART_CELL_SIGNAL_CABLE_STATE, this);
  50. }
  51. //-------------------------------------------------------------------------
  52. INT Matrix::Get(INT code, char *aValue)
  53. {
  54. INT err = ErrINVALID_CODE;
  55. switch(code)
  56. {
  57. // These, however, have no meaning to Matrix
  58. case ALLOWED_LOW_TRANSFER_VOLTAGES:
  59. case MIN_RETURN_CAPACITY:
  60. case ALLOWED_MIN_RETURN_CAPACITIES:
  61. //
  62. // These are not implemented on Matrix so dont ask the SmartUps
  63. // to do them.
  64. break;
  65. case MATRIX_FAN_STATE:
  66. err = ErrUNSUPPORTED;
  67. break;
  68. case BAD_BATTERY_PACKS:
  69. err = theNumberBadBatteriesSensor->Get(code, aValue);
  70. break;
  71. case BYPASS_POWER_SUPPLY_CONDITION:
  72. err = ErrUNSUPPORTED;
  73. break;
  74. case BYPASS_MODE:
  75. err = theBypassModeSensor->Get(code, aValue);
  76. break;
  77. case UPS_FRONT_PANEL_PASSWORD:
  78. err = ErrUNSUPPORTED;
  79. break;
  80. case UPS_RUN_TIME_AFTER_LOW_BATTERY:
  81. err = ErrUNSUPPORTED;
  82. break;
  83. case ALLOWED_UPS_RUN_TIME_AFTER_LOW_BATTERY:
  84. err = ErrUNSUPPORTED;
  85. break;
  86. default:
  87. err = SmartUps::Get(code, aValue);
  88. break;
  89. }
  90. return err;
  91. }
  92. //-------------------------------------------------------------------------
  93. INT Matrix::Set(INT code, const PCHAR aValue)
  94. {
  95. INT err = ErrINVALID_CODE;
  96. switch(code)
  97. {
  98. case LOW_TRANSFER_VOLTAGE:
  99. case ALLOWED_LOW_TRANSFER_VOLTAGES:
  100. case MIN_RETURN_CAPACITY:
  101. case ALLOWED_MIN_RETURN_CAPACITIES:
  102. break;
  103. case BYPASS_MODE:
  104. err = theBypassModeSensor->Set(code, aValue);
  105. break;
  106. case UPS_FRONT_PANEL_PASSWORD:
  107. err = ErrUNSUPPORTED;
  108. break;
  109. case UPS_RUN_TIME_AFTER_LOW_BATTERY:
  110. err = ErrUNSUPPORTED;
  111. break;
  112. default:
  113. err = SmartUps::Set(code, aValue);
  114. break;
  115. }
  116. return err;
  117. }
  118. INT Matrix::Update(PEvent anEvent)
  119. {
  120. switch(anEvent->GetCode()) {
  121. case BYPASS_MODE:
  122. handleBypassModeEvent(anEvent);
  123. break;
  124. case BYPASS_POWER_SUPPLY_CONDITION:
  125. break;
  126. case SMART_CELL_SIGNAL_CABLE_STATE:
  127. handleSmartCellSignalCableStateEvent(anEvent);
  128. break;
  129. default:
  130. SmartUps::Update(anEvent);
  131. break;
  132. }
  133. return ErrNO_ERROR;
  134. }
  135. VOID Matrix::HandleLineConditionEvent(PEvent anEvent)
  136. {
  137. switch(atoi(anEvent->GetValue())) {
  138. case LINE_GOOD:
  139. if (IS_STATE(UPS_STATE_ON_BATTERY)) {
  140. BackUps::HandleLineConditionEvent(anEvent);
  141. }
  142. break;
  143. case LINE_BAD:
  144. {
  145. CHAR value[32];
  146. theBypassModeSensor->Get(BYPASS_MODE, value);
  147. INT bypmode = atoi(value);
  148. if (bypmode != UPS_ON_BYPASS) {
  149. BackUps::HandleLineConditionEvent(anEvent);
  150. }
  151. }
  152. break;
  153. }
  154. }
  155. VOID Matrix::HandleBatteryConditionEvent(PEvent anEvent)
  156. {
  157. CHAR value[32];
  158. theNumberBatteryPacksSensor->DeepGet(value);
  159. INT packs = atoi(value);
  160. // If packs is 0 we assume the smart cell signal cable is not plugged in
  161. // and ignore the battery condition events the UPS puts out (a UPSLink-ism)
  162. if (packs > 0) {
  163. INT val = atoi(anEvent->GetValue());
  164. if((val == BATTERY_BAD) ||
  165. ((val == BATTERY_GOOD) && (theIgnoreBattConditionOKFlag == FALSE))) {
  166. SmartUps::HandleBatteryConditionEvent(anEvent);
  167. }
  168. }
  169. }
  170. VOID Matrix::handleBypassModeEvent(PEvent anEvent)
  171. {
  172. INT bit_to_use = 0;
  173. INT cause = atoi(anEvent->GetAttributeValue(BYPASS_CAUSE));
  174. switch(cause) {
  175. case BYPASS_BY_SOFTWARE:
  176. case BYPASS_BY_SWITCH:
  177. bit_to_use = BYPASS_MAINT_BIT;
  178. break;
  179. case BYPASS_BY_DC_IMBALANCE:
  180. case BYPASS_BY_VOLTAGE_LIMITS:
  181. case BYPASS_BY_TOP_FAN_FAILURE:
  182. case BYPASS_BY_INTERNAL_TEMP:
  183. case BYPASS_BY_BATT_CHARGER_FAILED:
  184. bit_to_use = BYPASS_MODULE_FAILED_BIT;
  185. break;
  186. }
  187. INT val = atoi(anEvent->GetValue());
  188. switch(val) {
  189. case UPS_ON_BYPASS:
  190. SET_BIT(theUpsState, bit_to_use);
  191. break;
  192. case UPS_NOT_ON_BYPASS:
  193. CLEAR_BIT(theUpsState, bit_to_use);
  194. break;
  195. }
  196. UpdateObj::Update(anEvent);
  197. }
  198. VOID Matrix::handleSmartCellSignalCableStateEvent(PEvent anEvent)
  199. {
  200. INT val = atoi(anEvent->GetValue());
  201. switch(val) {
  202. case CHECK_CABLE:
  203. case CABLE_OK:
  204. if(IS_STATE(UPS_STATE_ON_BATTERY)) {
  205. anEvent->AppendAttribute(UTILITY_LINE_CONDITION, LINE_BAD);
  206. }
  207. else {
  208. anEvent->AppendAttribute(UTILITY_LINE_CONDITION, LINE_GOOD);
  209. }
  210. UpdateObj::Update(anEvent);
  211. break;
  212. case IGNORE_BATTERY_GOOD:
  213. {
  214. Event cable_event(SMART_CELL_SIGNAL_CABLE_STATE,
  215. RESPOND_TO_BATTERY_GOOD);
  216. theIgnoreBattConditionOKFlag = TRUE;
  217. theTimerID = _theTimerManager->SetTheTimer(5, &cable_event, this);
  218. UpdateObj::Update(anEvent);
  219. }
  220. break;
  221. case RESPOND_TO_BATTERY_GOOD:
  222. theIgnoreBattConditionOKFlag = FALSE;
  223. break;
  224. }
  225. }
  226. INT Matrix::MakeSmartBoostSensor(const PFirmwareRevSensor rev)
  227. {
  228. //
  229. // Smart-Boost is not supported on the Matrix
  230. //
  231. theSmartBoostSensor = &_theUnsupportedSensor;
  232. return ErrNO_ERROR;
  233. }
  234. INT Matrix::MakeSmartTrimSensor(const PFirmwareRevSensor rev)
  235. {
  236. //
  237. // SmartTrim is not supported on the Matrix
  238. //
  239. theSmartTrimSensor = &_theUnsupportedSensor;
  240. return ErrNO_ERROR;
  241. }
  242. VOID Matrix::reinitialize()
  243. {
  244. SmartUps::reinitialize();
  245. theNumberBadBatteriesSensor->DeepGet();
  246. }