--- a/tool/DataTypeHandler.cpp Fri Mar 19 13:27:08 2010 +0100
+++ b/tool/DataTypeHandler.cpp Thu Apr 29 14:05:15 2010 +0200
@@ -75,7 +75,9 @@
<< " int8, int16, int32, int64," << endl
<< " uint8, uint16, uint32, uint64," << endl
<< " float, double" << endl
- << " string, octet_string, unicode_string." << 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();
}
@@ -232,6 +234,17 @@
throw runtime_error(err.str());
}
+ case 0xfffb: // sm8
+ case 0xfffc: // sm16
+ case 0xfffd: // sm32
+ case 0xfffe: // sm64
+ {
+ stringstream err;
+ err << "Sign-and-magitude types not yet"
+ " implemented for input direction.";
+ throw runtime_error(err.str());
+ }
+
default:
{
stringstream err;
@@ -256,12 +269,19 @@
size_t dataSize
)
{
- if (type->byteSize && dataSize != type->byteSize) {
- stringstream err;
- err << "Data type mismatch. Expected " << type->name
- << " with " << type->byteSize << " byte, but got "
- << dataSize << " byte.";
- throw SizeException(err.str());
+ uint16_t typeCode;
+
+ if (type) {
+ if (type->byteSize && dataSize != type->byteSize) {
+ stringstream err;
+ err << "Data type mismatch. Expected " << type->name
+ << " with " << type->byteSize << " byte, but got "
+ << dataSize << " byte.";
+ throw SizeException(err.str());
+ }
+ typeCode = type->code;
+ } else {
+ typeCode = 0xffff; // raw data
}
o << setfill('0');
@@ -327,7 +347,7 @@
o << string((const char *) data, dataSize) << endl;
break;
case 0x000a: // octet_string
- o << string((const char *) data, dataSize) << endl;
+ o << string((const char *) data, dataSize) << flush;
break;
case 0x000b: // unicode_string
// FIXME encoding
@@ -354,6 +374,43 @@
<< " " << dec << val << endl;
}
break;
+ case 0xfffb: // sm8
+ {
+ int8_t val = *(uint8_t *) data;
+ int8_t smval = val < 0 ? (val & 0x7f) * -1 : val;
+
+ o << "0x" << hex << setw(2) << (int) val
+ << " " << dec << (int) smval << endl;
+ }
+ break;
+ case 0xfffc: // sm16
+ {
+ int16_t val = le16_to_cpup(data);
+ int16_t smval = val < 0 ? (val & 0x7fff) * -1 : val;
+
+ o << "0x" << hex << setw(4) << val
+ << " " << dec << smval << endl;
+ }
+ break;
+ case 0xfffd: // sm32
+ {
+ int32_t val = le32_to_cpup(data);
+ int32_t smval = val < 0 ? (val & 0x7fffffffUL) * -1 : val;
+
+ o << "0x" << hex << setw(8) << val
+ << " " << dec << smval << endl;
+ }
+ break;
+ case 0xfffe: // sm64
+ {
+ int64_t val = le64_to_cpup(data);
+ int64_t smval =
+ val < 0 ? (val & 0x7fffffffffffffffULL) * -1 : val;
+
+ o << "0x" << hex << setw(16) << val
+ << " " << dec << smval << endl;
+ }
+ break;
default:
printRawData(o, (const uint8_t *) data, dataSize); // FIXME
@@ -406,6 +463,10 @@
{"uint56", 0x001a, 7},
{"uint64", 0x001b, 8},
// reserved 0x001c-0x001f
+ {"sm8", 0xfffb, 1}, // sign-and-magnitude coding
+ {"sm16", 0xfffc, 2}, // sign-and-magnitude coding
+ {"sm32", 0xfffd, 4}, // sign-and-magnitude coding
+ {"sm64", 0xfffe, 8}, // sign-and-magnitude coding
{"raw", 0xffff, 0},
{}
};