How to see what data is being send
-
I have a function
uint16_t Widget::writeFlashPage(uint8_t pageId, uint8_t *data, uint16_t pageSize){ uint16_t payLoadSize = pageSize + 1; uint16_t cmdSize = payLoadSize + 8; uint8_t cmd[3000]; memcpy(cmd, "x", 4); cmd[4] = CMD_SENDING_FIRMWARE_PAGE & 0xFF; cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF; cmd[6] = (uint8_t)(payLoadSize & 0xFF); cmd[7] = (uint8_t)(payLoadSize >>8); cmd[8] = pageId; memcpy(&cmd[9], data, pageSize); cmd[8 + payLoadSize] = calcChecksum(cmd, cmdSize); char* cmdChar = reinterpret_cast<char*>(cmd); // this conversion is needed so we can send via serial port! bool success = serialPort.write(cmdChar, cmdSize + 1);
How can I see what data is being sent to the serial port via qDebug()?
-
@JonB Ah yes I can see that now. Thanks.
Indecently when I use qDebug() cmdChar; the output is just "x" and nothing else. Surely this is not correct?@Aeroplane123
That is probably because it has something likex
followed by a byte of\0
, which it takes as a C string terminator and does not show any further bytes.To get
qDebug()
to show what is really there you will need something like:QByteArray ba(cmd, cmdSize + 1); qDebug() << ba; // or qDebug() << ba.toHex(':');
-
I have a function
uint16_t Widget::writeFlashPage(uint8_t pageId, uint8_t *data, uint16_t pageSize){ uint16_t payLoadSize = pageSize + 1; uint16_t cmdSize = payLoadSize + 8; uint8_t cmd[3000]; memcpy(cmd, "x", 4); cmd[4] = CMD_SENDING_FIRMWARE_PAGE & 0xFF; cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF; cmd[6] = (uint8_t)(payLoadSize & 0xFF); cmd[7] = (uint8_t)(payLoadSize >>8); cmd[8] = pageId; memcpy(&cmd[9], data, pageSize); cmd[8 + payLoadSize] = calcChecksum(cmd, cmdSize); char* cmdChar = reinterpret_cast<char*>(cmd); // this conversion is needed so we can send via serial port! bool success = serialPort.write(cmdChar, cmdSize + 1);
How can I see what data is being sent to the serial port via qDebug()?
@Aeroplane123
Umm, what aboutqDebug() << cmd;
? is that what you mean??BTW, in your previous thread on this code I told you that
cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
is wrong. Shame you have chosen to ignore this?
-
Hi can you explain why it is wrong?
-
Hi can you explain why it is wrong?
@Aeroplane123
The code you have will always evaluate to precisely a byte of0
. I doubt that is what you intended!Your
<<
is the wrong operator. Your code forcmd[7] = (uint8_t)(payLoadSize >>8);
does the same thing but correctly uses the>>
operator here. -
@Aeroplane123
The code you have will always evaluate to precisely a byte of0
. I doubt that is what you intended!Your
<<
is the wrong operator. Your code forcmd[7] = (uint8_t)(payLoadSize >>8);
does the same thing but correctly uses the>>
operator here.@JonB Ah yes I can see that now. Thanks.
Indecently when I use qDebug() cmdChar; the output is just "x" and nothing else. Surely this is not correct? -
@JonB Ah yes I can see that now. Thanks.
Indecently when I use qDebug() cmdChar; the output is just "x" and nothing else. Surely this is not correct?@Aeroplane123
That is probably because it has something likex
followed by a byte of\0
, which it takes as a C string terminator and does not show any further bytes.To get
qDebug()
to show what is really there you will need something like:QByteArray ba(cmd, cmdSize + 1); qDebug() << ba; // or qDebug() << ba.toHex(':');