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 trial;
18  size_t receivedSize;
19  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
20  SbgStreamBuffer inputStream;
21 
22  //
23  // Test that the input pointers are valid
24  //
25  if ((pHandle) && (pInfo))
26  {
27  //
28  // Send the command three times
29  //
30  for (trial = 0; trial < pHandle->numTrials; trial++)
31  {
32  //
33  // Send the command only since this is a no-payload command
34  //
36 
37  //
38  // Make sure that the command has been sent
39  //
40  if (errorCode == SBG_NO_ERROR)
41  {
42  //
43  // Try to read the device answer for 500 ms
44  //
45  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_INFO, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
46 
47  //
48  // Test if we have correctly received a message
49  //
50  if (errorCode == SBG_NO_ERROR)
51  {
52  //
53  // Make sure we have received a payload
54  //
55  if (receivedSize > 0)
56  {
57  //
58  // Initialize stream buffer to read parameters
59  //
60  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
61 
62  //
63  // Read parameters
64  //
66  pInfo->serialNumber = sbgStreamBufferReadUint32LE(&inputStream);
67  pInfo->calibationRev = sbgStreamBufferReadUint32LE(&inputStream);
68  pInfo->calibrationYear = sbgStreamBufferReadUint16LE(&inputStream);
69  pInfo->calibrationMonth = sbgStreamBufferReadUint8LE(&inputStream);
70  pInfo->calibrationDay = sbgStreamBufferReadUint8LE(&inputStream);
71  pInfo->hardwareRev = sbgStreamBufferReadUint32LE(&inputStream);
72  pInfo->firmwareRev = sbgStreamBufferReadUint32LE(&inputStream);
73 
74  //
75  // We have parsed a message so return immediately but report any error during payload parsing
76  //
77  errorCode = sbgStreamBufferGetLastError(&inputStream);
78 
79  break;
80  }
81  else
82  {
83  //
84  // We should have received a non empty payload so we have received an invalid frame
85  //
86  errorCode = SBG_INVALID_FRAME;
87  }
88  }
89  }
90  else
91  {
92  //
93  // We have a write error so exit the try loop
94  //
95  break;
96  }
97  }
98  }
99  else
100  {
101  //
102  // Null pointer
103  //
104  errorCode = SBG_NULL_POINTER;
105  }
106 
107  return errorCode;
108 }
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
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
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
uint8 productCode[SBG_ECOM_INFO_PRODUCT_CODE_LENGTH]
SBG_INLINE uint16 sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
SbgEComProtocol protocolHandle
Definition: sbgECom.h:82
SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer(SbgStreamBuffer *pHandle, void *pBuffer, size_t numBytesToRead)
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8 msgClass, uint8 msg, const void *pData, size_t size)
uint32 numTrials
Definition: sbgECom.h:86
#define NULL
Definition: sbgDefines.h:43
uint32 cmdDefaultTimeOut
Definition: sbgECom.h:87
SBG_INLINE uint32 sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
#define sbgStreamBufferReadUint8LE
unsigned char uint8
Definition: sbgTypes.h:56
SbgErrorCode sbgEComCmdGetInfo(SbgEComHandle *pHandle, SbgEComDeviceInfo *pInfo)
enum _SbgErrorCode SbgErrorCode
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError(SbgStreamBuffer *pHandle)
#define SBG_ECOM_MAX_BUFFER_SIZE


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