From ecf09abe0ff44823804b0fdef3d468aa0e6f544f Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Tue, 5 Feb 2008 13:14:30 +0000 Subject: [PATCH] Initial import of TellStick-driver --- driver/CMakeLists.txt | 6 + driver/TellUsbD101.sln | 20 + driver/TellUsbD101/CMakeLists.txt | 27 + driver/TellUsbD101/Device.cpp | 52 ++ driver/TellUsbD101/Device.h | 24 + driver/TellUsbD101/DeviceIkea.cpp | 141 ++++ driver/TellUsbD101/DeviceIkea.h | 23 + driver/TellUsbD101/DeviceNexa.cpp | 163 +++++ driver/TellUsbD101/DeviceNexa.h | 22 + driver/TellUsbD101/DeviceSartano.cpp | 128 ++++ driver/TellUsbD101/DeviceSartano.h | 21 + driver/TellUsbD101/DeviceWaveman.cpp | 58 ++ driver/TellUsbD101/DeviceWaveman.h | 11 + driver/TellUsbD101/Resource.h | 31 + driver/TellUsbD101/TellUsbD101.cpp | 321 +++++++++ driver/TellUsbD101/TellUsbD101.def | 24 + driver/TellUsbD101/TellUsbD101.h | 73 +++ driver/TellUsbD101/TellUsbD101.vcproj | 308 +++++++++ driver/TellUsbD101/TelldusSettings.cpp | 631 ++++++++++++++++++ driver/TellUsbD101/TelldusSettings.h | 42 ++ driver/TellUsbD101/linux/Device.cpp | 85 +++ driver/TellUsbD101/stdafx.cpp | 8 + driver/TellUsbD101/stdafx.h | 37 ++ driver/TellUsbD101/win/Device.cpp | 91 +++ driver/TellUsbD101/win/FTD2XX.H | 875 +++++++++++++++++++++++++ 25 files changed, 3222 insertions(+) create mode 100644 driver/CMakeLists.txt create mode 100644 driver/TellUsbD101.sln create mode 100644 driver/TellUsbD101/CMakeLists.txt create mode 100644 driver/TellUsbD101/Device.cpp create mode 100644 driver/TellUsbD101/Device.h create mode 100644 driver/TellUsbD101/DeviceIkea.cpp create mode 100644 driver/TellUsbD101/DeviceIkea.h create mode 100644 driver/TellUsbD101/DeviceNexa.cpp create mode 100644 driver/TellUsbD101/DeviceNexa.h create mode 100644 driver/TellUsbD101/DeviceSartano.cpp create mode 100644 driver/TellUsbD101/DeviceSartano.h create mode 100644 driver/TellUsbD101/DeviceWaveman.cpp create mode 100644 driver/TellUsbD101/DeviceWaveman.h create mode 100644 driver/TellUsbD101/Resource.h create mode 100644 driver/TellUsbD101/TellUsbD101.cpp create mode 100644 driver/TellUsbD101/TellUsbD101.def create mode 100644 driver/TellUsbD101/TellUsbD101.h create mode 100644 driver/TellUsbD101/TellUsbD101.vcproj create mode 100644 driver/TellUsbD101/TelldusSettings.cpp create mode 100644 driver/TellUsbD101/TelldusSettings.h create mode 100644 driver/TellUsbD101/linux/Device.cpp create mode 100644 driver/TellUsbD101/stdafx.cpp create mode 100644 driver/TellUsbD101/stdafx.h create mode 100644 driver/TellUsbD101/win/Device.cpp create mode 100644 driver/TellUsbD101/win/FTD2XX.H diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt new file mode 100644 index 00000000..18cc7359 --- /dev/null +++ b/driver/CMakeLists.txt @@ -0,0 +1,6 @@ +PROJECT( tellstick ) + +CMAKE_MINIMUM_REQUIRED( VERSION 2.4.0 ) + +ADD_SUBDIRECTORY(TellUsbD101) + diff --git a/driver/TellUsbD101.sln b/driver/TellUsbD101.sln new file mode 100644 index 00000000..1b22fbc9 --- /dev/null +++ b/driver/TellUsbD101.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TellUsbD101", "TellUsbD101\TellUsbD101.vcproj", "{2A868E40-88D9-4800-A83F-21D0F8DCB611}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2A868E40-88D9-4800-A83F-21D0F8DCB611}.Debug|Win32.ActiveCfg = Release|Win32 + {2A868E40-88D9-4800-A83F-21D0F8DCB611}.Debug|Win32.Build.0 = Release|Win32 + {2A868E40-88D9-4800-A83F-21D0F8DCB611}.Release|Win32.ActiveCfg = Release|Win32 + {2A868E40-88D9-4800-A83F-21D0F8DCB611}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/driver/TellUsbD101/CMakeLists.txt b/driver/TellUsbD101/CMakeLists.txt new file mode 100644 index 00000000..55842bce --- /dev/null +++ b/driver/TellUsbD101/CMakeLists.txt @@ -0,0 +1,27 @@ + +SET( tellusbd101_SRCS + Device.cpp + linux/Device.cpp + DeviceIkea.cpp + DeviceNexa.cpp + DeviceSartano.cpp + DeviceWaveman.cpp + ) + +ADD_DEFINITIONS( + -DOS_LINUX + ) + +ADD_LIBRARY(tellusbd101 SHARED + ${tellusbd101_SRCS} + ${tellusbd101_MOC_SRCS} + ) + +# TARGET_LINK_LIBRARIES(tellusbd101 +# ${MIDAS_LIBRARY} +# ) + +INSTALL(TARGETS tellusbd101 LIBRARY + DESTINATION lib + ) + diff --git a/driver/TellUsbD101/Device.cpp b/driver/TellUsbD101/Device.cpp new file mode 100644 index 00000000..3d6a6322 --- /dev/null +++ b/driver/TellUsbD101/Device.cpp @@ -0,0 +1,52 @@ +#include "Device.h" + +/* +* Constructor +*/ +Device::Device(int intDongleIndex) +{ + this->intDongleIndex = intDongleIndex; +} + +/* +* Destructor +*/ +Device::~Device(void) +{ + intDongleIndex = -1; +} + +/* +* Turn on, virtual +*/ +void Device::turnOn(void){ + //do nothing +} + +/* +* Turn off, virtual +*/ +void Device::turnOff(void){ + //do nothing +} + +/* +* Bell, virtual +*/ +void Device::bell(void){ + //do nothing +} + +/* +* Dim, virtual +*/ +void Device::dim(unsigned char level){ + //do nothing +} + +/* +* Has Method, virtual +*/ +bool Device::hasMethod(int methodname, char* strModel){ + return false; +} diff --git a/driver/TellUsbD101/Device.h b/driver/TellUsbD101/Device.h new file mode 100644 index 00000000..4f4e5f1d --- /dev/null +++ b/driver/TellUsbD101/Device.h @@ -0,0 +1,24 @@ +#pragma once + +#include "TellUsbD101.h" + +class Device +{ +private: + int intDongleIndex; +protected: + void send(char* strMessage); +public: + Device(int intDeviceIndex); + virtual void turnOn(void); + virtual void turnOff(void); + virtual void bell(void); + virtual void dim(unsigned char level); + virtual bool hasMethod(int methodname, char* strModel); + static int getDongleIndex(); + + static void debugLog(char* debugstring); + +public: + ~Device(void); +}; diff --git a/driver/TellUsbD101/DeviceIkea.cpp b/driver/TellUsbD101/DeviceIkea.cpp new file mode 100644 index 00000000..a32f00ff --- /dev/null +++ b/driver/TellUsbD101/DeviceIkea.cpp @@ -0,0 +1,141 @@ +// #include "StdAfx.h" //Needed? +#include "DeviceIkea.h" +#include +#include +#include +#include +#include + +using namespace std; + +/* +* Constructor +*/ +DeviceIkea::DeviceIkea(int intNewSystem, int intNewUnits, int intNewFadeStyle, int intDeviceIndex):Device(intDeviceIndex){ + intSystem = intNewSystem; + intUnits = intNewUnits; + intFadeStyle = intNewFadeStyle; +} + +/* +* Destructor +*/ +DeviceIkea::~DeviceIkea(void) +{ + intSystem = -1; + intUnits = -1; + intFadeStyle = -1; +} + +/* +* Turn on this device +*/ +void DeviceIkea::turnOn(void){ + try{ + string strCode = getStringCode(255); + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Turn off this device +*/ +void DeviceIkea::turnOff(void){ + try{ + string strCode = getStringCode(0); + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Turn off this device +*/ +void DeviceIkea::dim(unsigned char level){ + try{ + string strCode = getStringCode(level); + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Convert an integer to byte string where 0 is represented by ª and 1 by TT +*/ +string DeviceIkea::getStringCode(unsigned char level){ + + string strReturn = "STTTTTTª"; //Startcode, always like this; + + try{ + string strChannels = ""; + int intCode = (intSystem << 10) | intUnits; + int checksum1 = 0; + int checksum2 = 0; + for (int i = 13; i >= 0; --i) { + if ((intCode>>i) & 1) { + strChannels.append("TT"); + if (13 % 2 == 0) + checksum2++; + else + checksum1++; + } else { + strChannels.append("ª"); + } + } + strReturn.append(strChannels); //System + Units + + strReturn.append(checksum1 %2 == 0 ? "TT" : "ª"); //1st checksum + strReturn.append(checksum2 %2 == 0 ? "TT" : "ª"); //2nd checksum + + if (level <= 12) { + strReturn.append("ªTTªTT"); //Level 0 - Off + } else if (level <= 137) { + strReturn.append("TTªTTª"); //Level 5 + } else if (level <= 162) { + strReturn.append("ªTTTTª"); //Level 6 + } else { + strReturn.append("ªªªª"); //Level 10 - On + } + + if (intFadeStyle == 1) + strReturn.append("TTTTªª"); //Smooth + else + strReturn.append("TTªªTT"); //Instant + strReturn.append("+"); + + } + catch(...){ + throw; + } + return strReturn; + +} + +/* +* Has the device got the method? +*/ +bool DeviceIkea::hasMethod(int methodname, char* strModel){ + + if(strcmp(strModel, TELLSTICK_DEVICE_KOPPLA) == 0) { + if(methodname == TELLSTICK_TURNON || methodname == TELLSTICK_TURNOFF || methodname == TELLSTICK_DIM){ + return true; + } + } + return false; +} diff --git a/driver/TellUsbD101/DeviceIkea.h b/driver/TellUsbD101/DeviceIkea.h new file mode 100644 index 00000000..bbe34c75 --- /dev/null +++ b/driver/TellUsbD101/DeviceIkea.h @@ -0,0 +1,23 @@ +#pragma once +#include "Device.h" +#include + +class DeviceIkea : public Device +{ +public: + DeviceIkea(int intSystem, int intUnits, int fadeStyle, int intDeviceIndex); + virtual void turnOn(void); + virtual void turnOff(void); + virtual void dim(unsigned char level); + virtual bool hasMethod(int methodname, char* strModel); + +public: + ~DeviceIkea(void); + +protected: + int intSystem; + int intUnits; + int intFadeStyle; + std::string getStringCode(unsigned char); +}; + diff --git a/driver/TellUsbD101/DeviceNexa.cpp b/driver/TellUsbD101/DeviceNexa.cpp new file mode 100644 index 00000000..4deb98d7 --- /dev/null +++ b/driver/TellUsbD101/DeviceNexa.cpp @@ -0,0 +1,163 @@ +// #include "StdAfx.h" +#include "DeviceNexa.h" +#include +#include +#include +#include +#include + +using namespace std; + +/* +* Constructor +*/ +DeviceNexa::DeviceNexa(int intNewHouse, int intNewCode, int intDeviceIndex):Device(intDeviceIndex){ + intHouse = intNewHouse; + intCode = intNewCode; +} + +/* +* Destructor +*/ +DeviceNexa::~DeviceNexa(void) +{ + intHouse = -1; + intCode = -1; +} + +/* +* Turn on this device +*/ +void DeviceNexa::turnOn(void){ + + try{ + //char* model = getModel(intDeviceId); + string strCode = getStringCode(intCode); + string strHouse = getStringCode(intHouse); + strCode.append(strHouse); + + strCode.insert(0, "S"); + strCode.append("$k$k$kk$$kk$$kk$$k+"); //the "turn on"-code, keeps it like this, doesn't have to be regenerated each time + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Turn off this device +*/ +void DeviceNexa::turnOff(void){ + + try{ + string strCode = getStringCode(intCode); + string strHouse = getStringCode(intHouse); + + strCode.append(strHouse); + strCode.insert(0, "S"); + strCode.append("$k$k$kk$$kk$$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Send a bell +*/ +void DeviceNexa::bell(void){ + + try{ + string strCode = getStringCode(intCode); + + strCode.append("$kk$$kk$$kk$$k$k"); //the unit-code is always 7, doesn't have to be regenerated each time + strCode.insert(0, "S"); + strCode.append("$kk$$kk$$kk$$kk$$k+"); //the "bell"-code, keeps it like this, doesn't have to be regenerated each time + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Convert an integer to byte string where 0 is represented by $k and 1 by k$, reversed and padded with 0's as needed +*/ +string DeviceNexa::getStringCode(int intToConvert){ + + string strReturn = ""; + + try{ + bitset<4> bs ((long)intToConvert); + + strReturn = bs.to_string(); + reverse(strReturn.begin(), strReturn.end()); + + int intPos = (int)strReturn.find("0"); + while (intPos < string::npos){ + strReturn.replace(intPos, 1, "$k"); + intPos = (int)strReturn.find("0", intPos + 1); + } + + intPos = (int)strReturn.find("1"); + while (intPos < string::npos){ + strReturn.replace(intPos, 1, "k$"); + intPos = (int)strReturn.find("1", intPos + 1); + } + + intPos = 0; + while (intPos < (int)strReturn.length()){ + strReturn.insert(intPos, "$k"); + intPos = intPos + 4; + } + } + catch(...){ + throw; + } + return strReturn; + +} + +/* +* Has the device got the method? +*/ +bool DeviceNexa::hasMethod(int methodname, char* strModel){ + + if( strcmp(strModel, TELLSTICK_DEVICE_YCR3500) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_YCR300D) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_WSR1000) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_CMR1000) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_CMR300) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_PA33300) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_EL2000) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_EL2005) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_EL2006) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_SYCR3500) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_SYCR300) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_HDR105) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_EL2004) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_EL2016) == 0 || + strcmp(strModel, TELLSTICK_DEVICE_EL2010) == 0 + ) + { + if(methodname == TELLSTICK_TURNON || methodname == TELLSTICK_TURNOFF){ + return true; + } + } else if ( strcmp(strModel, TELLSTICK_DEVICE_ML7100) == 0 ) { + if(methodname == TELLSTICK_BELL) { + return true; + } + } + return false; +} diff --git a/driver/TellUsbD101/DeviceNexa.h b/driver/TellUsbD101/DeviceNexa.h new file mode 100644 index 00000000..9ae10a72 --- /dev/null +++ b/driver/TellUsbD101/DeviceNexa.h @@ -0,0 +1,22 @@ +#pragma once +#include "Device.h" +#include + +class DeviceNexa : public Device +{ +public: + DeviceNexa(int intHouse, int intCode, int intDeviceIndex); + virtual void turnOn(void); + virtual void turnOff(void); + virtual void bell(void); + virtual bool hasMethod(int methodname, char* strModel); + +public: + ~DeviceNexa(void); + +protected: + int intHouse; + int intCode; + std::string getStringCode(int); +}; + diff --git a/driver/TellUsbD101/DeviceSartano.cpp b/driver/TellUsbD101/DeviceSartano.cpp new file mode 100644 index 00000000..c06a7f0b --- /dev/null +++ b/driver/TellUsbD101/DeviceSartano.cpp @@ -0,0 +1,128 @@ +#include "DeviceSartano.h" +#include "DeviceNexa.h" +#include +#include +#include +#include + +using namespace std; + +/* +* Constructor +*/ +DeviceSartano::DeviceSartano(int intNewSystem, int intNewCode, int intDeviceIndex) + :Device(intDeviceIndex) +{ + intSystem = intNewSystem; + intCode = intNewCode; +} + + +DeviceSartano::~DeviceSartano(void) +{ + intSystem = -1; + intCode = -1; +} + + +/* +* Turn on this device +*/ +void DeviceSartano::turnOn(void){ + + try{ + string strSystem = getStringCode(intSystem); + string strCode = getStringCode(intCode); + strSystem.append(strCode); + + strSystem.insert(0, "S"); + strSystem.append("$k$k$kk$$k+"); //the "turn on"-code, keeps it like this, doesn't have to be regenerated each time + + char* strMessage = const_cast(strSystem.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Turn off this device +*/ +void DeviceSartano::turnOff(void){ + + try{ + string strSystem = getStringCode(intSystem); + string strCode = getStringCode(intCode); + strSystem.append(strCode); + + strSystem.insert(0, "S"); + strSystem.append("$kk$$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time + + char* strMessage = const_cast(strSystem.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Has the device got the method? +*/ +bool DeviceSartano::hasMethod(int methodname, char* strModel){ + + bool blnExists = false; + + try{ +// if(strModel == "xxxx" || strModel == "yyyy"){ + if(methodname == TELLSTICK_TURNON || methodname == TELLSTICK_TURNOFF){ + blnExists = true; +// } + } + } + catch(...){ + throw; + } + return blnExists; +} + +/* +* Convert an integer to byte string where 0 is represented by $k and 1 by k$, reversed and padded with 0's as needed +*/ +string DeviceSartano::getStringCode(int intToConvert){ + + string strReturn = ""; + + try{ + bitset<5> bs ((long)intToConvert); + + strReturn = bs.to_string(); + + int intPos = (int)strReturn.find("0"); + while (intPos < string::npos){ + strReturn.replace(intPos, 1, "$k"); + intPos = (int)strReturn.find("0", intPos + 1); + } + + intPos = (int)strReturn.find("1"); + while (intPos < string::npos){ + strReturn.replace(intPos, 1, "k$"); + intPos = (int)strReturn.find("1", intPos + 1); + } + + intPos = 0; + while (intPos < (int)strReturn.length()){ + strReturn.insert(intPos, "$k"); + intPos = intPos + 4; + } + } + catch(...){ + throw; + } + return strReturn; + +} + diff --git a/driver/TellUsbD101/DeviceSartano.h b/driver/TellUsbD101/DeviceSartano.h new file mode 100644 index 00000000..929cf32d --- /dev/null +++ b/driver/TellUsbD101/DeviceSartano.h @@ -0,0 +1,21 @@ +#pragma once +#include "Device.h" +#include + + +class DeviceSartano : public Device +{ +public: + DeviceSartano(int intSystem, int intCode, int intDeviceIndex); + virtual void turnOn(void); + virtual void turnOff(void); + virtual bool hasMethod(int methodname, char* strModel); + + ~DeviceSartano(void); + +protected: + std::string getStringCode(int); + + int intSystem; + int intCode; +}; diff --git a/driver/TellUsbD101/DeviceWaveman.cpp b/driver/TellUsbD101/DeviceWaveman.cpp new file mode 100644 index 00000000..dbbf3f69 --- /dev/null +++ b/driver/TellUsbD101/DeviceWaveman.cpp @@ -0,0 +1,58 @@ +// #include "StdAfx.h" +#include "DeviceWaveman.h" +#include +#include +#include +#include +#include + +using namespace std; + +/* +* Constructor +*/ +DeviceWaveman::DeviceWaveman(int intNewHouse, int intNewCode, int intDeviceIndex) + :DeviceNexa(intNewHouse, intNewCode, intDeviceIndex){ +} + +/* +* Turn off this device +*/ +void DeviceWaveman::turnOff(void){ + + try{ + string strCode = getStringCode(intCode); + string strHouse = getStringCode(intHouse); + + strCode.append(strHouse); + strCode.insert(0, "S"); + strCode.append("$k$k$k$k$k$k$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time + + char* strMessage = const_cast(strCode.c_str()); + + Device::send(strMessage); + } + catch(...){ + throw; + } +} + +/* +* Has the device got the method? +*/ +bool DeviceWaveman::hasMethod(int methodname, char* strModel){ + + bool blnExists = false; + + try{ +// if(strModel == "xxxx" || strModel == "yyyy"){ + if(methodname == TELLSTICK_TURNON || methodname == TELLSTICK_TURNOFF){ + blnExists = true; +// } + } + } + catch(...){ + throw; + } + return blnExists; +} diff --git a/driver/TellUsbD101/DeviceWaveman.h b/driver/TellUsbD101/DeviceWaveman.h new file mode 100644 index 00000000..ab013172 --- /dev/null +++ b/driver/TellUsbD101/DeviceWaveman.h @@ -0,0 +1,11 @@ +#pragma once +#include "DeviceNexa.h" +#include + +class DeviceWaveman : public DeviceNexa +{ +public: + DeviceWaveman(int intHouse, int intCode, int intDeviceIndex); + virtual void turnOff(void); + virtual bool hasMethod(int methodname, char* strModel); +}; diff --git a/driver/TellUsbD101/Resource.h b/driver/TellUsbD101/Resource.h new file mode 100644 index 00000000..0c5cdd60 --- /dev/null +++ b/driver/TellUsbD101/Resource.h @@ -0,0 +1,31 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by testruntelldus3.rc +// + +#define IDS_APP_TITLE 103 + +#define IDR_MAINFRAME 128 +#define IDD_TESTRUNTELLDUS3_DIALOG 102 +#define IDD_ABOUTBOX 103 +#define IDM_ABOUT 104 +#define IDM_EXIT 105 +#define IDI_TESTRUNTELLDUS3 107 +#define IDI_SMALL 108 +#define IDC_TESTRUNTELLDUS3 109 +#define IDC_MYICON 2 +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS + +#define _APS_NO_MFC 130 +#define _APS_NEXT_RESOURCE_VALUE 129 +#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 110 +#endif +#endif diff --git a/driver/TellUsbD101/TellUsbD101.cpp b/driver/TellUsbD101/TellUsbD101.cpp new file mode 100644 index 00000000..c51be172 --- /dev/null +++ b/driver/TellUsbD101/TellUsbD101.cpp @@ -0,0 +1,321 @@ +//DLL entry point + +#include "stdafx.h" +#include "TellUsbD101.h" +#include "TelldusSettings.h" +#include "Device.h" +#include +#include +#include +#include + +void handleException(std::exception e); + + +#define MAX_LOADSTRING 100 + +//TODO: +//delete on created objects +//comment (just copy from the called methods) + +bool __stdcall devTurnOn(int intDeviceId){ + + try{ + TelldusSettings ts; + Device* dev = ts.getDevice(intDeviceId); + if(dev != NULL){ + dev->turnOn(); + + delete(dev); + return true; + } + else{ + return false; + } + } + catch(exception e){ + handleException(e); + } + return false; +} + +bool __stdcall devTurnOff(int intDeviceId){ + + try{ + TelldusSettings ts; + Device* dev = ts.getDevice(intDeviceId); + if(dev != NULL){ + dev->turnOff(); + + delete(dev); + return true; + } + else{ + return false; + } + } + catch(exception e){ + handleException(e); + } + return false; +} + +bool __stdcall devBell(int intDeviceId){ + + try{ + TelldusSettings ts; + Device* dev = ts.getDevice(intDeviceId); + if(dev != NULL){ + dev->bell(); + + delete(dev); + return true; + } + else{ + return false; + } + } + catch(exception e){ + handleException(e); + } + return false; +} + +bool __stdcall devDim(int intDeviceId, unsigned char level){ + + try{ + TelldusSettings ts; + Device* dev = ts.getDevice(intDeviceId); + if(dev != NULL){ + if (level == 0) { + dev->turnOff(); + } else if (level == 255) { + dev->turnOn(); + } else { + dev->dim(level); + } + delete(dev); + return true; + } + else{ + return false; + } + } + catch(exception e){ + handleException(e); + } + return false; +} + +int __stdcall devGetNumberOfDevices(void){ + int intReturn = -1; + try{ + TelldusSettings ts; + intReturn = ts.getNumberOfDevices(); + } + catch(exception e){ + intReturn = -1; + handleException(e); + } + return intReturn; +} + +int __stdcall devGetDeviceId(int intDeviceIndex){ + int intReturn = -1; + try{ + TelldusSettings ts; + intReturn = ts.getDeviceId(intDeviceIndex); + } + catch(exception e){ + intReturn = -1; + handleException(e); + } + return intReturn; +} + +//general settings: +char * __stdcall devGetName(int intDeviceId){ + char* strReturn; + try{ + TelldusSettings ts; + strReturn = ts.getName(intDeviceId); + } + catch(exception e){ + strReturn = ""; + handleException(e); + } + return strReturn; +} + +bool __stdcall devSetName(int intDeviceId, char* strNewName){ + bool blnSuccess = false; + try{ + TelldusSettings ts; + blnSuccess = ts.setName(intDeviceId, strNewName); + } + catch(exception e){ + blnSuccess = false; + handleException(e); + } + return blnSuccess; +} + +char* __stdcall devGetVendor(int intDeviceId){ + char* strReturn = ""; + try{ + TelldusSettings ts; + strReturn = ts.getVendor(intDeviceId); + } + catch(exception e){ + strReturn = ""; + handleException(e); + } + return strReturn; +} + +bool __stdcall devSetVendor(int intDeviceId, char* strVendor){ + bool blnSuccess = false; + try{ + TelldusSettings ts; + blnSuccess = ts.setVendor(intDeviceId, strVendor); + } + catch(exception e){ + blnSuccess = false; + handleException(e); + } + return blnSuccess; +} + + char* __stdcall devGetModel(int intDeviceId){ + char* strReturn = ""; + try{ + TelldusSettings ts; + strReturn = ts.getModel(intDeviceId); + } + catch(exception e){ + strReturn = ""; + handleException(e); + } + return strReturn; +} + +bool __stdcall devSetModel(int intDeviceId, char* strNewModel){ + bool blnSuccess = false; + try{ + TelldusSettings ts; + blnSuccess = ts.setModel(intDeviceId, strNewModel); + } + catch(exception e){ + blnSuccess = false; + handleException(e); + } + return blnSuccess; +} + +bool __stdcall devSetArguments(int intDeviceId, char* strArguments){ + + vector vArguments; + //int intArguments[] = new int[]; //bort? + try{ + char* strTemp = strtok(strArguments, ","); + + while(strTemp != NULL){ + vArguments.push_back(atoi(strTemp)); + strTemp = strtok(NULL, ","); + } + TelldusSettings ts; + return ts.setArguments(intDeviceId, vArguments); + } + catch(exception e){ + handleException(e); + return false; + } +} + +int __stdcall devGetArgument(int intDeviceId, int intArgumentIndex){ + int intReturn; + try{ + if(intArgumentIndex != -1){ + TelldusSettings ts; + int* intArguments = ts.getArguments(intDeviceId); + intReturn = intArguments[intArgumentIndex]; + } + } + catch(exception e){ + handleException(e); + } + return intReturn; +} + +int __stdcall devGetNumberOfArguments(int intDeviceId){ + int intReturn; + try{ + TelldusSettings ts; + intReturn = ts.getNumberOfArguments(intDeviceId); + } + catch(exception e){ + handleException(e); + } + return intReturn; +} + +int __stdcall devAddDevice(){ + int intNewDeviceId = -1; + try{ + TelldusSettings ts; + int intNewDeviceId = ts.addDevice(); + } + catch(exception e){ + intNewDeviceId = -1; + handleException(e); + } + return intNewDeviceId; +} + +bool __stdcall devRemoveDevice(int intDeviceId){ + bool blnSuccess = false; + try{ + TelldusSettings ts; + blnSuccess = ts.removeDevice(intDeviceId); + } + catch(exception e){ + blnSuccess = false; + handleException(e); + } + return blnSuccess; +} + +bool __stdcall devHasMethod(int id, int methodname){ + + bool blnExists = false; + try{ + TelldusSettings ts; + char* strModel = ts.getModel(id); + Device* dev = ts.getDevice(id); + blnExists = dev->hasMethod(methodname, strModel); + } + catch(exception e){ + blnExists = false; + handleException(e); + } + return blnExists; +} + + +//******** +//* Error management, set strLogName to "" to turn off +//* +void handleException(exception e){ + + char* strLogName = "c:\\errorlog.txt"; + //char* strLogName = ""; + + if(strlen(strLogName) > 0){ + ofstream errorfile(strLogName, ios::app); + if(errorfile){ + errorfile << e.what() << endl; + errorfile.close(); + } + } +} + diff --git a/driver/TellUsbD101/TellUsbD101.def b/driver/TellUsbD101/TellUsbD101.def new file mode 100644 index 00000000..e79daad8 --- /dev/null +++ b/driver/TellUsbD101/TellUsbD101.def @@ -0,0 +1,24 @@ +LIBRARY TellUsbD101 +EXPORTS + devGetNumberOfDevices @1 + devGetDeviceId @2 + + devGetName @3 + devGetVendor @4 + devGetModel @5 + devGetNumberOfArguments @6 + devGetArgument @7 + + devSetName @8 + devSetVendor @9 + devSetModel @10 + devSetArguments @11 + + devAddDevice @12 + devRemoveDevice @13 + + devHasMethod @14 + devTurnOn @16 + devTurnOff @17 + devBell @18 + devDim @19 diff --git a/driver/TellUsbD101/TellUsbD101.h b/driver/TellUsbD101/TellUsbD101.h new file mode 100644 index 00000000..a5aeb6b8 --- /dev/null +++ b/driver/TellUsbD101/TellUsbD101.h @@ -0,0 +1,73 @@ +#ifndef TELLUSBD101_H +#define TELLUSBD101_H + +// The following ifdef block is the standard way of creating macros +// which make exporting from a DLL simpler. All files within this DLL +// are compiled with the TellUsbD101_EXPORTS symbol defined on the command line. +// This symbol should not be defined on any project that uses this DLL. +// This way any other project whose source files include this file see +// TELLSTICK_API functions as being imported from a DLL, whereas this DLL +// sees symbols defined with this macro as being exported. + +#ifdef TellUsbD101_EXPORTS + #define TELLSTICK_API __declspec(dllexport) +#else + #define TELLSTICK_API __declspec(dllimport) +#endif +#ifdef _WINDOWS + #define WINAPI __stdcall +#else + #define WINAPI +#endif + + +extern "C" { + TELLSTICK_API bool WINAPI devTurnOn(int intDeviceId); + TELLSTICK_API bool WINAPI devTurnOff(int intDeviceId); + TELLSTICK_API bool WINAPI devBell(int intDeviceId); + TELLSTICK_API bool WINAPI devDim(int intDeviceId, unsigned char level); + TELLSTICK_API int WINAPI devGetNumberOfDevices(); + TELLSTICK_API char * WINAPI devGetName(int intDeviceId); + TELLSTICK_API bool WINAPI devSetName(int intDeviceId, const char* chNewName); + TELLSTICK_API char* WINAPI devGetVendor(int intDeviceId); + TELLSTICK_API bool WINAPI devSetVendor(int intDeviceId, const char* chNewName); + TELLSTICK_API char* WINAPI devGetModel(int intDeviceId); + TELLSTICK_API bool WINAPI devSetModel(int intDeviceId, const char* chNewName); + TELLSTICK_API int WINAPI devGetArgument(int intDeviceId, int intArgumentIndex); + TELLSTICK_API int WINAPI devGetNumberOfArguments(int intDeviceId); + TELLSTICK_API bool WINAPI devSetArguments(int intDeviceId, const char* strArguments); + TELLSTICK_API int WINAPI devAddDevice(); + TELLSTICK_API int WINAPI devAddDeviceWithArguments(char* strVendor, int* intArguments[], int intNumberOfArguments); + TELLSTICK_API bool WINAPI devRemoveDevice(int intDeviceId); + TELLSTICK_API int WINAPI devGetDeviceId(int intDeviceIndex); + TELLSTICK_API bool WINAPI devHasMethod(int id, int methodname); +} + +#define TELLSTICK_TURNON 1 +#define TELLSTICK_TURNOFF 2 +#define TELLSTICK_BELL 4 +#define TELLSTICK_TOGGLE 8 +#define TELLSTICK_DIM 16 + +//Protocol Nexa +#define TELLSTICK_DEVICE_YCR3500 "1" +#define TELLSTICK_DEVICE_YCR300D "2" +#define TELLSTICK_DEVICE_WSR1000 "3" +#define TELLSTICK_DEVICE_CMR1000 "4" +#define TELLSTICK_DEVICE_CMR300 "5" +#define TELLSTICK_DEVICE_PA33300 "6" +#define TELLSTICK_DEVICE_EL2000 "8" +#define TELLSTICK_DEVICE_EL2005 "9" +#define TELLSTICK_DEVICE_EL2006 "10" +#define TELLSTICK_DEVICE_SYCR3500 "12" +#define TELLSTICK_DEVICE_SYCR300 "13" +#define TELLSTICK_DEVICE_HDR105 "14" +#define TELLSTICK_DEVICE_ML7100 "15" +#define TELLSTICK_DEVICE_EL2004 "16" +#define TELLSTICK_DEVICE_EL2016 "17" +#define TELLSTICK_DEVICE_EL2010 "18" + +//Protocol Ikea +#define TELLSTICK_DEVICE_KOPPLA "19" + +#endif diff --git a/driver/TellUsbD101/TellUsbD101.vcproj b/driver/TellUsbD101/TellUsbD101.vcproj new file mode 100644 index 00000000..5758d02b --- /dev/null +++ b/driver/TellUsbD101/TellUsbD101.vcproj @@ -0,0 +1,308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/driver/TellUsbD101/TelldusSettings.cpp b/driver/TellUsbD101/TelldusSettings.cpp new file mode 100644 index 00000000..d15b6e2f --- /dev/null +++ b/driver/TellUsbD101/TelldusSettings.cpp @@ -0,0 +1,631 @@ +#include "StdAfx.h" +#include "TelldusSettings.h" +#include "Device.h" +#include "DeviceNexa.h" +#include "DeviceWaveman.h" +#include "DeviceSartano.h" +#include "DeviceIkea.h" +#include +#include +#include +#include +#include + +using namespace std; + +/* +* Constructor +*/ +TelldusSettings::TelldusSettings(void) +{ + strRegPathDevice = "SOFTWARE\\Telldus\\Devices\\"; + strRegPath = "SOFTWARE\\Telldus\\"; + + intMaxRegValueLength = 1000; +} + +/* +* Destructor +*/ +TelldusSettings::~TelldusSettings(void) +{ + //RegCloseKey(hk); //close all, if still open //TODO: Need some way to know if open or closed + strRegPath = ""; + strRegPathDevice = ""; + intMaxRegValueLength = -1; + +} + +/* +* Return the number of stored devices +*/ +int TelldusSettings::getNumberOfDevices(void){ + + int intNumberOfDevices = 0; + + try{ + + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &hk); + + if(lnExists == ERROR_SUCCESS){ + + string strNumSubKeys; + DWORD dNumSubKeys; + RegQueryInfoKey(hk, NULL, NULL, NULL, &dNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + intNumberOfDevices = (int)dNumSubKeys; + + RegCloseKey(hk); + } + else{ + throw exception(); //couldn't open reg key + } + } + catch(...){ + intNumberOfDevices = -1; + } + return intNumberOfDevices; +} + +/* +* Get the requested device +*/ +Device* TelldusSettings::getDevice(int intDeviceId){ + + try{ + int intDongleIndex = Device::getDongleIndex(); + if(intDongleIndex != -1){ + return getDevice(intDeviceId, intDongleIndex); + } + else{ + return NULL; + } + } + catch(...){ + throw; + } +} + +/* +* Get the requested device, when the index of the USB dongle is known +* Note that the returned Device should be deleted when not in use anymore +*/ +Device* TelldusSettings::getDevice(int intDeviceId, int intDongleIndex){ + + Device* dev = 0; + + try{ + char* vendor = getVendor(intDeviceId); + + int* args = getArguments(intDeviceId); + + //each new brand must be added here + if (strcmp(vendor, "Nexa") == 0){ + dev = new DeviceNexa((int)args[0], (int)args[1], intDongleIndex); + } else if (strcmp(vendor, "Waveman") == 0) { + dev = new DeviceWaveman((int)args[0], (int)args[1], intDongleIndex); + } else if (strcmp(vendor, "Sartano") == 0) { + dev = new DeviceSartano((int)args[0], (int)args[1], intDongleIndex); + } else if (strcmp(vendor, "Ikea") == 0) { + dev = new DeviceIkea((int)args[0], (int)args[1], (int)args[2], intDongleIndex); + } + } + catch(...){ + throw; + } + return dev; +} + +/* +* Get the name of the device +*/ +char* TelldusSettings::getName(int intDeviceId){ + + char* strReturn = ""; + + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); + + if(lnExists == ERROR_SUCCESS){ + DWORD dwLength; + char* Buff = new char[intMaxRegValueLength]; + + long lngStatus = RegQueryValueEx(hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength); + if(lngStatus == ERROR_MORE_DATA){ + Buff = new char[dwLength]; + lngStatus = RegQueryValueEx(hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength); + } + strReturn = Buff; + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + } + catch(...){ + strReturn = ""; + } + return strReturn; +} + +/* +* Set the name of the device +*/ +bool TelldusSettings::setName(int intDeviceId, char* strNewName){ + + bool blnSuccess = true; + try{ + + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); + + if(lnExists == ERROR_SUCCESS){ + intMaxRegValueLength = (int)strlen(strNewName); + RegSetValueEx(hk, "Name", 0, REG_SZ, (LPBYTE)strNewName, intMaxRegValueLength); + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + + } + catch(...){ + blnSuccess = false; + } + return blnSuccess; +} + +/* +* Get the device vendor +*/ +char* TelldusSettings::getVendor(int intDeviceId){ + + char* strReturn = ""; + + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, (LPCSTR)strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); + + if(lnExists == ERROR_SUCCESS){ + DWORD dwLength; + char* Buff = new char[intMaxRegValueLength]; + + long lngStatus = RegQueryValueEx(hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength); + if(lngStatus == ERROR_MORE_DATA){ + Buff = new char[dwLength]; + lngStatus = RegQueryValueEx(hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength); + } + + strReturn = Buff; + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + } + catch(exception e){ + strReturn = ""; + ofstream errorfile("c:\\errorlog.txt", ios::app); + if(errorfile){ + errorfile << e.what() << endl; + errorfile.close(); + } + } + return strReturn; +} + +/* +* Set the device vendor +*/ +bool TelldusSettings::setVendor(int intDeviceId, char* strVendor){ + + bool blnSuccess = true; + try{ + + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); + + if(lnExists == ERROR_SUCCESS){ + intMaxRegValueLength = (int)strlen(strVendor); + RegSetValueEx(hk, "Vendor", 0, REG_SZ, (LPBYTE)strVendor, intMaxRegValueLength); + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + } + catch(...){ + blnSuccess = false; + } + return blnSuccess; +} + +/* +* Get the device model +*/ +char* TelldusSettings::getModel(int intDeviceId){ + + char* strReturn = ""; + + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); + + if(lnExists == ERROR_SUCCESS){ + DWORD dwLength; + char* Buff = new char[intMaxRegValueLength]; + + long lngStatus = RegQueryValueEx(hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength); + if(lngStatus == ERROR_MORE_DATA){ + + Buff = new char[dwLength]; + lngStatus = RegQueryValueEx(hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength); + } + strReturn = Buff; + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + } + catch(...){ + strReturn = ""; + } + return strReturn; +} + +/* +* Set the device model +*/ +bool TelldusSettings::setModel(int intDeviceId, char* strVendor){ + + bool blnSuccess = true; + try{ + + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); + + if(lnExists == ERROR_SUCCESS){ + intMaxRegValueLength = (int)strlen(strVendor); + RegSetValueEx(hk, "Model", 0, REG_SZ, (LPBYTE)strVendor, intMaxRegValueLength); + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + } + catch(...){ + blnSuccess = false; + } + return blnSuccess; +} + +int TelldusSettings::getDeviceId(int intDeviceIndex){ + int intReturn = -1; + + try{ + + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strRegPathDevice.c_str(), 0, KEY_READ, &hk); + + if(lnExists == ERROR_SUCCESS){ + + char* Buff = new char[intMaxRegValueLength]; + DWORD size; + if (RegEnumKeyEx(hk, intDeviceIndex, (LPSTR)Buff, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { + intReturn = (int)_atoi64(Buff); + } + + delete Buff; + + RegCloseKey(hk); + } + else{ + throw exception(); //couldn't open reg key + } + } + catch(...){ + intReturn = -1; + } + return intReturn; + + +} + +/* +* Get number of device arguments +*/ +int TelldusSettings::getNumberOfArguments(int intDeviceId){ + int intReturn = -1; + + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); + + if(lnExists == ERROR_SUCCESS){ + DWORD dNumValues; + RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL); + intReturn = (int)dNumValues - 3; //total number of values - model, name and vendor + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + } + catch(...){ + //error management + } + + return intReturn; +} + +/* +* Get device arguments +*/ +int* TelldusSettings::getArguments(int intDeviceId){ + vector vReturn; + int* intReturn = new int[]; + + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); + + if(lnExists == ERROR_SUCCESS){ + DWORD dNumValues; + RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL); + + int intNumberOfArguments = (int)dNumValues - 3; //total number of values - model, name and vendor + DWORD dwLength; + char chConvertBuffer[20]; + int i = 0; + + while(i < intNumberOfArguments){ + + char* Buff = new char[intMaxRegValueLength]; + + _itoa(i, chConvertBuffer, 10); + long lngStatus = RegQueryValueEx(hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength); + if(lngStatus == ERROR_MORE_DATA){ + lngStatus = RegQueryValueEx(hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength); + } + int intReturn = (int)_atoi64(Buff); + vReturn.push_back(intReturn); + + i++; + delete Buff; + } + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + + intReturn = new int[vReturn.size()]; + + int i = 0; + while(i < (int)vReturn.size()){ + intReturn[i] = vReturn.at(i); + i++; + } + } + catch(...){ + //error management + } + + return intReturn; +} + +/* +* Set device arguments +*/ +bool TelldusSettings::setArguments(int intDeviceId, int* intArguments[], int intNumberOfArguments){ + + bool blnSuccess = true; + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + char chConvertBuffer [20]; + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); + + if(lnExists == ERROR_SUCCESS){ + int i = 0; + while(i < intNumberOfArguments){ + _itoa(i, chConvertBuffer, 10); + RegSetValueEx(hk, chConvertBuffer, 0, REG_SZ, (LPBYTE)intArguments[i], intMaxRegValueLength); + i++; + } + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + + } + catch(...){ + blnSuccess = false; + } + return blnSuccess; +} + +/* +* Set device arguments +*/ +bool TelldusSettings::setArguments(int intDeviceId, vector vArguments){ + + bool blnSuccess = true; + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + char chConvertBuffer [20]; + char chConvertBufferValue [20]; + long lnExists = RegOpenKeyEx(HKEY_CURRENT_USER, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); + + if(lnExists == ERROR_SUCCESS){ + int i = 0; + while(i < vArguments.size()){ + _itoa(i, chConvertBuffer, 10); + _itoa(vArguments.at(i), chConvertBufferValue, 10); + intMaxRegValueLength = (int)strlen(chConvertBufferValue); + RegSetValueEx(hk, chConvertBuffer, 0, REG_SZ, (LPBYTE)chConvertBufferValue, intMaxRegValueLength); + i++; + } + } + else{ + throw exception(); //couldn't open reg key + } + RegCloseKey(hk); + + } + catch(...){ + blnSuccess = false; + } + return blnSuccess; +} + + +/* +* Add a new device +*/ +int TelldusSettings::addDevice(){ + + int intDeviceId = -1; + try{ + + DWORD dwDisp; + intDeviceId = getNextDeviceId(); + + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + + if(RegCreateKeyEx(HKEY_CURRENT_USER, + strCompleteRegPath.c_str(), + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hk, + &dwDisp)){ + //fail + throw exception("Create Key failed"); + } + + RegCloseKey(hk); + + } + catch(...){ + intDeviceId = -1; + } + return intDeviceId; +} + +/* +* Get next available device id +*/ +int TelldusSettings::getNextDeviceId(){ + + int intReturn = -1; + try{ + DWORD dwDisp; + long lnExists = RegCreateKeyEx(HKEY_CURRENT_USER, strRegPathDevice.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &hk, + &dwDisp); //create or open if already created + + if(lnExists == ERROR_SUCCESS){ + + DWORD dwLength; + char* Buff = new char[intMaxRegValueLength]; + + long lngStatus = RegQueryValueEx(hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength); + + if(lngStatus == ERROR_MORE_DATA){ + + + Buff = new char[dwLength]; + lngStatus = RegQueryValueEx(hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength); + } + + if(lngStatus == ERROR_SUCCESS){ + + int intLast = (int)Buff[0]; + intReturn = intLast + 1; + } + else{ + intReturn = 1; + } + delete Buff; + + DWORD dwVal = intReturn; + + RegSetValueEx (hk, "LastUsedId", 0L, REG_DWORD, (CONST BYTE*) &dwVal, sizeof(DWORD)); + + } + RegCloseKey(hk); + } + catch(...){ + intReturn = -1; + } + return intReturn; +} + +/* +* Remove a device +*/ +bool TelldusSettings::removeDevice(int intDeviceId){ + + bool blnSuccess = true; + try{ + std::ostringstream ssRegPath; + ssRegPath << strRegPathDevice << intDeviceId; + string strCompleteRegPath = ssRegPath.str(); + + long lngSuccess = RegDeleteKey(HKEY_CURRENT_USER, strCompleteRegPath.c_str()); + if(lngSuccess != ERROR_SUCCESS){ + blnSuccess = false; + } + } + catch(...){ + blnSuccess = false; + } + + return blnSuccess; +} + +//only for debug reasons +void TelldusSettings::debugLog(char* debugstring){ + ofstream debugfile("c:\\telldusdebug.txt", ios::app); + if(debugfile){ + debugfile << debugstring << endl; + debugfile.close(); + } +} + +//only for debug reasons +void TelldusSettings::debugLog(int debugint){ + ofstream debugfile("c:\\telldusdebug.txt", ios::app); + if(debugfile){ + debugfile << debugint << endl; + debugfile.close(); + } +} \ No newline at end of file diff --git a/driver/TellUsbD101/TelldusSettings.h b/driver/TellUsbD101/TelldusSettings.h new file mode 100644 index 00000000..65de9cc2 --- /dev/null +++ b/driver/TellUsbD101/TelldusSettings.h @@ -0,0 +1,42 @@ +#pragma once +#include "device.h" +#include "devicenexa.h" +#include +#include + +using namespace std; + +class TelldusSettings +{ +public: + TelldusSettings(void); + int getNumberOfDevices(void); + Device* getDevice(int intDeviceId); + Device* getDevice(int intDeviceId, int intDongleIndex); + char* getName(int intDeviceId); + bool setName(int intDeviceId, char* strNewName); + char* getVendor(int intDeviceId); + bool setVendor(int intDeviceId, char* strVendor); + char* getModel(int intDeviceId); + bool setModel(int intDeviceId, char* strModel); + int* getArguments(int intDeviceId); + bool setArguments(int intDeviceId, int* intArguments[], int intNumberOfArguments); + bool setArguments(int intDeviceId, vector vArguments); + int addDevice(); + int getDeviceId(int intDeviceIndex); + bool removeDevice(int intDeviceId); + void debugLog(char* debugstring); + void debugLog(int debugint); + int getNumberOfArguments(int intDeviceId); + + ~TelldusSettings(void); + +private: + int getNextDeviceId(); + + //variables + HKEY hk; + std::string strRegPathDevice; + std::string strRegPath; + int intMaxRegValueLength; +}; diff --git a/driver/TellUsbD101/linux/Device.cpp b/driver/TellUsbD101/linux/Device.cpp new file mode 100644 index 00000000..7aeff050 --- /dev/null +++ b/driver/TellUsbD101/linux/Device.cpp @@ -0,0 +1,85 @@ +#include "../Device.h" +#include +#include +#include + +/* +* Send message to the USB dongle +*/ +void Device::send(char* strMessage) { + int fd = -1; + struct termios tio; + + debugLog(strMessage); + + if( 0 > ( fd = open( "/dev/tellstick", O_RDWR ) ) ) { + return; + } + + /* adjust serial port parameters */ + bzero(&tio, sizeof(tio)); /* clear struct for new port settings */ + tio.c_cflag = B4800 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */ + tio.c_iflag = IGNPAR; + tio.c_oflag = 0; + tcflush(fd, TCIFLUSH); + tcsetattr(fd,TCSANOW,&tio); + + write(fd, strMessage, strlen(strMessage)); + + close(fd); +} + +/* +* Get the device index of the Telldus dongle (the first one if many are connected) +* -1 if no such device exists +*/ +int Device::getDongleIndex(){ + int intReturn = -1; +/* FT_HANDLE fthHandle = 0; + FT_STATUS ftStatus = FT_OK; + + try{ + DWORD dwNumberOfDevices = 0; + + 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 == 6017 && pData.ProductId == 3120){ + intReturn = i; + ftStatus = FT_Close(fthHandle); + break; + } + } + ftStatus = FT_Close(fthHandle); + } + } + } + catch(...){ + throw; + }*/ + return intReturn; +} + +//only for debugging purpose +void Device::debugLog(char* debugstring){ + std::cout << debugstring << std::endl; +} + diff --git a/driver/TellUsbD101/stdafx.cpp b/driver/TellUsbD101/stdafx.cpp new file mode 100644 index 00000000..54385d7a --- /dev/null +++ b/driver/TellUsbD101/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// testruntelldus3.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/driver/TellUsbD101/stdafx.h b/driver/TellUsbD101/stdafx.h new file mode 100644 index 00000000..5df7bbe1 --- /dev/null +++ b/driver/TellUsbD101/stdafx.h @@ -0,0 +1,37 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Allow use of features specific to Windows XP or later. +#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. +#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later. +#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE. +#endif + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include + +// C RunTime Header Files +#include +#include +#include +#include + + +// TODO: reference additional headers your program requires here diff --git a/driver/TellUsbD101/win/Device.cpp b/driver/TellUsbD101/win/Device.cpp new file mode 100644 index 00000000..ce5a065c --- /dev/null +++ b/driver/TellUsbD101/win/Device.cpp @@ -0,0 +1,91 @@ +#include "..\Device.h" +#include +#include +#include +#include +#include +#include "..\StdAfx.h" +#include "FTD2XX.H" + +/* +* Send message to the USB dongle +*/ +void Device::send(char* strMessage){ + + try{ + FT_STATUS ftStatus = FT_OK; + FT_HANDLE fthHandle = 0; + + ftStatus = FT_Open(this->intDongleIndex, &fthHandle); + int intBaudRate = 4800; //always 4800 + ftStatus = FT_SetBaudRate(fthHandle, intBaudRate); + ULONG bytesWritten; + + int intLen = (int)strlen(strMessage); + ftStatus = FT_Write(fthHandle, strMessage, intLen, &bytesWritten); + + ftStatus = FT_Close(fthHandle); + } + catch(...){ + throw; + } +} + +/* +* Get the device index of the Telldus dongle (the first one if many are connected) +* -1 if no such device exists +*/ +int Device::getDongleIndex(){ + int intReturn = -1; + FT_HANDLE fthHandle = 0; + FT_STATUS ftStatus = FT_OK; + + try{ + DWORD dwNumberOfDevices = 0; + + 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 == 6017 && pData.ProductId == 3120){ + intReturn = i; + ftStatus = FT_Close(fthHandle); + break; + } + } + ftStatus = FT_Close(fthHandle); + } + } + } + catch(...){ + throw; + } + return intReturn; +} + +//only for debugging purpose +void Device::debugLog(char* debugstring){ + std::ofstream debugfile("c:\\telldusdebug.txt", std::ios::app); + if(debugfile){ + debugfile << debugstring << std::endl; + debugfile.close(); + } +} + diff --git a/driver/TellUsbD101/win/FTD2XX.H b/driver/TellUsbD101/win/FTD2XX.H new file mode 100644 index 00000000..2507326c --- /dev/null +++ b/driver/TellUsbD101/win/FTD2XX.H @@ -0,0 +1,875 @@ +/*++ + +Copyright (c) 2001-2005 Future Technology Devices International Ltd. + +Module Name: + + ftd2xx.h + +Abstract: + + Native USB device driver for FTDI FT8U232/245 + FTD2XX library definitions + +Environment: + + kernel & user mode + +Revision History: + + 13/03/01 awm Created. + 13/01/03 awm Added device information support. + 19/03/03 awm Added FT_W32_CancelIo. + 12/06/03 awm Added FT_StopInTask and FT_RestartInTask. + 18/09/03 awm Added FT_SetResetPipeRetryCount. + 10/10/03 awm Added FT_ResetPort. + 23/01/04 awm Added support for open-by-location. + 16/03/04 awm Added support for FT2232C. + 23/09/04 awm Added support for FT232R. + 20/10/04 awm Added FT_CyclePort. + 18/01/05 awm Added FT_DEVICE_LIST_INFO_NODE type. + 11/02/05 awm Added LocId to FT_DEVICE_LIST_INFO_NODE. + 25/08/05 awm Added FT_SetDeadmanTimeout. + 02/12/05 awm Removed obsolete references. + 05/12/05 awm Added FT_GetVersion, FT_GetVersionEx. + + +--*/ + + +#ifndef FTD2XX_H +#define FTD2XX_H + +// The following ifdef block is the standard way of creating macros +// which make exporting from a DLL simpler. All files within this DLL +// are compiled with the FTD2XX_EXPORTS symbol defined on the command line. +// This symbol should not be defined on any project that uses this DLL. +// This way any other project whose source files include this file see +// FTD2XX_API functions as being imported from a DLL, whereas this DLL +// sees symbols defined with this macro as being exported. + +#ifdef FTD2XX_EXPORTS +#define FTD2XX_API __declspec(dllexport) +#else +#define FTD2XX_API __declspec(dllimport) +#endif + + +typedef PVOID FT_HANDLE; +typedef ULONG FT_STATUS; + +// +// Device status +// +enum { + FT_OK, + FT_INVALID_HANDLE, + FT_DEVICE_NOT_FOUND, + FT_DEVICE_NOT_OPENED, + FT_IO_ERROR, + FT_INSUFFICIENT_RESOURCES, + FT_INVALID_PARAMETER, + FT_INVALID_BAUD_RATE, + + FT_DEVICE_NOT_OPENED_FOR_ERASE, + FT_DEVICE_NOT_OPENED_FOR_WRITE, + FT_FAILED_TO_WRITE_DEVICE, + FT_EEPROM_READ_FAILED, + FT_EEPROM_WRITE_FAILED, + FT_EEPROM_ERASE_FAILED, + FT_EEPROM_NOT_PRESENT, + FT_EEPROM_NOT_PROGRAMMED, + FT_INVALID_ARGS, + FT_NOT_SUPPORTED, + FT_OTHER_ERROR +}; + + +#define FT_SUCCESS(status) ((status) == FT_OK) + +// +// FT_OpenEx Flags +// + +#define FT_OPEN_BY_SERIAL_NUMBER 1 +#define FT_OPEN_BY_DESCRIPTION 2 +#define FT_OPEN_BY_LOCATION 4 + +// +// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags +// + +#define FT_LIST_NUMBER_ONLY 0x80000000 +#define FT_LIST_BY_INDEX 0x40000000 +#define FT_LIST_ALL 0x20000000 + +#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL) + +// +// Baud Rates +// + +#define FT_BAUD_300 300 +#define FT_BAUD_600 600 +#define FT_BAUD_1200 1200 +#define FT_BAUD_2400 2400 +#define FT_BAUD_4800 4800 +#define FT_BAUD_9600 9600 +#define FT_BAUD_14400 14400 +#define FT_BAUD_19200 19200 +#define FT_BAUD_38400 38400 +#define FT_BAUD_57600 57600 +#define FT_BAUD_115200 115200 +#define FT_BAUD_230400 230400 +#define FT_BAUD_460800 460800 +#define FT_BAUD_921600 921600 + +// +// Word Lengths +// + +#define FT_BITS_8 (UCHAR) 8 +#define FT_BITS_7 (UCHAR) 7 +#define FT_BITS_6 (UCHAR) 6 +#define FT_BITS_5 (UCHAR) 5 + +// +// Stop Bits +// + +#define FT_STOP_BITS_1 (UCHAR) 0 +#define FT_STOP_BITS_1_5 (UCHAR) 1 +#define FT_STOP_BITS_2 (UCHAR) 2 + +// +// Parity +// + +#define FT_PARITY_NONE (UCHAR) 0 +#define FT_PARITY_ODD (UCHAR) 1 +#define FT_PARITY_EVEN (UCHAR) 2 +#define FT_PARITY_MARK (UCHAR) 3 +#define FT_PARITY_SPACE (UCHAR) 4 + +// +// Flow Control +// + +#define FT_FLOW_NONE 0x0000 +#define FT_FLOW_RTS_CTS 0x0100 +#define FT_FLOW_DTR_DSR 0x0200 +#define FT_FLOW_XON_XOFF 0x0400 + +// +// Purge rx and tx buffers +// +#define FT_PURGE_RX 1 +#define FT_PURGE_TX 2 + +// +// Events +// + +typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD); + +#define FT_EVENT_RXCHAR 1 +#define FT_EVENT_MODEM_STATUS 2 + +// +// Timeouts +// + +#define FT_DEFAULT_RX_TIMEOUT 300 +#define FT_DEFAULT_TX_TIMEOUT 300 + +// +// Device types +// + +typedef ULONG FT_DEVICE; + +enum { + FT_DEVICE_BM, + FT_DEVICE_AM, + FT_DEVICE_100AX, + FT_DEVICE_UNKNOWN, + FT_DEVICE_2232C, + FT_DEVICE_232R +}; + + +#ifdef __cplusplus +extern "C" { +#endif + + +FTD2XX_API +FT_STATUS WINAPI FT_Open( + int deviceNumber, + FT_HANDLE *pHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_OpenEx( + PVOID pArg1, + DWORD Flags, + FT_HANDLE *pHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_ListDevices( + PVOID pArg1, + PVOID pArg2, + DWORD Flags + ); + +FTD2XX_API +FT_STATUS WINAPI FT_Close( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_Read( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesReturned + ); + +FTD2XX_API +FT_STATUS WINAPI FT_Write( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesWritten + ); + +FTD2XX_API +FT_STATUS WINAPI FT_IoCtl( + FT_HANDLE ftHandle, + DWORD dwIoControlCode, + LPVOID lpInBuf, + DWORD nInBufSize, + LPVOID lpOutBuf, + DWORD nOutBufSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetBaudRate( + FT_HANDLE ftHandle, + ULONG BaudRate + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetDivisor( + FT_HANDLE ftHandle, + USHORT Divisor + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetDataCharacteristics( + FT_HANDLE ftHandle, + UCHAR WordLength, + UCHAR StopBits, + UCHAR Parity + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetFlowControl( + FT_HANDLE ftHandle, + USHORT FlowControl, + UCHAR XonChar, + UCHAR XoffChar + ); + +FTD2XX_API +FT_STATUS WINAPI FT_ResetDevice( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetDtr( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_ClrDtr( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetRts( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_ClrRts( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetModemStatus( + FT_HANDLE ftHandle, + ULONG *pModemStatus + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetChars( + FT_HANDLE ftHandle, + UCHAR EventChar, + UCHAR EventCharEnabled, + UCHAR ErrorChar, + UCHAR ErrorCharEnabled + ); + +FTD2XX_API +FT_STATUS WINAPI FT_Purge( + FT_HANDLE ftHandle, + ULONG Mask + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetTimeouts( + FT_HANDLE ftHandle, + ULONG ReadTimeout, + ULONG WriteTimeout + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetQueueStatus( + FT_HANDLE ftHandle, + DWORD *dwRxBytes + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetEventNotification( + FT_HANDLE ftHandle, + DWORD Mask, + PVOID Param + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetStatus( + FT_HANDLE ftHandle, + DWORD *dwRxBytes, + DWORD *dwTxBytes, + DWORD *dwEventDWord + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetBreakOn( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetBreakOff( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetWaitMask( + FT_HANDLE ftHandle, + DWORD Mask + ); + +FTD2XX_API +FT_STATUS WINAPI FT_WaitOnMask( + FT_HANDLE ftHandle, + DWORD *Mask + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetEventStatus( + FT_HANDLE ftHandle, + DWORD *dwEventDWord + ); + +FTD2XX_API +FT_STATUS WINAPI FT_ReadEE( + FT_HANDLE ftHandle, + DWORD dwWordOffset, + LPWORD lpwValue + ); + +FTD2XX_API +FT_STATUS WINAPI FT_WriteEE( + FT_HANDLE ftHandle, + DWORD dwWordOffset, + WORD wValue + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EraseEE( + FT_HANDLE ftHandle + ); + +// +// structure to hold program data for FT_Program function +// +typedef struct ft_program_data { + + DWORD Signature1; // Header - must be 0x00000000 + DWORD Signature2; // Header - must be 0xffffffff + DWORD Version; // Header - FT_PROGRAM_DATA version + // 0 = original + // 1 = FT2232C extensions + // 2 = FT232R extensions + + WORD VendorId; // 0x0403 + WORD ProductId; // 0x6001 + char *Manufacturer; // "FTDI" + char *ManufacturerId; // "FT" + char *Description; // "USB HS Serial Converter" + char *SerialNumber; // "FT000001" if fixed, or NULL + WORD MaxPower; // 0 < MaxPower <= 500 + WORD PnP; // 0 = disabled, 1 = enabled + WORD SelfPowered; // 0 = bus powered, 1 = self powered + WORD RemoteWakeup; // 0 = not capable, 1 = capable + // + // Rev4 extensions + // + UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise + UCHAR IsoIn; // non-zero if in endpoint is isochronous + UCHAR IsoOut; // non-zero if out endpoint is isochronous + UCHAR PullDownEnable; // non-zero if pull down enabled + UCHAR SerNumEnable; // non-zero if serial number to be used + UCHAR USBVersionEnable; // non-zero if chip uses USBVersion + WORD USBVersion; // BCD (0x0200 => USB2) + // + // FT2232C extensions + // + UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise + UCHAR IsoInA; // non-zero if in endpoint is isochronous + UCHAR IsoInB; // non-zero if in endpoint is isochronous + UCHAR IsoOutA; // non-zero if out endpoint is isochronous + UCHAR IsoOutB; // non-zero if out endpoint is isochronous + UCHAR PullDownEnable5; // non-zero if pull down enabled + UCHAR SerNumEnable5; // non-zero if serial number to be used + UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion + WORD USBVersion5; // BCD (0x0200 => USB2) + UCHAR AIsHighCurrent; // non-zero if interface is high current + UCHAR BIsHighCurrent; // non-zero if interface is high current + UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO + UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IFAIsFastSer; // non-zero if interface is Fast serial + UCHAR AIsVCP; // non-zero if interface is to use VCP drivers + UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO + UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IFBIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsVCP; // non-zero if interface is to use VCP drivers + // + // FT232R extensions + // + UCHAR UseExtOsc; // Use External Oscillator + UCHAR HighDriveIOs; // High Drive I/Os + UCHAR EndpointSize; // Endpoint size + + UCHAR PullDownEnableR; // non-zero if pull down enabled + UCHAR SerNumEnableR; // non-zero if serial number to be used + + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + + UCHAR RIsVCP; // non-zero if using VCP drivers + +} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA; + +FTD2XX_API +FT_STATUS WINAPI FT_EE_Program( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EE_ProgramEx( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EE_Read( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EE_ReadEx( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EE_UASize( + FT_HANDLE ftHandle, + LPDWORD lpdwSize + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EE_UAWrite( + FT_HANDLE ftHandle, + PUCHAR pucData, + DWORD dwDataLen + ); + +FTD2XX_API +FT_STATUS WINAPI FT_EE_UARead( + FT_HANDLE ftHandle, + PUCHAR pucData, + DWORD dwDataLen, + LPDWORD lpdwBytesRead + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetLatencyTimer( + FT_HANDLE ftHandle, + UCHAR ucLatency + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetLatencyTimer( + FT_HANDLE ftHandle, + PUCHAR pucLatency + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetBitMode( + FT_HANDLE ftHandle, + UCHAR ucMask, + UCHAR ucEnable + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetBitMode( + FT_HANDLE ftHandle, + PUCHAR pucMode + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetUSBParameters( + FT_HANDLE ftHandle, + ULONG ulInTransferSize, + ULONG ulOutTransferSize + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetDeadmanTimeout( + FT_HANDLE ftHandle, + ULONG ulDeadmanTimeout + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetDeviceInfo( + FT_HANDLE ftHandle, + FT_DEVICE *lpftDevice, + LPDWORD lpdwID, + PCHAR SerialNumber, + PCHAR Description, + LPVOID Dummy + ); + +FTD2XX_API +FT_STATUS WINAPI FT_StopInTask( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_RestartInTask( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_SetResetPipeRetryCount( + FT_HANDLE ftHandle, + DWORD dwCount + ); + +FTD2XX_API +FT_STATUS WINAPI FT_ResetPort( + FT_HANDLE ftHandle + ); + +FTD2XX_API +FT_STATUS WINAPI FT_CyclePort( + FT_HANDLE ftHandle + ); + + +// +// Win32-type functions +// + +FTD2XX_API +FT_HANDLE WINAPI FT_W32_CreateFile( + LPCSTR lpszName, + DWORD dwAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreate, + DWORD dwAttrsAndFlags, + HANDLE hTemplate + ); + +FTD2XX_API +BOOL WINAPI FT_W32_CloseHandle( + FT_HANDLE ftHandle + ); + +FTD2XX_API +BOOL WINAPI FT_W32_ReadFile( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + +FTD2XX_API +BOOL WINAPI FT_W32_WriteFile( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesWritten, + LPOVERLAPPED lpOverlapped + ); + +FTD2XX_API +DWORD WINAPI FT_W32_GetLastError( + FT_HANDLE ftHandle + ); + +FTD2XX_API +BOOL WINAPI FT_W32_GetOverlappedResult( + FT_HANDLE ftHandle, + LPOVERLAPPED lpOverlapped, + LPDWORD lpdwBytesTransferred, + BOOL bWait + ); + +FTD2XX_API +BOOL WINAPI FT_W32_CancelIo( + FT_HANDLE ftHandle + ); + + +// +// Win32 COMM API type functions +// +typedef struct _FTCOMSTAT { + DWORD fCtsHold : 1; + DWORD fDsrHold : 1; + DWORD fRlsdHold : 1; + DWORD fXoffHold : 1; + DWORD fXoffSent : 1; + DWORD fEof : 1; + DWORD fTxim : 1; + DWORD fReserved : 25; + DWORD cbInQue; + DWORD cbOutQue; +} FTCOMSTAT, *LPFTCOMSTAT; + +typedef struct _FTDCB { + DWORD DCBlength; /* sizeof(FTDCB) */ + DWORD BaudRate; /* Baudrate at which running */ + DWORD fBinary: 1; /* Binary Mode (skip EOF check) */ + DWORD fParity: 1; /* Enable parity checking */ + DWORD fOutxCtsFlow:1; /* CTS handshaking on output */ + DWORD fOutxDsrFlow:1; /* DSR handshaking on output */ + DWORD fDtrControl:2; /* DTR Flow control */ + DWORD fDsrSensitivity:1; /* DSR Sensitivity */ + DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ + DWORD fOutX: 1; /* Enable output X-ON/X-OFF */ + DWORD fInX: 1; /* Enable input X-ON/X-OFF */ + DWORD fErrorChar: 1; /* Enable Err Replacement */ + DWORD fNull: 1; /* Enable Null stripping */ + DWORD fRtsControl:2; /* Rts Flow control */ + DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ + DWORD fDummy2:17; /* Reserved */ + WORD wReserved; /* Not currently used */ + WORD XonLim; /* Transmit X-ON threshold */ + WORD XoffLim; /* Transmit X-OFF threshold */ + BYTE ByteSize; /* Number of bits/byte, 4-8 */ + BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */ + BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */ + char XonChar; /* Tx and Rx X-ON character */ + char XoffChar; /* Tx and Rx X-OFF character */ + char ErrorChar; /* Error replacement char */ + char EofChar; /* End of Input character */ + char EvtChar; /* Received Event character */ + WORD wReserved1; /* Fill for now. */ +} FTDCB, *LPFTDCB; + +typedef struct _FTTIMEOUTS { + DWORD ReadIntervalTimeout; /* Maximum time between read chars. */ + DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */ + DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */ + DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */ + DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */ +} FTTIMEOUTS,*LPFTTIMEOUTS; + + +FTD2XX_API +BOOL WINAPI FT_W32_ClearCommBreak( + FT_HANDLE ftHandle + ); + +FTD2XX_API +BOOL WINAPI FT_W32_ClearCommError( + FT_HANDLE ftHandle, + LPDWORD lpdwErrors, + LPFTCOMSTAT lpftComstat + ); + +FTD2XX_API +BOOL WINAPI FT_W32_EscapeCommFunction( + FT_HANDLE ftHandle, + DWORD dwFunc + ); + +FTD2XX_API +BOOL WINAPI FT_W32_GetCommModemStatus( + FT_HANDLE ftHandle, + LPDWORD lpdwModemStatus + ); + +FTD2XX_API +BOOL WINAPI FT_W32_GetCommState( + FT_HANDLE ftHandle, + LPFTDCB lpftDcb + ); + +FTD2XX_API +BOOL WINAPI FT_W32_GetCommTimeouts( + FT_HANDLE ftHandle, + FTTIMEOUTS *pTimeouts + ); + +FTD2XX_API +BOOL WINAPI FT_W32_PurgeComm( + FT_HANDLE ftHandle, + DWORD dwMask + ); + +FTD2XX_API +BOOL WINAPI FT_W32_SetCommBreak( + FT_HANDLE ftHandle + ); + +FTD2XX_API +BOOL WINAPI FT_W32_SetCommMask( + FT_HANDLE ftHandle, + ULONG ulEventMask + ); + +FTD2XX_API +BOOL WINAPI FT_W32_SetCommState( + FT_HANDLE ftHandle, + LPFTDCB lpftDcb + ); + +FTD2XX_API +BOOL WINAPI FT_W32_SetCommTimeouts( + FT_HANDLE ftHandle, + FTTIMEOUTS *pTimeouts + ); + +FTD2XX_API +BOOL WINAPI FT_W32_SetupComm( + FT_HANDLE ftHandle, + DWORD dwReadBufferSize, + DWORD dwWriteBufferSize + ); + +FTD2XX_API +BOOL WINAPI FT_W32_WaitCommEvent( + FT_HANDLE ftHandle, + PULONG pulEvent, + LPOVERLAPPED lpOverlapped + ); + + +// +// Device information +// + +typedef struct _ft_device_list_info_node { + ULONG Flags; + ULONG Type; + ULONG ID; + DWORD LocId; + char SerialNumber[16]; + char Description[64]; + FT_HANDLE ftHandle; +} FT_DEVICE_LIST_INFO_NODE; + + +FTD2XX_API +FT_STATUS WINAPI FT_CreateDeviceInfoList( + LPDWORD lpdwNumDevs + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetDeviceInfoList( + FT_DEVICE_LIST_INFO_NODE *pDest, + LPDWORD lpdwNumDevs + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetDeviceInfoDetail( + DWORD dwIndex, + LPDWORD lpdwFlags, + LPDWORD lpdwType, + LPDWORD lpdwID, + LPDWORD lpdwLocId, + LPVOID lpSerialNumber, + LPVOID lpDescription, + FT_HANDLE *pftHandle + ); + + +// +// Version information +// + +FTD2XX_API +FT_STATUS WINAPI FT_GetDriverVersion( + FT_HANDLE ftHandle, + LPDWORD lpdwVersion + ); + +FTD2XX_API +FT_STATUS WINAPI FT_GetLibraryVersion( + LPDWORD lpdwVersion + ); + + + + +#ifdef __cplusplus +} +#endif + + +#endif /* FTD2XX_H */ +