Changeset 06ac02
- Timestamp:
- 01/10/12 09:55:26 (4 months ago)
- Branches:
- ('master', 'deebf2045e7119c339412580f37a1e653f7d5715')('controller-upgrade', '00f95d22e12d96ef089e0902ef62ae8ce841dc6f')
- Children:
- dfae48ef33f9c218e80c5ec9ec1d96a1ae5fa625
- Parents:
- e019f416d9aa3212aa5dc3a677eb8e2cf8ad8290
- git-author:
- Stefan Persson <stefan.persson@telldus.se>2012-01-10 09:55:26+01:00
- git-committer:
- Stefan Persson <stefan.persson@telldus.se>2012-01-10 09:55:26+01:00
- Location:
- telldus-core/service
- Files:
-
- 6 edited
-
Controller.h (modified) (1 diff)
-
ControllerManager.cpp (modified) (5 diffs)
-
ControllerManager.h (modified) (1 diff)
-
DeviceManager.cpp (modified) (3 diffs)
-
TellStick.h (modified) (1 diff)
-
TellStick_libftdi.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telldus-core/service/Controller.h
r99f0b1 r06ac02 17 17 virtual int firmwareVersion() = 0; 18 18 virtual int send( const std::string &message ) = 0; 19 virtual int reset() = 0; 19 20 20 21 protected: -
telldus-core/service/ControllerManager.cpp
rbf4589 r06ac02 3 3 #include "Mutex.h" 4 4 #include "TellStick.h" 5 #include "Log.h" 5 6 6 7 #include <map> … … 91 92 92 93 std::list<TellStickDescriptor>::iterator it = list.begin(); 94 Log::notice("Before for-loop"); 93 95 for(; it != list.end(); ++it) { 96 Log::notice("Something in the loop"); 94 97 //Most backend only report non-opened devices. 95 98 //If they don't make sure we don't open them twice … … 97 100 ControllerMap::const_iterator cit = d->controllers.begin(); 98 101 for(; cit != d->controllers.end(); ++cit) { 102 Log::notice("Something in second the loop"); 99 103 TellStick *tellstick = reinterpret_cast<TellStick*>(cit->second); 100 104 if (!tellstick) { 105 Log::notice("No tellstick"); 101 106 continue; 102 107 } 103 108 if (tellstick->isSameAsDescriptor(*it)) { 104 109 found = true; 110 Log::notice("FOUND"); 105 111 break; 106 112 } … … 112 118 int controllerId = d->lastControllerId-1; 113 119 TellStick *controller = new TellStick(controllerId, d->event, *it); 120 Log::notice("Is it open?"); 114 121 if (!controller->isOpen()) { 122 Log::notice("Yes it was"); 115 123 delete controller; 116 124 continue; … … 120 128 } 121 129 } 130 131 int ControllerManager::resetController(Controller *controller) { 132 TellStick *tellstick = reinterpret_cast<TellStick*>(controller); 133 if (!tellstick) { 134 return true; //not tellstick, nothing to reset at the moment, just return true 135 } 136 Log::notice("resettingController"); 137 int success = controller->reset(); //ehh, här är väl controllern borttagen förresten? 138 Log::notice("Remove device"); 139 deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete 140 Log::notice("Device removed"); 141 return success; 142 } -
telldus-core/service/ControllerManager.h
rcccaf8 r06ac02 15 15 16 16 Controller *getBestControllerById(int id); 17 18 protected:19 17 void loadControllers(); 18 int resetController(Controller *controller); 20 19 21 20 private: -
telldus-core/service/DeviceManager.cpp
r1646eb r06ac02 7 7 #include "Message.h" 8 8 #include "common.h" 9 #include "Log.h" 9 10 10 11 #include <map> … … 432 433 } 433 434 else{ 435 Log::notice("Getting a controller..."); 434 436 Controller *controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); 437 Log::notice("Doing action..."); 438 if(!controller){ 439 Log::warning("No controller found, rescanning USB ports"); 440 //no controller found, scan for one, and retry once 441 d->controllerManager->loadControllers(); 442 controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); 443 } 444 435 445 if(controller){ 446 Log::notice("But now, a controller!"); 436 447 retval = device->doAction(action, data, controller); 448 Log::notice("Retval received, %d.", retval); 449 if(retval == TELLSTICK_ERROR_COMMUNICATION){ 450 Log::warning("Error in communication with TellStick, resetting USB"); 451 d->controllerManager->resetController(controller); 452 Log::notice("Controller reset"); 453 } 454 if(retval == TELLSTICK_ERROR_COMMUNICATION || retval == TELLSTICK_ERROR_NOT_FOUND){ 455 Log::warning("Rescanning USB ports"); 456 d->controllerManager->loadControllers(); 457 Log::notice("Loaded, get one"); 458 controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId()); 459 if(!controller){ 460 Log::error("No contoller (TellStick) found, even after reset. Giving up."); 461 return TELLSTICK_ERROR_NOT_FOUND; 462 } 463 Log::notice("Got a new, do action"); 464 retval = device->doAction(action, data, controller); //retry one more time 465 Log::notice("Did action"); 466 } 437 467 } else { 468 Log::error("No contoller (TellStick) found after one retry. Giving up."); 438 469 return TELLSTICK_ERROR_NOT_FOUND; 439 470 } … … 720 751 721 752 Controller *controller = d->controllerManager->getBestControllerById(-1); 753 754 if(!controller){ 755 //no controller found, scan for one, and retry once 756 d->controllerManager->loadControllers(); 757 controller = d->controllerManager->getBestControllerById(-1); 758 } 759 760 int retval = TELLSTICK_ERROR_UNKNOWN; 722 761 if(controller){ 723 return controller->send(TelldusCore::wideToString(command)); 724 } 725 else{ 762 retval = controller->send(TelldusCore::wideToString(command)); 763 if(retval == TELLSTICK_ERROR_COMMUNICATION){ 764 d->controllerManager->resetController(controller); 765 } 766 if(retval == TELLSTICK_ERROR_COMMUNICATION || retval == TELLSTICK_ERROR_NOT_FOUND){ 767 d->controllerManager->loadControllers(); 768 controller = d->controllerManager->getBestControllerById(-1); 769 if(!controller){ 770 return TELLSTICK_ERROR_NOT_FOUND; 771 } 772 retval = controller->send(TelldusCore::wideToString(command)); //retry one more time 773 } 774 return retval; 775 } else { 726 776 return TELLSTICK_ERROR_NOT_FOUND; 727 777 } -
telldus-core/service/TellStick.h
r05a816 r06ac02 30 30 virtual int firmwareVersion(); 31 31 virtual int pid() const; 32 virtual int vid() const; 33 virtual std::string serial() const; 34 32 35 bool isOpen() const; 33 36 bool isSameAsDescriptor(const TellStickDescriptor &d) const; 37 virtual int reset(); 34 38 virtual int send( const std::string &message ); 35 39 bool stillConnected() const; -
telldus-core/service/TellStick_libftdi.cpp
re019f4 r06ac02 22 22 #include "Strings.h" 23 23 #include "common.h" 24 #include "Log.h" 24 25 25 26 #include <unistd.h> … … 98 99 int TellStick::pid() const { 99 100 return d->pid; 101 } 102 103 int TellStick::vid() const { 104 return d->vid; 105 } 106 107 std::string TellStick::serial() const { 108 return d->serial; 100 109 } 101 110 … … 136 145 } 137 146 147 int TellStick::reset(){ 148 Log::notice("Resetting one"); 149 int success = ftdi_usb_reset( &d->ftHandle ); 150 Log::notice("Has reset one"); 151 if(success < 0){ 152 return TELLSTICK_ERROR_UNKNOWN; //-1 = FTDI reset failed, -2 = USB device unavailable 153 } 154 return success; 155 } 156 138 157 void TellStick::run() { 139 158 int dwBytesRead = 0; … … 274 293 ftdi_init(&ftdic); 275 294 295 Log::notice("Trying to find Duo"); 276 296 int ret = ftdi_usb_find_all(&ftdic, &devlist, vid, pid); 277 297 if (ret > 0) { 298 Log::notice("Curdev > 0"); 278 299 for (curdev = devlist; curdev != NULL; curdev = curdev->next) { 300 Log::notice("Something in the loop"); 279 301 ret = ftdi_usb_get_strings(&ftdic, curdev->dev, NULL, 0, NULL, 0, serialBuffer, 10); 302 Log::notice("Ret: %d",ret); 303 //blir -9 efter felen, "get serial number failed", även lsusb -v ger annat svar än innan...? 280 304 if (ret != 0) { 281 305 continue;
Note: See TracChangeset
for help on using the changeset viewer.
