From 53b40b8a3a6ae815abe945f3ef00029fa10546f5 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 21 Aug 2018 21:57:51 +0100 Subject: [PATCH] Attempt to fix Icom controller hanging. --- Common/IcomController.cpp | 4 ++-- Common/SerialDataController.cpp | 14 +++++++------- Common/SerialDataController.h | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Common/IcomController.cpp b/Common/IcomController.cpp index 89bf52a..ded29f1 100644 --- a/Common/IcomController.cpp +++ b/Common/IcomController.cpp @@ -397,7 +397,7 @@ RESP_TYPE_ICOM CIcomController::getResponse(unsigned char *buffer, unsigned int& unsigned int offset = 1U; while (offset < length) { - ret = m_serial.read(buffer + offset, length - offset); + ret = m_serial.read(buffer + offset, length - offset, 40U); if (ret < 0) { wxLogError(wxT("Error when reading from the Icom radio")); return RTI_ERROR; @@ -407,7 +407,7 @@ RESP_TYPE_ICOM CIcomController::getResponse(unsigned char *buffer, unsigned int& offset += ret; if (ret == 0) - Sleep(5UL); + return RTI_TIMEOUT; } // CUtils::dump(wxT("Received"), buffer, length); diff --git a/Common/SerialDataController.cpp b/Common/SerialDataController.cpp index fe8c5e6..e47bbf9 100644 --- a/Common/SerialDataController.cpp +++ b/Common/SerialDataController.cpp @@ -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 * * This program is free software; you can redistribute it and/or modify @@ -148,7 +148,7 @@ bool CSerialDataController::open() 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(buffer != NULL); @@ -156,7 +156,7 @@ int CSerialDataController::read(unsigned char* buffer, unsigned int length) unsigned int ptr = 0U; while (ptr < length) { - int ret = readNonblock(buffer + ptr, length - ptr); + int ret = readNonblock(buffer + ptr, length - ptr, timeout); if (ret < 0) { return ret; } else if (ret == 0) { @@ -170,7 +170,7 @@ int CSerialDataController::read(unsigned char* buffer, unsigned 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(buffer != NULL); @@ -377,7 +377,7 @@ bool CSerialDataController::open() 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(m_fd != -1); @@ -395,8 +395,8 @@ int CSerialDataController::read(unsigned char* buffer, unsigned int length) int n; if (offset == 0U) { struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 0; + tv.tv_sec = timeout / 1000U; + tv.tv_usec = (timeout % 1000U) * 1000U; n = ::select(m_fd + 1, &fds, NULL, NULL, &tv); if (n == 0) diff --git a/Common/SerialDataController.h b/Common/SerialDataController.h index 8c154fb..525054f 100644 --- a/Common/SerialDataController.h +++ b/Common/SerialDataController.h @@ -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 * * This program is free software; you can redistribute it and/or modify @@ -45,7 +45,7 @@ public: 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); void close(); @@ -66,7 +66,7 @@ private: #endif #if defined(__WINDOWS__) - int readNonblock(unsigned char* buffer, unsigned int length); + int readNonblock(unsigned char* buffer, unsigned int length, unsigned int timeout); #endif };