sbgEComCmdEvent.c
Go to the documentation of this file.
1 #include "sbgEComCmdEvent.h"
3 
4 //----------------------------------------------------------------------//
5 //- Event commands -//
6 //----------------------------------------------------------------------//
7 
16 {
17  SbgErrorCode errorCode = SBG_NO_ERROR;
18  uint32 trial;
19  size_t receivedSize;
20  uint8 outputBuffer;
21  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
22  SbgStreamBuffer inputStream;
23 
24  //
25  // Test that the input pointers are valid
26  //
27  if ((pHandle) && (pConf))
28  {
29  //
30  // Send the command three times
31  //
32  for (trial = 0; trial < pHandle->numTrials; trial++)
33  {
34  //
35  // Send the command with syncInId as a 1-byte payload
36  //
37  outputBuffer = (uint8)syncInId;
38  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_IN_CONF, &outputBuffer, sizeof(uint8));
39 
40  //
41  // Make sure that the command has been sent
42  //
43  if (errorCode == SBG_NO_ERROR)
44  {
45  //
46  // Try to read the device answer for 500 ms
47  //
48  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_IN_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
49 
50  //
51  // Test if we have received a SBG_ECOM_CMD_SYNC_IN_CONF command
52  //
53  if (errorCode == SBG_NO_ERROR)
54  {
55  //
56  // Initialize stream buffer to read parameters
57  //
58  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
59 
60  //
61  // Read parameters
62  // First is returned the id of the sync, then the sensitivity and the delay at last.
63  //
64  syncInId = (SbgEComSyncInId)sbgStreamBufferReadUint8LE(&inputStream);
66  pConf->delay = sbgStreamBufferReadInt32LE(&inputStream);
67 
68  //
69  // The command has been executed successfully so return
70  //
71  break;
72  }
73  }
74  else
75  {
76  //
77  // We have a write error so exit the try loop
78  //
79  break;
80  }
81  }
82  }
83  else
84  {
85  //
86  // Null pointer
87  //
88  errorCode = SBG_NULL_POINTER;
89  }
90 
91  return errorCode;
92 }
93 
102 {
103  SbgErrorCode errorCode = SBG_NO_ERROR;
104  uint32 trial;
105  uint8 outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
106  SbgStreamBuffer outputStream;
107 
108  //
109  // Test that the input pointer are valid
110  //
111  if ((pHandle) && (pConf))
112  {
113  //
114  // Send the command three times
115  //
116  for (trial = 0; trial < pHandle->numTrials; trial++)
117  {
118  //
119  // Init stream buffer for output
120  //
121  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
122 
123  //
124  // Build payload
125  //
126  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)syncInId);
127  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pConf->sensitivity);
128  sbgStreamBufferWriteInt32LE(&outputStream, pConf->delay);
129 
130  //
131  // Send the message over ECom
132  //
134 
135  //
136  // Make sure that the command has been sent
137  //
138  if (errorCode == SBG_NO_ERROR)
139  {
140  //
141  // Try to read the device answer for 500 ms
142  //
144 
145  //
146  // Test if we have received a valid ACK
147  //
148  if (errorCode == SBG_NO_ERROR)
149  {
150  //
151  // The command has been executed successfully so return
152  //
153  break;
154  }
155  }
156  else
157  {
158  //
159  // We have a write error so exit the try loop
160  //
161  break;
162  }
163  }
164  }
165  else
166  {
167  //
168  // Null pointer.
169  //
170  errorCode = SBG_NULL_POINTER;
171  }
172 
173  return errorCode;
174 }
175 
184 {
185  SbgErrorCode errorCode = SBG_NO_ERROR;
186  uint32 trial;
187  size_t receivedSize;
188  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
189  uint8 reserved;
190  SbgStreamBuffer inputStream;
191  uint8 outputBuffer;
192 
193  //
194  // Test that the input pointers are valid
195  //
196  if ((pHandle) && (pConf))
197  {
198  //
199  // Send the command three times
200  //
201  for (trial = 0; trial < pHandle->numTrials; trial++)
202  {
203  //
204  // Send the command with syncOutId as a 1-byte payload
205  //
206  outputBuffer = (uint8)syncOutId;
207  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_OUT_CONF, &outputBuffer, sizeof(uint8));
208 
209  //
210  // Make sure that the command has been sent
211  //
212  if (errorCode == SBG_NO_ERROR)
213  {
214  //
215  // Try to read the device answer for 500 ms
216  //
217  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_OUT_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
218 
219  //
220  // Test if we have received a SBG_ECOM_CMD_SYNC_OUT_CONF command
221  //
222  if (errorCode == SBG_NO_ERROR)
223  {
224  //
225  // Initialize stream buffer to read parameters
226  //
227  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
228 
229  //
230  // Read parameters
231  // First is returned the id of the sync, then a reserved field, the output function, polarity and the duration at last.
232  //
233  syncOutId = (SbgEComSyncOutId)sbgStreamBufferReadUint8LE(&inputStream);
234  reserved = sbgStreamBufferReadUint8LE(&inputStream);
237  pConf->duration = sbgStreamBufferReadUint32LE(&inputStream);
238 
239  //
240  // The command has been executed successfully so return
241  //
242  break;
243  }
244  }
245  else
246  {
247  //
248  // We have a write error so exit the try loop
249  //
250  break;
251  }
252  }
253  }
254  else
255  {
256  //
257  // Null pointer
258  //
259  errorCode = SBG_NULL_POINTER;
260  }
261 
262  return errorCode;
263 }
264 
273 {
274  SbgErrorCode errorCode = SBG_NO_ERROR;
275  uint32 trial;
276  uint8 outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
277  SbgStreamBuffer outputStream;
278 
279  //
280  // Test that the input pointer are valid
281  //
282  if ((pHandle) && (pConf))
283  {
284  //
285  // Send the command three times
286  //
287  for (trial = 0; trial < pHandle->numTrials; trial++)
288  {
289  //
290  // Init stream buffer for output
291  //
292  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
293 
294  //
295  // Build payload
296  //
297  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)syncOutId);
298  sbgStreamBufferWriteUint8LE(&outputStream, 0);
299  sbgStreamBufferWriteUint16LE(&outputStream, (uint16)pConf->outputFunction);
300  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pConf->polarity);
301  sbgStreamBufferWriteUint32LE(&outputStream, pConf->duration);
302 
303  //
304  // Send the payload over ECom
305  //
307 
308  //
309  // Make sure that the command has been sent
310  //
311  if (errorCode == SBG_NO_ERROR)
312  {
313  //
314  // Try to read the device answer for 500 ms
315  //
317 
318  //
319  // Test if we have received a valid ACK
320  //
321  if (errorCode == SBG_NO_ERROR)
322  {
323  //
324  // The command has been executed successfully so return
325  //
326  break;
327  }
328  }
329  else
330  {
331  //
332  // We have a write error so exit the try loop
333  //
334  break;
335  }
336  }
337  }
338  else
339  {
340  //
341  // Null pointer
342  //
343  errorCode = SBG_NULL_POINTER;
344  }
345 
346  return errorCode;
347 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
SbgEComSyncInSensitivity sensitivity
SbgErrorCode sbgEComReceiveCmd(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, void *pData, size_t *pSize, size_t maxSize, uint32 timeOut)
SbgErrorCode sbgEComCmdSyncOutGetConf(SbgEComHandle *pHandle, SbgEComSyncOutId syncOutId, SbgEComSyncOutConf *pConf)
unsigned int uint32
Definition: sbgTypes.h:58
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt32LE(SbgStreamBuffer *pHandle, int32 value)
enum _SbgEComSyncOutFunction SbgEComSyncOutFunction
enum _SbgEComSyncOutId SbgEComSyncOutId
Used to read/write data from/to a memory buffer stream.
enum _SbgEComSyncOutPolarity SbgEComSyncOutPolarity
SbgErrorCode sbgEComCmdSyncInSetConf(SbgEComHandle *pHandle, SbgEComSyncInId syncInId, const SbgEComSyncInConf *pConf)
SBG_INLINE uint16 sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, uint32 timeOut)
SbgEComProtocol protocolHandle
Definition: sbgECom.h:82
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8 msgClass, uint8 msg, const void *pData, size_t size)
SbgEComSyncOutPolarity polarity
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
uint32 numTrials
Definition: sbgECom.h:86
enum _SbgEComSyncInSensitivity SbgEComSyncInSensitivity
uint32 cmdDefaultTimeOut
Definition: sbgECom.h:87
SBG_INLINE uint32 sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16LE(SbgStreamBuffer *pHandle, uint16 value)
#define sbgStreamBufferReadUint8LE
SbgErrorCode sbgEComCmdSyncOutSetConf(SbgEComHandle *pHandle, SbgEComSyncOutId syncOutId, const SbgEComSyncOutConf *pConf)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32 value)
SbgEComSyncOutFunction outputFunction
unsigned char uint8
Definition: sbgTypes.h:56
This file implements SbgECom commands related to events.
SBG_INLINE int32 sbgStreamBufferReadInt32LE(SbgStreamBuffer *pHandle)
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
enum _SbgEComSyncInId SbgEComSyncInId
unsigned short uint16
Definition: sbgTypes.h:57
enum _SbgErrorCode SbgErrorCode
SbgErrorCode sbgEComCmdSyncInGetConf(SbgEComHandle *pHandle, SbgEComSyncInId syncInId, SbgEComSyncInConf *pConf)
#define SBG_ECOM_MAX_BUFFER_SIZE


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