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
)
11 Log::info("Mote %s (%s) @ %s", mac
.c_str(), platform
.c_str(), path
.c_str());
20 void Mote::invalidate()
27 std::string oldTty
= tty
;
30 programmer
= directory
+ "programmer";
31 if (programmer
== "" || !File::exists(programmer
))
34 path
= File::readFile(directory
+ "path");
38 platform
= File::readFile(directory
+ "platform");
42 tty
= File::readLink(directory
+ "tty");
46 if (!isOpen() && openTty() == FAILURE
)
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();
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(),
67 (char *) filename
.c_str(),
70 char * const envp
[] = {
71 (char *) mac_env
.c_str(),
72 (char *) tos_env
.c_str(),
76 Log::info("Programming TTY %s", tty
.c_str());
78 if (runChild(args
, envp
))
81 remove(filename
.c_str());
88 const std::string
& Mote::getMac()
93 const std::string
& Mote::getDevicePath()
98 const std::string
& Mote::getPlatform()
103 std::string
Mote::getImagePath()
105 return directory
+ "image";