sbgEComCmdInterface.c
Go to the documentation of this file.
1 #include "sbgEComCmdInterface.h"
3 
4 //----------------------------------------------------------------------//
5 //- Interface commands -//
6 //----------------------------------------------------------------------//
7 
16 {
17  SbgErrorCode errorCode = SBG_NO_ERROR;
18  uint32 trial;
19  size_t receivedSize;
20  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
21  SbgStreamBuffer inputStream;
22  uint8 outputBuffer;
23 
24  //
25  // Test that the input pointer 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 and the interfaceId as a 1-byte payload
36  //
37  outputBuffer = (uint8)interfaceId;
38  errorCode = sbgEComProtocolSend(&pHandle->protocolHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_UART_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_UART_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
49 
50  //
51  // Test if we have received correctly the answer
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 interfaceId, then baud rate and the mode at last.
63  //
64  interfaceId = (SbgEComPortId)sbgStreamBufferReadUint8LE(&inputStream);
65  pConf->baudRate = sbgStreamBufferReadUint32LE(&inputStream);
66  pConf->mode = (SbgEComPortMode)sbgStreamBufferReadUint8LE(&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)interfaceId);
127  sbgStreamBufferWriteUint32LE(&outputStream, pConf->baudRate);
128  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pConf->mode);
129 
130  //
131  // Send the payload 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  // Invalid protocol handle.
169  //
170  errorCode = SBG_NULL_POINTER;
171  }
172 
173  return errorCode;
174 }
175 
183 {
184  SbgErrorCode errorCode = SBG_NO_ERROR;
185  uint32 trial;
186  size_t receivedSize;
187  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
188  SbgStreamBuffer inputStream;
189 
190  //
191  // Test that the input pointer are valid
192  //
193  if ((pHandle) && (pBitrate))
194  {
195  //
196  // Send the command three times
197  //
198  for (trial = 0; trial < pHandle->numTrials; trial++)
199  {
200  //
201  // Send the command with no payload
202  //
204 
205  //
206  // Make sure that the command has been sent
207  //
208  if (errorCode == SBG_NO_ERROR)
209  {
210  //
211  // Try to read the device answer for 500 ms
212  //
213  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_CAN_BUS_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
214 
215  //
216  // Test if we have received a SBG_ECOM_CMD_CAN_BUS_CONF command
217  //
218  if (errorCode == SBG_NO_ERROR)
219  {
220  //
221  // Initialize stream buffer to read parameters
222  //
223  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
224 
225  //
226  // Read bit rate returned by the device
227  //
228  *pBitrate = (SbgEComCanBitRate)sbgStreamBufferReadUint16LE(&inputStream);
229 
230  //
231  // The command has been executed successfully so return
232  //
233  break;
234  }
235  }
236  else
237  {
238  //
239  // We have a write error so exit the try loop
240  //
241  break;
242  }
243  }
244  }
245  else
246  {
247  //
248  // Null pointer.
249  //
250  errorCode = SBG_NULL_POINTER;
251  }
252 
253  return errorCode;
254 }
255 
263 {
264  SbgErrorCode errorCode = SBG_NO_ERROR;
265  uint32 trial;
266  uint8 outputBuffer[2];
267  SbgStreamBuffer outputStream;
268  //
269  // Test that the input pointer are valid
270  //
271  if (pHandle)
272  {
273  //
274  // Send the command three times
275  //
276  for (trial = 0; trial < pHandle->numTrials; trial++)
277  {
278  //
279  // Build the payload
280  //
281  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
282  sbgStreamBufferWriteUint16LE(&outputStream, bitrate);
283 
284  //
285  // Send the payload over ECom
286  //
288 
289  //
290  // Make sure that the command has been sent
291  //
292  if (errorCode == SBG_NO_ERROR)
293  {
294  //
295  // Try to read the device answer for 500 ms
296  //
298 
299  //
300  // Test if we have received a valid ACK
301  //
302  if (errorCode == SBG_NO_ERROR)
303  {
304  //
305  // The command has been executed successfully so return
306  //
307  break;
308  }
309  }
310  else
311  {
312  //
313  // We have a write error so exit the try loop
314  //
315  break;
316  }
317  }
318  }
319  else
320  {
321  //
322  // Invalid protocol handle.
323  //
324  errorCode = SBG_NULL_POINTER;
325  }
326 
327  return errorCode;
328 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
enum _SbgEComPortId SbgEComPortId
SbgErrorCode sbgEComReceiveCmd(SbgEComHandle *pHandle, uint8 msgClass, uint8 msg, void *pData, size_t *pSize, size_t maxSize, uint32 timeOut)
unsigned int uint32
Definition: sbgTypes.h:58
Used to read/write data from/to a memory buffer stream.
SBG_INLINE uint16 sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
enum _SbgEComCanBitRate SbgEComCanBitRate
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)
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
uint32 numTrials
Definition: sbgECom.h:86
#define NULL
Definition: sbgDefines.h:43
uint32 cmdDefaultTimeOut
Definition: sbgECom.h:87
SBG_INLINE uint32 sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
SbgErrorCode sbgEComCmdInterfaceSetUartConf(SbgEComHandle *pHandle, SbgEComPortId interfaceId, const SbgEComInterfaceConf *pConf)
SbgErrorCode sbgEComCmdInterfaceGetUartConf(SbgEComHandle *pHandle, SbgEComPortId interfaceId, SbgEComInterfaceConf *pConf)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16LE(SbgStreamBuffer *pHandle, uint16 value)
#define sbgStreamBufferReadUint8LE
SbgErrorCode sbgEComCmdInterfaceGetCanConf(SbgEComHandle *pHandle, SbgEComCanBitRate *pBitrate)
enum _SbgEComPortMode SbgEComPortMode
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32 value)
SbgErrorCode sbgEComCmdInterfaceSetCanConf(SbgEComHandle *pHandle, SbgEComCanBitRate bitrate)
This file implements SbgECom commands related to interfaces.
unsigned char uint8
Definition: sbgTypes.h:56
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
enum _SbgErrorCode SbgErrorCode
#define SBG_ECOM_MAX_BUFFER_SIZE


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