pce-322a: unbreak send_command() return code
Data was sent to the serial port, and the non-zero positive write length
was mistaken as an error, since it did not match the SR_OK code's value.
This snuck in with commit 379e95c587
in 2017-08.
Rephrase the check for successful serial writes in the pce-322a driver.
Pass on error codes from the serial layer in verbatim form. Check for
the exact expected write length and derive SR_ERR_IO upon mismatch. Do
return SR_OK upon success.
Reported-By: Michael Ströder <michael@stroeder.com>
Tested-By: Michael Ströder <michael@stroeder.com>
This commit is contained in:
parent
5a0303474c
commit
a4be2b327b
|
@ -26,6 +26,7 @@ static int send_command(const struct sr_dev_inst *sdi, uint16_t command)
|
||||||
{
|
{
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
uint8_t buffer[2];
|
uint8_t buffer[2];
|
||||||
|
int ret;
|
||||||
|
|
||||||
buffer[0] = command >> 8;
|
buffer[0] = command >> 8;
|
||||||
buffer[1] = command;
|
buffer[1] = command;
|
||||||
|
@ -33,13 +34,20 @@ static int send_command(const struct sr_dev_inst *sdi, uint16_t command)
|
||||||
if (!(serial = sdi->conn))
|
if (!(serial = sdi->conn))
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
return serial_write_blocking(serial, (const void *)buffer, 2, 0);
|
ret = serial_write_blocking(serial, buffer, sizeof(buffer), 0);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
if ((size_t)ret != sizeof(buffer))
|
||||||
|
return SR_ERR_IO;
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command)
|
static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command)
|
||||||
{
|
{
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
uint8_t buffer[4];
|
uint8_t buffer[4];
|
||||||
|
int ret;
|
||||||
|
|
||||||
buffer[0] = command >> 24;
|
buffer[0] = command >> 24;
|
||||||
buffer[1] = command >> 16;
|
buffer[1] = command >> 16;
|
||||||
|
@ -49,7 +57,13 @@ static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command)
|
||||||
if (!(serial = sdi->conn))
|
if (!(serial = sdi->conn))
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
return serial_write_blocking(serial, (const void *)buffer, 4, 0);
|
ret = serial_write_blocking(serial, buffer, sizeof(buffer), 0);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
if ((size_t)ret != sizeof(buffer))
|
||||||
|
return SR_ERR_IO;
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_data(const struct sr_dev_inst *sdi, float sample)
|
static void send_data(const struct sr_dev_inst *sdi, float sample)
|
||||||
|
|
Loading…
Reference in New Issue