Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdWriteByte Class Reference

Write byte value to servo at address. More...

Inheritance diagram for DynaShellCmdWriteByte:
DynaShellCmd DynaShellCmdWriteWord

Public Member Functions

virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute write 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, uint_t uAddr, DynaSyncWriteTuple_T tup[], uint_t uCount)
 Write 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

Write byte value to servo at address.

Definition at line 2391 of file dynashell_cmd_servo.cxx.

Member Function Documentation

virtual void DynaShellCmdWriteByte::doExec ( DynaShell shell,
uint_t  uAddr,
DynaSyncWriteTuple_T  tup[],
uint_t  uCount 
)
inlineprotectedvirtual

Write byte.

Parameters
shellDynamixel shell.
uAddrWrite address.
tupArray of (servo id, value) 2-tuples.
uCountNumber of tuples.

Reimplemented in DynaShellCmdWriteWord.

Definition at line 2595 of file dynashell_cmd_servo.cxx.

References DYNA_OK, DynaShell::Error(), DynaShell::m_pDynaComm, DynaShell::Ok(), DynaComm::SyncWrite(), and DynaComm::Write8().

2599  {
2600  int rc;
2601 
2602  if( uCount == 1 )
2603  {
2604  rc = shell.m_pDynaComm->Write8(tup[0].m_nServoId, uAddr, tup[0].m_uVal);
2605 
2606  if( rc != DYNA_OK )
2607  {
2608  shell.Error(rc,
2609  "Servo %d: Failed to write byte 0x%02x to 0x%02x.",
2610  tup[0].m_nServoId, tup[0].m_uVal, uAddr);
2611  return;
2612  }
2613  }
2614  else
2615  {
2616  rc = shell.m_pDynaComm->SyncWrite(uAddr, 1, tup, uCount);
2617 
2618  if( rc != DYNA_OK )
2619  {
2620  shell.Error(rc,
2621  "Failed to syncwrite to 0x%02x for %u servos.",
2622  uAddr, uCount);
2623  return;
2624  }
2625  }
2626 
2627  shell.Ok();
2628  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
DynaComm * m_pDynaComm
dynamixel bus communication
Definition: dynashell.h:359
virtual int Write8(int nServoId, uint_t uAddr, byte_t byVal)=0
Write an 8-bit value to Dynamixel servo control table.
virtual void Ok()
Print standard ok success response.
Definition: dynashell.h:425
virtual int SyncWrite(uint_t uAddr, uint_t uValSize, DynaSyncWriteTuple_T tuples[], uint_t uCount)=0
Synchronous Write 8/16-bit values to a list of Dynamixel servos.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
virtual void DynaShellCmdWriteByte::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Execute write byte command on servos.

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

Implements DynaShellCmd.

Definition at line 2431 of file dynashell_cmd_servo.cxx.

References DYNA_ID_NONE, DYNA_ID_NUMOF, DynaShell::Error(), DynaChain::IterNext(), DynaChain::IterStart(), DynaSyncWriteTuple_T::m_nServoId, DynaShell::m_pDynaChain, DynaSyncWriteTuple_T::m_uVal, and TRY.

2432  {
2434  uint_t uAddr;
2435  uint_t uVal;
2436  int nServoId;
2437  int iter;
2438  int cnt;
2439  uint_t uNumPairs;
2440 
2441  TRY( ChkArgCnt(shell, argc) );
2442  TRY( ChkComm(shell) );
2443  TRY( ChkChainNotEmpty(shell) );
2444 
2445  TRY( ToInt(shell, argv[0], (int *)&uAddr) );
2446 
2447  cnt = argc - 1; // less address
2448 
2449  if( (cnt % 2) != 0 )
2450  {
2451  shell.Error("Unmatched servo_id,value pairs.");
2452  return;
2453  }
2454 
2455  uNumPairs = (uint_t)(cnt / 2);
2456 
2457  if( uNumPairs > DYNA_ID_NUMOF )
2458  {
2459  shell.Error("%u: Too many servo_id,value pairs.", uNumPairs);
2460  return;
2461  }
2462 
2463  if( !strcmp(argv[1], "chain") )
2464  {
2465  TRY( ChkArgCntEQ(shell, argc, 3) );
2466 
2467  TRY( ToInt(shell, argv[2], (int *)&uVal) );
2468 
2469  for(nServoId = shell.m_pDynaChain->IterStart(&iter), cnt=0;
2470  nServoId != DYNA_ID_NONE;
2471  nServoId = shell.m_pDynaChain->IterNext(&iter), ++cnt)
2472  {
2473  tup[cnt].m_nServoId = nServoId;
2474  tup[cnt].m_uVal = uVal;
2475  }
2476  }
2477 
2478  else
2479  {
2480  for(iter=1, cnt=0; iter<argc; iter+=2, ++cnt)
2481  {
2482  TRY( ToInt(shell, argv[iter], &nServoId) );
2483  TRY( ChkChainHasServo(shell, nServoId) );
2484  TRY( ToInt(shell, argv[iter+1], (int *)&uVal) );
2485 
2486  tup[cnt].m_nServoId = nServoId;
2487  tup[cnt].m_uVal = uVal;
2488  }
2489  }
2490 
2491  doExec(shell, uAddr, tup, (uint_t)cnt);
2492  }
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.
int m_nServoId
servo id
Definition: DynaTypes.h:296
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
#define DYNA_ID_NUMOF
number of unique servo id&#39;s
Definition: Dynamixel.h:148
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
uint_t m_uVal
write value
Definition: DynaTypes.h:297
virtual void doExec(DynaShell &shell, uint_t uAddr, DynaSyncWriteTuple_T tup[], uint_t uCount)
Write byte.
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
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
virtual char* DynaShellCmdWriteByte::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 2509 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().

2514  {
2515  int nArgNum;
2516 
2517  char buf[16];
2518 
2519  if( (shell.m_pDynaChain == NULL) ||
2520  (shell.m_pDynaChain->GetNumberInChain() == 0) )
2521  {
2522  return NULL;
2523  }
2524 
2525  // argument number of already (expanded) arguments
2526  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
2527 
2528  // cannot complete adrress
2529  if( nArgNum == 0 )
2530  {
2531  return NULL;
2532  }
2533 
2534  // every even argument is the servo value, which cannot be expanded
2535  else if( (nArgNum & 0x01) == 0 )
2536  {
2537  return NULL;
2538  }
2539 
2540  // New command argument to complete - initialize.
2541  //
2542  if( nState == ReadLine::FIRST )
2543  {
2545 
2546  if( nArgNum == 1 )
2547  {
2548  m_bTabIncChain = true;
2549  }
2550  else
2551  {
2552  m_bTabIncChain = false;
2553  }
2554  }
2555 
2556  while( m_nTabServoId != DYNA_ID_NONE )
2557  {
2558  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
2559  buf[sizeof(buf)-1] = 0;
2560 
2562 
2563  if( !strncmp(buf, sText, uTextLen) )
2564  {
2565  return ReadLine::dupstr(buf);
2566  }
2567  }
2568 
2569  if( m_bTabIncChain )
2570  {
2571  m_bTabIncChain = false;
2572  if( !strncmp("chain", sText, uTextLen) )
2573  {
2574  return ReadLine::dupstr("chain");
2575  }
2576  }
2577 
2578  // no more matches
2579  return NULL;
2580  }
bool m_bTabIncChain
tab completion: [do not] include chain keyword
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_nTabIter
tab completion: servo id iterator
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

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