I have a problem with parsing the contents of a char[]. It contains bytes, that can be formated as ASCII stings. The last two bytes however are CRC. Therefore I interpret everything but the last two entries in the array in hex to string:
std::ostringstream payload;
std::ostringstream crc;
payload << std::hex;
crc << std::hex;
// last two bytes are CRC
for (int i = 0; i < this->d_packetlen - 2; i++)
{
payload << static_cast<unsigned>(this->d_packet[i]);
for (int j = i; j < this->d_packetlen; i++)
{
crc << static_cast<unsigned>(this->d_packet[j]);
}
}
std::string payload_result = payload.str();
std::string crc_result = crc.str();
fprintf(d_new_fp, "%s, %s, %d, %d\n", payload_result.c_str(),
crc_result.c_str(), this->d_lqi, this->d_lqi_sample_count);
This doesn’t work, and I’m not sure why that is? Is there an easier way to cast unsinged chars to ASCII?
Best,
Marius
This is an infinite loop:
In this loop, you are NOT incrementing
j; instead you’re incrementingi. Maybe, that is the problem?Also, the way you’ve described the problem, I think the correct solution is this:
That is the second loop should be outside the first loop.