![]() |
botsense
3.2.0
RoadNarrows Client-Server Proxied Services Framework
|
BotSense bsProxy server plug-in DLL I2C bus device module. More...
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/new.h"
#include "rnr/netmsgs.h"
#include "rnr/i2c.h"
#include "botsense/BotSense.h"
#include "botsense/libBotSense.h"
#include "botsense/bsProxyModIF.h"
#include "botsense/bsI2C.h"
#include "botsense/bsI2CMsgs.h"
Go to the source code of this file.
Classes | |
struct | BsModCtlBlk_T |
Module resource control block structure type. More... | |
Macros | |
#define | BSMOD_MAX_HANDLES 32 |
Maximum number of module supported simultaneous virtual connections. | |
Functions | |
static BsModCtlBlk_T * | bsModCtlBlkNew (const char *sDevUri, bool_t bTrace) |
Allocate a new resource control block. More... | |
static void | bsModCtlBlkDelete (BsModCtlBlk_T *pCtlBlk) |
Delete an allocated resource control block. More... | |
static BsModCtlBlk_T * | bsModCtlBlkFind (const char *sDevUri) |
Find an already allocated resource control block. More... | |
static int | bsModI2CReqRead (BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen) |
Service a I2C read request. More... | |
static int | bsModI2CReqWrite (BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen) |
Service a I2C write request. More... | |
static int | bsModI2CReqTrans (BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen) |
Service a I2C write-read transaction request. More... | |
static int | bsModI2CScanCallback (i2c_t *pHndI2C, i2c_addr_t addr, void *pContext) |
I2C scan callback function. More... | |
static int | bsModI2CReqScan (BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen) |
Service a I2C scan for devices request. More... | |
int | bsModInit (const char *sModUri, const BsModProxyCb_T *pCallbacks) |
Initialize I2C module. More... | |
void | bsModExit () |
Exit I2C module. More... | |
int | bsModOpen (BsVConnHnd_T hndVConn, bool_t bTrace, const char *sDevUri, byte_t argbuf[], size_t uArgSize) |
Open an I2C device and associate with the given handle. More... | |
int | bsModClose (BsVConnHnd_T hndVConn) |
Close the I2C device and disassociate virtual connection handle. More... | |
int | bsModRequest (BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen) |
Service an I2C request. More... | |
int | bsModTrace (BsVConnHnd_T hndVConn, bool_t bTrace) |
Enable/disable message tracing on handle. More... | |
const BsModInfo_T * | bsModInfo () |
Query for the static module information. More... | |
Variables | |
static BsModInfo_T | BsModInfo |
Module static information. More... | |
static const char * | BsModUri |
module canonical name | |
static const BsModProxyCb_T * | BsModCallbacks |
module to bsProxy callbacks | |
static BsModRsrcTbl_T * | BsModRsrcTbl |
module resource table | |
BotSense bsProxy server plug-in DLL I2C bus device module.
Definition in file bsI2CServer.c.
int bsModClose | ( | BsVConnHnd_T | hndVConn | ) |
Close the I2C device and disassociate virtual connection handle.
The actual device and resources are only cleared if this is the last virtual connection reference to this device.
hndVConn | Virtual connection handle. |
Definition at line 782 of file bsI2CServer.c.
References BS_ECODE_INTERNAL, BS_ECODE_NO_VCONN, BS_OK, BSMOD_LOG_ERROR, BSMOD_RSRC_IS_INUSE, BSMOD_TRY_VCONN_HND_RANGE, bsModCtlBlkDelete(), BsModProxyCb_T::m_cbModRsrcRemove, BsModCtlBlk_T::m_hndI2C, and BsModCtlBlk_T::m_uRefCnt.
|
static |
Delete an allocated resource control block.
pCtlBlk | Pointer to allocated control block. |
Definition at line 145 of file bsI2CServer.c.
References BsModCtlBlk_T::m_sDevUri.
Referenced by bsModClose(), bsModExit(), and bsModOpen().
|
static |
Find an already allocated resource control block.
sDevUri | Device URI search parameter. |
Definition at line 162 of file bsI2CServer.c.
References BSMOD_MAX_HANDLES, BsModCtlBlk_T::m_sDevUri, and BsModRsrcTbl_T::m_vecRsrc.
Referenced by bsModOpen().
|
static |
Allocate a new resource control block.
Multiple virtual connection to the same I2C device share the same control block.
sDevUri | Device URI. |
bTrace | Do [not] trace messages. |
Definition at line 127 of file bsI2CServer.c.
References BsModCtlBlk_T::m_bTrace, BsModCtlBlk_T::m_sDevUri, and BsModCtlBlk_T::m_uRefCnt.
Referenced by bsModOpen().
void bsModExit | ( | ) |
Exit I2C module.
Called once prior to module being unloaded.
All open I2C devices will be closed.
Definition at line 651 of file bsI2CServer.c.
References BSMOD_MAX_HANDLES, bsModCtlBlkDelete(), BsModUri, BsModProxyCb_T::m_cbModRsrcTblDelete, BsModCtlBlk_T::m_hndI2C, BsModCtlBlk_T::m_uRefCnt, and BsModRsrcTbl_T::m_vecRsrc.
|
static |
Service a I2C read request.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgIdReq | Request message id. |
bufReq | Packed request message buffer. |
uReqLen | Size of request in buffer (number of bytes). |
Definition at line 194 of file bsI2CServer.c.
References BS_ECODE_BAD_MSG, BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_ECODE_SYS, BS_OK, BsI2CMsgIdRspRead, BsI2CPackRspRead(), BsI2CUnpackReqRead(), BSMOD_IS_VCONN_HANDLE, BSMOD_RSRC, BSMOD_SEND_ERROR_RSP, BSMOD_SEND_NMERROR_RSP, BSMOD_SEND_SYSERROR_RSP, BSPROXY_BUF_BODY, BSPROXY_MSG_MAX_LEN, BsI2CReqRead_T::m_addr, BsModCtlBlk_T::m_bTrace, BsModProxyCb_T::m_cbSendRsp, BsI2CRspRead_T::m_count, BsModCtlBlk_T::m_hndI2C, BsI2CRspRead_T::m_readbuf, BsI2CReqRead_T::m_readlen, and BsI2CRspRead_T::u.
Referenced by bsModRequest().
|
static |
Service a I2C scan for devices request.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgIdReq | Request message id. |
bufReq | Packed request message buffer. |
uReqLen | Size of request in buffer (number of bytes). |
Definition at line 541 of file bsI2CServer.c.
References BS_ECODE_BAD_MSG, BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_ECODE_SYS, BS_OK, BsI2CMsgIdRspScan, BsI2CPackRspScan(), BSMOD_IS_VCONN_HANDLE, BSMOD_RSRC, BSMOD_SEND_ERROR_RSP, BSMOD_SEND_NMERROR_RSP, BSMOD_SEND_SYSERROR_RSP, bsModI2CScanCallback(), BSPROXY_BUF_BODY, BSPROXY_MSG_MAX_LEN, BsModCtlBlk_T::m_bTrace, BsModProxyCb_T::m_cbSendRsp, BsI2CRspScan_T::m_count, BsModCtlBlk_T::m_hndI2C, and BsI2CRspScan_T::m_scan.
Referenced by bsModRequest().
|
static |
Service a I2C write-read transaction request.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgIdReq | Request message id. |
bufReq | Packed request message buffer. |
uReqLen | Size of request in buffer (number of bytes). |
Definition at line 404 of file bsI2CServer.c.
References BS_ECODE_BAD_MSG, BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_ECODE_SYS, BS_OK, BsI2CMsgIdRspRead, BsI2CPackRspRead(), BsI2CUnpackReqTrans(), BSMOD_IS_VCONN_HANDLE, BSMOD_RSRC, BSMOD_SEND_ERROR_RSP, BSMOD_SEND_NMERROR_RSP, BSMOD_SEND_SYSERROR_RSP, BSPROXY_BUF_BODY, BSPROXY_MSG_MAX_LEN, BsI2CReqTrans_T::m_addr, BsModCtlBlk_T::m_bTrace, BsModProxyCb_T::m_cbSendRsp, BsI2CReqTrans_T::m_count, BsI2CRspRead_T::m_count, BsModCtlBlk_T::m_hndI2C, BsI2CRspRead_T::m_readbuf, BsI2CReqTrans_T::m_readlen, BsI2CReqTrans_T::m_writebuf, BsI2CReqTrans_T::u, and BsI2CRspRead_T::u.
Referenced by bsModRequest().
|
static |
Service a I2C write request.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgIdReq | Request message id. |
bufReq | Packed request message buffer. |
uReqLen | Size of request in buffer (number of bytes). |
Definition at line 299 of file bsI2CServer.c.
References BS_ECODE_BAD_MSG, BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_ECODE_SYS, BS_OK, BsI2CMsgIdRspWrite, BsI2CPackRspWrite(), BsI2CUnpackReqWrite(), BSMOD_IS_VCONN_HANDLE, BSMOD_RSRC, BSMOD_SEND_ERROR_RSP, BSMOD_SEND_NMERROR_RSP, BSMOD_SEND_SYSERROR_RSP, BSPROXY_BUF_BODY, BSPROXY_MSG_MAX_LEN, BsI2CReqWrite_T::m_addr, BsModCtlBlk_T::m_bTrace, BsI2CRspWrite_T::m_byteswritten, BsModProxyCb_T::m_cbSendRsp, BsI2CReqWrite_T::m_count, BsModCtlBlk_T::m_hndI2C, BsI2CReqWrite_T::m_writebuf, and BsI2CReqWrite_T::u.
Referenced by bsModRequest().
|
static |
I2C scan callback function.
pHndI2C | Pointer to I2C Bus handle. |
addr | Discovered I2C device address during scan. |
pContext | Callback context. |
Definition at line 512 of file bsI2CServer.c.
References BS_ECODE_SYS, BSI2C_RSPSCAN_SCAN_LEN, BsI2CRspScan_T::m_count, BsI2CRspScan_T::m_scan, and BsI2CRspScan_T::u.
Referenced by bsModI2CReqScan().
const BsModInfo_T* bsModInfo | ( | ) |
Query for the static module information.
Definition at line 927 of file bsI2CServer.c.
References BsModInfo.
int bsModInit | ( | const char * | sModUri, |
const BsModProxyCb_T * | pCallbacks | ||
) |
Initialize I2C module.
Called once after module is loaded.
sModUri | Expanded, canonical module path name. |
pCallbacks | Pointer to a set of module -> bsProxy core callback functions. |
Definition at line 631 of file bsI2CServer.c.
References BS_OK, BSMOD_MAX_HANDLES, BsModUri, and BsModProxyCb_T::m_cbModRsrcTblNew.
int bsModOpen | ( | BsVConnHnd_T | hndVConn, |
bool_t | bTrace, | ||
const char * | sDevUri, | ||
byte_t | argbuf[], | ||
size_t | uArgSize | ||
) |
Open an I2C device and associate with the given handle.
Subsequent calls to the module use the given handle to associate the specific module-device instance.
The argument buffer contains packed message arguements specific to the device and module. For this I2C module, there are now additional arguments.
hndVConn | Virtual connection handle. |
bTrace | Do [not] enable message tracing on this handle. |
sDevUri | Device URI. |
argbuf | Packed specific open configuration arguments submessage. |
uArgSize | Size of packed argumets in buffer (number of bytes). |
Definition at line 708 of file bsI2CServer.c.
References BS_ECODE_BUSY, BS_ECODE_NO_RSRC, BS_ECODE_SYS, BSMOD_LOG_ERROR, BSMOD_LOG_SYSERROR, BSMOD_MAX_HANDLES, BSMOD_RSRC_INUSE_COUNT, BSMOD_RSRC_IS_INUSE, BSMOD_TRY_VCONN_HND_RANGE, bsModCtlBlkDelete(), bsModCtlBlkFind(), bsModCtlBlkNew(), BsModProxyCb_T::m_cbModRsrcAdd, BsModCtlBlk_T::m_hndI2C, and BsModCtlBlk_T::m_uRefCnt.
int bsModRequest | ( | BsVConnHnd_T | hndVConn, |
BsTid_T | uTid, | ||
BsMsgId_T | uMsgIdReq, | ||
byte_t | bufReq[], | ||
size_t | uReqLen | ||
) |
Service an I2C request.
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgIdReq | Request message id. |
bufReq | Packed request message buffer. |
uReqLen | Size of request in buffer (number of bytes). |
Definition at line 841 of file bsI2CServer.c.
References BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_ECODE_UNKNOWN_REQ, BsI2CMsgIdReqRead, BsI2CMsgIdReqScan, BsI2CMsgIdReqTrans, BsI2CMsgIdReqWrite, BSMOD_IS_VCONN_HANDLE, BSMOD_RSRC, BSMOD_SEND_ERROR_RSP, bsModI2CReqRead(), bsModI2CReqScan(), bsModI2CReqTrans(), and bsModI2CReqWrite().
int bsModTrace | ( | BsVConnHnd_T | hndVConn, |
bool_t | bTrace | ||
) |
Enable/disable message tracing on handle.
hndVConn | Virtual connection handle. |
bTrace | Do [not] enable message tracing on this handle. |
Definition at line 893 of file bsI2CServer.c.
References BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_OK, BSMOD_IS_VCONN_HANDLE, BSMOD_LOG_ERROR, BSMOD_RSRC, and BsModCtlBlk_T::m_bTrace.
|
static |
Module static information.
Definition at line 72 of file bsI2CServer.c.
Referenced by bsModInfo().