00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <OPENR/OPENRAPI.h>
00013 #include <OPENR/OSyslog.h>
00014 #include "PowerMonitor.h"
00015 #include "entry.h"
00016
00017 PowerMonitor::PowerMonitor ()
00018 {
00019 }
00020
00021 OStatus
00022 PowerMonitor::DoInit(const OSystemEvent& event)
00023 {
00024 return oSUCCESS;
00025 }
00026
00027 OStatus
00028 PowerMonitor::DoStart(const OSystemEvent& event)
00029 {
00030 OStatus result;
00031 OPowerStatus currentStatus;
00032
00033 result = OPENR::GetPowerStatus(¤tStatus);
00034 if (result == oSUCCESS) {
00035 PrintPowerStatus(currentStatus);
00036 } else {
00037 OSYSLOG1((osyslogERROR, "%s : %s %d",
00038 "PowerMonitor::DoStart()",
00039 "OPENR::GetPowerStatus() FAILED", result));
00040 }
00041
00042 OPowerStatus observationStatus;
00043 observationStatus.Set(orsbALL,
00044 obsbALL,
00045 opsoREMAINING_CAPACITY_NOT_NOTIFY,
00046 opsoTEMPERATURE_NOT_NOTIFY,
00047 opsoTIME_DIF_NOT_NOTIFY,
00048 opsoVOLUME_NOT_NOTIFY);
00049
00050 OServiceEntry entry(myOID_, Extra_Entry[entryUpdatePowerStatus]);
00051 result = OPENR::ObservePowerStatus(observationStatus, entry);
00052 if(result != oSUCCESS) {
00053 OSYSLOG1((osyslogERROR, "%s : %s %d",
00054 "PowerMonitor::DoStart()",
00055 "OPENR::ObservePowerStatus() FAILED", result));
00056 return oFAIL;
00057 }
00058
00059 return oSUCCESS;
00060 }
00061
00062 OStatus
00063 PowerMonitor::DoStop(const OSystemEvent& event)
00064 {
00065 return oSUCCESS;
00066 }
00067
00068 OStatus
00069 PowerMonitor::DoDestroy(const OSystemEvent& event)
00070 {
00071 return oSUCCESS;
00072 }
00073
00074 void
00075 PowerMonitor::UpdatePowerStatus(void* msg)
00076 {
00077 OPowerStatusMessage *pwsMsg = (OPowerStatusMessage*)msg;
00078 OPowerStatus status = pwsMsg->powerStatus;
00079
00080 if (status.robotStatus & orsbPAUSE ||
00081 status.robotStatus & orsbBATTERY_CAPACITY_LOW) {
00082
00083 PrintPowerStatus(status);
00084
00085 OServiceEntry entry(myOID_, Extra_Entry[entryUpdatePowerStatus]);
00086 OStatus result = OPENR::UnobservePowerStatus(entry);
00087 if(result != oSUCCESS) {
00088 OSYSLOG1((osyslogERROR, "%s : %s %d",
00089 "PowerMonitor::UpdatePowerStatus()",
00090 "OPENR::UnobservePowerStatus() FAILED", result));
00091 }
00092
00093 result = OPENR::SetMotorPower(opowerOFF);
00094 if(result != oSUCCESS) {
00095 OSYSLOG1((osyslogERROR, "%s : %s %d",
00096 "PowerMonitor::UpdatePowerStatus()",
00097 "OPENR::SetMotorPower() FAILED", result));
00098 }
00099
00100 OBootCondition bootCond(obcbPAUSE_SW);
00101 result = OPENR::Shutdown(bootCond);
00102 if(result != oSUCCESS) {
00103 OSYSLOG1((osyslogERROR, "%s : %s %d",
00104 "PowerMonitor::UpdatePowerStatus()",
00105 "OPENR::Shutdown() FAILED", result));
00106 return;
00107 }
00108
00109 OSYSDEBUG(("#########################\n"));
00110 OSYSDEBUG(("### SYSTEM SHUTDOWN ###\n"));
00111 OSYSDEBUG(("#########################\n"));
00112 }
00113 }
00114
00115 void
00116 PowerMonitor::PrintPowerStatus(const OPowerStatus& ps)
00117 {
00118 OSYSDEBUG(("[OPowerStatus]\n"));
00119 OSYSDEBUG((" robotStatus : 0x%08x\n", ps.robotStatus));
00120 OSYSDEBUG((" batteryStatus : 0x%04x\n", ps.batteryStatus));
00121 OSYSDEBUG((" remainingCapacity : %d\n", ps.remainingCapacity));
00122 OSYSDEBUG((" temperature : %d\n", ps.temperature));
00123 OSYSDEBUG((" fullyChargedCapacity : %d\n", ps.fullyChargedCapacity));
00124 OSYSDEBUG((" voltage : %d\n", ps.voltage));
00125 OSYSDEBUG((" current : %d\n", ps.current));
00126 OSYSDEBUG((" timeDif : %d\n", ps.timeDif));
00127 OSYSDEBUG((" volume : %d\n", ps.volume));
00128
00129 OSYSDEBUG(("[ORobotStatus]\n"));
00130 if(ps.robotStatus & orsbPAUSE) {
00131 OSYSDEBUG((" PAUSE\n"));
00132 }
00133 if(ps.robotStatus & orsbMOTOR_POWER) {
00134 OSYSDEBUG((" MOTOR_POWER\n"));
00135 }
00136 if(ps.robotStatus & orsbVIBRATION_DETECT) {
00137 OSYSDEBUG((" VIBRATION_DETECT\n"));
00138 }
00139 if(ps.robotStatus & orsbEX_PORT_CONNECTED) {
00140 OSYSDEBUG((" EX_PORT_CONNECTED\n"));
00141 }
00142 if(ps.robotStatus & orsbSTATION_CONNECTED) {
00143 OSYSDEBUG((" STATION_CONNECTED\n"));
00144 }
00145 if(ps.robotStatus & orsbEX_POWER_CONNECTED) {
00146 OSYSDEBUG((" EX_POWER_CONNECTED\n"));
00147 }
00148 if(ps.robotStatus & orsbBATTERY_CONNECTED) {
00149 OSYSDEBUG((" BATTERY_CONNECTED\n"));
00150 }
00151 if(ps.robotStatus & orsbBATTERY_CHARGING) {
00152 OSYSDEBUG((" BATTERY_CHARGING\n"));
00153 }
00154 if(ps.robotStatus & orsbBATTERY_CAPACITY_FULL) {
00155 OSYSDEBUG((" BATTERY_CAPACITY_FULL\n"));
00156 }
00157 if(ps.robotStatus & orsbBATTERY_CAPACITY_LOW) {
00158 OSYSDEBUG((" BATTERY_CAPACITY_LOW\n"));
00159 }
00160 if(ps.robotStatus & orsbBATTERY_OVER_CURRENT) {
00161 OSYSDEBUG((" BATTERY_OVER_CURRENT\n"));
00162 }
00163 if(ps.robotStatus & orsbBATTERY_OVER_TEMP_DISCHARGING) {
00164 OSYSDEBUG((" BATTERY_OVER_TEMP_DISCHARGING\n"));
00165 }
00166 if(ps.robotStatus & orsbBATTERY_OVER_TEMP_CHARGING) {
00167 OSYSDEBUG((" BATTERY_OVER_TEMP_CHARGING\n"));
00168 }
00169 if(ps.robotStatus & orsbBATTERY_ERROR_OF_CHARGING) {
00170 OSYSDEBUG((" BATTERY_ERROR_OF_CHARGING\n"));
00171 }
00172 if(ps.robotStatus & orsbERROR_OF_PLUNGER) {
00173 OSYSDEBUG((" ERROR_OF_PLUNGER\n"));
00174 }
00175 if(ps.robotStatus & orsbOPEN_R_POWER_GOOD) {
00176 OSYSDEBUG((" OPEN_R_POWER_GOOD\n"));
00177 }
00178 if(ps.robotStatus & orsbERROR_OF_FAN) {
00179 OSYSDEBUG((" ERROR_OF_FAN\n"));
00180 }
00181 if(ps.robotStatus & orsbDATA_STREAM_FROM_STATION) {
00182 OSYSDEBUG((" DATA_STREAM_FROM_STATION\n"));
00183 }
00184 if(ps.robotStatus & orsbREGISTER_UPDATED_BY_STATION) {
00185 OSYSDEBUG((" REGISTER_UPDATED_BY_STATION\n"));
00186 }
00187 if(ps.robotStatus & orsbRTC_ERROR) {
00188 OSYSDEBUG((" RTC_ERROR\n"));
00189 }
00190 if(ps.robotStatus & orsbRTC_OVERFLOW) {
00191 OSYSDEBUG((" RTC_OVERFLOW\n"));
00192 }
00193 if(ps.robotStatus & orsbRTC_RESET) {
00194 OSYSDEBUG((" RTC_RESET\n"));
00195 }
00196 if(ps.robotStatus & orsbRTC_SET) {
00197 OSYSDEBUG((" RTC_SET\n"));
00198 }
00199 if(ps.robotStatus & orsbSPECIAL_MODE) {
00200 OSYSDEBUG((" SPECIAL_MODE\n"));
00201 }
00202 if(ps.robotStatus & orsbBMN_DEBUG_MODE) {
00203 OSYSDEBUG((" BMN_DEBUG_MODE\n"));
00204 }
00205 if(ps.robotStatus & orsbCHARGER_STATUS) {
00206 OSYSDEBUG((" CHARGER_STATUS\n"));
00207 }
00208 if(ps.robotStatus & orsbPLUNGER) {
00209 OSYSDEBUG((" PLUNGER\n"));
00210 }
00211 if(ps.robotStatus & orsbSUSPENDED) {
00212 OSYSDEBUG((" SUSPENDED\n"));
00213 }
00214 if(ps.robotStatus & orsbSPECIAL_DATA_READ_REQ) {
00215 OSYSDEBUG((" SPECIAL_DATA_READ_REQ\n"));
00216 }
00217 }