sbgEComCmdGnss.c
Go to the documentation of this file.
1 #include "sbgEComCmdGnss.h"
4 
5 //----------------------------------------------------------------------//
6 //- GNSS private commands -//
7 //----------------------------------------------------------------------//
15 {
16  //
17  // Call generic function with specific command name
18  //
19  return sbgEComCmdGenericSetModelId(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, id);
20 }
21 
29 {
30  //
31  // Call generic function with specific command name
32  //
33  return sbgEComCmdGenericGetModelInfo(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, pModelInfo);
34 }
35 
45 SbgErrorCode sbgEComCmdGnssSetModel(SbgEComHandle *pHandle, const void *pBuffer, uint32 size, SbgEComCmd cmdId)
46 {
47  //
48  // Call function that handle data transfer
49  //
50  return sbgEComTransferSend(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, pBuffer, size);
51 }
52 
61 {
62  SbgErrorCode errorCode = SBG_NO_ERROR;
63  uint32 trial;
64  size_t receivedSize;
65  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
66  SbgStreamBuffer inputStream;
67 
68  //
69  // Test that the input pointer are valid
70  //
71  if ((pHandle) && (pAlignConf))
72  {
73  //
74  // Send the command three times
75  //
76  for (trial = 0; trial < pHandle->numTrials; trial++)
77  {
78  //
79  // Send the command only since this is a no-payload command
80  //
81  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, NULL, 0);
82 
83  //
84  // Make sure that the command has been sent
85  //
86  if (errorCode == SBG_NO_ERROR)
87  {
88  //
89  // Try to read the device answer for 500 ms
90  //
91  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
92 
93  //
94  // Test if we have received a SBG_ECOM_CMD_GNSS_1_LEVER_ARM_ALIGNMENT command
95  //
96  if (errorCode == SBG_NO_ERROR)
97  {
98  //
99  // Initialize stream buffer to read parameters
100  //
101  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
102 
103  //
104  // Read parameters
105  //
106  pAlignConf->leverArmX = sbgStreamBufferReadFloatLE(&inputStream);
107  pAlignConf->leverArmY = sbgStreamBufferReadFloatLE(&inputStream);
108  pAlignConf->leverArmZ = sbgStreamBufferReadFloatLE(&inputStream);
109  pAlignConf->pitchOffset = sbgStreamBufferReadFloatLE(&inputStream);
110  pAlignConf->yawOffset = sbgStreamBufferReadFloatLE(&inputStream);
111  pAlignConf->antennaDistance = sbgStreamBufferReadFloatLE(&inputStream);
112 
113  //
114  // The command has been executed successfully so return
115  //
116  break;
117  }
118  }
119  else
120  {
121  //
122  // We have a write error so exit the try loop
123  //
124  break;
125  }
126  }
127  }
128  else
129  {
130  //
131  // Null pointer.
132  //
133  errorCode = SBG_NULL_POINTER;
134  }
135 
136  return errorCode;
137 }
138 
147 {
148  SbgErrorCode errorCode = SBG_NO_ERROR;
149  uint32 trial;
150  uint8 outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
151  SbgStreamBuffer outputStream;
152 
153  //
154  // Test that the input pointer are valid
155  //
156  if ((pHandle) && (pAlignConf))
157  {
158  //
159  // Send the command three times
160  //
161  for (trial = 0; trial < pHandle->numTrials; trial++)
162  {
163  //
164  // Init stream buffer for output
165  //
166  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
167 
168  //
169  // Build payload
170  //
171  sbgStreamBufferWriteFloatLE(&outputStream, pAlignConf->leverArmX);
172  sbgStreamBufferWriteFloatLE(&outputStream, pAlignConf->leverArmY);
173  sbgStreamBufferWriteFloatLE(&outputStream, pAlignConf->leverArmZ);
174  sbgStreamBufferWriteFloatLE(&outputStream, pAlignConf->pitchOffset);
175  sbgStreamBufferWriteFloatLE(&outputStream, pAlignConf->yawOffset);
176  sbgStreamBufferWriteFloatLE(&outputStream, pAlignConf->antennaDistance);
177 
178  //
179  // Send the payload over ECom
180  //
181  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, sbgStreamBufferGetLinkedBuffer(&outputStream), sbgStreamBufferGetLength(&outputStream));
182 
183  //
184  // Make sure that the command has been sent
185  //
186  if (errorCode == SBG_NO_ERROR)
187  {
188  //
189  // Try to read the device answer for 500 ms
190  //
191  errorCode = sbgEComWaitForAck(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, pHandle->cmdDefaultTimeOut);
192 
193  //
194  // Test if we have received a valid ACK
195  //
196  if (errorCode == SBG_NO_ERROR)
197  {
198  //
199  // The command has been executed successfully so return
200  //
201  break;
202  }
203  }
204  else
205  {
206  //
207  // We have a write error so exit the try loop
208  //
209  break;
210  }
211  }
212  }
213  else
214  {
215  //
216  // Invalid protocol handle.
217  //
218  errorCode = SBG_NULL_POINTER;
219  }
220 
221  return errorCode;
222 }
223 
232 {
233  SbgErrorCode errorCode = SBG_NO_ERROR;
234  uint32 trial;
235  size_t receivedSize;
236  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
237  SbgStreamBuffer inputStream;
238 
239  //
240  // Test that the input pointer are valid
241  //
242  if ((pHandle) && (pRejectConf))
243  {
244  //
245  // Send the command three times
246  //
247  for (trial = 0; trial < pHandle->numTrials; trial++)
248  {
249  //
250  // Send the command only since this is a no-payload command
251  //
252  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, NULL, 0);
253 
254  //
255  // Make sure that the command has been sent
256  //
257  if (errorCode == SBG_NO_ERROR)
258  {
259  //
260  // Try to read the device answer for 500 ms
261  //
262  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
263 
264  //
265  // Test if we have received a SBG_ECOM_CMD_GNSS_1_REJECT_MODES command
266  //
267  if (errorCode == SBG_NO_ERROR)
268  {
269  //
270  // Initialize stream buffer to read parameters
271  //
272  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
273 
274  //
275  // Read parameters
276  //
277  pRejectConf->position = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
278  pRejectConf->velocity = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
279  sbgStreamBufferReadUint8LE(&inputStream); // Skipped for backward compatibility
280  pRejectConf->hdt = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
281 
282  //
283  // The command has been executed successfully so return
284  //
285  break;
286  }
287  }
288  else
289  {
290  //
291  // We have a write error so exit the try loop
292  //
293  break;
294  }
295  }
296  }
297  else
298  {
299  //
300  // Null pointer.
301  //
302  errorCode = SBG_NULL_POINTER;
303  }
304 
305  return errorCode;
306 }
307 
316 {
317  SbgErrorCode errorCode = SBG_NO_ERROR;
318  uint32 trial;
319  uint8 outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
320  SbgStreamBuffer outputStream;
321 
322  //
323  // Test that the input pointer are valid
324  //
325  if ((pHandle) && (pRejectConf))
326  {
327  //
328  // Send the command three times
329  //
330  for (trial = 0; trial < pHandle->numTrials; trial++)
331  {
332  //
333  // Init stream buffer for output
334  //
335  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
336 
337  //
338  // Build payload
339  //
340  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pRejectConf->position);
341  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pRejectConf->velocity);
342  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)SBG_ECOM_NEVER_ACCEPT_MODE); // Reserved parameter
343  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pRejectConf->hdt);
344 
345  //
346  // Send the payload over ECom
347  //
348  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, sbgStreamBufferGetLinkedBuffer(&outputStream), sbgStreamBufferGetLength(&outputStream));
349 
350  //
351  // Make sure that the command has been sent
352  //
353  if (errorCode == SBG_NO_ERROR)
354  {
355  //
356  // Try to read the device answer for 500 ms
357  //
358  errorCode = sbgEComWaitForAck(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, cmdId, pHandle->cmdDefaultTimeOut);
359 
360  //
361  // Test if we have received a valid ACK
362  //
363  if (errorCode == SBG_NO_ERROR)
364  {
365  //
366  // The command has been executed successfully so return
367  //
368  break;
369  }
370  }
371  else
372  {
373  //
374  // We have a write error so exit the try loop
375  //
376  break;
377  }
378  }
379  }
380  else
381  {
382  //
383  // Invalid protocol handle.
384  //
385  errorCode = SBG_NULL_POINTER;
386  }
387 
388  return errorCode;
389 }
390 
391 
392 //----------------------------------------------------------------------//
393 //- GNSS public commands -//
394 //----------------------------------------------------------------------//
395 
403 {
405 }
406 
414 {
415  return sbgEComCmdGnssGetModelInfo(pHandle, pModelInfo, SBG_ECOM_CMD_GNSS_1_MODEL_ID);
416 }
417 
427 SbgErrorCode sbgEComCmdGnss1SetModel(SbgEComHandle *pHandle, const void *pBuffer, uint32 size)
428 {
429  return sbgEComCmdGnssSetModel(pHandle, pBuffer, size, SBG_ECOM_CMD_GNSS_1_SET_MODEL);
430 }
431 
439 {
441 }
442 
450 {
452 }
453 
461 {
462  return sbgEComCmdGnssGetRejection(pHandle, pRejectConf, SBG_ECOM_CMD_GNSS_1_REJECT_MODES);
463 }
464 
472 {
473  return sbgEComCmdGnssSetRejection(pHandle, pRejectConf, SBG_ECOM_CMD_GNSS_1_REJECT_MODES);
474 }
SbgErrorCode sbgEComCmdGnssSetRejection(SbgEComHandle *pHandle, const SbgEComGnssRejectionConf *pRejectConf, SbgEComCmd cmdId)
SbgErrorCode sbgEComCmdGnss1SetModelId(SbgEComHandle *pHandle, uint32 id)
SbgErrorCode sbgEComCmdGnss1SetRejection(SbgEComHandle *pHandle, const SbgEComGnssRejectionConf *pRejectConf)
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
SbgErrorCode sbgEComCmdGnssSetLeverArmAlignment(SbgEComHandle *pHandle, const SbgEComGnssAlignmentInfo *pAlignConf, SbgEComCmd cmdId)
SbgEComRejectionMode velocity
enum _SbgEComCmd SbgEComCmd
SbgErrorCode sbgEComReceiveCmd(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, void *pData, size_t *pSize, size_t maxSize, uint32 timeOut)
SbgErrorCode sbgEComCmdGnss1SetLeverArmAlignment(SbgEComHandle *pHandle, const SbgEComGnssAlignmentInfo *pAlignConf)
SBG_INLINE float sbgStreamBufferReadFloatLE(SbgStreamBuffer *pHandle)
unsigned int uint32
Definition: sbgTypes.h:58
Used to read/write data from/to a memory buffer stream.
SbgErrorCode sbgEComTransferSend(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, const void *pBuffer, size_t size)
SbgEComRejectionMode hdt
SbgErrorCode sbgEComCmdGnss1SetModel(SbgEComHandle *pHandle, const void *pBuffer, uint32 size)
SbgErrorCode sbgEComCmdGnssGetLeverArmAlignment(SbgEComHandle *pHandle, SbgEComGnssAlignmentInfo *pAlignConf, SbgEComCmd cmdId)
enum _SbgEComRejectionMode SbgEComRejectionMode
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, uint32 timeOut)
Handle large send/receive transfer for specific ECom Protocol commands.
SbgEComProtocol protocolHandle
Definition: sbgECom.h:82
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
SbgErrorCode sbgEComCmdGnss1GetLeverArmAlignment(SbgEComHandle *pHandle, SbgEComGnssAlignmentInfo *pAlignConf)
SbgErrorCode sbgEComCmdGenericGetModelInfo(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, SbgEComModelInfo *pModelInfo)
SbgErrorCode sbgEComCmdGnss1GetRejection(SbgEComHandle *pHandle, SbgEComGnssRejectionConf *pRejectConf)
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8 msgClass, uint8 msg, const void *pData, size_t size)
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
uint32 numTrials
Definition: sbgECom.h:86
#define NULL
Definition: sbgDefines.h:43
uint32 cmdDefaultTimeOut
Definition: sbgECom.h:87
#define sbgStreamBufferReadUint8LE
SbgErrorCode sbgEComCmdGnss1GetModelInfo(SbgEComHandle *pHandle, SbgEComModelInfo *pModelInfo)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteFloatLE(SbgStreamBuffer *pHandle, float value)
SbgErrorCode sbgEComCmdGnssSetModel(SbgEComHandle *pHandle, const void *pBuffer, uint32 size, SbgEComCmd cmdId)
SbgErrorCode sbgEComCmdGnssGetRejection(SbgEComHandle *pHandle, SbgEComGnssRejectionConf *pRejectConf, SbgEComCmd cmdId)
unsigned char uint8
Definition: sbgTypes.h:56
SbgErrorCode sbgEComCmdGnssSetModelId(SbgEComHandle *pHandle, uint32 id, SbgEComCmd cmdId)
SbgErrorCode sbgEComCmdGenericSetModelId(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, uint32 modelId)
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
SbgEComRejectionMode position
enum _SbgErrorCode SbgErrorCode
SbgErrorCode sbgEComCmdGnssGetModelInfo(SbgEComHandle *pHandle, SbgEComModelInfo *pModelInfo, SbgEComCmd cmdId)
This file implements SbgECom commands related to GNSS module.
#define SBG_ECOM_MAX_BUFFER_SIZE


sbg_driver
Author(s):
autogenerated on Sun Jan 27 2019 03:42:20