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 }
This file implements the base interface for all Serial and Ethernet ports.
static const char * gInterfaceType[]
Definition: sbgInterface.c:11
#define SBG_IF_TYPE_FILE
Definition: sbgInterface.h:50
#define SBG_IF_TYPE_ETH_UDP
Definition: sbgInterface.h:48
uint32_t type
Definition: sbgInterface.h:134
void sbgInterfaceZeroInit(SbgInterface *pHandle)
Definition: sbgInterface.c:24
SbgInterfaceHandle handle
Definition: sbgInterface.h:133
SbgInterfaceGetDelayFunc pDelayFunc
Definition: sbgInterface.h:140
SbgInterfaceReadFunc pReadFunc
Definition: sbgInterface.h:138
void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName)
Definition: sbgInterface.c:61
#define NULL
Definition: sbgDefines.h:81
#define SBG_IF_TYPE_SERIAL
Definition: sbgInterface.h:47
const char * sbgInterfaceTypeGetAsString(const SbgInterface *pInterface)
Definition: sbgInterface.c:46
Main header file for SBG Systems common C library.
#define SBG_LOG_ERROR(format,...)
Definition: sbgDebug.h:62
#define SBG_ARRAY_SIZE(a)
Definition: sbgDefines.h:97
SbgInterfaceFlushFunc pFlushFunc
Definition: sbgInterface.h:139
char name[SBG_IF_NAME_MAX_SIZE]
Definition: sbgInterface.h:135
#define SBG_IF_TYPE_ETH_TCP_IP
Definition: sbgInterface.h:49
SbgInterfaceWriteFunc pWriteFunc
Definition: sbgInterface.h:137
#define SBG_IF_TYPE_UNKNOW
Definition: sbgInterface.h:46


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