home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2003 March
/
VPR0303A.ISO
/
AIBO
/
AiboBiff2
/
AiboBiff
/
AiboBiff.cc
next >
Wrap
C/C++ Source or Header
|
2002-12-19
|
5KB
|
181 lines
//-----------------------------------------------
// AiboBiff ver.2
// 2002/12/19 Kazuto Sato
//-----------------------------------------------
#include <string.h>
#include <OPENR/OSyslog.h>
#include <OPENR/OPENRAPI.h>
#include <OPENR/core_macro.h>
#include <OPENR/OTime.h>
#include "AiboBiff.h"
#include "entry.h"
AiboBiff::AiboBiff () : biffState(BIFF_IDLE),
moNetTestState(MNTS_IDLE), commandQueue()
{
}
OStatus
AiboBiff::DoInit(const OSystemEvent& event)
{
OSYSDEBUG(("AiboBiff::DoInit()\n"));
NEW_ALL_SUBJECT_AND_OBSERVER;
REGISTER_ALL_ENTRY;
SET_ALL_READY_AND_NOTIFY_ENTRY;
return oSUCCESS;
}
OStatus
AiboBiff::DoStart(const OSystemEvent& event)
{
OSYSDEBUG(("AiboBiff::DoStart()\n"));
if (subject[sbjCommand]->IsReady() == true) {
Execute(SLEEP2SLEEP_NULL);
moNetTestState = MNTS_WAITING_RESULT;
} else {
moNetTestState = MNTS_START;
}
ENABLE_ALL_SUBJECT;
ASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
}
OStatus
AiboBiff::DoStop(const OSystemEvent& event)
{
OSYSDEBUG(("AiboBiff::DoStop()\n"));
biffState = BIFF_IDLE;
moNetTestState = MNTS_IDLE;
DISABLE_ALL_SUBJECT;
DEASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
}
OStatus
AiboBiff::DoDestroy(const OSystemEvent& event)
{
DELETE_ALL_SUBJECT_AND_OBSERVER;
return oSUCCESS;
}
//-------------------------------------------------
// ・サ・オ。シ、ォ、鯏ホ、鬢サ、ア、ソ、鮟エヨ、チ・ァ・テ・ッ
//-------------------------------------------------
void AiboBiff::NotifySensor(const ONotifyEvent& event)
{
static time_t timeLast = 0;
if(biffState == BIFF_READY) {
OTime ot;
OPENR::GetTime(&ot);
time_t t = ot.GetClock();
if(timeLast == 0 ||
t - timeLast >= 5*60) {
char str[20];
strcpy(str, "let's go!");
// MailChecker、ヒ・ウ・゙・ノチョ
subject[sbjMailCheck]->SetData(str, sizeof(str));
subject[sbjMailCheck]->NotifyObservers();
timeLast = t;
}
}
observer[event.ObsIndex()]->AssertReady();
}
//-----------------------------------------------
// MailChecker、隍ス猜K
//-----------------------------------------------
void AiboBiff::ReadyMailCheck(const OReadyEvent& event)
{
OSYSDEBUG(("AiboBiff::ReadyMailCheck()\n"));
}
//-----------------------------------------------
// MailChecker、隍ソキテ螂癸シ・、ホ、ェテホ、鬢サ
//-----------------------------------------------
void AiboBiff::NotifyNewMail(const ONotifyEvent& event)
{
OSYSDEBUG(("AiboBiff::NotifyNewMail()\n"));
char cmd[20];
strcpy(cmd, "2 200 0");
// MoNet、ヒ・ウ・゙・ノチョ
OSYSPRINT(("You have new mail!\n"));
ParseCommandLine(cmd);
Execute(commandQueue.front());
commandQueue.pop_front();
observer[event.ObsIndex()]->AssertReady();
}
//-------------------------------------------------
// ーハイシ。「MoNetTest、隍・ウ・ヤ。シ、キ、ニイツ、
//-------------------------------------------------
void
AiboBiff::ReadyCommand(const OReadyEvent& event)
{
if (moNetTestState == MNTS_START) {
MoNetCommand cmd(SLEEP2SLEEP_NULL);
subject[sbjCommand]->SetData(&cmd, sizeof(cmd));
subject[sbjCommand]->NotifyObservers();
moNetTestState = MNTS_WAITING_RESULT;
}
}
void
AiboBiff::NotifyResult(const ONotifyEvent& event)
{
if (moNetTestState == MNTS_IDLE) {
; // do nothing
} else if (moNetTestState == MNTS_START) {
OSYSLOG1((osyslogERROR,
"MoNetTest::NotifyResult() : moNetTestState ERROR\n"));
observer[event.ObsIndex()]->AssertReady();
} else if (moNetTestState == MNTS_WAITING_RESULT) {
if(biffState == BIFF_IDLE) biffState = BIFF_READY;
MoNetResult* result = (MoNetResult*)event.Data(0);
OSYSPRINT(("MONET RESULT : commandID %d status %d posture %d\n",
result->commandID, result->status, result->posture));
if (commandQueue.size() > 0) {
Execute(commandQueue.front());
commandQueue.pop_front();
}
observer[event.ObsIndex()]->AssertReady();
}
}
void
AiboBiff::Execute(MoNetCommandID cmdID)
{
MoNetCommand cmd(cmdID);
subject[sbjCommand]->SetData(&cmd, sizeof(cmd));
subject[sbjCommand]->NotifyObservers();
}
void
AiboBiff::ParseCommandLine(char* cmdline)
{
char* ptr= strtok(cmdline, " \t");
commandQueue.push_back(atoi(ptr));
while ((ptr = strtok(0, " \t")) != 0) {
commandQueue.push_back(atoi(ptr));
}
}