52 #include "rnr/rnrconfig.h" 55 #include "rnr/netmsgs.h" 56 #include "rnr/serdev.h" 75 .brief =
"Raw R2-232 serial proxied device.",
78 .maintainer =
"RaodNarrows LLC",
79 .license =
"(C) 2010 RoadNarrows LLC. All rights reserved." 96 #define BSMOD_MAX_HANDLES 8 99 #define BSMOD_T_READ 1000000 100 #define BSMOD_T_TRANS 2000000
101 #define BSMOD_T_WRITE 1000000
111 const char *m_sDevUri;
141 pCtlBlk->
m_sDevUri = new_strdup(sDevUri);
155 if( pCtlBlk != NULL )
195 "Module vconn handle out-of-range.");
202 if( pCtlBlk == NULL )
205 "No resources for virtual connection found.");
218 "MsgId=%u", uMsgIdReq);
232 "SerDevRead(%d,...).", pCtlBlk->
m_fd);
236 LOGDIAG3(
"VConn=%d: %d=SerDevRead(fd=%d, buf=%p, count=%zu, usec=%u).",
252 "MsgId=%u", uMsgIdRsp);
259 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
297 "Module vconn handle out-of-range.");
304 if( pCtlBlk == NULL )
307 "No resources for virtual connection found.");
320 "MsgId=%u", uMsgIdReq);
334 "SerDevWrite(%d,...).", pCtlBlk->
m_fd);
338 LOGDIAG3(
"VConn=%d: %d=SerDevWrite(fd=%d, buf=%p, count=%zu, usec=%u).",
355 "MsgId=%u", uMsgIdRsp);
362 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
400 "Module vconn handle out-of-range.");
407 if( pCtlBlk == NULL )
410 "No resources for virtual connection found.");
423 "MsgId=%u", uMsgIdReq);
437 "SerDevWrite(%d,...).", pCtlBlk->
m_fd);
441 LOGDIAG3(
"VConn=%d: %d=SerDevWrite(fd=%d, buf=%p, count=%zu, usec=%u).",
452 "SerDevRead(%d,...).", pCtlBlk->
m_fd);
456 LOGDIAG3(
"VConn=%d: %d=SerDevRead(fd=%d, buf=%p, count=%zu, usec=%u)).",
472 "MsgId=%u", uMsgIdRsp);
479 BsModCallbacks->
m_cbSendRsp(hndVConn, uTid, uMsgIdRsp, bufRsp, (
size_t)n);
505 BsModCallbacks = pCallbacks;
530 if( pCtlBlk->
m_fd >= 0 )
532 SerDevClose(pCtlBlk->
m_fd);
590 "InUseCount=%u: No more resources available.",
599 "Module virtual connection handle already in use");
609 "Unpacking failed on BsSerialReqOpenArgs submessage");
630 LOGDIAG2(
"VConn=%d: %d=SerDevOpen(dev=%s, %d,%d,%c,%d, rts=%s, xon=%s).",
631 hndVConn, fd, sDevUri,
661 "Resources for virtual connection not found.");
669 if( pCtlBlk == NULL )
675 if( pCtlBlk->
m_fd >= 0 )
677 SerDevClose(pCtlBlk->
m_fd);
678 LOGDIAG2(
"VConn=%d: SerDevClose(fd=%d).", hndVConn, pCtlBlk->
m_fd);
711 "Module vconn handle out-of-range.");
719 if( pCtlBlk == NULL )
722 "No resources for virtual connection found.");
736 "MsgId=%u.", uMsgIdReq);
757 "Module vconn handle out-of-range.");
765 if( pCtlBlk == NULL )
768 "No resources for virtual connection found.");
INLINE_IN_H int BsSerialUnpackReqRead(byte_t buf[], size_t uMsgLen, BsSerialReqRead_T *pStruct, bool_t bTrace)
Unpack a BsSerialReqRead ITV message in big-endian byte order from the input buffer.
uint_t BsMsgId_T
client message id type [0-64k].
union BsSerialReqWrite_T::@18::@19 u
aligned vector items
#define BSMOD_LOG_ERROR(hndVConn, ecode, efmt,...)
Log Interface Module Error.
static BsModInfo_T BsModInfo
Module static information.
#define BS_ECODE_UNKNOWN_REQ
unknown request
#define BSMOD_LOG_NMERROR(hndVConn, nmecode, efmt,...)
Log Interface Module NetMsgs (Un)Packing Error.
Useful indirect indexing of handle to resource instance structure.
static const char * BsModUri
module canonical name
#define BSMOD_RSRC_IS_INUSE(pRsrcTbl, hndVConn)
Test if the resource table resource handle slot is in-use.
static int bsModSerialReqRead(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service a serial read request.
void(* m_cbModRsrcTblDelete)(BsModRsrcTbl_T *pRsrcTbl)
Delete an allocated resource table.
int bsModRequest(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service a serial request.
int bsModClose(BsVConnHnd_T hndVConn)
Close the serial device and disassociate virtual connection handle.
#define BSMOD_T_WRITE
default write time out (usec)
void bsModExit()
Exit serial module.
union BsSerialRspRead_T::@16::@17 u
aligned vector items
uint_t BsTid_T
client transaction id type [0-255].
#define BSMOD_T_READ
default read time out (usec)
#define BSMOD_LOG_SYSERROR(hndVConn, efmt,...)
Log Interface Module System Error.
struct BsSerialReqWrite_T::@18 m_writebuf
vector
INLINE_IN_H int BsSerialPackRspRead(BsSerialRspRead_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsSerialRspRead ITV message in big-endian byte order into the output buffer.
size_t m_count
vector item count
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.
byte_t m_bytesize
bytesize
uint_t m_baudrate
baudrate
const BsModInfo_T * bsModInfo()
Query for the static module information.
const char * m_sDevUri
I2C device path name.
int(* m_cbModRsrcAdd)(BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn, void *pRsrc)
Add a new resource to the resource table.
union BsSerialReqTrans_T::@14::@15 u
aligned vector items
#define BS_OK
not an error, success
static int bsModSerialReqTrans(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service a serial write-read transaction request.
static void bsModCtlBlkDelete(BsModCtlBlk_T *pCtlBlk)
Delete an allocated resource control block.
#define BS_ECODE_BAD_VCONN_HND
bad virtual connection handle
struct BsSerialReqTrans_T::@14 m_writebuf
vector
#define BS_ECODE_SYS
system (errno) error
const char * mod_name
module load name sans OS dependent substrings
BsSerialReqOpenArgs_T m_stDevCfg
serial device configuration
#define BSMOD_TRY_VCONN_HND_RANGE(hndVConn)
Check if handle is within the range of module handles.
<b><i>BotSense</i></b> bsProxy client library RS-232 serial interface.
Interface Module callbacks to bsProxy services type.
int bsModOpen(BsVConnHnd_T hndVConn, bool_t bTrace, const char *sDevUri, byte_t argbuf[], size_t uArgSize)
Open a serial device and associate with the given handle.
static int bsModSerialReqWrite(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgIdReq, byte_t bufReq[], size_t uReqLen)
Service a serial write request.
#define BS_SER_SERVER_MOD
server plugin dll module
INLINE_IN_H int BsSerialUnpackReqWrite(byte_t buf[], size_t uMsgLen, BsSerialReqWrite_T *pStruct, bool_t bTrace)
Unpack a BsSerialReqWrite ITV message in big-endian byte order from the input buffer.
<b><i>BotSense</i></b> client library declarations.
#define BS_ECODE_BAD_MSG
bad message
#define BSMOD_RSRC_INUSE_COUNT(pRsrcTbl)
Get the resouce table current in-use count.
void(* m_cbSendRsp)(BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufRsp[], size_t uRspLen)
Send module-specific repsonse callback function.
BotSense bsProxy server - client raw serial NetMsgs XML Definition.
int bsModInit(const char *sModUri, const BsModProxyCb_T *pCallbacks)
Initialize serial module.
#define BS_ECODE_NO_RSRC
no resource available
int bsModTrace(BsVConnHnd_T hndVConn, bool_t bTrace)
Enable/disable message tracing on handle.
#define BSMOD_RSRC(pRsrcTbl, hndVConn)
Get the resource given the handle.
#define BSMOD_MAX_HANDLES
Maximum number of module supported simultaneous virtual connections.
Standard bsProxy static interface module information structure type.
void *(* m_cbModRsrcRemove)(BsModRsrcTbl_T *pRsrcTbl, BsVConnHnd_T hndVConn)
Remove a resource from the resource table.
size_t m_count
vector item count
INLINE_IN_H int BsSerialUnpackReqOpenArgs(byte_t buf[], size_t uMsgLen, BsSerialReqOpenArgs_T *pStruct, bool_t bTrace)
Unpack a BsSerialReqOpenArgs ITV message in big-endian byte order from the input buffer.
size_t m_count
vector item count
#define BSMOD_SEND_NMERROR_RSP(pCb, hndVConn, uTid, nmecode, efmt,...)
Log NetMsgs (Un)Packing Error and Send Error Response.
<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.
byte_t m_stopbits
stopbits
byte_t m_byteswritten
byteswritten
INLINE_IN_H int BsSerialUnpackReqTrans(byte_t buf[], size_t uMsgLen, BsSerialReqTrans_T *pStruct, bool_t bTrace)
Unpack a BsSerialReqTrans ITV message in big-endian byte order from the input buffer.
#define BS_ECODE_INTERNAL
internal error (bug)
#define BSPROXY_BUF_BODY(buf)
Convenience macro to produce a buffer (offset, size) 2-tuple.
static BsModRsrcTbl_T * BsModRsrcTbl
module resource table
#define BS_ECODE_NO_VCONN
virtual connection not found
INLINE_IN_H int BsSerialPackRspWrite(BsSerialRspWrite_T *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a BsSerialRspWrite ITV message in big-endian byte order into the output buffer.
#define BSMOD_SEND_SYSERROR_RSP(pCb, hndVConn, uTid, efmt,...)
Log System Error and Send Error Response.
static BsModCtlBlk_T * bsModCtlBlkNew(int fd, const char *sDevUri, BsSerialReqOpenArgs_T *pDevCfg, bool_t bTrace)
Allocate a new resource control block.
#define BSPROXY_MSG_MAX_LEN
total message maximum length
void ** m_vecRsrc
vecRsrc[index] -> rsrc
#define BSMOD_SEND_ERROR_RSP(pCb, hndVConn, uTid, ecode, efmt,...)
Log <b><i>BotSense</i></b> Error and Send Error Response.
#define BS_ECODE_BUSY
resource busy
<b><i>BotSense</i></b> package top-level, unifying header declarations.
struct BsSerialRspRead_T::@16 m_readbuf
vector
int BsVConnHnd_T
virtual connection handle type
static const BsModProxyCb_T * BsModCallbacks
module to bsProxy callbacks
int m_fd
/dev/null open file descriptor