Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdChainIn Class Referenceabstract

Dynamixel chain input command abstract base class. More...

#include <dynashell_cmd.h>

Inheritance diagram for DynaShellCmdChainIn:
DynaShellCmd DynaShellCmdClearAlarms DynaShellCmdDump DynaShellCmdGetOdometer DynaShellCmdGetPid DynaShellCmdGetSoftTorqueTh DynaShellCmdReadCurPos DynaShellCmdReadCurSpeed DynaShellCmdReadDynamics DynaShellCmdReadGoalPos DynaShellCmdReadGoalSpeed DynaShellCmdReadHealth DynaShellCmdReadIsMoving DynaShellCmdReadTorqueEnable DynaShellCmdStop

Public Member Functions

 DynaShellCmdChainIn (bool bMasterOpOnly=false)
 Default constructor.
 
virtual ~DynaShellCmdChainIn ()
 Default destructor.
 
virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute 'read-like' 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, DynaServo *pServo)=0
 Derived class specific execution function. 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

bool m_bMasterOpOnly
 is [not] a master-only supported operation
 
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

Dynamixel chain input command abstract base class.

This class supports parsing a list of (master) servos as arguments to a derived command class executinng servo 'read-like' input operations. Input operations include read and get.

Syntax:
* CMD args
* args ::=
*      'chain'
*    | servo_list
*  servo_list ::=
*      servo_id
*    | servo_list servo_id
*  servo_id ::= INT
* 

Definition at line 576 of file dynashell_cmd.h.

Member Function Documentation

virtual void DynaShellCmdChainIn::doExec ( DynaShell shell,
DynaServo pServo 
)
protectedpure virtual
void DynaShellCmdChainIn::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
virtual

Execute 'read-like' command on servos.

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

Implements DynaShellCmd.

Definition at line 296 of file dynashell_cmd.cxx.

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

297 {
298  int nServoId;
299  int iter;
300  DynaServo *pServo;
301 
302  TRY( ChkArgCnt(shell, argc) );
303 
304  TRY( ChkComm(shell) );
305  TRY( ChkChainNotEmpty(shell) );
306 
307  if( !strcmp(argv[0], "chain") )
308  {
309  TRY( ChkArgCntEQ(shell, argc, 1) );
310 
311  if( m_bMasterOpOnly )
312  {
313  for(nServoId = shell.m_pDynaChain->IterStartMaster(&iter);
314  nServoId != DYNA_ID_NONE;
315  nServoId = shell.m_pDynaChain->IterNextMaster(&iter))
316  {
317  pServo = shell.m_pDynaChain->GetServo(nServoId);
318  doExec(shell, pServo);
319  }
320  }
321  else
322  {
323  for(nServoId = shell.m_pDynaChain->IterStart(&iter);
324  nServoId != DYNA_ID_NONE;
325  nServoId = shell.m_pDynaChain->IterNext(&iter))
326  {
327  pServo = shell.m_pDynaChain->GetServo(nServoId);
328  doExec(shell, pServo);
329  }
330  }
331  }
332 
333  else
334  {
335  for(iter=0; iter<argc; ++iter)
336  {
337  TRY( ToInt(shell, argv[iter], &nServoId) );
338  TRY( ChkChainHasServo(shell, nServoId) );
339  TRY( !m_bMasterOpOnly || ChkChainIsMasterServo(shell, nServoId) );
340 
341  pServo = shell.m_pDynaChain->GetServo(nServoId);
342  doExec(shell, pServo);
343  }
344  }
345 }
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.
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
bool ChkChainIsMasterServo(DynaShell &shell, int nServoId)
Check that the given servo is a master.
virtual int IterStartMaster(int *pIter)
Start iteration master servos over of entire servo chain.
Definition: DynaChain.cxx:1036
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
Definition: DynaChain.cxx:1058
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
bool m_bMasterOpOnly
is [not] a master-only supported operation
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
virtual DynaServo * GetServo(int nServoId)
Definition: DynaChain.h:129
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 void doExec(DynaShell &shell, DynaServo *pServo)=0
Derived class specific execution function.
char * DynaShellCmdChainIn::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
virtual

Command tab completion generator.

Completes <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 362 of file dynashell_cmd.cxx.

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

367 {
368  char buf[16];
369 
370  if( (shell.m_pDynaChain == NULL) ||
371  (shell.m_pDynaChain->GetNumberInChain() == 0) )
372  {
373  return NULL;
374  }
375 
377  {
378  return NULL;
379  }
380 
381  //
382  // New command to complete - initialize.
383  //
384  if( nState == ReadLine::FIRST )
385  {
386  if( m_bMasterOpOnly )
387  {
389  }
390  else
391  {
393  }
394 
395  if( ReadLine::wc(sContext) == ReadLine::wc(m_sPubName) )
396  {
397  m_bTabIncChain = true;
398  }
399  else
400  {
401  m_bTabIncChain = false;
402  }
403  }
404 
405  while( m_nTabServoId != DYNA_ID_NONE )
406  {
407  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
408  buf[sizeof(buf)-1] = 0;
409 
410  if( m_bMasterOpOnly )
411  {
413  }
414  else
415  {
417  }
418 
419  if( !strncmp(buf, sText, uTextLen) )
420  {
421  return ReadLine::dupstr(buf);
422  }
423  }
424 
425  if( m_bTabIncChain )
426  {
427  m_bTabIncChain = false;
428  if( !strncmp("chain", sText, uTextLen) )
429  {
430  return ReadLine::dupstr("chain");
431  }
432  }
433 
434  // no more matches
435  return NULL;
436 }
virtual uint_t GetNumberOfMastersInChain()
Get the number of servos currently in chain.
Definition: DynaChain.cxx:182
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
virtual int IterStartMaster(int *pIter)
Start iteration master servos over of entire servo chain.
Definition: DynaChain.cxx:1036
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
Definition: DynaChain.cxx:1058
virtual uint_t GetNumberInChain() const
Get the number of servos currently in chain.
Definition: DynaChain.h:140
int m_nTabIter
tab completion: servo id iterator
char * m_sPubName
command&#39;s published name
static int wc(const string &str)
Count the words in the string.
bool m_bMasterOpOnly
is [not] a master-only supported operation
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
int m_nTabServoId
tab completion: current servo id
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360
bool m_bTabIncChain
tab completion: [do not] include chain keyword

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