diff --git a/telldus-core/client/telldus-core.h b/telldus-core/client/telldus-core.h index e84cf0b4..3067ab7c 100644 --- a/telldus-core/client/telldus-core.h +++ b/telldus-core/client/telldus-core.h @@ -149,5 +149,6 @@ extern "C" { #define TELLSTICK_CHANGE_MODEL 3 #define TELLSTICK_CHANGE_METHOD 4 #define TELLSTICK_CHANGE_AVAILABLE 5 +#define TELLSTICK_CHANGE_FIRMWARE 6 #endif diff --git a/telldus-core/service/Controller.cpp b/telldus-core/service/Controller.cpp index e7b9794f..02a6b279 100644 --- a/telldus-core/service/Controller.cpp +++ b/telldus-core/service/Controller.cpp @@ -1,17 +1,20 @@ #include "Controller.h" #include "Protocol.h" -#include //TODO DEBUG +#include "EventUpdateManager.h" +#include "Strings.h" class Controller::PrivateData { public: - TelldusCore::EventRef event; - int id; + TelldusCore::EventRef event, updateEvent; + int id, firmwareVersion; }; -Controller::Controller(int id, TelldusCore::EventRef event){ +Controller::Controller(int id, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent){ d = new PrivateData; d->event = event; + d->updateEvent = updateEvent; d->id = id; + d->firmwareVersion = 0; } Controller::~Controller(){ @@ -33,3 +36,18 @@ void Controller::decodePublishData(const std::string &data) const { this->publishData(*msgIt); } } + +int Controller::firmwareVersion() const { + return d->firmwareVersion; +} + +void Controller::setFirmwareVersion(int version) { + d->firmwareVersion = version; + EventUpdateData *eventData = new EventUpdateData(); + eventData->messageType = L"TDControllerEvent"; + eventData->controllerId = d->id; + eventData->eventState = TELLSTICK_DEVICE_CHANGED; + eventData->eventChangeType = TELLSTICK_CHANGE_FIRMWARE; + eventData->eventValue = TelldusCore::intToWstring(version); + d->updateEvent->signal(eventData); +} diff --git a/telldus-core/service/Controller.h b/telldus-core/service/Controller.h index 6c9236af..eff903f7 100644 --- a/telldus-core/service/Controller.h +++ b/telldus-core/service/Controller.h @@ -14,14 +14,15 @@ class Controller { public: virtual ~Controller(); - virtual int firmwareVersion() = 0; + virtual int firmwareVersion() const; virtual int send( const std::string &message ) = 0; virtual int reset() = 0; protected: - Controller(int id, TelldusCore::EventRef event); + Controller(int id, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent); void publishData(const std::string &data) const; void decodePublishData(const std::string &data) const; + void setFirmwareVersion(int version); private: class PrivateData; diff --git a/telldus-core/service/ControllerManager.cpp b/telldus-core/service/ControllerManager.cpp index e43246dc..ba6bcff3 100644 --- a/telldus-core/service/ControllerManager.cpp +++ b/telldus-core/service/ControllerManager.cpp @@ -177,7 +177,7 @@ void ControllerManager::loadControllers() { } //int controllerId = d->lastControllerId+1; - TellStick *controller = new TellStick(controllerId, d->event, *it); + TellStick *controller = new TellStick(controllerId, d->event, d->updateEvent, *it); if (!controller->isOpen()) { delete controller; continue; diff --git a/telldus-core/service/TellStick.h b/telldus-core/service/TellStick.h index 1a5c1b45..05e76b04 100644 --- a/telldus-core/service/TellStick.h +++ b/telldus-core/service/TellStick.h @@ -24,10 +24,9 @@ public: class TellStick : public Controller, public TelldusCore::Thread { public: - TellStick(int controllerId, TelldusCore::EventRef event, const TellStickDescriptor &d); + TellStick(int controllerId, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent, const TellStickDescriptor &d); virtual ~TellStick(); - virtual int firmwareVersion(); virtual int pid() const; virtual int vid() const; virtual std::string serial() const; diff --git a/telldus-core/service/TellStick_ftd2xx.cpp b/telldus-core/service/TellStick_ftd2xx.cpp index 01f95038..a10e71f3 100644 --- a/telldus-core/service/TellStick_ftd2xx.cpp +++ b/telldus-core/service/TellStick_ftd2xx.cpp @@ -24,7 +24,7 @@ class TellStick::PrivateData { public: bool open, running, ignoreControllerConfirmation; - int vid, pid, fwVersion; + int vid, pid; std::string serial, message; FT_HANDLE ftHandle; TelldusCore::Mutex mutex; @@ -40,8 +40,8 @@ public: #endif }; -TellStick::TellStick(int controllerId, TelldusCore::EventRef event, const TellStickDescriptor &td ) - :Controller(controllerId, event) +TellStick::TellStick(int controllerId, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent, const TellStickDescriptor &td ) + :Controller(controllerId, event, updateEvent) { d = new PrivateData; #ifdef _WINDOWS @@ -54,7 +54,6 @@ TellStick::TellStick(int controllerId, TelldusCore::EventRef event, const TellSt d->running = false; d->vid = td.vid; d->pid = td.pid; - d->fwVersion = 0; d->serial = td.serial; Settings set; d->ignoreControllerConfirmation = set.getSetting(L"ignoreControllerConfirmation")==L"true"; @@ -109,10 +108,6 @@ void TellStick::setBaud( int baud ) { FT_SetBaudRate(d->ftHandle, baud); } -int TellStick::firmwareVersion() { - return d->fwVersion; -} - int TellStick::pid() const { return d->pid; } @@ -148,7 +143,7 @@ void TellStick::processData( const std::string &data ) { continue; } else if (data[i] == 10) { // \n found if (d->message.substr(0,2).compare("+V") == 0) { - d->fwVersion = TelldusCore::charToInteger(d->message.substr(2).c_str()); + setFirmwareVersion(TelldusCore::charToInteger(d->message.substr(2).c_str())); } else if (d->message.substr(0,2).compare("+R") == 0) { this->publishData(d->message.substr(2)); } else if(d->message.substr(0,2).compare("+W") == 0) {