1 #ifndef _SERIALCONTROL_H_
2 #define _SERIALCONTROL_H_
11 #include <sys/signal.h>
12 #include <sys/types.h>
14 #include <sys/ioctl.h>
16 #include "libutil/Log.h"
19 namespace remote
{ namespace mch
{
23 /** Serial Connection Control
25 * This class provides a low-level interface for managing a serial
26 * connection to a mote, such as opening and closing TTYs as well
27 * as starting and ending child processes operating on the mote TTYs.
32 /** Create serial control. */
35 /** Destroy serial control. */
38 /** Create and run child process.
40 * @param args The program and args.
41 * @param envp The process environment.
42 * @return True if the start was created.
44 bool runChild(char * const args
[], char * const envp
[]);
46 /** Read buffer from the serial port.
48 * @param buf The buffer start position.
49 * @param len The buffer maximum length.
50 * @return The number of read bytes.
52 ssize_t
readBuf(char *buf
, size_t len
);
54 /** Write buffer to the serial port.
56 * @param buf The buffer start position.
57 * @param len The buffer length.
58 * @return The number of written bytes.
60 ssize_t
writeBuf(const char *buf
, size_t len
);
62 /** Get the file descriptor for the serial port.
64 * @return The serial port being controlled.
69 /** Does any children exist?
71 * @return True if the mote has a child.
75 /** Is the serial control port open?
77 * @return True if the port is open.
81 /** Open serial control for TTY
83 * This method opens the request TTY. The platform string is used
84 * for determining the proper baud rate.
86 * @param platform The platform of the mote.
87 * @param tty The path to the TTY device.
88 * @return True if the TTY was successfully opened.
90 bool openTty(const std::string platform
, const std::string tty
);
92 /** Close serial control for opened TTY. */
95 /** Get exit result of child.
97 * @param killChild Force the child to end by killing it.
98 * @return True if the child exited successfully.
100 bool endChild(bool killChild
);
102 /** Enable or disable DTR.
104 * The DTR channel is wired to the RESET pin on the dig528-2 motes.
105 * Using this hardware configuration motes can be stopped and started
106 * by enabling/disabling it respectively.
108 * @param enable Set the DTR pin high.
109 * @return True if the operation succeeded.
111 bool controlDTR(bool enable
);
113 int port
; /**< Serial file descriptor (or -1). */
114 pid_t childPid
; /**< Process ID of child (or -1). */
115 struct termios oldsertio
; /**< Saved terminal settings. */