Go to the documentation of this file.
44 bool find_switch(
const std::vector<std::string> &
args,
const std::string &short_sw,
45 const std::string &long_sw) {
46 bool has_short = (std::find(
args.cbegin(),
args.cend(), short_sw)) !=
args.cend();
47 bool has_long = (std::find(
args.cbegin(),
args.cend(), long_sw)) !=
args.cend();
49 return (has_long || has_short);
52 std::string
get_option(
const std::vector<std::string> &
args,
const std::string &option,
53 const std::string &default_val) {
54 auto opt = std::find(
args.cbegin(),
args.cend(), option);
55 if (opt !=
args.cend() && std::next(opt) !=
args.cend()) {
62 int get_option(
const std::vector<std::string> &
args,
const std::string &option,
63 const int default_val) {
64 auto opt = std::find(
args.cbegin(),
args.cend(), option);
65 if (opt !=
args.cend() && std::next(opt) !=
args.cend()) {
66 return std::stoi(*(++opt));
91 }
catch (std::invalid_argument e) {
92 fprintf(stderr,
"%s\n",
"Expected integer for option -B");
108 virtual const char *
what()
const throw() {
return e_what_.c_str(); }
118 robot.
write(out.c_array(), out.size());
122 bool timedout =
false;
123 struct timespec
start, current_time;
124 clock_gettime(CLOCK_MONOTONIC, ¤t_time);
125 start = current_time;
127 while (robot.
isOpen() && !timedout) {
131 robot.
read(innew.c_array(), 1);
135 robot.
read(&innew.c_array()[1], 7);
145 clock_gettime(CLOCK_MONOTONIC, ¤t_time);
146 timedout = (current_time.tv_sec >=
start.tv_sec + 5);
153 throw std::runtime_error(
"unknown error while wating for serial");
157 int main(
int argc,
char const *argv[]) {
158 std::vector<std::string>
args(argv + 1, argv + argc);
167 fprintf(stderr,
"%s\n",
"Error parsing arguments");
172 printf(
"%s\n",
"Used to probe Ubiquity Robotics robots for version info");
173 printf(
"%s\n",
"Options:");
174 printf(
"%s\n",
" -D {PATH TO PORT}: Set the Serial Port to use (e.g. /dev/ttyAMA0)");
175 printf(
"%s\n",
" -B {BAUD RATE}: Set the Baud Rate to use (e.g. 38400)");
176 printf(
"%s\n",
"Switches:");
177 printf(
"%s\n",
" -a --all: Print out all options.");
178 printf(
"%s\n",
" -r --robot: Print out robot platform (e.g. loki, magni, none)");
179 printf(
"%s\n",
" -f --firmware: Print out firmware revision");
180 printf(
"%s\n",
" -p --pcb: Print out the PCB revision");
181 printf(
"%s\n",
" -v --verbose: Print out debugging information.");
182 printf(
"%s\n",
" -h --help: Print out this help");
188 fprintf(stderr,
"%s\n",
"Parsed Args:");
189 fprintf(stderr,
" Robot ID: %d\n", op.
robot);
190 fprintf(stderr,
" Firmware: %d\n", op.
firmware);
191 fprintf(stderr,
" PCB: %d\n", op.
pcb_rev);
192 fprintf(stderr,
" Verbose: %d\n", op.
verbose);
193 fprintf(stderr,
" Help: %d\n", op.
help);
194 fprintf(stderr,
" Serial Port: %s\n", op.
serial_port.c_str());
195 fprintf(stderr,
" Baud Rate: %d\n", op.
baud_rate);
204 int id_num = robot_id.
getData();
205 if (id_num == 0x00) {
206 printf(
"%s\n",
"magni");
207 }
else if (id_num == 0x01) {
208 printf(
"%s\n",
"loki");
210 printf(
"%s\n",
"unknown");
213 printf(
"%s\n",
"none");
220 printf(
"%d\n", firmware.
getData());
222 fprintf(stderr,
"%s\n",
"Timeout getting firmware version");
229 printf(
"%d\n", hardware.
getData());
231 fprintf(stderr,
"%s\n",
"Timeout getting hardware version");
237 fprintf(stderr,
"Error opening Serial Port %s\n", op.
serial_port.c_str());
MotorMessage::ErrorCodes deserialize(const RawMotorMessage &serialized)
const static uint8_t delimeter
MotorMessage::MessageTypes getType() const
TimeoutException & operator=(const TimeoutException &)
std::string get_option(const std::vector< std::string > &args, const std::string &option, const std::string &default_val)
TimeoutException(const TimeoutException &other)
virtual ~TimeoutException()
TimeoutException(const char *description)
virtual const char * what() const
void setData(int32_t data)
static Timeout simpleTimeout(uint32_t timeout)
RawMotorMessage serialize() const
MotorMessage readRegister(MotorMessage::Registers reg, serial::Serial &robot)
int main(int argc, char const *argv[])
MotorMessage::Registers getRegister() const
bool find_switch(const std::vector< std::string > &args, const std::string &short_sw, const std::string &long_sw)
void waitByteTimes(size_t count)
boost::array< uint8_t, 8 > RawMotorMessage
size_t write(const uint8_t *data, size_t size)
size_t read(uint8_t *buffer, size_t size)
Options parse_args(const std::vector< std::string > &args)
void setRegister(MotorMessage::Registers reg)
void setType(MotorMessage::MessageTypes type)