Moved driver and tdtool to telldus-core
This commit is contained in:
commit
8595ad0e6f
30 changed files with 3435 additions and 0 deletions
7
CMakeLists.txt
Normal file
7
CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
PROJECT( telldus-core )
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.4.0 )
|
||||
|
||||
ADD_SUBDIRECTORY(driver)
|
||||
ADD_SUBDIRECTORY(tdtool)
|
||||
|
6
driver/CMakeLists.txt
Normal file
6
driver/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
PROJECT( tellstick )
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.4.0 )
|
||||
|
||||
ADD_SUBDIRECTORY(TellUsbD101)
|
||||
|
20
driver/TellUsbD101.sln
Normal file
20
driver/TellUsbD101.sln
Normal file
|
@ -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
|
45
driver/TellUsbD101/CMakeLists.txt
Normal file
45
driver/TellUsbD101/CMakeLists.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
SET( tellusbd101_SRCS
|
||||
Device.cpp
|
||||
linux/Device.cpp
|
||||
DeviceIkea.cpp
|
||||
DeviceNexa.cpp
|
||||
DeviceSartano.cpp
|
||||
DeviceWaveman.cpp
|
||||
settings/TelldusSettings.cpp
|
||||
settings/TelldusSettingsConfuse.cpp
|
||||
TellUsbD101.cpp
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(
|
||||
-DOS_LINUX
|
||||
)
|
||||
|
||||
ADD_LIBRARY(tellusbd101 SHARED
|
||||
${tellusbd101_SRCS}
|
||||
${tellusbd101_MOC_SRCS}
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(tellusbd101
|
||||
confuse
|
||||
)
|
||||
|
||||
INSTALL(TARGETS tellusbd101 LIBRARY
|
||||
DESTINATION lib
|
||||
)
|
||||
|
||||
INSTALL(FILES
|
||||
TellUsbD101.h
|
||||
DESTINATION include
|
||||
)
|
||||
|
||||
SET(SYSCONF_INSTALL_DIR
|
||||
"/etc"
|
||||
CACHE PATH "The ${APPLICATION_NAME} sysconfig install dir (default prefix/etc)"
|
||||
FORCE
|
||||
)
|
||||
|
||||
INSTALL(FILES
|
||||
tellstick.conf
|
||||
DESTINATION ${SYSCONF_INSTALL_DIR}
|
||||
)
|
50
driver/TellUsbD101/Device.cpp
Normal file
50
driver/TellUsbD101/Device.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "Device.h"
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
Device::Device()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
Device::~Device(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
/*
|
||||
* Methods, virtual
|
||||
*/
|
||||
int Device::methods(char* strModel){
|
||||
return 0;
|
||||
}
|
25
driver/TellUsbD101/Device.h
Normal file
25
driver/TellUsbD101/Device.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "TellUsbD101.h"
|
||||
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
Device();
|
||||
~Device(void);
|
||||
|
||||
virtual void turnOn(void);
|
||||
virtual void turnOff(void);
|
||||
virtual void bell(void);
|
||||
virtual void dim(unsigned char level);
|
||||
virtual int methods(char* strModel);
|
||||
|
||||
#ifndef _WINDOWS
|
||||
void setDevice(const char *device);
|
||||
protected:
|
||||
char *strDevice;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void send(char* strMessage);
|
||||
};
|
196
driver/TellUsbD101/DeviceIkea.cpp
Normal file
196
driver/TellUsbD101/DeviceIkea.cpp
Normal file
|
@ -0,0 +1,196 @@
|
|||
// #include "StdAfx.h" //Needed?
|
||||
#include "DeviceIkea.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceIkea::DeviceIkea(char *strSystem, char *strUnits, char *strFadeStyle)
|
||||
:Device()
|
||||
{
|
||||
if (strSystem != NULL && strlen(strSystem) > 0) {
|
||||
intSystem = atoi(strSystem) - 1;
|
||||
} else {
|
||||
intSystem = 0;
|
||||
}
|
||||
if (strUnits != NULL && strlen(strUnits) > 0) {
|
||||
intUnits = 0; //Start without any units
|
||||
|
||||
char *strTemp = strtok(strUnits, ",");
|
||||
do {
|
||||
int intUnit = atoi(strTemp);
|
||||
if (intUnit == 10) {
|
||||
intUnit = 0;
|
||||
}
|
||||
intUnits = intUnits | ( 1<<(9-intUnit) );
|
||||
} while ( (strTemp = strtok(NULL, ",")) != NULL );
|
||||
}
|
||||
if (strUnits != NULL && strlen(strUnits) > 0 && strcasecmp(strFadeStyle, "true") == 0) {
|
||||
intFadeStyle = 1;
|
||||
} else {
|
||||
intFadeStyle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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<char*>(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<char*>(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<char*>(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 (i % 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
|
||||
|
||||
int intLevel = 0;
|
||||
if (level <= 12) {
|
||||
intLevel = 10; // Level 10 is actually off
|
||||
} else if (level <= 37) {
|
||||
intLevel = 1;
|
||||
} else if (level <= 62) {
|
||||
intLevel = 2;
|
||||
} else if (level <= 87) {
|
||||
intLevel = 3;
|
||||
} else if (level <= 112) {
|
||||
intLevel = 4;
|
||||
} else if (level <= 137) {
|
||||
intLevel = 5;
|
||||
} else if (level <= 162) {
|
||||
intLevel = 6;
|
||||
} else if (level <= 187) {
|
||||
intLevel = 7;
|
||||
} else if (level <= 212) {
|
||||
intLevel = 8;
|
||||
} else if (level <= 237) {
|
||||
intLevel = 9;
|
||||
} else {
|
||||
intLevel = 0; // Level 0 is actually full on
|
||||
}
|
||||
|
||||
int intFade = 0;
|
||||
if (intFadeStyle == 1) {
|
||||
intFade = 11 << 4; //Smooth
|
||||
} else {
|
||||
intFade = 1 << 4; //Instant
|
||||
}
|
||||
|
||||
intCode = intLevel | intFade; //Concat level and fade
|
||||
|
||||
checksum1 = 0;
|
||||
checksum2 = 0;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
if ((intCode>>i) & 1) {
|
||||
strReturn.append("TT");
|
||||
if (i % 2 == 0)
|
||||
checksum1++;
|
||||
else
|
||||
checksum2++;
|
||||
} else {
|
||||
strReturn.append("ª");
|
||||
}
|
||||
}
|
||||
|
||||
strReturn.append(checksum1 %2 == 0 ? "TT" : "ª"); //1st checksum
|
||||
strReturn.append(checksum2 %2 == 0 ? "TT" : "ª"); //2nd checksum
|
||||
|
||||
strReturn.append("+");
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
return strReturn;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceIkea::methods(char* strModel){
|
||||
|
||||
if(strcmp(strModel, TELLSTICK_DEVICE_KOPPLA) == 0) {
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM);
|
||||
}
|
||||
return 0;
|
||||
}
|
23
driver/TellUsbD101/DeviceIkea.h
Normal file
23
driver/TellUsbD101/DeviceIkea.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
#include "Device.h"
|
||||
#include <string>
|
||||
|
||||
class DeviceIkea : public Device
|
||||
{
|
||||
public:
|
||||
DeviceIkea(char *strSystem, char *strUnits, char *strFadeStyle);
|
||||
virtual void turnOn(void);
|
||||
virtual void turnOff(void);
|
||||
virtual void dim(unsigned char level);
|
||||
virtual int methods(char* strModel);
|
||||
|
||||
public:
|
||||
~DeviceIkea(void);
|
||||
|
||||
protected:
|
||||
int intSystem;
|
||||
int intUnits;
|
||||
int intFadeStyle;
|
||||
std::string getStringCode(unsigned char);
|
||||
};
|
||||
|
178
driver/TellUsbD101/DeviceNexa.cpp
Normal file
178
driver/TellUsbD101/DeviceNexa.cpp
Normal file
|
@ -0,0 +1,178 @@
|
|||
// #include "StdAfx.h"
|
||||
#include "DeviceNexa.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceNexa::DeviceNexa(char *strNewHouse, char *strNewCode)
|
||||
:Device()
|
||||
{
|
||||
if (strNewHouse != NULL && strlen(strNewHouse) > 0) {
|
||||
intHouse = strNewHouse[0] - 'A';
|
||||
} else {
|
||||
intHouse = 0;
|
||||
}
|
||||
|
||||
if (strNewCode != NULL && strlen(strNewCode) > 0) {
|
||||
intCode = atoi(strNewCode) - 1;
|
||||
} else {
|
||||
intCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
DeviceNexa::~DeviceNexa(void)
|
||||
{
|
||||
// intHouse = -1;
|
||||
// intCode = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn on this device
|
||||
*/
|
||||
void DeviceNexa::turnOn(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intHouse);
|
||||
string strUnit = getStringCode(intCode);
|
||||
strCode.append(strUnit);
|
||||
|
||||
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<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off this device
|
||||
*/
|
||||
void DeviceNexa::turnOff(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intHouse);
|
||||
string strUnit = getStringCode(intCode);
|
||||
strCode.append(strUnit);
|
||||
|
||||
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<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a bell
|
||||
*/
|
||||
void DeviceNexa::bell(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intHouse);
|
||||
|
||||
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<char*>(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?
|
||||
*/
|
||||
int DeviceNexa::methods(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 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_LYCR1000) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_LYCR300) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_LCMR1000) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_LCMR300) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_EL2023) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_EL2024) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_EL2021) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_EL2017) == 0 ||
|
||||
strcmp(strModel, TELLSTICK_DEVICE_EL2019) == 0
|
||||
)
|
||||
{
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
} else if ( strcmp(strModel, TELLSTICK_DEVICE_ML7100) == 0 ) {
|
||||
return TELLSTICK_BELL;
|
||||
}
|
||||
return 0;
|
||||
}
|
22
driver/TellUsbD101/DeviceNexa.h
Normal file
22
driver/TellUsbD101/DeviceNexa.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
#include "Device.h"
|
||||
#include <string>
|
||||
|
||||
class DeviceNexa : public Device
|
||||
{
|
||||
public:
|
||||
DeviceNexa(char *strHouse, char *strCode);
|
||||
virtual void turnOn(void);
|
||||
virtual void turnOff(void);
|
||||
virtual void bell(void);
|
||||
virtual int methods(char* strModel);
|
||||
|
||||
public:
|
||||
~DeviceNexa(void);
|
||||
|
||||
protected:
|
||||
int intHouse;
|
||||
int intCode;
|
||||
std::string getStringCode(int);
|
||||
};
|
||||
|
98
driver/TellUsbD101/DeviceSartano.cpp
Normal file
98
driver/TellUsbD101/DeviceSartano.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
#include "DeviceSartano.h"
|
||||
#include "DeviceNexa.h"
|
||||
#include <string>
|
||||
#include <bitset>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceSartano::DeviceSartano(char *strNewCode)
|
||||
:Device()
|
||||
{
|
||||
strCode = strNewCode;
|
||||
}
|
||||
|
||||
|
||||
DeviceSartano::~DeviceSartano(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Turn on this device
|
||||
*/
|
||||
void DeviceSartano::turnOn(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode();
|
||||
|
||||
strCode.insert(0, "S");
|
||||
strCode.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<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off this device
|
||||
*/
|
||||
void DeviceSartano::turnOff(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode();
|
||||
|
||||
strCode.insert(0, "S");
|
||||
strCode.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<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceSartano::methods(char* strModel){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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(void){
|
||||
|
||||
string strReturn = strCode;
|
||||
|
||||
try{
|
||||
int intPos = (int)strReturn.find("0");
|
||||
while (intPos < string::npos){
|
||||
strReturn.replace(intPos, 1, "$kk$");
|
||||
intPos = (int)strReturn.find("0", intPos + 1);
|
||||
}
|
||||
|
||||
intPos = (int)strReturn.find("1");
|
||||
while (intPos < string::npos){
|
||||
strReturn.replace(intPos, 1, "$k$k");
|
||||
intPos = (int)strReturn.find("1", intPos + 1);
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
return strReturn;
|
||||
|
||||
}
|
||||
|
19
driver/TellUsbD101/DeviceSartano.h
Normal file
19
driver/TellUsbD101/DeviceSartano.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
#include "Device.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
class DeviceSartano : public Device
|
||||
{
|
||||
public:
|
||||
DeviceSartano(char *strCode);
|
||||
virtual void turnOn(void);
|
||||
virtual void turnOff(void);
|
||||
virtual int methods(char* strModel);
|
||||
|
||||
~DeviceSartano(void);
|
||||
|
||||
protected:
|
||||
std::string getStringCode(void);
|
||||
std::string strCode;
|
||||
};
|
45
driver/TellUsbD101/DeviceWaveman.cpp
Normal file
45
driver/TellUsbD101/DeviceWaveman.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
// #include "StdAfx.h"
|
||||
#include "DeviceWaveman.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceWaveman::DeviceWaveman(char *strNewHouse, char *strNewCode)
|
||||
:DeviceNexa(strNewHouse, strNewCode){
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off this device
|
||||
*/
|
||||
void DeviceWaveman::turnOff(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intHouse);
|
||||
string strUnit = getStringCode(intCode);
|
||||
strCode.append(strUnit);
|
||||
|
||||
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<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Has the device got the method?
|
||||
*/
|
||||
int DeviceWaveman::methods(char* strModel){
|
||||
return (TELLSTICK_TURNON | TELLSTICK_TURNOFF);
|
||||
}
|
11
driver/TellUsbD101/DeviceWaveman.h
Normal file
11
driver/TellUsbD101/DeviceWaveman.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include "DeviceNexa.h"
|
||||
#include <string>
|
||||
|
||||
class DeviceWaveman : public DeviceNexa
|
||||
{
|
||||
public:
|
||||
DeviceWaveman(char *strHouse, char *strCode);
|
||||
virtual void turnOff(void);
|
||||
virtual int methods(char* strModel);
|
||||
};
|
31
driver/TellUsbD101/Resource.h
Normal file
31
driver/TellUsbD101/Resource.h
Normal file
|
@ -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
|
318
driver/TellUsbD101/TellUsbD101.cpp
Normal file
318
driver/TellUsbD101/TellUsbD101.cpp
Normal file
|
@ -0,0 +1,318 @@
|
|||
//DLL entry point
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include "stdafx.h"
|
||||
#include <ole2.h>
|
||||
#endif
|
||||
#include "TellUsbD101.h"
|
||||
#include "settings/TelldusSettings.h"
|
||||
#include "Device.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void handleException(std::exception e);
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
|
||||
//TODO:
|
||||
//delete on created objects
|
||||
//comment (just copy from the called methods)
|
||||
|
||||
bool WINAPI 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 WINAPI 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 WINAPI 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 WINAPI 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 WINAPI devGetNumberOfDevices(void){
|
||||
int intReturn = -1;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
intReturn = ts.getNumberOfDevices();
|
||||
}
|
||||
catch(exception e){
|
||||
intReturn = -1;
|
||||
handleException(e);
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
int WINAPI 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 * WINAPI devGetName(int intDeviceId){
|
||||
char* strReturn;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getName(intDeviceId);
|
||||
#ifdef _WINDOWS
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
#endif
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool WINAPI devSetName(int intDeviceId, const char* strNewName){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.setName(intDeviceId, strNewName);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
char* WINAPI devGetVendor(int intDeviceId){
|
||||
char* strReturn = "";
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getVendor(intDeviceId);
|
||||
#ifdef _WINDOWS
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
#endif
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool WINAPI devSetVendor(int intDeviceId, const char* strVendor){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.setVendor(intDeviceId, strVendor);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
char* WINAPI devGetModel(int intDeviceId){
|
||||
char* strReturn = "";
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getModel(intDeviceId);
|
||||
#ifdef _WINDOWS
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
#endif
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool WINAPI devSetModel(int intDeviceId, const char* strNewModel){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.setModel(intDeviceId, strNewModel);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
bool WINAPI devSetArgument(int intDeviceId, const char *strName, const char *strValue){
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
return ts.setArgument(intDeviceId, strName, strValue);
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * WINAPI devGetArgument(int intDeviceId, const char *strName, const char *defaultValue){
|
||||
char *strReturn = "";
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getArgument(intDeviceId, strName);
|
||||
if (strReturn == NULL) {
|
||||
return defaultValue;
|
||||
}
|
||||
#ifdef _WINDOWS
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
#endif
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
int WINAPI devAddDevice(){
|
||||
int intNewDeviceId = -1;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
intNewDeviceId = ts.addDevice();
|
||||
}
|
||||
catch(exception e){
|
||||
intNewDeviceId = -1;
|
||||
handleException(e);
|
||||
}
|
||||
return intNewDeviceId;
|
||||
}
|
||||
|
||||
bool WINAPI devRemoveDevice(int intDeviceId){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.removeDevice(intDeviceId);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
int WINAPI devMethods(int id){
|
||||
|
||||
int intMethods = 0;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
char* strModel = ts.getModel(id);
|
||||
Device* dev = ts.getDevice(id);
|
||||
if (dev != NULL) {
|
||||
intMethods = dev->methods(strModel);
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
intMethods = 0;
|
||||
handleException(e);
|
||||
}
|
||||
return intMethods;
|
||||
}
|
||||
|
||||
|
||||
//********
|
||||
//* 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
driver/TellUsbD101/TellUsbD101.def
Normal file
23
driver/TellUsbD101/TellUsbD101.def
Normal file
|
@ -0,0 +1,23 @@
|
|||
LIBRARY TellUsbD101
|
||||
EXPORTS
|
||||
devGetNumberOfDevices @1
|
||||
devGetDeviceId @2
|
||||
|
||||
devGetName @3
|
||||
devGetVendor @4
|
||||
devGetModel @5
|
||||
devGetArgument @6
|
||||
|
||||
devSetName @7
|
||||
devSetVendor @8
|
||||
devSetModel @9
|
||||
devSetArgument @10
|
||||
|
||||
devAddDevice @11
|
||||
devRemoveDevice @12
|
||||
|
||||
devMethods @13
|
||||
devTurnOn @14
|
||||
devTurnOff @15
|
||||
devBell @16
|
||||
devDim @17
|
84
driver/TellUsbD101/TellUsbD101.h
Normal file
84
driver/TellUsbD101/TellUsbD101.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
#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 _WINDOWS
|
||||
#ifdef TellUsbD101_EXPORTS
|
||||
#define TELLSTICK_API __declspec(dllexport)
|
||||
#else
|
||||
#define TELLSTICK_API __declspec(dllimport)
|
||||
#endif
|
||||
#define WINAPI __stdcall
|
||||
#else
|
||||
#define WINAPI
|
||||
#define TELLSTICK_API
|
||||
#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 devMethods(int id);
|
||||
|
||||
TELLSTICK_API int WINAPI devGetNumberOfDevices();
|
||||
TELLSTICK_API int WINAPI devGetDeviceId(int intDeviceIndex);
|
||||
|
||||
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 const char * WINAPI devGetArgument(int intDeviceId, const char *strName, const char *defaultValue);
|
||||
TELLSTICK_API bool WINAPI devSetArgument(int intDeviceId, const char *strName, const char* strValue);
|
||||
|
||||
TELLSTICK_API int WINAPI devAddDevice();
|
||||
TELLSTICK_API bool WINAPI devRemoveDevice(int intDeviceId);
|
||||
}
|
||||
|
||||
#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"
|
||||
#define TELLSTICK_DEVICE_LYCR1000 "20"
|
||||
#define TELLSTICK_DEVICE_LYCR300 "21"
|
||||
#define TELLSTICK_DEVICE_LCMR1000 "22"
|
||||
#define TELLSTICK_DEVICE_LCMR300 "23"
|
||||
#define TELLSTICK_DEVICE_EL2023 "24"
|
||||
#define TELLSTICK_DEVICE_EL2024 "25"
|
||||
#define TELLSTICK_DEVICE_EL2021 "26"
|
||||
#define TELLSTICK_DEVICE_EL2017 "27"
|
||||
#define TELLSTICK_DEVICE_EL2019 "28"
|
||||
|
||||
//Protocol Ikea
|
||||
#define TELLSTICK_DEVICE_KOPPLA "19"
|
||||
|
||||
#endif
|
312
driver/TellUsbD101/TellUsbD101.vcproj
Normal file
312
driver/TellUsbD101/TellUsbD101.vcproj
Normal file
|
@ -0,0 +1,312 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="TellUsbD101"
|
||||
ProjectGUID="{2A868E40-88D9-4800-A83F-21D0F8DCB611}"
|
||||
RootNamespace="TellUsbD101"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TELLTEST3_EXPORTS"
|
||||
GeneratePreprocessedFile="0"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
ModuleDefinitionFile="$(SolutionDir)\tellTest3\tellTest3.def"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;TellUsbD101_EXPORTS"
|
||||
GeneratePreprocessedFile="0"
|
||||
RuntimeLibrary="0"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="advapi32.lib oleaut32.lib"
|
||||
LinkIncremental="1"
|
||||
ModuleDefinitionFile="TellUsbD101.def"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\win\Device.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\$(InputName)1.obj"
|
||||
XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Device.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceIkea.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceNexa.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceSartano.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceWaveman.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\settings\TelldusSettings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\settings\TelldusSettingsWinRegistry.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\TellUsbD101.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Device.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceIkea.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceNexa.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceSartano.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DeviceWaveman.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\win\FTD2XX.H"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\settings\TelldusSettings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\TellUsbD101.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\TellUsbD101.def"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\FTD2XX.dll"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FTD2XX.lib"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
32
driver/TellUsbD101/linux/Device.cpp
Normal file
32
driver/TellUsbD101/linux/Device.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "../Device.h"
|
||||
#include <iostream>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
|
||||
/*
|
||||
* Send message to the USB dongle
|
||||
*/
|
||||
void Device::send(char* strMessage) {
|
||||
int fd = -1;
|
||||
struct termios tio;
|
||||
|
||||
if( 0 > ( fd = open( strDevice, 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);
|
||||
}
|
||||
|
||||
void Device::setDevice(const char *device) {
|
||||
strDevice = strdup(device);
|
||||
}
|
109
driver/TellUsbD101/settings/TelldusSettings.cpp
Normal file
109
driver/TellUsbD101/settings/TelldusSettings.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
#include "TelldusSettings.h"
|
||||
#include "../DeviceNexa.h"
|
||||
#include "../DeviceWaveman.h"
|
||||
#include "../DeviceSartano.h"
|
||||
#include "../DeviceIkea.h"
|
||||
|
||||
|
||||
/*
|
||||
* Get the requested device
|
||||
* Note that the returned Device should be deleted when not in use anymore
|
||||
*/
|
||||
Device* TelldusSettings::getDevice(int intDeviceId){
|
||||
|
||||
Device* dev = NULL;
|
||||
|
||||
try{
|
||||
char* vendor = getVendor(intDeviceId);
|
||||
|
||||
//each new brand must be added here
|
||||
if (strcmp(vendor, "Nexa") == 0){
|
||||
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
||||
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
||||
dev = new DeviceNexa(strHouse, strCode);
|
||||
|
||||
} else if (strcmp(vendor, "Waveman") == 0) {
|
||||
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
||||
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
||||
dev = new DeviceWaveman(strHouse, strCode);
|
||||
|
||||
} else if (strcmp(vendor, "Sartano") == 0) {
|
||||
char *strCode = getArgument(intDeviceId, "sartano_code");
|
||||
dev = new DeviceSartano(strCode);
|
||||
|
||||
} else if (strcmp(vendor, "Ikea") == 0) {
|
||||
char *strSystem = getArgument(intDeviceId, "ikea_system");
|
||||
char *strUnits = getArgument(intDeviceId, "ikea_units");
|
||||
char *strFade = getArgument(intDeviceId, "ikea_fade");
|
||||
dev = new DeviceIkea(strSystem, strUnits, strFade);
|
||||
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef _WINDOWS
|
||||
dev->setDevice( getSetting("deviceNode") );
|
||||
#endif
|
||||
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the name of the device
|
||||
*/
|
||||
char* TelldusSettings::getName(int intDeviceId){
|
||||
return getStringSetting(intDeviceId, "name", false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the name of the device
|
||||
*/
|
||||
bool TelldusSettings::setName(int intDeviceId, const char* strNewName){
|
||||
return setStringSetting(intDeviceId, "name", strNewName, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the device vendor
|
||||
*/
|
||||
char* TelldusSettings::getVendor(int intDeviceId){
|
||||
return getStringSetting(intDeviceId, "vendor", false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the device vendor
|
||||
*/
|
||||
bool TelldusSettings::setVendor(int intDeviceId, const char* strVendor){
|
||||
return setStringSetting(intDeviceId, "vendor", strVendor, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the device model
|
||||
*/
|
||||
char* TelldusSettings::getModel(int intDeviceId){
|
||||
return getStringSetting(intDeviceId, "model", false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the device model
|
||||
*/
|
||||
bool TelldusSettings::setModel(int intDeviceId, const char* strModel){
|
||||
return setStringSetting(intDeviceId, "model", strModel, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set device argument
|
||||
*/
|
||||
bool TelldusSettings::setArgument(int intDeviceId, const char *strName, const char *strValue){
|
||||
return setStringSetting(intDeviceId, strName, strValue, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get device argument
|
||||
*/
|
||||
char* TelldusSettings::getArgument(int intDeviceId, const char *strName) {
|
||||
return getStringSetting(intDeviceId, strName, true);
|
||||
}
|
42
driver/TellUsbD101/settings/TelldusSettings.h
Normal file
42
driver/TellUsbD101/settings/TelldusSettings.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef TELLDUSSETTINGS_H
|
||||
#define TELLDUSSETTINGS_H
|
||||
|
||||
#include "../Device.h"
|
||||
//#include <vector>
|
||||
|
||||
class privateVars;
|
||||
|
||||
class TelldusSettings
|
||||
{
|
||||
public:
|
||||
TelldusSettings(void);
|
||||
char * getSetting(const char *strName);
|
||||
int getNumberOfDevices(void);
|
||||
Device* getDevice(int intDeviceId);
|
||||
char* getName(int intDeviceId);
|
||||
bool setName(int intDeviceId, const char* strNewName);
|
||||
char* getVendor(int intDeviceId);
|
||||
bool setVendor(int intDeviceId, const char* strVendor);
|
||||
char* getModel(int intDeviceId);
|
||||
bool setModel(int intDeviceId, const char* strModel);
|
||||
char* getArgument(int intDeviceId, const char *strName);
|
||||
bool setArgument(int intDeviceId, const char *strName, const char *strValue);
|
||||
int addDevice();
|
||||
int getDeviceId(int intDeviceIndex);
|
||||
bool removeDevice(int intDeviceId);
|
||||
void debugLog(char* debugstring);
|
||||
void debugLog(int debugint);
|
||||
|
||||
~TelldusSettings(void);
|
||||
|
||||
protected:
|
||||
char *getStringSetting(int intDeviceId, const char* name, bool parameter);
|
||||
bool setStringSetting(int intDeviceId, const char* name, const char *value, bool parameter);
|
||||
|
||||
private:
|
||||
int getNextDeviceId();
|
||||
|
||||
privateVars *d;
|
||||
};
|
||||
|
||||
#endif
|
248
driver/TellUsbD101/settings/TelldusSettingsConfuse.cpp
Normal file
248
driver/TellUsbD101/settings/TelldusSettingsConfuse.cpp
Normal file
|
@ -0,0 +1,248 @@
|
|||
//
|
||||
// C++ Implementation: telldussettingsconfuse
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2008
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
//
|
||||
#include "TelldusSettings.h"
|
||||
#include <confuse.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class privateVars {
|
||||
public:
|
||||
cfg_t *cfg;
|
||||
};
|
||||
|
||||
bool readConfig(cfg_t **cfg);
|
||||
|
||||
const char* CONFIG_FILE = "/etc/tellstick.conf";
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
TelldusSettings::TelldusSettings(void)
|
||||
{
|
||||
d = new privateVars();
|
||||
readConfig(&d->cfg);
|
||||
// printf("Nu: %d\n", cfg_size(d->cfg, "device"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
TelldusSettings::~TelldusSettings(void)
|
||||
{
|
||||
if (d->cfg > 0)
|
||||
cfg_free(d->cfg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a setting
|
||||
*/
|
||||
char *TelldusSettings::getSetting(const char *strName) {
|
||||
if (d->cfg > 0) {
|
||||
return cfg_getstr(d->cfg, strName);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of stored devices
|
||||
*/
|
||||
int TelldusSettings::getNumberOfDevices(void){
|
||||
if (d->cfg > 0) {
|
||||
return cfg_size(d->cfg, "device");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TelldusSettings::getDeviceId(int intDeviceIndex){
|
||||
if (intDeviceIndex >= getNumberOfDevices()) { //Out of bounds
|
||||
return -1;
|
||||
}
|
||||
cfg_t *cfg_device = cfg_getnsec(d->cfg, "device", intDeviceIndex);
|
||||
int id = cfg_getint(cfg_device, "id");
|
||||
return id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a new device
|
||||
*/
|
||||
int TelldusSettings::addDevice(){
|
||||
int intDeviceId = getNextDeviceId();
|
||||
|
||||
FILE *fp = fopen(CONFIG_FILE, "w");
|
||||
cfg_print(d->cfg, fp); //Print the config-file
|
||||
fprintf(fp, "device {\n id=%d\n}\n", intDeviceId); //Print the new device
|
||||
fclose(fp);
|
||||
|
||||
//Re-read config-file
|
||||
cfg_free(d->cfg);
|
||||
readConfig(&d->cfg);
|
||||
return intDeviceId;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get next available device id
|
||||
*/
|
||||
int TelldusSettings::getNextDeviceId(){
|
||||
int intDeviceId = 0;
|
||||
cfg_t *cfg_device;
|
||||
for (int i = 0; i < cfg_size(d->cfg, "device"); ++i) {
|
||||
cfg_device = cfg_getnsec(d->cfg, "device", i);
|
||||
if (cfg_getint(cfg_device, "id") >= intDeviceId) {
|
||||
intDeviceId = cfg_getint(cfg_device, "id");
|
||||
}
|
||||
}
|
||||
intDeviceId++;
|
||||
return intDeviceId;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a device
|
||||
*/
|
||||
bool TelldusSettings::removeDevice(int intDeviceId){
|
||||
bool blnSuccess = true;
|
||||
FILE *fp = fopen(CONFIG_FILE, "w");
|
||||
|
||||
// Print all opts
|
||||
for(int i = 0; d->cfg->opts[i].name; i++) {
|
||||
|
||||
// Check if it isn't a device section
|
||||
if (strcmp(d->cfg->opts[i].name, "device") != 0) {
|
||||
cfg_opt_print(&d->cfg->opts[i], fp);
|
||||
} else {
|
||||
// Print all sections except the one to remove
|
||||
cfg_t *cfg_device;
|
||||
for (int i = 0; i < cfg_size(d->cfg, "device"); ++i) {
|
||||
cfg_device = cfg_getnsec(d->cfg, "device", i);
|
||||
if (cfg_getint(cfg_device, "id") != intDeviceId) { //This isn't the one to skip
|
||||
fprintf(fp, "device {\n");
|
||||
cfg_print_indent(cfg_device, fp, 1);
|
||||
fprintf(fp, "}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
//Re-read config-file
|
||||
cfg_free(d->cfg);
|
||||
readConfig(&d->cfg);
|
||||
|
||||
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();
|
||||
}*/
|
||||
}
|
||||
|
||||
char *TelldusSettings::getStringSetting(int intDeviceId, const char* name, bool parameter) {
|
||||
if (d->cfg == 0) {
|
||||
return "";
|
||||
}
|
||||
cfg_t *cfg_device;
|
||||
for (int i = 0; i < cfg_size(d->cfg, "device"); ++i) {
|
||||
cfg_device = cfg_getnsec(d->cfg, "device", i);
|
||||
if (cfg_getint(cfg_device, "id") == intDeviceId) {
|
||||
if (parameter) {
|
||||
cfg_device = cfg_getsec(cfg_device, "parameters");
|
||||
}
|
||||
const char *strSetting = cfg_getstr(cfg_device, name);
|
||||
if (strSetting == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
char *strReturn = (char *)malloc(strlen(strSetting) * sizeof(char));
|
||||
strcpy(strReturn, strSetting);
|
||||
return strReturn;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool TelldusSettings::setStringSetting(int intDeviceId, const char* name, const char *value, bool parameter) {
|
||||
if (d->cfg == 0) {
|
||||
return false;
|
||||
}
|
||||
cfg_t *cfg_device;
|
||||
for (int i = 0; i < cfg_size(d->cfg, "device"); ++i) {
|
||||
cfg_device = cfg_getnsec(d->cfg, "device", i);
|
||||
if (cfg_getint(cfg_device, "id") == intDeviceId) {
|
||||
if (parameter) {
|
||||
cfg_t *cfg_parameters = cfg_getsec(cfg_device, "parameters");
|
||||
cfg_setstr(cfg_parameters, name, value);
|
||||
} else {
|
||||
cfg_setstr(cfg_device, name, value);
|
||||
}
|
||||
FILE *fp = fopen(CONFIG_FILE, "w");
|
||||
cfg_print(d->cfg, fp);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool readConfig(cfg_t **cfg) {
|
||||
cfg_opt_t parameter_opts[] = {
|
||||
//Nexa
|
||||
CFG_STR("nexa_house", 0, CFGF_NONE),
|
||||
CFG_STR("nexa_unit", 0, CFGF_NONE),
|
||||
|
||||
//Sartano
|
||||
CFG_STR("sartano_code", 0, CFGF_NONE),
|
||||
|
||||
//Ikea
|
||||
CFG_STR("ikea_system", 0, CFGF_NONE),
|
||||
CFG_STR("ikea_units", 0, CFGF_NONE),
|
||||
CFG_STR("ikea_fade", 0, CFGF_NONE),
|
||||
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
cfg_opt_t device_opts[] = {
|
||||
CFG_INT("id", -1, CFGF_NONE),
|
||||
CFG_STR("name", "Unnamed", CFGF_NONE),
|
||||
CFG_STR("vendor", "Nexa", CFGF_NONE),
|
||||
CFG_STR("model", "1", CFGF_NONE),
|
||||
CFG_SEC("parameters", parameter_opts, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
cfg_opt_t opts[] = {
|
||||
CFG_STR("deviceNode", "/dev/tellstick", CFGF_NONE),
|
||||
CFG_SEC("device", device_opts, CFGF_MULTI),
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
(*cfg) = cfg_init(opts, CFGF_NOCASE);
|
||||
if (cfg_parse((*cfg), CONFIG_FILE) == CFG_PARSE_ERROR) {
|
||||
(*cfg) = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
367
driver/TellUsbD101/settings/TelldusSettingsWinRegistry.cpp
Normal file
367
driver/TellUsbD101/settings/TelldusSettingsWinRegistry.cpp
Normal file
|
@ -0,0 +1,367 @@
|
|||
#include "../StdAfx.h"
|
||||
#include "TelldusSettings.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
bool storeGlobal(privateVars *d);
|
||||
|
||||
class privateVars {
|
||||
public:
|
||||
HKEY hk;
|
||||
HKEY rootKey;
|
||||
std::string strRegPathDevice;
|
||||
std::string strRegPath;
|
||||
int intMaxRegValueLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
TelldusSettings::TelldusSettings(void)
|
||||
{
|
||||
d = new privateVars();
|
||||
d->strRegPathDevice = "SOFTWARE\\Telldus\\Devices\\";
|
||||
d->strRegPath = "SOFTWARE\\Telldus\\";
|
||||
d->intMaxRegValueLength = 1000;
|
||||
if (storeGlobal(d)) {
|
||||
d->rootKey = HKEY_LOCAL_MACHINE;
|
||||
} else {
|
||||
d->rootKey = HKEY_CURRENT_USER;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
TelldusSettings::~TelldusSettings(void)
|
||||
{
|
||||
//RegCloseKey(hk); //close all, if still open //TODO: Need some way to know if open or closed
|
||||
d->strRegPath = "";
|
||||
d->strRegPathDevice = "";
|
||||
d->intMaxRegValueLength = -1;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of stored devices
|
||||
*/
|
||||
int TelldusSettings::getNumberOfDevices(void){
|
||||
|
||||
int intNumberOfDevices = 0;
|
||||
|
||||
try{
|
||||
|
||||
long lnExists = RegOpenKeyEx(d->rootKey, d->strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
string strNumSubKeys;
|
||||
DWORD dNumSubKeys;
|
||||
RegQueryInfoKey(d->hk, NULL, NULL, NULL, &dNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
intNumberOfDevices = (int)dNumSubKeys;
|
||||
|
||||
RegCloseKey(d->hk);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
intNumberOfDevices = -1;
|
||||
}
|
||||
return intNumberOfDevices;
|
||||
}
|
||||
|
||||
|
||||
int TelldusSettings::getDeviceId(int intDeviceIndex){
|
||||
int intReturn = -1;
|
||||
|
||||
try{
|
||||
|
||||
long lnExists = RegOpenKeyEx(d->rootKey, d->strRegPathDevice.c_str(), 0, KEY_READ, &d->hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
char* Buff = new char[d->intMaxRegValueLength];
|
||||
DWORD size;
|
||||
if (RegEnumKeyEx(d->hk, intDeviceIndex, (LPSTR)Buff, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
|
||||
intReturn = (int)_atoi64(Buff);
|
||||
}
|
||||
|
||||
delete Buff;
|
||||
|
||||
RegCloseKey(d->hk);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
intReturn = -1;
|
||||
}
|
||||
return intReturn;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Set device arguments
|
||||
*/
|
||||
/* bool TelldusSettings::setArguments(int intDeviceId, vector <int> 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 << d->strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
|
||||
if(RegCreateKeyEx(d->rootKey,
|
||||
strCompleteRegPath.c_str(),
|
||||
0,
|
||||
NULL,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
NULL,
|
||||
&d->hk,
|
||||
&dwDisp)){
|
||||
//fail
|
||||
throw exception("Create Key failed");
|
||||
}
|
||||
|
||||
RegCloseKey(d->hk);
|
||||
|
||||
}
|
||||
catch(...){
|
||||
intDeviceId = -1;
|
||||
}
|
||||
return intDeviceId;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get next available device id
|
||||
*/
|
||||
int TelldusSettings::getNextDeviceId(){
|
||||
|
||||
int intReturn = -1;
|
||||
try{
|
||||
DWORD dwDisp;
|
||||
long lnExists = RegCreateKeyEx(d->rootKey, d->strRegPathDevice.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
NULL,
|
||||
&d->hk,
|
||||
&dwDisp); //create or open if already created
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[d->intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(d->hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
|
||||
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(d->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 (d->hk, "LastUsedId", 0L, REG_DWORD, (CONST BYTE*) &dwVal, sizeof(DWORD));
|
||||
|
||||
}
|
||||
RegCloseKey(d->hk);
|
||||
}
|
||||
catch(...){
|
||||
intReturn = -1;
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a device
|
||||
*/
|
||||
bool TelldusSettings::removeDevice(int intDeviceId){
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << d->strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
|
||||
long lngSuccess = RegDeleteKey(d->rootKey, strCompleteRegPath.c_str());
|
||||
if(lngSuccess != ERROR_SUCCESS){
|
||||
blnSuccess = false;
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
char *TelldusSettings::getStringSetting(int intDeviceId, const char* name, bool parameter) {
|
||||
char* strReturn = "";
|
||||
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << d->strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[d->intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(d->hk, name, NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(d->hk, name, NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
strReturn = Buff;
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(d->hk);
|
||||
}
|
||||
catch(...){
|
||||
strReturn = "";
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool TelldusSettings::setStringSetting(int intDeviceId, const char* name, const char *value, bool parameter) {
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << d->strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &d->hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
d->intMaxRegValueLength = (int)strlen(value);
|
||||
RegSetValueEx(d->hk, name, 0, REG_SZ, (LPBYTE)value, d->intMaxRegValueLength);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(d->hk);
|
||||
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
bool storeGlobal(privateVars *d) {
|
||||
bool blnReturn = false;
|
||||
try{
|
||||
long lnExists = RegOpenKeyEx(HKEY_LOCAL_MACHINE, d->strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &d->hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[d->intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(d->hk, "SharedDevices", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
|
||||
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(d->hk, "SharedDevices", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
|
||||
if(lngStatus == ERROR_SUCCESS){
|
||||
|
||||
int intValue = (int)Buff[0];
|
||||
blnReturn = (intValue == 1);
|
||||
}
|
||||
delete Buff;
|
||||
}
|
||||
RegCloseKey(d->hk);
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
return blnReturn;
|
||||
}
|
8
driver/TellUsbD101/stdafx.cpp
Normal file
8
driver/TellUsbD101/stdafx.cpp
Normal file
|
@ -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
|
37
driver/TellUsbD101/stdafx.h
Normal file
37
driver/TellUsbD101/stdafx.h
Normal file
|
@ -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 <windows.h>
|
||||
|
||||
// C RunTime Header Files
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
89
driver/TellUsbD101/win/Device.cpp
Normal file
89
driver/TellUsbD101/win/Device.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "..\Device.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "..\StdAfx.h"
|
||||
#include "FTD2XX.H"
|
||||
|
||||
int getDongleIndex();
|
||||
|
||||
/*
|
||||
* Send message to the USB dongle
|
||||
*/
|
||||
void Device::send(char* strMessage){
|
||||
|
||||
try{
|
||||
FT_STATUS ftStatus = FT_OK;
|
||||
FT_HANDLE fthHandle = 0;
|
||||
|
||||
int intDongleIndex = getDongleIndex();
|
||||
if (intDongleIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ftStatus = FT_Open(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 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;
|
||||
}
|
||||
|
875
driver/TellUsbD101/win/FTD2XX.H
Normal file
875
driver/TellUsbD101/win/FTD2XX.H
Normal file
|
@ -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 */
|
||||
|
20
tdtool/CMakeLists.txt
Normal file
20
tdtool/CMakeLists.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
PROJECT(tdtool)
|
||||
|
||||
SET(tdtool_SRCS
|
||||
main.cpp
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(tdtool
|
||||
${tdtool_SRCS}
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/driver
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(tdtool
|
||||
tellusbd101
|
||||
)
|
||||
|
||||
INSTALL(TARGETS tdtool RUNTIME DESTINATION bin)
|
95
tdtool/main.cpp
Normal file
95
tdtool/main.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "TellUsbD101.h"
|
||||
#ifdef __MINGW32__
|
||||
#define sleep(x) _sleep((x)*1000)
|
||||
#endif
|
||||
|
||||
void print_usage( char *name ) {
|
||||
printf("Usage:\n");
|
||||
printf(" %s [ options ]\n", name);
|
||||
printf("\n");
|
||||
printf("Options: -[lh] [--list] [--help]\n");
|
||||
printf(" [--on device] [--off device]\n");
|
||||
printf("\n");
|
||||
printf("Options:\n");
|
||||
printf(" --list (-l short option)\n");
|
||||
printf(" List currently configured devices.\n");
|
||||
printf("\n");
|
||||
printf(" --help (-h short option)\n");
|
||||
printf(" Shows this screen.\n");
|
||||
printf("\n");
|
||||
printf(" --on device\n");
|
||||
printf(" Turns on device. device should be an integer of the device-id.\n");
|
||||
printf(" The device-id is outputed with the --list option\n");
|
||||
printf("\n");
|
||||
printf(" --off device\n");
|
||||
printf(" Turns off device. device should be an integer of the device-id.\n");
|
||||
printf(" The device-id is outputed with the --list option\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_device( int index ) {
|
||||
int intId = devGetDeviceId(index);
|
||||
char *name = devGetName(intId);
|
||||
printf("%i\t%s\n", intId, name);
|
||||
}
|
||||
|
||||
void list_devices() {
|
||||
int intNum = devGetNumberOfDevices();
|
||||
printf("Number of devices: %i\n", intNum);
|
||||
int i = 0;
|
||||
while (i < intNum) {
|
||||
print_device( i );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void switch_device( bool turnOn, int device ) {
|
||||
if (turnOn) {
|
||||
char *name = devGetName( device );
|
||||
bool ok = devTurnOn( device );
|
||||
printf("Turning on device: %i %s - %s\n", device, name, (ok ? "ok" : "failed"));
|
||||
} else {
|
||||
char *name = devGetName( device );
|
||||
bool ok = devTurnOff( device );
|
||||
printf("Turning off device: %i %s - %s\n", device, name, (ok ? "ok" : "failed"));
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int optch, longindex;
|
||||
static char optstring[] = "ln:f:h";
|
||||
static struct option long_opts[] = {
|
||||
{ "list", 0, 0, 'l' },
|
||||
{ "on", 1, 0, 'n' },
|
||||
{ "off", 1, 0, 'f' },
|
||||
{ "help", 1, 0, 'h' },
|
||||
{ 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
while ( (optch = getopt_long(argc,argv,optstring,long_opts,&longindex)) != -1 )
|
||||
switch (optch) {
|
||||
case 'f' :
|
||||
switch_device(false, atoi(&optarg[0]));
|
||||
break;
|
||||
case 'h' :
|
||||
print_usage( argv[0] );
|
||||
break;
|
||||
case 'l' :
|
||||
list_devices();
|
||||
break;
|
||||
case 'n' :
|
||||
switch_device(true, atoi(&optarg[0]));
|
||||
break;
|
||||
default :
|
||||
print_usage( argv[0] );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue