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.

179 lines
4.5 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. *
  7. * cad08Sep93: Trapping set to handle wierd cases
  8. * cad10Sep93: Simplified, seems to work
  9. * pcy20Sep93: Wait for possible top fan event to occur
  10. * pcy08Apr94: Trim size, use static iterators, dead code removal
  11. * mwh30Jun94: if BYPASS_SOFTWARE sleep 3 secs to see if TOPFANFAILURE (1x)
  12. * mwh30Jun94: had to add unistd.h for sleep on unix
  13. * cgm12Apr96: Add destructor with unregister
  14. * clk24Jun98: In Set, changed Sensor::Set to theCommControllerSet
  15. */
  16. #define INCL_BASE
  17. #define INCL_DOS
  18. #define INCL_NOPM
  19. #include "cdefine.h"
  20. extern "C" {
  21. #if (C_OS & C_OS2)
  22. #include <os2.h>
  23. #endif
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #if (C_OS & C_UNIX)
  27. #include <unistd.h>
  28. #endif
  29. }
  30. #include "bypmodes.h"
  31. #include "comctrl.h"
  32. #include "event.h"
  33. #include "pollparm.h"
  34. #include "timerman.h"
  35. BypassModeSensor :: BypassModeSensor(PDevice aParent, PCommController aCommController)
  36. : StateSensor(aParent, aCommController, BYPASS_MODE, AREAD_WRITE),
  37. theBypassCause(0)
  38. {
  39. #ifdef SINGLETHREADED
  40. theAlreadyOnBypassFlag = 0;
  41. #endif
  42. storeState(UPS_NOT_ON_BYPASS);
  43. theCommController->RegisterEvent(theSensorCode, this);
  44. // We force registering for this cause protocol doesn't handle it
  45. //
  46. theCommController->RegisterEvent(STATE_REGISTER, this);
  47. }
  48. BypassModeSensor :: ~BypassModeSensor()
  49. {
  50. theCommController->UnregisterEvent(theSensorCode, this);
  51. theCommController->UnregisterEvent(STATE_REGISTER, this);
  52. }
  53. #if 0
  54. *** Removed for size concerns. This is really a redundant feature since
  55. *** protocol generates these events
  56. INT BypassModeSensor::Validate(INT aCode, const PCHAR aValue)
  57. {
  58. INT err = ErrNO_ERROR;
  59. if(aCode!=theSensorCode) {
  60. err = ErrINVALID_CODE;
  61. }
  62. else {
  63. err = StateSensor::Validate(aCode, aValue);
  64. }
  65. return err;
  66. }
  67. #endif
  68. INT BypassModeSensor::Update(PEvent anEvent)
  69. {
  70. INT val = atoi(anEvent->GetValue());
  71. switch(val) {
  72. case UPS_ON_BYPASS:
  73. theBypassCause = atoi(anEvent->GetAttributeValue(BYPASS_CAUSE));
  74. //
  75. // Another UPSLinkism. If on bypass by top fan failure, the UPS
  76. // also tells us on bypass by computer select which is what we
  77. // use to indicate a software bypass
  78. //
  79. if(theBypassCause == BYPASS_BY_SOFTWARE) {
  80. CHAR value[32];
  81. #ifdef SINGLETHREADED
  82. if (!theAlreadyOnBypassFlag) {
  83. theAlreadyOnBypassFlag = 1;
  84. #if (C_OS & C_WIN311)
  85. _theTimerManager->Wait(3000L); // changed wait to 3 seconds 3/15/94 jod
  86. #else
  87. sleep(3); // three seconds
  88. #endif
  89. }
  90. #else
  91. _theTimerManager->Wait(3000L); // changed wait to 3 seconds 3/15/94 jod
  92. #endif
  93. theCommController->Get(TRIP1_REGISTER, value);
  94. if(atoi(value) & TOPFANFAILUREMASK) {
  95. anEvent->SetAttributeValue(BYPASS_CAUSE,
  96. BYPASS_BY_TOP_FAN_FAILURE);
  97. theBypassCause = BYPASS_BY_TOP_FAN_FAILURE;
  98. }
  99. }
  100. break;
  101. case UPS_NOT_ON_BYPASS:
  102. #ifdef SINGLETHREADED
  103. theAlreadyOnBypassFlag = 0;
  104. #endif
  105. theBypassCause = 0;
  106. }
  107. return Sensor::Update(anEvent);
  108. }
  109. BypassModeSensor::Get(INT aCode, PCHAR aValue)
  110. {
  111. CHAR state_value[32];
  112. CHAR trip_value[32];
  113. CHAR trip1_value[32];
  114. theCommController->Get(STATE_REGISTER, state_value);
  115. theCommController->Get(TRIP_REGISTER, trip_value);
  116. theCommController->Get(TRIP1_REGISTER, trip1_value);
  117. INT state = 0;
  118. if((atoi(state_value) & (SWITCHEDBYPASSMASK | COMPSELECTBYPASSMASK)) ||
  119. (atoi(trip_value) & (OVERTEMPMASK | BATTERYCHARGERMASK)) ||
  120. (atoi(trip1_value) & (BYPASSDCIMBALANCEMASK | BYPASSOUTPUTLIMITSMASK | TOPFANFAILUREMASK))) {
  121. state = UPS_ON_BYPASS;
  122. }
  123. else {
  124. state = UPS_NOT_ON_BYPASS;
  125. }
  126. sprintf(aValue, "%d", state);
  127. return ErrNO_ERROR;
  128. }
  129. INT BypassModeSensor::Set(const PCHAR aValue)
  130. {
  131. INT err = ErrNO_ERROR;
  132. switch (atoi(aValue)) {
  133. case INITIATE_BYPASS:
  134. // sprintf(buf,"%d",UPS_ON_BYPASS);
  135. // err = StateSensor::Set(buf);
  136. // aValue[0]=0;
  137. err = theCommController->Set(theSensorCode, aValue);
  138. break;
  139. case CANCEL_BYPASS:
  140. // Let real value get set when state change in UPS is detected
  141. // Will cause double events, but should be OK
  142. //
  143. // aValue[0]=0;
  144. err = theCommController->Set(theSensorCode, aValue);
  145. break;
  146. default:
  147. err = ErrINVALID_VALUE;
  148. break;
  149. }
  150. return err;
  151. }