sbgEComCmdDvl.c
Go to the documentation of this file.
1 /* sbgCommonLib headers */
3 
4 /* Project headers */
6 
7 /* Local headers */
8 #include "sbgEComCmdDvl.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 = (SbgEComDvlModelsIds)modelIdAsUint;
34  }
35 
36  return errorCode;
37 }
38 
47 {
48  SbgErrorCode errorCode = SBG_NO_ERROR;
49  uint32_t trial;
50  uint8_t outputBuffer[64];
51  SbgStreamBuffer outputStream;
52 
53  assert(pHandle);
54  assert(pDvlInstallation);
55 
56  //
57  // Create the command payload
58  //
59  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
60 
61  //
62  // Build payload
63  //
64  sbgStreamBufferWriteFloatLE(&outputStream, pDvlInstallation->leverArm[0]);
65  sbgStreamBufferWriteFloatLE(&outputStream, pDvlInstallation->leverArm[1]);
66  sbgStreamBufferWriteFloatLE(&outputStream, pDvlInstallation->leverArm[2]);
67 
68  sbgStreamBufferWriteFloatLE(&outputStream, pDvlInstallation->alignment[0]);
69  sbgStreamBufferWriteFloatLE(&outputStream, pDvlInstallation->alignment[1]);
70  sbgStreamBufferWriteFloatLE(&outputStream, pDvlInstallation->alignment[2]);
71 
72  sbgStreamBufferWriteBooleanLE(&outputStream, pDvlInstallation->preciseInstallation);
73 
74  //
75  // Make sure the payload has been build correctly
76  //
77  errorCode = sbgStreamBufferGetLastError(&outputStream);
78 
79  if (errorCode == SBG_NO_ERROR)
80  {
81  //
82  // Send the command three times
83  //
84  for (trial = 0; trial < pHandle->numTrials; trial++)
85  {
86  //
87  // Send the payload over ECom
88  //
90 
91  //
92  // Make sure that the command has been sent
93  //
94  if (errorCode == SBG_NO_ERROR)
95  {
96  //
97  // Try to read the device answer for 500 ms
98  //
100 
101  //
102  // Test if we have received a valid ACK
103  //
104  if (errorCode == SBG_NO_ERROR)
105  {
106  //
107  // The command has been executed successfully so return
108  //
109  break;
110  }
111  }
112  else
113  {
114  //
115  // We have a write error so exit the try loop
116  //
117  break;
118  }
119  }
120  }
121 
122  return errorCode;
123 }
125 {
126  SbgErrorCode errorCode = SBG_NO_ERROR;
127  uint32_t trial;
128  size_t receivedSize;
129  uint8_t receivedBuffer[64];
130  SbgStreamBuffer inputStream;
131 
132  assert(pHandle);
133  assert(pDvlInstallation);
134 
135  //
136  // Send the command three times
137  //
138  for (trial = 0; trial < pHandle->numTrials; trial++)
139  {
140  //
141  // Send the command only since this is a no-payload command
142  //
144 
145  //
146  // Make sure that the command has been sent
147  //
148  if (errorCode == SBG_NO_ERROR)
149  {
150  //
151  // Try to read the device answer for 500 ms
152  //
153  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_DVL_INSTALLATION, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
154 
155  //
156  // Test if we have received a SBG_ECOM_CMD_GNSS_1_LEVER_ARM_ALIGNMENT command
157  //
158  if (errorCode == SBG_NO_ERROR)
159  {
160  //
161  // Initialize stream buffer to parse the payload
162  //
163  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
164 
165  pDvlInstallation->leverArm[0] = sbgStreamBufferReadFloatLE(&inputStream);
166  pDvlInstallation->leverArm[1] = sbgStreamBufferReadFloatLE(&inputStream);
167  pDvlInstallation->leverArm[2] = sbgStreamBufferReadFloatLE(&inputStream);
168 
169  pDvlInstallation->alignment[0] = sbgStreamBufferReadFloatLE(&inputStream);
170  pDvlInstallation->alignment[1] = sbgStreamBufferReadFloatLE(&inputStream);
171  pDvlInstallation->alignment[2] = sbgStreamBufferReadFloatLE(&inputStream);
172 
173  pDvlInstallation->preciseInstallation = sbgStreamBufferReadBooleanLE(&inputStream);
174 
175  //
176  // The command has been executed successfully so return if an error has occurred during payload parsing
177  //
178  errorCode = sbgStreamBufferGetLastError(&inputStream);
179  break;
180  }
181  }
182  else
183  {
184  //
185  // We have a write error so exit the try loop
186  //
187  break;
188  }
189  }
190 
191  return errorCode;
192 }
193 
195 {
196  SbgErrorCode errorCode = SBG_NO_ERROR;
197  uint32_t trial;
198  uint8_t outputBuffer[2*sizeof(uint8_t)];
199  SbgStreamBuffer outputStream;
200 
201  assert(pHandle);
202  assert(pRejectConf);
203 
204  //
205  // Create the command payload
206  //
207  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
208 
209  //
210  // Build payload
211  //
212  sbgStreamBufferWriteUint8LE(&outputStream, pRejectConf->bottomLayer);
213  sbgStreamBufferWriteUint8LE(&outputStream, pRejectConf->waterLayer);
214 
215  //
216  // Make sure the payload has been build correctly
217  //
218  errorCode = sbgStreamBufferGetLastError(&outputStream);
219 
220  if (errorCode == SBG_NO_ERROR)
221  {
222  //
223  // Send the command three times
224  //
225  for (trial = 0; trial < pHandle->numTrials; trial++)
226  {
227  //
228  // Send the payload over ECom
229  //
231 
232  //
233  // Make sure that the command has been sent
234  //
235  if (errorCode == SBG_NO_ERROR)
236  {
237  //
238  // Try to read the device answer for 500 ms
239  //
241 
242  //
243  // Test if we have received a valid ACK
244  //
245  if (errorCode == SBG_NO_ERROR)
246  {
247  //
248  // The command has been executed successfully so return
249  //
250  break;
251  }
252  }
253  else
254  {
255  //
256  // We have a write error so exit the try loop
257  //
258  break;
259  }
260  }
261  }
262 
263  return errorCode;
264 }
265 
267 {
268  SbgErrorCode errorCode = SBG_NO_ERROR;
269  uint32_t trial;
270  size_t receivedSize;
271  uint8_t receivedBuffer[2*sizeof(uint8_t)];
272  SbgStreamBuffer inputStream;
273 
274  assert(pHandle);
275  assert(pRejectConf);
276 
277  //
278  // Send the command three times
279  //
280  for (trial = 0; trial < pHandle->numTrials; trial++)
281  {
282  //
283  // Send the command only since this is a no-payload command
284  //
286 
287  //
288  // Make sure that the command has been sent
289  //
290  if (errorCode == SBG_NO_ERROR)
291  {
292  //
293  // Try to read the device answer for 500 ms
294  //
295  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_DVL_REJECT_MODES, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
296 
297  //
298  // Test if we have received a SBG_ECOM_CMD_GNSS_1_REJECT_MODES command
299  //
300  if (errorCode == SBG_NO_ERROR)
301  {
302  //
303  // Initialize stream buffer to parse payload
304  //
305  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
306 
307  //
308  // Parse the payload
309  //
310  pRejectConf->bottomLayer = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
311  pRejectConf->waterLayer = (SbgEComRejectionMode)sbgStreamBufferReadUint8LE(&inputStream);
312 
313  //
314  // The command has been executed successfully so return if an error has occurred during payload parsing
315  //
316  errorCode = sbgStreamBufferGetLastError(&inputStream);
317  break;
318  }
319  }
320  else
321  {
322  //
323  // We have a write error so exit the try loop
324  //
325  break;
326  }
327  }
328 
329  return errorCode;
330 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
SbgErrorCode sbgEComCmdDvlGetRejection(SbgEComHandle *pHandle, SbgEComDvlRejectionConf *pRejectConf)
SbgErrorCode sbgEComCmdDvlInstallationSet(SbgEComHandle *pHandle, const SbgEComDvlInstallation *pDvlInstallation)
Definition: sbgEComCmdDvl.c:46
SBG_INLINE float sbgStreamBufferReadFloatLE(SbgStreamBuffer *pHandle)
Used to read/write data from/to a memory buffer stream.
SbgEComRejectionMode bottomLayer
Definition: sbgEComCmdDvl.h:56
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)
#define sbgStreamBufferWriteBooleanLE
enum _SbgEComRejectionMode SbgEComRejectionMode
SbgErrorCode sbgEComCmdDvlSetModelId(SbgEComHandle *pHandle, SbgEComDvlModelsIds modelId)
Definition: sbgEComCmdDvl.c:14
SbgErrorCode sbgEComCmdDvlGetModelId(SbgEComHandle *pHandle, SbgEComDvlModelsIds *pModelId)
Definition: sbgEComCmdDvl.c:21
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 sbgEComWaitForAck(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t timeOut)
This file implements sbgECom commands related to DVL module.
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
#define NULL
Definition: sbgDefines.h:81
SbgErrorCode sbgEComCmdDvlInstallationGet(SbgEComHandle *pHandle, SbgEComDvlInstallation *pDvlInstallation)
SbgEComRejectionMode waterLayer
Definition: sbgEComCmdDvl.h:57
enum _SbgEComDvlModelsIds SbgEComDvlModelsIds
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)
SbgErrorCode sbgEComCmdDvlSetRejection(SbgEComHandle *pHandle, const SbgEComDvlRejectionConf *pRejectConf)
#define sbgStreamBufferReadBooleanLE
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
enum _SbgErrorCode SbgErrorCode
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError(SbgStreamBuffer *pHandle)


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