Removed tabs; output code as int.

This commit is contained in:
Florian Pose 2022-09-01 13:43:22 +02:00
parent e893051563
commit afbead48a7
1 changed files with 23 additions and 25 deletions

View File

@ -1,8 +1,6 @@
/*****************************************************************************
*
* $Id$
*
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH
* Copyright (C) 2006-2022 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT Master.
*
@ -67,19 +65,19 @@ const DataTypeHandler::DataType *DataTypeHandler::findDataType(
string DataTypeHandler::typeInfo()
{
stringstream s;
stringstream s;
s
<< "These are valid data types to use with" << endl
<< "the --type option:" << endl
<< " bool," << endl
<< " int8, int16, int32, int64," << endl
<< " uint8, uint16, uint32, uint64," << endl
<< " float, double," << endl
<< " string, octet_string, unicode_string." << endl
s
<< "These are valid data types to use with" << endl
<< "the --type option:" << endl
<< " bool," << endl
<< " int8, int16, int32, int64," << endl
<< " uint8, uint16, uint32, uint64," << endl
<< " float, double," << endl
<< " string, octet_string, unicode_string." << endl
<< "For sign-and-magnitude coding, use the following types:" << endl
<< " sm8, sm16, sm32, sm64" << endl;
return s.str();
return s.str();
}
/****************************************************************************/
@ -110,7 +108,7 @@ size_t DataTypeHandler::interpretAsType(
memset(target, 0, targetSize);
#if DEBUG
cerr << __func__ << "(targetSize=" << targetSize << ")" << endl;
cerr << __func__ << "(targetSize=" << targetSize << ")" << endl;
#endif
str << source;
@ -118,7 +116,7 @@ size_t DataTypeHandler::interpretAsType(
str.exceptions(ios::failbit);
#if DEBUG
cerr << "code=" << type->code << endl;
cerr << "code=" << (int) type->code << endl;
#endif
switch (type->code) {
@ -182,7 +180,7 @@ size_t DataTypeHandler::interpretAsType(
float val;
str >> val;
*(uint32_t *) target =
cpu_to_le32(*(uint32_t *) (void *) &val);
cpu_to_le32(*(uint32_t *) (void *) &val);
break;
}
case 0x0009: // string
@ -202,7 +200,7 @@ size_t DataTypeHandler::interpretAsType(
double val;
str >> val;
*(uint64_t *) target =
cpu_to_le64(*(uint64_t *) (void *) &val);
cpu_to_le64(*(uint64_t *) (void *) &val);
break;
}
break;
@ -234,7 +232,7 @@ size_t DataTypeHandler::interpretAsType(
{
stringstream err;
err << "Non-native integer type " << type->name
<< " is not yet implemented.";
<< " is not yet implemented.";
throw runtime_error(err.str());
}
@ -258,7 +256,7 @@ size_t DataTypeHandler::interpretAsType(
}
#if DEBUG
printRawData(cerr, (const uint8_t *) target, dataSize);
printRawData(cerr, (const uint8_t *) target, dataSize);
#endif
return dataSize;
@ -343,7 +341,7 @@ void DataTypeHandler::outputData(
case 0x0008: // float
{
uint32_t val = le32_to_cpup(data);
float fval = *(float *) (void *) &val;
float fval = *(float *) (void *) &val;
o << fval << endl;
}
break;
@ -354,13 +352,13 @@ void DataTypeHandler::outputData(
o << string((const char *) data, dataSize) << flush;
break;
case 0x000b: // unicode_string
// FIXME encoding
// FIXME encoding
o << string((const char *) data, dataSize) << endl;
break;
case 0x0011: // double
{
uint64_t val = le64_to_cpup(data);
double fval = *(double *) (void *) &val;
double fval = *(double *) (void *) &val;
o << fval << endl;
}
break;
@ -453,7 +451,7 @@ const DataTypeHandler::DataType DataTypeHandler::dataTypes[] = {
{"string", 0x0009, 0}, // a. k. a. visible_string
{"octet_string", 0x000a, 0},
{"unicode_string", 0x000b, 0},
// ... not implemented yet
// ... not implemented yet
{"int24", 0x0010, 3},
{"double", 0x0011, 8},
{"int40", 0x0012, 5},
@ -461,12 +459,12 @@ const DataTypeHandler::DataType DataTypeHandler::dataTypes[] = {
{"int56", 0x0014, 7},
{"int64", 0x0015, 8},
{"uint24", 0x0016, 3},
// reserved 0x0017
// reserved 0x0017
{"uint40", 0x0018, 5},
{"uint48", 0x0019, 6},
{"uint56", 0x001a, 7},
{"uint64", 0x001b, 8},
// reserved 0x001c-0x001f
// reserved 0x001c-0x001f
{"sm8", 0xfffb, 1}, // sign-and-magnitude coding
{"sm16", 0xfffc, 2}, // sign-and-magnitude coding
{"sm32", 0xfffd, 4}, // sign-and-magnitude coding