ipdbg-la: Allow rx to time out and handle invalid data properly
This is required for when we connect to invalid devices, e.g. port 4243 of the IPDBG host instead of 4242.
This commit is contained in:
parent
8771222588
commit
ed18648423
|
@ -92,7 +92,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
|
||||
ipdbg_org_la_send_reset(tcp);
|
||||
ipdbg_org_la_send_reset(tcp);
|
||||
ipdbg_org_la_request_id(tcp);
|
||||
|
||||
if (ipdbg_org_la_request_id(tcp) != SR_OK)
|
||||
return NULL;
|
||||
|
||||
struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
||||
if (!sdi) {
|
||||
|
|
|
@ -178,11 +178,16 @@ SR_PRIV int ipdbg_org_la_tcp_receive_blocking(struct ipdbg_org_la_tcp *tcp,
|
|||
uint8_t *buf, int bufsize)
|
||||
{
|
||||
int received = 0;
|
||||
int error_count = 0;
|
||||
|
||||
while (received < bufsize) {
|
||||
/* Timeout after 500ms of not receiving data */
|
||||
while ((received < bufsize) && (error_count < 500)) {
|
||||
if (ipdbg_org_la_tcp_receive(tcp, buf) > 0) {
|
||||
buf++;
|
||||
received++;
|
||||
} else {
|
||||
error_count++;
|
||||
g_usleep(1000); /* Sleep for 1ms */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,8 +537,10 @@ SR_PRIV int ipdbg_org_la_request_id(struct ipdbg_org_la_tcp *tcp)
|
|||
sr_warn("Couldn't send ID request");
|
||||
|
||||
char id[4];
|
||||
if (ipdbg_org_la_tcp_receive_blocking(tcp, (uint8_t *) id, 4) != 4)
|
||||
sr_warn("Couldn't read device ID");
|
||||
if (ipdbg_org_la_tcp_receive_blocking(tcp, (uint8_t*)id, 4) != 4) {
|
||||
sr_err("Couldn't read device ID");
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
if (strncmp(id, "IDBG", 4)) {
|
||||
sr_err("Invalid device ID: expected 'IDBG', got '%c%c%c%c'.",
|
||||
|
|
Loading…
Reference in New Issue