diff --git a/telldus-core/client/Client.cpp b/telldus-core/client/Client.cpp index 59d68e8e..291f45df 100644 --- a/telldus-core/client/Client.cpp +++ b/telldus-core/client/Client.cpp @@ -306,7 +306,7 @@ std::wstring Client::sendToService(const Message &msg) { msleep(500); continue; //retry } - readData = s.read(10000); //TODO changed to 10000 from 5000, how much does this do...? + readData = s.read(8000); //TODO changed to 10000 from 5000, how much does this do...? if(readData == L""){ printf("Readdata nothing\n\r"); msleep(500); diff --git a/telldus-core/client/telldus-core.cpp b/telldus-core/client/telldus-core.cpp index 18775d56..eccd6f0f 100644 --- a/telldus-core/client/telldus-core.cpp +++ b/telldus-core/client/telldus-core.cpp @@ -57,6 +57,9 @@ using namespace TelldusCore; * @def TELLSTICK_SUCCESS * Error code. Returned when the command succeeded. * + * @def TELLSTICK_ERROR_BROKEN_PIPE + * Error code. Pipe broken during communication. + * * @def TELLSTICK_ERROR_NOT_FOUND * Error code. Returned if a TellStick was not found on the system. * @@ -487,10 +490,11 @@ int WINAPI tdMethods(int id, int methodsSupported){ * @sa TELLSTICK_ERROR_CONNECTING_SERVICE * @sa TELLSTICK_ERROR_UNKNOWN_RESPONSE * @sa TELLSTICK_ERROR_SYNTAX + * @sa TELLSTICK_ERROR_BROKEN_PIPE * @sa TELLSTICK_ERROR_UNKNOWN */ char * WINAPI tdGetErrorString(int intErrorNo) { - const int numResponses = 9; + const int numResponses = 10; const char *responses[numResponses] = { "Success", "TellStick not found", @@ -500,7 +504,8 @@ char * WINAPI tdGetErrorString(int intErrorNo) { "An error occurred while communicating with TellStick", "Could not connect to the Telldus Service", "Received an unknown response", - "Syntax error" + "Syntax error", + "Broken pipe" }; std::string strReturn; intErrorNo = abs(intErrorNo); //We don't use negative values here. diff --git a/telldus-core/client/telldus-core.h b/telldus-core/client/telldus-core.h index 9d7ee9c2..cfa22122 100644 --- a/telldus-core/client/telldus-core.h +++ b/telldus-core/client/telldus-core.h @@ -116,6 +116,7 @@ extern "C" { #define TELLSTICK_ERROR_CONNECTING_SERVICE -6 #define TELLSTICK_ERROR_UNKNOWN_RESPONSE -7 #define TELLSTICK_ERROR_SYNTAX -8 +#define TELLSTICK_ERROR_BROKEN_PIPE -9 #define TELLSTICK_ERROR_UNKNOWN -99 //Device typedef diff --git a/telldus-core/service/ClientCommunicationHandler.cpp b/telldus-core/service/ClientCommunicationHandler.cpp index e6f04806..d51144ab 100644 --- a/telldus-core/service/ClientCommunicationHandler.cpp +++ b/telldus-core/service/ClientCommunicationHandler.cpp @@ -1,7 +1,6 @@ #include "ClientCommunicationHandler.h" #include "Message.h" #include "Strings.h" -#include "Log.h" //Debug #include diff --git a/telldus-core/service/ControllerManager.cpp b/telldus-core/service/ControllerManager.cpp index d9bc0360..6865e450 100644 --- a/telldus-core/service/ControllerManager.cpp +++ b/telldus-core/service/ControllerManager.cpp @@ -140,11 +140,11 @@ void ControllerManager::queryControllerStatus(){ std::string noop = "N+"; for(std::list::iterator it = tellStickControllers.begin(); it != tellStickControllers.end(); ++it) { int success = (*it)->send(noop); - if(success == TELLSTICK_ERROR_COMMUNICATION){ + if(success == TELLSTICK_ERROR_BROKEN_PIPE){ Log::warning("TellStick query: Error in communication with TellStick, resetting USB"); resetController(*it); } - if(success == TELLSTICK_ERROR_COMMUNICATION || success == TELLSTICK_ERROR_NOT_FOUND){ + if(success == TELLSTICK_ERROR_BROKEN_PIPE || success == TELLSTICK_ERROR_NOT_FOUND){ reloadControllers = true; } } diff --git a/telldus-core/service/DeviceManager.cpp b/telldus-core/service/DeviceManager.cpp index a6ef8603..3930108a 100644 --- a/telldus-core/service/DeviceManager.cpp +++ b/telldus-core/service/DeviceManager.cpp @@ -441,11 +441,11 @@ int DeviceManager::doAction(int deviceId, int action, unsigned char data){ if(controller){ retval = device->doAction(action, data, controller); - if(retval == TELLSTICK_ERROR_COMMUNICATION){ + if(retval == TELLSTICK_ERROR_BROKEN_PIPE){ Log::warning("Error in communication with TellStick when executing action. Resetting USB"); d->controllerManager->resetController(controller); } - if(retval == TELLSTICK_ERROR_COMMUNICATION || retval == TELLSTICK_ERROR_NOT_FOUND){ + if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND){ Log::warning("Rescanning USB ports"); d->controllerManager->loadControllers(); controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); @@ -751,10 +751,10 @@ int DeviceManager::sendRawCommand(const std::wstring &command, int reserved){ int retval = TELLSTICK_ERROR_UNKNOWN; if(controller){ retval = controller->send(TelldusCore::wideToString(command)); - if(retval == TELLSTICK_ERROR_COMMUNICATION){ + if(retval == TELLSTICK_ERROR_BROKEN_PIPE){ d->controllerManager->resetController(controller); } - if(retval == TELLSTICK_ERROR_COMMUNICATION || retval == TELLSTICK_ERROR_NOT_FOUND){ + if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND){ d->controllerManager->loadControllers(); controller = d->controllerManager->getBestControllerById(-1); if(!controller){ diff --git a/telldus-core/service/TellStick_libftdi.cpp b/telldus-core/service/TellStick_libftdi.cpp index 6410f989..6a114eb2 100644 --- a/telldus-core/service/TellStick_libftdi.cpp +++ b/telldus-core/service/TellStick_libftdi.cpp @@ -217,42 +217,44 @@ int TellStick::send( const std::string &strMessage ) { delete[] tempMessage; Log::notice("Message: %s", strMessage.c_str()); + Log::notice("FWVersion: %d", firmwareVersion()); + Log::notice("Pid: %X", pid()); + + if(!c){ + Log::debug("Broken pipe on send"); + return TELLSTICK_ERROR_BROKEN_PIPE; + } + if(d->ignoreControllerConfirmation || (strMessage == "N+" && ((pid() == 0x0C31 && firmwareVersion() < 5) || (pid() == 0x0C30 && firmwareVersion() < 6)))){ //these firmware versions doesn't implement ack to noop, just check that the noop can be sent correctly - Log::notice("Too old firmware, accepting this"); - if(c){ - Log::notice("Success"); - return TELLSTICK_SUCCESS; - } - else{ - Log::notice("Fail"); - return TELLSTICK_ERROR_COMMUNICATION; - } + Log::notice("Too old firmware, accepting this, just return success"); + return TELLSTICK_SUCCESS; } Log::warning("Continuing"); int retrycnt = 250; unsigned char in; - while(c && --retrycnt) { + while(--retrycnt) { ret = ftdi_read_data( &d->ftHandle, &in, 1); if (ret > 0) { - Log::notice("Returned %c", in); + Log::warning("%c", in); if (in == '\n') { - Log::notice("BREAK"); + Log::warning("Received an end"); break; } } else if(ret == 0) { // No data available usleep(100); } else { //Error - c = false; + Log::debug("Broken pipe on read"); + return TELLSTICK_ERROR_BROKEN_PIPE; } } + Log::warning("Retry ready"); if (!retrycnt) { - c = false; - } - if (!c) { + Log::warning("Error in communication, retrycount ended"); return TELLSTICK_ERROR_COMMUNICATION; } + Log::warning("Success"); return TELLSTICK_SUCCESS; } diff --git a/telldus-core/service/TelldusMain.cpp b/telldus-core/service/TelldusMain.cpp index 5a2b8b4b..a10f6da8 100644 --- a/telldus-core/service/TelldusMain.cpp +++ b/telldus-core/service/TelldusMain.cpp @@ -43,7 +43,7 @@ void TelldusMain::start(void) { EventRef dataEvent = d->eventHandler.addEvent(); EventRef janitor = d->eventHandler.addEvent(); //Used for regular cleanups Timer supervisor(janitor); //Tells the janitor to go back to work - supervisor.setInterval(10); //TODO Once every minute + supervisor.setInterval(60); //Once every minute supervisor.start(); ControllerManager controllerManager(dataEvent.get());