Add ec_error to string print function, fixes #227 and fixes #232

This commit is contained in:
Andreas Karlsson 2019-05-24 14:01:40 +02:00
parent 49810a5adf
commit c892921d7e
2 changed files with 60 additions and 48 deletions

View File

@ -291,18 +291,14 @@ char* ec_mbxerror2string( uint16 errorcode)
return (char *) ec_mbxerrorlist[i].errordescription; return (char *) ec_mbxerrorlist[i].errordescription;
} }
/** Look up error in ec_errorlist and convert to text string. /** Convert an error to text string.
* *
* @param[in] context = context struct * @param[in] Ec = Struct describing the error.
* @return readable string * @return readable string
*/ */
char* ecx_elist2string(ecx_contextt *context) char* ecx_err2string(const ec_errort Ec)
{ {
ec_errort Ec;
char timestr[20]; char timestr[20];
if (ecx_poperror(context, &Ec))
{
sprintf(timestr, "Time:%12.3f", Ec.Time.sec + (Ec.Time.usec / 1000000.0) ); sprintf(timestr, "Time:%12.3f", Ec.Time.sec + (Ec.Time.usec / 1000000.0) );
switch (Ec.Etype) switch (Ec.Etype)
{ {
@ -350,6 +346,20 @@ char* ecx_elist2string(ecx_contextt *context)
} }
} }
return (char*) estring; return (char*) estring;
}
/** Look up error in ec_errorlist and convert to text string.
*
* @param[in] context = context struct
* @return readable string
*/
char* ecx_elist2string(ecx_contextt *context)
{
ec_errort Ec;
if (ecx_poperror(context, &Ec))
{
return ecx_err2string(Ec);
} }
else else
{ {

View File

@ -19,6 +19,8 @@ extern "C"
char* ec_sdoerror2string( uint32 sdoerrorcode); char* ec_sdoerror2string( uint32 sdoerrorcode);
char* ec_ALstatuscode2string( uint16 ALstatuscode); char* ec_ALstatuscode2string( uint16 ALstatuscode);
char* ec_soeerror2string( uint16 errorcode); char* ec_soeerror2string( uint16 errorcode);
char* ec_mbxerror2string( uint16 errorcode);
char* ecx_err2string(const ec_errort Ec);
char* ecx_elist2string(ecx_contextt *context); char* ecx_elist2string(ecx_contextt *context);
#ifdef EC_VER1 #ifdef EC_VER1