sbgEComCmdAdvanced.c
Go to the documentation of this file.
1 #include "sbgEComCmdAdvanced.h"
3 
4 //----------------------------------------------------------------------//
5 //- Event commands -//
6 //----------------------------------------------------------------------//
7 
15 {
16  SbgErrorCode errorCode = SBG_NO_ERROR;
17  uint32_t trial;
18  size_t receivedSize;
19  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
20  SbgStreamBuffer inputStream;
21 
22  assert(pHandle);
23  assert(pConf);
24 
25  //
26  // Send the command three times
27  //
28  for (trial = 0; trial < pHandle->numTrials; trial++)
29  {
30  //
31  // Send the command without payload since this is a no-payload command
32  //
34 
35  //
36  // Make sure that the command has been sent
37  //
38  if (errorCode == SBG_NO_ERROR)
39  {
40  //
41  // Try to read the device answer for 500 ms
42  //
43  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_ADVANCED_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
44 
45  //
46  // Test if we have received a SBG_ECOM_CMD_ADVANCED_CONF command
47  //
48  if (errorCode == SBG_NO_ERROR)
49  {
50  //
51  // Initialize stream buffer to read parameters
52  //
53  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
54 
55  //
56  // Read parameters
57  //
59 
60  //
61  // The command has been executed successfully so return
62  //
63  break;
64  }
65  }
66  else
67  {
68  //
69  // We have a write error so exit the try loop
70  //
71  break;
72  }
73  }
74 
75  return errorCode;
76 }
77 
85 {
86  SbgErrorCode errorCode = SBG_NO_ERROR;
87  uint32_t trial;
88  uint8_t outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
89  SbgStreamBuffer outputStream;
90 
91  assert(pHandle);
92  assert(pConf);
93 
94  //
95  // Send the command three times
96  //
97  for (trial = 0; trial < pHandle->numTrials; trial++)
98  {
99  //
100  // Init stream buffer for output
101  //
102  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
103 
104  //
105  // Build payload
106  //
107  sbgStreamBufferWriteUint8LE(&outputStream, (uint8_t)pConf->timeReference);
108 
109  //
110  // Send the payload over ECom
111  //
113 
114  //
115  // Make sure that the command has been sent
116  //
117  if (errorCode == SBG_NO_ERROR)
118  {
119  //
120  // Try to read the device answer for 500 ms
121  //
123 
124  //
125  // Test if we have received a valid ACK
126  //
127  if (errorCode == SBG_NO_ERROR)
128  {
129  //
130  // The command has been executed successfully so return
131  //
132  break;
133  }
134  }
135  else
136  {
137  //
138  // We have a write error so exit the try loop
139  //
140  break;
141  }
142  }
143 
144  return errorCode;
145 }
146 
155 {
156  SbgErrorCode errorCode = SBG_NO_ERROR;
157  uint32_t trial;
158  size_t receivedSize;
159  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
160  SbgStreamBuffer inputStream;
161 
162  assert(pHandle);
163  assert(pConf);
164 
165  //
166  // Send the command three times
167  //
168  for (trial = 0; trial < pHandle->numTrials; trial++)
169  {
170  //
171  // Send the command without payload since this is a no-payload command
172  //
174 
175  //
176  // Make sure that the command has been sent
177  //
178  if (errorCode == SBG_NO_ERROR)
179  {
180  //
181  // Try to read the device answer for 500 ms
182  //
183  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_VALIDITY_THRESHOLDS, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
184 
185  //
186  // Test if we have received a SBG_ECOM_CMD_VALIDITY_THRESHOLDS command
187  //
188  if (errorCode == SBG_NO_ERROR)
189  {
190  //
191  // Initialize stream buffer to read parameters
192  //
193  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
194 
195  //
196  // Read parameters and check payload consistency
197  //
198  pConf->positionThreshold = sbgStreamBufferReadFloatLE(&inputStream);
199  pConf->velocityThreshold = sbgStreamBufferReadFloatLE(&inputStream);
200  pConf->attitudeThreshold = sbgStreamBufferReadFloatLE(&inputStream);
201  pConf->headingThreshold = sbgStreamBufferReadFloatLE(&inputStream);
202 
203  errorCode = sbgStreamBufferGetLastError(&inputStream);
204 
205  //
206  // The command has been executed successfully so return
207  //
208  break;
209  }
210  }
211  else
212  {
213  //
214  // We have a write error so exit the try loop
215  //
216  break;
217  }
218  }
219 
220  return errorCode;
221 }
229 {
230  SbgErrorCode errorCode = SBG_NO_ERROR;
231  uint32_t trial;
232  uint8_t outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
233  SbgStreamBuffer outputStream;
234 
235  assert(pHandle);
236  assert(pConf);
237 
238  //
239  // Send the command three times
240  //
241  for (trial = 0; trial < pHandle->numTrials; trial++)
242  {
243  //
244  // Init stream buffer for output
245  //
246  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
247 
248  //
249  // Build payload
250  //
251  sbgStreamBufferWriteFloatLE(&outputStream, pConf->positionThreshold);
252  sbgStreamBufferWriteFloatLE(&outputStream, pConf->velocityThreshold);
253  sbgStreamBufferWriteFloatLE(&outputStream, pConf->attitudeThreshold);
254  sbgStreamBufferWriteFloatLE(&outputStream, pConf->headingThreshold);
255 
256  //
257  // Send the payload over ECom
258  //
260 
261  //
262  // Make sure that the command has been sent
263  //
264  if (errorCode == SBG_NO_ERROR)
265  {
266  //
267  // Try to read the device answer for 500 ms
268  //
270 
271  //
272  // Test if we have received a valid ACK
273  //
274  if (errorCode == SBG_NO_ERROR)
275  {
276  //
277  // The command has been executed successfully so return
278  //
279  break;
280  }
281  }
282  else
283  {
284  //
285  // We have a write error so exit the try loop
286  //
287  break;
288  }
289  }
290 
291  return errorCode;
292 }
This file implements SbgECom commands related to advanced settings.
enum _SbgEComTimeReferenceSrc SbgEComTimeReferenceSrc
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
SBG_INLINE float sbgStreamBufferReadFloatLE(SbgStreamBuffer *pHandle)
Used to read/write data from/to a memory buffer stream.
SbgErrorCode sbgEComCmdAdvancedSetConf(SbgEComHandle *pHandle, const SbgEComAdvancedConf *pConf)
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8_t msgClass, uint8_t msg, const void *pData, size_t size)
SbgErrorCode sbgEComCmdAdvancedSetThresholds(SbgEComHandle *pHandle, const SbgEComValidityThresholds *pConf)
SbgErrorCode sbgEComCmdAdvancedGetThresholds(SbgEComHandle *pHandle, SbgEComValidityThresholds *pConf)
SbgEComProtocol protocolHandle
Definition: sbgECom.h:72
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t timeOut)
SbgEComTimeReferenceSrc timeReference
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
#define NULL
Definition: sbgDefines.h:81
SbgErrorCode sbgEComCmdAdvancedGetConf(SbgEComHandle *pHandle, SbgEComAdvancedConf *pConf)
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)
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
enum _SbgErrorCode SbgErrorCode
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError(SbgStreamBuffer *pHandle)
#define SBG_ECOM_MAX_BUFFER_SIZE


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