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_t trial;
19  size_t receivedSize;
20  uint8_t outputBuffer;
21  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
22  SbgStreamBuffer inputStream;
23 
24  assert(pHandle);
25  assert(pConf);
26 
27  //
28  // Send the command three times
29  //
30  for (trial = 0; trial < pHandle->numTrials; trial++)
31  {
32  //
33  // Send the command with syncInId as a 1-byte payload
34  //
35  outputBuffer = (uint8_t)syncInId;
36  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_IN_CONF, &outputBuffer, sizeof(uint8_t));
37 
38  //
39  // Make sure that the command has been sent
40  //
41  if (errorCode == SBG_NO_ERROR)
42  {
43  //
44  // Try to read the device answer for 500 ms
45  //
46  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_IN_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
47 
48  //
49  // Test if we have received a SBG_ECOM_CMD_SYNC_IN_CONF command
50  //
51  if (errorCode == SBG_NO_ERROR)
52  {
53  //
54  // Initialize stream buffer to read parameters
55  //
56  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
57 
58  //
59  // Read parameters
60  // First is returned the id of the sync, then the sensitivity and the delay at last.
61  //
62  syncInId = (SbgEComSyncInId)sbgStreamBufferReadUint8LE(&inputStream);
64  pConf->delay = sbgStreamBufferReadInt32LE(&inputStream);
65 
66  //
67  // The command has been executed successfully so return
68  //
69  break;
70  }
71  }
72  else
73  {
74  //
75  // We have a write error so exit the try loop
76  //
77  break;
78  }
79  }
80 
81  return errorCode;
82 }
83 
92 {
93  SbgErrorCode errorCode = SBG_NO_ERROR;
94  uint32_t trial;
95  uint8_t outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
96  SbgStreamBuffer outputStream;
97 
98  assert(pHandle);
99  assert(pConf);
100 
101  //
102  // Send the command three times
103  //
104  for (trial = 0; trial < pHandle->numTrials; trial++)
105  {
106  //
107  // Init stream buffer for output
108  //
109  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
110 
111  //
112  // Build payload
113  //
114  sbgStreamBufferWriteUint8LE(&outputStream, (uint8_t)syncInId);
115  sbgStreamBufferWriteUint8LE(&outputStream, (uint8_t)pConf->sensitivity);
116  sbgStreamBufferWriteInt32LE(&outputStream, pConf->delay);
117 
118  //
119  // Send the message over ECom
120  //
122 
123  //
124  // Make sure that the command has been sent
125  //
126  if (errorCode == SBG_NO_ERROR)
127  {
128  //
129  // Try to read the device answer for 500 ms
130  //
132 
133  //
134  // Test if we have received a valid ACK
135  //
136  if (errorCode == SBG_NO_ERROR)
137  {
138  //
139  // The command has been executed successfully so return
140  //
141  break;
142  }
143  }
144  else
145  {
146  //
147  // We have a write error so exit the try loop
148  //
149  break;
150  }
151  }
152 
153  return errorCode;
154 }
155 
164 {
165  SbgErrorCode errorCode = SBG_NO_ERROR;
166  uint32_t trial;
167  size_t receivedSize;
168  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
169  SbgStreamBuffer inputStream;
170  uint8_t outputBuffer;
171 
172  assert(pHandle);
173  assert(pConf);
174 
175  //
176  // Send the command three times
177  //
178  for (trial = 0; trial < pHandle->numTrials; trial++)
179  {
180  //
181  // Send the command with syncOutId as a 1-byte payload
182  //
183  outputBuffer = (uint8_t)syncOutId;
184  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_OUT_CONF, &outputBuffer, sizeof(uint8_t));
185 
186  //
187  // Make sure that the command has been sent
188  //
189  if (errorCode == SBG_NO_ERROR)
190  {
191  //
192  // Try to read the device answer for 500 ms
193  //
194  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_SYNC_OUT_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
195 
196  //
197  // Test if we have received a SBG_ECOM_CMD_SYNC_OUT_CONF command
198  //
199  if (errorCode == SBG_NO_ERROR)
200  {
201  //
202  // Initialize stream buffer to read parameters
203  //
204  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
205 
206  //
207  // Read parameters
208  // First is returned the id of the sync, then a reserved field, the output function, polarity and the duration at last.
209  //
210  syncOutId = (SbgEComSyncOutId)sbgStreamBufferReadUint8LE(&inputStream);
211  sbgStreamBufferReadUint8LE(&inputStream);
214  pConf->duration = sbgStreamBufferReadUint32LE(&inputStream);
215 
216  //
217  // The command has been executed successfully so return
218  //
219  break;
220  }
221  }
222  else
223  {
224  //
225  // We have a write error so exit the try loop
226  //
227  break;
228  }
229  }
230 
231  return errorCode;
232 }
233 
242 {
243  SbgErrorCode errorCode = SBG_NO_ERROR;
244  uint32_t trial;
245  uint8_t outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
246  SbgStreamBuffer outputStream;
247 
248  assert(pHandle);
249  assert(pConf);
250 
251  //
252  // Send the command three times
253  //
254  for (trial = 0; trial < pHandle->numTrials; trial++)
255  {
256  //
257  // Init stream buffer for output
258  //
259  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
260 
261  //
262  // Build payload
263  //
264  sbgStreamBufferWriteUint8LE(&outputStream, (uint8_t)syncOutId);
265  sbgStreamBufferWriteUint8LE(&outputStream, 0);
266  sbgStreamBufferWriteUint16LE(&outputStream, (uint16_t)pConf->outputFunction);
267  sbgStreamBufferWriteUint8LE(&outputStream, (uint8_t)pConf->polarity);
268  sbgStreamBufferWriteUint32LE(&outputStream, pConf->duration);
269 
270  //
271  // Send the payload over ECom
272  //
274 
275  //
276  // Make sure that the command has been sent
277  //
278  if (errorCode == SBG_NO_ERROR)
279  {
280  //
281  // Try to read the device answer for 500 ms
282  //
284 
285  //
286  // Test if we have received a valid ACK
287  //
288  if (errorCode == SBG_NO_ERROR)
289  {
290  //
291  // The command has been executed successfully so return
292  //
293  break;
294  }
295  }
296  else
297  {
298  //
299  // We have a write error so exit the try loop
300  //
301  break;
302  }
303  }
304 
305  return errorCode;
306 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
SbgEComSyncInSensitivity sensitivity
SbgErrorCode sbgEComCmdSyncOutGetConf(SbgEComHandle *pHandle, SbgEComSyncOutId syncOutId, SbgEComSyncOutConf *pConf)
enum _SbgEComSyncOutFunction SbgEComSyncOutFunction
enum _SbgEComSyncOutId SbgEComSyncOutId
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)
enum _SbgEComSyncOutPolarity SbgEComSyncOutPolarity
SbgErrorCode sbgEComCmdSyncInSetConf(SbgEComHandle *pHandle, SbgEComSyncInId syncInId, const SbgEComSyncInConf *pConf)
SbgEComProtocol protocolHandle
Definition: sbgECom.h:72
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
SBG_INLINE uint16_t sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t timeOut)
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
SbgEComSyncOutPolarity polarity
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
enum _SbgEComSyncInSensitivity SbgEComSyncInSensitivity
SbgErrorCode sbgEComReceiveCmd(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, void *pData, size_t *pSize, size_t maxSize, uint32_t timeOut)
#define sbgStreamBufferReadUint8LE
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt32LE(SbgStreamBuffer *pHandle, int32_t value)
uint32_t numTrials
Definition: sbgECom.h:77
SBG_INLINE int32_t sbgStreamBufferReadInt32LE(SbgStreamBuffer *pHandle)
SbgErrorCode sbgEComCmdSyncOutSetConf(SbgEComHandle *pHandle, SbgEComSyncOutId syncOutId, const SbgEComSyncOutConf *pConf)
SbgEComSyncOutFunction outputFunction
This file implements SbgECom commands related to events.
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32_t value)
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
SBG_INLINE uint32_t sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16LE(SbgStreamBuffer *pHandle, uint16_t value)
enum _SbgEComSyncInId SbgEComSyncInId
enum _SbgErrorCode SbgErrorCode
SbgErrorCode sbgEComCmdSyncInGetConf(SbgEComHandle *pHandle, SbgEComSyncInId syncInId, SbgEComSyncInConf *pConf)
#define SBG_ECOM_MAX_BUFFER_SIZE


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