sbgEComCmdEthernet.c
Go to the documentation of this file.
1 #include "sbgEComCmdEthernet.h"
3 //----------------------------------------------------------------------//
4 //- Private methods declarations -//
5 //----------------------------------------------------------------------//
6 
14 {
15  //
16  // Check input arguments
17  //
18  SBG_ASSERT(pOutputStream);
19  SBG_ASSERT(pEthernetConf);
20 
21  //
22  // Build payload
23  //
24  sbgStreamBufferWriteUint8LE(pOutputStream, (uint8)pEthernetConf->mode);
25  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->ipAddress);
26  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->netmask);
27  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->gateway);
28  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->dns1);
29  sbgStreamBufferWriteUint32LE(pOutputStream, pEthernetConf->dns2);
30 
31  //
32  // Return if an error has occurred during the parse
33  //
34  return sbgStreamBufferGetLastError(pOutputStream);
35 }
36 
44 {
45  //
46  // Check input arguments
47  //
48  SBG_ASSERT(pInputStream);
49  SBG_ASSERT(pEthernetConf);
50 
51  //
52  // Read all parameters from the payload
53  //
54  pEthernetConf->mode = (SbgEComEthernetMode)sbgStreamBufferReadUint8LE(pInputStream);
55  pEthernetConf->ipAddress = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
56  pEthernetConf->netmask = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
57  pEthernetConf->gateway = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
58  pEthernetConf->dns1 = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
59  pEthernetConf->dns2 = (sbgIpAddress)sbgStreamBufferReadUint32LE(pInputStream);
60 
61  //
62  // Return if an error has occurred during the parse
63  //
64  return sbgStreamBufferGetLastError(pInputStream);
65 }
66 
67 //----------------------------------------------------------------------//
68 //- Public methods -//
69 //----------------------------------------------------------------------//
70 
80 {
81  SbgErrorCode errorCode = SBG_NO_ERROR;
82  uint32 trial;
83  size_t receivedSize;
84  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
85  SbgStreamBuffer inputStream;
86 
87  //
88  // Check input arguments
89  //
90  SBG_ASSERT(pHandle);
91  SBG_ASSERT(pEthernetConf);
92 
93  //
94  // Send the command three times
95  //
96  for (trial = 0; trial < pHandle->numTrials; trial++)
97  {
98  //
99  // Send the command with no payload to retreive the network configuration
100  //
102 
103  //
104  // Make sure that the command has been sent
105  //
106  if (errorCode == SBG_NO_ERROR)
107  {
108  //
109  // Try to read the device answer for 500 ms
110  //
111  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_ETHERNET_CONF, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
112 
113  //
114  // Test if we have received correctly the answer
115  //
116  if (errorCode == SBG_NO_ERROR)
117  {
118  //
119  // Initialize stream buffer to read parameters
120  //
121  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
122 
123  //
124  // Read all parameters from the payload and return any error during the parse
125  //
126  errorCode = sbgEComEthernetConfParse(&inputStream, pEthernetConf);
127 
128  //
129  // The command has been executed successfully so return
130  //
131  break;
132  }
133  }
134  else
135  {
136  //
137  // We have a write error so exit the try loop
138  //
139  break;
140  }
141  }
142 
143  return errorCode;
144 }
145 
153 {
154  SbgErrorCode errorCode = SBG_NO_ERROR;
155  uint32 trial;
156  uint8 outputBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
157  SbgStreamBuffer outputStream;
158 
159  //
160  // Check input arguments
161  //
162  SBG_ASSERT(pHandle);
163  SBG_ASSERT(pEthernetConf);
164 
165  //
166  // Send the command three times
167  //
168  for (trial = 0; trial < pHandle->numTrials; trial++)
169  {
170  //
171  // Init stream buffer for output
172  //
173  sbgStreamBufferInitForWrite(&outputStream, outputBuffer, sizeof(outputBuffer));
174 
175  //
176  // Build payload
177  //
178  errorCode = sbgEComEthernetConfWrite(&outputStream, pEthernetConf);
179 
180  //
181  // Send the payload if no error has occurred
182  //
183  if (errorCode == SBG_NO_ERROR)
184  {
186  }
187 
188  //
189  // Make sure that the command has been sent
190  //
191  if (errorCode == SBG_NO_ERROR)
192  {
193  //
194  // Try to read the device answer for 500 ms
195  //
197 
198  //
199  // Test if we have received a valid ACK
200  //
201  if (errorCode == SBG_NO_ERROR)
202  {
203  //
204  // The command has been executed successfully so return
205  //
206  break;
207  }
208  }
209  else
210  {
211  //
212  // We have a write error so exit the try loop
213  //
214  break;
215  }
216  }
217 
218  return errorCode;
219 }
220 
230 {
231  SbgErrorCode errorCode = SBG_NO_ERROR;
232  uint32 trial;
233  size_t receivedSize;
234  uint8 receivedBuffer[SBG_ECOM_MAX_BUFFER_SIZE];
235  SbgStreamBuffer inputStream;
236 
237  //
238  // Check input arguments
239  //
240  SBG_ASSERT(pHandle);
241  SBG_ASSERT(pEthernetConf);
242 
243  //
244  // Send the command three times
245  //
246  for (trial = 0; trial < pHandle->numTrials; trial++)
247  {
248  //
249  // Send the command with no payload to retreive the network configuration
250  //
252 
253  //
254  // Make sure that the command has been sent
255  //
256  if (errorCode == SBG_NO_ERROR)
257  {
258  //
259  // Try to read the device answer for 500 ms
260  //
261  errorCode = sbgEComReceiveCmd(pHandle, SBG_ECOM_CLASS_LOG_CMD_0, SBG_ECOM_CMD_ETHERNET_INFO, receivedBuffer, &receivedSize, sizeof(receivedBuffer), pHandle->cmdDefaultTimeOut);
262 
263  //
264  // Test if we have received correctly the answer
265  //
266  if (errorCode == SBG_NO_ERROR)
267  {
268  //
269  // Initialize stream buffer to read parameters
270  //
271  sbgStreamBufferInitForRead(&inputStream, receivedBuffer, receivedSize);
272 
273  //
274  // Read all parameters from the payload and return any error during the parse
275  //
276  errorCode = sbgEComEthernetConfParse(&inputStream, pEthernetConf);
277 
278  //
279  // The command has been executed successfully so return
280  //
281  break;
282  }
283  }
284  else
285  {
286  //
287  // We have a write error so exit the try loop
288  //
289  break;
290  }
291  }
292 
293  return errorCode;
294 }
SbgErrorCode sbgEComEthernetSetConf(SbgEComHandle *pHandle, const SbgEComEthernetConf *pEthernetConf)
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
enum _SbgEComEthernetMode SbgEComEthernetMode
SbgErrorCode sbgEComEthernetInfo(SbgEComHandle *pHandle, SbgEComEthernetConf *pEthernetConf)
uint32 sbgIpAddress
Definition: sbgTypes.h:70
Used to read/write data from/to a memory buffer stream.
SbgErrorCode sbgEComEthernetConfParse(SbgStreamBuffer *pInputStream, SbgEComEthernetConf *pEthernetConf)
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)
SbgErrorCode sbgEComEthernetConfWrite(SbgStreamBuffer *pOutputStream, const SbgEComEthernetConf *pEthernetConf)
#define sbgStreamBufferWriteUint8LE
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer(SbgStreamBuffer *pHandle)
This file implements SbgECom commands related to Ethernet configuration.
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
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32 value)
unsigned char uint8
Definition: sbgTypes.h:56
SbgEComEthernetMode mode
#define SBG_ASSERT(expression)
Definition: sbgDebug.h:52
SBG_INLINE size_t sbgStreamBufferGetLength(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):
autogenerated on Sun Jan 27 2019 03:42:20