Changeset 673daf


Ignore:
Timestamp:
01/10/12 16:00:14 (4 months ago)
Author:
Stefan Persson <stefan.persson@…>
Branches:
('master', 'deebf2045e7119c339412580f37a1e653f7d5715')('controller-upgrade', '00f95d22e12d96ef089e0902ef62ae8ce841dc6f')
Children:
0c8de249d4250159c0b215c5d806d15d28de3bae
Parents:
dfae48ef33f9c218e80c5ec9ec1d96a1ae5fa625
git-author:
Stefan Persson <stefan.persson@telldus.se>2012-01-10 16:00:14+01:00
git-committer:
Stefan Persson <stefan.persson@telldus.se>2012-01-10 16:00:14+01:00
Message:

Sending noop to TellStick every 5 minutes, attempting to reconnect if TellStick is missing. In Linux.

Location:
telldus-core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • telldus-core/common/Socket_unix.cpp

    re35877 r673daf  
    115115        TelldusCore::MutexLocker locker(&d->mutex); 
    116116        d->connected = false; 
     117        //TODO somehow signal the socket here? 
    117118} 
    118119 
  • telldus-core/service/ControllerManager.cpp

    r06ac02 r673daf  
    44#include "TellStick.h" 
    55#include "Log.h" 
     6#include "../client/telldus-core.h" 
    67 
    78#include <map> 
     
    100101                ControllerMap::const_iterator cit = d->controllers.begin(); 
    101102                for(; cit != d->controllers.end(); ++cit) { 
    102                         Log::notice("Something in second the loop"); 
     103                        Log::notice("Something in the second loop"); 
    103104                        TellStick *tellstick = reinterpret_cast<TellStick*>(cit->second); 
    104105                        if (!tellstick) { 
     
    129130} 
    130131 
     132void ControllerManager::queryControllerStatus(){ 
     133 
     134        std::list<TellStick *> tellStickControllers; 
     135 
     136        { 
     137                TelldusCore::MutexLocker locker(&d->mutex); 
     138                for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) { 
     139                        Log::notice("found a controller"); 
     140                        TellStick *tellstick = reinterpret_cast<TellStick*>(it->second); 
     141                        if (tellstick) { 
     142                                Log::notice("found a tellstick"); 
     143                                tellStickControllers.push_back(tellstick); 
     144                        } 
     145                } 
     146        } 
     147 
     148        bool reloadControllers = false; 
     149        std::string noop = "noop"; 
     150        for(std::list<TellStick *>::iterator it = tellStickControllers.begin(); it != tellStickControllers.end(); ++it) { 
     151                int success = (*it)->send(noop); 
     152                if(success == TELLSTICK_ERROR_COMMUNICATION){ 
     153                        Log::warning("TellStick query: Error in communication with TellStick, resetting USB"); 
     154                        resetController(*it); 
     155                        Log::notice("has reset"); 
     156                } 
     157                if(success == TELLSTICK_ERROR_COMMUNICATION || success == TELLSTICK_ERROR_NOT_FOUND){ 
     158                        reloadControllers = true; 
     159                        Log::notice("Set reload"); 
     160                } 
     161        } 
     162 
     163        if(!tellStickControllers.size() || reloadControllers){ 
     164                //no tellstick at all found, or controller was reset 
     165                Log::warning("TellStick query: Rescanning USB ports"); 
     166                loadControllers(); 
     167        } 
     168} 
     169 
    131170int ControllerManager::resetController(Controller *controller) { 
    132171        TellStick *tellstick = reinterpret_cast<TellStick*>(controller); 
     
    135174        } 
    136175        Log::notice("resettingController"); 
    137         int success = controller->reset(); //ehh, här är väl controllern borttagen förresten? 
     176        int success = controller->reset(); 
    138177        Log::notice("Remove device"); 
    139178        deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete 
  • telldus-core/service/ControllerManager.h

    r06ac02 r673daf  
    1616        Controller *getBestControllerById(int id); 
    1717        void loadControllers(); 
     18        void queryControllerStatus(); 
    1819        int resetController(Controller *controller); 
    1920 
  • telldus-core/service/TellStick_libftdi.cpp

    r06ac02 r673daf  
    216216 
    217217        delete[] tempMessage; 
     218        if(strMessage == "noop"){ 
     219                if(c){ 
     220                        return TELLSTICK_SUCCESS; 
     221                } 
     222                else{ 
     223                        return TELLSTICK_ERROR_COMMUNICATION; 
     224                } 
     225        } 
    218226 
    219227        int retrycnt = 500; 
  • telldus-core/service/TelldusMain.cpp

    r542d17a r673daf  
    4444        EventRef janitor = d->eventHandler.addEvent(); //Used for regular cleanups 
    4545        Timer supervisor(janitor); //Tells the janitor to go back to work 
    46         supervisor.setInterval(60*5); //Every 5 minutes 
     46        supervisor.setInterval(10); //Every 5 minutes TODO how often? 60*5 
    4747        supervisor.start(); 
    4848 
     
    114114                        } 
    115115                        Log::debug("Do Janitor cleanup"); 
     116                        controllerManager.queryControllerStatus(); 
    116117                } 
    117118        } 
Note: See TracChangeset for help on using the changeset viewer.