Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
dynashell_main.cxx File Reference

RoadNarrows simple Dynamixel shell using the RoadNarrows Dynamixel library. More...

#include <sys/select.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <ctype.h>
#include <errno.h>
#include "rnr/rnrconfig.h"
#include "rnr/opts.h"
#include "rnr/log.h"
#include "Dynamixel/Dynamixel.h"
#include "version.h"
#include "dynashell.h"
#include "dynashell_cmd.h"
#include "dynashell_util.h"

Go to the source code of this file.

Functions

static void MainInitArgs (DynaShell &shell, int argc, char *argv[])
 Main command-line argument initialization. More...
 
static void MainInit (DynaShell &shell, int argc, char *argv[])
 Main initialization. More...
 
static void MainFini (DynaShell &shell)
 Main clean-up on exiting. More...
 
int main (int argc, char *argv[])
 Example main. More...
 

Variables

static char * Argv0
 the command
 
static char * OptsSerDevUri = NULL
 the serial device URI
 
static int OptsBaudRate = 1000000
 serial baudrate
 
static char * OptsScript = NULL
 script file
 
static bool OptsXTrace = false
 trace script
 
static bool OptsSilent = false
 silence output
 
static OptsPgmInfo_T AppPgmInfo
 Program information. More...
 
static OptsInfo_T AppOptsInfo []
 Command line options information.
 

Detailed Description

RoadNarrows simple Dynamixel shell using the RoadNarrows Dynamixel library.

LastChangedDate
2015-01-12 10:56:06 -0700 (Mon, 12 Jan 2015)
Rev
3845
Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file dynashell_main.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Example main.

Parameters
argcCommand-line argument count.
argvCommand-line argument list.
Exit Status:
Program exits with 0 success, > 0 on failure.

Definition at line 291 of file dynashell_main.cxx.

References DYNA_OK, MainFini(), MainInit(), and DynaShell::Run().

292 {
293  DynaShell shell;
294  int rc;
295 
296  MainInit(shell, argc, argv);
297 
298  rc = shell.Run();
299 
300  MainFini(shell);
301 
302  return rc == DYNA_OK? 0: 8;
303 }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
static void MainInit(DynaShell &shell, int argc, char *argv[])
Main initialization.
static void MainFini(DynaShell &shell)
Main clean-up on exiting.
int Run()
Command execution loop.
Definition: dynashell.cxx:884
static void MainFini ( DynaShell shell)
static

Main clean-up on exiting.

Parameters
shellDynamixel shell.

Definition at line 278 of file dynashell_main.cxx.

Referenced by main().

279 {
280 }
static void MainInit ( DynaShell shell,
int  argc,
char *  argv[] 
)
static

Main initialization.

Parameters
shellDynamixel shell.
argcCommand-line argument count.
argvCommand-line argument list.
Exits:
Program terminates on conversion error.

Definition at line 252 of file dynashell_main.cxx.

References MainInitArgs(), DynaShell::PublishMap(), PublishShellCoreCommands(), PublishShellInterfaceCommands(), and PublishShellServoCommands().

Referenced by main().

253 {
254  MainInitArgs(shell, argc, argv);
255 
256  shell.PublishMap("bg", "Commands to control the vServo background thread.");
257  shell.PublishMap("clear", "Commands to clear run-time state.");
258  shell.PublishMap("dump", "Dump memory contents.");
259  shell.PublishMap("get", "Commands to get servo class object parameters.");
260  shell.PublishMap("load", "Commands to load files.");
261  shell.PublishMap("read", "Commands to read from the physical servos.");
262  shell.PublishMap("run", "Commands to run scripts.");
263  shell.PublishMap("save", "Commands to save files.");
264  shell.PublishMap("set", "Commands to set servo class object parameters.");
265  shell.PublishMap("write", "Commands to write to the physical servos.");
266 
270  //PublishShellTrainCommands(shell);
271 }
void PublishShellServoCommands(DynaShell &shell)
Publish shell servo commands to shell.
void PublishShellInterfaceCommands(DynaShell &shell)
Publish shell dynamixel interface commands to shell.
void PublishMap(const char *sParent, const string &strBrief)
Publish new command map to shell.
Definition: dynashell.cxx:159
void PublishShellCoreCommands(DynaShell &shell)
Publish shell core commands to shell.
static void MainInitArgs(DynaShell &shell, int argc, char *argv[])
Main command-line argument initialization.
static void MainInitArgs ( DynaShell shell,
int  argc,
char *  argv[] 
)
static

Main command-line argument initialization.

Parameters
shellDynamixel shell.
argcCommand-line argument count.
argvCommand-line argument list.
Exits:
Program terminates on conversion error.

Definition at line 190 of file dynashell_main.cxx.

References AppOptsInfo, AppPgmInfo, Argv0, DynaShell::m_bIsInteractive, DynaShell::m_bSilent, DynaShell::m_bXTrace, DynaShell::m_pDynaBgThread, DynaShell::m_pDynaChain, DynaShell::m_pDynaComm, DynaComm::New(), OptsBaudRate, OptsScript, OptsSerDevUri, OptsSilent, OptsXTrace, PkgInfo, DynaBgThread::RegisterChainAgent(), and DynaShell::ScriptPush().

Referenced by MainInit().

191 {
192  FILE *fp;
193 
194  // name of this process
195  Argv0 = basename(argv[0]);
196 
197  // parse input options
198  argv = OptsGet(Argv0, &PkgInfo, &AppPgmInfo, AppOptsInfo, true,
199  &argc, argv);
200 
201  if( OptsSerDevUri != NULL )
202  {
204 
205  if( shell.m_pDynaComm == NULL )
206  {
207  OptsInvalid(Argv0, "Failed to create interface on %s@%d.",
209  }
210 
211  shell.m_pDynaChain = new DynaChain(*shell.m_pDynaComm);
212 
213  // create background thread and register chain - leave in ready state
214  if( shell.m_pDynaBgThread == NULL )
215  {
216  shell.m_pDynaBgThread = new DynaBgThread();
218  }
219  }
220 
221  if( OptsScript != NULL )
222  {
223  if( access(OptsScript, F_OK|R_OK) != 0 )
224  {
225  OptsInvalid(Argv0, "%s: %s.", OptsScript, strerror(errno));
226  }
227  else if( (fp = fopen(OptsScript, "r")) == NULL )
228  {
229  OptsInvalid(Argv0, "%s: %s.", OptsScript, strerror(errno));
230  }
231  else
232  {
233  shell.ScriptPush(OptsScript, fp);
234  shell.m_bIsInteractive = false;
235  }
236  }
237 
238  shell.m_bXTrace = OptsXTrace;
239  shell.m_bSilent = OptsSilent;
240 }
static bool OptsXTrace
trace script
virtual void RegisterChainAgent(DynaChain *pChain)
Register the Dynamixel chain for control and monitoring.
DynaComm * m_pDynaComm
dynamixel bus communication
Definition: dynashell.h:359
void ScriptPush(const char *sScriptFile, FILE *fp)
Push new script on the stack.
Definition: dynashell.cxx:669
static bool OptsSilent
silence output
static char * OptsScript
script file
static OptsPgmInfo_T AppPgmInfo
Program information.
static DynaComm * New(const char *sUri, int nBaudRate)
Archetype constructor to create a new Dynamixel bus communication derived instance.
Definition: DynaComm.cxx:179
bool m_bIsInteractive
[not] user interactive
Definition: dynashell.h:356
bool m_bXTrace
do [not] trace script
Definition: dynashell.h:357
static const PkgInfo_T PkgInfo
Definition: version.h:45
static int OptsBaudRate
serial baudrate
static char * OptsSerDevUri
the serial device URI
Dynamixel Chain Container Base Class.
Definition: DynaChain.h:75
DynaBgThread * m_pDynaBgThread
dynamixel chain
Definition: dynashell.h:361
static OptsInfo_T AppOptsInfo[]
Command line options information.
bool m_bSilent
do [not] silence non-error responses
Definition: dynashell.h:358
static char * Argv0
the command
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360

Variable Documentation

OptsPgmInfo_T AppPgmInfo
static
Initial value:
=
{
NULL,
"Dynamixel simple shell.",
"The %P provides a simple command-line shell to the Dynamixel interface "
"provided by the library libDynamixel.",
NULL
}

Program information.

Definition at line 86 of file dynashell_main.cxx.

Referenced by MainInitArgs().