gusimplewhiteboard
Oculus_PrimeSerialInterface.hpp
Go to the documentation of this file.
1
9#ifndef Oculus_PrimeSerialInterface_DEFINED
10#define Oculus_PrimeSerialInterface_DEFINED
11
13
14#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
15#include <arpa/inet.h>
16
17#pragma clang diagnostic push
18#pragma clang diagnostic ignored "-Wreserved-id-macro"
19#include <sstream>
20#pragma clang diagnostic pop
21#endif
22
23namespace guWhiteboard
24{
39 {
40 public:
41
45
46#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
50 Oculus_PrimeSerialInterface(const std::string &str) { from_string(str); }
51#undef DELIMITER
52#undef SEP
53#undef SV
54#undef PARSER
55#undef COMP
56#undef PARSE
57
58#define DELIMITER ','
59#define SEP ':'
60#define ARRAY_DEL '-'
61#define SV std::vector<std::string>
62#define PARSER(s, c, p) if (k.compare(s) == 0) { set_##c ( p ); continue; }
63#define ARRAY_PARSER(s, c, p) if (k.compare(s) == 0) \
64 { \
65 SV kk = components_of_string_separated(v, ARRAY_DEL, true); \
66 for(size_t n = 0; n < kk.size(); n++) \
67 { v = kk.at(n); _##c[n] = p; _##c##_mask = 1; } \
68 continue; \
69 }
70#define COMP(v, s) v.compare(0, 2, s) == 0
71
72#define PARSE_UINT8 static_cast<uint8_t>(atoi(v.c_str()))
73
77 void from_string(const std::string &str)
78 {
79 SV sn = components_of_string_separated(str, DELIMITER, true);
80 for(size_t i = 0; i < sn.size(); i++)
81 {
82 SV kv = components_of_string_separated(sn.at(i), SEP, true);
83 if(kv.size() != 2)
84 {
85 fprintf(stderr, "parse error\n");
86 return;
87 }
88 std::string k = kv.at(0);
89 std::string v = kv.at(1);
90
91 //serial parser - removed indenting so I can read it, Carl.
92ARRAY_PARSER("f", forward, PARSE_UINT8 )
94ARRAY_PARSER("r", right, PARSE_UINT8 )
95PARSER("s", stop, 1)
96
97 //pretty parser - removed indenting so I can read it, Carl.
98ARRAY_PARSER("forward", forward, PARSE_UINT8)
100ARRAY_PARSER("right", right, PARSE_UINT8)
101PARSER("stop", stop, 1)
102 }
103 }
104
108 std::string description() const
109 {
110 std::stringstream ss;
111 ss
112 << static_cast<int>(forward()[0]) << " " << static_cast<int>(forward()[1]) << " forward : , ";
113 return ss.str();
114 }
115#endif // WHITEBOARD_POSTER_STRING_CONVERSION
116 };
117}
118
119#endif //Oculus_PrimeSerialInterface_DEFINED
#define ARRAY_PARSER(s, c, p)
#define DELIMITER
#define PARSER(s, c, p)
#define PARSE_UINT8
Serial interface for the main oculus prime board.
std::string description() const
pretty print method for showing the current property values
void from_string(const std::string &str)
parse class properties from a string
Oculus_PrimeSerialInterface(const std::string &str)
string constructor (see from_string() below)
/file APM_Interface.h
/file wb_oculus_prime_serial.h