EStopController.cc
Go to the documentation of this file.00001 #include "EStopController.h"
00002 #include "Motion/EmergencyStopMC.h"
00003 #include "Motion/MotionPtr.h"
00004
00005 REGISTER_BEHAVIOR_MENU_OPT(EStopController,"TekkotsuMon",BEH_START|BEH_NONEXCLUSIVE);
00006
00007 EStopController* EStopController::theOne = NULL;
00008
00009 void EStopController::doStart() {
00010
00011 erouter->addListener(this, EventBase::estopEGID);
00012
00013 cmdsock=wireless->socket(Socket::SOCK_STREAM, 300, 300);
00014 wireless->setDaemon(cmdsock,true);
00015 wireless->setReceiver(cmdsock->sock, callback);
00016 wireless->listen(cmdsock->sock, config->main.estopControl_port);
00017 }
00018
00019 void EStopController::doStop() {
00020
00021 wireless->setDaemon(cmdsock,false);
00022 wireless->close(cmdsock);
00023 }
00024
00025 void EStopController::runCommand(const std::string& s) {
00026 if(s==std::string("start")) {
00027 ProjectInterface::estop->setStopped(false);
00028 } else if(s==std::string("stop")) {
00029 ProjectInterface::estop->setStopped(true);
00030 } else if(s==std::string("refresh")) {
00031 if(ProjectInterface::estop->getStopped())
00032 cmdsock->printf("on\n");
00033 else
00034 cmdsock->printf("off\n");
00035 } else {
00036 serr->printf("EStopController::runCommand() - bad message: '%s'",s.c_str());
00037 }
00038 }
00039
00040 void EStopController::doEvent() {
00041 if(event->getTypeID()==EventBase::activateETID) {
00042 cmdsock->printf("on\n");
00043 } else if(event->getTypeID()==EventBase::deactivateETID) {
00044 cmdsock->printf("off\n");
00045 }
00046 }
00047
00048
00049 int EStopController::callback(char *buf, int bytes) {
00050 if(EStopController::theOne==NULL)
00051 return 0;
00052 static std::string cmd;
00053 for(int i=0; i<bytes; i++) {
00054 if(buf[i]=='\n') {
00055 EStopController::theOne->runCommand(cmd);
00056 cmd.clear();
00057 } else
00058 cmd+=buf[i];
00059 }
00060 return 0;
00061 }
00062
00063
00064
00065
00066
00067