const char *conn, const char *serialcomm)
{
struct sr_serial_dev_inst *serial;
- const struct rdtech_um_profile *p = NULL;
- GSList *devices = NULL;
- struct dev_context *devc = NULL;
- struct sr_dev_inst *sdi = NULL;
+ const struct rdtech_um_profile *p;
+ GSList *devices;
+ struct dev_context *devc;
+ struct sr_dev_inst *sdi;
size_t ch_idx;
const char *name;
for (ch_idx = 0; (name = p->channels[ch_idx].name); ch_idx++)
sr_channel_new(sdi, ch_idx, SR_CHANNEL_ANALOG, TRUE, name);
- devices = g_slist_append(devices, sdi);
+ devices = g_slist_append(NULL, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
+ const char *conn;
+ const char *serialcomm;
+ GSList *l;
struct sr_config *src;
- const char *conn = NULL;
- const char *serialcomm = RDTECH_UM_SERIALCOMM;
- for (GSList *l = options; l; l = l->next) {
+ conn = NULL;
+ serialcomm = RDTECH_UM_SERIALCOMM;
+ for (l = options; l; l = l->next) {
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
- struct dev_context *devc = sdi->priv;
- struct sr_serial_dev_inst *serial = sdi->conn;
+ struct dev_context *devc;
+ struct sr_serial_dev_inst *serial;
+ devc = sdi->priv;
sr_sw_limits_acquisition_start(&devc->limits);
std_session_send_df_header(sdi);
+ serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 50,
rdtech_um_receive_data, (void *)sdi);
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)