00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <string.h>
00013 #include <OPENR/OPENRAPI.h>
00014 #include <OPENR/OSyslog.h>
00015 #include <OPENR/core_macro.h>
00016 #include "MoNetTest.h"
00017
00018 MoNetTest::MoNetTest() : moNetTestState(MNTS_IDLE), commandQueue()
00019 {
00020 }
00021
00022 OStatus
00023 MoNetTest::DoInit(const OSystemEvent& event)
00024 {
00025 NEW_ALL_SUBJECT_AND_OBSERVER;
00026 REGISTER_ALL_ENTRY;
00027 SET_ALL_READY_AND_NOTIFY_ENTRY;
00028
00029 return oSUCCESS;
00030 }
00031
00032 OStatus
00033 MoNetTest::DoStart(const OSystemEvent& event)
00034 {
00035 if (subject[sbjCommand]->IsReady() == true) {
00036 Execute(STAND2STAND_NULL);
00037 moNetTestState = MNTS_IDLE;
00038 } else {
00039 moNetTestState = MNTS_START;
00040 }
00041
00042 ENABLE_ALL_SUBJECT;
00043 ASSERT_READY_TO_ALL_OBSERVER;
00044
00045 return oSUCCESS;
00046 }
00047
00048 OStatus
00049 MoNetTest::DoStop(const OSystemEvent& event)
00050 {
00051 moNetTestState = MNTS_IDLE;
00052
00053 DISABLE_ALL_SUBJECT;
00054 DEASSERT_READY_TO_ALL_OBSERVER;
00055
00056 return oSUCCESS;
00057 }
00058
00059 OStatus
00060 MoNetTest::DoDestroy(const OSystemEvent& event)
00061 {
00062 DELETE_ALL_SUBJECT_AND_OBSERVER;
00063 return oSUCCESS;
00064 }
00065
00066 void
00067 MoNetTest::ReadyCommand(const OReadyEvent& event)
00068 {
00069 if (moNetTestState == MNTS_START) {
00070 Execute(STAND2STAND_NULL);
00071 moNetTestState = MNTS_IDLE;
00072 }
00073 }
00074
00075 void
00076 MoNetTest::NotifyResult(const ONotifyEvent& event)
00077 {
00078 if (moNetTestState == MNTS_IDLE) {
00079
00080 ;
00081
00082 } else if (moNetTestState == MNTS_START) {
00083
00084 OSYSLOG1((osyslogERROR,
00085 "MoNetTest::NotifyResult() : moNetTestState ERROR\n"));
00086
00087 observer[event.ObsIndex()]->AssertReady();
00088
00089 } else if (moNetTestState == MNTS_WAITING_RESULT) {
00090
00091 MoNetResult* result = (MoNetResult*)event.Data(0);
00092 OSYSPRINT(("MONET RESULT : commandID %d status %d posture %d\n",
00093 result->commandID, result->status, result->posture));
00094
00095 if (commandQueue.size() > 0) {
00096
00097 Execute(commandQueue.front());
00098 commandQueue.pop_front();
00099
00100 } else {
00101
00102 char cmdline[256];
00103 do {
00104 OSYSPRINT(("MoNetTest> "));
00105 gets(cmdline);
00106 } while (strlen(cmdline) == 0);
00107
00108 if (strcmp(cmdline, "shutdown") == 0) {
00109 Execute(SLEEP2SLEEP_NULL);
00110 moNetTestState = MNTS_SHUTDOWN;
00111 } else {
00112 ParseCommandLine(cmdline);
00113 Execute(commandQueue.front());
00114 commandQueue.pop_front();
00115 }
00116 }
00117
00118 observer[event.ObsIndex()]->AssertReady();
00119
00120 } else if (moNetTestState == MNTS_SHUTDOWN) {
00121
00122 OSYSPRINT(("SHUTDOWN ...\n"));
00123 OBootCondition bootCond(obcbPAUSE_SW);
00124 OPENR::Shutdown(bootCond);
00125 }
00126 }
00127
00128 void
00129 MoNetTest::Execute(MoNetCommandID cmdID)
00130 {
00131 MoNetCommand cmd(cmdID);
00132 subject[sbjCommand]->SetData(&cmd, sizeof(cmd));
00133 subject[sbjCommand]->NotifyObservers();
00134 }
00135
00136 void
00137 MoNetTest::ParseCommandLine(char* cmdline)
00138 {
00139 char* ptr= strtok(cmdline, " \t");
00140 commandQueue.push_back(atoi(ptr));
00141
00142 while ((ptr = strtok(0, " \t")) != 0) {
00143 commandQueue.push_back(atoi(ptr));
00144 }
00145 }