This file implements the base interface for all Serial and Ethernet ports. More...
#include <sbgCommon.h>
Go to the source code of this file.
Classes | |
struct | _SbgInterface |
Macros | |
#define | SBG_IF_NAME_MAX_SIZE (48) |
#define | SBG_IF_TYPE_ETH_TCP_IP (3) |
#define | SBG_IF_TYPE_ETH_UDP (2) |
#define | SBG_IF_TYPE_FILE (4) |
#define | SBG_IF_TYPE_LAST_RESERVED (999) |
#define | SBG_IF_TYPE_SERIAL (1) |
#define | SBG_IF_TYPE_UNKNOW (0) |
Typedefs | |
typedef struct _SbgInterface | SbgInterface |
typedef SbgErrorCode(* | SbgInterfaceFlushFunc) (SbgInterface *pHandle) |
typedef uint32_t(* | SbgInterfaceGetDelayFunc) (SbgInterface *pHandle, size_t numBytes) |
typedef void * | SbgInterfaceHandle |
typedef SbgErrorCode(* | SbgInterfaceReadFunc) (SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead) |
typedef SbgErrorCode(* | SbgInterfaceWriteFunc) (SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite) |
Functions | |
SBG_INLINE SbgErrorCode | sbgInterfaceFlush (SbgInterface *pHandle) |
SBG_INLINE uint32_t | sbgInterfaceGetDelay (SbgInterface *pHandle, size_t numBytes) |
SBG_INLINE const char * | sbgInterfaceNameGet (const SbgInterface *pInterface) |
SBG_COMMON_LIB_API void | sbgInterfaceNameSet (SbgInterface *pInterface, const char *pName) |
SBG_INLINE SbgErrorCode | sbgInterfaceRead (SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead) |
SBG_INLINE uint32_t | sbgInterfaceTypeGet (const SbgInterface *pInterface) |
SBG_COMMON_LIB_API const char * | sbgInterfaceTypeGetAsString (const SbgInterface *pInterface) |
SBG_INLINE SbgErrorCode | sbgInterfaceWrite (SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite) |
SBG_COMMON_LIB_API void | sbgInterfaceZeroInit (SbgInterface *pHandle) |
This file implements the base interface for all Serial and Ethernet ports.
An interface is used to provide a common API for both serial and ethernet ports. An interface can be opened/closed and some data can be written or read from it.
Copyright (C) 2007-2013, SBG Systems SAS. All rights reserved.
This source code is intended for use only by SBG Systems SAS and those that have explicit written permission to use it from SBG Systems SAS.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
Definition in file sbgInterface.h.
#define SBG_IF_NAME_MAX_SIZE (48) |
Maximum size in bytes for the interface name string
Definition at line 41 of file sbgInterface.h.
#define SBG_IF_TYPE_ETH_TCP_IP (3) |
The interface is an TCP/IP one.
Definition at line 49 of file sbgInterface.h.
#define SBG_IF_TYPE_ETH_UDP (2) |
The interface is an UDP one.
Definition at line 48 of file sbgInterface.h.
#define SBG_IF_TYPE_FILE (4) |
The interface is a file.
Definition at line 50 of file sbgInterface.h.
#define SBG_IF_TYPE_LAST_RESERVED (999) |
Last reserved value for standard types.
Definition at line 51 of file sbgInterface.h.
#define SBG_IF_TYPE_SERIAL (1) |
The interface is a serial com port.
Definition at line 47 of file sbgInterface.h.
#define SBG_IF_TYPE_UNKNOW (0) |
Type values reserved for standard interface types.The interface type is not defined.
Definition at line 46 of file sbgInterface.h.
typedef struct _SbgInterface SbgInterface |
Interface structure pre-definition.
Definition at line 60 of file sbgInterface.h.
typedef SbgErrorCode(* SbgInterfaceFlushFunc) (SbgInterface *pHandle) |
Make an interface flush all pending input or output data.
[in] | pHandle | Valid handle on an initialized interface. |
Definition at line 104 of file sbgInterface.h.
typedef uint32_t(* SbgInterfaceGetDelayFunc) (SbgInterface *pHandle, size_t numBytes) |
Compute and return the delay needed by the interface to transmit / receive X number of bytes.
This method isn't applicable to all interfaces and as such should return a default delay of zero.
[in] | pHandle | Valid handle on an initialized interface. |
[in] | numBytes | The number of bytes to transmit / receive to evaluate the needed delay. |
Definition at line 115 of file sbgInterface.h.
typedef void* SbgInterfaceHandle |
Handle that stores the internal interface handle (ie Serial or Ethernet)
Definition at line 65 of file sbgInterface.h.
typedef SbgErrorCode(* SbgInterfaceReadFunc) (SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead) |
Method to implement to read data from an interface.
This method returns an error only if there is a 'low level' error on the interface. If no byte is read at all or less bytes than bytesToRead, this method returns SBG_NO_ERROR. You have to check pReadBytes field to know the number of bytes actually read.
[in] | pHandle | Valid handle on an initialized interface. |
[in] | pBuffer | Pointer on an allocated buffer that can hold at least bytesToRead bytes of data. |
[out] | pReadBytes | Returns the number of bytes actually read (can be zero and up to bytesToRead). |
[in] | bytesToRead | Maximum number of bytes to try to read on the interface. |
Definition at line 97 of file sbgInterface.h.
typedef SbgErrorCode(* SbgInterfaceWriteFunc) (SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite) |
Method to implement to write a buffer to an interface.
This method should return an error only if all bytes were not written successfully. If you try to write zero byte, the method shouldn't return any error.
[in] | pHandle | Valid handle on an initialized interface. |
[in] | pBuffer | Pointer on an allocated buffer that contains the data to write |
[in] | bytesToWrite | Number of bytes we would like to write (can be zero). |
Definition at line 82 of file sbgInterface.h.
SBG_INLINE SbgErrorCode sbgInterfaceFlush | ( | SbgInterface * | pHandle | ) |
Make an interface flush all pending input or output data.
This method isn't applicable to all interfaces and as such if no implementation is provided it does nothing.
[in] | pHandle | Valid handle on an initialized interface. |
Definition at line 211 of file sbgInterface.h.
SBG_INLINE uint32_t sbgInterfaceGetDelay | ( | SbgInterface * | pHandle, |
size_t | numBytes | ||
) |
Compute and return the delay needed by the interface to transmit / receive X number of bytes.
This method isn't applicable to all interfaces and as such if no implementation is provided a default delay of zero.
[in] | pHandle | Valid handle on an initialized interface. |
[in] | numBytes | The number of bytes to transmit / receive to evaluate the needed delay. |
Definition at line 244 of file sbgInterface.h.
SBG_INLINE const char* sbgInterfaceNameGet | ( | const SbgInterface * | pInterface | ) |
Returns the interface name string.
[in] | pInterface | Interface instance |
Definition at line 289 of file sbgInterface.h.
SBG_COMMON_LIB_API void sbgInterfaceNameSet | ( | SbgInterface * | pInterface, |
const char * | pName | ||
) |
Define the interface name as a NULL terminated C string.
This method make sure that the provided string will always fit within the allocated name buffer.
If the interface name you would like to set is too long, only the end of the string will be kept.
[in] | pInterface | Interface instance |
[in] | pName | The interface name to set as a NULL terminated C string |
Definition at line 61 of file sbgInterface.c.
SBG_INLINE SbgErrorCode sbgInterfaceRead | ( | SbgInterface * | pHandle, |
void * | pBuffer, | ||
size_t * | pReadBytes, | ||
size_t | bytesToRead | ||
) |
Try to read some data from an interface.
This method returns an error only if there is a 'low level' error on the interface. If no byte is read at all or less bytes than bytesToRead, this method returns SBG_NO_ERROR. You have to check pReadBytes field to know the number of bytes actually read.
[in] | pHandle | Valid handle on an initialized interface. |
[in] | pBuffer | Pointer on an allocated buffer that can hold at least bytesToRead bytes of data. |
[out] | pReadBytes | Returns the number of bytes actually read (can be zero and up to bytesToRead). |
[in] | bytesToRead | Maximum number of bytes to try to read on the interface. |
Definition at line 190 of file sbgInterface.h.
SBG_INLINE uint32_t sbgInterfaceTypeGet | ( | const SbgInterface * | pInterface | ) |
Returns the interface type.
[in] | pInterface | Interface instance |
Definition at line 268 of file sbgInterface.h.
SBG_COMMON_LIB_API const char* sbgInterfaceTypeGetAsString | ( | const SbgInterface * | pInterface | ) |
Returns the interface as string.
[in] | pInterface | Interface instance |
Definition at line 46 of file sbgInterface.c.
SBG_INLINE SbgErrorCode sbgInterfaceWrite | ( | SbgInterface * | pHandle, |
const void * | pBuffer, | ||
size_t | bytesToWrite | ||
) |
Write some data to an interface.
This method should return an error only if all bytes were not written successfully. If you try to write zero byte, the method shouldn't return any error.
[in] | pHandle | Valid handle on an initialized interface. |
[in] | pBuffer | Pointer on an allocated buffer that contains the data to write |
[in] | bytesToWrite | Number of bytes we would like to write (can be zero). |
Definition at line 165 of file sbgInterface.h.
SBG_COMMON_LIB_API void sbgInterfaceZeroInit | ( | SbgInterface * | pHandle | ) |
Initialize an interface instance to zero.
[in] | pHandle | Handle on an allocated interface to initialize to zero. |
Definition at line 24 of file sbgInterface.c.