55, 57, 59, 63, 67, 69, 73, 79, 83, 89, 97, 99, 109,
111, 113, 119, 121, 127,
};
+
unsigned int i;
- uint8_t csum = 0;
+ uint8_t csum;
if (len != UM_POLL_LEN)
return 0;
+ csum = 0;
for (i = 0; i < ARRAY_SIZE(positions); i++)
csum ^= buf[positions[i]];
+ if (csum != (uint8_t)buf[len - 1])
+ return 0;
- return csum == (uint8_t)buf[len - 1];
+ return 1;
}
static const struct rdtech_um_profile um_profiles[] = {
static const struct rdtech_um_profile *find_profile(uint16_t id)
{
unsigned int i;
+
for (i = 0; i < ARRAY_SIZE(um_profiles); i++) {
if (um_profiles[i].model_id == id)
return &um_profiles[i];
SR_PRIV const struct rdtech_um_profile *rdtech_um_probe(struct sr_serial_dev_inst *serial)
{
const struct rdtech_um_profile *p;
- static const uint8_t request = UM_CMD_POLL;
+ uint8_t request;
char buf[RDTECH_UM_BUFSIZE];
int len;
+ request = UM_CMD_POLL;
if (serial_write_blocking(serial, &request, sizeof(request),
SERIAL_WRITE_TIMEOUT_MS) < 0) {
sr_err("Unable to send probe request.");
SR_PRIV int rdtech_um_poll(const struct sr_dev_inst *sdi)
{
- struct dev_context *devc = sdi->priv;
- struct sr_serial_dev_inst *serial = sdi->conn;
- static const uint8_t request = UM_CMD_POLL;
+ struct dev_context *devc;
+ struct sr_serial_dev_inst *serial;
+ uint8_t request;
+ serial = sdi->conn;
+ request = UM_CMD_POLL;
if (serial_write_blocking(serial, &request, sizeof(request),
SERIAL_WRITE_TIMEOUT_MS) < 0) {
sr_err("Unable to send poll request.");
return SR_ERR;
}
+ devc = sdi->priv;
devc->cmd_sent_at = g_get_monotonic_time() / 1000;
return SR_OK;
static void handle_poll_data(const struct sr_dev_inst *sdi)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
int i;
GSList *ch;
+ devc = sdi->priv;
sr_spew("Received poll packet (len: %d).", devc->buflen);
if (devc->buflen != UM_POLL_LEN) {
sr_err("Unexpected poll packet length: %i", devc->buflen);
static void recv_poll_data(struct sr_dev_inst *sdi, struct sr_serial_dev_inst *serial)
{
- struct dev_context *devc = sdi->priv;
- const struct rdtech_um_profile *p = devc->profile;
+ struct dev_context *devc;
+ const struct rdtech_um_profile *p;
int len;
/* Serial data arrived. */
+ devc = sdi->priv;
+ p = devc->profile;
while (devc->buflen < UM_POLL_LEN) {
len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1);
if (len < 1)