51 #include <sys/types.h> 60 #include "rnr/rnrconfig.h" 92 PrintDelim(width,
'-');
93 col = printf(
"%s - ", m_sPubName);
94 PrintBlock(col, indent, width, m_sCmdHelpBrief);
97 if( (m_sCmdHelpArgs != NULL) && (*m_sCmdHelpArgs != 0) )
100 PrintSynopses(indent, width);
105 if( (m_sCmdHelpDesc != NULL) && (*m_sCmdHelpDesc != 0) )
108 PrintBlock(0, indent, width, m_sCmdHelpDesc);
127 if( (m_sCmdHelpArgs != NULL) && (*m_sCmdHelpArgs != 0) )
129 for(s=m_sCmdHelpArgs, bFirst=
true, bLast=
false; !bLast; )
142 if( len >=
sizeof(buf) )
147 strncpy(buf, s, len);
152 col = printf(
"%*sUsage: %s ", indent,
"", m_sPubName);
157 col = printf(
"%*s %s ", indent,
"", m_sPubName);
160 PrintBlock(col, col, width, buf);
189 for(s=sText; *s != 0; )
211 col = printf(
"%*s", indent,
"");
217 col += printf(
"%.*s", n, s);
232 col = printf(
"%*s", indent,
"");
244 void DynaShellCmd::PrintDelim(
int width,
const char cDelim)
248 printf(
"%c", cDelim);
268 if( (s == NULL) || (*s == 0) )
273 for(t=(
char *)s; *t; ++t)
302 TRY( ChkArgCnt(shell, argc) );
304 TRY( ChkComm(shell) );
305 TRY( ChkChainNotEmpty(shell) );
307 if( !strcmp(argv[0],
"chain") )
309 TRY( ChkArgCntEQ(shell, argc, 1) );
311 if( m_bMasterOpOnly )
318 doExec(shell, pServo);
328 doExec(shell, pServo);
335 for(iter=0; iter<argc; ++iter)
337 TRY( ToInt(shell, argv[iter], &nServoId) );
338 TRY( ChkChainHasServo(shell, nServoId) );
339 TRY( !m_bMasterOpOnly || ChkChainIsMasterServo(shell, nServoId) );
342 doExec(shell, pServo);
366 const char *sContext)
386 if( m_bMasterOpOnly )
397 m_bTabIncChain =
true;
401 m_bTabIncChain =
false;
407 snprintf(buf,
sizeof(buf),
"%d", m_nTabServoId);
408 buf[
sizeof(buf)-1] = 0;
410 if( m_bMasterOpOnly )
419 if( !strncmp(buf, sText, uTextLen) )
427 m_bTabIncChain =
false;
428 if( !strncmp(
"chain", sText, uTextLen) )
459 TRY( ChkArgCnt(shell, argc) );
461 if( (argc % 2) != 0 )
463 shell.
Error(
"Unmatched servo_id,value pairs.");
467 uNumPairs = (uint_t)(argc / 2);
471 shell.
Error(
"%u: Too many servo_id,value pairs.", uNumPairs);
475 TRY( ChkComm(shell) );
476 TRY( ChkChainNotEmpty(shell) );
479 if( !strcmp(argv[0],
"chain") )
481 TRY( ChkArgCntEQ(shell, argc, 2) );
482 TRY( ArgToInt(shell, argv[1], &nVal) );
484 if( m_bMasterOpOnly )
505 uNumPairs = (uint_t)cnt;
511 for(iter=0, cnt=0; iter<argc; iter+=2, ++cnt)
513 TRY( ToInt(shell, argv[iter], &nServoId) );
514 TRY( ArgToInt(shell, argv[iter+1], &nVal) );
515 TRY( ChkChainHasServo(shell, nServoId) );
516 TRY( !m_bMasterOpOnly || ChkChainIsMasterServo(shell, nServoId) );
523 doExec(shell, tup, uNumPairs);
545 const char *sContext)
556 else if( m_bMasterOpOnly &&
576 if( m_bMasterOpOnly )
587 m_bTabIncChain =
true;
591 m_bTabIncChain =
false;
597 snprintf(buf,
sizeof(buf),
"%d", m_nTabServoId);
598 buf[
sizeof(buf)-1] = 0;
600 if( m_bMasterOpOnly )
609 if( !strncmp(buf, sText, uTextLen) )
617 m_bTabIncChain =
false;
618 if( !strncmp(
"chain", sText, uTextLen) )
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
char * eow(const char *s)
Find end of word.
Dynamixel shell utilities.
virtual void PrintBlock(int col, int indent, int width, const char *sText)
Print a block of indented text of width.
virtual void Exec(DynaShell &shell, int argc, char *argv[])
Execute 'read-like' command on servos.
virtual uint_t GetNumberOfMastersInChain()
Get the number of servos currently in chain.
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
virtual void Exec(DynaShell &shell, int argc, char *argv[])
Execute 'write-like' command on servos.
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.
#define DYNA_ID_NUMOF
number of unique servo id's
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
virtual uint_t GetNumberInChain() const
Get the number of servos currently in chain.
Dynamixel Servo Abstract Base Class.
Dynamixel background thread class declarations.
Execute 2-tuple structure type.
static int wc(const string &str)
Count the words in the string.
virtual void PrintHelp(int indent=0, int width=80)
Print command help with the description aligned at the given indentation.
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
virtual DynaServo * GetServo(int nServoId)
RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
virtual char * TabCompletion(DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command tab completion generator.
#define TRY(boolexpr,...)
Try boolean expression.
RoadNarrows Dynamixel Top-Level Package Header File.
The dynashell Command Class Interface.
#define DYNA_ID_NONE
no servo id
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
DynaChain * m_pDynaChain
dynamixel chain
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
virtual void PrintSynopses(int indent, int width)
Print synsopses.
The simple dynashell declarations.
virtual char * TabCompletion(DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command tab completion generator.