atten-pps3xxx: Fix serial port timeout.

This commit is contained in:
Bert Vermeulen 2014-10-05 12:29:28 +02:00
parent 204014007f
commit 945cfd4fdd
3 changed files with 18 additions and 3 deletions

View File

@ -92,6 +92,7 @@ static GSList *scan(GSList *options, int modelid)
struct sr_serial_dev_inst *serial; struct sr_serial_dev_inst *serial;
GSList *l, *devices; GSList *l, *devices;
struct pps_model *model; struct pps_model *model;
float byte_delay_ms;
uint8_t packet[PACKET_SIZE]; uint8_t packet[PACKET_SIZE];
unsigned int i; unsigned int i;
int ret; int ret;
@ -126,11 +127,20 @@ static GSList *scan(GSList *options, int modelid)
return NULL; return NULL;
serial_flush(serial); serial_flush(serial);
/* This is how the vendor software channels for hardware. */ /* How long it takes for a byte to transfer over the serial port. */
if (sp_get_port_transport(serial->data) == SP_TRANSPORT_NATIVE)
/* 11 bits at 9600 bps. */
byte_delay_ms = 1.15;
else
/* Emulated serial over USB or bluetooth is just enqueueing. */
byte_delay_ms = 0;
/* This is how the vendor software scans for hardware. */
memset(packet, 0, PACKET_SIZE); memset(packet, 0, PACKET_SIZE);
packet[0] = 0xaa; packet[0] = 0xaa;
packet[1] = 0xaa; packet[1] = 0xaa;
if (serial_write_blocking(serial, packet, PACKET_SIZE, 0) < PACKET_SIZE) { if (serial_write_blocking(serial, packet, PACKET_SIZE,
byte_delay_ms * PACKET_SIZE + 1) < PACKET_SIZE) {
sr_err("Unable to write while probing for hardware."); sr_err("Unable to write while probing for hardware.");
return NULL; return NULL;
} }
@ -178,6 +188,7 @@ static GSList *scan(GSList *options, int modelid)
devc = g_malloc0(sizeof(struct dev_context)); devc = g_malloc0(sizeof(struct dev_context));
devc->model = model; devc->model = model;
devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels); devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels);
devc->byte_delay_ms = byte_delay_ms;
sdi->priv = devc; sdi->priv = devc;
drvc->instances = g_slist_append(drvc->instances, sdi); drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);

View File

@ -83,10 +83,13 @@ static void handle_packet(const struct sr_dev_inst *sdi)
SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet) SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet)
{ {
struct dev_context *devc;
struct sr_serial_dev_inst *serial; struct sr_serial_dev_inst *serial;
devc = sdi->priv;
serial = sdi->conn; serial = sdi->conn;
if (serial_write_blocking(serial, packet, PACKET_SIZE, 0) < PACKET_SIZE) if (serial_write_blocking(serial, packet, PACKET_SIZE,
devc->byte_delay_ms * PACKET_SIZE + 1) < PACKET_SIZE)
sr_dbg("Failed to send packet."); sr_dbg("Failed to send packet.");
dump_packet("sent", packet); dump_packet("sent", packet);
} }

View File

@ -82,6 +82,7 @@ struct dev_context {
/* Operational state */ /* Operational state */
gboolean config_dirty; gboolean config_dirty;
struct per_channel_config *config; struct per_channel_config *config;
float byte_delay_ms;
/* Received from device. */ /* Received from device. */
int channel_mode; int channel_mode;
gboolean over_current_protection; gboolean over_current_protection;