Started refactoring Device into Controllers

This commit is contained in:
Micke Prag 2009-11-01 19:19:58 +00:00
parent 72cc92b5af
commit c688af38c4
5 changed files with 129 additions and 6 deletions

View file

@ -22,6 +22,7 @@ SET( telldus-core_SRCS
Controller.cpp
Manager.cpp
Settings.cpp
TellStick.cpp
telldus-core.cpp
)

View file

@ -21,13 +21,13 @@
namespace TelldusCore {
class Controller {
public:
Controller();
virtual ~Controller();
virtual int firmwareVersion() = 0;
virtual int send( const std::string &message ) = 0;
protected:
Controller();
};
}

View file

@ -25,7 +25,7 @@
#include "Controller.h"
#ifdef TELLSTICK_DUO
#include "TellStickDuo.h"
#include "TellStick.h"
#endif
#include "common.h"
@ -46,8 +46,10 @@ Manager::Manager()
: lastCallbackId(0)
{
#ifdef TELLSTICK_DUO
Controller *controller = new TellStickDuo("TSQVB5HU");
/* Controller *controller = TellStick::findFirstDevice();
if (controller) {
controllers[1] = controller;
}*/
#endif
}

View file

@ -0,0 +1,85 @@
//
// C++ Implementation: TellStick
//
// Description:
//
//
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "TellStick.h"
#include "ftd2xx.h"
#include <string>
using namespace TelldusCore;
TellStick::TellStick() {
}
TellStick::~TellStick() {
}
int TellStick::findFirstDevice() {
//TellStick
std::string serial = findByVIDPID(0x1781, 0x0C30);
if (serial.length() > 0) {
return 1;
}
//TellStick Duo
serial = findByVIDPID(0x1781, 0x0C31);
if (serial.length() > 0) {
return 2;
}
return 0;
}
std::string TellStick::findByVIDPID( int vid, int pid ) {
FT_HANDLE fthHandle = 0;
FT_STATUS ftStatus = FT_OK;
try{
DWORD dwNumberOfDevices = 0;
#ifndef _WINDOWS
FT_SetVIDPID(vid, pid);
#endif
ftStatus = FT_CreateDeviceInfoList(&dwNumberOfDevices);
if (ftStatus == FT_OK) {
for (int i = 0; i < (int)dwNumberOfDevices; i++) {
FT_PROGRAM_DATA pData;
char ManufacturerBuf[32];
char ManufacturerIdBuf[16];
char DescriptionBuf[64];
char SerialNumberBuf[16];
pData.Signature1 = 0x00000000;
pData.Signature2 = 0xffffffff;
pData.Version = 0x00000002; // EEPROM structure with FT232R extensions
pData.Manufacturer = ManufacturerBuf;
pData.ManufacturerId = ManufacturerIdBuf;
pData.Description = DescriptionBuf;
pData.SerialNumber = SerialNumberBuf;
ftStatus = FT_Open(i, &fthHandle);
ftStatus = FT_EE_Read(fthHandle, &pData);
if(ftStatus == FT_OK){
if(pData.VendorId == vid && pData.ProductId == pid){
ftStatus = FT_Close(fthHandle);
return pData.SerialNumber;
}
}
ftStatus = FT_Close(fthHandle);
}
}
}
catch(...){
throw;
}
return "";
}

View file

@ -0,0 +1,35 @@
//
// C++ Interface: TellStick
//
// Description:
//
//
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef TELLSTICK_H
#define TELLSTICK_H
#include "controller.h"
/**
@author Micke Prag <micke.prag@telldus.se>
*/
namespace TelldusCore {
class TellStick : public Controller {
public:
virtual ~TellStick();
static int findFirstDevice();
protected:
TellStick();
private:
static std::string findByVIDPID( int vid, int pid );
};
}
#endif