1 #ifndef REMOTE_MCH_MOTE_H
2 #define REMOTE_MCH_MOTE_H
4 #include "libutil/File.h"
5 #include "SerialControl.h"
6 #include "motecontrol/localconstants.h"
8 namespace remote
{ namespace diku_mch
{
10 using namespace protocols
;
11 using namespace protocols::motecontrol
;
15 * This class is used for keeping track of information from the mote
16 * device directory and whether a mote is valid. A mote object is
17 * created for each mote attached to a mote host.
19 * All the lowlevel control of the serial connection to the mote is
20 * done via the subclassed #SerialControl class.
22 class Mote
: public SerialControl
25 static const std::string NONE
;
26 static const std::string START
;
27 static const std::string STOP
;
28 static const std::string RESET
;
29 static const std::string PROGRAM
;
31 /** Create a new mote.
33 * A newly created will automatically be validated using
36 * @param mac The mote's MAC address.
37 * @param directory The mote device directory.
39 Mote(std::string
& mac
, std::string
& directory
);
41 /** Is the mote valid?
43 * @return True if the mote is valid.
47 /** Mark the mote invalid. */
52 * When validating a mote, information from files in the mote
53 * device directory are reread in order to check if the mote is
60 * @return SUCCESS if mote was started.
66 * @return SUCCESS if mote was stopped.
72 * @return SUCCESS if mote was reset.
76 /** Start programming a mote.
78 * This will fork a child process to do the actual programming.
80 * @param netaddress The net address of the mote.
81 * @param image The flash image which to use.
82 * @param imagelen The length of the flash image data.
83 * @return SUCCESS if the programming was started.
85 result_t
program(std::string netaddress
, const uint8_t *image
, uint32_t imagelen
);
87 /** Cancel mote programming.
89 * @return SUCCESS if mote was being programmed.
91 result_t
cancelProgramming();
93 /** Get result of exiting child.
95 * @param force Whether to force the child to exit.
96 * @return SUCCESS if the child exited with code 0.
98 result_t
getChildResult(bool force
= false);
102 * @return The mote status code.
104 status_t
getStatus();
108 * @return The MAC address.
110 const std::string
& getMac();
112 /** Get the physical device path.
114 * The physical device path contains information about where on
115 * the mote host the mote is attached. This includes information
116 * such as which PCI bus it uses, which USB interface etc, for
117 * example: "/devices/pci0000:00/0000:00:1d.0/usb1/1-1".
119 * This information is read from the "path" file in the mote
122 * @return The physical device path.
124 const std::string
& getDevicePath();
126 /** Get platform name.
128 * Contains the name of the mote platform, for example "MicaZ"
131 * This information is read from the "platform" file in the mote
134 * @return The name of the mote's platform.
136 const std::string
& getPlatform();
138 /** Get control command.
140 * Get name of the command currently being executed.
142 * @return Command name.
144 const std::string
& getControlCommand();
149 * This will setup the TTY by opening it. The command parameter
150 * can be used to indicate in what power mode the mote should start.
152 * @param cmd Command to execute, if non-empty string.
153 * @return True if setup succeeded.
155 bool setupTty(const std::string cmd
);
157 /** Execute power command.
159 * @param cmd Command to execute, may be: start, stop, or reset.
160 * @return SUCCESS if power command was executed.
162 result_t
power(const std::string cmd
);
164 std::string mac
; /**< MAC address. */
165 std::string directory
; /**< Device directory path. */
166 std::string imagefile
; /**< Path to temporary flash image file. */
167 std::string controller
; /**< Path to mote control binary. */
168 std::string programmer
; /**< Path to mote programmer binary. */
169 std::string ttyControl
; /**< Path to control TTY. */
170 std::string ttyData
; /**< Path to console data TTY. */
171 std::string path
; /**< Physical device path. */
172 std::string platform
; /**< Platform name. */
173 bool isvalid
; /**< Valid flag. */
174 bool isRunning
; /**< Mote is started or stopped? */
175 std::string controlCmd
; /**< The command being executed. */