MCS: Use remote.h and cleanup header file inclusion
[remote/remote-mci.git] / mch / Mote.h
blobad559bdfd2b10ac95468fd89f07cf696ad813877
1 #ifndef REMOTE_MCH_MOTE_H
2 #define REMOTE_MCH_MOTE_H
4 #include "remote.h"
5 #include "mch/SerialControl.h"
7 namespace remote { namespace mch {
9 /** MCH Mote
11 * This class is used for keeping track of information from the mote
12 * device directory and whether a mote is valid. A mote object is
13 * created for each mote attached to a mote host.
15 * All the lowlevel control of the serial connection to the mote is
16 * done via the subclassed #SerialControl class.
18 class Mote : public SerialControl
20 public:
21 static const std::string NONE;
22 static const std::string START;
23 static const std::string STOP;
24 static const std::string RESET;
25 static const std::string PROGRAM;
27 /** Create a new mote.
29 * A newly created will automatically be validated using
30 * #validate().
32 * @param mac The mote's MAC address.
33 * @param directory The mote device directory.
35 Mote(std::string& mac, std::string& directory);
37 /** Is the mote started or stopped?
39 * @return True if the mote is running.
41 bool isRunning();
43 /** Is the mote valid?
45 * @return True if the mote is valid.
47 bool isValid();
49 /** Mark the mote invalid. */
50 void invalidate();
52 /** Validate mote.
54 * When validating a mote, information from files in the mote
55 * device directory are reread in order to check if the mote is
56 * still operational.
58 void validate();
60 /** Start mote.
62 * @return True if mote was started.
64 bool start();
66 /** Stop mote.
68 * @return True if mote was stopped.
70 bool stop();
72 /** Reset mote.
74 * @return True if mote was reset.
76 bool reset();
78 /** Start programming a mote.
80 * This will fork a child process to do the actual programming.
82 * @param netaddress The net address of the mote.
83 * @param image The flash image which to use.
84 * @param imagelen The length of the flash image data.
85 * @return True if the programming was started.
87 bool program(std::string netaddress, const uint8_t *image, uint32_t imagelen);
89 /** Cancel mote programming.
91 * @return True if mote was being programmed.
93 bool cancelProgramming();
95 /** Get result of exiting child.
97 * @param force Whether to force the child to exit.
98 * @return True if the child exited with code 0.
100 bool getChildResult(bool force = false);
102 /** Get MAC address.
104 * @return The MAC address.
106 const std::string& getMac();
108 /** Get the physical device path.
110 * The physical device path contains information about where on
111 * the mote host the mote is attached. This includes information
112 * such as which PCI bus it uses, which USB interface etc, for
113 * example: "/devices/pci0000:00/0000:00:1d.0/usb1/1-1".
115 * This information is read from the "path" file in the mote
116 * device directory.
118 * @return The physical device path.
120 const std::string& getDevicePath();
122 /** Get platform name.
124 * Contains the name of the mote platform, for example "MicaZ"
125 * or "dig528-2".
127 * This information is read from the "platform" file in the mote
128 * device directory.
130 * @return The name of the mote's platform.
132 const std::string& getPlatform();
134 /** Get control command.
136 * Get name of the command currently being executed.
138 * @return Command name.
140 const std::string& getControlCommand();
142 private:
143 /** Setup TTY port.
145 * This will setup the TTY by opening it. The command parameter
146 * can be used to indicate in what power mode the mote should start.
148 * @param cmd Command to execute, if non-empty string.
149 * @return True if setup succeeded.
151 bool setupTty(const std::string cmd);
153 /** Execute power command.
155 * @param cmd Command to execute, may be: START, STOP, or RESET.
156 * @return True if power command was executed.
158 bool power(const std::string cmd);
160 std::string mac; /**< MAC address. */
161 std::string directory; /**< Device directory path. */
162 std::string imagefile; /**< Path to temporary flash image file. */
163 std::string controller; /**< Path to mote control binary. */
164 std::string programmer; /**< Path to mote programmer binary. */
165 std::string ttyControl; /**< Path to control TTY. */
166 std::string ttyData; /**< Path to console data TTY. */
167 std::string path; /**< Physical device path. */
168 std::string platform; /**< Platform name. */
169 bool isvalid; /**< Valid flag. */
170 bool running; /**< Mote is started or stopped? */
171 std::string controlCmd; /**< The command being executed. */
176 #endif