Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package

RoadNarrows Dynamixel Library Error and Logging Routines. More...

#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "Dynamixel/Dynamixel.h"

Go to the source code of this file.

Functions

const char * DynaStrError (int ecode)
 Get the error string describing the Dynamixel error code. More...
 
void DynaPrintBuf (FILE *fp, const char *sPreface, byte_t buf[], const char *sFmt, size_t uCount, size_t uNLFreq, uint_t uCol)
 Pretty print a byte buffer to opened file stream. More...
 
void DynaLogServoAlarms (int nServoId, uint_t uAlarms)
 Log servo alarms. More...
 
void DynaLogBuf (const char *sPreface, byte_t buf[], size_t uCount, const char *sFmt)
 Log integer data. More...
 

Detailed Description

RoadNarrows Dynamixel Library Error and Logging Routines.

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 DynaError.h.

Function Documentation

void DynaLogBuf ( const char *  sPreface,
byte_t  buf[],
size_t  uCount,
const char *  sFmt 
)

Log integer data.

Print diagnostic logging of the contents of a buffer of bytes.

Parameters
sPrefaceBuffer preface string.
bufBuffer contents to log.
uCountNumber of entries to log.
sFmtBuffer entry format string.

Definition at line 206 of file DynaError.cxx.

210 {
211  FILE *fp; // log file pointer
212  size_t i; // working index
213 
214  fp = LOG_GET_LOGFP();
215 
216  fprintf(fp, "%sDiag%d: %s", LOG_PREFACE, LOG_GET_THRESHOLD()-1, sPreface);
217  for(i=0; i<uCount; ++i)
218  {
219  if( (i % 16) == 0 )
220  {
221  fprintf(fp, "\n");
222  }
223  fprintf(fp, sFmt, buf[i]);
224  }
225  fprintf(fp, "\n");
226 }
void DynaLogServoAlarms ( int  nServoId,
uint_t  uAlarms 
)

Log servo alarms.

Parameters
nServoIdServo id.
uAlarmsAlarm bits fields.

Definition at line 183 of file DynaError.cxx.

References DYNA_ALARM_NONE, and DynaComm::GetAlarmsString().

184 {
185  FILE *fp;
186  string strAlarms;
187 
188  fp = LOG_GET_LOGFP();
189 
190  fprintf(fp, "%sDiag%d: ", LOG_PREFACE, LOG_GET_THRESHOLD()-1);
191  fprintf(fp, "Servo %d alarms: ", nServoId);
192 
193  if( uAlarms == DYNA_ALARM_NONE )
194  {
195  fprintf(fp, "no alarms;\n");
196  return;
197  }
198 
199  else
200  {
201  strAlarms = DynaComm::GetAlarmsString(uAlarms);
202  fprintf(fp, "%s\n", strAlarms.c_str());
203  }
204 }
#define DYNA_ALARM_NONE
no alarms
Definition: Dynamixel.h:646
static std::string GetAlarmsString(const uint_t uAlarms, const std::string &strSep="; ")
Get a formatted servo alarms string associated with the alarms.
Definition: DynaComm.cxx:312
void DynaPrintBuf ( FILE *  fp,
const char *  sPreface,
byte_t  buf[],
const char *  sFmt,
size_t  uCount,
size_t  uNLFreq,
uint_t  uCol 
)

Pretty print a byte buffer to opened file stream.

Parameters
fpFile pointer.
sPrefaceOptional buffer preface string (set to NULL for no preface).
bufBuffer to print.
sFmtBuffer entry format string.
uCountNumber of entries to print.
uNLFreqNewline frequency (set to 0 for no newlines).
uColColumn alignment number.

Definition at line 155 of file DynaError.cxx.

162 {
163  size_t i;
164 
165  if( sPreface && *sPreface )
166  {
167  fprintf(fp, "%s", sPreface);
168  }
169 
170  for(i=0; i<uCount; ++i)
171  {
172  if( (uNLFreq > 0) && ((i % uNLFreq) == 0) && (i != 0) )
173  {
174  fprintf(fp, "\n%*s", uCol, "");
175  }
176  fprintf(fp, sFmt, buf[i]);
177  }
178  fprintf(fp, "\n");
179 }
const char* DynaStrError ( int  ecode)

Get the error string describing the Dynamixel error code.

The absolute value of the error code is taken prior retrieving the string. An unknown or out-of-range error code will be mapped to DYNA_ECODE_BADEC.

Parameters
ecodeDynamixel error code.
Returns
Returns the appropriate error code string.

Definition at line 141 of file DynaError.cxx.

References DYNA_ECODE_BADEC, and DynaEcodeStrTbl.

Referenced by DynaShellCmdPlay::ControlToGoals(), DynaShell::Error(), DynaShellCmdPlay::PidSetPoint(), and DynaShellCmdPlay::SetRecordGoals().

142 {
143  if( ecode < 0 )
144  {
145  ecode = -ecode;
146  }
147 
148  if( ecode >= arraysize(DynaEcodeStrTbl) )
149  {
150  ecode = DYNA_ECODE_BADEC;
151  }
152  return DynaEcodeStrTbl[ecode];
153 }
static const char * DynaEcodeStrTbl[]
Package Dynamixel Error Code String Table.
Definition: DynaError.cxx:82
#define DYNA_ECODE_BADEC
bad error code
Definition: Dynamixel.h:83