My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ServoCommandSa.h
Go to the documentation of this file.
1 #ifndef SERVOCOMMANDSA_H
2 #define SERVOCOMMANDSA_H
3 
12 #include <string>
13 #include <map>
14 #include <vector>
15 
16 // The hard limit -- pmac can't process more than this in a single
17 // message
18 
19 #define SERVO_DATA_MAX_LEN 1400
20 #define MILLI_SECOND_SAMPLE_RATE 200
21 #define MAX_RESPONSE_SAMPLES 1000/MILLI_SECOND_SAMPLE_RATE*14
22 
23 namespace gcp {
24  namespace antenna {
25  namespace control {
26 
27 
28  class ServoComms;
29 
31 
32  public:
33 
37  enum Request {
38 
39  INVALID, // Default which will be used to
40  // indicate that a command has not
41  // been initialized
42  /* These are for the South African dish */
43  SERVO_ENGAGE ,
44  GET_AZEL ,
45  GET_PRIOR_LOC ,
46  SEND_POS ,
47  SEND_POS_TRIP ,
48  LOAD_LOOP_PARAMS_A ,
49  LOAD_LOOP_PARAMS_B ,
50  LOAD_LOOP_PARAMS_C ,
51  LOAD_LOOP_PARAMS_D ,
52  QUERY_STATUS ,
53  AZ_BRAKE_ON ,
54  AZ_BRAKE_OFF ,
55  EL_BRAKE_ON ,
56  EL_BRAKE_OFF ,
57  CLUTCHES_ON ,
58  CLUTCHES_OFF ,
59  AZ_CONTACTORS_ON ,
60  AZ_CONTACTORS_OFF ,
61  EL_CONTACTORS_ON ,
62  EL_CONTACTORS_OFF ,
63  POSITION_ERRORS
64 
65 
66  // For the South African Dish
67  // INVALID = "";
68  // SERVO_ENGAGE = "SVE"; // one input, echo output
69  // GET_AZEL = "GAE"; // no input, two outputs
70  // GET_PRIOR_LOC = "GIM"; // no input, many outputs
71  // QUERY_STATUS = "STS"; // no input, one output
72  // SEND_POS = "AEL"; // two inputs, echo output
73  // LOAD_LOOP_PARAMS_A = "LPRA"; // 6 inputs, echo output
74  // LOAD_LOOP_PARAMS_B = "LPRB"; // 6 inputs, echo output
75  // LOAD_LOOP_PARAMS_C = "LPRC"; // 6 inputs, echo output
76  // LOAD_LOOP_PARAMS_D = "LPRD"; // 6 inputs, echo output
77  // AZ_BRAKE_ON = "ABN"; // no input, echo output
78  // AZ_BRAKE_OFF = "ABF"; // no input, echo output
79  // EL_BRAKE_ON = "EBN"; // no input, echo output
80  // EL_BRAKE_OFF = "EBF"; // no input, echo output
81  // CLUTCHES_ON = "CLN"; // no input, echo output
82  // CLUTCHES_OFF = "CLF"; // no input, echo output
83  // AZ_CONTACTORS_ON = "AMN"; // no input, echo output
84  // AZ_CONTACTORS_OFF = "AMF"; // no input, echo output
85  // EL_CONTACTORS_ON = "EMN"; // no input, echo output
86  // EL_CONTACTORS_OFF = "EMF"; // no input, echo output
87  // POSITION_ERRORS = "ERR"; // no input, two outputs
88  };
89 
93  std::map<Request, std::string> commandMap_;
94 
98  void constructMap();
99 
103  unsigned char request_;
104 
108  std::string messageToSend_;
109 
113  std::string expectedResponse_;
114 
118  char responseReceived_[SERVO_DATA_MAX_LEN];
119 
123  ServoCommandSa();
124 
128  ~ServoCommandSa();
129 
133  void packCommand(Request req);
134  void packCommand(Request req, std::vector<float>& values);
135 
136 
140  void checkOneOutput();
141 
145  void checkTwoOutputs();
146 
150  void checkManyOutputs();
151 
152 
156  void interpretStatusResponse(const char* response);
157 
161  void interpretResponse();
162 
166  bool simpleValidityCheck();
167 
171  size_t responseLength();
172 
173 
174  // private:
175 
176  friend class ServoComms;
177 
181  unsigned short cmdSize_;
182 
187 
192  unsigned short responseLength_;
193 
197  unsigned char readData_[SERVO_DATA_MAX_LEN];
198 
203  unsigned char tmpBuffer_[SERVO_DATA_MAX_LEN];
204 
209 
214 
219 
223  float responseValue_[MAX_RESPONSE_SAMPLES];
224 
228  size_t size();
229 
230 
231  }; // End class ServoCommandSa
232 
233  }; // End namespace control
234  }; // End namespace antenna
235 }; // End namespace gcp
236 
237 #endif // End #ifndef
void constructMap()
Definition: ServoCommandSa.cc:462
void checkTwoOutputs()
Definition: ServoCommandSa.cc:383
void checkManyOutputs()
Definition: ServoCommandSa.cc:416
Request
Definition: ServoCommandSa.h:37
~ServoCommandSa()
Definition: ServoCommandSa.cc:33
ServoCommandSa()
Definition: ServoCommandSa.cc:24
bool simpleValidityCheck()
Definition: ServoCommandSa.cc:301
unsigned char readData_[SERVO_DATA_MAX_LEN]
Definition: ServoCommandSa.h:197
void interpretStatusResponse(const char *response)
Definition: ServoCommandSa.cc:350
unsigned short responseLength_
Definition: ServoCommandSa.h:192
void interpretResponse()
Definition: ServoCommandSa.cc:245
float responseValue_[MAX_RESPONSE_SAMPLES]
Definition: ServoCommandSa.h:223
void checkOneOutput()
Definition: ServoCommandSa.cc:320
char responseReceived_[SERVO_DATA_MAX_LEN]
Definition: ServoCommandSa.h:118
unsigned char request_
Definition: ServoCommandSa.h:103
Definition: ServoCommandSa.h:30
bool responseValid_
Definition: ServoCommandSa.h:208
void packCommand(Request req)
Definition: ServoCommandSa.cc:38
bool responseValueValid_
Definition: ServoCommandSa.h:213
bool expectsResponse_
Definition: ServoCommandSa.h:186
std::map< Request, std::string > commandMap_
Definition: ServoCommandSa.h:93
std::string expectedResponse_
Definition: ServoCommandSa.h:113
unsigned short cmdSize_
Definition: ServoCommandSa.h:181
size_t responseLength()
Definition: ServoCommandSa.cc:237
size_t size()
Definition: ServoCommandSa.cc:229
bool ppsPresent_
Definition: ServoCommandSa.h:218
Definition: ServoComms.h:42
unsigned char tmpBuffer_[SERVO_DATA_MAX_LEN]
Definition: ServoCommandSa.h:203
std::string messageToSend_
Definition: ServoCommandSa.h:108