Thank you wysota! (as always to the rescue! )
Let me expose my code:
the structure:
//! \brief Fleet Management Protocol
//! \note All packets related to the fleet management protocol use packet ID 161.
typedef struct {
quint8 DLE; // =16;
quint8 packet_id; // =161
quint8 size_packet_data; // size of fleet_management_payload + 2
quint16 fleet_management_packet_id; // see #defines below
vector<char> fleet_management_payload; // 0 to 253 bytes
quint8 checksum; // compute this BEFORE sending the packet!
quint8 DLE_end; // =16
quint8 ETX; // =3
} fleet_management_packet_data_type;
//! \brief Fleet Management Protocol
//! \note All packets related to the fleet management protocol use packet ID 161.
typedef struct {
quint8 DLE; // =16;
quint8 packet_id; // =161
quint8 size_packet_data; // size of fleet_management_payload + 2
quint16 fleet_management_packet_id; // see #defines below
vector<char> fleet_management_payload; // 0 to 253 bytes
quint8 checksum; // compute this BEFORE sending the packet!
quint8 DLE_end; // =16
quint8 ETX; // =3
} fleet_management_packet_data_type;
To copy to clipboard, switch view to plain text mode
the function (so far):
//! \brief Process Fleet Management packets
//! \param records QDataStream raw data
//! \note First two bytes of the packet have already been read by TeltonikaUnit::parseFM4GarminRecs
void processFleetManagement
( QDataStream & records
) { fleet_management_packet_data_type packet;
bool debug = true;
records >> packet.size_packet_data;
records >> packet.fleet_management_packet_id;
packet.fleet_management_payload.resize(packet.size_packet_data+2);
// get the payload in a byte at a time...
char ch;
for (int i = 0; i < packet.size_packet_data; ++i)
{
records >> (char*&) ch;
packet.fleet_management_payload.push_back(ch);
}
records >> packet.checksum;
records >> packet.DLE_end;
records >> packet.ETX;
}
//! \brief Process Fleet Management packets
//! \param records QDataStream raw data
//! \note First two bytes of the packet have already been read by TeltonikaUnit::parseFM4GarminRecs
void processFleetManagement ( QDataStream & records ) {
fleet_management_packet_data_type packet;
bool debug = true;
records >> packet.size_packet_data;
records >> packet.fleet_management_packet_id;
packet.fleet_management_payload.resize(packet.size_packet_data+2);
// get the payload in a byte at a time...
char ch;
for (int i = 0; i < packet.size_packet_data; ++i)
{
records >> (char*&) ch;
packet.fleet_management_payload.push_back(ch);
}
records >> packet.checksum;
records >> packet.DLE_end;
records >> packet.ETX;
}
To copy to clipboard, switch view to plain text mode
So, as you can see, I'm trying to read packet.size_packet_data bytes from the data stream.
Your suggestion for using a QByteArray is perfectly valid but I'd like to stick with a vector, hence the question in the first place...
TIA,
Pedro.
Bookmarks