52 #include <sys/types.h> 66 #include "rnr/rnrconfig.h" 98 "Operation timed out",
100 "No resource available",
103 "Permissions denied",
104 "Dynamixel chain or servo error",
110 "Robot is in an alarmed state",
111 "Operation interrupted",
112 "Robotic link(s) movement obstructed",
113 "Robot emergency stopped",
125 int ec = ecode >= 0 ? ecode : -ecode;
129 ec = HEK_ECODE_BADEC;
141 sscanf(str.c_str(),
"%d.%d.%d", &nMajor, &nMinor, &nRevision);
148 if( lhs.tv_sec < rhs.tv_sec )
152 else if( (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_usec < rhs.tv_usec) )
164 return (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_usec == rhs.tv_usec)?
170 return !((lhs < rhs) || (lhs == rhs));
173 struct timeval
hekateros::operator+(const struct timeval& op1,
174 const struct timeval& op2)
176 struct timeval sum = op1;
178 sum.tv_sec += op2.tv_sec;
179 sum.tv_usec += op2.tv_usec;
181 if( sum.tv_usec > MILLION )
184 sum.tv_usec -= MILLION;
190 struct timeval hekateros::operator-(const struct timeval& op1,
191 const struct timeval& op2)
195 diff.tv_sec = op1.tv_sec - op2.tv_sec;
197 if( op1.tv_usec >= op2.tv_usec)
199 diff.tv_usec = op1.tv_usec - op2.tv_usec;
204 diff.tv_usec = MILLION + op1.tv_usec - op2.tv_usec;
212 struct timeval dt = t1 - t0;
214 return (
long)dt.tv_sec * MILLION + (long)dt.tv_usec;
221 return (
double)
dt_usec(t1, t0) / (double)MILLION;
225 return -(double)
dt_usec(t0, t1) / (double)MILLION;
230 const struct timespec& rhs)
232 if( lhs.tv_sec < rhs.tv_sec )
236 else if( (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_nsec < rhs.tv_nsec) )
247 const struct timespec& rhs)
249 return (lhs.tv_sec == rhs.tv_sec) && (lhs.tv_nsec == rhs.tv_nsec)?
254 const struct timespec& rhs)
256 return !((lhs < rhs) || (lhs == rhs));
259 struct timespec hekateros::operator+(const struct timespec& op1,
260 const struct timespec& op2)
262 struct timespec sum = op1;
264 sum.tv_sec += op2.tv_sec;
265 sum.tv_nsec += op2.tv_nsec;
267 if( sum.tv_nsec > BILLION )
270 sum.tv_nsec -= BILLION;
276 struct timespec hekateros::operator-(const struct timespec& op1,
277 const struct timespec& op2)
279 struct timespec diff;
281 diff.tv_sec = op1.tv_sec - op2.tv_sec;
283 if( op1.tv_nsec >= op2.tv_nsec)
285 diff.tv_nsec = op1.tv_nsec - op2.tv_nsec;
290 diff.tv_nsec = BILLION + op1.tv_nsec - op2.tv_nsec;
298 struct timespec dt = t1 - t0;
300 return (
long long)dt.tv_sec * BILLION + (
long long)dt.tv_nsec;
303 double hekateros::dt(
struct timespec& t1,
struct timespec& t0)
307 return (
double)
dt_nsec(t1, t0) / (double)BILLION;
311 return -(double)
dt_nsec(t0, t1) / (double)BILLION;
317 char buf[MAX_PATH+1];
323 if( (len = readlink(strDevName.c_str(), buf, MAX_PATH)) > 0 )
330 string strRealDevName(buf);
331 return strRealDevName;
337 char s[strDevName.size()+1];
340 strcpy(s, strDevName.c_str());
342 char *sDirName = dirname(s);
344 ss << sDirName <<
"/" << buf;
361 vector<string> &elems)
366 while( getline(ss, item, delim) )
368 elems.push_back(item);
375 vector<string> elems;
377 split(s, delim, elems);
bool operator>(const struct timeval &lhs, const struct timeval &rhs)
Compare operator to test if left hand side time is later than the right hand side time...
bool operator<(const struct timeval &lhs, const struct timeval &rhs)
Compare operator to test if left hand side time is earlier than the right hand side time...
double dt(struct timeval &t1, struct timeval &t0)
Calculate delta time.
static const char * EcodeStrTbl[]
<b><i>Hekateros</i></b> Error Code String Table.
const char * getStrError(const int ecode)
Get the error string describing the <b><i>Hekateros</i></b> error code.
bool operator==(const struct timeval &lhs, const struct timeval &rhs)
Compare operator to test if left hand side time equals the right hand side time.
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Split string at the delimiter character.
Top-level package include file.
uint_t strToVersion(const std::string &str)
Convert version dotted string to integer equivalent.
std::string getRealDeviceName(const std::string &strDevName)
Get real device name.
#define HEK_VERSION(major, minor, revision)
Convert version triplet to integer equivalent.
Hekateros common utilities.
long long dt_nsec(struct timespec &t1, struct timespec &t0)
Calculate delta time in nanoseconds.
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
long dt_usec(struct timeval &t1, struct timeval &t0)
Calculate delta time in microseconds.