Added TELLSTICK_ERROR_BROKEN_PIPE to distinguate between when communication with TellStick fails due to timeout or actual error.
This commit is contained in:
parent
69059b935b
commit
b84e8b3806
8 changed files with 34 additions and 27 deletions
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "ClientCommunicationHandler.h"
|
||||
#include "Message.h"
|
||||
#include "Strings.h"
|
||||
#include "Log.h" //Debug
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
@ -140,11 +140,11 @@ void ControllerManager::queryControllerStatus(){
|
|||
std::string noop = "N+";
|
||||
for(std::list<TellStick *>::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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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");
|
||||
Log::notice("Too old firmware, accepting this, just return success");
|
||||
return TELLSTICK_SUCCESS;
|
||||
}
|
||||
else{
|
||||
Log::notice("Fail");
|
||||
return TELLSTICK_ERROR_COMMUNICATION;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue