Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdSaveRecording Class Reference

Save recording to file. More...

Inheritance diagram for DynaShellCmdSaveRecording:
DynaShellCmd

Public Member Functions

 DynaShellCmdSaveRecording ()
 Default constructor.
 
virtual ~DynaShellCmdSaveRecording ()
 Default destructor.
 
virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute save recording. 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 Save (DynaShell &shell, FILE *fp)
 Save recording. 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...
 

Additional Inherited Members

- 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

Save recording to file.

Definition at line 1127 of file dynashell_cmd_train.cxx.

Member Function Documentation

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

Execute save recording.

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

Implements DynaShellCmd.

Definition at line 1156 of file dynashell_cmd_train.cxx.

References DynaShell::Error(), DynaRecording::GetNumOfRecords(), DynaShell::m_pRecording, DynaShell::Response(), and TRY.

1157  {
1158  FILE *fp;
1159 
1160  TRY( ChkArgCnt(shell, argc) );
1161 
1162  if( (shell.m_pRecording == NULL) ||
1163  (shell.m_pRecording->GetNumOfRecords() == 0) )
1164  {
1165  shell.Error("No recording to save.");
1166  return;
1167  }
1168 
1169  if( (fp = fopen(argv[0], "w")) == NULL )
1170  {
1171  shell.Error("%s: cannot open.", argv[1]);
1172  return;
1173  }
1174 
1175  Save(shell, fp);
1176 
1177  fclose(fp);
1178 
1179  shell.Response("Saved recording to file %s\n", argv[0]);
1180  }
virtual int GetNumOfRecords()
Get the number of records in the recording.
void Save(DynaShell &shell, FILE *fp)
Save recording.
DynaRecording * m_pRecording
dynamixel recording
Definition: dynashell.h:362
void Response(const char *sFmt,...)
Print formatted success response.
Definition: dynashell.cxx:763
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
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
void DynaShellCmdSaveRecording::Save ( DynaShell shell,
FILE *  fp 
)
inlineprotected

Save recording.

Parameters
shellDynamixel shell.
fpFile pointer.

Definition at line 1214 of file dynashell_cmd_train.cxx.

References DynaRecording::END, DynaRecording::FirstField(), DynaRecording::FirstRecord(), DynaRecording::GetDate(), DynaRecording::GetField(), DynaRecording::GetNumOfRecords(), DynaRecording::GetNumOfServosInRecording(), DynaRecording::GetSamplePeriod(), DynaRecording::GetServoId(), DynaRecording::GetServoModelNumber(), DynaRecord::FieldTuple_T::m_nPos, DynaRecord::FieldTuple_T::m_nSpeed, DynaShell::m_pRecording, DynaRecording::NextField(), and DynaRecording::NextRecord().

1215  {
1216  DynaRecording *pRecording = shell.m_pRecording;
1217  int nRecNum;
1218  int nFldNum;
1219  int nServoId;
1220  DynaRecord::FieldTuple_T tupRec;
1221 
1222  fprintf(fp, "# .DYD v1.0 - Dynamixel Data file format\n");
1223  fprintf(fp, "VERSION 1.0\n");
1224  fprintf(fp, "DATE %s\n", pRecording->GetDate());
1225  fprintf(fp, "NUM_SERVOS %d\n", pRecording->GetNumOfServosInRecording());
1226  fprintf(fp, "SERVOS");
1227 
1228  for(nFldNum = pRecording->FirstField(0);
1229  nFldNum != DynaRecording::END;
1230  nFldNum = pRecording->NextField(0, nFldNum))
1231  {
1232  nServoId = pRecording->GetServoId(nFldNum);
1233  fprintf(fp, " %d 0x%04x",
1234  nServoId,
1235  pRecording->GetServoModelNumber(nServoId));
1236  }
1237  fprintf(fp, "\n");
1238 
1239  fprintf(fp, "SAMPLE_PERIOD %d\n", pRecording->GetSamplePeriod());
1240  fprintf(fp, "NUM_RECORDS %d\n", pRecording->GetNumOfRecords());
1241  fprintf(fp, "DATA ascii\n");
1242 
1243  for(nRecNum = pRecording->FirstRecord();
1244  nRecNum != DynaRecording::END;
1245  nRecNum = pRecording->NextRecord(nRecNum))
1246  {
1247  for(nFldNum = pRecording->FirstField(nRecNum);
1248  nFldNum != DynaRecording::END;
1249  nFldNum = pRecording->NextField(nRecNum, nFldNum))
1250  {
1251  tupRec = pRecording->GetField(nRecNum, nFldNum);
1252  fprintf(fp, " %4d %-4d", tupRec.m_nPos, tupRec.m_nSpeed);
1253  }
1254  fprintf(fp, "\n");
1255  }
1256  }
virtual int GetNumOfRecords()
Get the number of records in the recording.
Record Field Tuple Structure Type.
virtual const int GetServoId(int nFldNum)
Get the servo id associated with the given field number.
DynaRecording * m_pRecording
dynamixel recording
Definition: dynashell.h:362
virtual uint_t GetServoModelNumber(int nServoId)
Get the registered servo model number.
static const int END
past-the-end mark
virtual int GetSamplePeriod() const
Get the sample period of the recording.
virtual const char * GetDate() const
Get the recording data.
virtual int FirstRecord()
Get the first record number in the recording.
virtual int NextField(int nRecNum, int nFldNum)
Get the next field number in the record after the given field number.
virtual int GetNumOfServosInRecording()
Get the number of servos in the recording.
virtual int NextRecord(int nRecNum)
Get the next record number in the recording after the given record number.
virtual const DynaRecord::FieldTuple_T & GetField(const int nRecNum, const int nFldNum) const
Get the given recorded field tuple.
virtual int FirstField(int nRecNum)
Get the first field number in the given record.
virtual char* DynaShellCmdSaveRecording::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes <file>

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 1197 of file dynashell_cmd_train.cxx.

References ReadLine::FileCompletionGenerator().

1202  {
1203  return ReadLine::FileCompletionGenerator(sText, nState);
1204  }
static char * FileCompletionGenerator(const char *sText, int nState)
File name tab completion generator.

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