Sending noop to TellStick every 5 minutes, attempting to reconnect if TellStick is missing. In Linux.
This commit is contained in:
parent
dfae48ef33
commit
673daf471d
5 changed files with 53 additions and 3 deletions
|
@ -114,6 +114,7 @@ std::wstring Socket::read(int timeout) {
|
|||
void Socket::stopReadWait(){
|
||||
TelldusCore::MutexLocker locker(&d->mutex);
|
||||
d->connected = false;
|
||||
//TODO somehow signal the socket here?
|
||||
}
|
||||
|
||||
void Socket::write(const std::wstring &msg) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Mutex.h"
|
||||
#include "TellStick.h"
|
||||
#include "Log.h"
|
||||
#include "../client/telldus-core.h"
|
||||
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
|
@ -99,7 +100,7 @@ void ControllerManager::loadControllers() {
|
|||
bool found = false;
|
||||
ControllerMap::const_iterator cit = d->controllers.begin();
|
||||
for(; cit != d->controllers.end(); ++cit) {
|
||||
Log::notice("Something in second the loop");
|
||||
Log::notice("Something in the second loop");
|
||||
TellStick *tellstick = reinterpret_cast<TellStick*>(cit->second);
|
||||
if (!tellstick) {
|
||||
Log::notice("No tellstick");
|
||||
|
@ -128,13 +129,51 @@ void ControllerManager::loadControllers() {
|
|||
}
|
||||
}
|
||||
|
||||
void ControllerManager::queryControllerStatus(){
|
||||
|
||||
std::list<TellStick *> tellStickControllers;
|
||||
|
||||
{
|
||||
TelldusCore::MutexLocker locker(&d->mutex);
|
||||
for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) {
|
||||
Log::notice("found a controller");
|
||||
TellStick *tellstick = reinterpret_cast<TellStick*>(it->second);
|
||||
if (tellstick) {
|
||||
Log::notice("found a tellstick");
|
||||
tellStickControllers.push_back(tellstick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool reloadControllers = false;
|
||||
std::string noop = "noop";
|
||||
for(std::list<TellStick *>::iterator it = tellStickControllers.begin(); it != tellStickControllers.end(); ++it) {
|
||||
int success = (*it)->send(noop);
|
||||
if(success == TELLSTICK_ERROR_COMMUNICATION){
|
||||
Log::warning("TellStick query: Error in communication with TellStick, resetting USB");
|
||||
resetController(*it);
|
||||
Log::notice("has reset");
|
||||
}
|
||||
if(success == TELLSTICK_ERROR_COMMUNICATION || success == TELLSTICK_ERROR_NOT_FOUND){
|
||||
reloadControllers = true;
|
||||
Log::notice("Set reload");
|
||||
}
|
||||
}
|
||||
|
||||
if(!tellStickControllers.size() || reloadControllers){
|
||||
//no tellstick at all found, or controller was reset
|
||||
Log::warning("TellStick query: Rescanning USB ports");
|
||||
loadControllers();
|
||||
}
|
||||
}
|
||||
|
||||
int ControllerManager::resetController(Controller *controller) {
|
||||
TellStick *tellstick = reinterpret_cast<TellStick*>(controller);
|
||||
if (!tellstick) {
|
||||
return true; //not tellstick, nothing to reset at the moment, just return true
|
||||
}
|
||||
Log::notice("resettingController");
|
||||
int success = controller->reset(); //ehh, här är väl controllern borttagen förresten?
|
||||
int success = controller->reset();
|
||||
Log::notice("Remove device");
|
||||
deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete
|
||||
Log::notice("Device removed");
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
|
||||
Controller *getBestControllerById(int id);
|
||||
void loadControllers();
|
||||
void queryControllerStatus();
|
||||
int resetController(Controller *controller);
|
||||
|
||||
private:
|
||||
|
|
|
@ -215,6 +215,14 @@ int TellStick::send( const std::string &strMessage ) {
|
|||
}
|
||||
|
||||
delete[] tempMessage;
|
||||
if(strMessage == "noop"){
|
||||
if(c){
|
||||
return TELLSTICK_SUCCESS;
|
||||
}
|
||||
else{
|
||||
return TELLSTICK_ERROR_COMMUNICATION;
|
||||
}
|
||||
}
|
||||
|
||||
int retrycnt = 500;
|
||||
unsigned char in;
|
||||
|
|
|
@ -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(60*5); //Every 5 minutes
|
||||
supervisor.setInterval(10); //Every 5 minutes TODO how often? 60*5
|
||||
supervisor.start();
|
||||
|
||||
ControllerManager controllerManager(dataEvent.get());
|
||||
|
@ -113,6 +113,7 @@ void TelldusMain::start(void) {
|
|||
janitor->popSignal();
|
||||
}
|
||||
Log::debug("Do Janitor cleanup");
|
||||
controllerManager.queryControllerStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue