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 }
sbgStreamBufferReadUint8LE
#define sbgStreamBufferReadUint8LE
Definition: sbgStreamBufferCommon.h:141
_SbgEComSyncOutConf::outputFunction
SbgEComSyncOutFunction outputFunction
Definition: sbgEComCmdEvent.h:114
sbgEComWaitForAck
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t timeOut)
Definition: sbgEComCmdCommon.c:278
SbgEComSyncOutId
enum _SbgEComSyncOutId SbgEComSyncOutId
sbgStreamBufferWriteInt32LE
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt32LE(SbgStreamBuffer *pHandle, int32_t value)
Definition: sbgStreamBufferLE.h:1434
sbgStreamBufferInitForWrite
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
Definition: sbgStreamBufferCommon.h:208
sbgStreamBufferReadUint16LE
SBG_INLINE uint16_t sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:106
sbgEComCmdSyncOutGetConf
SbgErrorCode sbgEComCmdSyncOutGetConf(SbgEComHandle *pHandle, SbgEComSyncOutId syncOutId, SbgEComSyncOutConf *pConf)
Definition: sbgEComCmdEvent.c:163
_SbgEComSyncInConf::sensitivity
SbgEComSyncInSensitivity sensitivity
Definition: sbgEComCmdEvent.h:105
_SbgEComSyncOutConf
Definition: sbgEComCmdEvent.h:112
SBG_ECOM_MAX_BUFFER_SIZE
#define SBG_ECOM_MAX_BUFFER_SIZE
Implementation of the Ekinox binary communication protocol. You can access low-level communication w...
Definition: sbgEComProtocol.h:35
sbgStreamBufferReadInt32LE
SBG_INLINE int32_t sbgStreamBufferReadInt32LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:313
sbgStreamBufferGetLinkedBuffer
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferCommon.h:467
sbgEComCmdSyncInGetConf
SbgErrorCode sbgEComCmdSyncInGetConf(SbgEComHandle *pHandle, SbgEComSyncInId syncInId, SbgEComSyncInConf *pConf)
Definition: sbgEComCmdEvent.c:15
SbgEComSyncOutFunction
enum _SbgEComSyncOutFunction SbgEComSyncOutFunction
_SbgEComSyncOutConf::polarity
SbgEComSyncOutPolarity polarity
Definition: sbgEComCmdEvent.h:115
_SbgEComSyncInConf::delay
int32_t delay
Definition: sbgEComCmdEvent.h:106
SBG_ECOM_CLASS_LOG_CMD_0
@ SBG_ECOM_CLASS_LOG_CMD_0
Definition: sbgEComIds.h:59
sbgStreamBufferWriteUint16LE
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16LE(SbgStreamBuffer *pHandle, uint16_t value)
Definition: sbgStreamBufferLE.h:1250
SBG_ECOM_CMD_SYNC_IN_CONF
@ SBG_ECOM_CMD_SYNC_IN_CONF
Definition: sbgEComIds.h:241
sbgEComReceiveCmd
SbgErrorCode sbgEComReceiveCmd(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, void *pData, size_t *pSize, size_t maxSize, uint32_t timeOut)
Definition: sbgEComCmdCommon.c:174
SbgEComSyncInSensitivity
enum _SbgEComSyncInSensitivity SbgEComSyncInSensitivity
sbgStreamBufferReadUint32LE
SBG_INLINE uint32_t sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:386
_SbgEComHandle::cmdDefaultTimeOut
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
_SbgEComHandle::protocolHandle
SbgEComProtocol protocolHandle
Definition: sbgECom.h:72
_SbgEComHandle
Definition: sbgECom.h:70
_SbgEComHandle::numTrials
uint32_t numTrials
Definition: sbgECom.h:77
_SbgStreamBuffer
Definition: sbgStreamBufferCommon.h:188
sbgStreamBufferWriteUint8LE
#define sbgStreamBufferWriteUint8LE
Definition: sbgStreamBufferCommon.h:146
sbgEComCmdEvent.h
sbgStreamBufferGetLength
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferCommon.h:333
SBG_NO_ERROR
@ SBG_NO_ERROR
Definition: sbgErrorCodes.h:35
SBG_ECOM_CMD_SYNC_OUT_CONF
@ SBG_ECOM_CMD_SYNC_OUT_CONF
Definition: sbgEComIds.h:242
sbgEComCmdSyncOutSetConf
SbgErrorCode sbgEComCmdSyncOutSetConf(SbgEComHandle *pHandle, SbgEComSyncOutId syncOutId, const SbgEComSyncOutConf *pConf)
Definition: sbgEComCmdEvent.c:241
sbgStreamBuffer.h
_SbgEComSyncOutConf::duration
uint32_t duration
Definition: sbgEComCmdEvent.h:116
SbgEComSyncInId
enum _SbgEComSyncInId SbgEComSyncInId
This file implements SbgECom commands related to events.
SbgEComSyncOutPolarity
enum _SbgEComSyncOutPolarity SbgEComSyncOutPolarity
sbgEComCmdSyncInSetConf
SbgErrorCode sbgEComCmdSyncInSetConf(SbgEComHandle *pHandle, SbgEComSyncInId syncInId, const SbgEComSyncInConf *pConf)
Definition: sbgEComCmdEvent.c:91
SbgErrorCode
enum _SbgErrorCode SbgErrorCode
Header file that defines all error codes for SBG Systems libraries.
sbgEComProtocolSend
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8_t msgClass, uint8_t msg, const void *pData, size_t size)
Definition: sbgEComProtocol.c:60
sbgStreamBufferInitForRead
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
Definition: sbgStreamBufferCommon.h:242
_SbgEComSyncInConf
Definition: sbgEComCmdEvent.h:103
sbgStreamBufferWriteUint32LE
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32_t value)
Definition: sbgStreamBufferLE.h:1499


sbg_driver
Author(s): SBG Systems
autogenerated on Fri Oct 11 2024 02:13:40