sbgEComCmdInfo.c
Go to the documentation of this file.
1 #include "sbgEComCmdInfo.h"
3 
4 //----------------------------------------------------------------------//
5 //- Info commands -//
6 //----------------------------------------------------------------------//
7 
15 {
16  SbgErrorCode errorCode = SBG_NO_ERROR;
17  uint32_t trial;
18  size_t receivedSize;
19  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
20  SbgStreamBuffer inputStream;
21 
22  assert(pHandle);
23  assert(pInfo);
24 
25  //
26  // Send the command three times
27  //
28  for (trial = 0; trial < pHandle->numTrials; trial++)
29  {
30  //
31  // Send the command only since this is a no-payload command
32  //
34 
35  //
36  // Make sure that the command has been sent
37  //
38  if (errorCode == SBG_NO_ERROR)
39  {
40  //
41  // Try to read the device answer for 500 ms
42  //
43  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_INFO, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
44 
45  //
46  // Test if we have correctly received a message
47  //
48  if (errorCode == SBG_NO_ERROR)
49  {
50  //
51  // Make sure we have received a payload
52  //
53  if (receivedSize > 0)
54  {
55  //
56  // Initialize stream buffer to read parameters
57  //
58  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
59 
60  //
61  // Read parameters
62  //
64  pInfo->serialNumber = sbgStreamBufferReadUint32LE(&inputStream);
65  pInfo->calibationRev = sbgStreamBufferReadUint32LE(&inputStream);
66  pInfo->calibrationYear = sbgStreamBufferReadUint16LE(&inputStream);
67  pInfo->calibrationMonth = sbgStreamBufferReadUint8LE(&inputStream);
68  pInfo->calibrationDay = sbgStreamBufferReadUint8LE(&inputStream);
69  pInfo->hardwareRev = sbgStreamBufferReadUint32LE(&inputStream);
70  pInfo->firmwareRev = sbgStreamBufferReadUint32LE(&inputStream);
71 
72  //
73  // We have parsed a message so return immediately but report any error during payload parsing
74  //
75  errorCode = sbgStreamBufferGetLastError(&inputStream);
76 
77  break;
78  }
79  else
80  {
81  //
82  // We should have received a non empty payload so we have received an invalid frame
83  //
84  errorCode = SBG_INVALID_FRAME;
85  }
86  }
87  }
88  else
89  {
90  //
91  // We have a write error so exit the try loop
92  //
93  break;
94  }
95  }
96 
97  return errorCode;
98 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
uint8_t productCode[SBG_ECOM_INFO_PRODUCT_CODE_LENGTH]
uint16_t calibrationYear
This file implements SbgECom commands related to device info.
Used to read/write data from/to a memory buffer stream.
#define SBG_ECOM_INFO_PRODUCT_CODE_LENGTH
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8_t msgClass, uint8_t msg, const void *pData, size_t size)
SbgEComProtocol protocolHandle
Definition: sbgECom.h:72
SBG_INLINE uint16_t sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer(SbgStreamBuffer *pHandle, void *pBuffer, size_t numBytesToRead)
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
#define NULL
Definition: sbgDefines.h:81
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
SbgErrorCode sbgEComCmdGetInfo(SbgEComHandle *pHandle, SbgEComDeviceInfo *pInfo)
SBG_INLINE uint32_t sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
enum _SbgErrorCode SbgErrorCode
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError(SbgStreamBuffer *pHandle)
#define SBG_ECOM_MAX_BUFFER_SIZE


sbg_driver
Author(s): SBG Systems
autogenerated on Sat Sep 3 2022 02:53:36