bsproxy/bsproxy.h File Reference


Detailed Description

Botsense proxy IP server declarations.

Version:
$LastChangedDate$ $Rev$
Author:
Robin Knight (robin.knight@roadnarrows.com)
Copyright:
(C) 2007. RoadNarrows LLC. (http://www.roadnarrows.com)
All Rights Reserved

Definition in file bsproxy.h.

#include <pthread.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/sock.h"
#include "rnr/sockset.h"
#include "rcb3/rcb3lib.h"

Go to the source code of this file.

Classes

struct  BsProxyDevI2C_T
struct  BsProxyDevRS232_T
struct  BsProxyDevRCB3_T
struct  BsProxyDev_T
struct  BsProxyClientDev_T
struct  BsProxyClient_T
struct  BsProxyServer_T

Defines

#define BSPROXY_CLIENT_DEV_MAX   8
 max. num of proxied devices per client
#define BSPROXY_REG_CLIENT_MAX   8
 max. num of simultaneous reg. clients
#define BSPROXY_DEVCLASS_NONE   0
 no device
#define BSPROXY_DEVCLASS_I2C   1
 shared I2C bus
#define BSPROXY_DEVCLASS_SER   2
 point-to-point serial
#define BSPROXY_DEVCLASS_SWR   3
 software resource
#define BSPROXY_DEVCLASS_RCB3   4
 RCB-3.
#define BSPROXY_LOG_CMD(pClient, bufCmd, lenCmd)
 Log command invocation.
#define BSPROXY_LOG_DEV_CMD(pClient, bufCmd, lenCmd)
 Log device specific command invocation.
#define chkCmdBLenEQ(pClient, bufCmd, lenValid)
 Check that length of command body equals the expected value.
#define chkCmdBLenGE(pClient, bufCmd, lenMin)
 Check that length of command body is greater than or equal the minimum value.

Functions

INLINE_IN_H int BSPACK16 (uint_t uVal, byte_t bytes[])
 Pack lower 16 bits into the next 2 bytes of the byte stream.
INLINE_IN_H int BSUNPACK16 (byte_t bytes[], uint_t *pVal)
 Unpack the next 2 bytes from the byte stream into lower 16 bits.
INLINE_IN_H int BSPACK32 (uint_t uVal, byte_t bytes[])
 Pack lower 32 bits into the next 4 bytes of the byte stream.
INLINE_IN_H int BSUNPACK32 (byte_t bytes[], uint_t *pVal)
 Unpack the next 4 bytes from the byte stream into lower 32 bits.
BsProxyDev_TProxDevOpen (int eDevType, const char *sDevName)
 Open a proxied device.
void ProxDevClose (BsProxyDev_T *pProxDev)
 Close a proxied device.
int ProxDevI2CScan (BsProxyDev_T *pProxDev, byte_t bufScan[], size_t sizeBuf)
 Scan I2C Bus for attached address.
int ProxDevI2CTrans (BsProxyDev_T *pProxDev, uint_t i2cAddr, byte_t bufWrite[], size_t countWrite, byte_t bufRead[], size_t countRead)
 Perform a write/read transaction between an I2C device.
int ProxDevI2CWrite (BsProxyDev_T *pProxDev, uint_t i2cAddr, byte_t bufWrite[], size_t countWrite)
 Write buffer to an I2C device.
int ProxDevI2CRead (BsProxyDev_T *pProxDev, uint_t i2cAddr, byte_t bufRead[], size_t countRead)
 Read bytes from an I2C device.
int ProxDevRCB3Read (BsProxyDev_T *pProxDev, byte_t bufRead[], size_t countRead)
 Read bytes from an RCB-3 controller device.
int ProxDevRCB3Write (BsProxyDev_T *pProxDev, byte_t bufWrite[], size_t countWrite)
 Write bytes to an RCB-3 controller device.
int ProxDevRCB3Trans (BsProxyDev_T *pProxDev, byte_t bufWrite[], size_t countWrite, byte_t bufRead[], size_t countRead)
 Do a write/read transaction with an RCB-3 controller device.
int ClientDispatch (BsProxyServer_T *pServer, BsProxyClient_T *pClient, byte_t bufCmd[], size_t lenCmd)
 Client top-level command dispatcher.
int ClientSendPassRsp (BsProxyClient_T *pClient, byte_t bufCmd[], byte_t bufRsp[], size_t lenRsp)
 Send pass response to the client.
int ClientSendFailRsp (BsProxyClient_T *pClient, byte_t bufCmd[], const char *sErrFmt,...)
 Send fail response to the client.
BsProxyClient_TClientNew (Socket_T *pSockClient)
 Create new client control structure.
void ClientDelete (BsProxyClient_T *pClient)
 Delete a client with the server.
int BPFootDispatch (BsProxyServer_T *pServer, BsProxyClient_T *pClient, BsProxyClientDev_T *pDev, byte_t bufCmd[], size_t lenCmd)
 BrainPack Foot command dispatcher.
int BPIMUDispatch (BsProxyServer_T *pServer, BsProxyClient_T *pClient, BsProxyClientDev_T *pDev, byte_t bufCmd[], size_t lenCmd)
 BrainPack IMU command dispatcher.
int RCB3Dispatch (BsProxyServer_T *pServer, BsProxyClient_T *pClient, BsProxyClientDev_T *pDev, byte_t bufCmd[], size_t lenCmd)
 RCB-3 Robot Controller command dispatcher.


Define Documentation

#define BSPROXY_CLIENT_DEV_MAX   8
 

max. num of proxied devices per client

BotSense Proxy Limits

Definition at line 63 of file bsproxy.h.

Referenced by ClientDelete(), ClientDevFindEmptySlot(), ClientGetHandle(), ClientNew(), and CmdDevOpen().

#define BSPROXY_DEVCLASS_NONE   0
 

no device

Device Classes

Definition at line 69 of file bsproxy.h.

#define BSPROXY_LOG_CMD pClient,
bufCmd,
lenCmd   ) 
 

Value:

LOGDIAG2("%s: %s(msgid=0x%02x, tid=%u, blen=%u)", \
      pClient->m_sClientName, LOGFUNCNAME, \
      (uint_t)bufCmd[BSPROXY_CMD_HDR_MSGID_IDX], \
      (uint_t)bufCmd[BSPROXY_CMD_HDR_TID_IDX], \
      (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX])
Log command invocation.

Parameters:
pClient BotSense client.
bufCmd Received command buffer.
lenCmd Received command length (number of bytes).

Definition at line 169 of file bsproxy.h.

Referenced by CmdDevClose(), CmdDevIoctl(), CmdDevOpen(), CmdDevRead(), CmdDevScan(), CmdDevTrans(), CmdDevWrite(), CmdLog(), CmdLoopback(), CmdProxyInfo(), and CmdVersion().

#define BSPROXY_LOG_DEV_CMD pClient,
bufCmd,
lenCmd   ) 
 

Value:

LOGDIAG2("%s: %s(msgid=0x%02x, tid=%u, blen=%u, cmdid=0x%02x)", \
      pClient->m_sClientName, LOGFUNCNAME, \
      (uint_t)bufCmd[BSPROXY_CMD_HDR_MSGID_IDX], \
      (uint_t)bufCmd[BSPROXY_CMD_HDR_TID_IDX] ,\
      (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX], \
      (uint_t)bufCmd[BSPROXY_CMD_HDR_LEN+1])
Log device specific command invocation.

Parameters:
pClient BotSense client.
bufCmd Received command buffer.
lenCmd Received command length (number of bytes).

Definition at line 183 of file bsproxy.h.

Referenced by BPFootCmdGetCooked(), BPFootCmdGetIds(), BPFootCmdGetRaw(), BPFootCmdSetCal(), BPIMUCmdGetCooked(), BPIMUCmdGetIds(), BPIMUCmdGetRaw(), BPIMUCmdSetCal(), and BPIMUCmdSetOrientation().

#define chkCmdBLenEQ pClient,
bufCmd,
lenValid   ) 
 

Value:

{if( bufCmd[BSPROXY_CMD_HDR_BLEN_IDX] != lenValid ) \
  { \
    LOGERROR("%s: lenBody=%u != lenValid=%u: bad command body length", \
        pClient->m_sClientName, (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX], \
        (uint_t)(lenValid)); \
    return ClientSendFailRsp(pClient, bufCmd, "%u: bad command body length", \
        (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX]); \
  }}
Check that length of command body equals the expected value.

Automatically returns from embedding function if false.

Parameters:
pClient BotSense client.
bufCmd Received command buffer.
lenValid Expected length (number of bytes).

Definition at line 200 of file bsproxy.h.

Referenced by CmdDevRead(), and CmdLog().

#define chkCmdBLenGE pClient,
bufCmd,
lenMin   ) 
 

Value:

{if( bufCmd[BSPROXY_CMD_HDR_BLEN_IDX] < lenMin ) \
  { \
    LOGERROR("%s: lenBody=%u < lenMin=%u: bad command body length", \
        pClient->m_sClientName, (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX], \
        (uint_t)(lenMin)); \
    return ClientSendFailRsp(pClient, bufCmd, "%u: bad command body length", \
        (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX]); \
  }}
Check that length of command body is greater than or equal the minimum value.

Automatically returns from embedding function if false.

Parameters:
pClient BotSense client.
bufCmd Received command buffer.
lenMin Expected minimum length (number of bytes).

Definition at line 220 of file bsproxy.h.

Referenced by ClientGetHandle(), CmdDevCmd(), CmdDevOpen(), CmdDevTrans(), and CmdDevWrite().


Function Documentation

int BPFootDispatch BsProxyServer_T pServer,
BsProxyClient_T pClient,
BsProxyClientDev_T pDev,
byte_t  bufCmd[],
size_t  lenCmd
 

BrainPack Foot command dispatcher.

Parameters:
pServer BotSense server.
pClient BotSense client.
pDev Client device.
bufCmd Received command buffer.
lenCmd Received command length (number of bytes).
Returns:
Returns OK on success, RC_ERROR on failure.

Definition at line 387 of file bpfoot.c.

References BPFootCmdGetCooked(), BPFootCmdGetIds(), BPFootCmdGetRaw(), BPFootCmdSetCal(), BSPROXY_BPFOOT_CMDID_CAL, BSPROXY_BPFOOT_CMDID_GET_COOKED, BSPROXY_BPFOOT_CMDID_GET_IDS, BSPROXY_BPFOOT_CMDID_GET_RAW, BSPROXY_CMD_HDR_LEN, ClientSendFailRsp(), and BsProxyClient_T::m_sClientName.

Referenced by CmdDevCmd().

00391 {
00392   byte_t  byDevCmdId;
00393 
00394   byDevCmdId = bufCmd[BSPROXY_CMD_HDR_LEN+1];
00395 
00396   //
00397   // Dispatch BrainPack Foot command.
00398   //
00399   switch( byDevCmdId )
00400   {
00401     // get device identifiers
00402     case BSPROXY_BPFOOT_CMDID_GET_IDS:
00403       return BPFootCmdGetIds(pServer, pClient, pDev, bufCmd, lenCmd);
00404 
00405     // get raw sensor data 
00406     case BSPROXY_BPFOOT_CMDID_GET_RAW:
00407       return BPFootCmdGetRaw(pServer, pClient, pDev, bufCmd, lenCmd);
00408 
00409     // get cooked sensor data 
00410     case BSPROXY_BPFOOT_CMDID_GET_COOKED:
00411       return BPFootCmdGetCooked(pServer, pClient, pDev, bufCmd, lenCmd);
00412 
00413     // calibrate sensors
00414     case BSPROXY_BPFOOT_CMDID_CAL:
00415       return BPFootCmdSetCal(pServer, pClient, pDev, bufCmd, lenCmd);
00416 
00417     default:
00418       LOGERROR("%s: BrainPack Foot: 0x%02x: unsupported device command",
00419           pClient->m_sClientName, byDevCmdId);
00420       return ClientSendFailRsp(pClient, bufCmd, "bad device command");
00421   }
00422 
00423   LOGERROR("%s: BrainPack Foot: here?", pClient->m_sClientName);
00424   return ClientSendFailRsp(pClient, bufCmd, "bad message");
00425 }

int BPIMUDispatch BsProxyServer_T pServer,
BsProxyClient_T pClient,
BsProxyClientDev_T pDev,
byte_t  bufCmd[],
size_t  lenCmd
 

BrainPack IMU command dispatcher.

Parameters:
pServer BotSense server.
pClient BotSense client.
pDev Client device.
bufCmd Received command buffer.
lenCmd Received command length (number of bytes).
Returns:
Returns OK on success, RC_ERROR on failure.

Definition at line 414 of file bpimu.c.

References BPIMUCmdGetCooked(), BPIMUCmdGetIds(), BPIMUCmdGetRaw(), BPIMUCmdSetCal(), BPIMUCmdSetOrientation(), BSPROXY_BPIMU_CMDID_CAL, BSPROXY_BPIMU_CMDID_GET_COOKED, BSPROXY_BPIMU_CMDID_GET_IDS, BSPROXY_BPIMU_CMDID_GET_RAW, BSPROXY_BPIMU_CMDID_SET_ORIENT, BSPROXY_CMD_HDR_LEN, ClientSendFailRsp(), and BsProxyClient_T::m_sClientName.

Referenced by CmdDevCmd().

00418 {
00419   byte_t  byDevCmdId;
00420 
00421   byDevCmdId = bufCmd[BSPROXY_CMD_HDR_LEN+1];
00422 
00423   //
00424   // Dispatch BrainPack IMU command.
00425   //
00426   switch( byDevCmdId )
00427   {
00428     // get device identifiers
00429     case BSPROXY_BPIMU_CMDID_GET_IDS:
00430       return BPIMUCmdGetIds(pServer, pClient, pDev, bufCmd, lenCmd);
00431 
00432     // get raw sensor data 
00433     case BSPROXY_BPIMU_CMDID_GET_RAW:
00434       return BPIMUCmdGetRaw(pServer, pClient, pDev, bufCmd, lenCmd);
00435 
00436     // get cooked sensor data 
00437     case BSPROXY_BPIMU_CMDID_GET_COOKED:
00438       return BPIMUCmdGetCooked(pServer, pClient, pDev, bufCmd, lenCmd);
00439 
00440     // calibrate sensors
00441     case BSPROXY_BPIMU_CMDID_CAL:
00442       return BPIMUCmdSetCal(pServer, pClient, pDev, bufCmd, lenCmd);
00443 
00444     // set sensor orientation
00445     case BSPROXY_BPIMU_CMDID_SET_ORIENT:
00446       return BPIMUCmdSetOrientation(pServer, pClient, pDev, bufCmd, lenCmd);
00447 
00448     default:
00449       LOGERROR("%s: BrainPack IMU: 0x%02x: unsupported device command",
00450           pClient->m_sClientName, byDevCmdId);
00451       return ClientSendFailRsp(pClient, bufCmd, "bad device command");
00452   }
00453 
00454   LOGERROR("%s: BrainPack IMU: here?", pClient->m_sClientName);
00455   return ClientSendFailRsp(pClient, bufCmd, "bad message");
00456 }

INLINE_IN_H int BSPACK16 uint_t  uVal,
byte_t  bytes[]
 

Pack lower 16 bits into the next 2 bytes of the byte stream.

Parameters:
uVal Value to pack.
bytes[] Output byte stream.
Returns:
Returns number of bytes packed.

Definition at line 241 of file bsproxy.h.

Referenced by BPFootCmdGetIds(), BPIMUCmdGetIds(), and RCB3CmdGetCurPos().

00242 {
00243   bytes[0] = (byte_t)((uVal >> 8) & 0xFF);    
00244   bytes[1] = (byte_t)(uVal & 0xFF);
00245   return 2;
00246 }

INLINE_IN_H int BSPACK32 uint_t  uVal,
byte_t  bytes[]
 

Pack lower 32 bits into the next 4 bytes of the byte stream.

Parameters:
uVal Value to pack.
bytes[] Output byte stream.
Returns:
Returns number of bytes packed.

Definition at line 266 of file bsproxy.h.

00267 {
00268   bytes[0] = (byte_t)((uVal >> 24) & 0xFF);    
00269   bytes[1] = (byte_t)((uVal >> 16) & 0xFF);    
00270   bytes[2] = (byte_t)((uVal >>  8) & 0xFF);    
00271   bytes[3] = (byte_t)(uVal & 0xFF);
00272   return 4;
00273 }

INLINE_IN_H int BSUNPACK16 byte_t  bytes[],
uint_t *  pVal
 

Unpack the next 2 bytes from the byte stream into lower 16 bits.

Parameters:
bytes[] Input byte stream.
pVal Output unpacked value.
Returns:
Returns number of bytes unpacked.

Definition at line 254 of file bsproxy.h.

Referenced by BPFootCmdGetCooked(), BPFootCmdGetIds(), BPFootCmdGetRaw(), BPIMUCmdGetIds(), and RCB3CmdMoveServo().

00255 {
00256   *pVal = (uint_t)((((uint_t)bytes[0]) << 8) + (uint_t)bytes[1]);
00257   return 2;
00258 }

INLINE_IN_H int BSUNPACK32 byte_t  bytes[],
uint_t *  pVal
 

Unpack the next 4 bytes from the byte stream into lower 32 bits.

Parameters:
bytes[] Input byte stream.
pVal Output unpacked value.
Returns:
Returns number of bytes unpacked.

Definition at line 281 of file bsproxy.h.

00282 {
00283   *pVal = (uint_t)((((uint_t)bytes[0]) << 24) + 
00284           (uint_t)(((uint_t)bytes[1]) << 16) + 
00285           (uint_t)(((uint_t)bytes[2]) <<  8) + 
00286           (uint_t)bytes[1]);
00287   return 4;
00288 }

void ClientDelete BsProxyClient_T pClient  ) 
 

Delete a client with the server.

Parameters:
pClient BotSense client.

Definition at line 1253 of file client.c.

References BSPROXY_CLIENT_DEV_MAX, BSPROXY_DEVTYPE_NONE, BsProxyClientDev_T::m_eDevType, BsProxyClientDev_T::m_pProxDev, BsProxyClient_T::m_tblClientDev, and ProxDevClose().

Referenced by BsProxyClientUnregister().

01254 {
01255   int   i;
01256 
01257   if( pClient == NULL )
01258   {
01259     return;
01260   }
01261 
01262   for(i=0; i<BSPROXY_CLIENT_DEV_MAX; ++i)
01263   {
01264     if( pClient->m_tblClientDev[i].m_eDevType != BSPROXY_DEVTYPE_NONE )
01265     {
01266       ProxDevClose(pClient->m_tblClientDev[i].m_pProxDev);
01267     }
01268   }
01269 
01270   SocketClose(pClient->m_pClientSock);
01271   SocketDelete(pClient->m_pClientSock);
01272 
01273   delete(pClient);
01274 }

int ClientDispatch BsProxyServer_T pServer,
BsProxyClient_T pClient,
byte_t  bufCmd[],
size_t  lenCmd
 

Client top-level command dispatcher.

Command Format:
cmdhdr
cmdhdr body
Response Format:
rsphdr
rsphdr body
rsphdr errmsg
Parameters:
pServer BotSense server.
pClient BotSense client.
bufCmd Received command buffer.
lenCmd Received command length (number of bytes).
Returns:
Returns OK on success, RC_ERROR on failure.

Definition at line 1048 of file client.c.

References BSPROXY_CMD_HDR_BLEN_IDX, BSPROXY_CMD_HDR_LEN, BSPROXY_CMD_HDR_MSGID_IDX, BSPROXY_MSGID_DEV_CLOSE, BSPROXY_MSGID_DEV_CMD, BSPROXY_MSGID_DEV_IOCTL, BSPROXY_MSGID_DEV_OPEN, BSPROXY_MSGID_DEV_READ, BSPROXY_MSGID_DEV_SCAN, BSPROXY_MSGID_DEV_TRANS, BSPROXY_MSGID_DEV_WRITE, BSPROXY_MSGID_LOG, BSPROXY_MSGID_LOOPBACK, BSPROXY_MSGID_PROXY_INFO, BSPROXY_MSGID_VERSION, ClientSendFailRsp(), ClientSendHdrError(), CmdDevClose(), CmdDevCmd(), CmdDevIoctl(), CmdDevOpen(), CmdDevRead(), CmdDevScan(), CmdDevTrans(), CmdDevWrite(), CmdLog(), CmdLoopback(), CmdProxyInfo(), CmdVersion(), and BsProxyClient_T::m_sClientName.

Referenced by Server().

01051 {
01052   //
01053   // Validate command header.
01054   //
01055   if( lenCmd < BSPROXY_CMD_HDR_LEN )
01056   {
01057     return ClientSendHdrError(pClient, bufCmd, lenCmd);
01058   }
01059 
01060   //
01061   // Validate length of message body in header matches recieved command length.
01062   //
01063   // Note: For now, report error. But in the future, if recieved a partial
01064   // message (hdr+blen > len), try to read more bytes. If too many bytes,
01065   // flush??
01066   //
01067   if( (size_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX]+BSPROXY_CMD_HDR_LEN != lenCmd )
01068   {
01069     LOGERROR("%s: received %u bytes, but blen header field value is %u",
01070         pClient->m_sClientName, (uint_t)lenCmd,
01071         (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX]);
01072     return ClientSendFailRsp(pClient, bufCmd,
01073         "received %u bytes, but blen header field value is %u",
01074         (uint_t)lenCmd, (uint_t)bufCmd[BSPROXY_CMD_HDR_BLEN_IDX]);
01075   }
01076 
01077   //
01078   // Dispatch client command.
01079   //
01080   switch( bufCmd[BSPROXY_CMD_HDR_MSGID_IDX] )
01081   {
01082     // loopback client's message
01083     case BSPROXY_MSGID_LOOPBACK:
01084       return CmdLoopback(pServer, pClient, bufCmd, lenCmd);
01085 
01086     // set server's log level
01087     case BSPROXY_MSGID_LOG:
01088       return CmdLog(pServer, pClient, bufCmd, lenCmd);
01089 
01090     // get server's version
01091     case BSPROXY_MSGID_VERSION:
01092       return CmdVersion(pServer, pClient, bufCmd, lenCmd);
01093 
01094     // open proxied device for client
01095     case BSPROXY_MSGID_DEV_OPEN:
01096       return CmdDevOpen(pServer, pClient, bufCmd, lenCmd);
01097 
01098     // close proxied device for client
01099     case BSPROXY_MSGID_DEV_CLOSE:
01100       return CmdDevClose(pServer, pClient, bufCmd, lenCmd);
01101 
01102     // get supported proxied devices
01103     case BSPROXY_MSGID_PROXY_INFO:
01104       return CmdProxyInfo(pServer, pClient, bufCmd, lenCmd);
01105 
01106     // read from proxied device
01107     case BSPROXY_MSGID_DEV_READ:
01108       return CmdDevRead(pServer, pClient, bufCmd, lenCmd);
01109 
01110     // write to proxied device
01111     case BSPROXY_MSGID_DEV_WRITE:
01112       return CmdDevWrite(pServer, pClient, bufCmd, lenCmd);
01113 
01114     // perform a write/read transaction with proxied device
01115     case BSPROXY_MSGID_DEV_TRANS:
01116       return CmdDevTrans(pServer, pClient, bufCmd, lenCmd);
01117 
01118     // issue an ioctl to proxied device
01119     case BSPROXY_MSGID_DEV_IOCTL:
01120       return CmdDevIoctl(pServer, pClient, bufCmd, lenCmd);
01121 
01122     // scan for attached devices on proxied device
01123     case BSPROXY_MSGID_DEV_SCAN:
01124       return CmdDevScan(pServer, pClient, bufCmd, lenCmd);
01125 
01126     // send a specific command to a client's proxied device
01127     case BSPROXY_MSGID_DEV_CMD:
01128       return CmdDevCmd(pServer, pClient, bufCmd, lenCmd);
01129 
01130     default:
01131       LOGERROR("%s: 0x%02x: unknown command",
01132           pClient->m_sClientName, bufCmd[BSPROXY_CMD_HDR_MSGID_IDX]);
01133       return RC_ERROR;
01134   }
01135 
01136   LOGERROR("%s: here?", pClient->m_sClientName);
01137 
01138   return RC_ERROR;
01139 }

BsProxyClient_T* ClientNew Socket_T *  pSockClient  ) 
 

Create new client control structure.

Parameters:
pSockClient Accecpted client socket.
Returns:
Returns a newly allocated and intialized client control block.

Definition at line 1229 of file client.c.

References BSPROXY_CLIENT_DEV_MAX, BSPROXY_DEVTYPE_NONE, BsProxyClientDev_T::m_eDevType, BsProxyClientDev_T::m_i2cAddr, BsProxyClient_T::m_pClientSock, BsProxyClientDev_T::m_pProxDev, BsProxyClient_T::m_sClientName, and BsProxyClient_T::m_tblClientDev.

Referenced by BsProxyClientRegister().

01230 {
01231   BsProxyClient_T  *pClient;
01232   int               i;
01233 
01234   pClient                     = NEW(BsProxyClient_T);
01235   pClient->m_sClientName      = SocketAttrGetRemoteName(pSockClient);
01236   pClient->m_pClientSock      = pSockClient;
01237 
01238   for(i=0; i<BSPROXY_CLIENT_DEV_MAX; ++i)
01239   {
01240     pClient->m_tblClientDev[i].m_eDevType = BSPROXY_DEVTYPE_NONE;
01241     pClient->m_tblClientDev[i].m_pProxDev = NULL;
01242     pClient->m_tblClientDev[i].m_i2cAddr  = 0;
01243   }
01244 
01245   return pClient;
01246 }

int ClientSendFailRsp BsProxyClient_T pClient,
byte_t  bufCmd[],
const char *  sErrFmt,
  ...
 

Send fail response to the client.

Parameters:
pClient BotSense client.
bufCmd Received command buffer.
sErrFmt Error format string.
... Variable arguments to format string.
Returns:
Returns RC_ERROR.

Definition at line 1178 of file client.c.

References BSPROXY_CMD_HDR_MSGID_IDX, BSPROXY_CMD_HDR_TID_IDX, BSPROXY_MSG_MAX_LEN, BSPROXY_RSP_FAIL, BSPROXY_RSP_HDR_BLEN_IDX, BSPROXY_RSP_HDR_LEN, BSPROXY_RSP_HDR_MSGID_IDX, BSPROXY_RSP_HDR_PF_IDX, BSPROXY_RSP_HDR_TID_IDX, and BsProxyClient_T::m_pClientSock.

Referenced by BPFootCmdGetCooked(), BPFootCmdGetIds(), BPFootCmdGetRaw(), BPFootCmdSetCal(), BPFootDispatch(), BPIMUCmdGetCooked(), BPIMUCmdGetIds(), BPIMUCmdGetRaw(), BPIMUCmdSetCal(), BPIMUCmdSetOrientation(), BPIMUDispatch(), ClientDispatch(), ClientGetHandle(), ClientSendHdrError(), CmdDevCmd(), CmdDevIoctl(), CmdDevOpen(), CmdDevRead(), CmdDevScan(), CmdDevTrans(), CmdDevWrite(), and RCB3Dispatch().

01180 {
01181   byte_t    bufRsp[BSPROXY_MSG_MAX_LEN];
01182   size_t    lenBody, lenRsp;
01183   va_list   ap;
01184   char     *sBody;
01185 
01186   // stuff response header
01187   bufRsp[BSPROXY_RSP_HDR_MSGID_IDX] = bufCmd[BSPROXY_CMD_HDR_MSGID_IDX];
01188   bufRsp[BSPROXY_RSP_HDR_TID_IDX]   = bufCmd[BSPROXY_CMD_HDR_TID_IDX];
01189   bufRsp[BSPROXY_RSP_HDR_PF_IDX]    = BSPROXY_RSP_FAIL;
01190 
01191   sBody = (char *)(bufRsp+BSPROXY_RSP_HDR_LEN);
01192 
01193   //
01194   // Fill in formatted error string as the response message body.
01195   //
01196   va_start(ap, sErrFmt);
01197  
01198   vsnprintf(sBody, (size_t)(sizeof(bufRsp)-BSPROXY_RSP_HDR_LEN), sErrFmt, ap);
01199 
01200   va_end(ap);
01201 
01202   // guarantee string is null-terminated
01203   bufRsp[sizeof(bufRsp)-1] = 0;
01204 
01205   lenBody = strlen(sBody);
01206 
01207   // include null
01208   sBody[lenBody++] = 0;
01209 
01210   // body length
01211   bufRsp[BSPROXY_RSP_HDR_BLEN_IDX] = (byte_t)lenBody;
01212 
01213   // total response message length
01214   lenRsp = BSPROXY_RSP_HDR_LEN + lenBody;
01215 
01216   // send
01217   write(SocketAttrGetSd(pClient->m_pClientSock), bufRsp, lenRsp);
01218 
01219   return RC_ERROR;
01220 }

int ClientSendPassRsp BsProxyClient_T pClient,
byte_t  bufCmd[],
byte_t  bufRsp[],
size_t  lenRsp
 

Send pass response to the client.

Parameters:
pClient BotSense client.
bufCmd Received command buffer.
bufRsp Response buffer.
lenRsp Response buffer length (number of bytes).
Returns:
Returns OK on success, RC_ERROR on failure.

Definition at line 1151 of file client.c.

References BSPROXY_CMD_HDR_MSGID_IDX, BSPROXY_CMD_HDR_TID_IDX, BSPROXY_RSP_HDR_BLEN_IDX, BSPROXY_RSP_HDR_LEN, BSPROXY_RSP_HDR_MSGID_IDX, BSPROXY_RSP_HDR_PF_IDX, BSPROXY_RSP_HDR_TID_IDX, BSPROXY_RSP_PASS, and BsProxyClient_T::m_pClientSock.

Referenced by BPFootCmdGetIds(), BPFootCmdSetCal(), BPIMUCmdGetIds(), BPIMUCmdSetCal(), BPIMUCmdSetOrientation(), CmdDevClose(), CmdDevOpen(), CmdDevRead(), CmdDevTrans(), CmdDevWrite(), CmdLog(), CmdLoopback(), CmdProxyInfo(), CmdVersion(), RCB3CmdMoveServo(), RCB3CmdPlay(), and RCB3CmdStop().

01153 {
01154   ssize_t n;
01155 
01156   // response header
01157   bufRsp[BSPROXY_RSP_HDR_MSGID_IDX] = bufCmd[BSPROXY_CMD_HDR_MSGID_IDX];
01158   bufRsp[BSPROXY_RSP_HDR_TID_IDX]   = bufCmd[BSPROXY_CMD_HDR_TID_IDX];
01159   bufRsp[BSPROXY_RSP_HDR_PF_IDX]    = BSPROXY_RSP_PASS;
01160   bufRsp[BSPROXY_RSP_HDR_BLEN_IDX]  = (byte_t)(lenRsp-BSPROXY_RSP_HDR_LEN);
01161 
01162   // send
01163   n = write(SocketAttrGetSd(pClient->m_pClientSock), bufRsp, lenRsp);
01164 
01165   return n < (ssize_t)lenRsp? RC_ERROR: OK;
01166 }

void ProxDevClose BsProxyDev_T pProxDev  ) 
 

Close a proxied device.

Since an actual device can be shared between multiple client devices and between several clients, the device is closed only on when its reference count is zero.

Parameters:
pProxDev Proxied device.

Definition at line 260 of file proxdev.c.

References BSPROXY_DEVCLASS_I2C, BSPROXY_DEVCLASS_RCB3, BSPROXY_DEVCLASS_SER, BsProxyDev_T::i2c, BsProxyDev_T::m_eDevClass, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_nDevRefCnt, BsProxyDevRCB3_T::m_nHandle, BsProxyDev_T::m_sDevName, BsProxyDev_T::m_unDevSpec, ProxDevFind(), ProxDevTbl, and BsProxyDev_T::rcb3.

Referenced by ClientDelete(), and CmdDevClose().

00261 {
00262   int           iSlot;
00263   i2c_t         i2c;
00264 
00265   if( pProxDev == NULL )
00266   {
00267     return;
00268   } 
00269 
00270   //
00271   // Device is found
00272   //
00273   if( (iSlot = ProxDevFind(pProxDev->m_sDevName)) >= 0 )
00274   {
00275     if( pProxDev != ProxDevTbl[iSlot] )
00276     {
00277       LOGERROR("%p != %p: client data corruption", pProxDev, ProxDevTbl[iSlot]);
00278       return;
00279     }
00280 
00281     pProxDev->m_nDevRefCnt--;
00282 
00283     //
00284     // No client is using this device, so close.
00285     //
00286     if( pProxDev->m_nDevRefCnt <= 0 )
00287     {
00288       switch( pProxDev->m_eDevClass )
00289       {
00290         case BSPROXY_DEVCLASS_I2C:
00291           i2c.fd = pProxDev->m_unDevSpec.i2c.m_fd;
00292           i2c_close(&i2c);
00293           pProxDev->m_unDevSpec.i2c.m_fd = -1;
00294           break;
00295 
00296         case BSPROXY_DEVCLASS_RCB3:
00297           RCB3DestroyInterface(pProxDev->m_unDevSpec.rcb3.m_nHandle);
00298           break;
00299 
00300         case BSPROXY_DEVCLASS_SER:
00301           LOGERROR("%s: %d: device class not supported yet",
00302               pProxDev->m_sDevName, pProxDev->m_eDevClass);
00303           break;
00304 
00305         default:
00306           LOGERROR("%s: %d: unknown proxied device class.",
00307               pProxDev->m_sDevName, pProxDev->m_eDevClass);
00308           break;
00309       }
00310 
00311       LOGDIAG2("Closed proxied device %s", pProxDev->m_sDevName);
00312 
00313       delete((char *)pProxDev->m_sDevName);
00314       pthread_mutex_destroy(&pProxDev->m_mutDev);
00315       delete(pProxDev);
00316       
00317       ProxDevTbl[iSlot] = NULL;
00318     }
00319 
00320     //
00321     // Device is still in use, so release
00322     //
00323     else
00324     {
00325       LOGDIAG2("Released proxied device %s, refcnt=%d",
00326           pProxDev->m_sDevName, pProxDev->m_nDevRefCnt);
00327     }
00328   }
00329 
00330   else
00331   {
00332     LOGERROR("%s: cannot find device in table", pProxDev->m_sDevName);
00333   }
00334 }

int ProxDevI2CRead BsProxyDev_T pProxDev,
uint_t  i2cAddr,
byte_t  bufRead[],
size_t  countRead
 

Read bytes from an I2C device.

Parameters:
pProxDev Proxied device.
i2cAddr I2C address.
[out] bufRead Read buffer.
countRead Number of bytes to read from device to read buffer.
Returns:
Returns number of bytes read on success, <=0 on error.

Definition at line 212 of file proxdev_i2c.c.

References BsProxyDev_T::i2c, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_sDevName, and BsProxyDev_T::m_unDevSpec.

Referenced by CmdDevRead().

00214 {
00215   i2c_t     i2c;
00216   int       n;
00217 
00218   pthread_mutex_lock(&pProxDev->m_mutDev);
00219   
00220   i2c.fd  = pProxDev->m_unDevSpec.i2c.m_fd;
00221   i2c.dev = 0;
00222 
00223   n = i2c_llread(&i2c, i2cAddr, (char *)bufRead, (uint_t)countRead);
00224 
00225   if( n <= 0 )
00226   {
00227     LOGSYSERROR("%s: i2c_llread(0x%02x...)", pProxDev->m_sDevName, i2cAddr);
00228   }
00229 
00230   pthread_mutex_unlock(&pProxDev->m_mutDev);
00231 
00232   return n;
00233 }

int ProxDevI2CScan BsProxyDev_T pProxDev,
byte_t  bufScan[],
size_t  sizeBuf
 

Scan I2C Bus for attached address.

The addresses of all discovered devices are returned.

Parameters:
pProxDev Proxied device.
[out] bufScan Vector of addresses of discovered devices from scan.
sizeBuf Size of scan buffer.
Returns:
Returns number of discovered devices.

Definition at line 107 of file proxdev_i2c.c.

References cb_i2c_scan(), BsProxyDev_T::i2c, i2c_scanned_cnt, i2c_scanned_dev, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, and BsProxyDev_T::m_unDevSpec.

Referenced by CmdDevScan().

00108 {
00109   i2c_t     i2c;
00110   int       n;
00111 
00112   pthread_mutex_lock(&pProxDev->m_mutDev);
00113   
00114   i2c.fd  = pProxDev->m_unDevSpec.i2c.m_fd;
00115   i2c.dev = 0;
00116 
00117   i2c_scanned_cnt = 0;
00118 
00119   i2c_scan(&i2c, cb_i2c_scan, NULL);
00120 
00121   for(n=0; n<i2c_scanned_cnt && n<sizeBuf; ++n)
00122   {
00123     bufScan[n] = i2c_scanned_dev[n];
00124   }
00125 
00126   pthread_mutex_unlock(&pProxDev->m_mutDev);
00127 
00128   return n;
00129 }

int ProxDevI2CTrans BsProxyDev_T pProxDev,
uint_t  i2cAddr,
byte_t  bufWrite[],
size_t  countWrite,
byte_t  bufRead[],
size_t  countRead
 

Perform a write/read transaction between an I2C device.

Parameters:
pProxDev Proxied device.
i2cAddr I2C address.
bufWrite Write buffer.
countWrite Number of bytes to write from write buffer to device.
[out] bufRead Read buffer.
countRead Number of bytes to read from device to read buffer.
Returns:
Returns number of bytes read on success, <=0 on error.

Definition at line 143 of file proxdev_i2c.c.

References BsProxyDev_T::i2c, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_sDevName, and BsProxyDev_T::m_unDevSpec.

Referenced by BPFootCmdGetCooked(), BPFootCmdGetIds(), BPFootCmdGetRaw(), BPIMUCmdGetCooked(), BPIMUCmdGetIds(), BPIMUCmdGetRaw(), and CmdDevTrans().

00146 {
00147   i2c_t     i2c;
00148   int       n;
00149 
00150   pthread_mutex_lock(&pProxDev->m_mutDev);
00151   
00152   i2c.fd  = pProxDev->m_unDevSpec.i2c.m_fd;
00153   i2c.dev = i2cAddr;
00154 
00155   n = i2c_lltransfer(&i2c, i2cAddr,
00156                      (char *)bufWrite, (uint_t)countWrite,
00157                      (char *)bufRead, (uint_t)countRead);
00158 
00159   if( n <= 0 )
00160   {
00161     LOGSYSERROR("%s: i2c_lltransfer(0x%02x...)", pProxDev->m_sDevName, i2cAddr);
00162   }
00163 
00164   pthread_mutex_unlock(&pProxDev->m_mutDev);
00165 
00166   return n;
00167 }

int ProxDevI2CWrite BsProxyDev_T pProxDev,
uint_t  i2cAddr,
byte_t  bufWrite[],
size_t  countWrite
 

Write buffer to an I2C device.

Parameters:
pProxDev Proxied device.
i2cAddr I2C address.
bufWrite Write buffer.
countWrite Number of bytes to write from write buffer to device.
Returns:
Returns number of bytes written on success, <=0 on error.

Definition at line 179 of file proxdev_i2c.c.

References BsProxyDev_T::i2c, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_sDevName, and BsProxyDev_T::m_unDevSpec.

Referenced by BPFootCmdSetCal(), BPIMUCmdSetCal(), BPIMUCmdSetOrientation(), and CmdDevWrite().

00181 {
00182   i2c_t     i2c;
00183   int       n;
00184 
00185   pthread_mutex_lock(&pProxDev->m_mutDev);
00186   
00187   i2c.fd  = pProxDev->m_unDevSpec.i2c.m_fd;
00188   i2c.dev = 0;
00189 
00190   n = i2c_llwrite(&i2c, i2cAddr, (char *)bufWrite, (uint_t)countWrite);
00191 
00192   if( n <= 0 )
00193   {
00194     LOGSYSERROR("%s: i2c_llwrite(0x%02x...)", pProxDev->m_sDevName, i2cAddr);
00195   }
00196 
00197   pthread_mutex_unlock(&pProxDev->m_mutDev);
00198 
00199   return n;
00200 }

BsProxyDev_T* ProxDevOpen int  eDevType,
const char *  sDevName
 

Open a proxied device.

Since an actual device can be shared between multiple client devices and between several clients, the device is opened only on the first call. Otherwise its reference count is incremented.

The device name serves as the unique key for the proxied device identification.

Parameters:
eDevType Supported proxied device type.
sDevName Actual device name.
Returns:
Returns pointer to proxied device on success, NULL on failure.

Definition at line 140 of file proxdev.c.

References BSPROXY_DEVCLASS_I2C, BSPROXY_DEVCLASS_RCB3, BSPROXY_DEVCLASS_SER, BSPROXY_DEVTYPE_BPCOMPASS, BSPROXY_DEVTYPE_BPFOOT, BSPROXY_DEVTYPE_BPHAND, BSPROXY_DEVTYPE_BPIMU, BSPROXY_DEVTYPE_I2C, BSPROXY_DEVTYPE_RCB3, BSPROXY_DEVTYPE_RS232, BsProxyDev_T::i2c, BsProxyDev_T::m_eDevClass, BsProxyDevI2C_T::m_fd, BsProxyDev_T::m_mutDev, BsProxyDev_T::m_nDevRefCnt, BsProxyDevRCB3_T::m_nHandle, BsProxyDev_T::m_sDevName, BsProxyDev_T::m_unDevSpec, PROX_DEV_MAX, ProxDevFind(), ProxDevFindEmptySlot(), ProxDevTbl, and BsProxyDev_T::rcb3.

Referenced by CmdDevOpen().

00141 {
00142   uint_t        eDevClass;
00143   int           iSlot;
00144   BsProxyDev_T *pProxDev;
00145   i2c_t         i2c;
00146   handle_t      nHandle;
00147 
00148   //
00149   // map device type into device class
00150   //
00151   switch( eDevType )
00152   {
00153     case BSPROXY_DEVTYPE_I2C:
00154     case BSPROXY_DEVTYPE_BPFOOT:
00155     case BSPROXY_DEVTYPE_BPIMU:
00156     case BSPROXY_DEVTYPE_BPHAND:
00157     case BSPROXY_DEVTYPE_BPCOMPASS:
00158       eDevClass = BSPROXY_DEVCLASS_I2C;
00159       break;
00160     case BSPROXY_DEVTYPE_RS232:
00161       eDevClass = BSPROXY_DEVCLASS_SER;
00162       break;
00163     case BSPROXY_DEVTYPE_RCB3:
00164       eDevClass = BSPROXY_DEVCLASS_RCB3;
00165       break;
00166     default:
00167       LOGERROR("0x%02x: unknown proxied device type.", eDevType);
00168       return NULL;
00169   }
00170 
00171   //
00172   // Device already open
00173   //
00174   if( (iSlot = ProxDevFind(sDevName)) >= 0 )
00175   {
00176     pProxDev = ProxDevTbl[iSlot];
00177     if( pProxDev->m_eDevClass != eDevClass )
00178     {
00179       LOGERROR("%s: %d <--> %d: conflicting device classes",
00180           sDevName, pProxDev->m_eDevClass, eDevClass);
00181       return NULL;
00182     }
00183     pProxDev->m_nDevRefCnt++;
00184 
00185     LOGDIAG2("Attached to proxied device %s, refcnt=%d",
00186           pProxDev->m_sDevName, pProxDev->m_nDevRefCnt);
00187 
00188     return pProxDev;
00189   }
00190 
00191   //
00192   // New proxied device.
00193   //
00194   else if( (iSlot = ProxDevFindEmptySlot()) >= 0 )
00195   {
00196     switch( eDevClass )
00197     {
00198       case BSPROXY_DEVCLASS_I2C:
00199         if( i2c_open(&i2c, sDevName) < 0 )
00200         {
00201           LOGSYSERROR("%s", sDevName);
00202           return NULL;
00203         }
00204         pProxDev = NEW(BsProxyDev_T);
00205         pProxDev->m_unDevSpec.i2c.m_fd = i2c.fd;
00206         break;
00207 
00208       case BSPROXY_DEVCLASS_RCB3:
00209         nHandle = RCB3CreateInterface(sDevName, 115200, 0, NULL, false);
00210         if( nHandle < 0 )
00211         {
00212           LOGERROR("%s: failed to open", sDevName);
00213           return NULL;
00214         }
00215         pProxDev = NEW(BsProxyDev_T);
00216         pProxDev->m_unDevSpec.rcb3.m_nHandle = nHandle;
00217         break;
00218 
00219       case BSPROXY_DEVCLASS_SER:
00220         LOGERROR("%s: %d: device class not supported yet", sDevName, eDevClass);
00221         return NULL;
00222 
00223       default:
00224         LOGERROR("%d: unknown proxied device class.", eDevClass);
00225         return NULL;
00226     }
00227 
00228     pProxDev->m_sDevName    = new_strdup(sDevName);
00229     pProxDev->m_eDevClass   = eDevClass;
00230     pProxDev->m_nDevRefCnt  = 1;
00231 
00232     pthread_mutex_init(&pProxDev->m_mutDev, NULL);
00233 
00234     ProxDevTbl[iSlot] = pProxDev;
00235 
00236     LOGDIAG2("Opened proxied device %s", pProxDev->m_sDevName);
00237 
00238     return pProxDev;
00239   }
00240 
00241   //
00242   // No available resources
00243   else
00244   {
00245     LOGERROR("%s: %s: cannot open device, currently at server maximum of %d",
00246           LOGFUNCNAME, sDevName, PROX_DEV_MAX);
00247     return NULL;
00248   }
00249 }

int ProxDevRCB3Read BsProxyDev_T pProxDev,
byte_t  bufRead[],
size_t  countRead
 

Read bytes from an RCB-3 controller device.

Parameters:
pProxDev Proxied device.
[out] bufRead Read buffer.
countRead Number of bytes to read from device to read buffer.
Returns:
Returns number of bytes read on success, <=0 on error.

Definition at line 377 of file rcb3.c.

References BsProxyDevRCB3_T::m_nHandle, BsProxyDev_T::m_sDevName, BsProxyDev_T::m_unDevSpec, and BsProxyDev_T::rcb3.

Referenced by CmdDevRead().

00378 {
00379   int   n;
00380 
00381   n = RCB3Receive(pProxDev->m_unDevSpec.rcb3.m_nHandle, bufRead, countRead);
00382 
00383   if( n <= 0 )
00384   {
00385     LOGSYSERROR("%s: RCB3Receive(%d...): %s",
00386                 pProxDev->m_sDevName, 
00387                 pProxDev->m_unDevSpec.rcb3.m_nHandle,
00388                 RCB3ErrorGetMsg());
00389   }
00390 
00391   return n;
00392 }

int ProxDevRCB3Trans BsProxyDev_T pProxDev,
byte_t  bufWrite[],
size_t  countWrite,
byte_t  bufRead[],
size_t  countRead
 

Do a write/read transaction with an RCB-3 controller device.

Parameters:
pProxDev Proxied device.
bufWrite Write buffer.
countWrite Number of bytes to write to the device.
[out] bufRead Read buffer.
countRead Number of bytes to read from device to read buffer.
Returns:
Returns number of bytes read on success, <=0 on error.

Definition at line 434 of file rcb3.c.

References BsProxyDevRCB3_T::m_nHandle, BsProxyDev_T::m_sDevName, BsProxyDev_T::m_unDevSpec, and BsProxyDev_T::rcb3.

Referenced by CmdDevTrans().

00437 {
00438   int   rc;
00439 
00440   if( countRead == 0 )
00441   {
00442     rc = RCB3SendCmd(pProxDev->m_unDevSpec.rcb3.m_nHandle,
00443                             bufWrite, countWrite);
00444   }
00445   else if( countRead == 1 )
00446   {
00447     rc = RCB3AckTransaction(pProxDev->m_unDevSpec.rcb3.m_nHandle,
00448                             bufWrite, countWrite);
00449   }
00450   else
00451   {
00452     rc = RCB3DataTransaction(pProxDev->m_unDevSpec.rcb3.m_nHandle,
00453                             bufWrite, countWrite,
00454                             bufRead, countRead);
00455   }
00456 
00457   if( rc <= 0 )
00458   {
00459     LOGSYSERROR("%s: RCB3xTransaction(%d...): %s",
00460                 pProxDev->m_sDevName, 
00461                 pProxDev->m_unDevSpec.rcb3.m_nHandle,
00462                 RCB3ErrorGetMsg());
00463 
00464     return -1;
00465   }
00466 
00467   if( countRead == 1 )
00468   {
00469     bufRead[0] = RCB3RspIdAck;
00470   }
00471 
00472   return (int)countRead;
00473 }

int ProxDevRCB3Write BsProxyDev_T pProxDev,
byte_t  bufWrite[],
size_t  countWrite
 

Write bytes to an RCB-3 controller device.

Parameters:
pProxDev Proxied device.
bufWrite Write buffer.
countWrite Number of bytes to write to the device.
Returns:
Returns number of written on success, <=0 on error.

Definition at line 403 of file rcb3.c.

References BsProxyDevRCB3_T::m_nHandle, BsProxyDev_T::m_sDevName, BsProxyDev_T::m_unDevSpec, and BsProxyDev_T::rcb3.

Referenced by CmdDevWrite().

00405 {
00406   int   rc;
00407 
00408   rc = RCB3SendCmd(pProxDev->m_unDevSpec.rcb3.m_nHandle, bufWrite, countWrite);
00409 
00410   if( rc <= 0 )
00411   {
00412     LOGSYSERROR("%s: RCB3SendCmd(%d...): %s",
00413                 pProxDev->m_sDevName, 
00414                 pProxDev->m_unDevSpec.rcb3.m_nHandle,
00415                 RCB3ErrorGetMsg());
00416 
00417     return -1;
00418   }
00419 
00420   return (int)countWrite;
00421 }

int RCB3Dispatch BsProxyServer_T pServer,
BsProxyClient_T pClient,
BsProxyClientDev_T pDev,
byte_t  bufCmd[],
size_t  lenCmd
 

RCB-3 Robot Controller command dispatcher.

Parameters:
pServer BotSense server.
pClient BotSense client.
pDev Client device.
bufCmd Received command buffer.
lenCmd Received command length (number of bytes).
Returns:
Returns OK on success, RC_ERROR on failure.

Definition at line 324 of file rcb3.c.

References BSPROXY_CMD_HDR_LEN, ClientSendFailRsp(), BsProxyClient_T::m_sClientName, RCB3CmdGetCurPos(), RCB3CmdGetVersion(), RCB3CmdMoveServo(), RCB3CmdPlay(), and RCB3CmdStop().

Referenced by CmdDevCmd().

00328 {
00329   byte_t  byDevCmdId;
00330 
00331   byDevCmdId = bufCmd[BSPROXY_CMD_HDR_LEN+1];
00332 
00333   //
00334   // Dispatch RCB-3 command.
00335   //
00336   switch( byDevCmdId )
00337   {
00338     // get device identifiers
00339     case RCB3CmdIdGetVersion:
00340       return RCB3CmdGetVersion(pServer, pClient, pDev, bufCmd, lenCmd);
00341 
00342     // get servos' current positions
00343     case RCB3CmdIdGetCurPos:
00344       return RCB3CmdGetCurPos(pServer, pClient, pDev, bufCmd, lenCmd);
00345 
00346     // move one servo
00347     case RCB3CmdIdMoveServo:
00348       return RCB3CmdMoveServo(pServer, pClient, pDev, bufCmd, lenCmd);
00349 
00350     // playback a motion or scenario
00351     case RCB3CmdIdPlay:
00352       return RCB3CmdPlay(pServer, pClient, pDev, bufCmd, lenCmd);
00353 
00354     // move one servo
00355     case RCB3CmdIdStop:
00356       return RCB3CmdStop(pServer, pClient, pDev, bufCmd, lenCmd);
00357 
00358     default:
00359       LOGERROR("%s: BrainPack Foot: 0x%02x: unsupported device command",
00360           pClient->m_sClientName, byDevCmdId);
00361       return ClientSendFailRsp(pClient, bufCmd, "bad device command");
00362   }
00363 
00364   LOGERROR("%s: BrainPack Foot: here?", pClient->m_sClientName);
00365   return ClientSendFailRsp(pClient, bufCmd, "bad message");
00366 }


Generated on Wed Nov 28 11:01:08 2007 for botsense by doxygen 1.4.6