sbgInterface.c
Go to the documentation of this file.
1 /* sbgCommonLib headers */
2 #include <sbgCommon.h>
3 
4 /* Local headers */
5 #include "sbgInterface.h"
6 
7 //----------------------------------------------------------------------//
8 //- Private definitions -//
9 //----------------------------------------------------------------------//
10 
11 static const char *gInterfaceType[] =
12 {
13  [SBG_IF_TYPE_UNKNOW] = "unknown",
14  [SBG_IF_TYPE_SERIAL] = "serial",
15  [SBG_IF_TYPE_ETH_UDP] = "eth UDP",
16  [SBG_IF_TYPE_ETH_TCP_IP] = "eth TCP",
17  [SBG_IF_TYPE_FILE] = "file"
18 };
19 
20 //----------------------------------------------------------------------//
21 //- Public methods -//
22 //----------------------------------------------------------------------//
23 
25 {
26  assert(pHandle);
27 
28  //
29  // Make sure the whole struct is zero init
30  //
31  memset(pHandle, 0x00, sizeof(*pHandle));
32 
33  //
34  // Initialize all fields to default values
35  //
36  pHandle->handle = NULL;
37  pHandle->type = SBG_IF_TYPE_UNKNOW;
38  pHandle->name[0] = '\0';
39 
40  pHandle->pWriteFunc = NULL;
41  pHandle->pReadFunc = NULL;
42  pHandle->pFlushFunc = NULL;
43  pHandle->pDelayFunc = NULL;
44 }
45 
46 const char *sbgInterfaceTypeGetAsString(const SbgInterface *pInterface)
47 {
48  assert(pInterface);
49 
50  if (pInterface->type < SBG_ARRAY_SIZE(gInterfaceType))
51  {
52  return gInterfaceType[pInterface->type];
53  }
54  else
55  {
56  SBG_LOG_ERROR(SBG_INVALID_PARAMETER, "Unknown interface type: %u", pInterface->type);
58  }
59 }
60 
61 void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName)
62 {
63  size_t nameLen;
64 
65  assert(pInterface);
66  assert(pName);
67 
68  //
69  // Only keep the end of the name that can fit in the interface name buffer
70  //
71  nameLen = strlen(pName);
72 
73  if (nameLen < SBG_ARRAY_SIZE(pInterface->name))
74  {
75  strcpy(pInterface->name, pName);
76  }
77  else
78  {
79  strcpy(pInterface->name, pName+(nameLen-(SBG_ARRAY_SIZE(pInterface->name)-1)));
80  }
81 }
_SbgInterface::pWriteFunc
SbgInterfaceWriteFunc pWriteFunc
Definition: sbgInterface.h:137
SBG_IF_TYPE_ETH_UDP
#define SBG_IF_TYPE_ETH_UDP
Definition: sbgInterface.h:48
_SbgInterface::type
uint32_t type
Definition: sbgInterface.h:134
SBG_IF_TYPE_FILE
#define SBG_IF_TYPE_FILE
Definition: sbgInterface.h:50
SBG_IF_TYPE_UNKNOW
#define SBG_IF_TYPE_UNKNOW
Definition: sbgInterface.h:46
NULL
#define NULL
Definition: sbgDefines.h:81
SBG_ARRAY_SIZE
#define SBG_ARRAY_SIZE(a)
Definition: sbgDefines.h:97
SBG_IF_TYPE_SERIAL
#define SBG_IF_TYPE_SERIAL
Definition: sbgInterface.h:47
_SbgInterface::pFlushFunc
SbgInterfaceFlushFunc pFlushFunc
Definition: sbgInterface.h:139
sbgCommon.h
sbgInterfaceTypeGetAsString
const char * sbgInterfaceTypeGetAsString(const SbgInterface *pInterface)
Definition: sbgInterface.c:46
sbgInterfaceNameSet
void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName)
Definition: sbgInterface.c:61
_SbgInterface::handle
SbgInterfaceHandle handle
Definition: sbgInterface.h:133
SBG_LOG_ERROR
#define SBG_LOG_ERROR(format,...)
Definition: sbgDebug.h:62
SBG_INVALID_PARAMETER
@ SBG_INVALID_PARAMETER
Definition: sbgErrorCodes.h:47
_SbgInterface::pReadFunc
SbgInterfaceReadFunc pReadFunc
Definition: sbgInterface.h:138
sbgInterfaceZeroInit
void sbgInterfaceZeroInit(SbgInterface *pHandle)
Definition: sbgInterface.c:24
SBG_IF_TYPE_ETH_TCP_IP
#define SBG_IF_TYPE_ETH_TCP_IP
Definition: sbgInterface.h:49
gInterfaceType
static const char * gInterfaceType[]
Definition: sbgInterface.c:11
_SbgInterface::pDelayFunc
SbgInterfaceGetDelayFunc pDelayFunc
Definition: sbgInterface.h:140
_SbgInterface::name
char name[SBG_IF_NAME_MAX_SIZE]
Definition: sbgInterface.h:135
_SbgInterface
Definition: sbgInterface.h:131
sbgInterface.h


sbg_driver
Author(s): SBG Systems
autogenerated on Fri Oct 11 2024 02:13:40