X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fcem-dt-885x%2Fprotocol.c;h=e3fea4c3a93f5d04a50bad8f2ce32a2357e730e2;hb=815e3cb83e715fad442c491d406f6ceba79e3a74;hp=19e083062c69331230589be10ab7e6ec34bab4e2;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git diff --git a/src/hardware/cem-dt-885x/protocol.c b/src/hardware/cem-dt-885x/protocol.c index 19e08306..e3fea4c3 100644 --- a/src/hardware/cem-dt-885x/protocol.c +++ b/src/hardware/cem-dt-885x/protocol.c @@ -21,7 +21,7 @@ #include "protocol.h" /* Length of expected payload for each token. */ -static int token_payloads[][2] = { +static const int token_payloads[][2] = { { TOKEN_WEIGHT_TIME_FAST, 0 }, { TOKEN_WEIGHT_TIME_SLOW, 0 }, { TOKEN_HOLD_MAX, 0 }, @@ -84,7 +84,7 @@ static void process_mset(const struct sr_dev_inst *sdi) g_string_free(dbg, TRUE); } - switch(devc->token) { + switch (devc->token) { case TOKEN_WEIGHT_TIME_FAST: devc->cur_mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_F; devc->cur_mqflags &= ~SR_MQFLAG_SPL_TIME_WEIGHT_S; @@ -166,7 +166,7 @@ static void process_mset(const struct sr_dev_inst *sdi) case TOKEN_MEAS_RANGE_OK: case TOKEN_MEAS_RANGE_OVER: case TOKEN_MEAS_RANGE_UNDER: - /* Not useful, or not expressable in sigrok. */ + /* Not useful, or not expressible in sigrok. */ break; } @@ -385,7 +385,7 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data) devc = sdi->priv; serial = sdi->conn; if (revents == G_IO_IN) { - if (serial_read(serial, &c, 1) != 1) + if (serial_read_nonblocking(serial, &c, 1) != 1) return TRUE; process_byte(sdi, c, TRUE); @@ -396,7 +396,7 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data) } else { /* Tell device to start transferring from memory. */ cmd = CMD_TRANSFER_MEMORY; - serial_write(serial, &cmd, 1); + serial_write_nonblocking(serial, &cmd, 1); } } } @@ -404,7 +404,6 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data) return TRUE; } - static int wait_for_token(const struct sr_dev_inst *sdi, int8_t *tokens, int timeout) { struct dev_context *devc; @@ -418,7 +417,7 @@ static int wait_for_token(const struct sr_dev_inst *sdi, int8_t *tokens, int tim devc->state = ST_INIT; start_time = g_get_monotonic_time() / 1000; while (TRUE) { - if (serial_read(serial, &c, 1) != 1) + if (serial_read_nonblocking(serial, &c, 1) != 1) /* Device might have gone away. */ return SR_ERR; process_byte(sdi, c, FALSE); @@ -453,7 +452,7 @@ static int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd, * only thing to do is wait for the token that will confirm * whether the command worked or not, and resend if needed. */ while (TRUE) { - if (serial_write(serial, (const void *)&cmd, 1) != 1) + if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1) return SR_ERR; if (wait_for_token(sdi, tokens, timeout) == SR_ERR) return SR_ERR; @@ -811,20 +810,14 @@ SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi) serial = sdi->conn; - /* Reopen the port in non-blocking mode, so we can properly - * detect when the device stops communicating. */ - serial_close(serial); - if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) - return SR_ERR; - cmd = CMD_TOGGLE_POWER_OFF; while (TRUE) { serial_flush(serial); - if (serial_write(serial, (const void *)&cmd, 1) != 1) + if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1) return SR_ERR; /* It never takes more than 23ms for the next token to arrive. */ g_usleep(25 * 1000); - if (serial_read(serial, &c, 1) != 1) + if (serial_read_nonblocking(serial, &c, 1) != 1) /* Device is no longer responding. Good! */ break; }