Signal the firmware version as a modified signal. This since we don't know the firmware when a new controller is found. We need to communicate with the device first and the version will be detected later
This commit is contained in:
parent
237cf4e8e7
commit
d728664785
6 changed files with 32 additions and 18 deletions
|
@ -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
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
#include "Controller.h"
|
||||
#include "Protocol.h"
|
||||
#include <stdio.h> //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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue