Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdCreate Class Reference

Create command. More...

Inheritance diagram for DynaShellCmdCreate:
DynaShellCmd

Public Member Functions

void Exec (DynaShell &shell, int argc, char *argv[])
 Create dynamixel interface. 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

DynaCommCommNew (DynaShell &shell, const char *sUri, int nBaudRate)
 Create a new open dynamixel bus object. 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: baud rate iterator
 
- 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

Create command.

Definition at line 85 of file dynashell_cmd_if.cxx.

Member Function Documentation

DynaComm* DynaShellCmdCreate::CommNew ( DynaShell shell,
const char *  sUri,
int  nBaudRate 
)
inlineprotected

Create a new open dynamixel bus object.

Parameters
shellDynamixel shell.
sUriDynamixel bus [proxied] device Uniform Resource Id.
nBaudRateDevice and servo baudrate.
Returns
Returns new DynaComm object on success, NULL on failure.

Definition at line 235 of file dynashell_cmd_if.cxx.

References DynaShell::Error(), DynaComm::IsOpen(), and DynaComm::New().

236  {
237  DynaComm *pDynaComm = DynaComm::New(sUri, nBaudRate);
238 
239  if( pDynaComm == NULL )
240  {
241  shell.Error("Failed to create %s@%d.", sUri, nBaudRate);
242  }
243 
244  else if( !pDynaComm->IsOpen() )
245  {
246  shell.Error("Failed to open %s@%d.", sUri, nBaudRate);
247  delete pDynaComm;
248  pDynaComm = NULL;
249  }
250 
251  return pDynaComm;
252  }
virtual bool IsOpen()
Test if Dynamixel Bus is open.
Definition: DynaComm.h:383
static DynaComm * New(const char *sUri, int nBaudRate)
Archetype constructor to create a new Dynamixel bus communication derived instance.
Definition: DynaComm.cxx:179
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
Dynamixel Bus Communications Abstract Base Class.
Definition: DynaComm.h:80
void DynaShellCmdCreate::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Create dynamixel interface.

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

Implements DynaShellCmd.

Definition at line 117 of file dynashell_cmd_if.cxx.

References DynaBgThread::BgThreadStatePaused, DynaBgThread::BgThreadStateRunning, DynaShell::Error(), DynaBgThread::GetCurrentState(), DynaShell::m_pDynaBgThread, DynaShell::m_pDynaChain, DynaShell::m_pDynaComm, DynaShell::Ok(), DynaBgThread::RegisterChainAgent(), DynaBgThread::Stop(), TRY, and DynaBgThread::UnregisterAgent().

118  {
119  char *sUri;
120  int nBaudRate;
121 
122  TRY( ChkArgCnt(shell, argc) );
123 
124  sUri = argv[0];
125 
126  TRY( ToInt(shell, argv[1], &nBaudRate) );
127 
128  if( shell.m_pDynaChain != NULL )
129  {
130  shell.Error("Dynamixel interface already created. Try destroying first.");
131  return;
132  }
133 
134  shell.m_pDynaComm = CommNew(shell, sUri, nBaudRate);
135 
136  TRY( shell.m_pDynaComm != NULL );
137 
138  shell.m_pDynaChain = new DynaChain(*shell.m_pDynaComm);
139 
140  // create background thread and register chain - leave in ready state
141  if( shell.m_pDynaBgThread == NULL )
142  {
143  shell.m_pDynaBgThread = new DynaBgThread();
145  }
146 
147  // register new chain with background thread - leave in ready state
148  else
149  {
150  switch( shell.m_pDynaBgThread->GetCurrentState() )
151  {
154  shell.m_pDynaBgThread->Stop();
155  break;
156  default:
157  break;
158  }
159 
162  }
163 
164  shell.Ok();
165  }
virtual void RegisterChainAgent(DynaChain *pChain)
Register the Dynamixel chain for control and monitoring.
DynaComm * m_pDynaComm
dynamixel bus communication
Definition: dynashell.h:359
BgThreadState GetCurrentState()
Get current background thread state.
Definition: DynaBgThread.h:415
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
virtual int Stop()
Stop control and monitoring tasks.
virtual void UnregisterAgent()
Unregister any chain or servo from control and monitoring.
DynaComm * CommNew(DynaShell &shell, const char *sUri, int nBaudRate)
Create a new open dynamixel bus object.
virtual void Ok()
Print standard ok success response.
Definition: dynashell.h:425
virtual bool ChkArgCnt(DynaShell &shell, int argc)
Check that the argument count is within the class (min,max).
Dynamixel Chain Container Base Class.
Definition: DynaChain.h:75
DynaBgThread * m_pDynaBgThread
dynamixel chain
Definition: dynashell.h:361
#define TRY(boolexpr,...)
Try boolean expression.
Definition: dynashell_cmd.h:89
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* DynaShellCmdCreate::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes <device> <baudrate>

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 182 of file dynashell_cmd_if.cxx.

References DynaComm::BaudRateAt(), ReadLine::dupstr(), ReadLine::FileCompletionGenerator(), ReadLine::FIRST, and ReadLine::wc().

187  {
188  int nBaudRate;
189  char buf[32];
190 
191  // <device>
192  if( ReadLine::wc(sContext) == ReadLine::wc(m_sPubName) )
193  {
194  return ReadLine::FileCompletionGenerator(sText, nState);
195  }
196 
197  //
198  // New command to complete - initialize.
199  //
200  if( nState == ReadLine::FIRST )
201  {
202  m_nTabIter = 0;
203  }
204 
205  // <baudrate>
206  while( (nBaudRate = DynaComm::BaudRateAt(m_nTabIter)) != 0 )
207  {
208  m_nTabIter++;
209 
210  snprintf(buf, sizeof(buf), "%d", nBaudRate);
211  buf[sizeof(buf)-1] = 0;
212 
213  if( !strncmp(buf, sText, uTextLen) )
214  {
215  return ReadLine::dupstr(buf);
216  }
217  }
218 
219  // no more matches
220  return NULL;
221  }
static int BaudRateAt(int nIndex)
Get the baud rate associated with the given index.
Definition: DynaComm.cxx:396
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
char * m_sPubName
command&#39;s published name
static int wc(const string &str)
Count the words in the string.
static char * FileCompletionGenerator(const char *sText, int nState)
File name tab completion generator.
int m_nTabIter
tab completion: baud rate iterator

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