Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaError.cxx File Reference

Error and logging handling routines. More...

#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <string>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/new.h"
#include "rnr/units.h"
#include "Dynamixel/dxl/dxl.h"
#include "Dynamixel/Dynamixel.h"
#include "Dynamixel/DynaError.h"
#include "Dynamixel/DynaComm.h"
#include "DynaLibInternal.h"

Go to the source code of this file.

Functions

int DynaMapDxlToEcode (int nDxlError)
 Map DXL library error code to Dynamixel error code. More...
 
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...
 

Variables

static const char * DynaEcodeStrTbl []
 Package Dynamixel Error Code String Table. More...
 

Detailed Description

Error and logging handling routines.

LastChangedDate
2015-03-13 13:28:02 -0600 (Fri, 13 Mar 2015)
Rev
3890
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.cxx.

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
int DynaMapDxlToEcode ( int  nDxlError)

Map DXL library error code to Dynamixel error code.

Parameters
nDxlErrorDXL error code.
Returns
Dynamixel library error code.

Definition at line 117 of file DynaError.cxx.

References DXL_COMM_RXCORRUPT, DXL_COMM_RXFAIL, DXL_COMM_RXTIMEOUT, DXL_COMM_TXERROR, DXL_COMM_TXFAIL, DYNA_ECODE_ECOMM, DYNA_ECODE_RX_BAD_PKT, DYNA_ECODE_RX_FAIL, DYNA_ECODE_RX_TIMEOUT, DYNA_ECODE_TX_ERROR, and DYNA_ECODE_TX_FAIL.

Referenced by newstr(), DynaCommSerial::Read16(), DynaCommSerial::Read8(), DynaCommSerial::Reset(), DynaCommSerial::SyncWrite(), DynaCommSerial::Write16(), and DynaCommSerial::Write8().

118 {
119  switch( nDxlError )
120  {
121  case DXL_COMM_TXFAIL:
122  return DYNA_ECODE_TX_FAIL;
123  case DXL_COMM_RXFAIL:
124  return DYNA_ECODE_RX_FAIL;
125  case DXL_COMM_TXERROR:
126  return DYNA_ECODE_TX_ERROR;
127  case DXL_COMM_RXTIMEOUT:
128  return DYNA_ECODE_RX_TIMEOUT;
129  case DXL_COMM_RXCORRUPT:
130  return DYNA_ECODE_RX_BAD_PKT;
131  default:
132  return DYNA_ECODE_ECOMM;
133  }
134 }
#define DXL_COMM_TXFAIL
transmit failure error
Definition: dxl.h:110
#define DYNA_ECODE_RX_TIMEOUT
dynamixel receive packet time out
Definition: Dynamixel.h:93
#define DXL_COMM_TXERROR
packed transmit packet format error
Definition: dxl.h:112
#define DYNA_ECODE_RX_BAD_PKT
dynamixel receive bad packet
Definition: Dynamixel.h:94
#define DXL_COMM_RXTIMEOUT
receive timeout error
Definition: dxl.h:114
#define DYNA_ECODE_ECOMM
dynamixel communication error
Definition: Dynamixel.h:89
#define DYNA_ECODE_TX_ERROR
dynamixel transmit packet error
Definition: Dynamixel.h:92
#define DXL_COMM_RXCORRUPT
receive corrupted packet
Definition: dxl.h:115
#define DXL_COMM_RXFAIL
receive failure error
Definition: dxl.h:111
#define DYNA_ECODE_TX_FAIL
dynamixel transmit packet failure
Definition: Dynamixel.h:90
#define DYNA_ECODE_RX_FAIL
dynamixel receive packet failure
Definition: Dynamixel.h:91
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

Variable Documentation

const char* DynaEcodeStrTbl[]
static
Initial value:
=
{
"Ok",
"Error",
"System error",
"Internal error",
"Invalid error code",
"Invalid units",
"Invalid value",
"No servo",
"Serial device error",
"Not open",
"Communication error",
"Transmit packet failure",
"Receive packet failure",
"Transmit packet error",
"Receive packet time out",
"Received corrupted packet",
"Servo errored condition",
"Resource not available",
"feature/function no supported",
"Linked servos error",
"Operation not permitted on slave servo",
"BotSense proxy error",
"Shell parse error",
"Shell run-time error",
"Cannot execute"
}

Package Dynamixel Error Code String Table.

Table is indexed by error codes (see Package Error Codes). Keep in sync.

Definition at line 82 of file DynaError.cxx.

Referenced by DynaStrError().