52 #include "rnr/rnrconfig.h" 55 #include "rnr/netmsgs.h" 75 .brief =
"Raw I2C Bus proxied device.",
78 .maintainer =
"RaodNarrows LLC",
79 .license =
"(C) 2010 RoadNarrows LLC. All rights reserved." 96 #define BSMOD_MAX_HANDLES 32 134 pCtlBlk->
m_sDevUri = new_strdup(sDevUri);
147 if( pCtlBlk != NULL )
172 if( !strcmp(pCtlBlk->
m_sDevUri, sDevUri) )
215 "Module vconn handle out-of-range.");
222 if( pCtlBlk == NULL )
225 "No resources for virtual connection found.");
238 "MsgId=%u", uMsgIdReq);
242 addr = (i2c_addr_t)msgReq.
m_addr;
254 "i2c_read(fd=%d, addr=0x%02x, ...).", pCtlBlk->
m_hndI2C.fd, addr);
258 LOGDIAG3(
"VConn=%d: %d=i2c_read(fd=%d, addr=0x%02x, buf=%p, count=%zu).",
274 "MsgId=%u", uMsgIdRsp);
281 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
320 "Module vconn handle out-of-range.");
327 if( pCtlBlk == NULL )
330 "No resources for virtual connection found.");
343 "MsgId=%u", uMsgIdReq);
347 addr = (i2c_addr_t)msgReq.
m_addr;
359 "i2c_write(fd=%d, addr=0x%02x, ...).", pCtlBlk->
m_hndI2C.fd, addr);
363 LOGDIAG3(
"VConn=%d: %d=i2c_write(fd=%d, addr=0x%02x, buf=%p, count=%zu).",
379 "MsgId=%u", uMsgIdRsp);
386 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
426 "Module vconn handle out-of-range.");
433 if( pCtlBlk == NULL )
436 "No resources for virtual connection found.");
449 "MsgId=%u", uMsgIdReq);
453 addr = (i2c_addr_t)msgReq.
m_addr;
458 rc = i2c_transfer(&pCtlBlk->
m_hndI2C, addr,
466 "i2c_transfer(fd=%d, addr=0x%02x, ...).", pCtlBlk->
m_hndI2C.fd, addr);
470 LOGDIAG3(
"VConn=%d: i2c_transfer(fd=%d, addr=0x%02x, wbuf=%p, wcount=%zu, " 471 "rbuf=%p, rcount=%zu).",
489 "MsgId=%u", uMsgIdRsp);
496 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
560 "Module vconn handle out-of-range.");
567 if( pCtlBlk == NULL )
570 "No resources for virtual connection found.");
586 "i2c_scan(fd=%d, ...).", pCtlBlk->
m_hndI2C.fd);
590 LOGDIAG3(
"VConn=%d: %d=i2c_scan(fd=%d, ...).",
603 "MsgId=%u", uMsgIdRsp);
610 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
636 BsModCallbacks = pCallbacks;
724 "InUseCount=%u: No more resources available.",
733 "Module virtual connection handle already in use");
748 rc = i2c_open(&pCtlBlk->
m_hndI2C, sDevUri);
765 LOGDIAG2(
"VConn=%d: %d=i2c_open(%p, dev=%s).",
793 "Resources for virtual connection not found.");
801 if( pCtlBlk == NULL )
814 LOGDIAG2(
"VConn=%d: i2c_close(fd=%d).", hndVConn, pCtlBlk->
m_hndI2C.fd);
853 "Module vconn handle out-of-range.");
861 if( pCtlBlk == NULL )
864 "No resources for virtual connection found.");
880 "MsgId=%u.", uMsgIdReq);
901 "Module vconn handle out-of-range.");
909 if( pCtlBlk == NULL )
912 "No resources for virtual connection found.");
uint_t BsMsgId_T
client message id type [0-64k].
#define BSMOD_LOG_ERROR(hndVConn, ecode, efmt,...)
Log Interface Module Error.
static const char * BsModUri
module canonical name
#define BS_ECODE_UNKNOWN_REQ
unknown request
struct BsI2CReqTrans_T::@0 m_writebuf
vector
Useful indirect indexing of handle to resource instance structure.
#define BSI2C_RSPSCAN_SCAN_LEN
#define BSMOD_RSRC_IS_INUSE(pRsrcTbl, hndVConn)
Test if the resource table resource handle slot is in-use.
void(* m_cbModRsrcTblDelete)(BsModRsrcTbl_T *pRsrcTbl)
Delete an allocated resource table.
size_t m_count
vector item count
union BsI2CReqWrite_T::@4::@5 u
aligned vector items
void bsModExit()
Exit I2C module.
INLINE_IN_H int BsI2CPackRspRead(BsI2CRspRead_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsI2CRspRead ITV message in big-endian byte order into the output buffer.
int bsModClose(BsVConnHnd_T hndVConn)
Close the I2C device and disassociate virtual connection handle.
uint_t BsTid_T
client transaction id type [0-255].
uint_t m_uRefCnt
reference count to this device
const BsModInfo_T * bsModInfo()
Query for the static module information.
#define BSMOD_LOG_SYSERROR(hndVConn, efmt,...)
Log Interface Module System Error.
<b><i>BotSense</i></b> bsProxy client library I2C bus interface.
#define BS_I2C_SERVER_MOD
server plugin dll module
Module resource control block structure type.
bool_t m_bTrace
do [not] trace messages
#define BSMOD_IS_VCONN_HANDLE(hndVConn)
Test if the handle is in the valid module virtual connection range.
const char * m_sDevUri
I2C device path name.
struct BsI2CReqWrite_T::@4 m_writebuf
vector
int(* m_cbModRsrcAdd)(BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn, void *pRsrc)
Add a new resource to the resource table.
#define BS_OK
not an error, success
struct BsI2CRspRead_T::@2 m_readbuf
vector
#define BS_ECODE_BAD_VCONN_HND
bad virtual connection handle
size_t m_count
vector item count
#define BS_ECODE_SYS
system (errno) error
const char * mod_name
module load name sans OS dependent substrings
#define BSMOD_MAX_HANDLES
Maximum number of module supported simultaneous virtual connections.
#define BSMOD_TRY_VCONN_HND_RANGE(hndVConn)
Check if handle is within the range of module handles.
Interface Module callbacks to bsProxy services type.
BotSense bsProxy server - client raw I2C NetMsgs XML Definition.
<b><i>BotSense</i></b> client library declarations.
#define BS_ECODE_BAD_MSG
bad message
int bsModTrace(BsVConnHnd_T hndVConn, bool_t bTrace)
Enable/disable message tracing on handle.
#define BSMOD_RSRC_INUSE_COUNT(pRsrcTbl)
Get the resouce table current in-use count.
union BsI2CReqTrans_T::@0::@1 u
aligned vector items
void(* m_cbSendRsp)(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufRsp[], size_t uRspLen)
Send module-specific repsonse callback function.
INLINE_IN_H int BsI2CPackRspWrite(BsI2CRspWrite_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsI2CRspWrite ITV message in big-endian byte order into the output buffer. ...
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.
static int bsModI2CReqRead(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service a I2C read request.
struct BsI2CRspScan_T::@6 m_scan
vector
INLINE_IN_H int BsI2CUnpackReqWrite(byte_t buf[], size_t uMsgLen, BsI2CReqWrite_T *pStruct, bool_t bTrace)
Unpack a BsI2CReqWrite ITV message in big-endian byte order from the input buffer.
size_t m_count
vector item count
#define BS_ECODE_NO_RSRC
no resource available
i2c_t m_hndI2C
I2C bus handle.
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.
byte_t m_byteswritten
byteswritten
#define BSMOD_RSRC(pRsrcTbl, hndVConn)
Get the resource given the handle.
Standard bsProxy static interface module information structure type.
static BsModCtlBlk_T * bsModCtlBlkFind(const char *sDevUri)
Find an already allocated resource control block.
size_t m_count
vector item count
void *(* m_cbModRsrcRemove)(BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn)
Remove a resource from the resource table.
int bsModRequest(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service an I2C request.
INLINE_IN_H int BsI2CUnpackReqTrans(byte_t buf[], size_t uMsgLen, BsI2CReqTrans_T *pStruct, bool_t bTrace)
Unpack a BsI2CReqTrans ITV message in big-endian byte order from the input buffer.
static int bsModI2CScanCallback(i2c_t *pHndI2C, i2c_addr_t addr, void *pContext)
I2C scan callback function.
#define BSMOD_SEND_NMERROR_RSP(pCb, hndVConn, uTid, nmecode, efmt,...)
Log NetMsgs (Un)Packing Error and Send Error Response.
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.
<b><i>BotSense</i></b> bsProxy Dynamically Linked Library module interface.
BsModRsrcTbl_T *(* m_cbModRsrcTblNew)(int nMaxResources)
Allocatae a new module resource table of fixed size.
static BsModCtlBlk_T * bsModCtlBlkNew(const char *sDevUri, bool_t bTrace)
Allocate a new resource control block.
#define BS_ECODE_INTERNAL
internal error (bug)
#define BSPROXY_BUF_BODY(buf)
Convenience macro to produce a buffer (offset, size) 2-tuple.
#define BS_ECODE_NO_VCONN
virtual connection not found
int bsModInit(const char *sModUri, const BsModProxyCb_T *pCallbacks)
Initialize I2C module.
#define BSMOD_SEND_SYSERROR_RSP(pCb, hndVConn, uTid, efmt,...)
Log System Error and Send Error Response.
static int bsModI2CReqWrite(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service a I2C write request.
static BsModRsrcTbl_T * BsModRsrcTbl
module resource table
static const BsModProxyCb_T * BsModCallbacks
module to bsProxy callbacks
#define BSPROXY_MSG_MAX_LEN
total message maximum length
void ** m_vecRsrc
vecRsrc[index] -> rsrc
union BsI2CRspScan_T::@6::@7 u
aligned vector items
#define BSMOD_SEND_ERROR_RSP(pCb, hndVConn, uTid, ecode, efmt,...)
Log <b><i>BotSense</i></b> Error and Send Error Response.
union BsI2CRspRead_T::@2::@3 u
aligned vector items
static BsModInfo_T BsModInfo
Module static information.
INLINE_IN_H int BsI2CUnpackReqRead(byte_t buf[], size_t uMsgLen, BsI2CReqRead_T *pStruct, bool_t bTrace)
Unpack a BsI2CReqRead ITV message in big-endian byte order from the input buffer. ...
#define BS_ECODE_BUSY
resource busy
<b><i>BotSense</i></b> package top-level, unifying header declarations.
int BsVConnHnd_T
virtual connection handle type
static void bsModCtlBlkDelete(BsModCtlBlk_T *pCtlBlk)
Delete an allocated resource control block.
INLINE_IN_H int BsI2CPackRspScan(BsI2CRspScan_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsI2CRspScan ITV message in big-endian byte order into the output buffer.