sbgEComCmdAirData.c
Go to the documentation of this file.
1 /* sbgCommonLib headers */
3 
4 /* Project headers */
6 
7 /* Local headers */
8 #include "sbgEComCmdAirData.h"
9 
10 //----------------------------------------------------------------------//
11 //- Public methods -//
12 //----------------------------------------------------------------------//
13 
15 {
16  assert(pHandle);
17 
19 }
20 
22 {
23  SbgErrorCode errorCode = SBG_NO_ERROR;
24  uint32_t modelIdAsUint;
25 
26  assert(pHandle);
27  assert(pModelId);
28 
30 
31  if (errorCode == SBG_NO_ERROR)
32  {
33  *pModelId = (SbgEComAirDataModelsIds)modelIdAsUint;
34  }
35 
36  return errorCode;
37 }
38 
39 SbgErrorCode sbgEComCmdAirDataSetLeverArm(SbgEComHandle *pHandle, const float *pLeverArm)
40 {
41  SbgErrorCode errorCode = SBG_NO_ERROR;
42  uint32_t trial;
43  uint8_t outputBuffer[64];
44  SbgStreamBuffer outputStream;
45 
46  assert(pHandle);
47  assert(pLeverArm);
48 
49  //
50  // Create the command payload
51  //
52  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
53 
54  //
55  // Build payload
56  //
57  sbgStreamBufferWriteFloatLE(&outputStream, pLeverArm[0]);
58  sbgStreamBufferWriteFloatLE(&outputStream, pLeverArm[1]);
59  sbgStreamBufferWriteFloatLE(&outputStream, pLeverArm[2]);
60 
61  //
62  // Make sure the payload has been build correctly
63  //
64  errorCode = sbgStreamBufferGetLastError(&outputStream);
65 
66  if (errorCode == SBG_NO_ERROR)
67  {
68  //
69  // Send the command three times
70  //
71  for (trial = 0; trial < pHandle->numTrials; trial++)
72  {
73  //
74  // Send the payload over ECom
75  //
77 
78  //
79  // Make sure that the command has been sent
80  //
81  if (errorCode == SBG_NO_ERROR)
82  {
83  //
84  // Try to read the device answer for 500 ms
85  //
87 
88  //
89  // Test if we have received a valid ACK
90  //
91  if (errorCode == SBG_NO_ERROR)
92  {
93  //
94  // The command has been executed successfully so return
95  //
96  break;
97  }
98  }
99  else
100  {
101  //
102  // We have a write error so exit the try loop
103  //
104  break;
105  }
106  }
107  }
108 
109  return errorCode;
110 }
111 
113 {
114  SbgErrorCode errorCode = SBG_NO_ERROR;
115  uint32_t trial;
116  size_t receivedSize;
117  uint8_t receivedBuffer[64];
118  SbgStreamBuffer inputStream;
119 
120  assert(pHandle);
121  assert(pLeverArm);
122 
123  //
124  // Send the command three times
125  //
126  for (trial = 0; trial < pHandle->numTrials; trial++)
127  {
128  //
129  // Send the command only since this is a no-payload command
130  //
132 
133  //
134  // Make sure that the command has been sent
135  //
136  if (errorCode == SBG_NO_ERROR)
137  {
138  //
139  // Try to read the device answer for 500 ms
140  //
141  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_AIRDATA_LEVER_ARM, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
142 
143  //
144  // Test if we have received a SBG_ECOM_CMD_GNSS_1_LEVER_ARM_ALIGNMENT command
145  //
146  if (errorCode == SBG_NO_ERROR)
147  {
148  //
149  // Initialize stream buffer to parse the payload
150  //
151  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
152 
153  pLeverArm[0] = sbgStreamBufferReadFloatLE(&inputStream);
154  pLeverArm[1] = sbgStreamBufferReadFloatLE(&inputStream);
155  pLeverArm[2] = sbgStreamBufferReadFloatLE(&inputStream);
156 
157  //
158  // The command has been executed successfully so return if an error has occurred during payload parsing
159  //
160  errorCode = sbgStreamBufferGetLastError(&inputStream);
161  break;
162  }
163  }
164  else
165  {
166  //
167  // We have a write error so exit the try loop
168  //
169  break;
170  }
171  }
172 
173  return errorCode;
174 }
175 
177 {
178  SbgErrorCode errorCode = SBG_NO_ERROR;
179  uint32_t trial;
180  uint8_t outputBuffer[2 * sizeof(uint8_t)];
181  SbgStreamBuffer outputStream;
182 
183  assert(pHandle);
184  assert(pRejectConf);
185 
186  //
187  // Create the command payload
188  //
189  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
190 
191  //
192  // Build payload
193  //
194  sbgStreamBufferWriteUint8LE(&outputStream, pRejectConf->airspeed);
195  sbgStreamBufferWriteUint8LE(&outputStream, pRejectConf->altitude);
196 
197  //
198  // Make sure the payload has been build correctly
199  //
200  errorCode = sbgStreamBufferGetLastError(&outputStream);
201 
202  if (errorCode == SBG_NO_ERROR)
203  {
204  //
205  // Send the command three times
206  //
207  for (trial = 0; trial < pHandle->numTrials; trial++)
208  {
209  //
210  // Send the payload over ECom
211  //
213 
214  //
215  // Make sure that the command has been sent
216  //
217  if (errorCode == SBG_NO_ERROR)
218  {
219  //
220  // Try to read the device answer for 500 ms
221  //
223 
224  //
225  // Test if we have received a valid ACK
226  //
227  if (errorCode == SBG_NO_ERROR)
228  {
229  //
230  // The command has been executed successfully so return
231  //
232  break;
233  }
234  }
235  else
236  {
237  //
238  // We have a write error so exit the try loop
239  //
240  break;
241  }
242  }
243  }
244 
245  return errorCode;
246 }
247 
249 {
250  SbgErrorCode errorCode = SBG_NO_ERROR;
251  uint32_t trial;
252  size_t receivedSize;
253  uint8_t receivedBuffer[2 * sizeof(uint8_t)];
254  SbgStreamBuffer inputStream;
255 
256  assert(pHandle);
257  assert(pRejectConf);
258 
259  //
260  // Send the command three times
261  //
262  for (trial = 0; trial < pHandle->numTrials; trial++)
263  {
264  //
265  // Send the command only since this is a no-payload command
266  //
268 
269  //
270  // Make sure that the command has been sent
271  //
272  if (errorCode == SBG_NO_ERROR)
273  {
274  //
275  // Try to read the device answer for 500 ms
276  //
277  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_AIRDATA_REJECT_MODES, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
278 
279  //
280  // Test if we have received a SBG_ECOM_CMD_GNSS_1_REJECT_MODES command
281  //
282  if (errorCode == SBG_NO_ERROR)
283  {
284  //
285  // Initialize stream buffer to parse payload
286  //
287  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
288 
289  //
290  // Parse the payload
291  //
292  pRejectConf->airspeed = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
293  pRejectConf->altitude = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
294 
295  //
296  // The command has been executed successfully so return if an error has occurred during payload parsing
297  //
298  errorCode = sbgStreamBufferGetLastError(&inputStream);
299  break;
300  }
301  }
302  else
303  {
304  //
305  // We have a write error so exit the try loop
306  //
307  break;
308  }
309  }
310 
311  return errorCode;
312 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
SbgEComRejectionMode altitude
SBG_INLINE float sbgStreamBufferReadFloatLE(SbgStreamBuffer *pHandle)
SbgErrorCode sbgEComCmdAirDataSetRejection(SbgEComHandle *pHandle, const SbgEComAirDataRejectionConf *pRejectConf)
This file implements sbgECom commands related to AirData module.
Used to read/write data from/to a memory buffer stream.
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8_t msgClass, uint8_t msg, const void *pData, size_t size)
SbgErrorCode sbgEComCmdGenericSetModelId(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t modelId)
enum _SbgEComRejectionMode SbgEComRejectionMode
enum _SbgEComAirDataModelsIds SbgEComAirDataModelsIds
Handle large send/receive transfer for specific ECom Protocol commands.
SbgEComProtocol protocolHandle
Definition: sbgECom.h:72
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
SbgErrorCode sbgEComCmdAirDataSetLeverArm(SbgEComHandle *pHandle, const float *pLeverArm)
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t timeOut)
SbgErrorCode sbgEComCmdAirDataGetLeverArm(SbgEComHandle *pHandle, float *pLeverArm)
SbgErrorCode sbgEComCmdAirDataGetRejection(SbgEComHandle *pHandle, SbgEComAirDataRejectionConf *pRejectConf)
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
#define NULL
Definition: sbgDefines.h:81
SbgErrorCode sbgEComCmdAirDataGetModelId(SbgEComHandle *pHandle, SbgEComAirDataModelsIds *pModelId)
SbgErrorCode sbgEComReceiveCmd(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, void *pData, size_t *pSize, size_t maxSize, uint32_t timeOut)
#define sbgStreamBufferReadUint8LE
uint32_t numTrials
Definition: sbgECom.h:77
SBG_INLINE SbgErrorCode sbgStreamBufferWriteFloatLE(SbgStreamBuffer *pHandle, float value)
SbgErrorCode sbgEComCmdGenericGetModelId(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t *pModelId)
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
SbgEComRejectionMode airspeed
enum _SbgErrorCode SbgErrorCode
SbgErrorCode sbgEComCmdAirDataSetModelId(SbgEComHandle *pHandle, SbgEComAirDataModelsIds modelId)
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError(SbgStreamBuffer *pHandle)


sbg_driver
Author(s): SBG Systems
autogenerated on Thu Oct 22 2020 03:47:22