Attempt to fix Icom controller hanging.

pull/1/head
Jonathan Naylor 8 years ago
parent 9187e31665
commit 53b40b8a3a

@ -397,7 +397,7 @@ RESP_TYPE_ICOM CIcomController::getResponse(unsigned char *buffer, unsigned int&
unsigned int offset = 1U; unsigned int offset = 1U;
while (offset < length) { while (offset < length) {
ret = m_serial.read(buffer + offset, length - offset); ret = m_serial.read(buffer + offset, length - offset, 40U);
if (ret < 0) { if (ret < 0) {
wxLogError(wxT("Error when reading from the Icom radio")); wxLogError(wxT("Error when reading from the Icom radio"));
return RTI_ERROR; return RTI_ERROR;
@ -407,7 +407,7 @@ RESP_TYPE_ICOM CIcomController::getResponse(unsigned char *buffer, unsigned int&
offset += ret; offset += ret;
if (ret == 0) if (ret == 0)
Sleep(5UL); return RTI_TIMEOUT;
} }
// CUtils::dump(wxT("Received"), buffer, length); // CUtils::dump(wxT("Received"), buffer, length);

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2002-2004,2007-2011,2013,2014,2015 by Jonathan Naylor G4KLX * Copyright (C) 2002-2004,2007-2011,2013,2014,2015,2018 by Jonathan Naylor G4KLX
* Copyright (C) 1999-2001 by Thomas Sailor HB9JNX * Copyright (C) 1999-2001 by Thomas Sailor HB9JNX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -148,7 +148,7 @@ bool CSerialDataController::open()
return true; return true;
} }
int CSerialDataController::read(unsigned char* buffer, unsigned int length) int CSerialDataController::read(unsigned char* buffer, unsigned int length, unsigned int timeout)
{ {
wxASSERT(m_handle != INVALID_HANDLE_VALUE); wxASSERT(m_handle != INVALID_HANDLE_VALUE);
wxASSERT(buffer != NULL); wxASSERT(buffer != NULL);
@ -156,7 +156,7 @@ int CSerialDataController::read(unsigned char* buffer, unsigned int length)
unsigned int ptr = 0U; unsigned int ptr = 0U;
while (ptr < length) { while (ptr < length) {
int ret = readNonblock(buffer + ptr, length - ptr); int ret = readNonblock(buffer + ptr, length - ptr, timeout);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} else if (ret == 0) { } else if (ret == 0) {
@ -170,7 +170,7 @@ int CSerialDataController::read(unsigned char* buffer, unsigned int length)
return int(length); return int(length);
} }
int CSerialDataController::readNonblock(unsigned char* buffer, unsigned int length) int CSerialDataController::readNonblock(unsigned char* buffer, unsigned int length, unsigned int timeout)
{ {
wxASSERT(m_handle != INVALID_HANDLE_VALUE); wxASSERT(m_handle != INVALID_HANDLE_VALUE);
wxASSERT(buffer != NULL); wxASSERT(buffer != NULL);
@ -377,7 +377,7 @@ bool CSerialDataController::open()
return true; return true;
} }
int CSerialDataController::read(unsigned char* buffer, unsigned int length) int CSerialDataController::read(unsigned char* buffer, unsigned int length, unsigned int timeout)
{ {
wxASSERT(buffer != NULL); wxASSERT(buffer != NULL);
wxASSERT(m_fd != -1); wxASSERT(m_fd != -1);
@ -395,8 +395,8 @@ int CSerialDataController::read(unsigned char* buffer, unsigned int length)
int n; int n;
if (offset == 0U) { if (offset == 0U) {
struct timeval tv; struct timeval tv;
tv.tv_sec = 0; tv.tv_sec = timeout / 1000U;
tv.tv_usec = 0; tv.tv_usec = (timeout % 1000U) * 1000U;
n = ::select(m_fd + 1, &fds, NULL, NULL, &tv); n = ::select(m_fd + 1, &fds, NULL, NULL, &tv);
if (n == 0) if (n == 0)

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2002-2004,2007-2009,2011-2013,2015 by Jonathan Naylor G4KLX * Copyright (C) 2002-2004,2007-2009,2011-2013,2015,2018 by Jonathan Naylor G4KLX
* Copyright (C) 1999-2001 by Thomas Sailor HB9JNX * Copyright (C) 1999-2001 by Thomas Sailor HB9JNX
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -45,7 +45,7 @@ public:
bool open(); bool open();
int read(unsigned char* buffer, unsigned int length); int read(unsigned char* buffer, unsigned int length, unsigned int timeout = 0U);
int write(const unsigned char* buffer, unsigned int length); int write(const unsigned char* buffer, unsigned int length);
void close(); void close();
@ -66,7 +66,7 @@ private:
#endif #endif
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
int readNonblock(unsigned char* buffer, unsigned int length); int readNonblock(unsigned char* buffer, unsigned int length, unsigned int timeout);
#endif #endif
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.