Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdLoadRecording Class Reference

Load recording from file. More...

Inheritance diagram for DynaShellCmdLoadRecording:
DynaShellCmd

Public Member Functions

 DynaShellCmdLoadRecording ()
 Default constructor.
 
virtual ~DynaShellCmdLoadRecording ()
 Default destructor.
 
virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute load 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 Load (DynaShell &shell)
 Load recording. More...
 
int ParseServoList (DynaShell &shell)
 Parse servo list and save in working recording. More...
 
int ParseRecordedData (DynaShell &shell)
 Parse recorded data and save in working recording. More...
 
void SetDateField (DynaShell &shell, const char *sDate)
 Set date value. More...
 
int ParseIntField (DynaShell &shell, const char *sWord, int *pFieldVal)
 Parse integer field. More...
 
char * GetFirstWord ()
 Get the first word in line buffer. More...
 
char * GetNextWord ()
 Get the next word in line buffer. More...
 
char * GetEolPhrase ()
 Get the end-of-line phrase. More...
 
bool LineHasNoData ()
 Test if line is all white space or a comment. More...
 
bool GetLine ()
 Read the next line of data. More...
 
int Init (DynaShell &shell, char *sFileName)
 Initialize data prior to file loading. More...
 
void Cleanup (DynaShell &shell)
 Clean up data after to file loading parsing. 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

FILE * m_fp
 open file pointer
 
char * m_sFileName
 file name
 
int m_nLineNum
 line number
 
int m_nColNum
 column number in line
 
char * m_sCursor
 current line parse cursor
 
char * m_sField
 current field being parsed
 
char * m_buf
 input buffer
 
size_t m_sizeBuf
 size of input buffer
 
int m_nNumServos
 NUM_SERVOS value.
 
int m_nNumRecords
 NUM_RECORDS value.
 
int m_nSamplePeriod
 SAMPLE_PERIOD value.
 
char * m_sDate
 DATE value.
 
DynaRecordingm_pRecording
 working and new recording
 
- 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

Load recording from file.

Definition at line 413 of file dynashell_cmd_train.cxx.

Member Function Documentation

void DynaShellCmdLoadRecording::Cleanup ( DynaShell shell)
inlineprotected

Clean up data after to file loading parsing.

Parameters
shellDynamixel shell.

Definition at line 1076 of file dynashell_cmd_train.cxx.

1077  {
1078  if( m_fp != NULL)
1079  {
1080  fclose(m_fp);
1081  m_fp = NULL;
1082  }
1083 
1084  if( m_sFileName != NULL )
1085  {
1086  delete[] m_sFileName;
1087  m_sFileName = NULL;
1088  }
1089 
1090  if( m_buf != NULL )
1091  {
1092  delete[] m_buf;
1093  m_buf = NULL;
1094  }
1095 
1096  if( m_sDate != NULL )
1097  {
1098  delete[] m_sDate;
1099  m_sDate = NULL;
1100  }
1101 
1102  // load failed, delete associated recording
1103  if( m_pRecording != NULL )
1104  {
1105  delete m_pRecording;
1106  m_pRecording = NULL;
1107  }
1108 
1109  m_nLineNum = 0;
1110  m_nColNum = 0;
1111  m_sCursor = NULL;
1112  m_sField = NULL;
1113  m_nNumServos = 0;
1114  m_nNumRecords = 0;
1115  m_nSamplePeriod = 0;
1116  }
int m_nSamplePeriod
SAMPLE_PERIOD value.
int m_nNumServos
NUM_SERVOS value.
DynaRecording * m_pRecording
working and new recording
char * m_sField
current field being parsed
char * m_sCursor
current line parse cursor
FILE * m_fp
open file pointer
int m_nColNum
column number in line
int m_nNumRecords
NUM_RECORDS value.
virtual void DynaShellCmdLoadRecording::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Execute load recording.

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

Implements DynaShellCmd.

Definition at line 456 of file dynashell_cmd_train.cxx.

References DYNA_OK, and TRY.

457  {
458  FILE *fp;
459 
460  TRY( ChkArgCnt(shell, argc) );
461 
462  if( Init(shell, argv[0]) != DYNA_OK )
463  {
464  return;
465  }
466 
467  Load(shell);
468 
469  Cleanup(shell);
470  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
int Init(DynaShell &shell, char *sFileName)
Initialize data prior to file loading.
void Cleanup(DynaShell &shell)
Clean up data after to file loading parsing.
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 Load(DynaShell &shell)
Load recording.
char* DynaShellCmdLoadRecording::GetEolPhrase ( )
inlineprotected

Get the end-of-line phrase.

The eol phrase is defined as a set of characters bracketed by non-white space characters.

Returns
Returns pointer to start of phrase if a phrase is found.
Else returns NULL.

Definition at line 954 of file dynashell_cmd_train.cxx.

955  {
956  char *sPhrase;
957  char *s;
958 
959  m_nColNum = (int)(m_sCursor - m_buf) + 1;
960 
961  while( *m_sCursor && isspace((int)*m_sCursor) )
962  {
963  ++m_sCursor;
964  ++m_nColNum;
965  }
966 
967  if( *m_sCursor == 0 )
968  {
969  return NULL;
970  }
971 
972  sPhrase = m_sCursor;
973 
974  while( *m_sCursor && (*m_sCursor != '\n') )
975  {
976  ++m_sCursor;
977  }
978 
979  if( *m_sCursor != 0 )
980  {
981  ++m_sCursor;
982  }
983 
984  s = m_sCursor - 1;
985 
986  while( (s > sPhrase) && isspace((int)*s) )
987  {
988  --s;
989  }
990 
991  *++s = 0;
992 
993  //fprintf(stderr, "DBG: phrase=%s\n", sPhrase);
994 
995  return sPhrase;
996  }
char * m_sCursor
current line parse cursor
int m_nColNum
column number in line
char* DynaShellCmdLoadRecording::GetFirstWord ( )
inlineprotected

Get the first word in line buffer.

A word is defined as characters separated by white space.

Returns
Returns pointer to start of word if a word is found.
Else returns NULL.

Definition at line 893 of file dynashell_cmd_train.cxx.

894  {
895  m_sCursor = m_buf;
896  m_nColNum = 1;
897 
898  return GetNextWord();
899  }
char * GetNextWord()
Get the next word in line buffer.
char * m_sCursor
current line parse cursor
int m_nColNum
column number in line
bool DynaShellCmdLoadRecording::GetLine ( )
inlineprotected

Read the next line of data.

Returns
Returns true if line found, false otherwise.

Definition at line 1026 of file dynashell_cmd_train.cxx.

1027  {
1028  if( getline(&m_buf, &m_sizeBuf, m_fp) != -1 )
1029  {
1030  m_nLineNum++;
1031  m_nColNum = 0;
1032  return true;
1033  }
1034  else
1035  {
1036  return false;
1037  }
1038  }
size_t m_sizeBuf
size of input buffer
FILE * m_fp
open file pointer
int m_nColNum
column number in line
char* DynaShellCmdLoadRecording::GetNextWord ( )
inlineprotected

Get the next word in line buffer.

A word is defined as characters separated by white space.

Returns
Returns pointer to start of word if a word is found.
Else returns NULL.

Definition at line 910 of file dynashell_cmd_train.cxx.

911  {
912  char *sWord;
913 
914  m_nColNum = (int)(m_sCursor - m_buf) + 1;
915 
916  while( *m_sCursor && isspace((int)*m_sCursor) )
917  {
918  ++m_sCursor;
919  ++m_nColNum;
920  }
921 
922  if( *m_sCursor == 0 )
923  {
924  return NULL;
925  }
926 
927  sWord = m_sCursor;
928 
929  while( *m_sCursor && !isspace((int)*m_sCursor) )
930  {
931  ++m_sCursor;
932  }
933 
934  if( *m_sCursor != 0 )
935  {
936  *m_sCursor++ = 0;
937  }
938 
939  //fprintf(stderr, "DBG: word=%s\n", sWord);
940 
941  return sWord;
942  }
char * m_sCursor
current line parse cursor
int m_nColNum
column number in line
int DynaShellCmdLoadRecording::Init ( DynaShell shell,
char *  sFileName 
)
inlineprotected

Initialize data prior to file loading.

Parameters
shellDynamixel shell.
sFileNameFile to open.
Returns
On success, DYNA_OK is returned.
On error, the appropriate < 0 negated Dynamixel Error Code is returned.

Definition at line 1048 of file dynashell_cmd_train.cxx.

References DYNA_ECODE_BADF, DYNA_OK, DynaShell::Error(), and newstr().

1049  {
1050  if( (m_fp = fopen(sFileName, "r")) == NULL )
1051  {
1052  shell.Error("%s: cannot open.", sFileName);
1053  return -DYNA_ECODE_BADF;
1054  }
1055 
1056  m_sFileName = newstr(sFileName);
1057  m_nLineNum = 0;
1058  m_nColNum = 0;
1059  m_sizeBuf = 4096;
1060  m_buf = new char[m_sizeBuf];
1061 
1062  m_sDate = NULL;
1063  m_nNumServos = 0;
1064  m_nNumRecords = 0;
1065  m_nSamplePeriod = 0;
1067 
1068  return DYNA_OK;
1069  }
int m_nSamplePeriod
SAMPLE_PERIOD value.
char * newstr(const char *s)
Allocate new duplicated string.
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
int m_nNumServos
NUM_SERVOS value.
DynaRecording * m_pRecording
working and new recording
size_t m_sizeBuf
size of input buffer
FILE * m_fp
open file pointer
#define DYNA_ECODE_BADF
no comm object or not open
Definition: Dynamixel.h:88
int m_nColNum
column number in line
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
int m_nNumRecords
NUM_RECORDS value.
bool DynaShellCmdLoadRecording::LineHasNoData ( )
inlineprotected

Test if line is all white space or a comment.

Returns
Returns true if line contains no data, false otherwise.

Definition at line 1003 of file dynashell_cmd_train.cxx.

1004  {
1005  char *s;
1006 
1007  for(s=m_buf; *s; ++s)
1008  {
1009  if( *s == '#' )
1010  {
1011  return true;
1012  }
1013  else if( !isspace((int)*s) )
1014  {
1015  return false;
1016  }
1017  }
1018  return true;
1019  }
void DynaShellCmdLoadRecording::Load ( DynaShell shell)
inlineprotected

Load recording.

Parameters
shellDynamixel shell.

Definition at line 517 of file dynashell_cmd_train.cxx.

References DYNA_ECODE_PARSE, DYNA_ID_NUMOF, DYNA_OK, DynaShell::Error(), DynaRecording::GetDate(), DynaRecording::GetNumOfRecords(), DynaRecording::GetNumOfServosInRecording(), DynaRecording::GetSamplePeriod(), DynaShell::m_pRecording, DynaRecording::MaxRecords, DynaShell::RecordingReplace(), DynaShell::Response(), DynaRecording::SetSamplePeriod(), and DynaShell::Warning().

518  {
519  int n;
520  int rc = DYNA_OK;
521 
522  while( (rc == DYNA_OK) && GetLine() )
523  {
525 
526  // empty line
527  if( m_sField == NULL )
528  {
529  continue;
530  }
531 
532  // comment
533  else if( *m_sField == '#' )
534  {
535  continue;
536  }
537 
538  // version - ignored for now
539  else if( !strcmp(m_sField, "VERSION") )
540  {
541  continue;
542  }
543 
544  // recording date
545  else if( !strcmp(m_sField, "DATE") )
546  {
547  SetDateField(shell, GetEolPhrase());
548  }
549 
550  // number of servos recorded
551  else if( !strcmp(m_sField, "NUM_SERVOS") )
552  {
553  if( ParseIntField(shell, GetNextWord(), &m_nNumServos) != DYNA_OK )
554  {
555  rc = -DYNA_ECODE_PARSE;
556  }
557  else if( (m_nNumServos <= 0) || (m_nNumServos > DYNA_ID_NUMOF) )
558  {
559  shell.Error("Line %dc%d: Field %s: Value %d: Out-of-range.",
561  rc = -DYNA_ECODE_PARSE;
562  }
563  }
564 
565  // list of servo id, model number pairs
566  else if( !strcmp(m_sField, "SERVOS") )
567  {
568  rc = ParseServoList(shell) != DYNA_OK;
569  }
570 
571  // sample period (msec)
572  else if( !strcmp(m_sField, "SAMPLE_PERIOD") )
573  {
574  if( ParseIntField(shell, GetNextWord(), &m_nSamplePeriod) != DYNA_OK )
575  {
576  rc = -DYNA_ECODE_PARSE;
577  }
578  else if( m_nSamplePeriod <= 0 )
579  {
580  shell.Error("Line %dc%d: Field %s: Value %d: Out-of-range.",
582  rc = -DYNA_ECODE_PARSE;
583  }
584  else
585  {
587  }
588  }
589 
590  // number of records
591  else if( !strcmp(m_sField, "NUM_RECORDS") )
592  {
593  if( ParseIntField(shell, GetNextWord(), &m_nNumRecords) != DYNA_OK )
594  {
595  rc = -DYNA_ECODE_PARSE;
596  }
597  else if( (m_nNumRecords <= 0) ||
599  {
600  shell.Error("Line %dc%d: Field %s: Value %d: Out-of-range.",
602  rc = -DYNA_ECODE_PARSE;
603  }
604  }
605 
606  // recorded servo data - last extended field
607  else if( !strcmp(m_sField, "DATA") )
608  {
609  //
610  // Final checks and parsing
611  //
612  if( m_nNumServos == 0 )
613  {
614  shell.Error("Field NUM_SERVOS: Not specified in file header.",
615  m_sField);
616  rc = -DYNA_ECODE_PARSE;
617  }
618 
620  {
621  shell.Error(
622  "Field SERVOS lists %d servos != Field NUM_SERVOS value of %d.",
624  rc = -DYNA_ECODE_PARSE;
625  }
626 
627  else if( m_nNumRecords == 0 )
628  {
629  shell.Error("Field NUM_RECORDS: Not specified in file header.");
630  rc = -DYNA_ECODE_PARSE;
631  }
632 
633  else if( m_nSamplePeriod == 0 )
634  {
635  shell.Error("Field SAMPLE_PERIOD: Not specified in file header.");
636  rc = -DYNA_ECODE_PARSE;
637  }
638 
639  else
640  {
641  rc = ParseRecordedData(shell);
642  }
643 
644  break;
645  }
646 
647  else
648  {
649  shell.Warning("Line %d: Field %s: Unknown field - ignoring.",
651  }
652  }
653 
654  //
655  // If ok, then the recording was successfully loaded from the file.
656  //
657  if( rc == DYNA_OK )
658  {
659  if( m_sDate == NULL )
660  {
661  shell.Warning("Field DATE: Not specified in file header.");
662  SetDateField(shell, "Unknown File Date");
663  }
664 
666  m_pRecording = NULL; // make sure the cleanup does not delete this
667 
668  shell.Response("Loaded recording from file %s\n", m_sFileName);
669  shell.Response(" Recording date: %s.\n",
670  shell.m_pRecording->GetDate());
671  shell.Response(" Number of servos: %d\n",
673  shell.Response(" Number of records: %d\n",
674  shell.m_pRecording->GetNumOfRecords());
675  shell.Response(" Sample period: %dms.\n",
676  shell.m_pRecording->GetSamplePeriod());
677  }
678  }
bool GetLine()
Read the next line of data.
int m_nSamplePeriod
SAMPLE_PERIOD value.
virtual int GetNumOfRecords()
Get the number of records in the recording.
int ParseRecordedData(DynaShell &shell)
Parse recorded data and save in working recording.
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
int m_nNumServos
NUM_SERVOS value.
char * GetNextWord()
Get the next word in line buffer.
char * GetFirstWord()
Get the first word in line buffer.
void RecordingReplace(DynaRecording *pNewRecording)
Replace recording.
Definition: dynashell.h:397
DynaRecording * m_pRecording
working and new recording
virtual int SetSamplePeriod(int nSamplePeriod)
Set the sample period of the recording.
#define DYNA_ECODE_PARSE
Shell parse error.
Definition: Dynamixel.h:101
#define DYNA_ID_NUMOF
number of unique servo id&#39;s
Definition: Dynamixel.h:148
DynaRecording * m_pRecording
dynamixel recording
Definition: dynashell.h:362
virtual int GetSamplePeriod() const
Get the sample period of the recording.
void Response(const char *sFmt,...)
Print formatted success response.
Definition: dynashell.cxx:763
char * m_sField
current field being parsed
virtual const char * GetDate() const
Get the recording data.
void Warning(const char *sFmt,...)
Issue warning.
Definition: dynashell.cxx:781
int ParseServoList(DynaShell &shell)
Parse servo list and save in working recording.
char * GetEolPhrase()
Get the end-of-line phrase.
int ParseIntField(DynaShell &shell, const char *sWord, int *pFieldVal)
Parse integer field.
int m_nColNum
column number in line
virtual int GetNumOfServosInRecording()
Get the number of servos in the recording.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
int m_nNumRecords
NUM_RECORDS value.
void SetDateField(DynaShell &shell, const char *sDate)
Set date value.
static const int MaxRecords
maximum number of records
int DynaShellCmdLoadRecording::ParseIntField ( DynaShell shell,
const char *  sWord,
int *  pFieldVal 
)
inlineprotected

Parse integer field.

String field can be specified in hexidecimal, decimal, or octal.

Parameters
shellDynamixel shell.
sWordWord to parse.
[out]pFieldValConverted value.
Returns
On success, DYNA_OK is returned.
On error, the appropriate < 0 negated Dynamixel Error Code is returned.

Definition at line 864 of file dynashell_cmd_train.cxx.

References DYNA_ECODE_PARSE, DYNA_OK, and DynaShell::Error().

865  {
866  if( sWord == NULL )
867  {
868  shell.Error("Line %dc%d: Field %s: No field value found.",
870  return -DYNA_ECODE_PARSE;
871  }
872  else if( sscanf(sWord, "%i", pFieldVal) != 1 )
873  {
874  shell.Error("Line %dc%d: Field %s: Value %s: Not an integer.",
875  m_nLineNum, m_nColNum, m_sField, sWord);
876  return -DYNA_ECODE_PARSE;
877  }
878  else
879  {
880  return DYNA_OK;
881  }
882  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
#define DYNA_ECODE_PARSE
Shell parse error.
Definition: Dynamixel.h:101
char * m_sField
current field being parsed
int m_nColNum
column number in line
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
int DynaShellCmdLoadRecording::ParseRecordedData ( DynaShell shell)
inlineprotected

Parse recorded data and save in working recording.

Parameters
shellDynamixel shell.
Returns
On success, DYNA_OK is returned.
On error, the appropriate < 0 negated Dynamixel Error Code is returned.

Definition at line 735 of file dynashell_cmd_train.cxx.

References DynaRecording::AddFieldTuple(), DynaRecording::AddRecord(), DYNA_ECODE_PARSE, DYNA_ID_NONE, DYNA_OK, DynaRecording::END, DynaShell::Error(), DynaRecording::GetServoId(), and DynaRecording::MaxRecords.

736  {
737  int nRecNum;
738  int nFldNum;
739  char *sWord;
740  int nServoId;
741  int nPos;
742  int nSpeed;
743  int rc;
744 
745  while( GetLine() )
746  {
747  if( LineHasNoData() )
748  {
749  continue;
750  }
751 
752  m_sField = (char *)"DATA"; // multiline parsing clobbers this
753 
754  nRecNum = m_pRecording->AddRecord();
755 
756  if( nRecNum == DynaRecording::END )
757  {
758  shell.Error(
759  "Line %d: Field DATA: Exceeded maximum number of %d records.",
761  return -DYNA_ECODE_PARSE;
762  }
763 
764  else if( nRecNum >= m_nNumRecords )
765  {
766  shell.Error(
767  "Line %d: Field DATA: Exceeded NUM_RECORDS value of %d records.",
769  return -DYNA_ECODE_PARSE;
770  }
771 
772  for(sWord = GetFirstWord(), nFldNum=0;
773  sWord != NULL;
774  sWord = GetNextWord(), ++nFldNum)
775  {
776  if( nFldNum >= m_nNumServos )
777  {
778  shell.Error(
779  "Line %dc%d: Field %s: Exceeded NUM_SERVOS value of %d servos.",
781  return -DYNA_ECODE_PARSE;
782  }
783 
784  // read 2-tuple position, speed
785  if( (rc = ParseIntField(shell, sWord, &nPos)) != DYNA_OK )
786  {
787  return -DYNA_ECODE_PARSE;
788  }
789 
790  if( (rc = ParseIntField(shell, GetNextWord(), &nSpeed)) != DYNA_OK )
791  {
792  return -DYNA_ECODE_PARSE;
793  }
794 
795  if( (nServoId = m_pRecording->GetServoId(nFldNum)) == DYNA_ID_NONE )
796  {
797  shell.Error("Line %dc%d: Field %s: No registered servo at pos %d.",
798  m_nLineNum, m_nColNum, m_sField, nFldNum);
799  return -DYNA_ECODE_PARSE;
800  }
801 
802  rc = m_pRecording->AddFieldTuple(nRecNum, nServoId, nPos, nSpeed);
803 
804  if( rc == DynaRecording::END )
805  {
806  shell.Error("Line %dc%d: Field %s: Cannot add any more fields.",
808  return -DYNA_ECODE_PARSE;
809  }
810  }
811 
812  if( nFldNum < m_nNumServos )
813  {
814  shell.Error(
815  "Line %d: Field %s: Only %d (pos,speed) 2-tuples found, expected %d.",
816  m_nLineNum, m_sField, nFldNum, m_nNumServos);
817  return -DYNA_ECODE_PARSE;
818  }
819  }
820 
821  if( nRecNum+1 < m_nNumRecords )
822  {
823  shell.Error("Line %d: Field %s: Only %d records found, expected %d.",
824  m_nLineNum, m_sField, nRecNum+1, m_nNumRecords);
825  return -DYNA_ECODE_PARSE;
826  }
827 
828  return DYNA_OK;
829  }
bool GetLine()
Read the next line of data.
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
int m_nNumServos
NUM_SERVOS value.
char * GetNextWord()
Get the next word in line buffer.
virtual int AddRecord()
Add a new empty record to the recording.
char * GetFirstWord()
Get the first word in line buffer.
virtual int AddFieldTuple(int nRecNum, int nServoId, int nPos, int nSpeed)
Add new recording field tuple.
DynaRecording * m_pRecording
working and new recording
virtual const int GetServoId(int nFldNum)
Get the servo id associated with the given field number.
#define DYNA_ECODE_PARSE
Shell parse error.
Definition: Dynamixel.h:101
static const int END
past-the-end mark
char * m_sField
current field being parsed
bool LineHasNoData()
Test if line is all white space or a comment.
int ParseIntField(DynaShell &shell, const char *sWord, int *pFieldVal)
Parse integer field.
int m_nColNum
column number in line
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
int m_nNumRecords
NUM_RECORDS value.
static const int MaxRecords
maximum number of records
int DynaShellCmdLoadRecording::ParseServoList ( DynaShell shell)
inlineprotected

Parse servo list and save in working recording.

Parameters
shellDynamixel shell.
Returns
On success, DYNA_OK is returned.
On error, the appropriate < 0 negated Dynamixel Error Code is returned.

Definition at line 687 of file dynashell_cmd_train.cxx.

References DYNA_ECODE_PARSE, DYNA_ID_MAX, DYNA_ID_MIN, DYNA_OK, DynaShell::Error(), and DynaRecording::RegisterServoInfo().

688  {
689  char *sWord;
690  int nServoId;
691  uint_t uModelNum;
692  int rc = DYNA_OK;
693 
694  while( (rc == DYNA_OK) && ((sWord = GetNextWord()) != NULL) )
695  {
696  // 2-tuple servo_id, model_num
697  if( (rc = ParseIntField(shell, sWord, &nServoId)) == DYNA_OK )
698  {
699  rc = ParseIntField(shell, GetNextWord(), (int *)&uModelNum);
700  }
701 
702  if( rc != DYNA_OK )
703  {
704  }
705 
706  else if( (nServoId < DYNA_ID_MIN) || (nServoId > DYNA_ID_MAX) )
707  {
708  shell.Error("Line %dc%d: Field %s: Value %d': Out-of-range.",
709  m_nLineNum, m_nColNum, m_sField, nServoId);
710  rc = -DYNA_ECODE_PARSE;
711  }
712 
713  else
714  {
715  rc = m_pRecording->RegisterServoInfo(nServoId, uModelNum);
716 
717  if( rc != DYNA_OK )
718  {
719  shell.Error("Line %dc%d: Field %s: Servo %d: Duplicate.",
720  m_nLineNum, m_nColNum, m_sField, nServoId);
721  }
722  }
723  }
724 
725  return rc;
726  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
char * GetNextWord()
Get the next word in line buffer.
DynaRecording * m_pRecording
working and new recording
#define DYNA_ID_MIN
minimum servo id
Definition: Dynamixel.h:146
#define DYNA_ECODE_PARSE
Shell parse error.
Definition: Dynamixel.h:101
#define DYNA_ID_MAX
maximum servo id
Definition: Dynamixel.h:147
char * m_sField
current field being parsed
int ParseIntField(DynaShell &shell, const char *sWord, int *pFieldVal)
Parse integer field.
int m_nColNum
column number in line
virtual int RegisterServoInfo(int nServoId, uint_t uModelNum)
Register servo information in recording header.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
void DynaShellCmdLoadRecording::SetDateField ( DynaShell shell,
const char *  sDate 
)
inlineprotected

Set date value.

Parameters
shellDynamixel shell.
sDateDate string.
Returns
On success, DYNA_OK is returned.
On error, the appropriate < 0 negated Dynamixel Error Code is returned.

Definition at line 839 of file dynashell_cmd_train.cxx.

References newstr(), and DynaRecording::SetDate().

840  {
841  if( m_sDate != NULL )
842  {
843  delete[] m_sDate;
844  m_sDate = NULL;
845  }
846  if( (sDate != NULL) && (*sDate != 0) )
847  {
848  m_sDate = newstr(sDate);
850  }
851  }
char * newstr(const char *s)
Allocate new duplicated string.
DynaRecording * m_pRecording
working and new recording
virtual void SetDate(const char *sDate)
virtual char* DynaShellCmdLoadRecording::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 487 of file dynashell_cmd_train.cxx.

References ReadLine::FileCompletionGenerator().

492  {
493  return ReadLine::FileCompletionGenerator(sText, nState);
494  }
static char * FileCompletionGenerator(const char *sText, int nState)
File name tab completion generator.

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