Merge commit 'refs/merge-requests/7' of git://gitorious.org/fg/flightgear into topics/merge7
This commit is contained in:
commit
94a3471956
2 changed files with 40 additions and 38 deletions
|
@ -467,12 +467,12 @@ union FGMultiplayMgr::MsgBuf
|
||||||
|
|
||||||
T_MsgHdr* msgHdr()
|
T_MsgHdr* msgHdr()
|
||||||
{
|
{
|
||||||
return reinterpret_cast<T_MsgHdr*>(Msg);
|
return &Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
const T_MsgHdr* msgHdr() const
|
const T_MsgHdr* msgHdr() const
|
||||||
{
|
{
|
||||||
return reinterpret_cast<const T_MsgHdr*>(Msg);
|
return reinterpret_cast<const T_MsgHdr*>(&Header);
|
||||||
}
|
}
|
||||||
|
|
||||||
T_PositionMsg* posMsg()
|
T_PositionMsg* posMsg()
|
||||||
|
@ -514,16 +514,17 @@ union FGMultiplayMgr::MsgBuf
|
||||||
*/
|
*/
|
||||||
xdr_data_t* propsRecvdEnd()
|
xdr_data_t* propsRecvdEnd()
|
||||||
{
|
{
|
||||||
return reinterpret_cast<xdr_data_t*>(Msg + msgHdr()->MsgLen);
|
return reinterpret_cast<xdr_data_t*>(Msg + Header.MsgLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
const xdr_data_t* propsRecvdEnd() const
|
const xdr_data_t* propsRecvdEnd() const
|
||||||
{
|
{
|
||||||
return reinterpret_cast<const xdr_data_t*>(Msg + msgHdr()->MsgLen);
|
return reinterpret_cast<const xdr_data_t*>(Msg + Header.MsgLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
xdr_data2_t double_val;
|
xdr_data2_t double_val;
|
||||||
char Msg[MAX_PACKET_SIZE];
|
char Msg[MAX_PACKET_SIZE];
|
||||||
|
T_MsgHdr Header;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -95,20 +95,20 @@ bool FGGeneric::gen_message_binary() {
|
||||||
|
|
||||||
switch (_out_message[i].type) {
|
switch (_out_message[i].type) {
|
||||||
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;
|
||||||
|
int32_t intVal = val;
|
||||||
if (binary_byte_order == BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
||||||
*((int32_t*)&buf[length]) = (int32_t)val;
|
intVal = (int32_t) sg_bswap_32((uint32_t)intVal);
|
||||||
} else {
|
|
||||||
*((uint32_t*)&buf[length]) = sg_bswap_32((uint32_t)val);
|
|
||||||
}
|
}
|
||||||
|
memcpy(&buf[length], &intVal, sizeof(int32_t));
|
||||||
length += sizeof(int32_t);
|
length += sizeof(int32_t);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case FG_BOOL:
|
case FG_BOOL:
|
||||||
*((int8_t*)&buf[length])
|
buf[length] = (char) (_out_message[i].prop->getBoolValue() ? true : false);
|
||||||
= _out_message[i].prop->getBoolValue() ? true : false;
|
|
||||||
length += 1;
|
length += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -117,46 +117,48 @@ bool FGGeneric::gen_message_binary() {
|
||||||
val = _out_message[i].offset +
|
val = _out_message[i].offset +
|
||||||
_out_message[i].prop->getFloatValue() * _out_message[i].factor;
|
_out_message[i].prop->getFloatValue() * _out_message[i].factor;
|
||||||
|
|
||||||
int fixed = (int)(val * 65536.0f);
|
int32_t fixed = (int)(val * 65536.0f);
|
||||||
if (binary_byte_order == BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
||||||
*((int32_t*)&buf[length]) = (int32_t)fixed;
|
fixed = (int32_t) sg_bswap_32((uint32_t)fixed);
|
||||||
} else {
|
|
||||||
*((uint32_t*)&buf[length]) = sg_bswap_32((uint32_t)fixed);
|
|
||||||
}
|
}
|
||||||
|
memcpy(&buf[length], &fixed, sizeof(int32_t));
|
||||||
length += sizeof(int32_t);
|
length += sizeof(int32_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case FG_FLOAT:
|
case FG_FLOAT:
|
||||||
|
{
|
||||||
val = _out_message[i].offset +
|
val = _out_message[i].offset +
|
||||||
_out_message[i].prop->getFloatValue() * _out_message[i].factor;
|
_out_message[i].prop->getFloatValue() * _out_message[i].factor;
|
||||||
|
u32 tmpun32;
|
||||||
|
tmpun32.floatVal = static_cast<float>(val);
|
||||||
|
|
||||||
if (binary_byte_order == BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
||||||
*((float*)&buf[length]) = val;
|
tmpun32.intVal = sg_bswap_32(tmpun32.intVal);
|
||||||
} else {
|
|
||||||
u32 tmpun32;
|
|
||||||
tmpun32.floatVal = static_cast<float>(val);
|
|
||||||
*((uint32_t*)&buf[length]) = sg_bswap_32(tmpun32.intVal);
|
|
||||||
}
|
}
|
||||||
|
memcpy(&buf[length], &tmpun32.intVal, sizeof(uint32_t));
|
||||||
length += sizeof(uint32_t);
|
length += sizeof(uint32_t);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case FG_DOUBLE:
|
case FG_DOUBLE:
|
||||||
|
{
|
||||||
val = _out_message[i].offset +
|
val = _out_message[i].offset +
|
||||||
_out_message[i].prop->getFloatValue() * _out_message[i].factor;
|
_out_message[i].prop->getFloatValue() * _out_message[i].factor;
|
||||||
|
u64 tmpun64;
|
||||||
|
tmpun64.doubleVal = val;
|
||||||
|
|
||||||
if (binary_byte_order == BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
||||||
*((double*)&buf[length]) = val;
|
tmpun64.longVal = sg_bswap_64(tmpun64.longVal);
|
||||||
} else {
|
|
||||||
u64 tmpun64;
|
|
||||||
tmpun64.doubleVal = val;
|
|
||||||
*((uint64_t*)&buf[length]) = sg_bswap_64(tmpun64.longVal);
|
|
||||||
}
|
}
|
||||||
length += sizeof(int64_t);
|
memcpy(&buf[length], &tmpun64.longVal, sizeof(uint64_t));
|
||||||
|
length += sizeof(uint64_t);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: // SG_STRING
|
default: // SG_STRING
|
||||||
const char *strdata = _out_message[i].prop->getStringValue();
|
const char *strdata = _out_message[i].prop->getStringValue();
|
||||||
int strlength = strlen(strdata);
|
int32_t strlength = strlen(strdata);
|
||||||
|
|
||||||
if (binary_byte_order == BYTE_ORDER_NEEDS_CONVERSION) {
|
if (binary_byte_order == BYTE_ORDER_NEEDS_CONVERSION) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "Generic protocol: "
|
SG_LOG( SG_IO, SG_ALERT, "Generic protocol: "
|
||||||
|
@ -165,11 +167,10 @@ bool FGGeneric::gen_message_binary() {
|
||||||
/* Format for strings is
|
/* Format for strings is
|
||||||
* [length as int, 4 bytes][ASCII data, length bytes]
|
* [length as int, 4 bytes][ASCII data, length bytes]
|
||||||
*/
|
*/
|
||||||
if (binary_byte_order == BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
||||||
*((int32_t*)&buf[length]) = strlength;
|
strlength = sg_bswap_32(strlength);
|
||||||
} else {
|
|
||||||
*((int32_t*)&buf[length]) = sg_bswap_32(strlength);
|
|
||||||
}
|
}
|
||||||
|
memcpy(&buf[length], &strlength, sizeof(int32_t));
|
||||||
length += sizeof(int32_t);
|
length += sizeof(int32_t);
|
||||||
strncpy(&buf[length], strdata, strlength);
|
strncpy(&buf[length], strdata, strlength);
|
||||||
length += strlength;
|
length += strlength;
|
||||||
|
@ -191,11 +192,11 @@ bool FGGeneric::gen_message_binary() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binary_footer_type != FOOTER_NONE) {
|
if (binary_footer_type != FOOTER_NONE) {
|
||||||
if (binary_byte_order == BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
int32_t intValue = binary_footer_value;
|
||||||
*((int32_t*)&buf[length]) = binary_footer_value;
|
if (binary_byte_order != BYTE_ORDER_MATCHES_NETWORK_ORDER) {
|
||||||
} else {
|
intValue = sg_bswap_32(binary_footer_value);
|
||||||
*((int32_t*)&buf[length]) = sg_bswap_32(binary_footer_value);
|
|
||||||
}
|
}
|
||||||
|
memcpy(&buf[length], &intValue, sizeof(int32_t));
|
||||||
length += sizeof(int32_t);
|
length += sizeof(int32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue