sbgEComCmdEthernet.c
Go to the documentation of this file.
1 #include "sbgEComCmdEthernet.h"
3 
4 //----------------------------------------------------------------------//
5 //- Private methods declarations -//
6 //----------------------------------------------------------------------//
7 
14 static SbgErrorCode sbgEComEthernetConfWrite(SbgStreamBuffer *pOutputStream, const SbgEComEthernetConf *pEthernetConf)
15 {
16  assert(pOutputStream);
17  assert(pEthernetConf);
18 
19  //
20  // Build payload
21  //
22  sbgStreamBufferWriteUint8LE(pOutputStream, (uint8_t)pEthernetConf->mode);
23  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->ipAddress);
24  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->netmask);
25  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->gateway);
26  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->dns1);
27  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->dns2);
28 
29  //
30  // Return if an error has occurred during the parse
31  //
32  return sbgStreamBufferGetLastError(pOutputStream);
33 }
34 
42 {
43  assert(pInputStream);
44  assert(pEthernetConf);
45 
46  //
47  // Read all parameters from the payload
48  //
49  pEthernetConf->mode = (SbgEComEthernetMode)sbgStreamBufferReadUint8LE(pInputStream);
50  pEthernetConf->ipAddress = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
51  pEthernetConf->netmask = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
52  pEthernetConf->gateway = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
53  pEthernetConf->dns1 = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
54  pEthernetConf->dns2 = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
55 
56  //
57  // Return if an error has occurred during the parse
58  //
59  return sbgStreamBufferGetLastError(pInputStream);
60 }
61 
62 //----------------------------------------------------------------------//
63 //- Public methods -//
64 //----------------------------------------------------------------------//
65 
75 {
76  SbgErrorCode errorCode = SBG_NO_ERROR;
77  uint32_t trial;
78  size_t receivedSize;
79  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
80  SbgStreamBuffer inputStream;
81 
82  assert(pHandle);
83  assert(pEthernetConf);
84 
85  //
86  // Send the command three times
87  //
88  for (trial = 0; trial < pHandle->numTrials; trial++)
89  {
90  //
91  // Send the command with no payload to retreive the network configuration
92  //
94 
95  //
96  // Make sure that the command has been sent
97  //
98  if (errorCode == SBG_NO_ERROR)
99  {
100  //
101  // Try to read the device answer for 500 ms
102  //
103  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_ETHERNET_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
104 
105  //
106  // Test if we have received correctly the answer
107  //
108  if (errorCode == SBG_NO_ERROR)
109  {
110  //
111  // Initialize stream buffer to read parameters
112  //
113  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
114 
115  //
116  // Read all parameters from the payload and return any error during the parse
117  //
118  errorCode = sbgEComEthernetConfParse(&inputStream, pEthernetConf);
119 
120  //
121  // The command has been executed successfully so return
122  //
123  break;
124  }
125  }
126  else
127  {
128  //
129  // We have a write error so exit the try loop
130  //
131  break;
132  }
133  }
134 
135  return errorCode;
136 }
137 
145 {
146  SbgErrorCode errorCode = SBG_NO_ERROR;
147  uint32_t trial;
148  uint8_t outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
149  SbgStreamBuffer outputStream;
150 
151  assert(pHandle);
152  assert(pEthernetConf);
153 
154  //
155  // Send the command three times
156  //
157  for (trial = 0; trial < pHandle->numTrials; trial++)
158  {
159  //
160  // Init stream buffer for output
161  //
162  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
163 
164  //
165  // Build payload
166  //
167  errorCode = sbgEComEthernetConfWrite(&outputStream, pEthernetConf);
168 
169  //
170  // Send the payload if no error has occurred
171  //
172  if (errorCode == SBG_NO_ERROR)
173  {
175  }
176 
177  //
178  // Make sure that the command has been sent
179  //
180  if (errorCode == SBG_NO_ERROR)
181  {
182  //
183  // Try to read the device answer for 500 ms
184  //
186 
187  //
188  // Test if we have received a valid ACK
189  //
190  if (errorCode == SBG_NO_ERROR)
191  {
192  //
193  // The command has been executed successfully so return
194  //
195  break;
196  }
197  }
198  else
199  {
200  //
201  // We have a write error so exit the try loop
202  //
203  break;
204  }
205  }
206 
207  return errorCode;
208 }
209 
219 {
220  SbgErrorCode errorCode = SBG_NO_ERROR;
221  uint32_t trial;
222  size_t receivedSize;
223  uint8_t receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
224  SbgStreamBuffer inputStream;
225 
226  assert(pHandle);
227  assert(pEthernetConf);
228 
229  //
230  // Send the command three times
231  //
232  for (trial = 0; trial < pHandle->numTrials; trial++)
233  {
234  //
235  // Send the command with no payload to retreive the network configuration
236  //
238 
239  //
240  // Make sure that the command has been sent
241  //
242  if (errorCode == SBG_NO_ERROR)
243  {
244  //
245  // Try to read the device answer for 500 ms
246  //
247  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_ETHERNET_INFO, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
248 
249  //
250  // Test if we have received correctly the answer
251  //
252  if (errorCode == SBG_NO_ERROR)
253  {
254  //
255  // Initialize stream buffer to read parameters
256  //
257  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
258 
259  //
260  // Read all parameters from the payload and return any error during the parse
261  //
262  errorCode = sbgEComEthernetConfParse(&inputStream, pEthernetConf);
263 
264  //
265  // The command has been executed successfully so return
266  //
267  break;
268  }
269  }
270  else
271  {
272  //
273  // We have a write error so exit the try loop
274  //
275  break;
276  }
277  }
278 
279  return errorCode;
280 }
SbgErrorCode sbgEComEthernetSetConf(SbgEComHandle *pHandle, const SbgEComEthernetConf *pEthernetConf)
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead(SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
static SbgErrorCode sbgEComEthernetConfParse(SbgStreamBuffer *pInputStream, SbgEComEthernetConf *pEthernetConf)
enum _SbgEComEthernetMode SbgEComEthernetMode
SbgErrorCode sbgEComEthernetInfo(SbgEComHandle *pHandle, SbgEComEthernetConf *pEthernetConf)
Used to read/write data from/to a memory buffer stream.
SbgErrorCode sbgEComProtocolSend(SbgEComProtocol *pHandle, uint8_t msgClass, uint8_t msg, const void *pData, size_t size)
SbgEComProtocol protocolHandle
Definition: sbgECom.h:72
SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite(SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
static SbgErrorCode sbgEComEthernetConfWrite(SbgStreamBuffer *pOutputStream, const SbgEComEthernetConf *pEthernetConf)
SbgErrorCode sbgEComWaitForAck(SbgEComHandle *pHandle, uint8_t msgClass, uint8_t msg, uint32_t timeOut)
uint32_t cmdDefaultTimeOut
Definition: sbgECom.h:78
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
This file implements SbgECom commands related to Ethernet configuration.
#define NULL
Definition: sbgDefines.h:81
uint32_t sbgIpAddress
Definition: sbgTypes.h:64
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
SbgEComEthernetMode mode
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32_t value)
SBG_INLINE size_t sbgStreamBufferGetLength(SbgStreamBuffer *pHandle)
SBG_INLINE uint32_t sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
SbgErrorCode sbgEComEthernetGetConf(SbgEComHandle *pHandle, SbgEComEthernetConf *pEthernetConf)
enum _SbgErrorCode SbgErrorCode
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError(SbgStreamBuffer *pHandle)
#define SBG_ECOM_MAX_BUFFER_SIZE


sbg_driver
Author(s): SBG Systems
autogenerated on Thu Oct 22 2020 03:47:22