![]() |
Dynamixel
2.9.5
RoadNarrows Robotics Dynamixel Package
|
#include <dynashell.h>
Public Member Functions | |
DynaShell () | |
~DynaShell () | |
void | PublishMap (const char *sParent, const string &strBrief) |
Publish new command map to shell. More... | |
void | PublishCommand (const char *sParent, DynaShellCmd *pNewCmd) |
Publish new command to shell. More... | |
void | DeleteCommands (ShCmdMap &cmdMap) |
Delete all published commands in map. More... | |
DynaShellCmd * | MatchCmd (int argc, char *argv[], ShCmdMap &cmdMap) |
Match command. More... | |
void | RecordingInit (int nSamplePeriod, const char *sDate=NULL) |
(Re)Initialize recording. More... | |
void | RecordingReplace (DynaRecording *pNewRecording) |
Replace recording. More... | |
void | ScriptPush (const char *sScriptFile, FILE *fp) |
Push new script on the stack. More... | |
void | ScriptPop () |
Pop the current script from stack. More... | |
void | ScriptFlush () |
Flush all scripts from stack. More... | |
void | ScriptTrace (const char *sLine) |
Trace script execution. More... | |
bool | IsRunningScript () |
Test if executing a script. More... | |
virtual void | Ok () |
Print standard ok success response. | |
void | Response (const char *sFmt,...) |
Print formatted success response. More... | |
void | Warning (const char *sFmt,...) |
Issue warning. More... | |
void | Error (int rc, const char *sFmt,...) |
Raise error on dynamixel error code. More... | |
void | Error (int nServoId, uint_t uAlarms) |
Raise error on alarmed servo. More... | |
void | Error (const char *sFmt,...) |
Raise error. More... | |
int | Run () |
Command execution loop. More... | |
ShCmdMap & | GetRootCmds () |
char * | CmdListGenerator (int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext) |
Command list generator function. More... | |
char * | CmdSpecGenerator (int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext) |
Command spec generator function. More... | |
Public Attributes | |
bool | m_bRun |
do [not] run shell | |
bool | m_bIsInteractive |
[not] user interactive | |
bool | m_bXTrace |
do [not] trace script | |
bool | m_bSilent |
do [not] silence non-error responses | |
DynaComm * | m_pDynaComm |
dynamixel bus communication | |
DynaChain * | m_pDynaChain |
dynamixel chain | |
DynaBgThread * | m_pDynaBgThread |
dynamixel chain | |
DynaRecording * | m_pRecording |
dynamixel recording | |
Static Public Attributes | |
static const int | m_nMaxScriptDepth = 5 |
maximum script stack depth | |
Protected Types | |
typedef map< int, DynaShellCmd * > | MapTabCompleteGen |
Protected Member Functions | |
void | InputInit () |
Initialize input. | |
char * | GetInputLine () |
Get one input line from file stream. More... | |
int | GetInput () |
Get one, non-empty input line. More... | |
bool | IsExecStmt (const char *sLine) |
Test if line is a potential executable statement. More... | |
void | AddToHistory (char *sLine) |
Add command line to history. More... | |
FILE * | InputFp () |
Get the current input file pointer. More... | |
void | ScriptBumpLineNum () |
Bump the line number of the current executing script, if any, by one. | |
bool | IsEOF () |
Test if input is at End Of File condition. More... | |
Static Protected Member Functions | |
static char * | CmdListGeneratorWrap (int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext, void *pArg) |
Command list generator wrapper function. More... | |
static char * | CmdSpecGeneratorWrap (int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext, void *pArg) |
Command spec generator wrapper function. More... | |
Protected Attributes | |
const char * | m_sShellName |
shell name | |
const char * | m_sPS1 |
primary user prompt | |
const char * | m_sPS2 |
secondary user prompt | |
bool | m_bNoExec |
parse only, no execution | |
char * | m_sInputLine |
working, allocated line of input | |
ReadLine | m_ReadLine |
readline object | |
ShCmdMap | m_mapCmds |
map of published commnds | |
MapTabCompleteGen | m_mapTabGen |
command tab-completion generators map | |
vector< ShScript * > | m_vecScripts |
script stack | |
int | m_rc |
last command executed return code | |
The Dynamixel shell class.
Definition at line 350 of file dynashell.h.
DynaShell::DynaShell | ( | ) |
DynaShell default constructor.
Definition at line 95 of file dynashell.cxx.
References DYNA_OK, InputInit(), m_bIsInteractive, m_bNoExec, m_bRun, m_bSilent, m_bXTrace, m_pDynaBgThread, m_pDynaChain, m_pDynaComm, m_pRecording, and m_rc.
DynaShell::~DynaShell | ( | ) |
DynaShell destructor.
Definition at line 118 of file dynashell.cxx.
References DeleteCommands(), m_mapCmds, m_pDynaBgThread, m_pDynaChain, m_pDynaComm, m_pRecording, ScriptFlush(), and DynaBgThread::Stop().
|
protected |
Add command line to history.
sLine | Null-terminated line string. |
Definition at line 443 of file dynashell.cxx.
References ReadLine::AddToHistory(), InputFp(), IsExecStmt(), m_bIsInteractive, and m_ReadLine.
Referenced by GetInput().
char * DynaShell::CmdListGenerator | ( | int | nUid, |
const char * | sText, | ||
size_t | uTextLen, | ||
int | nState, | ||
const char * | sContext | ||
) |
Command list generator function.
nUid | ReadLine registered unique id. |
sText | Text string to complete as a command. |
uTextLen | Length of text. |
nState | Generator state. State lets us know whether to start from scratch. If state == START(0), then we start at the top of the command list. |
sContext | Parent command path. |
Definition at line 319 of file dynashell.cxx.
References ReadLine::dupstr(), ReadLine::FIRST, and m_mapCmds.
Referenced by CmdListGeneratorWrap(), and DynaShellCmdHelp::TabCompletion().
|
staticprotected |
Command list generator wrapper function.
nUid | ReadLine registered unique id. |
sText | Text string to complete as a command. |
uTextLen | Length of text. |
nState | Generator state. State lets us know whether to start from scratch. If state == START(0), then we start at the top of the command list. |
sContext | Parent command path. |
pArg | Pointer to this shell instance. |
Definition at line 292 of file dynashell.cxx.
References CmdListGenerator().
Referenced by InputInit(), PublishCommand(), and PublishMap().
char * DynaShell::CmdSpecGenerator | ( | int | nUid, |
const char * | sText, | ||
size_t | uTextLen, | ||
int | nState, | ||
const char * | sContext | ||
) |
Command spec generator function.
nUid | ReadLine registered unique id. |
sText | Text string to complete as a command. |
uTextLen | Length of text. |
nState | Generator state. State lets us know whether to start from scratch. If state == START(0), then we start at the top of the command list. |
sContext | Parent command path. |
Definition at line 418 of file dynashell.cxx.
References m_mapTabGen.
Referenced by CmdSpecGeneratorWrap().
|
staticprotected |
Command spec generator wrapper function.
nUid | ReadLine registered unique id. |
sText | Text string to complete as a command. |
uTextLen | Length of text. |
nState | Generator state. State lets us know whether to start from scratch. If state == START(0), then we start at the top of the command list. |
sContext | Parent command path. |
pArg | Pointer to this shell instance. |
Definition at line 391 of file dynashell.cxx.
References CmdSpecGenerator().
Referenced by PublishCommand().
void DynaShell::DeleteCommands | ( | ShCmdMap & | cmdMap | ) |
Delete all published commands in map.
cmdMap | Map of published commands. |
Definition at line 249 of file dynashell.cxx.
References m_mapTabGen.
Referenced by ~DynaShell().
void DynaShell::Error | ( | int | rc, |
const char * | sFmt, | ||
... | |||
) |
Raise error on dynamixel error code.
rc | Package Error Codes. |
sFmt | Format string. |
... | Optional format string arguments. |
Definition at line 808 of file dynashell.cxx.
References DynaStrError().
Referenced by DynaShellCmdCfgWriteServoMode::ArgToInt(), DynaShellCmdWriteTorqueEnable::ArgToInt(), DynaShellCmd::ChkArgCnt0(), DynaShellCmd::ChkArgCntEQ(), DynaShellCmd::ChkArgCntGE(), DynaShellCmd::ChkArgCntLE(), DynaShellCmd::ChkChain(), DynaShellCmd::ChkChainHasServo(), DynaShellCmd::ChkChainIsMasterServo(), DynaShellCmd::ChkChainNotEmpty(), DynaShellCmd::ChkComm(), DynaShellCmdCreate::CommNew(), DynaShellCmdMegaScan::CommNew(), DynaShellCmdMoveTo::doExec(), DynaShellCmdMoveAtSpeedTo::doExec(), DynaShellCmdCfgWriteServoMode::doExec(), DynaShellCmdReadTorqueEnable::doExec(), DynaShellCmdWriteTorqueEnable::doExec(), DynaShellCmdReadGoalPos::doExec(), DynaShellCmdReadGoalSpeed::doExec(), DynaShellCmdWriteGoalSpeed::doExec(), DynaShellCmdReadMaxTorqueLimit::doExec(), DynaShellCmdWriteMaxTorqueLimit::doExec(), DynaShellCmdReadCurPos::doExec(), DynaShellCmdReadCurSpeed::doExec(), DynaShellCmdReadDynamics::doExec(), DynaShellCmdReadHealth::doExec(), DynaShellCmdReadIsMoving::doExec(), DynaShellCmdClearAlarms::doExec(), DynaShellCmdReadByte::doExec(), DynaShellCmdWriteByte::doExec(), DynaShellCmdReadWord::doExec(), DynaShellCmdWriteWord::doExec(), Error(), DynaShellCmdCreate::Exec(), DynaShellCmdHelp::Exec(), DynaShellCmdMoveAtSpeedTo::Exec(), DynaShellCmdSetPid::Exec(), DynaShellCmdDestroy::Exec(), DynaShellCmdEStop::Exec(), DynaShellCmdFreeze::Exec(), DynaShellCmdRelease::Exec(), DynaShellCmdLink::Exec(), DynaShellCmdSetOdometer::Exec(), DynaShellCmdScript::Exec(), DynaShellCmdChainOut::Exec(), DynaShellCmdUnlink::Exec(), DynaShellCmdBgtStart::Exec(), DynaShellCmdSaveRecording::Exec(), DynaShellCmdBgtStop::Exec(), DynaShellCmdReadMaxTorqueLimit::Exec(), DynaShellCmdSetHalfDuplexCtl::Exec(), DynaShellCmdWriteMaxTorqueLimit::Exec(), DynaShellCmdPlay::Exec(), DynaShellCmdSetSoftTorqueTh::Exec(), DynaShellCmdWriteByte::Exec(), GetInput(), DynaShellCmdLoadRecording::Init(), DynaShellCmdLoadRecording::Load(), MatchCmd(), DynaShellCmdHelp::MatchHelp(), DynaShellCmdLoadRecording::ParseIntField(), DynaShellCmdLoadRecording::ParseRecordedData(), DynaShellCmdLoadRecording::ParseServoList(), DynaShellCmdTrain::RecordTraining(), ScriptPush(), DynaShellCmd::ToBool(), DynaShellCmd::ToDouble(), and DynaShellCmd::ToInt().
void DynaShell::Error | ( | int | nServoId, |
uint_t | uAlarms | ||
) |
Raise error on alarmed servo.
nServoId | Servo id. |
uAlarms | EEPROM Alarm Shutdown. |
Definition at line 829 of file dynashell.cxx.
References Error(), and DynaComm::GetAlarmsString().
void DynaShell::Error | ( | const char * | sFmt, |
... | |||
) |
Raise error.
If the error occurred while running a script, the script is aborted. If the shell is non-interactive, the shell is terminated.
sFmt | Format string. |
... | Optional format string arguments. |
Definition at line 847 of file dynashell.cxx.
References DYNA_ECODE_RUNTIME, m_bIsInteractive, m_bRun, m_rc, m_vecScripts, and ScriptFlush().
|
protected |
Get one, non-empty input line.
Definition at line 505 of file dynashell.cxx.
References AddToHistory(), Error(), GetInputLine(), IsEOF(), IsExecStmt(), m_bIsInteractive, m_bNoExec, m_bXTrace, m_sInputLine, ScriptTrace(), SH_RC_EOF, SH_RC_OK, SH_RC_OK_NOEXEC, and SH_RC_SYS_ERROR.
Referenced by Run().
|
protected |
Get one input line from file stream.
Characters will be read from the input of the given file pointer using the prompt string to prompt the user. If the prompt is NULL or an empty string then no prompt is issued. The line returned is allocated, so the caller must free it when finished.
If the readline free library is available, then command line editing is supported for terminal input.
Definition at line 469 of file dynashell.cxx.
References ReadLine::fReadLine(), InputFp(), ReadLine::iReadLine(), m_ReadLine, m_sPS1, and ScriptBumpLineNum().
Referenced by GetInput().
|
inline |
Get map of shell root commands.
Definition at line 446 of file dynashell.h.
Referenced by DynaShellCmdHelp::Exec().
|
inlineprotected |
Get the current input file pointer.
Definition at line 518 of file dynashell.h.
Referenced by AddToHistory(), and GetInputLine().
|
inlineprotected |
Test if input is at End Of File condition.
Definition at line 540 of file dynashell.h.
Referenced by GetInput().
|
inlineprotected |
Test if line is a potential executable statement.
sLine | Line to test. |
Definition at line 492 of file dynashell.h.
Referenced by AddToHistory(), and GetInput().
|
inline |
Test if executing a script.
Definition at line 416 of file dynashell.h.
Referenced by ScriptTrace().
DynaShellCmd * DynaShell::MatchCmd | ( | int | argc, |
char * | argv[], | ||
ShCmdMap & | cmdMap | ||
) |
Match command.
argc | Command argument count. |
argv | Array of arguments. |
cmdMap | Command map to search. |
Definition at line 567 of file dynashell.cxx.
References Error().
Referenced by Run().
void DynaShell::PublishCommand | ( | const char * | sParent, |
DynaShellCmd * | pNewCmd | ||
) |
Publish new command to shell.
The new command is inserted into the map of commands. The map is kept in lexicogrphahical increasing order.
sParent | Parent command. Set to NULL or "" to publish the command at the root(0) level. |
pNewCmd | Allocated new command. The shell owns the command and will delete it when the shell is destroyed. |
Definition at line 192 of file dynashell.cxx.
References CmdListGeneratorWrap(), CmdSpecGeneratorWrap(), DynaShellCmd::GetCmdHelpBrief(), DynaShellCmd::GetCmdName(), DynaShellCmd::GetPublishedName(), m_mapCmds, m_mapTabGen, m_ReadLine, ReadLine::NOT_REG, ReadLine::RegisterGenerator(), and DynaShellCmd::SetPublishedInfo().
Referenced by PublishShellCoreCommands(), PublishShellInterfaceCommands(), PublishShellServoCommands(), and PublishShellTrainCommands().
void DynaShell::PublishMap | ( | const char * | sParent, |
const string & | strBrief | ||
) |
Publish new command map to shell.
The new map is inserted into the map of root commands. The map is kept in lexicogrphahical increasing order.
sParent | Parent command. Set to NULL or "" to publish the command at the root(0) level. |
strBrief | Map brief description. |
Definition at line 159 of file dynashell.cxx.
References CmdListGeneratorWrap(), m_mapCmds, m_ReadLine, and ReadLine::RegisterGenerator().
Referenced by MainInit().
|
inline |
(Re)Initialize recording.
If the shell does not have a recording object, it is created. Any previously recorded data is 'erased'.
nSamplePeriod | Recording sample period (msec). |
sData | Recording date string. |
Definition at line 383 of file dynashell.h.
References DynaRecording::Init().
Referenced by DynaShellCmdTrain::Exec().
|
inline |
Replace recording.
pNewRecording | Allocated new recording. |
Definition at line 397 of file dynashell.h.
Referenced by DynaShellCmdLoadRecording::Load().
void DynaShell::Response | ( | const char * | sFmt, |
... | |||
) |
Print formatted success response.
sFmt | Format string. |
... | Variable argument list. |
Definition at line 763 of file dynashell.cxx.
References m_bSilent.
Referenced by DynaShellCmdGetOdometer::doExec(), DynaShellCmdReadTorqueEnable::doExec(), DynaShellCmdReadGoalPos::doExec(), DynaShellCmdReadGoalSpeed::doExec(), DynaShellCmdReadMaxTorqueLimit::doExec(), DynaShellCmdGetSoftTorqueTh::doExec(), DynaShellCmdReadCurPos::doExec(), DynaShellCmdReadCurSpeed::doExec(), DynaShellCmdReadDynamics::doExec(), DynaShellCmdReadHealth::doExec(), DynaShellCmdReadIsMoving::doExec(), DynaShellCmdClearAlarms::doExec(), DynaShellCmdReadByte::doExec(), DynaShellCmdReadWord::doExec(), DynaShellCmdDump::doExec(), DynaShellCmdScan::Exec(), DynaShellCmdPing::Exec(), DynaShellCmdList::Exec(), DynaShellCmdMegaScan::Exec(), DynaShellCmdBgtStart::Exec(), DynaShellCmdSaveRecording::Exec(), DynaShellCmdBgtStop::Exec(), DynaShellCmdBgtGetState::Exec(), DynaShellCmdLoadRecording::Load(), and DynaShellCmdPlay::Play().
int DynaShell::Run | ( | ) |
Command execution loop.
Loop through all commands from input intil EOF, error, or user commanded termination.
Definition at line 884 of file dynashell.cxx.
References DYNA_ECODE_SYS, DYNA_OK, DynaShellCmd::Exec(), GetInput(), DynaShellCmd::GetPublishedLevel(), m_bIsInteractive, m_bRun, m_mapCmds, m_rc, m_sInputLine, MatchCmd(), ScriptPop(), SH_RC_EOF, SH_RC_OK, SH_RC_OK_NOEXEC, SH_RC_SYS_ERROR, and ReadLine::tokenize().
Referenced by main().
void DynaShell::ScriptFlush | ( | ) |
Flush all scripts from stack.
If this shell is not user interactive, the shell will marked for termination. Otherwise, standard input becomes the point of execution.
Definition at line 716 of file dynashell.cxx.
References m_bIsInteractive, m_bRun, and m_vecScripts.
Referenced by Error(), and ~DynaShell().
void DynaShell::ScriptPop | ( | ) |
Pop the current script from stack.
The new top-of-stack script resumes execution. If there are no more scripts on the stack and this shell is not user interactive, then the shell will marked for termination. Otherwise, if the stack is empty, standard input becomes the point of execution.
Definition at line 693 of file dynashell.cxx.
References m_bIsInteractive, m_bRun, and m_vecScripts.
Referenced by Run().
void DynaShell::ScriptPush | ( | const char * | sScriptFile, |
FILE * | fp | ||
) |
Push new script on the stack.
The new script becomes the point of execution.
sScriptFile | Script file path name. |
fp | Script file opened file pointer. |
Definition at line 669 of file dynashell.cxx.
References Error(), m_nMaxScriptDepth, and m_vecScripts.
Referenced by DynaShellCmdScript::Exec(), and MainInitArgs().
void DynaShell::ScriptTrace | ( | const char * | sLine | ) |
Trace script execution.
sLine | Executable script statement. |
Definition at line 739 of file dynashell.cxx.
References IsRunningScript(), m_bIsInteractive, and m_vecScripts.
Referenced by GetInput().
void DynaShell::Warning | ( | const char * | sFmt, |
... | |||
) |
Issue warning.
sFmt | Format string. |
... | Optional format string arguments. |
Definition at line 781 of file dynashell.cxx.
References m_vecScripts.
Referenced by DynaShellCmdLoadRecording::Load().