Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdReadByte Class Reference

Read servo byte value at address. More...

Inheritance diagram for DynaShellCmdReadByte:
DynaShellCmd DynaShellCmdReadWord

Public Member Functions

virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute read byte command on servos. More...
 
virtual char * TabCompletion (DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
 Command tab completion generator. More...
 
- Public Member Functions inherited from DynaShellCmd
 DynaShellCmd (int nArgCntMin=0, int nArgCntMax=0)
 Default constructor.
 
virtual ~DynaShellCmd ()
 Default destructor.
 
const char * GetCmdName ()
 Get dynamixel shell command name. More...
 
const char * GetCmdHelpBrief ()
 Get shell command name brief description. More...
 
virtual void PrintHelp (int indent=0, int width=80)
 Print command help with the description aligned at the given indentation. More...
 
int GetPublishedLevel () const
 
const char * GetPublishedName () const
 
int SetPublishedInfo (int nLevel, const char *sParent=NULL)
 
virtual bool ChkArgCnt (DynaShell &shell, int argc)
 Check that the argument count is within the class (min,max). More...
 
bool ChkArgCnt0 (DynaShell &shell, int argc)
 Check that the argument count is zero. More...
 
bool ChkArgCntEQ (DynaShell &shell, int argc, int eq)
 Check that the argument count is equal to the required. More...
 
bool ChkArgCntGE (DynaShell &shell, int argc, int min)
 Check argument count against minimum required. More...
 
bool ChkArgCntLE (DynaShell &shell, int argc, int max)
 Check argument count against maximum allowed. More...
 
bool ChkComm (DynaShell &shell)
 Check that Dynamixel communication exists and is open. More...
 
bool ChkChain (DynaShell &shell)
 Check that the servo chain exists. More...
 
bool ChkChainNotEmpty (DynaShell &shell)
 Check that the servo chain exists and is not empty. More...
 
bool ChkChainHasServo (DynaShell &shell, int nServoId)
 Check that the given servo is present in the chain. More...
 
bool ChkChainIsMasterServo (DynaShell &shell, int nServoId)
 Check that the given servo is a master. More...
 
bool ToInt (DynaShell &shell, const char *sArg, int *pVal)
 Convert command argument to integer. More...
 
bool ToUInt (DynaShell &shell, const char *sArg, uint_t *pVal)
 Convert command argument to unsigned integer. More...
 
bool ToDouble (DynaShell &shell, const char *sArg, double *pVal)
 Convert command argument to double. More...
 
bool ToBool (DynaShell &shell, const char *sArg, bool *pVal)
 Convert command argument to boolean. More...
 

Protected Member Functions

virtual void doExec (DynaShell &shell, int nServoId, uint_t uAddr)
 Read byte. More...
 
- Protected Member Functions inherited from DynaShellCmd
virtual void PrintSynopses (int indent, int width)
 Print synsopses. More...
 
virtual void PrintBlock (int col, int indent, int width, const char *sText)
 Print a block of indented text of width. More...
 
virtual void PrintDelim (int width, const char cDelim)
 
char * eow (const char *s)
 Find end of word. More...
 

Protected Attributes

int m_nTabIter
 tab completion: servo id iterator
 
int m_nTabServoId
 tab completion: current servo id
 
bool m_bTabIncChain
 tab completion: [do not] include chain keyword
 
- Protected Attributes inherited from DynaShellCmd
const char * m_sCmdName
 command name
 
const char * m_sCmdHelpBrief
 command help brief
 
const char * m_sCmdHelpArgs
 command help arguments
 
const char * m_sCmdHelpDesc
 command help description
 
const int m_nArgCntMin
 minimum argument count
 
const int m_nArgCntMax
 maximum argument count (0 if not max)
 
int m_nPubLevel
 command's published level (depth)
 
char * m_sPubName
 command's published name
 

Detailed Description

Read servo byte value at address.

Definition at line 2199 of file dynashell_cmd_servo.cxx.

Member Function Documentation

virtual void DynaShellCmdReadByte::doExec ( DynaShell shell,
int  nServoId,
uint_t  uAddr 
)
inlineprotectedvirtual

Read byte.

Parameters
shellDynamixel shell.
nServoIdServo id.
uAddrServo read address.

Reimplemented in DynaShellCmdReadWord.

Definition at line 2365 of file dynashell_cmd_servo.cxx.

References DYNA_OK, DynaShell::Error(), DynaShell::m_pDynaComm, DynaComm::Read8(), and DynaShell::Response().

2366  {
2367  uint_t uVal;
2368  int rc;
2369 
2370  rc = shell.m_pDynaComm->Read8(nServoId, uAddr, &uVal);
2371 
2372  if( rc != DYNA_OK )
2373  {
2374  shell.Error(rc, "Servo %d: Failed to read byte at 0x%02x.",
2375  nServoId, uAddr);
2376  return;
2377  }
2378 
2379  shell.Response("Servo %3d: 0x%02x.\n", nServoId, uVal);
2380  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
DynaComm * m_pDynaComm
dynamixel bus communication
Definition: dynashell.h:359
virtual int Read8(int nServoId, uint_t uAddr, byte_t *pVal)=0
Read an 8-bit value from Dynamixel servo control table.
void Response(const char *sFmt,...)
Print formatted success response.
Definition: dynashell.cxx:763
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
virtual void DynaShellCmdReadByte::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Execute read byte command on servos.

Parameters
shellDynamixel shell.
argcCommand argument count.
argvArray of arguments.

Implements DynaShellCmd.

Definition at line 2234 of file dynashell_cmd_servo.cxx.

References DYNA_ID_NONE, DynaChain::IterNext(), DynaChain::IterStart(), DynaShell::m_pDynaChain, and TRY.

2235  {
2236  uint_t uAddr;
2237  int nServoId;
2238  int iter;
2239 
2240  TRY( ChkArgCnt(shell, argc) );
2241  TRY( ChkComm(shell) );
2242  TRY( ChkChainNotEmpty(shell) );
2243 
2244  TRY( ToInt(shell, argv[0], (int *)&uAddr) );
2245 
2246  if( !strcmp(argv[1], "chain") )
2247  {
2248  TRY( ChkArgCntEQ(shell, argc, 2) );
2249 
2250  for(nServoId = shell.m_pDynaChain->IterStart(&iter);
2251  nServoId != DYNA_ID_NONE;
2252  nServoId = shell.m_pDynaChain->IterNext(&iter))
2253  {
2254  doExec(shell, nServoId, uAddr);
2255  }
2256  }
2257 
2258  else
2259  {
2260  for(iter=1; iter<argc; ++iter)
2261  {
2262  TRY( ToInt(shell, argv[iter], &nServoId) );
2263  TRY( ChkChainHasServo(shell, nServoId) );
2264 
2265  doExec(shell, nServoId, uAddr);
2266  }
2267  }
2268  }
bool ChkChainNotEmpty(DynaShell &shell)
Check that the servo chain exists and is not empty.
bool ChkArgCntEQ(DynaShell &shell, int argc, int eq)
Check that the argument count is equal to the required.
virtual void doExec(DynaShell &shell, int nServoId, uint_t uAddr)
Read byte.
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
virtual bool ChkArgCnt(DynaShell &shell, int argc)
Check that the argument count is within the class (min,max).
#define TRY(boolexpr,...)
Try boolean expression.
Definition: dynashell_cmd.h:89
bool ChkComm(DynaShell &shell)
Check that Dynamixel communication exists and is open.
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
Definition: DynaChain.cxx:1020
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360
virtual char* DynaShellCmdReadByte::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes NULL <servo_id> | chain [servo_id [servo_id ...]]

Parameters
shellDynamixel shell.
sTextPartial text string to complete.
uTextLenLength of text.
nStateGenerator state. If FIRST, then initialize any statics.
sContextGenerator context (i.e. canonical command path).
Returns
If a first/next match is made, return allocated completed match.
Otherwise return NULL.

Reimplemented from DynaShellCmd.

Definition at line 2285 of file dynashell_cmd_servo.cxx.

References ReadLine::dupstr(), DYNA_ID_NONE, ReadLine::FIRST, DynaChain::GetNumberInChain(), DynaChain::IterNext(), DynaChain::IterStart(), DynaShell::m_pDynaChain, and ReadLine::wc().

2290  {
2291  int nArgNum;
2292 
2293  char buf[16];
2294 
2295  if( (shell.m_pDynaChain == NULL) ||
2296  (shell.m_pDynaChain->GetNumberInChain() == 0) )
2297  {
2298  return NULL;
2299  }
2300 
2301  // argument number of already (expanded) arguments
2302  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
2303 
2304  // <addr> cannot complete adrress
2305  if( nArgNum == 0 )
2306  {
2307  return NULL;
2308  }
2309 
2310  //
2311  // New command to complete - initialize.
2312  //
2313  if( nState == ReadLine::FIRST )
2314  {
2316 
2317  if( nArgNum == 1 )
2318  {
2319  m_bTabIncChain = true;
2320  }
2321  else
2322  {
2323  m_bTabIncChain = false;
2324  }
2325  }
2326 
2327  while( m_nTabServoId != DYNA_ID_NONE )
2328  {
2329  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
2330  buf[sizeof(buf)-1] = 0;
2331 
2333 
2334  if( !strncmp(buf, sText, uTextLen) )
2335  {
2336  return ReadLine::dupstr(buf);
2337  }
2338  }
2339 
2340  if( m_bTabIncChain )
2341  {
2342  m_bTabIncChain = false;
2343  if( !strncmp("chain", sText, uTextLen) )
2344  {
2345  return ReadLine::dupstr("chain");
2346  }
2347  }
2348 
2349  // no more matches
2350  return NULL;
2351  }
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
virtual uint_t GetNumberInChain() const
Get the number of servos currently in chain.
Definition: DynaChain.h:140
char * m_sPubName
command&#39;s published name
static int wc(const string &str)
Count the words in the string.
int m_nTabServoId
tab completion: current servo id
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
Definition: DynaChain.cxx:1020
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360
int m_nTabIter
tab completion: servo id iterator
bool m_bTabIncChain
tab completion: [do not] include chain keyword

The documentation for this class was generated from the following file: