00001 #include <Ice/Ice.h> 00002 #include "Devices/Serial.H" 00003 #include "Component/ModelComponent.H" 00004 #include "Component/ModelManager.H" 00005 #include "Robots/Scorbot/ScorbotSimple.ice.H" 00006 00007 class ScorbotSimpleI: public ScorbotSimpleIce::ScorbotSimple, public ModelComponent 00008 { 00009 public: 00010 ScorbotSimpleI(OptionManager& mgr, 00011 const std::string& descrName = "", 00012 const std::string& tagName = "") : 00013 ModelComponent(mgr, descrName, tagName), 00014 itsSerial(new Serial(mgr)) 00015 { 00016 addSubComponent(itsSerial); 00017 itsSerial->configure("/dev/ttyACM0", 115200, "8N1", false, false, 1000000); 00018 } 00019 00020 bool getState(const Ice::Current&) 00021 { 00022 char cmd = 'a'; 00023 itsSerial->write(&cmd, 1); 00024 usleep(10000); 00025 char retVal; 00026 itsSerial->read(&retVal, 1); 00027 return (retVal == 'B'); 00028 } 00029 00030 void setNext(const Ice::Current&) 00031 { 00032 char cmd = 'b'; 00033 itsSerial->write(&cmd, 1); 00034 } 00035 00036 void reset(const Ice::Current&) 00037 { 00038 char cmd = 'c'; 00039 itsSerial->write(&cmd, 1); 00040 usleep(10000); 00041 } 00042 00043 private: 00044 nub::ref<Serial> itsSerial; 00045 }; 00046 00047 00048 int main(int argc, char** argv) 00049 { 00050 ModelManager manager("ScorbotServerManager"); 00051 nub::ref<ScorbotSimpleI> scorbot(new ScorbotSimpleI(manager)); 00052 manager.addSubComponent(scorbot); 00053 00054 manager.parseCommandLine(argc, argv, "", 0, 0); 00055 manager.start(); 00056 00057 std::string connString("default -p 10000"); 00058 00059 int status = 0; 00060 Ice::CommunicatorPtr ic; 00061 00062 try { 00063 ic = Ice::initialize(argc, argv); 00064 Ice::ObjectAdapterPtr adapter = 00065 ic->createObjectAdapterWithEndpoints( 00066 "ScorbotServerAdapter", connString.c_str()); 00067 Ice::ObjectPtr object = scorbot.get(); 00068 adapter->add(object, ic->stringToIdentity("ScorbotServer")); 00069 adapter->activate(); 00070 ic->waitForShutdown(); 00071 } catch(const Ice::Exception& e) { 00072 std::cerr << e << std::endl; 00073 status = 1; 00074 } catch(const char* msg) { 00075 std::cerr << msg << std::endl; 00076 status = 1; 00077 } 00078 00079 if(ic) { 00080 try { 00081 ic->destroy(); 00082 } catch(const Ice::Exception& e) { 00083 std::cerr << e << std::endl; 00084 status = 1; 00085 } 00086 } 00087 00088 return status; 00089 } 00090