Ok ... maybe it's me who's got really tired
but:
I have this struct:
#pragma pack(1)
typedef struct {
quint8 DLE; // ASCII DLE character (16 decimal)
quint8 packet_id;
quint8 size_app_payload; // number of bytes of packet data (bytes 3 to n-4)
char app_payload[255]; // 0 to 255 bytes
quint8 checksum; // 2's complement of the sum of all bytes from byte 1 to byte n-4 (end of the payload)
quint8 DLE_end; // same as DLE
quint8 ETX; // End of text - ASCII ETX character (3 decimal)
} serial_packet_format;
#pragma pack()
#pragma pack(1)
typedef struct {
quint8 DLE; // ASCII DLE character (16 decimal)
quint8 packet_id;
quint8 size_app_payload; // number of bytes of packet data (bytes 3 to n-4)
char app_payload[255]; // 0 to 255 bytes
quint8 checksum; // 2's complement of the sum of all bytes from byte 1 to byte n-4 (end of the payload)
quint8 DLE_end; // same as DLE
quint8 ETX; // End of text - ASCII ETX character (3 decimal)
} serial_packet_format;
#pragma pack()
To copy to clipboard, switch view to plain text mode
filled it with:
sPacket Contents
DLE: 10
Packet id: A1
size app payload: 02
Payload:
01
00
Checksum: 5C
DLE end: 10
ETX: 03
Now the serialization:
stream<< sPacket.DLE // DLE
<< sPacket.packet_id // packet id
<< sPacket.size_app_payload; // app_payload size
QByteArray byteArray;
QDataStream stream(&byteArray, QIODevice::WriteOnly);
stream<< sPacket.DLE // DLE
<< sPacket.packet_id // packet id
<< sPacket.size_app_payload; // app_payload size
To copy to clipboard, switch view to plain text mode
and so on for the rest...
now when I print the resulting byte array
for (i = 0; i < byteArray.size(); i++) {
printf("%02X\r\n", (qint8) byteArray[i] );
}
for (i = 0; i < byteArray.size(); i++) {
printf("%02X\r\n", (qint8) byteArray[i] );
}
To copy to clipboard, switch view to plain text mode
this is what I get!
10
FFFFFFA1
02
Why 0xA1 turned into 0xFFFFFFA1 ?! 
Could someone please take me out of my misery? 
Best regards,
Pedro Doria Meunier
Bookmarks