Snapdragon® Telematics Application Framework (TelAF) Interface Specification
taf_can_client.c File Reference
#include "taf_can_interface.h"
#include "taf_can_messages.h"
#include "taf_can_service.h"

Data Structures

struct  _ClientThreadData_t
 

Macros

#define LOCK_INIT   le_mutex_Lock(le_ifgen_InitMutexRef);
 Locks the mutex. More...
 
#define UNLOCK_INIT   le_mutex_Unlock(le_ifgen_InitMutexRef);
 Unlocks the mutex. More...
 

Functions

 LE_MEM_DEFINE_STATIC_POOL (taf_can_ClientThreadData, LE_CDATA_COMPONENT_COUNT, sizeof(_ClientThreadData_t))
 
static le_result_t InitClientForThread (bool isBlocking)
 
static _ClientThreadData_tGetClientThreadDataPtr (void)
 
 __attribute__ ((unused))
 
static void ClientThreadDestructor (void *objPtr)
 
static void InitCommonData (void)
 
static le_result_t DoConnectService (bool isBlocking)
 
void taf_can_ConnectService (void)
 
le_result_t taf_can_TryConnectService (void)
 
static void SessionCloseHandler (le_msg_SessionRef_t sessionRef, void *contextPtr)
 
void taf_can_SetServerDisconnectHandler (taf_can_DisconnectHandler_t disconnectHandler, void *contextPtr)
 
static void NonExitSessionCloseHandler (le_msg_SessionRef_t sessionRef, void *contextPtr)
 
void taf_can_SetNonExitServerDisconnectHandler (taf_can_DisconnectHandler_t disconnectHandler, void *contextPtr)
 
void taf_can_DisconnectService (void)
 
taf_can_CanInterfaceRef_t taf_can_CreateCanInf (const char *LE_NONNULL infName, taf_can_InfProtocol_t canInfType)
 
le_result_t taf_can_SetFilter (taf_can_CanInterfaceRef_t canInfRef, uint32_t frameId)
 
le_result_t taf_can_EnableLoopback (taf_can_CanInterfaceRef_t canInfRef)
 
le_result_t taf_can_DisableLoopback (taf_can_CanInterfaceRef_t canInfRef)
 
le_result_t taf_can_EnableRcvOwnMsg (taf_can_CanInterfaceRef_t canInfRef)
 
le_result_t taf_can_DisableRcvOwnMsg (taf_can_CanInterfaceRef_t canInfRef)
 
bool taf_can_IsFdSupported (taf_can_CanInterfaceRef_t canInfRef)
 
le_result_t taf_can_EnableFdFrame (taf_can_CanInterfaceRef_t canInfRef)
 
bool taf_can_GetFdStatus (taf_can_CanInterfaceRef_t canInfRef)
 
taf_can_CanEventHandlerRef_t taf_can_AddCanEventHandler (taf_can_CanInterfaceRef_t canInfRef, uint32_t frameId, uint32_t frIdMask, taf_can_CallbackFunc_t handlerPtr, void *contextPtr)
 
void taf_can_RemoveCanEventHandler (taf_can_CanEventHandlerRef_t handlerRef)
 
taf_can_CanFrameRef_t taf_can_CreateCanFrame (taf_can_CanInterfaceRef_t canInfRef, uint32_t frameId)
 
le_result_t taf_can_SetPayload (taf_can_CanFrameRef_t frameRef, const uint8_t *dataPtr, size_t dataSize)
 
le_result_t taf_can_SetFrameType (taf_can_CanFrameRef_t frameRef, taf_can_FrameType_t frameType)
 
le_result_t taf_can_SendFrame (taf_can_CanFrameRef_t frameRef)
 
le_result_t taf_can_DeleteCanInf (taf_can_CanInterfaceRef_t canInfRef)
 
le_result_t taf_can_DeleteCanFrame (taf_can_CanFrameRef_t frameRef)
 

Variables

static le_mem_PoolRef_t _ClientThreadDataPool
 
static pthread_key_t _ThreadDataKey
 
static bool CommonDataInitialized = false
 
le_mutex_Ref_t le_ifgen_InitMutexRef
 

Macro Definition Documentation

◆ LOCK_INIT

#define LOCK_INIT   le_mutex_Lock(le_ifgen_InitMutexRef);

Locks the mutex.

◆ UNLOCK_INIT

#define UNLOCK_INIT   le_mutex_Unlock(le_ifgen_InitMutexRef);

Unlocks the mutex.

Function Documentation

◆ LE_MEM_DEFINE_STATIC_POOL()

LE_MEM_DEFINE_STATIC_POOL ( taf_can_ClientThreadData  ,
LE_CDATA_COMPONENT_COUNT  ,
sizeof(_ClientThreadData_t  
)

Static pool for client threads.

◆ InitClientForThread()

static le_result_t InitClientForThread ( bool  isBlocking)
static

Initialize thread specific data, and connect to the service for the current thread.

Returns
  • LE_OK if the client connected successfully to the service.
  • LE_UNAVAILABLE if the server is not currently offering the service to which the client is bound.
  • LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
  • LE_COMM_ERROR if the Service Directory cannot be reached.

◆ GetClientThreadDataPtr()

static _ClientThreadData_t* GetClientThreadDataPtr ( void  )
static

Get a pointer to the client thread data for the current thread.

If the current thread does not have client data, then NULL is returned

◆ __attribute__()

__attribute__ ( (unused)  )

Return the sessionRef for the current thread.

If the current thread does not have a session ref, then this is a fatal error.

◆ ClientThreadDestructor()

static void ClientThreadDestructor ( void *  objPtr)
static

Destructor function for client thread objects.

◆ InitCommonData()

static void InitCommonData ( void  )
static

Init data that is common across all threads.

◆ DoConnectService()

static le_result_t DoConnectService ( bool  isBlocking)
static

Connect to the service, using either blocking or non-blocking calls.

This function implements the details of the public ConnectService functions.

Returns
  • LE_OK if the client connected successfully to the service.
  • LE_UNAVAILABLE if the server is not currently offering the service to which the client is bound.
  • LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
  • LE_COMM_ERROR if the Service Directory cannot be reached.

◆ taf_can_ConnectService()

void taf_can_ConnectService ( void  )

Connect the current client thread to the service providing this API. Block until the service is available.

For each thread that wants to use this API, either ConnectService or TryConnectService must be called before any other functions in this API. Normally, ConnectService is automatically called for the main thread, but not for any other thread. For details, see apiFilesC_client.

This function is created automatically.

◆ taf_can_TryConnectService()

le_result_t taf_can_TryConnectService ( void  )

Try to connect the current client thread to the service providing this API. Return with an error if the service is not available.

For each thread that wants to use this API, either ConnectService or TryConnectService must be called before any other functions in this API. Normally, ConnectService is automatically called for the main thread, but not for any other thread. For details, see apiFilesC_client.

This function is created automatically.

Returns
  • LE_OK if the client connected successfully to the service.
  • LE_UNAVAILABLE if the server is not currently offering the service to which the client is bound.
  • LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
  • LE_COMM_ERROR if the Service Directory cannot be reached.

◆ SessionCloseHandler()

static void SessionCloseHandler ( le_msg_SessionRef_t  sessionRef,
void *  contextPtr 
)
static

◆ taf_can_SetServerDisconnectHandler()

void taf_can_SetServerDisconnectHandler ( taf_can_DisconnectHandler_t  disconnectHandler,
void *  contextPtr 
)

Set handler called when server disconnection is detected.

When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants to continue without exiting, it should call longjmp() from inside the handler.

◆ NonExitSessionCloseHandler()

static void NonExitSessionCloseHandler ( le_msg_SessionRef_t  sessionRef,
void *  contextPtr 
)
static

◆ taf_can_SetNonExitServerDisconnectHandler()

void taf_can_SetNonExitServerDisconnectHandler ( taf_can_DisconnectHandler_t  disconnectHandler,
void *  contextPtr 
)

Set handler called when server disconnection is detected without exiting.

When a server connection is lost, call this handler without exit.

Warning
When using the API, it needs the application developer to handle some cases like re-connecting and recycling the resources. For most of cases, it is safe to use SetServerDisconnectHandler.

◆ taf_can_DisconnectService()

void taf_can_DisconnectService ( void  )

Disconnect the current client thread from the service providing this API.

Normally, this function doesn't need to be called. After this function is called, there's no longer a connection to the service, and the functions in this API can't be used. For details, see apiFilesC_client.

This function is created automatically.

◆ taf_can_CreateCanInf()

taf_can_CanInterfaceRef_t taf_can_CreateCanInf ( const char *LE_NONNULL  infName,
taf_can_InfProtocol_t  canInfType 
)

Creates a CAN interface.

Returns
  • Reference to the created CAN interface.
  • Null when attempt failed.
Note
The process exits if an invalid or existing tag is passed.
Parameters
[in]infNameCAN interface name, e.g., can0, can1, etc.
[in]canInfTypeCAN interface type.

◆ taf_can_SetFilter()

le_result_t taf_can_SetFilter ( taf_can_CanInterfaceRef_t  canInfRef,
uint32_t  frameId 
)

Sets a filter to receive CAN frame for the given frame ID.

Returns
  • LE_OK – Filter successfully set.
  • LE_OUT_OF_RANGE – Frame ID greater than 29 bits.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.
[in]frameIdFrame ID.

◆ taf_can_EnableLoopback()

le_result_t taf_can_EnableLoopback ( taf_can_CanInterfaceRef_t  canInfRef)

Enables loopback message sending from the given CAN interface (can0/can1/..).

Returns
  • LE_OK – Local loopback successfully enabled.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_DisableLoopback()

le_result_t taf_can_DisableLoopback ( taf_can_CanInterfaceRef_t  canInfRef)

Disables loopback message sending from the given CAN interface (can0/can1/..).

Returns
  • LE_OK – Local loopback successfully disabled.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_EnableRcvOwnMsg()

le_result_t taf_can_EnableRcvOwnMsg ( taf_can_CanInterfaceRef_t  canInfRef)

Enables receiving messages sent from the same CanInterface reference.

Returns
  • LE_OK – Reception of the application's own sent messages successfully enabled.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_DisableRcvOwnMsg()

le_result_t taf_can_DisableRcvOwnMsg ( taf_can_CanInterfaceRef_t  canInfRef)

Disables receiving messages sent from the same CanInterface reference.

Returns
  • LE_OK – Reception of the application's own sent messages successfully disabled.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_IsFdSupported()

bool taf_can_IsFdSupported ( taf_can_CanInterfaceRef_t  canInfRef)

Checks whether the device supports FD frame or not.

Returns
  • True – FD frame supported.
  • False – FD frame not supported.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_EnableFdFrame()

le_result_t taf_can_EnableFdFrame ( taf_can_CanInterfaceRef_t  canInfRef)

Enables CAN FD frame, if the device supports FD frame.

Returns
  • LE_OK – CAN FD frame successfully enabled.
  • LE_UNSUPPORTED – CAN FD frame not supported.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_GetFdStatus()

bool taf_can_GetFdStatus ( taf_can_CanInterfaceRef_t  canInfRef)

Checks whether the CAN FD frame is enabled or not.

Returns
  • True – CAN FD frame is enabled.
  • False – CAN FD frame is not enabled.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface.

◆ taf_can_AddCanEventHandler()

taf_can_CanEventHandlerRef_t taf_can_AddCanEventHandler ( taf_can_CanInterfaceRef_t  canInfRef,
uint32_t  frameId,
uint32_t  frIdMask,
taf_can_CallbackFunc_t  handlerPtr,
void *  contextPtr 
)

Add handler function for EVENT 'taf_can_CanEvent'

CAN event.

Parameters
[in]canInfRefReference of the created CAN interface.
[in]frameIdFrame ID.
[in]frIdMaskFrame ID mask for message filtering.
[in]handlerPtr
[in]contextPtr

◆ taf_can_RemoveCanEventHandler()

void taf_can_RemoveCanEventHandler ( taf_can_CanEventHandlerRef_t  handlerRef)

Remove handler function for EVENT 'taf_can_CanEvent'

Parameters
[in]handlerRef

◆ taf_can_CreateCanFrame()

taf_can_CanFrameRef_t taf_can_CreateCanFrame ( taf_can_CanInterfaceRef_t  canInfRef,
uint32_t  frameId 
)

Creates a CAN frame.

Returns
  • Reference to the created CAN frame.
  • Null when attempt failed.
Note
The process exits if an invalid reference or existing tag is passed.
Parameters
[in]canInfRefReference of the created CAN interface.
[in]frameIdframe ID.

◆ taf_can_SetPayload()

le_result_t taf_can_SetPayload ( taf_can_CanFrameRef_t  frameRef,
const uint8_t *  dataPtr,
size_t  dataSize 
)

Sets the data payload.

Returns
  • LE_OK – Data payload successfully set.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]frameRefReference of the created CAN frame.
[in]dataPtrData payload.
[in]dataSize

◆ taf_can_SetFrameType()

le_result_t taf_can_SetFrameType ( taf_can_CanFrameRef_t  frameRef,
taf_can_FrameType_t  frameType 
)

Sets the frame type to send.

Returns
  • LE_OK – Frame type successfully set.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]frameRefReference of the created CAN frame.
[in]frameTypeCAN frame type.

◆ taf_can_SendFrame()

le_result_t taf_can_SendFrame ( taf_can_CanFrameRef_t  frameRef)

Sends a CAN frame.

Returns
  • LE_OK – CAN frame successfully sent.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]frameRefReference of the created CAN frame to send.

◆ taf_can_DeleteCanInf()

le_result_t taf_can_DeleteCanInf ( taf_can_CanInterfaceRef_t  canInfRef)

Deletes a created CAN interface.

Returns
  • LE_OK – Created CAN interface successfully deleted.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]canInfRefReference of the created CAN interface to delete.

◆ taf_can_DeleteCanFrame()

le_result_t taf_can_DeleteCanFrame ( taf_can_CanFrameRef_t  frameRef)

Deletes a created CAN frame.

Returns
  • LE_OK – Created CAN frame successfully deleted.
  • LE_FAULT – Failed.
Note
The process exits if an invalid reference is passed.
Parameters
[in]frameRefReference of the created CAN frame to delete.

Variable Documentation

◆ _ClientThreadDataPool

le_mem_PoolRef_t _ClientThreadDataPool
static

The memory pool for client thread objects

◆ _ThreadDataKey

pthread_key_t _ThreadDataKey
static

Key under which the pointer to the Thread Object (_ClientThreadData_t) will be kept in thread-local storage. This allows a thread to quickly get a pointer to its own Thread Object.

◆ CommonDataInitialized

bool CommonDataInitialized = false
static

This global flag is shared by all client threads, and is used to indicate whether the common data has been initialized.

Warning
Use InitMutex, defined below, to protect accesses to this data.

◆ le_ifgen_InitMutexRef

le_mutex_Ref_t le_ifgen_InitMutexRef

Mutex and associated macros for use with the above CommonDataInitialized.