-static int send_longcommand(int fd, uint8_t command, uint32_t data)
+static int send_longcommand(struct sr_serial_dev_inst *serial,
+ uint8_t command, uint32_t data)
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("ols: %s: devc malloc failed", __func__);
return NULL;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("ols: %s: devc malloc failed", __func__);
return NULL;
g_string_append_c(tmp_str, tmp_c);
sr_dbg("ols: got metadata key 0x%.2x value '%s'",
key, tmp_str->str);
g_string_append_c(tmp_str, tmp_c);
sr_dbg("ols: got metadata key 0x%.2x value '%s'",
key, tmp_str->str);
break;
tmp_int = reverse32(tmp_int);
sr_dbg("ols: got metadata key 0x%.2x value 0x%.8x",
break;
tmp_int = reverse32(tmp_int);
sr_dbg("ols: got metadata key 0x%.2x value 0x%.8x",
- if (serialcomm == NULL) {
- serialcomm = g_strdup("115200/8n1");
- }
+ if (serialcomm == NULL)
+ serialcomm = SERIALCOMM;
+
+ if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
+ return NULL;
/* The discovery procedure is like this: first send the Reset
* command (0x00) 5 times, since the device could be anywhere
* in a 5-byte command. Then send the ID command (0x02).
* If the device responds with 4 bytes ("OLS1" or "SLA1"), we
* have a match.
/* The discovery procedure is like this: first send the Reset
* command (0x00) 5 times, since the device could be anywhere
* in a 5-byte command. Then send the ID command (0x02).
* If the device responds with 4 bytes ("OLS1" or "SLA1"), we
* have a match.
- fd = serial_open(conn, O_RDWR | O_NONBLOCK);
- if (fd < 0) {
- sr_err("ols: could not open port %s .", conn);
+ if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
- g_poll(&probefd/*fds*/, 1/*devcnt*/, 1);
+ probefd.fd = serial->fd;
+ probefd.events = G_IO_IN;
+ g_poll(&probefd, 1, 1);
return NULL;
if (strncmp(buf, "1SLO", 4) && strncmp(buf, "1ALS", 4))
return NULL;
return NULL;
if (strncmp(buf, "1SLO", 4) && strncmp(buf, "1ALS", 4))
return NULL;
- /* not an OLS -- some other board that uses the sump protocol */
- sdi = sr_dev_inst_new(final_devcnt, SR_ST_INACTIVE,
+ /* Not an OLS -- some other board that uses the sump protocol. */
+ sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
delaycount = readcount * (1 - devc->capture_ratio / 100.0);
devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
delaycount = readcount * (1 - devc->capture_ratio / 100.0);
devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
"demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
devc->flag_reg & FLAG_DEMUX ? "on" : "off");
sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
"demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
devc->flag_reg & FLAG_DEMUX ? "on" : "off");
reverse32(devc->cur_samplerate_divider)) != SR_OK)
return SR_ERR;
/* Send sample limit and pre/post-trigger capture ratio. */
data = ((readcount - 1) & 0xffff) << 16;
data |= (delaycount - 1) & 0xffff;
reverse32(devc->cur_samplerate_divider)) != SR_OK)
return SR_ERR;
/* Send sample limit and pre/post-trigger capture ratio. */
data = ((readcount - 1) & 0xffff) << 16;
data |= (delaycount - 1) & 0xffff;
return SR_ERR;
sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data,
return SR_ERR;
sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data,