sbgEComCmdAdvanced.c
Go to the documentation of this file.
1 #include "sbgEComCmdAdvanced.h"
3 
4 //----------------------------------------------------------------------//
5 //- Event 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) && (pConf))
26  {
27  //
28  // Send the command three times
29  //
30  for (trial = 0; trial < pHandle->numTrials; trial++)
31  {
32  //
33  // Send the command without payload 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_ADVANCED_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
46 
47  //
48  // Test if we have received a SBG_ECOM_CMD_ADVANCED_CONF command
49  //
50  if (errorCode == SBG_NO_ERROR)
51  {
52  //
53  // Initialize stream buffer to read parameters
54  //
55  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
56 
57  //
58  // Read parameters
59  //
61 
62  //
63  // The command has been executed successfully so return
64  //
65  break;
66  }
67  }
68  else
69  {
70  //
71  // We have a write error so exit the try loop
72  //
73  break;
74  }
75  }
76  }
77  else
78  {
79  //
80  // Null pointer
81  //
82  errorCode = SBG_NULL_POINTER;
83  }
84 
85  return errorCode;
86 }
87 
95 {
96  SbgErrorCode errorCode = SBG_NO_ERROR;
97  uint32 trial;
98  uint8 outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
99  SbgStreamBuffer outputStream;
100 
101  //
102  // Test that the input pointer are valid
103  //
104  if ((pHandle) && (pConf))
105  {
106  //
107  // Send the command three times
108  //
109  for (trial = 0; trial < pHandle->numTrials; trial++)
110  {
111  //
112  // Init stream buffer for output
113  //
114  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
115 
116  //
117  // Build payload
118  //
119  sbgStreamBufferWriteUint8LE(&outputStream, (uint8)pConf->timeReference);
120 
121  //
122  // Send the payload over ECom
123  //
125 
126  //
127  // Make sure that the command has been sent
128  //
129  if (errorCode == SBG_NO_ERROR)
130  {
131  //
132  // Try to read the device answer for 500 ms
133  //
135 
136  //
137  // Test if we have received a valid ACK
138  //
139  if (errorCode == SBG_NO_ERROR)
140  {
141  //
142  // The command has been executed successfully so return
143  //
144  break;
145  }
146  }
147  else
148  {
149  //
150  // We have a write error so exit the try loop
151  //
152  break;
153  }
154  }
155  }
156  else
157  {
158  //
159  // Null pointer.
160  //
161  errorCode = SBG_NULL_POINTER;
162  }
163 
164  return errorCode;
165 }
This file implements SbgECom commands related to advanced settings.
enum _SbgEComTimeReferenceSrc SbgEComTimeReferenceSrc
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
Used to read/write data from/to a memory buffer stream.
SbgErrorCode sbgEComCmdAdvancedSetConf(SbgEComHandle *pHandle, const SbgEComAdvancedConf *pConf)
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)
SbgEComTimeReferenceSrc timeReference
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
SbgErrorCode sbgEComCmdAdvancedGetConf(SbgEComHandle *pHandle, SbgEComAdvancedConf *pConf)
#define sbgStreamBufferReadUint8LE
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