My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
NetMsg.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_NETMSG_H
2 #define GCP_UTIL_NETMSG_H
3 
11 #include "gcp/util/common/AntNum.h"
12 #include "gcp/util/common/Debug.h"
13 #include "gcp/util/common/Exception.h"
14 #include "gcp/util/common/LogStream.h"
15 #include "gcp/util/common/NetSendStr.h"
16 #include "gcp/util/common/Mutex.h"
17 
18 #include <string.h>
19 
20 #include "gcp/control/code/unix/libunix_src/common/netobj.h"
21 #include "gcp/control/code/unix/libunix_src/specific/rtcnetcoms.h"
22 
23 namespace gcp {
24  namespace util {
25 
26  class NetMsg {
27  public:
28 
32  enum MsgType {
33 
34  // A message to be logged
35 
36  GREETING = gcp::control::NET_GREETING_MSG,
37 
38  // A message to be logged
39 
40  LOG = gcp::control::NET_LOG_MSG,
41 
42  // An antenna ID
43 
44  ID = gcp::control::NET_ID_MSG,
45 
46  // A request for updates of phemeris positions from the
47  // navigator thread
48 
49  NAV_UPDATE = gcp::control::NET_NAV_UPDATE_MSG,
50 
51  // Report the completion of a pmac transaction
52 
53  DRIVE_DONE = gcp::control::NET_DRIVE_DONE_MSG,
54 
55  // Report the completion of a bench transaction
56 
57  BENCH_DONE = gcp::control::NET_BENCH_DONE_MSG,
58 
59  // Report the completion of a scan transaction
60 
61  SCAN_DONE = gcp::control::NET_SCAN_DONE_MSG,
62 
63  // Report that a source has set
64 
65  SOURCE_SET = gcp::control::NET_SOURCE_SET_MSG,
66 
67  // Report the completion of a caltert transaction
68 
69  CALTERT_DONE = gcp::control::NET_CALTERT_DONE_MSG,
70 
71  // Report the completion of a caltert transaction
72 
73  IFMOD_DONE = gcp::control::NET_IFMOD_DONE_MSG,
74 
75  // Report the completion of a CAN transaction
76 
77  CAN_DONE = gcp::control::NET_CAN_DONE_MSG,
78 
79  // Report the completion of a SCRIPT transaction
80 
81  SCRIPT_DONE = gcp::control::NET_SCRIPT_DONE_MSG,
82  };
83 
88 
93 
94  //------------------------------------------------------------
95  // Set the antenna id.
96  //------------------------------------------------------------
97 
98  inline void setAntId(AntNum::Id antId) {
99  body.antenna = antId;
100  }
101 
102  //------------------------------------------------------------
103  // Methods to pack Network messages
104  //------------------------------------------------------------
105 
106  //------------------------------------------------------------
107  // Method to pack a greeting to an antenna
108 
109  inline void packGreetingMsg(unsigned int id,
110  unsigned revision,
111  unsigned nReg,
112  unsigned nByte) {
113 
114  type = GREETING;
115 
116  body.antenna = id;
117  body.msg.greeting.revision = revision;
118  body.msg.greeting.nReg = nReg;
119  body.msg.greeting.nByte = nByte;
120  }
121 
122 
123  //------------------------------------------------------------
124  // Method to pack a log message
125 
126  inline unsigned maxMsgLen() {
127  return gcp::control::NET_LOG_MAX;
128  }
129 
130  //------------------------------------------------------------
131  // Method to pack a log message
132 
133  inline void packLogMsg(std::string message, bool isError,
134  unsigned seq=0, bool end=0) {
135 
136  int length = message.length();
137 
138  length = (length > gcp::control::NET_LOG_MAX) ?
139  gcp::control::NET_LOG_MAX : length;
140 
141  type = LOG;
142 
143  strncpy(body.msg.log.text, message.c_str(), length);
144 
145  // Make sure the string is properly terminated
146 
147  body.msg.log.text[length] = '\0';
148  body.msg.log.bad = isError;
149  body.msg.log.seq = seq;
150  body.msg.log.end = end;
151  }
152 
153  //------------------------------------------------------------
154  // Method to pack an antenna id
155 
156  inline void packAntennaIdMsg(unsigned int id) {
157 
158  type = ID;
159  body.antenna = id;
160  }
161 
162  //------------------------------------------------------------
163  // Method to pack a request for ephemeris updates from the
164  // navigator thread
165 
166  inline void packNavUpdateMsg() {
167  type = NAV_UPDATE;
168  }
169 
170  //------------------------------------------------------------
171  // Method to pack a pmacxo transaction completion message
172 
173  inline void packDriveDoneMsg(unsigned seq) {
174  type = DRIVE_DONE;
175  body.msg.drive_done.seq = seq;
176  }
177 
178  //------------------------------------------------------------
179  // Method to pack a bench transaction completion message
180 
181  inline void packBenchDoneMsg(unsigned seq) {
182  type = BENCH_DONE;
183  body.msg.bench_done.seq = seq;
184  }
185 
186  //------------------------------------------------------------
187  // Method to pack a scan completion message
188 
189  inline void packScanDoneMsg(unsigned seq) {
190  type = SCAN_DONE;
191  body.msg.scan_done.seq = seq;
192  }
193 
194  //------------------------------------------------------------
195  // Method to pack a script completion message
196 
197  inline void packScriptDoneMsg(unsigned seq) {
198  type = SCRIPT_DONE;
199  body.msg.scriptDone.seq = seq;
200  }
201 
202  //------------------------------------------------------------
203  // Method to report that a source has set
204 
205  inline void packSourceSetMsg(unsigned seq) {
206  type = SOURCE_SET;
207  body.msg.source_set.seq = seq;
208  }
209 
210  //------------------------------------------------------------
211  // Method to pack a CalTert transaction completion message
212 
213  inline void packCalTertDoneMsg(unsigned seq) {
214  type = CALTERT_DONE;
215  body.msg.calTertDone.seq = seq;
216  }
217 
218  //------------------------------------------------------------
219  // Method to pack a IFMod transaction completion message
220 
221  inline void packIFModDoneMsg(unsigned seq) {
222  type = IFMOD_DONE;
223  body.msg.IFModDone.seq = seq;
224  }
225 
226  //------------------------------------------------------------
227  // Method to pack a CAN transaction completion message
228 
229  inline void packCanCommandDoneMsg(unsigned seq) {
230  type = CAN_DONE;
231  body.msg.canDone.seq = seq;
232  }
233 
234  inline friend std::ostream& operator<<(std::ostream& os, const NetMsg& rhs) {
235  switch (rhs.type) {
236  case GREETING:
237  os << std::endl <<
238  "GreetingMsg" << std::endl <<
239  "antenna " << rhs.body.antenna << std::endl <<
240  "revision " << rhs.body.msg.greeting.revision << std::endl <<
241  "nReg " << rhs.body.msg.greeting.nReg << std::endl <<
242  "nByte " << rhs.body.msg.greeting.nByte << std::endl;
243  break;
244  default:
245  os << "Other NetMsg" << std::endl;
246  break;
247  }
248  }
249  }; // End class NetMsg
250 
251  } // End namespace util
252 } // End namespace gcp
253 
254 
255 
256 
257 #endif // End #ifndef GCP_UTIL_NETMSG_H
MsgType type
Definition: NetMsg.h:87
Definition: NetMsg.h:26
MsgType
Definition: NetMsg.h:32
Definition: rtcnetcoms.h:216
Id
Definition: AntNum.h:37
gcp::control::RtcNetMsg body
Definition: NetMsg.h:92