Remove TODO file
[remote/remote-mci.git] / diku_mch / Mote.cc
blob39e97ec1e8027e0173927c352c20cff3251dad06
1 #include "Mote.h"
3 namespace remote { namespace diku_mch {
5 using namespace remote::util;
7 Mote::Mote(std::string& p_mac, std::string& p_directory)
8 : SerialControl(), mac(p_mac), directory(p_directory)
10 validate();
11 Log::info("Mote %s (%s) @ %s", mac.c_str(), platform.c_str(), path.c_str());
15 bool Mote::isValid()
17 return isvalid;
20 void Mote::invalidate()
22 isvalid = false;
25 void Mote::validate()
27 std::string oldTty = tty;
29 isvalid = true;
30 programmer = directory + "programmer";
31 if (programmer == "" || !File::exists(programmer))
32 isvalid = false;
34 path = File::readFile(directory + "path");
35 if (path == "")
36 isvalid = false;
38 platform = File::readFile(directory + "platform");
39 if (platform == "")
40 isvalid = false;
42 tty = File::readLink(directory + "tty");
43 if (tty == "")
44 isvalid = false;
46 if (!isOpen() && openTty() == FAILURE)
47 isvalid = false;
49 if (!isvalid)
50 Log::warn("Mote %s @ %s is invalid", mac.c_str(), tty.c_str());
54 result_t Mote::program(std::string tos, const uint8_t *image, uint32_t imagelen)
56 std::string filename = getImagePath();
58 if (hasChild())
59 return FAILURE;
61 if (File::writeFile(filename, image, imagelen)) {
62 std::string mac_env = "macaddress=" + mac;
63 std::string tos_env = "tosaddress=" + tos;
64 char * const args[] = {
65 (char *) programmer.c_str(),
66 (char *) tty.c_str(),
67 (char *) filename.c_str(),
68 NULL
70 char * const envp[] = {
71 (char *) mac_env.c_str(),
72 (char *) tos_env.c_str(),
73 NULL
76 Log::info("Programming TTY %s", tty.c_str());
78 if (runChild(args, envp))
79 return SUCCESS;
81 remove(filename.c_str());
84 return FAILURE;
88 const std::string& Mote::getMac()
90 return mac;
93 const std::string& Mote::getDevicePath()
95 return path;
98 const std::string& Mote::getPlatform()
100 return platform;
103 std::string Mote::getImagePath()
105 return directory + "image";