Add some more details to the error messages

This commit is contained in:
Jef Driesen 2024-03-26 22:19:02 +01:00
parent b8c3a09c6f
commit a86cb92ed8

View File

@ -193,7 +193,7 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
}; };
status = dc_iostream_write (device->iostream, command, sizeof(command), NULL); status = dc_iostream_write (device->iostream, command, sizeof(command), NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command."); ERROR (abstract->context, "Failed to send the command header.");
return status; return status;
} }
@ -201,7 +201,7 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
if (size) { if (size) {
status = dc_iostream_write (device->iostream, data, size, NULL); status = dc_iostream_write (device->iostream, data, size, NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command."); ERROR (abstract->context, "Failed to send the command data.");
return status; return status;
} }
} }
@ -210,20 +210,20 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
unsigned char header[1] = {0}; unsigned char header[1] = {0};
status = dc_iostream_read (device->iostream, header, sizeof (header), NULL); status = dc_iostream_read (device->iostream, header, sizeof (header), NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to receive the answer."); ERROR (abstract->context, "Failed to receive the packet header.");
return status; return status;
} }
// Verify the header byte. // Verify the header byte.
if (header[0] != ACK) { if (header[0] != ACK) {
ERROR (abstract->context, "Unexpected answer byte."); ERROR (abstract->context, "Unexpected packet header byte (%02x).", header[0]);
return DC_STATUS_PROTOCOL; return DC_STATUS_PROTOCOL;
} }
// Read the packet. // Read the packet.
status = dc_iostream_read (device->iostream, answer, asize, NULL); status = dc_iostream_read (device->iostream, answer, asize, NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to receive the answer."); ERROR (abstract->context, "Failed to receive the packet data.");
return status; return status;
} }
@ -231,13 +231,13 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
unsigned char trailer[1] = {0}; unsigned char trailer[1] = {0};
status = dc_iostream_read (device->iostream, trailer, sizeof (trailer), NULL); status = dc_iostream_read (device->iostream, trailer, sizeof (trailer), NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to receive the answer."); ERROR (abstract->context, "Failed to receive the packet trailer.");
return status; return status;
} }
// Verify the trailer byte. // Verify the trailer byte.
if (trailer[0] != END) { if (trailer[0] != END) {
ERROR (abstract->context, "Unexpected answer byte."); ERROR (abstract->context, "Unexpected packet trailer byte (%02x).", trailer[0]);
return DC_STATUS_PROTOCOL; return DC_STATUS_PROTOCOL;
} }