19 #ifndef SNARK_ACTUATORS_QUICKSET_ptcr_COMMANDS_H_
20 #define SNARK_ACTUATORS_QUICKSET_ptcr_COMMANDS_H_
23 #include <boost/array.hpp>
24 #include <comma/base/exception.h>
25 #include <comma/packed/byte.h>
26 #include <comma/packed/little_endian.h>
27 #include <comma/packed/struct.h>
29 namespace snark {
namespace quickset {
namespace ptcr {
namespace commands {
31 struct pan_status:
public comma::packed::packed_struct< pan_status, 1 >
33 comma::packed::byte value;
35 bool cwsl()
const {
return 0x80 & *value.data(); }
36 bool ccwsl()
const {
return 0x40 & *value.data(); }
37 bool cwhl()
const {
return 0x20 & *value.data(); }
38 bool ccwhl()
const {
return 0x10 & *value.data(); }
39 bool to()
const {
return 0x8 & *value.data(); }
40 bool de()
const {
return 0x4 & *value.data(); }
41 bool fault()
const {
return de() || to(); }
42 std::string to_string()
const { std::ostringstream oss; oss << cwsl() << ccwsl() << cwhl() << ccwhl() << to() << de() << 0 << 0;
return oss.str(); }
45 struct tilt_status:
public comma::packed::packed_struct< tilt_status, 1 >
47 comma::packed::byte value;
49 bool usl()
const {
return 0x80 & *value.data(); }
50 bool dsl()
const {
return 0x40 & *value.data(); }
51 bool uhl()
const {
return 0x20 & *value.data(); }
52 bool dhl()
const {
return 0x10 & *value.data(); }
53 bool to()
const {
return 0x8 & *value.data(); }
54 bool de()
const {
return 0x4 & *value.data(); }
55 bool fault()
const {
return de() || to(); }
56 std::string to_string()
const { std::ostringstream oss; oss << usl() << dsl() << uhl() << dhl() << to() << de() << 0 << 0;
return oss.str(); }
59 struct general_status:
public comma::packed::packed_struct< general_status, 1 >
61 comma::packed::byte value;
63 bool con()
const {
return 0x80 & *value.data(); }
64 bool exec()
const {
return 0x40 & *value.data(); }
65 bool des()
const {
return 0x20 & *value.data(); }
66 bool oslr()
const {
return 0x10 & *value.data(); }
67 bool cwm()
const {
return 0x8 & *value.data(); }
68 bool ccwm()
const {
return 0x4 & *value.data(); }
69 bool upm()
const {
return 0x2 & *value.data(); }
70 bool dwnm()
const {
return 0x1 & *value.data(); }
71 std::string to_string()
const { std::ostringstream oss; oss << con() << exec() << des() << oslr() << cwm() << ccwm() << upm() << dwnm();
return oss.str(); }
74 struct get_status :
public comma::packed::packed_struct< get_status, 7 >
78 static const unsigned char pdir = 0x80;
79 static const unsigned char tdir = 0x40;
80 static const unsigned char pslo = 0x10;
81 static const unsigned char tslo = 0x08;
82 static const unsigned char osl = 0x04;
83 static const unsigned char stop = 0x02;
84 static const unsigned char res = 0x01;
88 comma::packed::byte command;
89 comma::packed::byte pan_jog_command;
90 comma::packed::byte tilt_jog_command;
91 comma::packed::byte zoom1_jog;
92 comma::packed::byte focus1_jog;
93 comma::packed::byte zoom2_jog;
94 comma::packed::byte focus2_jog;
96 get_status() { ::memset( command.data(), 0, size ); }
98 struct response :
public comma::packed::packed_struct< get_status::response, 15 >
100 typedef get_status command;
101 enum {
id = command::id };
102 comma::packed::int24 pan;
103 comma::packed::int24 tilt;
104 pan_status response_pan_status;
105 tilt_status response_tilt_status;
106 general_status status;
107 comma::packed::byte zoom1position;
108 comma::packed::byte focus1position;
109 comma::packed::byte zoom2position;
110 comma::packed::byte focus2position;
111 comma::packed::byte camera1count;
112 comma::packed::byte camera2count;
114 response() { camera1count = 0; camera2count = 0; }
116 bool operator==(
const response& rhs )
const { return ::memcmp( data(), rhs.data(), size - 6 ) == 0; }
117 bool operator!=(
const response& rhs )
const {
return !operator==( rhs ); }
121 struct move_to :
public comma::packed::packed_struct< move_to, 6 >
124 comma::packed::int24 pan;
125 comma::packed::int24 tilt;
127 struct response :
public comma::packed::packed_struct< move_to::response, 13 >
129 typedef move_to command;
130 enum {
id = command::id };
131 comma::packed::int24 pan;
132 comma::packed::int24 tilt;
133 pan_status response_pan_status;
134 tilt_status response_tilt_status;
135 general_status status;
136 comma::packed::byte zoom1position;
137 comma::packed::byte focus1position;
138 comma::packed::byte zoom2position;
139 comma::packed::byte focus2position;
143 struct move_to_delta :
public comma::packed::packed_struct< move_to_delta, 6 >
146 comma::packed::int24 pan;
147 comma::packed::int24 tilt;
149 struct response :
public comma::packed::packed_struct< move_to_delta::response, 13 >
151 typedef move_to_delta command;
152 enum {
id = command::id };
153 comma::packed::int24 pan;
154 comma::packed::int24 tilt;
155 pan_status response_pan_status;
156 tilt_status response_tilt_status;
157 general_status status;
158 comma::packed::byte zoom1position;
159 comma::packed::byte focus1position;
160 comma::packed::byte zoom2position;
161 comma::packed::byte focus2position;
165 struct get_limits :
public comma::packed::packed_struct< get_limits, 1 >
168 struct direction {
enum values { clockwise = 0, right = clockwise, counterclockwise = 1, left = counterclockwise, up = 2, down = 3 }; };
169 static const unsigned char query = 0x80;
170 comma::packed::byte direction_byte;
171 get_limits() { direction_byte = query; }
172 get_limits( direction::values a ) { direction_byte = query | a; }
174 struct response :
public comma::packed::packed_struct< response, 4 >
176 typedef get_limits command;
177 enum {
id = command::id };
178 comma::packed::byte direction;
179 comma::packed::int24 value;
183 struct set_limits :
public comma::packed::packed_struct< set_limits, 4 >
185 enum {
id = get_limits::id };
186 typedef get_limits::direction direction;
187 comma::packed::byte direction_byte;
188 comma::packed::int24 value;
190 set_limits( direction::values a,
int v ) { direction_byte = a; value = v; }
192 struct response :
public comma::packed::packed_struct< response, 4 >
194 typedef set_limits command;
195 enum {
id = command::id };
196 comma::packed::byte direction;
197 comma::packed::int24 value;
201 struct set_camera :
public comma::packed::packed_struct< set_camera, 2 >
204 boost::array< comma::packed::byte, 2 > flags;
205 set_camera() { flags[0] = flags[1] = 0; }
207 struct response :
public comma::packed::packed_struct< response, 2 >
209 typedef set_camera command;
210 enum {
id = command::id };
211 boost::array< comma::packed::byte, 2 > flags;
212 response() { flags[0] = flags[1] = 0; }
218 #endif // #ifndef SNARK_ACTUATORS_QUICKSET_ptcr_COMMANDS_H_