sbgECom Library  5.2.590-stable
Interface SBG Systems IMU/AHRS/INS
Loading...
Searching...
No Matches
sbgInterface.h
Go to the documentation of this file.
1
35
36#ifndef SBG_INTERFACE_H
37#define SBG_INTERFACE_H
38
39//----------------------------------------------------------------------//
40//- Header (open extern C block) -//
41//----------------------------------------------------------------------//
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/* sbgCommonLib headers */
47#include <sbgCommon.h>
48
49//----------------------------------------------------------------------//
50//- Constant definitions -//
51//----------------------------------------------------------------------//
52
53#define SBG_IF_NAME_MAX_SIZE (48)
54
58#define SBG_IF_TYPE_UNKNOW (0)
59#define SBG_IF_TYPE_SERIAL (1)
60#define SBG_IF_TYPE_ETH_UDP (2)
61#define SBG_IF_TYPE_ETH_TCP_IP (3)
62#define SBG_IF_TYPE_FILE (4)
63#define SBG_IF_TYPE_LAST_RESERVED (999)
64
65//
66// Flags for the flush operation.
67//
68#define SBG_IF_FLUSH_INPUT ((uint32_t)1 << 0)
69#define SBG_IF_FLUSH_OUTPUT ((uint32_t)1 << 1)
70#define SBG_IF_FLUSH_ALL (SBG_IF_FLUSH_INPUT | SBG_IF_FLUSH_OUTPUT)
71
72//----------------------------------------------------------------------//
73//- Predefinitions -//
74//----------------------------------------------------------------------//
75
80
84typedef void* SbgInterfaceHandle;
85
86//----------------------------------------------------------------------//
87//- Callbacks definitions -//
88//----------------------------------------------------------------------//
89
97
109typedef SbgErrorCode (*SbgInterfaceWriteFunc)(SbgInterface *pInterface, const void *pBuffer, size_t bytesToWrite);
110
124typedef SbgErrorCode (*SbgInterfaceReadFunc)(SbgInterface *pInterface, void *pBuffer, size_t *pReadBytes, size_t bytesToRead);
125
138typedef SbgErrorCode (*SbgInterfaceFlushFunc)(SbgInterface *pInterface, uint32_t flags);
139
155typedef SbgErrorCode (*SbgInterfaceSetSpeed)(SbgInterface *pInterface, uint32_t speed);
156
165typedef uint32_t (*SbgInterfaceGetSpeed)(const SbgInterface *pInterface);
166
176typedef uint32_t (*SbgInterfaceGetDelayFunc)(const SbgInterface *pInterface, size_t numBytes);
177
178//----------------------------------------------------------------------//
179//- Structures definitions -//
180//----------------------------------------------------------------------//
181
206
207//----------------------------------------------------------------------//
208//- Public methods -//
209//----------------------------------------------------------------------//
210
217
227
234SBG_INLINE uint32_t sbgInterfaceTypeGet(const SbgInterface *pInterface)
235{
236 assert(pInterface);
237
238 return pInterface->type;
239}
240
248
255SBG_INLINE const char *sbgInterfaceNameGet(const SbgInterface *pInterface)
256{
257 assert(pInterface);
258
259 return pInterface->name;
260}
261
274SBG_COMMON_LIB_API void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName);
275
288SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pInterface, const void *pBuffer, size_t bytesToWrite)
289{
290 SbgErrorCode errorCode;
291
292 assert(pInterface);
293 assert(pBuffer);
294
295 if (pInterface->pWriteFunc)
296 {
297 errorCode = pInterface->pWriteFunc(pInterface, pBuffer, bytesToWrite);
298 }
299 else
300 {
301 errorCode = SBG_INVALID_PARAMETER;
302 }
303
304 return errorCode;
305}
306
321SBG_INLINE SbgErrorCode sbgInterfaceRead(SbgInterface *pInterface, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
322{
323 SbgErrorCode errorCode;
324
325 assert(pInterface);
326 assert(pBuffer);
327 assert(pReadBytes);
328
329 if (pInterface->pReadFunc)
330 {
331 errorCode = pInterface->pReadFunc(pInterface, pBuffer, pReadBytes, bytesToRead);
332 }
333 else
334 {
335 *pReadBytes = 0;
336 errorCode = SBG_INVALID_PARAMETER;
337 }
338
339 return errorCode;
340}
341
355{
356 SbgErrorCode errorCode;
357
358 assert(pInterface);
359 assert((flags & ~SBG_IF_FLUSH_ALL) == 0);
360
361 if (pInterface->pFlushFunc)
362 {
363 errorCode = pInterface->pFlushFunc(pInterface, flags);
364 }
365 else
366 {
367 errorCode = SBG_NO_ERROR;
368 }
369
370 return errorCode;
371}
372
389{
390 assert(pInterface);
391 assert(speed > 0);
392
393 if (pInterface->pSetSpeedFunc)
394 {
395 return pInterface->pSetSpeedFunc(pInterface, speed);
396 }
397 else
398 {
399 return SBG_NO_ERROR;
400 }
401}
402
412{
413 assert(pInterface);
414
415 if (pInterface->pGetSpeedFunc)
416 {
417 return pInterface->pGetSpeedFunc(pInterface);
418 }
419 else
420 {
421 return 0;
422 }
423}
424
434SBG_INLINE uint32_t sbgInterfaceGetDelay(const SbgInterface *pInterface, size_t numBytes)
435{
436 assert(pInterface);
437
438 if (pInterface->pDelayFunc)
439 {
440 return pInterface->pDelayFunc(pInterface, numBytes);
441 }
442 else
443 {
444 return 0;
445 }
446}
447
448//----------------------------------------------------------------------//
449//- Footer (close extern C block) -//
450//----------------------------------------------------------------------//
451#ifdef __cplusplus
452}
453#endif
454
455#endif // SBG_INTERFACE_H
Main header for the SBG Systems common C library.
#define SBG_INLINE
Definition sbgDefines.h:227
#define SBG_COMMON_LIB_API
Definition sbgDefines.h:79
enum _SbgErrorCode SbgErrorCode
@ SBG_NO_ERROR
Definition sbgErrorCodes.h:52
@ SBG_INVALID_PARAMETER
Definition sbgErrorCodes.h:64
SBG_INLINE SbgErrorCode sbgInterfaceRead(SbgInterface *pInterface, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
Definition sbgInterface.h:321
SbgErrorCode(* SbgInterfaceWriteFunc)(SbgInterface *pInterface, const void *pBuffer, size_t bytesToWrite)
Definition sbgInterface.h:109
SBG_INLINE uint32_t sbgInterfaceTypeGet(const SbgInterface *pInterface)
Definition sbgInterface.h:234
SbgErrorCode(* SbgInterfaceFlushFunc)(SbgInterface *pInterface, uint32_t flags)
Definition sbgInterface.h:138
SBG_INLINE SbgErrorCode sbgInterfaceSetSpeed(SbgInterface *pInterface, uint32_t speed)
Definition sbgInterface.h:388
void * SbgInterfaceHandle
Definition sbgInterface.h:84
SBG_COMMON_LIB_API SbgErrorCode sbgInterfaceDestroy(SbgInterface *pInterface)
SbgErrorCode(* SbgInterfaceDestroyFunc)(SbgInterface *pInterface)
Definition sbgInterface.h:96
SBG_INLINE uint32_t sbgInterfaceGetSpeed(const SbgInterface *pInterface)
Definition sbgInterface.h:411
SBG_COMMON_LIB_API const char * sbgInterfaceTypeGetAsString(const SbgInterface *pInterface)
#define SBG_IF_NAME_MAX_SIZE
Definition sbgInterface.h:53
uint32_t(* SbgInterfaceGetDelayFunc)(const SbgInterface *pInterface, size_t numBytes)
Definition sbgInterface.h:176
#define SBG_IF_FLUSH_ALL
Definition sbgInterface.h:70
SBG_INLINE SbgErrorCode sbgInterfaceFlush(SbgInterface *pInterface, uint32_t flags)
Definition sbgInterface.h:354
uint32_t(* SbgInterfaceGetSpeed)(const SbgInterface *pInterface)
Definition sbgInterface.h:165
SBG_INLINE uint32_t sbgInterfaceGetDelay(const SbgInterface *pInterface, size_t numBytes)
Definition sbgInterface.h:434
SbgErrorCode(* SbgInterfaceReadFunc)(SbgInterface *pInterface, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
Definition sbgInterface.h:124
SBG_COMMON_LIB_API void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName)
SBG_COMMON_LIB_API void sbgInterfaceZeroInit(SbgInterface *pInterface)
SbgErrorCode(* SbgInterfaceSetSpeed)(SbgInterface *pInterface, uint32_t speed)
Definition sbgInterface.h:155
struct _SbgInterface SbgInterface
Definition sbgInterface.h:79
SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pInterface, const void *pBuffer, size_t bytesToWrite)
Definition sbgInterface.h:288
SBG_INLINE const char * sbgInterfaceNameGet(const SbgInterface *pInterface)
Definition sbgInterface.h:255
Definition sbgInterface.h:193
SbgInterfaceDestroyFunc pDestroyFunc
Definition sbgInterface.h:198
char name[SBG_IF_NAME_MAX_SIZE]
Definition sbgInterface.h:196
uint32_t type
Definition sbgInterface.h:195
SbgInterfaceGetSpeed pGetSpeedFunc
Definition sbgInterface.h:203
SbgInterfaceSetSpeed pSetSpeedFunc
Definition sbgInterface.h:202
SbgInterfaceFlushFunc pFlushFunc
Definition sbgInterface.h:201
SbgInterfaceGetDelayFunc pDelayFunc
Definition sbgInterface.h:204
SbgInterfaceWriteFunc pWriteFunc
Definition sbgInterface.h:199
SbgInterfaceHandle handle
Definition sbgInterface.h:194
SbgInterfaceReadFunc pReadFunc
Definition sbgInterface.h:200