Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdBgtStart Class Reference

Start the background thread. More...

Inheritance diagram for DynaShellCmdBgtStart:
DynaShellCmd

Public Member Functions

void Exec (DynaShell &shell, int argc, char *argv[])
 Execute background thread start. 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

void SetTabTDefaults ()
 Set tab completion time period default strings.
 
- 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_nTabIndex
 tab completion: index
 
string m_strTDefault
 default time period value
 
- 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

Start the background thread.

Definition at line 987 of file dynashell_cmd_if.cxx.

Member Function Documentation

void DynaShellCmdBgtStart::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Execute background thread start.

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

Implements DynaShellCmd.

Definition at line 1018 of file dynashell_cmd_if.cxx.

References DynaBgThread::BgThreadStatePaused, DynaBgThread::BgThreadStateReady, DynaBgThread::BgThreadStateRunning, DynaShell::Error(), DynaBgThread::GetCurrentState(), DynaBgThread::getHz(), DynaShell::m_pDynaBgThread, DynaShell::Response(), DynaBgThread::Run(), DynaBgThread::setHz(), and TRY.

1019  {
1020  int i;
1021  double val;
1022  double fHz;
1023 
1024  TRY( ChkArgCnt(shell, argc) );
1025 
1026  TRY( ChkComm(shell) );
1027  TRY( ChkChainNotEmpty(shell) );
1028 
1029  switch( shell.m_pDynaBgThread->GetCurrentState() )
1030  {
1033  break;
1035  default:
1036  shell.Error("Background thread already running. "
1037  "Try stopping first.");
1038  return;
1039  }
1040 
1041  if( argc > 0 )
1042  {
1043  TRY( ToDouble(shell, argv[0], &val) );
1044  fHz = val;
1045  }
1046  else
1047  {
1048  fHz = shell.m_pDynaBgThread->getHz();
1049  }
1050 
1051  shell.m_pDynaBgThread->setHz(fHz);
1052 
1053  shell.m_pDynaBgThread->Run();
1054 
1055  shell.Response("Background thread started.\n");
1056  }
bool ChkChainNotEmpty(DynaShell &shell)
Check that the servo chain exists and is not empty.
thread created and ready to run
Definition: DynaBgThread.h:254
BgThreadState GetCurrentState()
Get current background thread state.
Definition: DynaBgThread.h:415
virtual int Run()
Run the background thread control and monitoring tasks.
double getHz()
Get control and monitoring hetrz rate.
Definition: DynaBgThread.h:457
void Response(const char *sFmt,...)
Print formatted success response.
Definition: dynashell.cxx:763
bool ToDouble(DynaShell &shell, const char *sArg, double *pVal)
Convert command argument to double.
virtual bool ChkArgCnt(DynaShell &shell, int argc)
Check that the argument count is within the class (min,max).
DynaBgThread * m_pDynaBgThread
dynamixel chain
Definition: dynashell.h:361
#define TRY(boolexpr,...)
Try boolean expression.
Definition: dynashell_cmd.h:89
bool ChkComm(DynaShell &shell)
Check that Dynamixel communication exists and is open.
void setHz(double fHz)
Set new control and monitoring execution hertz rate.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
virtual char* DynaShellCmdBgtStart::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes t_posctl_dft|notask t_dynamics_dft|notask t_health_dft|notask

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

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

1078  {
1079  int nArgNum;
1080  char buf[16];
1081 
1082  if( (shell.m_pDynaChain == NULL) ||
1083  (shell.m_pDynaChain->GetNumberInChain() == 0) )
1084  {
1085  return NULL;
1086  }
1087 
1088  // argument number of already (expanded) arguments
1089  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
1090 
1091  if( nArgNum > m_nArgCntMax )
1092  {
1093  return NULL;
1094  }
1095 
1096  //
1097  // New command to complete - initialize.
1098  //
1099  if( nState == ReadLine::FIRST )
1100  {
1101  m_nTabIndex = 0;
1102  }
1103 
1104  // can only expand default keyword
1105  while( m_nTabIndex < 2 )
1106  {
1107  ++m_nTabIndex;
1108 
1109  if( m_nTabIndex == 1 )
1110  {
1111  if( !strncmp(m_strTDefault.c_str(), sText, uTextLen) )
1112  {
1114  }
1115  }
1116  }
1117 
1118  // no more matches
1119  return NULL;
1120  }
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
const int m_nArgCntMax
maximum argument count (0 if not max)
char * m_sPubName
command&#39;s published name
static int wc(const string &str)
Count the words in the string.
string m_strTDefault
default time period value
int m_nTabIndex
tab completion: index
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360

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