Initial commit
[remote/remote-mci.git] / diku_mch / Mote.cc
blobab6faa45b62d8f544428dab452c634b0deb8b311
1 #include "Mote.h"
3 namespace remote { namespace diku_mch {
5 Mote::Mote( uint64_t p_macAddress,
6 std::string& p_path,
7 uint16_t p_ttyNum )
8 : SerialControl(p_ttyNum),
9 macAddress(p_macAddress),
10 ttyNum(p_ttyNum),
11 isvalid(true)
13 path = p_path;
14 printf("New mote %x at %s\n",(uint32_t)macAddress,path.c_str());
18 bool Mote::isValid()
20 return isvalid;
23 void Mote::invalidate()
25 isvalid = false;
28 void Mote::validate(std::string& p_path, uint16_t p_ttyNum)
30 isvalid = true;
31 if ( p_path != path )
33 path = p_path;
36 if ( p_ttyNum != ttyNum )
38 Mote* testmote = new Mote(macAddress,path,p_ttyNum);
39 testmote->_open();
40 bool testOpen = testmote->isOpen;
41 testmote->_close();
42 delete testmote;
43 if ( testOpen )
45 printf("Changed ttynum from %u to %u\n",ttyNum,p_ttyNum);
46 ttyNum = p_ttyNum;
47 char nstring[100];
48 sprintf(nstring,Configuration::vm["usbSerialDevicePath"].as<std::string>().c_str(),ttyNum);
49 DeviceName = nstring;
51 if (isOpen)
53 _close();
54 _open();
56 isvalid = isOpen;
59 if (!isvalid) printf("Mote at ttyUSB%u is invalid./n",ttyNum);
62 uint64_t Mote::getMac()
64 return macAddress;
67 uint16_t Mote::getTty()
69 return ttyNum;
72 const std::string& Mote::getPath()
74 return path;