CARMA C++
NetMsg.h
Go to the documentation of this file.
1 #ifndef SZA_UTIL_NETMSG_H
2 #define SZA_UTIL_NETMSG_H
3 
11 #include "carma/szautil/AntNum.h"
12 #include "carma/szautil/Debug.h"
16 
17 #include "carma/szaarrayutils/netobj.h"
18 #include "carma/szaarrayutils/rtcnetcoms.h"
19 
20 #include <cstring>
21 
22 namespace sza {
23  namespace util {
24 
25  class NetMsg {
26  public:
27 
31  enum MsgType {
32 
33  // A message to be logged
34 
35  GREETING = sza::array::NET_GREETING_MSG,
36 
37  // A message to be logged
38 
39  LOG = sza::array::NET_LOG_MSG,
40 
41  // An antenna ID
42 
43  ID = sza::array::NET_ID_MSG,
44 
45  // A request for updates of phemeris positions from the
46  // navigator thread
47 
48  NAV_UPDATE = sza::array::NET_NAV_UPDATE_MSG,
49 
50  // Report the completion of a pmac transaction
51 
52  PMAC_DONE = sza::array::NET_PMAC_DONE_MSG,
53 
54  // Report that a source has set
55 
56  SOURCE_SET = sza::array::NET_SOURCE_SET_MSG,
57 
58  // Report the completion of a caltert transaction
59 
60  CALTERT_DONE = sza::array::NET_CALTERT_DONE_MSG,
61 
62  // Report the completion of a caltert transaction
63 
64  IFMOD_DONE = sza::array::NET_IFMOD_DONE_MSG,
65 
66  // Report the completion of a CAN transaction
67 
68  CAN_DONE = sza::array::NET_CAN_DONE_MSG,
69 
70  // Report the completion of a Noise source transaction
71 
72  NOISE_DONE = sza::array::NET_NOISE_DONE_MSG,
73  };
74 
78  MsgType type;
79 
83  sza::array::RtcNetMsg body;
84 
85  //------------------------------------------------------------
86  // Set the antenna id.
87  //------------------------------------------------------------
88 
89  inline void setAntId(AntNum::Id antId) {
90  body.antenna = antId;
91  }
92 
93  //------------------------------------------------------------
94  // Methods to pack Network messages
95  //------------------------------------------------------------
96 
97  //------------------------------------------------------------
98  // Method to pack a greeting to an antenna
99 
100  inline void packGreetingMsg(unsigned int id,
101  unsigned revision,
102  unsigned nReg,
103  unsigned nByte) {
104 
105  type = GREETING;
106 
107  body.antenna = id;
108  body.msg.greeting.revision = revision;
109  body.msg.greeting.nReg = nReg;
110  body.msg.greeting.nByte = nByte;
111  }
112 
113  //------------------------------------------------------------
114  // Method to pack a log message
115 
116  inline unsigned maxMsgLen() {
117  return sza::array::NET_LOG_MAX;
118  }
119 
120  //------------------------------------------------------------
121  // Method to pack a log message
122 
123  inline void packLogMsg(std::string message, bool isError,
124  unsigned seq=0, bool end=0) {
125 
126  int length = message.length();
127 
128  length = (length > sza::array::NET_LOG_MAX) ?
129  sza::array::NET_LOG_MAX : length;
130 
131  type = LOG;
132 
133  strncpy(body.msg.log.text, message.c_str(), length);
134 
135  // Make sure the string is properly terminated
136 
137  body.msg.log.text[length] = '\0';
138  body.msg.log.bad = isError;
139  body.msg.log.seq = seq;
140  body.msg.log.end = end;
141  }
142 
143  //------------------------------------------------------------
144  // Method to pack an antenna id
145 
146  inline void packAntennaIdMsg(unsigned int id) {
147 
148  type = ID;
149  body.antenna = id;
150  }
151 
152  //------------------------------------------------------------
153  // Method to pack a request for ephemeris updates from the
154  // navigator thread
155 
156  inline void packNavUpdateMsg() {
157  type = NAV_UPDATE;
158  }
159 
160  //------------------------------------------------------------
161  // Method to pack a pmacxo transaction completion message
162 
163  inline void packPmacDoneMsg(unsigned seq) {
164  type = PMAC_DONE;
165  body.msg.pmac_done.seq = seq;
166  }
167 
168  //------------------------------------------------------------
169  // Method to report that a source has set
170 
171  inline void packSourceSetMsg(unsigned seq) {
172  type = SOURCE_SET;
173  body.msg.source_set.seq = seq;
174  }
175 
176  //------------------------------------------------------------
177  // Method to pack a CalTert transaction completion message
178 
179  inline void packCalTertDoneMsg(unsigned seq) {
180  type = CALTERT_DONE;
181  body.msg.calTertDone.seq = seq;
182  }
183 
184  //------------------------------------------------------------
185  // Method to pack a IFMod transaction completion message
186 
187  inline void packIFModDoneMsg(unsigned seq) {
188  type = IFMOD_DONE;
189  body.msg.IFModDone.seq = seq;
190  }
191 
192  //------------------------------------------------------------
193  // Method to pack a CAN transaction completion message
194 
195  inline void packCanCommandDoneMsg(unsigned seq) {
196  type = CAN_DONE;
197  body.msg.canDone.seq = seq;
198  }
199 
200  //------------------------------------------------------------
201  // Method to pack a Noise transaction completion message
202 
203  inline void packNoiseCommandDoneMsg(unsigned seq) {
204  type = NOISE_DONE;
205  body.msg.noiseDone.seq = seq;
206  }
207 
208  }; // End class NetMsg
209 
210  } // End namespace util
211 } // End namespace sza
212 
213 
214 
215 #endif // End #ifndef SZA_UTIL_NETMSG_H
Started: Wed Jan 14 11:00:24 PST 2004.
Started: Sun Feb 29 15:29:37 UTC 2004.
Tagged: Fri Nov 14 12:39:31 UTC 2003.
Started: Sun Dec 14 07:19:50 UTC 2003.
Id
Enumerate known receivers.
Definition: AntNum.h:35
Tagged: Fri Nov 14 12:39:33 UTC 2003.