1
0
Fork 0

generic binary protocol: add 'word' datatype

this patch adds support for binary datatype word (aka int16)
now we have int (32bit), word (16bit) and byte (8bit) integer types
This commit is contained in:
Torsten Dreyer 2013-10-28 22:57:22 +01:00
parent 1970a8e0a8
commit 35dad8c4c4
2 changed files with 26 additions and 1 deletions

View file

@ -346,6 +346,16 @@ bool FGGeneric::gen_message_binary() {
break; break;
} }
case FG_WORD:
{
val = _out_message[i].offset +
_out_message[i].prop->getIntValue() * _out_message[i].factor;
int16_t wordVal = val;
memcpy(&buf[length], &wordVal, sizeof(int16_t));
length += sizeof(int16_t);
break;
}
default: // SG_STRING default: // SG_STRING
const char *strdata = _out_message[i].prop->getStringValue(); const char *strdata = _out_message[i].prop->getStringValue();
int32_t strlength = strlen(strdata); int32_t strlength = strlen(strdata);
@ -413,6 +423,7 @@ bool FGGeneric::gen_message_ascii() {
switch (_out_message[i].type) { switch (_out_message[i].type) {
case FG_BYTE: case FG_BYTE:
case FG_WORD:
case FG_INT: case FG_INT:
val = _out_message[i].offset + val = _out_message[i].offset +
_out_message[i].prop->getIntValue() * _out_message[i].factor; _out_message[i].prop->getIntValue() * _out_message[i].factor;
@ -531,6 +542,16 @@ bool FGGeneric::parse_message_binary(int length) {
p1 += sizeof(int8_t); p1 += sizeof(int8_t);
break; break;
case FG_WORD:
if (binary_byte_order == BYTE_ORDER_NEEDS_CONVERSION) {
tmp32 = sg_bswap_16(*(int16_t *)p1);
} else {
tmp32 = *(int16_t *)p1;
}
updateValue(_in_message[i], (int)tmp32);
p1 += sizeof(int16_t);
break;
default: // SG_STRING default: // SG_STRING
SG_LOG( SG_IO, SG_ALERT, "Generic protocol: " SG_LOG( SG_IO, SG_ALERT, "Generic protocol: "
"Ignoring unsupported binary input chunk type."); "Ignoring unsupported binary input chunk type.");
@ -571,6 +592,7 @@ bool FGGeneric::parse_message_ascii(int length) {
switch (_in_message[i].type) { switch (_in_message[i].type) {
case FG_BYTE: case FG_BYTE:
case FG_WORD:
case FG_INT: case FG_INT:
updateValue(_in_message[i], atoi(p1)); updateValue(_in_message[i], atoi(p1));
break; break;
@ -931,6 +953,9 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
} else if (type == "byte") { } else if (type == "byte") {
chunk.type = FG_BYTE; chunk.type = FG_BYTE;
record_length += sizeof(int8_t); record_length += sizeof(int8_t);
} else if (type == "word") {
chunk.type = FG_WORD;
record_length += sizeof(int16_t);
} else { } else {
chunk.type = FG_INT; chunk.type = FG_INT;
record_length += sizeof(int32_t); record_length += sizeof(int32_t);

View file

@ -59,7 +59,7 @@ public:
bool getInitOk(void) { return initOk; } bool getInitOk(void) { return initOk; }
protected: protected:
enum e_type { FG_BOOL=0, FG_INT, FG_FLOAT, FG_DOUBLE, FG_STRING, FG_FIXED, FG_BYTE }; enum e_type { FG_BOOL=0, FG_INT, FG_FLOAT, FG_DOUBLE, FG_STRING, FG_FIXED, FG_BYTE, FG_WORD };
typedef struct { typedef struct {
// string name; // string name;