Compare commits
No commits in common. "master" and "1.2" have entirely different histories.
753 changed files with 3289 additions and 97944 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,7 +0,0 @@
|
|||
build/
|
||||
qtcreator-build/
|
||||
Doxyfile
|
||||
html/
|
||||
latex/
|
||||
CMakeLists.txt.user
|
||||
*.pyc
|
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "telldus-gui/3rdparty/qt-components-desktop"]
|
||||
path = telldus-gui/3rdparty/qt-components-desktop
|
||||
url = http://git.telldus.com/qt-components-desktop.git
|
|
@ -1,35 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TellStick.NET")]
|
||||
[assembly: AssemblyDescription("A managed .NET wrapper class library for the TellStick native DLL")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Eyedealistic / Levén Labs (http://labs.leven.se)")]
|
||||
[assembly: AssemblyProduct("TellStick.NET")]
|
||||
[assembly: AssemblyCopyright("Created by Mikael Levén in 2007")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("24411992-c766-4eb8-b7ac-c002f0d7d5ad")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("0.1.0.*")]
|
||||
[assembly: AssemblyFileVersion("0.1.0.0")]
|
102
3rdparty/tellstick.net/TellStick.NET.csproj
vendored
102
3rdparty/tellstick.net/TellStick.NET.csproj
vendored
|
@ -1,102 +0,0 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{700E41E9-ADB6-4D5A-B9EB-B6560C1C0D3F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TellStick</RootNamespace>
|
||||
<AssemblyName>TellStick.NET</AssemblyName>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
<SccLocalPath>
|
||||
</SccLocalPath>
|
||||
<SccAuxPath>
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>none</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files (x86)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<DocumentationFile>bin\x86\Release\TellStick.NET.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>none</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisRuleAssemblies>C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\\rules</CodeAnalysisRuleAssemblies>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<DocumentationFile>bin\x64\Release\TellStick.NET.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TellStick.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
318
3rdparty/tellstick.net/TellStick.cs
vendored
318
3rdparty/tellstick.net/TellStick.cs
vendored
|
@ -1,318 +0,0 @@
|
|||
/* -------------------------------------------------------------------------------
|
||||
* TellStick.NET
|
||||
* -------------------------------------------------------------------------------
|
||||
* Created by Mikael Levén (http://labs.leven.se)
|
||||
*
|
||||
* This piece of code is licensed as open source and can be freely used and
|
||||
* redistributed in any type of project, both commercial and non-commercial,
|
||||
* as long as this licensing policy is not altered. This means that any alterations
|
||||
* of this code must also be licensed as open source and therefore cannot be
|
||||
* protected or patented in any way. However, any software based on this code may
|
||||
* still be copyrighted (and/or patented) and sold as propritary software as long as
|
||||
* this code (and any alterations of it) can be freely used and modified by others.
|
||||
*
|
||||
* Altough the code is licensed as open source you don't need to republish any
|
||||
* changes made back to the community (it will be much appreciated tough).
|
||||
*
|
||||
* The code comes without any kind of warrantys and the author cannot be held
|
||||
* responsible for any kind of damage this software may (or may not) cause, no matter
|
||||
* if it's direct or indirect damage.
|
||||
*
|
||||
* Please note:
|
||||
* All TellStick core functionality is developed by Telldus Technologies
|
||||
* and as of now (2007-12-14) that code is also licensed as open source. This may
|
||||
* however change in the future and I suggest that you check there website
|
||||
* to make sure the licensing terms are still the same: http://www.telldus.se/
|
||||
* The documentation and example code for Tellstic is available at their Wiki:
|
||||
* http://www.telldus.se/wiki/
|
||||
*
|
||||
* -------------------------------------------------------------------------------
|
||||
* Description:
|
||||
* TellStick.NET is a Microsoft .NET wrapper for the native TellStick DLL.
|
||||
* The wrapper also adds some functionality to make it easier to work with
|
||||
* TellStick devices.
|
||||
*
|
||||
* Author: Mikael Levén
|
||||
* Created: 2007-12-14
|
||||
*
|
||||
* Dependencies:
|
||||
* This library depends on the native DLL for TellStick. To be able to actually
|
||||
* switch lights on and off you also need the driver to be installed as well
|
||||
* as an TellStick USB device.
|
||||
*
|
||||
* Revisions:
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
/// TellStick.NET is a Microsoft .NET wrapper for the native TellStick DLL.
|
||||
/// The wrapper also adds some functionality to make it easier to work with TellStick devices.
|
||||
/// </summary>
|
||||
public sealed class TellStick
|
||||
{
|
||||
private TellStick()
|
||||
{ }
|
||||
|
||||
|
||||
#region TellStick native DLL imports class
|
||||
public sealed class Native
|
||||
{
|
||||
private Native()
|
||||
{ }
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern int devAddDevice();
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devTurnOn(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devTurnOff(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern int devGetNumberOfDevices();
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern string devGetName(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devSetName(int intDeviceId, string chNewName);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern string devGetVendor(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devSetVendor(int intDeviceId, string chNewName);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern string devGetModel(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devSetModel(int intDeviceId, string chNewName);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern int[] devGetArguments(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devSetArguments(int intDeviceId, int[] intArguments, int intNumberOfArguments);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern int devAddDeviceWithArguments(string strVendor, int[] intArguments, int intNumberOfArguments);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern bool devRemoveDevice(int intDeviceId);
|
||||
|
||||
[DllImport("TellUsbD101.dll")]
|
||||
public static extern int devGetDeviceId(int intDeviceIndex);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of devices registered
|
||||
/// </summary>
|
||||
/// <returns>Returns the number of devices as an integer</returns>
|
||||
/// <remarks>The native DLL is required for this methods to run. If it's missing a ModuleNotFoundException exception will be thrown.</remarks>
|
||||
public static int GetNumberOfDevices()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Native.devGetNumberOfDevices();
|
||||
}
|
||||
catch (System.DllNotFoundException ex)
|
||||
{
|
||||
throw new ModuleNotFoundException("Could not find TellStick software. Please make sure it's installed before you run this application!", ex);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique idetifier of the device
|
||||
/// </summary>
|
||||
/// <param name="deviceIndex">Index number of the device to get ID for</param>
|
||||
/// <returns>Returns the unique identifier as an integer</returns>
|
||||
/// <remarks>The native DLL is required for this methods to run. If it's missing a ModuleNotFoundException exception will be thrown.</remarks>
|
||||
public static int GetDeviceId(int deviceIndex)
|
||||
{
|
||||
// Retrieve and return the device unqiue identifier from the native method
|
||||
try
|
||||
{
|
||||
return Native.devGetDeviceId(deviceIndex);
|
||||
}
|
||||
catch (System.DllNotFoundException ex)
|
||||
{
|
||||
throw new ModuleNotFoundException("Could not find TellStick software. Please make sure it's installed before you run this application!", ex);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user defined name of the device
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Device unqiue identification</param>
|
||||
/// <returns>Returns the user defined device name as a string</returns>
|
||||
/// <remarks>The native DLL is required for this methods to run. If it's missing a ModuleNotFoundException exception will be thrown.</remarks>
|
||||
public static string GetName(int deviceId)
|
||||
{
|
||||
// Retrieve and return the device name from the native method
|
||||
try
|
||||
{
|
||||
return Native.devGetName(deviceId);
|
||||
}
|
||||
catch (System.DllNotFoundException ex)
|
||||
{
|
||||
throw new ModuleNotFoundException("Could not find TellStick software. Please make sure it's installed before you run this application!", ex);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Turns on the selected device
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Device unqiue identification</param>
|
||||
/// <returns>Returns true if the device was succesfully turned on</returns>
|
||||
/// <remarks>The native DLL is required for this methods to run. If it's missing a ModuleNotFoundException exception will be thrown.</remarks>
|
||||
public static bool TurnOn(int deviceId)
|
||||
{
|
||||
// Send "on" signal
|
||||
try
|
||||
{
|
||||
return Native.devTurnOn(deviceId);
|
||||
}
|
||||
catch (System.DllNotFoundException ex)
|
||||
{
|
||||
throw new ModuleNotFoundException("Could not find TellStick software. Please make sure it's installed before you run this application!", ex);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns off the selected device
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Device unqiue identification</param>
|
||||
/// <returns>Returns true if the device was succesfully turned off</returns>
|
||||
/// <remarks>The native DLL is required for this methods to run. If it's missing a ModuleNotFoundException exception will be thrown.</remarks>
|
||||
public static bool TurnOff(int deviceId)
|
||||
{
|
||||
// Send "off" signal
|
||||
try
|
||||
{
|
||||
return Native.devTurnOff(deviceId);
|
||||
}
|
||||
catch (System.DllNotFoundException ex)
|
||||
{
|
||||
throw new ModuleNotFoundException("Could not find TellStick software. Please make sure it's installed before you run this application!", ex);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vendors name
|
||||
/// </summary>
|
||||
/// <param name="deviceId"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>The native DLL is required for this methods to run. If it's missing a ModuleNotFoundException exception will be thrown.</remarks>
|
||||
public static string GetVendor(int deviceId)
|
||||
{
|
||||
// Retrieve and return the vendor from the native method
|
||||
try
|
||||
{
|
||||
return Native.devGetVendor(deviceId);
|
||||
}
|
||||
catch (System.DllNotFoundException ex)
|
||||
{
|
||||
throw new ModuleNotFoundException("Could not find TellStick software. Please make sure it's installed before you run this application!", ex);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region "Support classes"
|
||||
|
||||
public abstract class TellStickException : System.Exception
|
||||
{
|
||||
public TellStickException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public TellStickException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public TellStickException(string message, System.Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class UnmanagedException : TellStickException
|
||||
{
|
||||
public UnmanagedException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public UnmanagedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public UnmanagedException(string message, System.Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ModuleNotFoundException : TellStickException
|
||||
{
|
||||
public ModuleNotFoundException()
|
||||
: base("Could not find TellStick software. Please make sure it's installed before you run this application!")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ModuleNotFoundException(string message)
|
||||
: base(message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ModuleNotFoundException(string message, System.Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
674
3rdparty/tellstickcontroller/License
vendored
674
3rdparty/tellstickcontroller/License
vendored
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
181
3rdparty/tellstickcontroller/Readme
vendored
181
3rdparty/tellstickcontroller/Readme
vendored
|
@ -1,181 +0,0 @@
|
|||
This Readme explains how to use tellstickControllerTdtool and
|
||||
tellstickControllerRfcmd programs to control a tellstick.
|
||||
|
||||
The tellstickController shell script can be used as a wrapper help
|
||||
for old users.
|
||||
|
||||
The two configuration files can also be used as a starting point on
|
||||
how to control receiver devices when running tellstickController in
|
||||
daemon mode.
|
||||
|
||||
tellstickControllerTdtool.conf shows how the configuration file can
|
||||
be written when using tdtool. Remember that tellstick.conf needs to
|
||||
be used for actual confiuration of receiver devices.
|
||||
|
||||
tellstickControllerRfcmd.conf shows how the configuration file can
|
||||
be written when using rfcmd.
|
||||
|
||||
The example directory contains a number of shell scripts that can be
|
||||
used as a starting point for how to use tellstickController.
|
||||
|
||||
######################################################################
|
||||
|
||||
NAME
|
||||
tellstickControllerTdtool
|
||||
|
||||
SYNOPSIS
|
||||
tellstickControllerTdtool [options]
|
||||
|
||||
DESCRIPTION
|
||||
tellstickController is used for controlling wireless recevier devices from
|
||||
a TellStick transmitter. This version uses the tdtool software to perform
|
||||
the actual device control. tellstickController can be used for manual
|
||||
control of devices, or used as a daemon that is controlled by a number of
|
||||
configuration file rules.
|
||||
Devices and groups can be accessed by either name or id.
|
||||
States can be set to ON, OFF or an integer between 0-255 for dimmer.
|
||||
|
||||
-h, --help Show this help text.
|
||||
-v, --verbose Show extra information.
|
||||
-d, --daemon Starts in daemon mode.
|
||||
-f, --file F Set configfile to file F.
|
||||
-c, --check Check content of configuration file.
|
||||
-t, --test Test mode, no real devices will used.
|
||||
-a, --aliases List of aliases for devices/groups.
|
||||
-l, --list List states for all devices/groups.
|
||||
-s, --set D S Set device D to state S
|
||||
-g, --get D Get state for device/group D.
|
||||
-w, --swapfirst G Swap states for group G based on first device state.
|
||||
-x, --swap D Swap state for device/group D.
|
||||
|
||||
EXAMPLES
|
||||
tellstickControllerTdtool -l
|
||||
tellstickControllerTdtool --set device_alias on
|
||||
tellstickControllerTdtool --swap device_alias
|
||||
tellstickControllerTdtool -d -f myConfigFile.conf
|
||||
|
||||
DEPENDENCIES
|
||||
The following Perl modules needs to be installed:
|
||||
DateTime and DateTime::Event::Sunrise
|
||||
|
||||
FILES
|
||||
tellstickController.conf
|
||||
tellstickController.log
|
||||
tellstickController.pid
|
||||
|
||||
CONFIGURATION
|
||||
The configuration file consists of a number of settings 'Set', a number of
|
||||
group aliases 'Group', and a number of device rules 'Rules'.
|
||||
|
||||
The settings controls sunrise/sunset, logfile, pidfile, etc.
|
||||
|
||||
The groups configures a list of devices and a delay time.
|
||||
|
||||
The rules can be written as a string containing two parts.
|
||||
The first part is optional and ends with an '/'. It can contain one or more
|
||||
of these keywords 'Weekend', 'Workweek', 'Monday', 'Tuesday', 'Wednesday',
|
||||
'Thursday', 'Friday', 'Saturday' and 'Sunday'. A specified date like
|
||||
'2008-03-18', '2008-03-##', '####-03-##' or '####-##-15' is also allowed.
|
||||
The second part is mandatory and is either a expression or the keyword 'No'.
|
||||
The expression can contain a micture of these keywords 'Sunrise', 'Sunset',
|
||||
'Random(HH:MM)', 'HH:MM' and 'Dimmer(HH:MM,startlevel,stoplevel,steplevel)'.
|
||||
A Dimmer can be controlled to change dim level from startlevel to stoplevel
|
||||
by adding/subtracting steplevel value every HH:MM time period.
|
||||
|
||||
Example rule: Weekend/07:15
|
||||
Example rule: Monday+Sunday/07:15
|
||||
Example rule: 2008-03-##/12:10
|
||||
Example rule: 07:15+Random(02:00)
|
||||
Example rule: Sunset-00:30
|
||||
Example rule: Workweek/07:00+Dimmer(00:01,5,255,25)
|
||||
|
||||
AUTHOR
|
||||
Original version written by Rickard Andersson
|
||||
|
||||
LICENSE
|
||||
Copyright (C) 2008-2010 Rickard Andersson. Version 2.0.0
|
||||
This program comes with ABSOLUTELY NO WARRANTY.
|
||||
This is free software, and you are welcome to redistribute it under certain
|
||||
conditions; See license file for details.
|
||||
|
||||
######################################################################
|
||||
|
||||
NAME
|
||||
tellstickControllerRfcmd
|
||||
|
||||
SYNOPSIS
|
||||
tellstickControllerRfcmd [options]
|
||||
|
||||
DESCRIPTION
|
||||
tellstickController is used for controlling wireless recevier devices from
|
||||
a TellStick transmitter. This version uses the rfcmd software to perform
|
||||
the actual device control. tellstickController can be used for manual
|
||||
control of devices, or used as a daemon that is controlled by a number of
|
||||
configuration file rules.
|
||||
A small database is used for keeping track of device states between every
|
||||
execution of tellstickController.
|
||||
|
||||
-h, --help Show this help text.
|
||||
-v, --verbose Show extra information.
|
||||
-d, --daemon Starts in daemon mode.
|
||||
-f, --file F Set configfile to file F.
|
||||
-c, --check Check content of configuration file.
|
||||
-t, --test Test mode, no real devices will used.
|
||||
-a, --aliases List of aliases for devices/groups.
|
||||
-l, --list List states for all devices/groups.
|
||||
-s, --set D S Set device D to state S.
|
||||
-g, --get D Get state for device/group D.
|
||||
-w, --swapfirst G Swap states for group G based on first device state.
|
||||
-x, --swap D Swap state for device/group D.
|
||||
|
||||
EXAMPLES
|
||||
tellstickControllerRfcmd -l
|
||||
tellstickControllerRfcmd --set device_alias on
|
||||
tellstickControllerRfcmd --swap device_alias
|
||||
tellstickControllerRfcmd -d -f myConfigFile.conf
|
||||
|
||||
DEPENDENCIES
|
||||
The following Perl modules needs to be installed:
|
||||
DB_File, DateTime and DateTime::Event::Sunrise
|
||||
|
||||
FILES
|
||||
tellstickController.conf
|
||||
tellstickController.db
|
||||
tellstickController.log
|
||||
tellstickController.pid
|
||||
|
||||
CONFIGURATION
|
||||
The configuration file consists of a number of settings 'Set', a number of
|
||||
device aliases 'Alias', and a number of device rules 'Rules'.
|
||||
|
||||
The settings controls sunrise/sunset, logfile, pidfile, etc.
|
||||
|
||||
The aliases configures device name, channel, code, etc.
|
||||
|
||||
The groups configures a list of devices and a delay time.
|
||||
|
||||
The rules can be written as a string containing two parts.
|
||||
The first part is optional and ends with an '/'. It can contain one or more
|
||||
of these keywords 'Weekend', 'Workweek', 'Monday', 'Tuesday', 'Wednesday',
|
||||
'Thursday', 'Friday', 'Saturday' and 'Sunday'. A specified date like
|
||||
'2008-03-18', '2008-03-##', '####-03-##' or '####-##-15' is also allowed.
|
||||
The second part is mandatory and is either a expression or the keyword 'No'.
|
||||
The expression can contain a micture of these keywords 'Sunrise', 'Sunset',
|
||||
'Random(HH:MM)' and 'HH:MM'.
|
||||
|
||||
Example rule: Weekend/07:15
|
||||
Example rule: Monday+Sunday/07:15
|
||||
Example rule: 2008-03-##/12:10
|
||||
Example rule: 07:15+Random(02:00)
|
||||
Example rule: Sunset-00:30
|
||||
|
||||
AUTHOR
|
||||
Original version written by Rickard Andersson
|
||||
|
||||
LICENSE
|
||||
Copyright (C) 2008-2010 Rickard Andersson. Version 2.0.0
|
||||
This program comes with ABSOLUTELY NO WARRANTY.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; See license file for details.
|
||||
|
||||
######################################################################
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Power off every device that control light sources.
|
||||
#
|
||||
|
||||
tellstickController --set bedroom_mythtv_leds off
|
||||
tellstickController --set bedroom_window off
|
||||
tellstickController --set kitchen_cabinets off
|
||||
tellstickController --set livingroom_cabinets off
|
||||
tellstickController --set livingroom_mythtv_leds off
|
||||
tellstickController --set livingroom_uplight off
|
||||
tellstickController --set livingroom_wall_north off
|
||||
tellstickController --set livingroom_wall_east off
|
||||
tellstickController --set livingroom_window off
|
||||
tellstickController --set study_window off
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Power off bedroom MythTV, turn off backlight leds.
|
||||
#
|
||||
|
||||
tellstickController --set bedroom_mythtv_power off
|
||||
tellstickController --set bedroom_mythtv_leds off
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Power on every device that control light sources.
|
||||
#
|
||||
|
||||
tellstickController --set bedroom_mythtv_leds on
|
||||
tellstickController --set bedroom_window on
|
||||
tellstickController --set kitchen_cabinets on
|
||||
tellstickController --set livingroom_cabinets on
|
||||
tellstickController --set livingroom_mythtv_leds on
|
||||
tellstickController --set livingroom_uplight on
|
||||
tellstickController --set livingroom_wall_north on
|
||||
tellstickController --set livingroom_wall_east on
|
||||
tellstickController --set Livingroom_window on
|
||||
tellstickController --set study_window on
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Power on bedroom MythTV, turn on backlight leds and turn off window lamp.
|
||||
#
|
||||
|
||||
tellstickController --set bedroom_mythtv_power on
|
||||
tellstickController --set bedroom_mythtv_leds on
|
||||
tellstickController --set bedroom_window off
|
||||
tellstickController --set bedroom_bed off
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Swaps livingroom tv mode on/off
|
||||
#
|
||||
|
||||
led_status=`tellstickController --get livingroom_mythtv_leds`
|
||||
#echo $led_status
|
||||
|
||||
if [ "$led_status" != "on" ]; then
|
||||
# echo on
|
||||
tellstickController --set livingroom_cabinets on
|
||||
tellstickController --set livingroom_mythtv_leds on
|
||||
tellstickController --set livingroom_uplight off
|
||||
tellstickController --set livingroom_wall_north on
|
||||
tellstickController --set livingroom_wall_east off
|
||||
tellstickController --set Livingroom_window on
|
||||
else
|
||||
# echo off
|
||||
tellstickController --set livingroom_cabinets on
|
||||
tellstickController --set livingroom_mythtv_leds off
|
||||
tellstickController --set livingroom_uplight off
|
||||
tellstickController --set livingroom_wall_north on
|
||||
tellstickController --set livingroom_wall_east on
|
||||
tellstickController --set Livingroom_window on
|
||||
fi
|
||||
|
||||
exit
|
|
@ -1,96 +0,0 @@
|
|||
################################################################################
|
||||
#
|
||||
# Configuration file for tellstickController
|
||||
#
|
||||
# Copyright (C) 2008 Rickard Andersson (ran42ran@gmail.com)
|
||||
# Version: 1.4
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# List of location settings.
|
||||
#
|
||||
# Usage example:
|
||||
# Set Key Value
|
||||
# Set Timezone Europe/Stockholm
|
||||
#
|
||||
#
|
||||
Set Timezone Europe/Stockholm
|
||||
Set Latitude 58.24
|
||||
Set Longitude 15.31
|
||||
Set dbfile /var/lib/tellstickController.db
|
||||
Set pidfile /var/run/tellstickController.pid
|
||||
Set logfile /var/log/tellstickController.log
|
||||
|
||||
|
||||
# Aliases for recevier devices.
|
||||
#
|
||||
# Usage example:
|
||||
# Alias Name Sender Dimmer Protocol Housecode Channel
|
||||
# Alias BedroomWindow /dev/tellstick0 yes Nexa A 1
|
||||
# Alias device42 /dev/tellstick1 No Waveman B 3
|
||||
# or
|
||||
# Usage example:
|
||||
# Alias Name Sender Dimmer Protocol Channel
|
||||
# Alias MythTv_Backlight /dev/ttyUSB0 No Sartano 000000001
|
||||
#
|
||||
#
|
||||
Alias Bedroom_window /dev/tellstick0 No Nexa G 10
|
||||
Alias Bedroom_mythtv_power /dev/tellstick0 No Nexa G 6
|
||||
Alias Bedroom_mythtv_leds /dev/tellstick0 No Nexa G 7
|
||||
Alias Kitchen_cabinets /dev/tellstick0 No Nexa G 2
|
||||
Alias Kitchen_window /dev/tellstick0 No Nexa G 11
|
||||
Alias Livingroom_cabinets /dev/tellstick0 No Nexa G 3
|
||||
Alias Livingroom_wall_north /dev/tellstick0 No Nexa G 4
|
||||
Alias Livingroom_wall_east /dev/tellstick0 No Nexa G 9
|
||||
Alias Livingroom_uplight /dev/tellstick0 Yes Nexa G 5
|
||||
Alias Livingroom_mythtv_leds /dev/tellstick0 No Nexa G 8
|
||||
Alias Livingroom_window /dev/tellstick0 No Nexa G 1
|
||||
Alias Study_window /dev/tellstick0 No Nexa G 12
|
||||
|
||||
|
||||
# Group aliases uses for handling a group of aliases
|
||||
#
|
||||
# Usage examples:
|
||||
# Group Name Delay List of Aliases
|
||||
# Group Livingroom_walls 60 Livingroom_wall_north Livingroom_wall_east
|
||||
# Group Kitchen 5 Kitchen_cabinets Kitchen_window
|
||||
#
|
||||
#
|
||||
Group Christmas_lights 20 Bedroom_window Kitchen_window Study_window
|
||||
Group Background_lights 60 Kitchen_cabinets Livingroom_window Livingroom_wall_east Livingroom_wall_north
|
||||
Group All_lights 10 Bedroom_mythtv_leds Bedroom_window Kitchen_cabinets Kitchen_window Livingroom_cabinets Livingroom_mythtv_leds Livingroom_uplight Livingroom_wall_north Livingroom_wall_east Livingroom_window Study_window
|
||||
|
||||
|
||||
# Timer rules for reciever devices.
|
||||
#
|
||||
# Usage examples:
|
||||
# Rule Alias DeviceOn DeviceOff
|
||||
# Rule BedroomWindow Sunrise Sunrise+01:30
|
||||
# Rule BedroomWindow 18:33 23:10+Random(00:45)
|
||||
# Rule MythTv_Backlight Weekend/20:00 Weekend/Sunset
|
||||
#
|
||||
#
|
||||
Rule Background_lights Workweek/Sunset+Random(01:00) Workweek/00:00+Random(00:30)
|
||||
Rule Background_lights Weekend/Sunset-Random(00:30) Weekend/00:45+Random(00:30)
|
||||
|
||||
Rule Christmas_lights 07:00+Random(00:30) 09:00+Random(00:30)
|
||||
Rule Christmas_lights 14:30+Random(00:30) 00:30+Random(00:30)
|
||||
|
||||
Rule Kitchen_cabinets Sunrise-01:30 Sunrise+01:00
|
||||
|
||||
Rule All_lights No 02:00
|
142
3rdparty/tellstickcontroller/tellstick.conf
vendored
142
3rdparty/tellstickcontroller/tellstick.conf
vendored
|
@ -1,142 +0,0 @@
|
|||
deviceNode = "/dev/tellstick0"
|
||||
|
||||
device {
|
||||
id = 1
|
||||
name = "Bedroom_bed"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100010"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 2
|
||||
name = "Bedroom_window"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100020"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 3
|
||||
name = "Bedroom_mythtv_leds"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100030"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 4
|
||||
name = "Study_window"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100040"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 5
|
||||
name = "Kitchen_cabinets"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100050"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 6
|
||||
name = "Bedroom_dimmer"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-dimmer"
|
||||
parameters {
|
||||
house = "100060"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 7
|
||||
name = "Livingroom_cabinets"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100070"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 8
|
||||
name = "Livingroom_wall_north"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100080"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 9
|
||||
name = "Test"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100090"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 10
|
||||
name = "Livingroom_window"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100100"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 11
|
||||
name = "Kitchen_window"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100110"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 12
|
||||
name = "Livingroom_wall_east"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100120"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 13
|
||||
name = "Livingroom_mythtv_leds"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-switch"
|
||||
parameters {
|
||||
house = "100130"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
||||
device {
|
||||
id = 14
|
||||
name = "Livingroom_uplight"
|
||||
protocol = "arctech"
|
||||
model = "selflearning-dimmer"
|
||||
parameters {
|
||||
house = "100140"
|
||||
unit = "1"
|
||||
}
|
||||
}
|
58
3rdparty/tellstickcontroller/tellstickController
vendored
58
3rdparty/tellstickcontroller/tellstickController
vendored
|
@ -1,58 +0,0 @@
|
|||
#!/bin/sh
|
||||
######################################################################
|
||||
#
|
||||
# Wrapper script that can be used to select which tellstickController
|
||||
# program to run
|
||||
#
|
||||
# Copyright (C) 2008-2010 Rickard Andersson (ran42ran@gmail.com)
|
||||
# Version 2.0.0
|
||||
#
|
||||
######################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
######################################################################
|
||||
#
|
||||
# How to run tellstickController with tdtool
|
||||
# tellstickController --tdtool --list
|
||||
#
|
||||
# How to run tellstickController with rfcmd
|
||||
# tellstickController --rdfcmd --list
|
||||
#
|
||||
# How to run tellstickController with default program (tdtool or rfcmd)
|
||||
# tellstickController --list
|
||||
#
|
||||
|
||||
|
||||
case "$1" in
|
||||
--tdtool)
|
||||
shift
|
||||
tellstickControllerTdtool $@
|
||||
exit $?
|
||||
;;
|
||||
--rfcmd)
|
||||
shift
|
||||
tellstickControllerRfcmd $@
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Uncomment your choice of default program below
|
||||
#
|
||||
|
||||
# tellstickControllerRfcmd $@
|
||||
tellstickControllerTdtool $@
|
||||
|
||||
exit $?
|
|
@ -1,85 +0,0 @@
|
|||
################################################################################
|
||||
#
|
||||
# Configuration file for tellstickController
|
||||
#
|
||||
# Copyright (C) 2008-2010 Rickard Andersson (ran42ran@gmail.com)
|
||||
# Version: 2.0.0
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# List of location settings.
|
||||
#
|
||||
# Usage example:
|
||||
# Set Key Value
|
||||
#
|
||||
# Set Timezone Europe/Stockholm
|
||||
#
|
||||
Set Timezone Europe/Stockholm
|
||||
Set Altitude -0.833
|
||||
Set Latitude 58.24
|
||||
Set Longitude 15.31
|
||||
Set dbfile /var/lib/tellstickController.db
|
||||
Set pidfile /var/run/tellstickController.pid
|
||||
Set logfile /var/log/tellstickController.log
|
||||
|
||||
|
||||
# Aliases for recevier devices.
|
||||
#
|
||||
# Usage example:
|
||||
# Alias Name Sender Dimmer Protocol Housecode Channel
|
||||
#
|
||||
# Alias BedroomWindow /dev/tellstick0 yes Nexa A 1
|
||||
# Alias device42 /dev/tellstick1 No Waveman B 3
|
||||
#
|
||||
# or
|
||||
#
|
||||
# Usage example:
|
||||
# Alias Name Sender Dimmer Protocol Channel
|
||||
#
|
||||
# Alias MythTv_Backlight /dev/ttyUSB0 No Sartano 000000001
|
||||
#
|
||||
Alias device1 /dev/tellstick No Nexa A 1
|
||||
Alias device2 /dev/tellstick No Nexa A 2
|
||||
|
||||
|
||||
# Groups used for handling a list of aliases.
|
||||
#
|
||||
# Usage examples:
|
||||
# Group Name Delay Aliases
|
||||
# Group Livingroom_walls 60 Livingroom_wall_north Livingroom_wall_east
|
||||
# Group Kitchen 5 Kitchen_cabinets Kitchen_window
|
||||
#
|
||||
Group allDevices 10 Device1 Device2
|
||||
|
||||
|
||||
# Timer rules for reciever devices.
|
||||
#
|
||||
# Usage examples:
|
||||
# Rule Alias DeviceOn DeviceOff
|
||||
#
|
||||
# Rule BedroomWindow Sunrise Sunrise+01:30
|
||||
# Rule BedroomWindow 18:33 23:10+Random(00:45)
|
||||
# Rule MythTv_Backlight Weekend/20:00 Weekend/Sunset
|
||||
# Rule device42 2008-03-##/18:45 2008-03-##/22:11
|
||||
# Rule device42 No 02:00
|
||||
#
|
||||
Rule device1 weekend/sunrise weekend/08:45
|
||||
Rule device1 sunset+00:15 23:30+Random(00:20)
|
||||
Rule device2 Workweek/07:00+Dimmer(00:02,0,200,25) weekend/08:45
|
||||
Rule allDevices 16:45 23:45
|
||||
|
1083
3rdparty/tellstickcontroller/tellstickControllerRfcmd
vendored
1083
3rdparty/tellstickcontroller/tellstickControllerRfcmd
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,108 +0,0 @@
|
|||
################################################################################
|
||||
#
|
||||
# Configuration file for tellstickController
|
||||
#
|
||||
# Copyright (C) 2008 Rickard Andersson (ran42ran@gmail.com)
|
||||
# Version: 1.4
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# List of location settings.
|
||||
#
|
||||
# Usage example:
|
||||
# Set Key Value
|
||||
# Set Timezone Europe/Stockholm
|
||||
#
|
||||
#
|
||||
Set Timezone Europe/Stockholm
|
||||
Set Altitude -0.833
|
||||
Set Latitude 58.24
|
||||
Set Longitude 15.31
|
||||
Set dbfile /var/lib/tellstickController.db
|
||||
Set pidfile /var/run/tellstickController.pid
|
||||
Set logfile /var/log/tellstickController.log
|
||||
set progrsm /usr/bin/rfcmd
|
||||
|
||||
|
||||
# Aliases for recevier devices.
|
||||
#
|
||||
# Usage example:
|
||||
# Alias Name Sender Dimmer Protocol Housecode Channel
|
||||
# Alias BedroomWindow /dev/tellstick0 yes Nexa A 1
|
||||
# Alias device42 /dev/tellstick1 No Waveman B 3
|
||||
# or
|
||||
# Usage example:
|
||||
# Alias Name Sender Dimmer Protocol Channel
|
||||
# Alias MythTv_Backlight /dev/ttyUSB0 No Sartano 000000001
|
||||
#
|
||||
#
|
||||
Alias Bedroom_bed /dev/tellstick0 No Nexa G 11
|
||||
Alias Bedroom_window /dev/tellstick0 No Nexa G 10
|
||||
Alias Bedroom_mythtv_power /dev/tellstick0 No Nexa G 6
|
||||
Alias Bedroom_mythtv_leds /dev/tellstick0 No Nexa G 7
|
||||
Alias Kitchen_cabinets /dev/tellstick0 No Nexa G 2
|
||||
Alias Kitchen_window /dev/tellstick0 No Nexa G 12
|
||||
Alias Livingroom_cabinets /dev/tellstick0 No Nexa G 3
|
||||
Alias Livingroom_wall_north /dev/tellstick0 No Nexa G 4
|
||||
Alias Livingroom_wall_east /dev/tellstick0 No Nexa G 9
|
||||
Alias Livingroom_uplight /dev/tellstick0 Yes Nexa G 5
|
||||
Alias Livingroom_mythtv_leds /dev/tellstick0 No Nexa G 8
|
||||
Alias Livingroom_window /dev/tellstick0 No Nexa G 1
|
||||
Alias Study_window /dev/tellstick0 No Nexa G 13
|
||||
|
||||
|
||||
# Group aliases uses for handling a group of aliases
|
||||
#
|
||||
# Usage examples:
|
||||
# Group Name Delay List of Aliases
|
||||
# Group Livingroom_walls 60 Livingroom_wall_north Livingroom_wall_east
|
||||
# Group Kitchen 5 Kitchen_cabinets Kitchen_window
|
||||
#
|
||||
#
|
||||
Group Normal_lights 120 Bedroom_window Kitchen_cabinets Kitchen_window Livingroom_window Livingroom_wall_east Study_window
|
||||
Group Extra_lights 180 Livingroom_cabinets Livingroom_uplight Livingroom_wall_north
|
||||
Group All_lights 10 Bedroom_mythtv_leds Bedroom_window Bedroom_bed Kitchen_cabinets Kitchen_window Livingroom_cabinets Livingroom_mythtv_leds Livingroom_uplight Livingroom_wall_north Livingroom_wall_east Livingroom_window Study_window
|
||||
Group Christmas_lights 60 Bedroom_window Kitchen_window Study_window
|
||||
|
||||
|
||||
# Timer rules for reciever devices.
|
||||
#
|
||||
# Usage examples:
|
||||
# Rule Alias DeviceOn DeviceOff
|
||||
# Rule BedroomWindow Sunrise Sunrise+01:30
|
||||
# Rule BedroomWindow 18:33 23:10+Random(00:45)
|
||||
# Rule MythTv_Backlight Weekend/20:00 Weekend/Sunset
|
||||
#
|
||||
#
|
||||
Rule Normal_lights Workweek/Sunset-01:00+Random(00:50) Workweek/00:01+Random(00:50)
|
||||
Rule Normal_lights Weekend/Sunset-01:00+Random(00:50) Weekend/00:01+Random(00:50)
|
||||
|
||||
Rule Extra_lights No 00:15+Random(00:30)
|
||||
|
||||
Rule All_lights No 02:00
|
||||
Rule All_lights No 03:00
|
||||
|
||||
#Rule Bedroom_window Workweek/07:30 Workweek/08:30
|
||||
|
||||
#Rule Christmas_lights 07:00+Random(00:15) 10:00+Random(00:30)
|
||||
#Rule Christmas_lights 15:00+Random(00:30) 00:30+Random(00:15)
|
||||
|
||||
#Rule Livingroom_cabinets 18:55+Random(01:00) 21:55+Random(01:00)
|
||||
#Rule Livingroom_wall_north 19:55+Random(01:00) 20:55+Random(01:00)
|
||||
#Rule Bedroom_bed 20:55+Random(01:00) 22:55+Random(01:00)
|
||||
|
1133
3rdparty/tellstickcontroller/tellstickControllerTdtool
vendored
1133
3rdparty/tellstickcontroller/tellstickControllerTdtool
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,89 +0,0 @@
|
|||
################################################################################
|
||||
#
|
||||
# Configuration file for tellstickController
|
||||
#
|
||||
# Copyright (C) 2008-2010 Rickard Andersson (ran42ran@gmail.com)
|
||||
# Version: 2.0
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# List of location settings
|
||||
#
|
||||
# Usage example:
|
||||
# Set Key Value
|
||||
# Set Timezone Europe/Stockholm
|
||||
#
|
||||
#
|
||||
Set Timezone Europe/Stockholm
|
||||
Set Altitude -0.833
|
||||
Set Latitude 58.24
|
||||
Set Longitude 15.31
|
||||
|
||||
Set pidfile /var/run/tellstickController.pid
|
||||
Set logfile /var/log/tellstickController.log
|
||||
Set program /usr/bin/tdtool
|
||||
|
||||
|
||||
# Group aliases uses for handling a group of devices
|
||||
#
|
||||
# Usage examples:
|
||||
# Group Name Delay List of devices
|
||||
# Group Livingroom_walls 60 Livingroom_wall_north Livingroom_wall_east
|
||||
# Group Kitchen 5 Kitchen_cabinets Kitchen_window
|
||||
#
|
||||
#
|
||||
Group Normal_lights 120 Bedroom_window Kitchen_cabinets Kitchen_window Livingroom_window Livingroom_wall_east Study_window
|
||||
|
||||
Group Extra_lights 180 Livingroom_cabinets Livingroom_uplight Livingroom_wall_north
|
||||
|
||||
Group All_lights 10 Bedroom_mythtv_leds Bedroom_window Bedroom_bed Kitchen_cabinets Kitchen_window Livingroom_cabinets Livingroom_mythtv_leds Livingroom_uplight Livingroom_wall_north Livingroom_wall_east Livingroom_window Study_window
|
||||
|
||||
#Group Christmas_lights 60 Bedroom_window Kitchen_window Study_window
|
||||
|
||||
#Group dimmers 60 testDimmer test
|
||||
|
||||
|
||||
# Timer rules for devices
|
||||
#
|
||||
# Usage examples:
|
||||
# Rule Alias DeviceOn DeviceOff
|
||||
# Rule LivingroomWindow Sunrise Sunrise+01:30
|
||||
# Rule LivingroomWindow 18:33 23:10+Random(00:45)
|
||||
# Rule MythTv_Backlight Weekend/20:00 Weekend/Sunset
|
||||
# Rule BedroomDimmer 07:00+Dimmer(00:01,5,255,25) 08:00
|
||||
#
|
||||
#
|
||||
Rule Normal_lights Workweek/Sunset-01:00+Random(00:50) Workweek/00:01+Random(00:50)
|
||||
Rule Normal_lights Weekend/Sunset-01:00+Random(00:50) Weekend/00:01+Random(00:50)
|
||||
|
||||
Rule Extra_lights No 00:15+Random(00:30)
|
||||
|
||||
Rule All_lights No 02:00
|
||||
Rule All_lights No 03:00
|
||||
|
||||
#Rule Bedroom_window Workweek/07:30 Workweek/08:30
|
||||
|
||||
#Rule Christmas_lights 07:00+Random(00:15) 10:00+Random(00:30)
|
||||
#Rule Christmas_lights 15:00+Random(00:30) 00:30+Random(00:15)
|
||||
|
||||
#Rule Livingroom_cabinets 18:55+Random(01:00) 21:55+Random(01:00)
|
||||
#Rule Livingroom_wall_north 19:55+Random(01:00) 20:55+Random(01:00)
|
||||
#Rule Bedroom_bed 20:55+Random(01:00) 22:55+Random(01:00)
|
||||
|
||||
#Rule testDimmer 22:00+Dimmer(00:01,5,255,50) Sunrise+Dimmer(00:01,5,250,25)
|
||||
#Rule dimmers No 23:00+Dimmer(00:01,250,0,50)
|
674
3rdparty/tellstickd/LICENSE
vendored
674
3rdparty/tellstickd/LICENSE
vendored
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
46
3rdparty/tellstickd/README
vendored
46
3rdparty/tellstickd/README
vendored
|
@ -1,46 +0,0 @@
|
|||
General
|
||||
=================
|
||||
This software is intended for controlling remote switch devices with rfcmd.
|
||||
|
||||
Dependencies
|
||||
=================
|
||||
For this script to run you need perl and the following perl-modules:
|
||||
DateTime
|
||||
DateTime::Event::Sunrise
|
||||
|
||||
|
||||
Installation
|
||||
=================
|
||||
0. Install rfcmd and necessary perl modules (on a typical Fedora/Centos/RHEL with the necessary repos installed, this should do it for you: yum install perl-DateTime perl-DateTime-Event-Sunrise).
|
||||
|
||||
1. Copy the file tellstickd-version/tellstickd to /usr/local/bin/ (or anywhere else depending on your wishes).
|
||||
|
||||
2. Copy the file tellstickd-version/tellstickd.conf to /etc/ (or anywhere else depending on your wishes).
|
||||
|
||||
3. Copy the suitable init script found under tellstickd-version/init_script to /etc/rc.d/init.d, this way you can control the script as any other service, easily make it start at boot (with chkconfig --level 35 tellstickd on). The file init_script/tellstickd is a Redhat type script whereas init_script/tellstickd.debian not unexpectedly should work on Debian type systems.
|
||||
4. Remember to make the perl-script and init-script executable. As root chmod 755 /usr/local/bin/tellstickd /etc/rc.d/init.d/tellstickd
|
||||
|
||||
Configuration
|
||||
=================
|
||||
1. In tellstickd.conf:
|
||||
a. Set appropriate coordinates and timezone to suit your geographical location (further information: http://search.cpan.org/dist/DateTime-Event-Sunrise/lib/DateTime/Event/Sunrise.pm).
|
||||
b. Specifiy the rfcmd-binary location. Default: /usr/local/bin/rfcmd
|
||||
c. Specify the tellstick device name. Default: /dev/tellstick
|
||||
d. Specify the location of the logfile.
|
||||
e. Add device configurations. Multiple definitions for each device are possible (avoid having on and off times of multiple definitions overlapping each other).
|
||||
|
||||
2. If you would like this script to start at boot-time, on a RHEL/Centos/Fedora system, execute the following command chkconfig --level 35 tellstickd on
|
||||
|
||||
|
||||
Licensing
|
||||
=================
|
||||
This software is freely distributable under the GNU General Public License,
|
||||
the full content of the license is included in the file LICENSE.
|
||||
Bug reports are welcome, but even more appreciated are patches with the solution to the problem.
|
||||
|
||||
Authors
|
||||
=================
|
||||
Magnus Juntti
|
||||
mjuntti@gmail.com
|
||||
|
||||
Anders Betnér
|
84
3rdparty/tellstickd/init_script/tellstickd
vendored
84
3rdparty/tellstickd/init_script/tellstickd
vendored
|
@ -1,84 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Init file for tellstickd remote light switch daemon
|
||||
#
|
||||
# Written by Magnus Juntti
|
||||
#
|
||||
# chkconfig: 35 54 46
|
||||
# description: tellstickd remote light switch daemon
|
||||
#
|
||||
# processname: tellstickd
|
||||
# config: /etc/tellstickd.conf
|
||||
# pidfile: /var/run/tellstick
|
||||
|
||||
source /etc/rc.d/init.d/functions
|
||||
|
||||
EXECUTABLE="/usr/bin/tellstickd"
|
||||
CONFIG_FILE="/etc/tellstickd.conf"
|
||||
OPTIONS=""
|
||||
|
||||
[ -x $EXECUTABLE ] || exit 1
|
||||
[ -r $CONFIG_FILE ] || exit 1
|
||||
|
||||
RETVAL=0
|
||||
prog="tellstickd"
|
||||
desc="remote switch daemon"
|
||||
|
||||
start() {
|
||||
echo -n $"Starting $desc ($prog): "
|
||||
daemon --user root $prog --daemon --config $CONFIG_FILE $OPTIONS
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
echo -n $"Shutting down $desc ($prog): "
|
||||
killproc $prog
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
reload() {
|
||||
echo -n $"Reloading $desc ($prog): "
|
||||
killproc $prog -HUP
|
||||
RETVAL=$?
|
||||
echo
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
condrestart)
|
||||
[ -e /var/lock/subsys/$prog ] && restart
|
||||
RETVAL=$?
|
||||
;;
|
||||
status)
|
||||
status $prog
|
||||
RETVAL=$?
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
|
||||
RETVAL=1
|
||||
esac
|
||||
|
||||
exit $RETVAL
|
|
@ -1,75 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Init file for tellstickd remote light switch daemon
|
||||
#
|
||||
# Written by Magnus Juntti
|
||||
#
|
||||
# chkconfig: 35 54 46
|
||||
# description: tellstickd remote light switch daemon
|
||||
#
|
||||
# processname: tellstickd
|
||||
# config: /etc/tellstickd.conf
|
||||
# pidfile: /var/run/tellstick
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
DAEMON="/usr/local/bin/tellstickd"
|
||||
NAME="tellstickd"
|
||||
CONFIG_FILE="/etc/tellstickd.conf"
|
||||
PID_FILE="/var/run/tellstickd.pid"
|
||||
OPTIONS=""
|
||||
|
||||
[ -x $DAEMON ] || exit 1
|
||||
[ -r $CONFIG_FILE ] || exit 1
|
||||
|
||||
|
||||
RETVAL=0
|
||||
prog="tellstickd"
|
||||
desc="remote switch daemon"
|
||||
|
||||
start() {
|
||||
log_begin_msg "Starting $desc ($prog): "
|
||||
start-stop-daemon --start --quiet --pidfile "$PID_FILE" --name $NAME --exec $DAEMON -- --daemon --config $CONFIG_FILE $OPTIONS
|
||||
log_end_msg $?
|
||||
|
||||
}
|
||||
|
||||
stop() {
|
||||
log_begin_msg "Shutting down $desc ($prog): "
|
||||
start-stop-daemon --stop --quiet --pidfile "$PID_FILE" --name $NAME
|
||||
log_end_msg $?
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
reload() {
|
||||
restart
|
||||
# the daemon doesn't reacto to sig HUP, so just restart it
|
||||
# log_begin_msg "Reloading $desc ($prog): "
|
||||
# start-stop-daemon --stop --quiet --pidfile "$PID_FILE" --name $NAME --signal 1
|
||||
# log_end_msg $?
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|restart|reload}"
|
||||
exit 2
|
||||
esac
|
||||
|
||||
exit 0
|
850
3rdparty/tellstickd/tellstickd
vendored
850
3rdparty/tellstickd/tellstickd
vendored
|
@ -1,850 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use POSIX;
|
||||
use DateTime;
|
||||
use DateTime::Event::Sunrise;
|
||||
use Time::Local;
|
||||
use strict;
|
||||
use sigtrap 'handler', \&daemon_exit, 'normal-signals';
|
||||
|
||||
# The following variables should be adapted to your geographical location and system setup
|
||||
my $LATITUDE = "65.603"; # 65.603N 22.18W -> Luleå, Sweden
|
||||
my $LONGITUDE = "22.18";
|
||||
my $TIMEZONE = "Europe/Stockholm";
|
||||
my $RFCMD = "/usr/local/bin/rfcmd";
|
||||
my $TELLSTICK_DEVICE = "/dev/tellstick";
|
||||
my $CONFIG_FILE = "/etc/tellstickd.conf";
|
||||
my $LOG_FILE = "/var/log/tellstickd";
|
||||
my $pidFile = '/var/run/tellstickd.pid';
|
||||
|
||||
|
||||
# You should not need to go beyond this point (unless you have found a bug or need to improve the functionality).
|
||||
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
||||
my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
|
||||
my $NO = 0;
|
||||
my $YES = 1;
|
||||
my @device_cfg;
|
||||
my $conf_file = "";
|
||||
my $make_daemon = $NO;
|
||||
my $simulate = $NO;
|
||||
my $n_rfcmd_calls;
|
||||
my $current_time;
|
||||
my $number_of_rules;
|
||||
my $Day;
|
||||
my $Month;
|
||||
my $Year;
|
||||
my $Minute;
|
||||
my $Hour;
|
||||
my $Second;
|
||||
my $WeekDay;
|
||||
my $DayOfYear;
|
||||
my $IsDST;
|
||||
my $daylightSavings;
|
||||
my $dayOfYear;
|
||||
my $dayOfWeek;
|
||||
my $dayOfMonth;
|
||||
|
||||
my $PROGRAM_NAME = "tellstickd";
|
||||
my $VERSION = "0.6.3";
|
||||
|
||||
# Structure of the configurations to be read;
|
||||
# $device_cfg[$i][0]; # Protocol, only NEXA, WAVEMAN and SARTANO supported so far by rfcmd
|
||||
# $device_cfg[$i][1]; # Housecode A-P
|
||||
# $device_cfg[$i][2]; # Channel 1-3
|
||||
# $device_cfg[$i][3]; # On time
|
||||
# $device_cfg[$i][4]; # Off time
|
||||
# $device_cfg[$i][5]; # Off when bright, 0 = no, 1 = yes
|
||||
# $device_cfg[$i][6]; # Off when bright delay
|
||||
# $device_cfg[$i][7]; # Time in advance when getting dark
|
||||
# $device_cfg[$i][8]; # On time random interval
|
||||
# $device_cfg[$i][9]; # Off time random interval
|
||||
# $device_cfg[$i][10]; # Rule active these days [11234567], 1=monday, ... 7=sunday.
|
||||
# $device_cfg[$i][20]; # Sunrise off time, calculated in this program and stored here
|
||||
# $device_cfg[$i][21]; # Sunset on time, calculated in this program and stored here
|
||||
# $device_cfg[$i][22]; # Switch state, 0 = off, 1 = on
|
||||
# $device_cfg[$i][23]; # Original on time
|
||||
# $device_cfg[$i][24]; # Original off time
|
||||
|
||||
sub daemonize {
|
||||
chdir '/' or die "$PROGRAM_NAME: Can't chdir to /: $!";
|
||||
open STDIN, '/dev/null' or die "$PROGRAM_NAME: Can't read /dev/null: $!";
|
||||
#open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
|
||||
#open STDERR, '>/dev/null' or die "$PROGRAM_NAME: Can't write to /dev/null: $!";
|
||||
defined(my $pid = fork) or die "$PROGRAM_NAME: Can't fork: $!";
|
||||
exit if $pid;
|
||||
setsid or die "$PROGRAM_NAME: Can't start a new session: $!";
|
||||
umask 0;
|
||||
}
|
||||
sub daemon_exit() {
|
||||
# Remove pidfile
|
||||
unlink $pidFile;
|
||||
# Since tellstickd most probably is stuck sleeping just kill ourself
|
||||
kill('TERM', $$);
|
||||
die;
|
||||
}
|
||||
sub get_sunrise_time
|
||||
{
|
||||
my $sunrise_time;
|
||||
|
||||
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
|
||||
$Year += 1900;
|
||||
|
||||
# Note, localtime returns months 0..11, Datetime->new expects months 1..12.
|
||||
my $dt = DateTime->new( year => $Year, month => $Month+1, day => $Day, time_zone => $TIMEZONE, );
|
||||
my $sunrise = DateTime::Event::Sunrise ->new( longitude => $LONGITUDE, latitude => $LATITUDE, altitude => '-0.833', iteration => '1');
|
||||
|
||||
my $dt1 = $sunrise->sunrise_datetime($dt);
|
||||
|
||||
($sunrise_time) = $dt1->datetime =~ /T(.*)\:/;
|
||||
|
||||
return $sunrise_time
|
||||
}
|
||||
|
||||
sub get_sunset_time
|
||||
{
|
||||
my $sunset_time;
|
||||
|
||||
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
|
||||
$Year += 1900;
|
||||
|
||||
# Note, localtime returns months 0..11, Datetime->new expects months 1..12.
|
||||
my $dt = DateTime->new( year => $Year, month => $Month+1, day => $Day, time_zone => $TIMEZONE, );
|
||||
my $sunrise = DateTime::Event::Sunrise ->new( longitude => $LONGITUDE, latitude => $LATITUDE, altitude => '-0.833', iteration => '1');
|
||||
|
||||
my $dt2 = $sunrise->sunset_datetime($dt);
|
||||
|
||||
($sunset_time) = $dt2->datetime =~ /T(.*)\:/;
|
||||
|
||||
return $sunset_time;
|
||||
}
|
||||
|
||||
# Checks if $current_time is inbetween argument 1 ($time1) and argument 2 ($time2)
|
||||
sub is_inbetween_times
|
||||
{
|
||||
my $time1 = $_[0];
|
||||
my $time2 = $_[1];
|
||||
my $curr_time = $_[2];
|
||||
|
||||
$curr_time =~ s/://g;
|
||||
$time1 =~ s/://g;
|
||||
$time2 =~ s/://g;
|
||||
$curr_time =~ s/^0*//;
|
||||
$time1 =~ s/^0*//;
|
||||
$time2 =~ s/^0*//;
|
||||
|
||||
# If we pass midnight, the following has to be checked/done
|
||||
if ($time2 <= $time1) {
|
||||
if ($curr_time >= $time1 && $curr_time < 2400 || $curr_time >= 0000 && $curr_time < $time2) {
|
||||
return $YES;
|
||||
}
|
||||
}
|
||||
# The following applies to the most common rules within a day.
|
||||
else {
|
||||
if ($curr_time >= $time1 && $curr_time < $time2) {
|
||||
return $YES;
|
||||
}
|
||||
}
|
||||
|
||||
return $NO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub rfcmd_exec {
|
||||
my $device_id = $_[0];
|
||||
my $action = $_[1];
|
||||
my $RFCMD_OPTIONS;
|
||||
|
||||
if ($device_cfg[$device_id][0] eq "SARTANO") {
|
||||
$RFCMD_OPTIONS = "$TELLSTICK_DEVICE $device_cfg[$device_id][0] $device_cfg[$device_id][1]";
|
||||
}
|
||||
elsif ($device_cfg[$device_id][0] eq "NEXA" || $device_cfg[$device_id][0] eq "WAVEMAN") {
|
||||
$RFCMD_OPTIONS = "$TELLSTICK_DEVICE $device_cfg[$device_id][0] $device_cfg[$device_id][1] $device_cfg[$device_id][2]";
|
||||
}
|
||||
else {
|
||||
die("$PROGRAM_NAME: Device $device_id has an unknown protocol. Only NEXA, WAVEMAN and SARTANO allowed.\n");
|
||||
}
|
||||
|
||||
|
||||
# Action = 1 means turn device on, 0 turn device off
|
||||
if ($action == 1) {
|
||||
# Only turn the device on if it is not already turned on to avoid flashing dimmers.
|
||||
# and check that it is not disabled by on/off time set to -1 in the config file
|
||||
if ($device_cfg[$device_id][22] == 0 && $device_cfg[$device_id][23] != -1) {
|
||||
printf("$PROGRAM_NAME: Time is $current_time. Switching on $device_cfg[$device_id][0] device $device_cfg[$device_id][1]$device_cfg[$device_id][2].\n");
|
||||
if ($simulate == $NO) {
|
||||
`$RFCMD $RFCMD_OPTIONS 1`;
|
||||
}
|
||||
$device_cfg[$device_id][22] = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
elsif ($action == 0) {
|
||||
if ($device_cfg[$device_id][22] == 1 && $device_cfg[$device_id][24] != -1) {
|
||||
printf("$PROGRAM_NAME: Time is $current_time. Switching off $device_cfg[$device_id][0] device $device_cfg[$device_id][1]$device_cfg[$device_id][2].\n");
|
||||
if ($simulate == $NO) {
|
||||
`$RFCMD $RFCMD_OPTIONS 0`;
|
||||
}
|
||||
$device_cfg[$device_id][22] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
# Time format xx:yy for input parameters argument1 has to be positive, argument2 can be positive or negative
|
||||
sub add_time
|
||||
{
|
||||
my $time1 = $_[0];
|
||||
my $time2 = $_[1];
|
||||
my $multiplier = 1;
|
||||
my $hour;
|
||||
my $min;
|
||||
my $time1_hour;
|
||||
my $time1_minute;
|
||||
my $time2_hour;
|
||||
my $time2_minute;
|
||||
my $time1_epoch_seconds;
|
||||
my $time2_offset_seconds;
|
||||
|
||||
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
|
||||
$Year += 1900;
|
||||
|
||||
(my $sign) = $time2 =~ /^(.*?)[0-9]/;
|
||||
($time1_hour, $time1_minute) = $time1 =~ /(.*)\:(.*)/;
|
||||
# Remove any leading signs
|
||||
$time2 =~ s/^-?//g;
|
||||
($time2_hour, $time2_minute) = $time2 =~ /(.*)\:(.*)/;
|
||||
|
||||
if ($sign eq "-") {
|
||||
$multiplier = -1;
|
||||
}
|
||||
|
||||
$time1_epoch_seconds = timelocal(0,$time1_minute,$time1_hour, $Day, $Month, $Year);
|
||||
$time2_offset_seconds = 3600*$time2_hour + 60*$time2_minute;
|
||||
|
||||
my $result_seconds = $time1_epoch_seconds + $multiplier*$time2_offset_seconds;
|
||||
|
||||
($min,$hour)= (localtime($result_seconds))[1,2];
|
||||
|
||||
return sprintf("%02d:%02d", $hour, $min);
|
||||
}
|
||||
|
||||
# Time format xx:yy for input parameters
|
||||
sub subtract_time
|
||||
{
|
||||
my $time1 = $_[0];
|
||||
my $time2 = $_[1];
|
||||
my $multiplier = 1;
|
||||
my $hour;
|
||||
my $min;
|
||||
my $time1_hour;
|
||||
my $time1_minute;
|
||||
my $time2_hour;
|
||||
my $time2_minute;
|
||||
my $time1_epoch_seconds;
|
||||
my $time2_offset_seconds;
|
||||
|
||||
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
|
||||
$Year += 1900;
|
||||
|
||||
(my $sign) = $time2 =~ /^(.*?)[0-9]/;
|
||||
($time1_hour, $time1_minute) = $time1 =~ /(.*)\:(.*)/;
|
||||
# Remove any leading signs
|
||||
$time2 =~ s/^-?//g;
|
||||
($time2_hour, $time2_minute) = $time2 =~ /(.*)\:(.*)/;
|
||||
|
||||
if ($sign eq "-") {
|
||||
$multiplier = -1;
|
||||
}
|
||||
|
||||
$time1_epoch_seconds = timelocal(0,$time1_minute,$time1_hour, $Day, $Month, $Year);
|
||||
$time2_offset_seconds = 3600*$time2_hour + 60*$time2_minute;
|
||||
|
||||
my $result_seconds = $time1_epoch_seconds - $multiplier*$time2_offset_seconds;
|
||||
|
||||
($min,$hour)= (localtime($result_seconds))[1,2];
|
||||
|
||||
return sprintf("%02d:%02d", $hour, $min);
|
||||
}
|
||||
|
||||
sub randomize_on
|
||||
{
|
||||
my $device_id = $_[0];
|
||||
|
||||
# If the on- and off times are the same, just return
|
||||
if ($device_cfg[$device_id][23] eq $device_cfg[$device_id][24]) {
|
||||
return;
|
||||
}
|
||||
|
||||
(my $random_hour, my $random_minute) = $device_cfg[$device_id][8] =~ /(.*)\:(.*)/;
|
||||
|
||||
my $rand_res = int(rand(60 * $random_hour + $random_minute));
|
||||
|
||||
my $rand_res_hour = floor($rand_res / 60);
|
||||
my $rand_res_minute = $rand_res - 60*$rand_res_hour;
|
||||
|
||||
# Here we have the random offset in format xx:yy
|
||||
my $random_time = sprintf("%02d:%02d", $rand_res_hour, $rand_res_minute);
|
||||
|
||||
$device_cfg[$device_id][3] = add_time($device_cfg[$device_id][23], $random_time);
|
||||
|
||||
if (is_inbetween_times($device_cfg[$device_id][23], $device_cfg[$device_id][24], $device_cfg[$device_id][3]) == $NO) {
|
||||
randomize_on($device_id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub randomize_off
|
||||
{
|
||||
my $device_id = $_[0];
|
||||
|
||||
# If the on- and off times are the same, just return
|
||||
if ($device_cfg[$device_id][23] eq $device_cfg[$device_id][24]) {
|
||||
return;
|
||||
}
|
||||
|
||||
(my $random_hour, my $random_minute) = $device_cfg[$device_id][9] =~ /(.*)\:(.*)/;
|
||||
|
||||
my $rand_res = int(rand(60 * $random_hour + $random_minute));
|
||||
|
||||
my $rand_res_hour = floor($rand_res / 60);
|
||||
my $rand_res_minute = $rand_res - 60*$rand_res_hour;
|
||||
|
||||
# Here we have the random offset in format xx:yy
|
||||
my $random_time = sprintf("%02d:%02d", $rand_res_hour, $rand_res_minute);
|
||||
|
||||
$device_cfg[$device_id][4] = add_time($device_cfg[$device_id][24], $random_time);
|
||||
|
||||
if (is_inbetween_times($device_cfg[$device_id][23], $device_cfg[$device_id][24], $device_cfg[$device_id][4]) == $YES) {
|
||||
randomize_off($device_id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
# Time format sanity check routine
|
||||
sub is_time_format_correct
|
||||
{
|
||||
my $time = $_[0];
|
||||
(my $hour, my $minute) = $time =~ /^-?(\d\d)\:(\d\d)$/;
|
||||
|
||||
if ($hour && $minute) {
|
||||
if ($hour >= 0 && $hour <= 23 && $minute >= 0 && $minute <= 59) {
|
||||
return $YES;
|
||||
}
|
||||
}
|
||||
|
||||
return $NO;
|
||||
}
|
||||
|
||||
|
||||
# Time format sanity check routine
|
||||
sub is_rule_valid_today
|
||||
{
|
||||
my $device_id = $_[0];
|
||||
my $now = $_[1];
|
||||
my $rule = $device_cfg[$device_id][10];
|
||||
|
||||
(my $week_rule) = $rule =~/^([e|o])/;
|
||||
if ($week_rule) {
|
||||
my $is_odd_week = ($now->week_number % 2);
|
||||
if (($is_odd_week && ($week_rule eq "e")) ||
|
||||
(!$is_odd_week && ($week_rule eq "o"))) {
|
||||
return $NO;
|
||||
}
|
||||
}
|
||||
my $day_of_week = $now->day_of_week;
|
||||
if ($rule =~ /$day_of_week/) {
|
||||
return $YES;
|
||||
}
|
||||
|
||||
return $NO;
|
||||
}
|
||||
|
||||
# Ugly hack, but we have to get the log_file option from the config file
|
||||
# before parsing the config file
|
||||
sub get_config_log_file_param
|
||||
{
|
||||
my $input_file = $_[0];
|
||||
open(CFG_FILE, "<$input_file") or die "$PROGRAM_NAME: Could not access config file: $conf_file\n";
|
||||
|
||||
while ($_ = <CFG_FILE>) {
|
||||
chomp($_);
|
||||
(my $value) = $_ =~ /^log_file\s*=\s*([a-zA-Z0-9_\/\.]*)/;
|
||||
if ($value) {
|
||||
close(CFG_FILE);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
close(CFG_FILE);
|
||||
return $NO;
|
||||
}
|
||||
|
||||
sub read_config
|
||||
{
|
||||
my $input_file = $_[0];
|
||||
my @inrad;
|
||||
my $on_interval_end;
|
||||
my $off_interval_end;
|
||||
|
||||
printf("$PROGRAM_NAME: Reading configuration file $conf_file...\n");
|
||||
|
||||
open(CFG_FILE, "<$input_file") or die "$PROGRAM_NAME: Could not access config file: $conf_file\n";
|
||||
|
||||
my $i = 0;
|
||||
my $conf_row = 0;
|
||||
while ($_ = <CFG_FILE>) {
|
||||
$conf_row++;
|
||||
if ($_ =~ /^[\#|\s|\n]/) {
|
||||
# skip lines beginning with # or space or just a new line
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
if ($_ =~ /^[NEXA|WAVEMAN|SARTANO]/ ) {
|
||||
chomp($_);
|
||||
|
||||
@inrad = split /\s+/, $_;
|
||||
$device_cfg[$i][0] = $inrad[0]; # Protocol
|
||||
$device_cfg[$i][1] = $inrad[1]; # Housecode A and channel for NEXA, WAVEMAN, channel for SARTANO.
|
||||
$device_cfg[$i][10] = $inrad[2]; # Rule valid days [[oe]1234567]
|
||||
$device_cfg[$i][22] = 1; # Initial state set to on (1) so that they will be switched off at startup
|
||||
|
||||
|
||||
if ($device_cfg[$i][0] eq "SARTANO") {
|
||||
$device_cfg[$i][2] = "";
|
||||
}
|
||||
elsif ($device_cfg[$i][0] eq "NEXA" || $device_cfg[$i][0] eq "WAVEMAN") {
|
||||
# Put the housecode and channel in the respective fields.
|
||||
(my $house_code,my $channel) = $device_cfg[$i][1] =~ /^([A-P])(\d{1,2})$/;
|
||||
if (!$house_code || !$channel || ($channel < 1) || ($channel > 16)) {
|
||||
die("$PROGRAM_NAME: Housecode/channel out of range error on row $conf_row in configuration file.\n");
|
||||
}
|
||||
$device_cfg[$i][1] = $house_code;
|
||||
$device_cfg[$i][2] = $channel;
|
||||
}
|
||||
else {
|
||||
die("$PROGRAM_NAME: Unsupported protcol: $device_cfg[$i][0]. Only NEXA, WAVEMAN or SARTANO allowed.\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# Lets find the on interval and put it into the proper fields, $device_cfg[$i][3]=On time, $device_cfg[$i][8] = On time random interval
|
||||
|
||||
if ($inrad[3] =~ /-/) {
|
||||
($device_cfg[$i][3], $on_interval_end) = $inrad[3] =~ /^(\d?\d:\d\d)-(\d?\d:\d\d)$/;
|
||||
}
|
||||
else {
|
||||
($device_cfg[$i][3]) = $inrad[3] =~ /^(\d?\d:\d\d)$/;
|
||||
$on_interval_end = $device_cfg[$i][3];
|
||||
}
|
||||
|
||||
$device_cfg[$i][8] = subtract_time($on_interval_end, $device_cfg[$i][3]);
|
||||
|
||||
|
||||
|
||||
# Off time = $device_cfg[$i][4], Off time random interval = $device_cfg[$i][9]
|
||||
if ($inrad[4] =~ /-/) {
|
||||
($device_cfg[$i][4], $off_interval_end) = $inrad[4] =~ /^(\d?\d:\d\d)-(\d?\d:\d\d)$/;
|
||||
}
|
||||
else {
|
||||
($device_cfg[$i][4]) = $inrad[4] =~ /^(\d?\d:\d\d)$/;
|
||||
$off_interval_end = $device_cfg[$i][4];
|
||||
}
|
||||
|
||||
$device_cfg[$i][9] = subtract_time($off_interval_end, $device_cfg[$i][4]);
|
||||
|
||||
|
||||
|
||||
# Save the original on and off
|
||||
$device_cfg[$i][23] = $device_cfg[$i][3]; # Original on time is stored here pos 3 will be used for random on times
|
||||
$device_cfg[$i][24] = $device_cfg[$i][4]; # Original off time is stored here pos 4 will be used for random off times
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# $inrad[5] is the off post sunrise value including sign, $inrad[6] is the on pre sunrise value sign,
|
||||
if (length($inrad[5]) > 0 && length($inrad[6]) > 0) {
|
||||
# Found a parameter after off interval, assuming daytime switch off is sought.
|
||||
$device_cfg[$i][5] = 1;
|
||||
|
||||
|
||||
# First the off post sunrise
|
||||
(my $sign, my $minutes) = $inrad[5] =~ /^([-\+]?)(.*?)$/;
|
||||
|
||||
if ($sign eq "+") {
|
||||
$sign = "";
|
||||
}
|
||||
|
||||
(my $hours) = floor($minutes / 60);
|
||||
$minutes = $minutes - $hours * 60;
|
||||
|
||||
$device_cfg[$i][6] = sprintf("%s%02d:%02d", $sign, $hours, $minutes);
|
||||
|
||||
# Then figure on pre sunset out
|
||||
(my $sign, my $minutes) = $inrad[6] =~ /^([-\+]?)(.*?)$/;
|
||||
|
||||
if ($sign eq "+") {
|
||||
$sign = "";
|
||||
}
|
||||
|
||||
(my $hours) = floor($minutes / 60);
|
||||
$minutes = $minutes - $hours * 60;
|
||||
|
||||
$device_cfg[$i][7] = sprintf("%s%02d:%02d", $sign, $hours, $minutes);
|
||||
}
|
||||
else {
|
||||
# If no parameters given after off interval it is assumed that the light will be on daytime
|
||||
$device_cfg[$i][5] = 0;
|
||||
$device_cfg[$i][6] = "00:00";
|
||||
$device_cfg[$i][7] = "00:00";
|
||||
}
|
||||
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Some sanity checks
|
||||
# If the turn on time is not to be used, this is marked with -1
|
||||
if ($device_cfg[$i][3] != -1) {
|
||||
if (is_time_format_correct($device_cfg[$i][3]) == $NO) {
|
||||
die("$PROGRAM_NAME: Format of turn on time for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] not correct: $device_cfg[$i][3]\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("$PROGRAM_NAME: Noted configuration for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] with no turn on time.\n");
|
||||
}
|
||||
|
||||
# If the turn off time is not to be used, this is marked with -1
|
||||
if ($device_cfg[$i][4] != -1) {
|
||||
if (is_time_format_correct($device_cfg[$i][4]) == $NO) {
|
||||
die("$PROGRAM_NAME: Format of turn off time for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] not correct: $device_cfg[$i][4]\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("$PROGRAM_NAME: Noted configuration for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] with no turn off time.\n");
|
||||
}
|
||||
|
||||
if (is_time_format_correct($device_cfg[$i][6]) == $NO) {
|
||||
die("$PROGRAM_NAME: Format of turn off after sunrise for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] not correct: $device_cfg[$i][6]\n");
|
||||
}
|
||||
|
||||
if (is_time_format_correct($device_cfg[$i][7]) == $NO) {
|
||||
die("$PROGRAM_NAME: Format of turn on before sunset for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] not correct. Exiting.\n");
|
||||
}
|
||||
|
||||
if (is_time_format_correct($device_cfg[$i][8]) == $NO) {
|
||||
die("$PROGRAM_NAME: Format of on interval for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] not correct: $device_cfg[$i][8]\n");
|
||||
}
|
||||
|
||||
if (is_time_format_correct($device_cfg[$i][9]) == $NO) {
|
||||
die("$PROGRAM_NAME: Format of off interval for device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] not correct: $device_cfg[$i][9]\n");
|
||||
}
|
||||
|
||||
if ($device_cfg[$i][10] =~ /^[o|e][^1-7]/) {
|
||||
die("$PROGRAM_NAME: Device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2]: Specified rule validity day out of range: $device_cfg[$i][10]\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
printf("$PROGRAM_NAME: $device_cfg[$i][0] device $device_cfg[$i][1]$device_cfg[$i][2] config:\n");
|
||||
|
||||
printf(" This rule is valid: ");
|
||||
for (my $j = 1 ; $j <= 7 ; $j++) {
|
||||
if ($device_cfg[$i][10] =~ /$j/) {
|
||||
printf(" $weekDays[$j]");
|
||||
}
|
||||
}
|
||||
if ($device_cfg[$i][10] =~ /o/) {
|
||||
printf(" (odd weeks)");
|
||||
}
|
||||
if ($device_cfg[$i][10] =~ /e/) {
|
||||
printf(" (even weeks)");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if ($device_cfg[$i][3] == -1) {
|
||||
printf(" On time: N/A\n");
|
||||
}
|
||||
else {
|
||||
printf(" On time: $device_cfg[$i][3]\n");
|
||||
}
|
||||
|
||||
if ($device_cfg[$i][4] == -1) {
|
||||
printf(" Off time: N/A\n");
|
||||
}
|
||||
else {
|
||||
printf(" Off time: $device_cfg[$i][4]\n");
|
||||
}
|
||||
|
||||
printf(" On time random interval: $device_cfg[$i][8]\n");
|
||||
printf(" Off time random interval: $device_cfg[$i][9]\n");
|
||||
|
||||
if ($device_cfg[$i][5] == $YES) {
|
||||
printf(" Turned off daytime: yes\n");
|
||||
printf(" Off post sunrise: $device_cfg[$i][6]\n");
|
||||
printf(" On pre sunset: $device_cfg[$i][7]\n");
|
||||
}
|
||||
else {
|
||||
printf(" Turned off daytime: no\n");
|
||||
}
|
||||
|
||||
$i++;
|
||||
next;
|
||||
}
|
||||
# Try to get config parameter name and value
|
||||
(my $param, my $value) = $_ =~ /\s*(\w+)\s*=\s*(-?[a-zA-Z0-9_\/\.]*)/;
|
||||
if ($param && $value) {
|
||||
printf("$PROGRAM_NAME: $param = $value\n");
|
||||
if ($param eq 'latitude') {
|
||||
if ($value !~ /^-?[0-9\.]*$/) {
|
||||
die ("$PROGRAM_NAME: Latitude must be a valid number\n");
|
||||
}
|
||||
if ($value < -90 || $value > 90) {
|
||||
die ("$PROGRAM_NAME: Latitude must be between -90 and 90 degrees\n");
|
||||
}
|
||||
$LATITUDE = $value;
|
||||
next;
|
||||
}
|
||||
if ($param eq 'longitude') {
|
||||
if ($value !~ /^-?[0-9\.]*$/) {
|
||||
die ("$PROGRAM_NAME: Longitude must be a valid number\n");
|
||||
}
|
||||
if ($value < -90 || $value > 90) {
|
||||
die ("$PROGRAM_NAME: Longitude must be between -180 and 180 degrees\n");
|
||||
}
|
||||
$LONGITUDE = $value;
|
||||
next;
|
||||
}
|
||||
if ($param eq 'timezone') {
|
||||
if (!DateTime::TimeZone->is_valid_name($value)) {
|
||||
die ("$PROGRAM_NAME: Invalid timezone\n");
|
||||
}
|
||||
$TIMEZONE = $value;
|
||||
next;
|
||||
}
|
||||
if ($param eq 'rfcmd') {
|
||||
$RFCMD = $value;
|
||||
next;
|
||||
}
|
||||
if ($param eq 'tellstick_device') {
|
||||
$TELLSTICK_DEVICE = $value;
|
||||
next;
|
||||
}
|
||||
if ($param eq 'log_file') {
|
||||
$LOG_FILE = $value;
|
||||
next;
|
||||
}
|
||||
if ($param eq 'pid_file') {
|
||||
$pidFile = $value;
|
||||
next;
|
||||
}
|
||||
die ("$PROGRAM_NAME: Unknown config parameter $param = $value\n");
|
||||
}
|
||||
else {
|
||||
die("$PROGRAM_NAME: Unknown config file line $_\n");
|
||||
}
|
||||
}
|
||||
close(CFG_FILE);
|
||||
return $i;
|
||||
}
|
||||
|
||||
sub usageprompt
|
||||
{
|
||||
printf("This program is intended for control of Tellstick remote devices.\n");
|
||||
printf("Version: %s\n", $VERSION);
|
||||
|
||||
printf("\nUsage: %s [options]\n", $PROGRAM_NAME);
|
||||
printf("\nOptions:\n");
|
||||
printf("-c, --config filename Searchpath to configuration file, if not given $CONFIG_FILE is assumed.\n");
|
||||
printf("-d, --daemon Run the program as a daemon and write a logfile.\n");
|
||||
printf("-h, --help Show this message and exit.\n");
|
||||
printf("--simulate Run in foreground, log to console, no actual device operations performed.\n");
|
||||
}
|
||||
|
||||
|
||||
# ############## Main section ######################
|
||||
my $i = -1;
|
||||
|
||||
while ($i < $#ARGV) {
|
||||
if ($i+1 <= $#ARGV) {
|
||||
if ($ARGV[$i+1] =~ /^--config$/ || $ARGV[$i+1] =~ /^-c$/) {
|
||||
$i++;
|
||||
$conf_file = $ARGV[$i+1];
|
||||
}
|
||||
elsif ($ARGV[$i+1] =~ /^-d$/ || $ARGV[$i+1] =~ /^--daemon$/) {
|
||||
$make_daemon = $YES;
|
||||
}
|
||||
elsif ($ARGV[$i+1] =~ /^-h$/ || $ARGV[$i+1] =~ /^--help$/) {
|
||||
usageprompt();
|
||||
exit;
|
||||
}
|
||||
elsif ($ARGV[$i+1] =~ /--simulate/) {
|
||||
$simulate = $YES;
|
||||
}
|
||||
else {
|
||||
die("$PROGRAM_NAME: Unknown input argument: $ARGV[$i+1]\n");
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($#ARGV < 0) {
|
||||
die "Try \"$PROGRAM_NAME --help\" for more information.\n";
|
||||
}
|
||||
|
||||
|
||||
if (length($conf_file) < 1) {
|
||||
$conf_file = $CONFIG_FILE;
|
||||
}
|
||||
$LOG_FILE = get_config_log_file_param($conf_file);
|
||||
|
||||
if ($LOG_FILE && $make_daemon && !$simulate) {
|
||||
open STDOUT, "> $LOG_FILE" or die "$PROGRAM_NAME: Can't write to $LOG_FILE: $!";
|
||||
open STDERR, ">> $LOG_FILE" or die "$PROGRAM_NAME: Can't write to $LOG_FILE: $!";
|
||||
}
|
||||
if (!$LOG_FILE && $make_daemon) {
|
||||
# start a daemon without a log file
|
||||
open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
|
||||
open STDERR, '>/dev/null' or die "$PROGRAM_NAME: Can't write to /dev/null: $!";
|
||||
}
|
||||
# Read the configuration file
|
||||
$number_of_rules = read_config($conf_file);
|
||||
|
||||
if ($number_of_rules < 1) {
|
||||
die("$PROGRAM_NAME: Configuration file has no devices to control, exiting.\n");
|
||||
}
|
||||
else {
|
||||
printf("\n$PROGRAM_NAME: $number_of_rules rule(s) has been read.\n\n");
|
||||
}
|
||||
|
||||
if ($make_daemon == $YES && $simulate == $NO) {
|
||||
&daemonize();
|
||||
open PIDFILE, ">$pidFile" or die "$PROGRAM_NAME: Can't open $pidFile: $!\n";
|
||||
print PIDFILE $$ . "\n";
|
||||
close PIDFILE;
|
||||
}
|
||||
|
||||
|
||||
printf("$PROGRAM_NAME: Starting $PROGRAM_NAME version $VERSION\n");
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Now to the eternal loop
|
||||
my $first_loop = $YES;
|
||||
my $now;
|
||||
while (1) {
|
||||
$n_rfcmd_calls = 0;
|
||||
|
||||
# What is the current time
|
||||
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime();
|
||||
$Year += 1900;
|
||||
$current_time = sprintf("%02d:%02d", $Hour, $Minute);
|
||||
$now = DateTime->now( time_zone => $TIMEZONE);
|
||||
|
||||
###################################################################################################
|
||||
|
||||
# First, lets set the sunrise and sunset times for the devices that it applies to, once a day, at 00:00.
|
||||
if ($first_loop == $YES || $current_time eq "00:00") {
|
||||
my $sunrise_time = get_sunrise_time();
|
||||
printf("$PROGRAM_NAME: Recalculating sunrise/sunset. Current date: %d-%02d-%02d\n", $Year, $Month + 1, $Day);
|
||||
printf("$PROGRAM_NAME: Time is $current_time. Sunrise today is expected at $sunrise_time\n");
|
||||
|
||||
my $sunset_time = get_sunset_time();
|
||||
printf("$PROGRAM_NAME: Time is $current_time. Sunset today is expected at $sunset_time\n\n");
|
||||
|
||||
for (my $i = 0; $i < $number_of_rules; $i++) {
|
||||
# Initially all devices are switched off to get a known state
|
||||
if ($first_loop == $YES) {
|
||||
rfcmd_exec($i, 0);
|
||||
}
|
||||
|
||||
# Lets set the actual on- and offtimes depending on random interval settings.
|
||||
randomize_on($i);
|
||||
if (is_rule_valid_today($i, $now) == $YES) {
|
||||
printf("$PROGRAM_NAME: Today device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] will be turned on $device_cfg[$i][3]\n");
|
||||
}
|
||||
randomize_off($i);
|
||||
if (is_rule_valid_today($i, $now) == $YES) {
|
||||
printf("$PROGRAM_NAME: Today device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] will be turned off $device_cfg[$i][4]\n");
|
||||
}
|
||||
|
||||
# If the device is supposed to be off daytime, the following applies
|
||||
# Sunrise time + requested offset
|
||||
if ($device_cfg[$i][5] == $YES) {
|
||||
$device_cfg[$i][20] = add_time($sunrise_time, $device_cfg[$i][6]);
|
||||
if (is_rule_valid_today($i, $now) == $YES) {
|
||||
printf("$PROGRAM_NAME: Device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] sunrise off time set to $device_cfg[$i][20].\n");
|
||||
}
|
||||
# Sunset time - requested offset
|
||||
$device_cfg[$i][21] = subtract_time($sunset_time, $device_cfg[$i][7]);
|
||||
if (is_rule_valid_today($i, $now) == $YES) {
|
||||
printf("$PROGRAM_NAME: Device $device_cfg[$i][0] $device_cfg[$i][1]$device_cfg[$i][2] sunset on time set to $device_cfg[$i][21].\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###################################################################################################
|
||||
|
||||
# Below the required actions are performed for each device
|
||||
for ($i = 0; $i < $number_of_rules; $i++) {
|
||||
|
||||
|
||||
# Lets check if the rule is to be applied today
|
||||
if (is_rule_valid_today($i, $now) == $YES) {
|
||||
|
||||
|
||||
|
||||
# First if we consider daytime off
|
||||
if ($device_cfg[$i][5] == $YES) {
|
||||
if (is_inbetween_times($device_cfg[$i][3], $device_cfg[$i][4], $current_time) == $YES && is_inbetween_times($device_cfg[$i][20], $device_cfg[$i][21], $current_time) == $NO) {
|
||||
rfcmd_exec($i, 1);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
else {
|
||||
rfcmd_exec($i, 0);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Then if daytime off is not considered
|
||||
else {
|
||||
if (is_inbetween_times($device_cfg[$i][3], $device_cfg[$i][4], $current_time) == $YES) {
|
||||
rfcmd_exec($i, 1);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
else {
|
||||
rfcmd_exec($i, 0);
|
||||
$n_rfcmd_calls++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$first_loop = $NO;
|
||||
|
||||
if ($n_rfcmd_calls < 30) {
|
||||
sleep(60 - 2*$n_rfcmd_calls); # Wait a while until next round [seconds]. If rfcmd has been called, reduce this figure by 2 seconds per call.
|
||||
}
|
||||
}
|
60
3rdparty/tellstickd/tellstickd.conf
vendored
60
3rdparty/tellstickd/tellstickd.conf
vendored
|
@ -1,60 +0,0 @@
|
|||
# Tellstickd file for control of remote switches with rfcmd.
|
||||
|
||||
# To be able to calculate sunrise and sunset times tellstickd needs to know your position
|
||||
# Your latitude
|
||||
latitude = 65.603
|
||||
|
||||
# Your longitude
|
||||
longitude = 22.18
|
||||
|
||||
# Your timezone
|
||||
timezone = Europe/Stockholm
|
||||
|
||||
# Where to find the rfcmd command
|
||||
rfcmd = /usr/local/bin/rfcmd
|
||||
|
||||
# The tellstick device name
|
||||
tellstick_device = /dev/tellstick
|
||||
|
||||
# Where to put the log file
|
||||
log_file = /var/log/tellstickd
|
||||
|
||||
# Where to put the pid file
|
||||
pid_file = /var/run/tellstickd.pid
|
||||
|
||||
#
|
||||
#<protocol> <housecode/channel> <valid day(s)> <on time[-end random on time]> <off time[-end random off time]> <off after sunrise in minutes> <on before sunset in minutes>
|
||||
#
|
||||
# In valid day field, days are numbered 1=Monday, 2=Tuesday, ... , 7=Sunday. I.e. 1234567 means that the rule should be active every weekday.
|
||||
# The day fields can be prefixed with "o" or "e" making the rule valid on odd or even weeks. Week numbers are
|
||||
# calculated according to ISO, with the first week of the year being the one containing 4 jan
|
||||
|
||||
# Time format xx:yy where xx is hour and yy is minute
|
||||
# Multiple definitions are possible for each device. Be aware that overlapping rules (overlapping in time) can/will cause troubles.
|
||||
#
|
||||
# Setting <on time> and <off time> the same means that the device will always be switched on.
|
||||
#
|
||||
|
||||
# Sample rules
|
||||
|
||||
|
||||
# The sample rule below will turn on the device between 06:10 and 06:20 and off between 22:00 and 23:00 monday to friday.
|
||||
# The device will be turned off daytime 10 minutes after sunrise and 15 before sunset
|
||||
SARTANO 0000000000 12345 06:10-06:20 22:00-23:00 10 15
|
||||
|
||||
# This device will be turned on between 07:34 and 07:48, turned off between 23:00 and 23:15 (every day of the week).
|
||||
# It will be turned off exactly on sunrise and off exactly on sunset.
|
||||
WAVEMAN P2 1234567 07:34-07:48 23:00-23:15 0 0
|
||||
|
||||
# This device will be turned on 07:00 off between 20:00 and 20:30 and will be on daytime on sundays.
|
||||
NEXA P3 7 07:00 20:00-20:30
|
||||
|
||||
# This device will be turned on 07:00 and off 20:00 on fridays and sundays on evenly numbered weeks
|
||||
NEXA P3 e57 07:00 20:00
|
||||
|
||||
# This device will be turned on 07:00 and off 20:00 on fridays and sundays on oddly numbered weeks
|
||||
NEXA P3 o57 07:00 20:00
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TelldusNETWrapper")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Telldus Technologies AB")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Copyright © Telldus Technologies AB 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(true)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a66028f7-b342-4dc0-9504-9e07c462ec15")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -1,816 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TelldusWrapper
|
||||
{
|
||||
public sealed class TelldusNETWrapper //don't allow inheritance
|
||||
{
|
||||
int lastEventID = 0;
|
||||
Dictionary<int, Object> callbackFunctionReferenceList = new Dictionary<int, Object>(); //this prevents errors in "unknown module" due to callback functions being garbage collected since there are no reference to them
|
||||
|
||||
//TODO
|
||||
List<Object> lista = new List<object>();
|
||||
|
||||
//Device methods
|
||||
public const int TELLSTICK_TURNON = 1;
|
||||
public const int TELLSTICK_TURNOFF = 2;
|
||||
public const int TELLSTICK_BELL = 4;
|
||||
public const int TELLSTICK_TOGGLE = 8;
|
||||
public const int TELLSTICK_DIM = 16;
|
||||
public const int TELLSTICK_LEARN = 32;
|
||||
public const int TELLSTICK_EXECUTE = 64;
|
||||
public const int TELLSTICK_UP = 128;
|
||||
public const int TELLSTICK_DOWN = 256;
|
||||
public const int TELLSTICK_STOP = 512;
|
||||
|
||||
//Error codes
|
||||
public const int TELLSTICK_SUCCESS = 0;
|
||||
public const int TELLSTICK_ERROR_NOT_FOUND = -1;
|
||||
public const int TELLSTICK_ERROR_PERMISSION_DENIED = -2;
|
||||
public const int TELLSTICK_ERROR_DEVICE_NOT_FOUND = -3;
|
||||
public const int TELLSTICK_ERROR_METHOD_NOT_SUPPORTED = -4;
|
||||
public const int TELLSTICK_ERROR_COMMUNICATION = -5;
|
||||
public const int TELLSTICK_ERROR_CONNECTING_SERVICE = -6;
|
||||
public const int TELLSTICK_ERROR_UNKNOWN_RESPONSE = -7;
|
||||
public const int TELLSTICK_ERROR_UNKNOWN = -99;
|
||||
|
||||
//Device typedef
|
||||
public const int TELLSTICK_TYPE_DEVICE = 1;
|
||||
public const int TELLSTICK_TYPE_GROUP = 2;
|
||||
public const int TELLSTICK_TYPE_SCENE = 3;
|
||||
|
||||
//Device changes
|
||||
public const int TELLSTICK_DEVICE_ADDED = 1;
|
||||
public const int TELLSTICK_DEVICE_CHANGED = 2;
|
||||
public const int TELLSTICK_DEVICE_REMOVED = 3;
|
||||
public const int TELLSTICK_DEVICE_STATE_CHANGED = 4;
|
||||
|
||||
//Change types
|
||||
public const int TELLSTICK_CHANGE_NAME = 1;
|
||||
public const int TELLSTICK_CHANGE_PROTOCOL = 2;
|
||||
public const int TELLSTICK_CHANGE_MODEL = 3;
|
||||
|
||||
//variables for event callback (e.g. turnon, turnoff)
|
||||
public delegate int EventCallbackFunction(int deviceId, int method, string data, int callbackId, Object obj);
|
||||
private struct DeviceEventFunctionContext
|
||||
{
|
||||
public EventCallbackFunction eventCallbackFunc;
|
||||
public Object context;
|
||||
public int callbackId;
|
||||
}
|
||||
Dictionary<int, DeviceEventFunctionContext> deviceEventList = new Dictionary<int, DeviceEventFunctionContext>();
|
||||
int registeredEventFunctionId = -1;
|
||||
|
||||
//variables for device event callback (e.g. change of name/protocol)
|
||||
public delegate int DeviceChangeEventCallbackFunction(int deviceId, int changeEvent, int changeType, int callbackId, Object obj);
|
||||
private struct DeviceChangeEventFunctionContext
|
||||
{
|
||||
public DeviceChangeEventCallbackFunction changeEventCallbackFunc;
|
||||
public Object context;
|
||||
public int callbackId;
|
||||
}
|
||||
Dictionary<int, DeviceChangeEventFunctionContext> deviceChangeEventList = new Dictionary<int, DeviceChangeEventFunctionContext>();
|
||||
int registeredDeviceChangeEventFunctionId = -1;
|
||||
|
||||
//variables for raw controller listening callback (e.g. Tellstick Duo receives data)
|
||||
public delegate int RawListeningCallbackFunction(string data, int controllerId, int callbackId, Object obj);
|
||||
private struct RawEventFunctionContext
|
||||
{
|
||||
public RawListeningCallbackFunction rawCallbackFunc;
|
||||
public Object context;
|
||||
public int callbackId;
|
||||
}
|
||||
Dictionary<int, RawEventFunctionContext> rawListenerList = new Dictionary<int, RawEventFunctionContext>();
|
||||
int registeredRawListenerFunctionId = -1;
|
||||
|
||||
public TelldusNETWrapper()
|
||||
{
|
||||
}
|
||||
|
||||
~TelldusNETWrapper()
|
||||
{
|
||||
//clean up
|
||||
if (registeredEventFunctionId != -1)
|
||||
{
|
||||
UnmanagedImport.tdUnregisterCallback(registeredEventFunctionId);
|
||||
}
|
||||
if (registeredDeviceChangeEventFunctionId != -1)
|
||||
{
|
||||
UnmanagedImport.tdUnregisterCallback(registeredDeviceChangeEventFunctionId);
|
||||
}
|
||||
if (registeredRawListenerFunctionId != -1)
|
||||
{
|
||||
UnmanagedImport.tdUnregisterCallback(registeredRawListenerFunctionId);
|
||||
}
|
||||
UnmanagedImport.tdClose(); //Close the library and clean up the cache it uses.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imported functions from TelldusCore.dll
|
||||
/// </summary>
|
||||
private sealed class UnmanagedImport
|
||||
{
|
||||
private UnmanagedImport() { } //cannot instantiate this class
|
||||
|
||||
#region Unmanaged Code
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdGetNumberOfDevices();
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdGetDeviceId(int value);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern char* tdGetName(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern char* tdGetProtocol(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern char* tdGetModel(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern char* tdGetDeviceParameter(int deviceId, char* name, char* defaultValue);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern bool tdSetName(int deviceId, char* name);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern bool tdSetProtocol(int deviceId, char* protocol);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern bool tdSetModel(int deviceId, char* model);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern bool tdSetDeviceParameter(int deviceId, char* name, char* value);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdAddDevice();
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern bool tdRemoveDevice(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdMethods(int deviceId, int methodsSupported);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdTurnOn(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdTurnOff(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdBell(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdDim(int deviceId, char level);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdExecute(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdUp(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdDown(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdStop(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern char* tdGetErrorString(int errorNo);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern void tdClose();
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern void tdInit();
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdRegisterDeviceEvent(Delegate deviceEventFunction, void* context);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdLastSentCommand(int deviceId, int methods);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdGetDeviceType(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdSendRawCommand(char* command, int reserved);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdRegisterRawDeviceEvent(Delegate rawListeningFunction, void* context);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdLearn(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern char* tdLastSentValue(int deviceId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern void tdReleaseString(char* value);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdUnregisterCallback(int eventId);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static unsafe extern int tdRegisterDeviceChangeEvent(Delegate deviceChangeEventFunction, void* context);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public unsafe delegate void EventFunctionDelegate(int deviceId, int method, char* data, int callbackId, void* context);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public unsafe delegate void DeviceChangeEventFunctionDelegate(int deviceId, int changeEvent, int changeType, int callbackId, void* context);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public unsafe delegate void RawListeningDelegate(char* data, int controllerId, int callbackId, void* context);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Add a new device to the global database of devices. This function must be called first before
|
||||
/// any call to tdSetName(), tdSetProtocol() and similar functions.
|
||||
/// </summary>
|
||||
/// <returns> The device id for the newly created device. If the creation fails it returnes a
|
||||
/// negative value.</returns>
|
||||
public static int tdAddDevice()
|
||||
{
|
||||
return UnmanagedImport.tdAddDevice();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends bell command to devices supporting this.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to sound the bell on</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdBell(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdBell(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close the library and clean up the cache it uses.
|
||||
/// This should be called when the library is not supposed to be used anymore.
|
||||
/// Do not use when this has been instantiated, will be closed in destructor then, only on static methods.
|
||||
/// </summary>
|
||||
public static void tdClose()
|
||||
{
|
||||
UnmanagedImport.tdClose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dims a device.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The device id to dim</param>
|
||||
/// <param name="level">The level the device should dim to. This value should be 0-255</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdDim(int deviceId, char level)
|
||||
{
|
||||
return UnmanagedImport.tdDim(deviceId, level);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send "down" command to device.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The device id to send the command to</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdDown(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdDown(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a scene action.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to perform the execute action on</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdExecute(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdExecute(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function returns the unique id of a device with a specific index.
|
||||
/// To get all the id numbers you should loop over all the devices, use tdGetNumberOfDevices() to get the number of devices
|
||||
/// </summary>
|
||||
/// <param name="order">Device index</param>
|
||||
/// <returns>Id of device at that position</returns>
|
||||
public static int tdGetDeviceId(int order)
|
||||
{
|
||||
return UnmanagedImport.tdGetDeviceId(order);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a protocol specific device parameter
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The id of the device to query</param>
|
||||
/// <param name="name">The name of the parameter to query</param>
|
||||
/// <param name="defaultValue">A defaultValue to return if the current parameter hasn't previously been set</param>
|
||||
/// <returns>Any protocol specific parameter specified by "name"</returns>
|
||||
public static unsafe string tdGetDeviceParameter(int deviceId, string name, string defaultValue)
|
||||
{
|
||||
return getString(UnmanagedImport.tdGetDeviceParameter(deviceId, stringToChar(name), stringToChar(defaultValue)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns which type the device is
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of the device</param>
|
||||
/// <returns>TELLSTICK_TYPE_DEVICE or TELLSTICK_TYPE_GROUP</returns>
|
||||
public static int tdGetDeviceType(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdGetDeviceType(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a human readable string from an error code returned from a function in telldus-core
|
||||
/// </summary>
|
||||
/// <param name="errorNo">The error code to translate</param>
|
||||
/// <returns>A string ready to show to the user.
|
||||
/// TELLSTICK_SUCCESS
|
||||
/// TELLSTICK_ERROR_NOT_FOUND
|
||||
/// TELLSTICK_ERROR_PERMISSION_DENIED
|
||||
/// TELLSTICK_ERROR_DEVICE_NOT_FOUND
|
||||
/// TELLSTICK_ERROR_METHOD_NOT_SUPPORTED
|
||||
/// TELLSTICK_ERROR_COMMUNICATION
|
||||
/// TELLSTICK_ERROR_CONNECTING_SERVICE
|
||||
/// TELLSTICK_ERROR_UNKNOWN_RESPONSE
|
||||
/// TELLSTICK_ERROR_UNKNOWN
|
||||
/// </returns>
|
||||
public static unsafe string tdGetErrorString(int errorNo)
|
||||
{
|
||||
return getString(UnmanagedImport.tdGetErrorString(errorNo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query a device for it’s name
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to query</param>
|
||||
/// <returns>The name of the device or an empty string if the device is not found</returns>
|
||||
public static unsafe string tdGetName(int deviceId)
|
||||
{
|
||||
return getString(UnmanagedImport.tdGetName(deviceId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query a device for which methods it supports. By supplying the methods you support
|
||||
/// the library could remap the methods a device support for better fit the application.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to query</param>
|
||||
/// <param name="methodsSupported">Methods that the client application supports</param>
|
||||
/// <returns>Supported (both by client application and by device) method-flags OR'ed into an integer
|
||||
/// TELLSTICK_TURNON
|
||||
/// TELLSTICK_TURNOFF
|
||||
/// TELLSTICK_BELL
|
||||
/// TELLSTICK_TOGGLE
|
||||
/// TELLSTICK_DIM
|
||||
/// TELLSTICK_EXECUTE
|
||||
/// TELLSTICK_UP
|
||||
/// TELLSTICK_DOWN
|
||||
/// TELLSTICK_EXECUTE
|
||||
/// TELLSTICK_LEARN
|
||||
/// </returns>
|
||||
public static int tdMethods(int deviceId, int methodsSupported)
|
||||
{
|
||||
return UnmanagedImport.tdMethods(deviceId, methodsSupported);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query a device for it’s model
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to query</param>
|
||||
/// <returns>The model for a device. Not all protocols use this.</returns>
|
||||
public static unsafe string tdGetModel(int deviceId)
|
||||
{
|
||||
return getString(UnmanagedImport.tdGetModel(deviceId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function returns the number of devices configured
|
||||
/// </summary>
|
||||
/// <returns>The total number of devices configured</returns>
|
||||
public static int tdGetNumberOfDevices()
|
||||
{
|
||||
return UnmanagedImport.tdGetNumberOfDevices();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query a device for it’s protocol
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to query</param>
|
||||
/// <returns>The protocol for a device.</returns>
|
||||
public static unsafe string tdGetProtocol(int deviceId)
|
||||
{
|
||||
return getString(UnmanagedImport.tdGetProtocol(deviceId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the last sent command to a specific device
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to query</param>
|
||||
/// <param name="methods">The methods supported by the client. See tdMethods() for more information.</param>
|
||||
/// <returns>The last sent command as integer, for example TELLSTICK_TURNON or TELLSTICK_TURNOFF</returns>
|
||||
public static int tdLastSentCommand(int deviceId, int methods)
|
||||
{
|
||||
return UnmanagedImport.tdLastSentCommand(deviceId, methods);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the last sent command it TELLSTICK_DIM this returns the dimmed value
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to query</param>
|
||||
/// <returns>The the value as a human readable string, for example "128" for 50%</returns>
|
||||
public static unsafe string tdLastSentValue(int deviceId)
|
||||
{
|
||||
return getString(UnmanagedImport.tdLastSentValue(deviceId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a special learn command to some devices that need a special learn-command to be used from TellStick
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to learn</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdLearn(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdLearn(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a callback event function to be called when a device event (e.g. turn on, turn off) occurs
|
||||
/// </summary>
|
||||
/// <param name="eventFunc">Callback function to be called</param>
|
||||
/// <param name="obj">Context object that will be echoed back when function is called. Only the object when the first function is registered will be used. Set to null if not used.</param>
|
||||
/// <returns>Callback event id</returns>
|
||||
public unsafe int tdRegisterDeviceEvent(EventCallbackFunction deviceEventFunc, Object obj)
|
||||
{
|
||||
int returnValue = 0;
|
||||
|
||||
if (deviceEventList.Count == 0)
|
||||
{
|
||||
//first added, register with dll too
|
||||
UnmanagedImport.EventFunctionDelegate deviceEventFunctionDelegate = new UnmanagedImport.EventFunctionDelegate(deviceEventFunction);
|
||||
|
||||
registeredEventFunctionId = UnmanagedImport.tdRegisterDeviceEvent(deviceEventFunctionDelegate, (void*)null); //context here or above?
|
||||
GC.Collect();
|
||||
callbackFunctionReferenceList.Add(registeredEventFunctionId, deviceEventFunctionDelegate);
|
||||
}
|
||||
|
||||
++lastEventID;
|
||||
returnValue = lastEventID;
|
||||
DeviceEventFunctionContext deviceEventFuncContext = new DeviceEventFunctionContext();
|
||||
deviceEventFuncContext.eventCallbackFunc = deviceEventFunc;
|
||||
deviceEventFuncContext.context = obj;
|
||||
deviceEventFuncContext.callbackId = returnValue;
|
||||
deviceEventList.Add(returnValue, deviceEventFuncContext);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a callback device change event function to be called when a device change event (e.g. change of name, device added) occurs
|
||||
/// </summary>
|
||||
/// <param name="deviceEventFunc">Callback function to be called</param>
|
||||
/// <param name="obj">Context object that will be echoed back when function is called. Only the object when the first function is registered will be used. Set to null if not used.</param>
|
||||
/// <returns>Callback event id</returns>
|
||||
public unsafe int tdRegisterDeviceChangeEvent(DeviceChangeEventCallbackFunction deviceChangeEventFunc, Object obj)
|
||||
{
|
||||
int returnValue = 0;
|
||||
if (deviceChangeEventList.Count == 0)
|
||||
{
|
||||
//first added, register with dll too
|
||||
//only the context object of the first event will be registered
|
||||
UnmanagedImport.DeviceChangeEventFunctionDelegate deviceChangeEventFunctionDelegate = new UnmanagedImport.DeviceChangeEventFunctionDelegate(deviceChangeEventFunction);
|
||||
|
||||
registeredDeviceChangeEventFunctionId = UnmanagedImport.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate, (void*)null);
|
||||
GC.Collect();
|
||||
callbackFunctionReferenceList.Add(registeredDeviceChangeEventFunctionId, deviceChangeEventFunctionDelegate);
|
||||
}
|
||||
++lastEventID;
|
||||
returnValue = lastEventID;
|
||||
DeviceChangeEventFunctionContext deviceChangeEventFuncContext = new DeviceChangeEventFunctionContext();
|
||||
deviceChangeEventFuncContext.changeEventCallbackFunc = deviceChangeEventFunc;
|
||||
deviceChangeEventFuncContext.context = obj;
|
||||
deviceChangeEventFuncContext.callbackId = returnValue;
|
||||
deviceChangeEventList.Add(returnValue, deviceChangeEventFuncContext);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a callback listening function to be called when a listening event (e.g. data is received with Tellstick Duo) occurs
|
||||
/// </summary>
|
||||
/// <param name="listeningFunc">Callback function to be called</param>
|
||||
/// <param name="obj">Context object that will be echoed back when function is called. Only the object when the first function is registered will be used. Set to null if not used.</param>
|
||||
/// <returns>Callback event id</returns>
|
||||
public unsafe int tdRegisterRawDeviceEvent(RawListeningCallbackFunction listeningFunc, Object obj)
|
||||
{
|
||||
int returnValue = 0;
|
||||
if (rawListenerList.Count == 0)
|
||||
{
|
||||
//first added, register with dll too
|
||||
//only the context object of the first event will be registered
|
||||
UnmanagedImport.RawListeningDelegate listeningFunctionDelegate = new UnmanagedImport.RawListeningDelegate(rawListeningFunction);
|
||||
|
||||
registeredRawListenerFunctionId = UnmanagedImport.tdRegisterRawDeviceEvent(listeningFunctionDelegate, (void*)null);
|
||||
GC.Collect();
|
||||
callbackFunctionReferenceList.Add(registeredRawListenerFunctionId, listeningFunctionDelegate);
|
||||
}
|
||||
++lastEventID;
|
||||
returnValue = lastEventID;
|
||||
RawEventFunctionContext rawEventFuncContext = new RawEventFunctionContext();
|
||||
rawEventFuncContext.rawCallbackFunc = listeningFunc;
|
||||
rawEventFuncContext.context = obj;
|
||||
rawEventFuncContext.callbackId = returnValue;
|
||||
rawListenerList.Add(returnValue, rawEventFuncContext);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a device.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to remove</param>
|
||||
/// <returns>True on success, false otherwise</returns>
|
||||
public static bool tdRemoveDevice(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdRemoveDevice(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a raw command to TellStick. Please read the TellStick protocol definition on how the command should be constructed.
|
||||
/// </summary>
|
||||
/// <param name="command">The command for TellStick in its native format</param>
|
||||
/// <param name="reserved"></param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static unsafe int tdSendRawCommand(string command, int reserved)
|
||||
{
|
||||
char* commandChar = stringToChar(command);
|
||||
int returnValue = UnmanagedImport.tdSendRawCommand(commandChar, reserved);
|
||||
Marshal.FreeHGlobal((IntPtr)commandChar);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new protocol specific parameter. Please see the documentation of the protocols before setting any parameter.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to change</param>
|
||||
/// <param name="name">The name of the parameter to change</param>
|
||||
/// <param name="value">The new value for the parameter</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static unsafe bool tdSetDeviceParameter(int deviceId, string name, string value)
|
||||
{
|
||||
char* nameChar = stringToChar(name);
|
||||
char* valueChar = stringToChar(value);
|
||||
bool returnValue = UnmanagedImport.tdSetDeviceParameter(deviceId, nameChar, valueChar);
|
||||
Marshal.FreeHGlobal((IntPtr)nameChar);
|
||||
Marshal.FreeHGlobal((IntPtr)valueChar);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new model for a device. Which model to set depends on the current protocol.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to change</param>
|
||||
/// <param name="model">The new model</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static unsafe bool tdSetModel(int deviceId, string model)
|
||||
{
|
||||
char* modelChar = stringToChar(model);
|
||||
bool returnValue = UnmanagedImport.tdSetModel(deviceId, modelChar);
|
||||
Marshal.FreeHGlobal((IntPtr)modelChar);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new name for a device.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to change</param>
|
||||
/// <param name="name">The new name</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static unsafe bool tdSetName(int deviceId, string name)
|
||||
{
|
||||
char* nameChar = stringToChar(name);
|
||||
bool returnValue = UnmanagedImport.tdSetName(deviceId, nameChar);
|
||||
Marshal.FreeHGlobal((IntPtr)nameChar);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This changes the current protocol used by a device. After changing the protocol, setting new parameters is required.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to change</param>
|
||||
/// <param name="protocol">The new protocol to use</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static unsafe bool tdSetProtocol(int deviceId, string protocol)
|
||||
{
|
||||
char* protocolChar = stringToChar(protocol);
|
||||
bool returnValue = UnmanagedImport.tdSetProtocol(deviceId, protocolChar);
|
||||
Marshal.FreeHGlobal((IntPtr)protocolChar);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send "stop" command to device.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The device id to stop</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdStop(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdStop(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns a device on.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to turn on</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdTurnOn(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdTurnOn(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns a device off.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of device to turn off</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdTurnOff(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdTurnOff(deviceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister a callback function. All functions will be unregistered automatically when this objekt is deleted.
|
||||
/// </summary>
|
||||
/// <param name="eventId">Id of callback even to unregister</param>
|
||||
public void unregisterCallback(int eventId)
|
||||
{
|
||||
deviceEventList.Remove(eventId);
|
||||
if (deviceEventList.Count == 0)
|
||||
{
|
||||
//no more events in list
|
||||
UnmanagedImport.tdUnregisterCallback(registeredEventFunctionId);
|
||||
callbackFunctionReferenceList.Remove(registeredEventFunctionId);
|
||||
/*
|
||||
if (eventContextHandle.IsAllocated)
|
||||
{
|
||||
eventContextHandle.Free();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
deviceChangeEventList.Remove(eventId);
|
||||
if (deviceChangeEventList.Count == 0)
|
||||
{
|
||||
//no more events in list
|
||||
UnmanagedImport.tdUnregisterCallback(registeredDeviceChangeEventFunctionId);
|
||||
callbackFunctionReferenceList.Remove(registeredDeviceChangeEventFunctionId);
|
||||
}
|
||||
|
||||
rawListenerList.Remove(eventId);
|
||||
if (rawListenerList.Count == 0)
|
||||
{
|
||||
//no more events in list
|
||||
UnmanagedImport.tdUnregisterCallback(registeredRawListenerFunctionId);
|
||||
callbackFunctionReferenceList.Remove(registeredRawListenerFunctionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send "up" command to device.
|
||||
/// Make sure the device supports this by calling tdMethods() before any calls to this function.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The device id to send the command to</param>
|
||||
/// <returns>Success or error code</returns>
|
||||
public static int tdUp(int deviceId)
|
||||
{
|
||||
return UnmanagedImport.tdUp(deviceId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Convert char* to correctly encoded string, clean up received char*
|
||||
/// </summary>
|
||||
/// <param name="input">Char* to convert</param>
|
||||
/// <returns>Converted string</returns>
|
||||
private static unsafe string getString(char* input)
|
||||
{
|
||||
return getString(input, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert char* to correctly encoded string, clean up of received char* is optional
|
||||
/// </summary>
|
||||
/// <param name="input">Char* to convert</param>
|
||||
/// <param name="release">Clean up char* or not (don't do that if it is still should be used somewhere)</param>
|
||||
/// <returns>Converted string</returns>
|
||||
private static unsafe string getString(char* input, bool release)
|
||||
{
|
||||
string returnString = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(input)));
|
||||
|
||||
if (returnString.Contains("\0"))
|
||||
{
|
||||
returnString = returnString.Substring(0, returnString.IndexOf('\0'));
|
||||
}
|
||||
|
||||
if (release)
|
||||
{
|
||||
UnmanagedImport.tdReleaseString(input);
|
||||
}
|
||||
GC.Collect();
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert string to correctly encoded char*
|
||||
/// </summary>
|
||||
/// <param name="input">String to convert</param>
|
||||
/// <returns>Converted char*</returns>
|
||||
private static unsafe char* stringToChar(string input)
|
||||
{
|
||||
input = String.Concat(input, char.MinValue); //add null terminator
|
||||
byte[] inputByte = System.Text.Encoding.UTF8.GetBytes(input);
|
||||
int size = Marshal.SystemDefaultCharSize * inputByte.Length;
|
||||
IntPtr inputPointer = Marshal.AllocHGlobal(size);
|
||||
|
||||
Marshal.Copy(inputByte, 0, inputPointer, inputByte.Length);
|
||||
return (char*)inputPointer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event function wrapper that will call all registered event functions with C#-arguments when
|
||||
/// this event function is called from telldus core, with C++-style arguments. This function will
|
||||
/// be registered with telldus core when the first event callback function is added.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of affected device</param>
|
||||
/// <param name="method">Method that was executed on device</param>
|
||||
/// <param name="data">Optional data that was sent to the method (e.g. dim value)</param>
|
||||
/// <param name="callbackId">Callback event id</param>
|
||||
/// <param name="context">Context (optional)</param>
|
||||
/// <returns>0</returns>
|
||||
private unsafe void deviceEventFunction(int deviceId, int method, char* data, int callbackId, void* context)
|
||||
{
|
||||
foreach (DeviceEventFunctionContext deviceEventFuncContext in deviceEventList.Values)
|
||||
{
|
||||
deviceEventFuncContext.eventCallbackFunc(deviceId, method, getString(data, false), deviceEventFuncContext.callbackId, deviceEventFuncContext.context);
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Event function wrapper that will call all registered device change event functions with C#-arguments when
|
||||
/// this device change event function is called from telldus core, with C++-style arguments. This function will
|
||||
/// be registered with telldus core when the first device change event callback function is added.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Id of affected device</param>
|
||||
/// <param name="changeEvent">Method that was executed, TELLSTICK_DEVICE_ADDED, TELLSTICK_DEVICE_CHANGED, TELLSTICK_DEVICE_REMOVED, TELLSTICK_DEVICE_STATE_CHANGED</param>
|
||||
/// <param name="changeType">Type of change TELLSTICK_CHANGE_NAME, TELLSTICK_CHANGE_PROTOCOL, TELLSTICK_CHANGE_MODEL</param>
|
||||
/// <param name="callbackId">Callback event id</param>
|
||||
/// <param name="context">Context (optional)</param>
|
||||
/// <returns>0</returns>
|
||||
private unsafe void deviceChangeEventFunction(int deviceId, int changeEvent, int changeType, int callbackId, void* context)
|
||||
{
|
||||
foreach (DeviceChangeEventFunctionContext deviceChangeEventFuncContext in deviceChangeEventList.Values)
|
||||
{
|
||||
deviceChangeEventFuncContext.changeEventCallbackFunc(deviceId, changeEvent, changeType, deviceChangeEventFuncContext.callbackId, deviceChangeEventFuncContext.context);
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event function wrapper that will call all registered listening functions with C#-arguments when
|
||||
/// this listening function is called from telldus core, with C++-style arguments. This function will
|
||||
/// be registered with telldus core when the first listening callback function is added.
|
||||
/// </summary>
|
||||
/// <param name="data">Received data</param>
|
||||
/// <param name="controllerId">Id of receiving controller</param>
|
||||
/// <param name="callbackId">Callback event id</param>
|
||||
/// <param name="context">Context (optional)</param>
|
||||
/// <returns>0</returns>
|
||||
private unsafe void rawListeningFunction(char* data, int controllerId, int callbackId, void* context)
|
||||
{
|
||||
foreach (RawEventFunctionContext rawListeningFuncContext in rawListenerList.Values)
|
||||
{
|
||||
rawListeningFuncContext.rawCallbackFunc(getString(data, false), controllerId, rawListeningFuncContext.callbackId, rawListeningFuncContext.context);
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{675C494F-7D3B-4F6F-AB7A-98BA9E2B2B43}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TelldusNETWrapper</RootNamespace>
|
||||
<AssemblyName>TelldusNETWrapper</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkSubset>
|
||||
</TargetFrameworkSubset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TelldusNETWrapper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TelldusNETWrapper", "TelldusNETWrapper.csproj", "{675C494F-7D3B-4F6F-AB7A-98BA9E2B2B43}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{675C494F-7D3B-4F6F-AB7A-98BA9E2B2B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{675C494F-7D3B-4F6F-AB7A-98BA9E2B2B43}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{675C494F-7D3B-4F6F-AB7A-98BA9E2B2B43}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{675C494F-7D3B-4F6F-AB7A-98BA9E2B2B43}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Binary file not shown.
|
@ -1,3 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
|
Binary file not shown.
Binary file not shown.
|
@ -1,98 +0,0 @@
|
|||
import java.io.*;
|
||||
|
||||
class test
|
||||
{
|
||||
tellstick TS = new tellstick();
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
int nbrDevices = TS.devGetNumberOfDevices();
|
||||
for (int i = 0; i < nbrDevices; i++) {
|
||||
int id = TS.devGetDeviceId(i);
|
||||
String deviceName = TS.devGetName(id);
|
||||
System.out.println(id + "\t" + deviceName);
|
||||
}
|
||||
|
||||
System.out.print("Enter a device: ");
|
||||
int device = Integer.parseInt(in.readLine());
|
||||
process(device);
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void process(int device) {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
int methods = TS.devMethods(device);
|
||||
if ((methods & TS.TELLSTICK_TURNON) > 0) {
|
||||
System.out.println(TS.TELLSTICK_TURNON + "\tTurn on");
|
||||
}
|
||||
if ((methods & TS.TELLSTICK_TURNOFF) > 0) {
|
||||
System.out.println(TS.TELLSTICK_TURNOFF + "\tTurn off");
|
||||
}
|
||||
if ((methods & TS.TELLSTICK_BELL) > 0) {
|
||||
System.out.println(TS.TELLSTICK_BELL + "\tBell");
|
||||
}
|
||||
if ((methods & TS.TELLSTICK_DIM) > 0) {
|
||||
System.out.println(TS.TELLSTICK_DIM + "\tDim");
|
||||
}
|
||||
System.out.println("What do you want to do?");
|
||||
int action = Integer.parseInt(in.readLine());
|
||||
if ( (action & methods) == 0 ) {
|
||||
System.out.println("The device doesn't support this method");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((action & TS.TELLSTICK_TURNON) > 0) {
|
||||
turnOn(device);
|
||||
} else if ((action & TS.TELLSTICK_TURNOFF) > 0) {
|
||||
turnOff(device);
|
||||
} else if ((action & TS.TELLSTICK_BELL) > 0) {
|
||||
bell(device);
|
||||
} else if ((action & TS.TELLSTICK_DIM) > 0) {
|
||||
dim(device);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void turnOn(int device) {
|
||||
System.out.println("Turning on " + TS.devGetName(device));
|
||||
TS.devTurnOn(device);
|
||||
}
|
||||
|
||||
private void turnOff(int device) {
|
||||
System.out.println("Turning off " + TS.devGetName(device));
|
||||
TS.devTurnOff(device);
|
||||
}
|
||||
|
||||
private void bell(int device) {
|
||||
System.out.println("Sending bell to " + TS.devGetName(device));
|
||||
TS.devBell(device);
|
||||
}
|
||||
|
||||
private void dim(int device) {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
System.out.print("Select level (0-255): ");
|
||||
int level = Integer.parseInt(in.readLine());
|
||||
if (level >= 256 || level < 0) {
|
||||
System.out.println("Out of range");
|
||||
}
|
||||
System.out.println("Dim " + TS.devGetName(device));
|
||||
TS.devDim(device, level);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
test t = new test();
|
||||
t.run();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*tellstick.c*/
|
||||
#include "tellstick.h"
|
||||
#include <stdio.h>
|
||||
#include <TellUsbD101.h>
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_tellstick_devTurnOn(JNIEnv *, jobject, jint intDeviceId)
|
||||
{
|
||||
return (jboolean) devTurnOn( (int)intDeviceId);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_tellstick_devTurnOff(JNIEnv *, jobject, jint intDeviceId)
|
||||
{
|
||||
return (jboolean) devTurnOff( (int)intDeviceId);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_tellstick_devBell(JNIEnv *, jobject, jint intDeviceId)
|
||||
{
|
||||
return (jboolean) devBell( (int)intDeviceId);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_tellstick_devDim(JNIEnv *, jobject, jint intDeviceId, jint level)
|
||||
{
|
||||
return (jboolean) devDim( (int)intDeviceId, (unsigned char) level);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_tellstick_devMethods(JNIEnv *, jobject, jint intDeviceId)
|
||||
{
|
||||
return (jint) devMethods( (int)intDeviceId );
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_tellstick_devGetNumberOfDevices(JNIEnv *, jobject)
|
||||
{
|
||||
return (jint)devGetNumberOfDevices();
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_tellstick_devGetDeviceId(JNIEnv *, jobject, jint intDeviceIndex)
|
||||
{
|
||||
return (jint)devGetDeviceId( (int)intDeviceIndex );
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_tellstick_devGetName(JNIEnv *env, jobject, jint intDeviceId)
|
||||
{
|
||||
const char *name = devGetName( (int)intDeviceId );
|
||||
return env->NewStringUTF(name);
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class tellstick */
|
||||
|
||||
#ifndef _Included_tellstick
|
||||
#define _Included_tellstick
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devTurnOn
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_tellstick_devTurnOn
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devTurnOff
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_tellstick_devTurnOff
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devBell
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_tellstick_devBell
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devDim
|
||||
* Signature: (II)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_tellstick_devDim
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devMethods
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_tellstick_devMethods
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devGetNumberOfDevices
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_tellstick_devGetNumberOfDevices
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devGetDeviceId
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_tellstick_devGetDeviceId
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: tellstick
|
||||
* Method: devGetName
|
||||
* Signature: (I)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_tellstick_devGetName
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,27 +0,0 @@
|
|||
//firstJNI.java
|
||||
|
||||
public class tellstick
|
||||
{
|
||||
public final int TELLSTICK_TURNON = 1;
|
||||
public final int TELLSTICK_TURNOFF = 2;
|
||||
public final int TELLSTICK_BELL = 4;
|
||||
public final int TELLSTICK_DIM = 16;
|
||||
|
||||
public native boolean devTurnOn(int intDeviceId);
|
||||
public native boolean devTurnOff(int intDeviceId);
|
||||
public native boolean devBell(int intDeviceId);
|
||||
public native boolean devDim(int intDeviceId, int level);
|
||||
public native int devMethods(int intDeviceId);
|
||||
|
||||
public native int devGetNumberOfDevices();
|
||||
public native int devGetDeviceId(int intDeviceIndex);
|
||||
|
||||
public native String devGetName(int intDeviceId);
|
||||
|
||||
static {
|
||||
System.loadLibrary("tellstickJNI");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
PHP_ARG_ENABLE(telldus, whether to enable Telldus TellStick support,
|
||||
[ --enable-telldus Enable Telldus TellStick support])
|
||||
|
||||
if test "$PHP_TELLDUS" = "yes"; then
|
||||
AC_DEFINE(HAVE_TELLDUS, 1, [Whether you have Telldus TellStick])
|
||||
|
||||
SEARCH_PATH="/usr/local /usr"
|
||||
SEARCH_FOR="/include/telldus-core.h"
|
||||
if test -r $PHP_TELLDUS/; then # path given as parameter
|
||||
TELLDUS_DIR=$PHP_TELLDUS
|
||||
else # search default path list
|
||||
AC_MSG_CHECKING([for telldus files in default path])
|
||||
for i in $SEARCH_PATH ; do
|
||||
if test -r $i/$SEARCH_FOR; then
|
||||
TELLDUS_DIR=$i
|
||||
AC_MSG_RESULT(found in $i)
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if test -z "$TELLDUS_DIR"; then
|
||||
AC_MSG_RESULT([not found])
|
||||
AC_MSG_ERROR([Please reinstall the telldus-core distribution])
|
||||
fi
|
||||
# --enable-telldus -> add include path
|
||||
PHP_ADD_INCLUDE($TELLDUS_DIR/include)
|
||||
# --enable-telldus -> check for lib and symbol presence
|
||||
LIBNAME=telldus-core
|
||||
LIBSYMBOL=tdGetNumberOfDevices
|
||||
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
|
||||
[
|
||||
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TELLDUS_DIR/lib, TELLDUS_SHARED_LIBADD)
|
||||
AC_DEFINE(HAVE_TELLDUSLIB,1,[ ])
|
||||
],[
|
||||
AC_MSG_ERROR([wrong telldus lib version or lib not found])
|
||||
],[
|
||||
-L$TELLDUS_DIR/lib -lm
|
||||
])
|
||||
PHP_SUBST(TELLDUS_SHARED_LIBADD)
|
||||
|
||||
PHP_NEW_EXTENSION(telldus, telldus.c, $ext_shared)
|
||||
fi
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
if(!extension_loaded('telldus')) {
|
||||
dl('telldus.' . PHP_SHLIB_SUFFIX);
|
||||
}
|
||||
|
||||
$devices = tdGetNumberOfDevices();
|
||||
printf("Devices: %d\n", $devices);
|
||||
|
||||
$allMethods = TELLDUS_TURNON | TELLDUS_TURNOFF | TELLDUS_BELL | TELLDUS_DIM;
|
||||
|
||||
for( $i = 0; $i < $devices; ++$i ) {
|
||||
$id = tdGetDeviceId( $i );
|
||||
$name = utf8_encode(tdGetName( $id ));
|
||||
printf("%s - %s\n", $id, $name);
|
||||
|
||||
$methods = tdMethods( $id, $allMethods );
|
||||
if ($methods & TELLDUS_TURNON) {
|
||||
echo " * TurnOn\n";
|
||||
tdTurnOn( $id );
|
||||
sleep(1);
|
||||
}
|
||||
if ($methods & TELLDUS_TURNOFF) {
|
||||
echo " * TurnOff\n";
|
||||
tdTurnOff( $id );
|
||||
sleep(1);
|
||||
}
|
||||
if ($methods & TELLDUS_BELL) {
|
||||
echo " * Bell\n";
|
||||
tdBell( $id );
|
||||
sleep(1);
|
||||
}
|
||||
if ($methods & TELLDUS_TOGGLE) {
|
||||
echo " * Toggle\n";
|
||||
}
|
||||
if ($methods & TELLDUS_DIM) {
|
||||
echo " * Dim\n";
|
||||
tdDim( $id, 128 );
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef PHP_TELLDUS_H
|
||||
#define PHP_TELLDUS_H 1
|
||||
|
||||
#define PHP_TELLDUS_VERSION "2.0.2"
|
||||
#define PHP_TELLDUS_EXTNAME "telldus"
|
||||
|
||||
PHP_MINIT_FUNCTION(telldus);
|
||||
PHP_MSHUTDOWN_FUNCTION(telldus);
|
||||
PHP_RINIT_FUNCTION(telldus);
|
||||
|
||||
PHP_FUNCTION(tdInit);
|
||||
PHP_FUNCTION(tdClose);
|
||||
|
||||
PHP_FUNCTION(tdTurnOn);
|
||||
PHP_FUNCTION(tdTurnOff);
|
||||
PHP_FUNCTION(tdBell);
|
||||
PHP_FUNCTION(tdDim);
|
||||
PHP_FUNCTION(tdLearn);
|
||||
PHP_FUNCTION(tdMethods);
|
||||
PHP_FUNCTION(tdLastSentCommand);
|
||||
PHP_FUNCTION(tdLastSentValue);
|
||||
|
||||
PHP_FUNCTION(tdGetNumberOfDevices);
|
||||
PHP_FUNCTION(tdGetDeviceId);
|
||||
PHP_FUNCTION(tdGetDeviceType);
|
||||
|
||||
PHP_FUNCTION(tdGetErrorString);
|
||||
|
||||
PHP_FUNCTION(tdGetName);
|
||||
PHP_FUNCTION(tdSetName);
|
||||
PHP_FUNCTION(tdGetProtocol);
|
||||
PHP_FUNCTION(tdSetProtocol);
|
||||
PHP_FUNCTION(tdGetModel);
|
||||
PHP_FUNCTION(tdSetModel);
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceParameter);
|
||||
PHP_FUNCTION(tdSetDeviceParameter);
|
||||
|
||||
PHP_FUNCTION(tdAddDevice);
|
||||
PHP_FUNCTION(tdRemoveDevice);
|
||||
|
||||
PHP_FUNCTION(tdSendRawCommand);
|
||||
|
||||
extern zend_module_entry telldus_module_entry;
|
||||
#define phpext_telldus_ptr &telldus_module_entry
|
||||
|
||||
#endif
|
|
@ -1,401 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "php_telldus.h"
|
||||
#include <telldus-core.h>
|
||||
|
||||
|
||||
static function_entry telldus_functions[] = {
|
||||
PHP_FE(tdInit, NULL)
|
||||
PHP_FE(tdClose, NULL)
|
||||
|
||||
PHP_FE(tdTurnOn, NULL)
|
||||
PHP_FE(tdTurnOff, NULL)
|
||||
PHP_FE(tdBell, NULL)
|
||||
PHP_FE(tdDim, NULL)
|
||||
PHP_FE(tdLearn, NULL)
|
||||
PHP_FE(tdMethods, NULL)
|
||||
PHP_FE(tdLastSentCommand, NULL)
|
||||
PHP_FE(tdLastSentValue, NULL)
|
||||
|
||||
PHP_FE(tdGetNumberOfDevices, NULL)
|
||||
PHP_FE(tdGetDeviceId, NULL)
|
||||
PHP_FE(tdGetDeviceType, NULL)
|
||||
|
||||
PHP_FE(tdGetErrorString, NULL)
|
||||
|
||||
PHP_FE(tdGetName, NULL)
|
||||
PHP_FE(tdSetName, NULL)
|
||||
PHP_FE(tdGetProtocol, NULL)
|
||||
PHP_FE(tdSetProtocol, NULL)
|
||||
PHP_FE(tdGetModel, NULL)
|
||||
PHP_FE(tdSetModel, NULL)
|
||||
|
||||
PHP_FE(tdGetDeviceParameter, NULL)
|
||||
PHP_FE(tdSetDeviceParameter, NULL)
|
||||
|
||||
PHP_FE(tdAddDevice, NULL)
|
||||
PHP_FE(tdRemoveDevice, NULL)
|
||||
|
||||
PHP_FE(tdSendRawCommand, NULL)
|
||||
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
zend_module_entry telldus_module_entry = {
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
STANDARD_MODULE_HEADER,
|
||||
#endif
|
||||
PHP_TELLDUS_EXTNAME,
|
||||
telldus_functions,
|
||||
PHP_MINIT(telldus),
|
||||
PHP_MSHUTDOWN(telldus),
|
||||
PHP_RINIT(telldus),
|
||||
NULL,
|
||||
NULL,
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
PHP_TELLDUS_VERSION,
|
||||
#endif
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
|
||||
#ifdef COMPILE_DL_TELLDUS
|
||||
ZEND_GET_MODULE(telldus)
|
||||
#endif
|
||||
|
||||
|
||||
PHP_RINIT_FUNCTION(telldus)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_MINIT_FUNCTION(telldus)
|
||||
{
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TURNON", TELLSTICK_TURNON, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TURNOFF", TELLSTICK_TURNOFF, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_BELL", TELLSTICK_BELL, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TOGGLE", TELLSTICK_TOGGLE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_DIM", TELLSTICK_DIM, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_LEARN", TELLSTICK_LEARN, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_SUCCESS", TELLSTICK_SUCCESS, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_NOT_FOUND", TELLSTICK_ERROR_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_PERMISSION_DENIED", TELLSTICK_ERROR_PERMISSION_DENIED, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_DEVICE_NOT_FOUND", TELLSTICK_ERROR_DEVICE_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_METHOD_NOT_SUPPORTED", TELLSTICK_ERROR_METHOD_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_COMMUNICATION", TELLSTICK_ERROR_COMMUNICATION, CONST_CS | CONST_PERSISTENT);
|
||||
//REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_CONNECTING_SERVICE", TELLSTICK_ERROR_CONNECTING_SERVICE, CONST_CS | CONST_PERSISTENT);
|
||||
//REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_UNKNOWN_RESPONSE", TELLSTICK_ERROR_UNKNOWN_RESPONSE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_ERROR_UNKNOWN", TELLSTICK_ERROR_UNKNOWN, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TYPE_DEVICE", TELLSTICK_TYPE_DEVICE, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("TELLSTICK_TYPE_GROUP", TELLSTICK_TYPE_GROUP, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_MSHUTDOWN_FUNCTION(telldus)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdInit)
|
||||
{
|
||||
tdInit();
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdClose)
|
||||
{
|
||||
tdClose();
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdTurnOn)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdTurnOn( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdTurnOff)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdTurnOff( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdBell)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdBell( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdDim)
|
||||
{
|
||||
long id;
|
||||
long level;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &id, &level) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
if (level < 0 || level > 255) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdDim( id, level ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdLearn)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdLearn( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdMethods)
|
||||
{
|
||||
long id;
|
||||
long supportedMethods;
|
||||
long methods;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &id, &supportedMethods) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
methods = tdMethods( id, supportedMethods );
|
||||
RETURN_LONG(methods);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdLastSentCommand)
|
||||
{
|
||||
long id;
|
||||
long supportedMethods;
|
||||
long command;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &id, &supportedMethods) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
command = tdLastSentCommand( id, supportedMethods );
|
||||
RETURN_LONG(command);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdLastSentValue)
|
||||
{
|
||||
long id;
|
||||
char *value, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
value = tdLastSentValue( id );
|
||||
retval = estrdup(value);
|
||||
tdReleaseString(value);
|
||||
RETURN_STRING(retval, 0);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetNumberOfDevices)
|
||||
{
|
||||
int nbr = tdGetNumberOfDevices();
|
||||
RETURN_LONG(nbr);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceId)
|
||||
{
|
||||
long index;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
|
||||
RETURN_LONG(0);
|
||||
}
|
||||
|
||||
RETURN_LONG( tdGetDeviceId( index ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceType)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_LONG(0);
|
||||
}
|
||||
|
||||
RETURN_LONG( tdGetDeviceType( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetErrorString)
|
||||
{
|
||||
long errorNo;
|
||||
char *errorString, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &errorNo) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
errorString = tdGetErrorString( errorNo );
|
||||
retval = estrdup(errorString);
|
||||
tdReleaseString(errorString);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetName)
|
||||
{
|
||||
long id;
|
||||
char *name, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
name = tdGetName( id );
|
||||
retval = estrdup(name);
|
||||
tdReleaseString(name);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetName)
|
||||
{
|
||||
long id;
|
||||
char *name;
|
||||
int nameLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &id, &name, &nameLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetName( id, name ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetProtocol)
|
||||
{
|
||||
long id;
|
||||
char *protocol, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
protocol = tdGetProtocol( id );
|
||||
retval = estrdup(protocol);
|
||||
tdReleaseString(protocol);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetProtocol)
|
||||
{
|
||||
long id;
|
||||
char *protocol;
|
||||
int protocolLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &id, &protocol, &protocolLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetProtocol( id, protocol ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetModel)
|
||||
{
|
||||
long id;
|
||||
char *model, *retval;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
model = tdGetModel( id );
|
||||
retval = estrdup(model);
|
||||
tdReleaseString(model);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetModel)
|
||||
{
|
||||
long id;
|
||||
char *model;
|
||||
int modelLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &id, &model, &modelLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetModel( id, model ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdGetDeviceParameter)
|
||||
{
|
||||
long id;
|
||||
char *param, *name, *defaultValue, *retval;
|
||||
int nameLen, defaultValueLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &id, &name, &nameLen, &defaultValue, &defaultValueLen) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
param = tdGetDeviceParameter( id, name, defaultValue );
|
||||
retval = estrdup(param);
|
||||
tdReleaseString(param);
|
||||
RETURN_STRING( retval, 0 );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSetDeviceParameter)
|
||||
{
|
||||
long id;
|
||||
char *name, *value;
|
||||
int nameLen, valueLen;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &id, &name, &nameLen, &value, &valueLen) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL( tdSetDeviceParameter( id, name, value ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdAddDevice)
|
||||
{
|
||||
RETURN_LONG(tdAddDevice());
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdRemoveDevice)
|
||||
{
|
||||
long deviceId;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &deviceId) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_BOOL(tdRemoveDevice(deviceId));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(tdSendRawCommand)
|
||||
{
|
||||
char *command;
|
||||
int commandLen;
|
||||
long reserved = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &command, &commandLen, &reserved) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
RETURN_LONG(tdSendRawCommand(command, reserved));
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
include telldus.c
|
||||
include telldus-core.h
|
||||
recursive-include example/*
|
|
@ -1,47 +0,0 @@
|
|||
|
||||
import telldus
|
||||
import time
|
||||
|
||||
telldus.tdInit()
|
||||
devices = telldus.tdGetNumberOfDevices()
|
||||
print "Devices: %d\n" % devices
|
||||
|
||||
allMethods = telldus.TELLSTICK_TURNON | telldus.TELLSTICK_TURNOFF | telldus.TELLSTICK_BELL | telldus.TELLSTICK_DIM
|
||||
|
||||
for i in xrange(devices):
|
||||
deviceid = telldus.tdGetDeviceId(i)
|
||||
|
||||
if deviceid:
|
||||
name = telldus.tdGetName(deviceid)
|
||||
|
||||
print "%s - %s\n" % (deviceid, name)
|
||||
|
||||
methods = telldus.tdMethods(deviceid, allMethods)
|
||||
|
||||
if methods & telldus.TELLSTICK_TURNON:
|
||||
print " * TurnOn\n"
|
||||
telldus.tdTurnOn(deviceid)
|
||||
time.sleep(1)
|
||||
|
||||
if methods & telldus.TELLSTICK_TURNOFF:
|
||||
print " * TurnOff\n"
|
||||
telldus.tdTurnOff(deviceid)
|
||||
time.sleep(1)
|
||||
|
||||
if methods & telldus.TELLSTICK_BELL:
|
||||
print " * Bell\n"
|
||||
telldus.tdBell(deviceid)
|
||||
time.sleep(1)
|
||||
|
||||
if methods & telldus.TELLSTICK_TOGGLE:
|
||||
print " * Toggle\n"
|
||||
|
||||
if methods & telldus.TELLSTICK_DIM:
|
||||
print " * Dim\n"
|
||||
telldus.tdDim(deviceid, 128)
|
||||
time.sleep(1)
|
||||
|
||||
telldus.tdClose()
|
||||
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
import threading
|
||||
import telldus
|
||||
import time
|
||||
|
||||
telldus.tdInit()
|
||||
|
||||
def turnOn():
|
||||
print "turning on"
|
||||
telldus.tdTurnOn(1)
|
||||
|
||||
def turnOff():
|
||||
print "turning off"
|
||||
telldus.tdTurnOff(1)
|
||||
|
||||
def callback(deviceId, method, value, callbackId):
|
||||
print "callback"
|
||||
print "DeviceId: %i Method: %i Value: %s" % (deviceId, method, value)
|
||||
return True
|
||||
|
||||
#function to be called when device event occurs, even for unregistered devices
|
||||
def rawcallback(data, controllerId, callbackId):
|
||||
print "raw callback"
|
||||
print "Data: %s ControllerId: %i" % (data, controllerId)
|
||||
return True
|
||||
|
||||
callbackid = telldus.tdRegisterDeviceEvent(callback)
|
||||
rawcallbackid = telldus.tdRegisterRawDeviceEvent(rawcallback)
|
||||
|
||||
print callbackid, rawcallbackid
|
||||
|
||||
try:
|
||||
while(1):
|
||||
time.sleep(0.5) #don't exit
|
||||
except KeyboardInterrupt:
|
||||
print "Exiting"
|
||||
telldus.tdUnregisterCallback(callbackid)
|
||||
telldus.tdUnregisterCallback(rawcallbackid)
|
||||
telldus.tdClose()
|
|
@ -1,28 +0,0 @@
|
|||
import telldus
|
||||
|
||||
telldus.tdInit()
|
||||
|
||||
while True:
|
||||
result = telldus.tdSensor()
|
||||
if not isinstance(result, tuple):
|
||||
break
|
||||
else:
|
||||
protocol, model, sensorId, dataTypes = result
|
||||
print "Protocol: %s,\tModel: %s,\tSensorId: %i\nDataTypes: %i" % (protocol, model, sensorId, dataTypes)
|
||||
|
||||
# Retrieve the values the sensor supports
|
||||
if dataTypes & telldus.TELLSTICK_TEMPERATURE:
|
||||
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_TEMPERATURE)
|
||||
if isinstance(result, tuple):
|
||||
value, timestamp = result
|
||||
print "Temperature:\t%sC\t(%s)\n" % (value, str(timestamp))
|
||||
|
||||
if dataTypes & telldus.TELLSTICK_HUMIDITY:
|
||||
result = telldus.tdSensorValue(protocol, model, sensorId, telldus.TELLSTICK_HUMIDITY)
|
||||
if isinstance(result, tuple):
|
||||
value, timestamp = result
|
||||
print "Humidity:\t%s\t(%s)\n" % (value, str(timestamp))
|
||||
|
||||
print "\n"
|
||||
|
||||
telldus.tdClose()
|
|
@ -1,345 +0,0 @@
|
|||
import sys
|
||||
from distutils.core import setup, Extension
|
||||
|
||||
DEBUG = True
|
||||
|
||||
PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')
|
||||
|
||||
if PLATFORM_IS_WINDOWS:
|
||||
|
||||
__doc__="""This is a distutils setup-script for the telldus extension
|
||||
|
||||
To build the telldus extensions, simply execute:
|
||||
python setup.py -q build
|
||||
or
|
||||
python setup.py -q install
|
||||
to build and install into your current Python installation.
|
||||
|
||||
These extensions require a number of libraries to build, some of which may
|
||||
require you to install special SDKs or toolkits. This script will attempt
|
||||
to build as many as it can, and at the end of the build will report any
|
||||
extension modules that could not be built and why.
|
||||
|
||||
This has got complicated due to the various different versions of
|
||||
Visual Studio used - some VS versions are not compatible with some SDK
|
||||
versions. Below are the Windows SDK versions required (and the URL - although
|
||||
these are subject to being changed by MS at any time:)
|
||||
|
||||
Python 2.6+:
|
||||
|
||||
Build using Microsoft Visual Studio 2008 Express Edition:
|
||||
http://www.microsoft.com/en-us/download/details.aspx?id=6506
|
||||
http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/
|
||||
http://www.cppblog.com/Files/xcpp/VCE64BIT_WIN7SDK.zip
|
||||
|
||||
For 32bit build:
|
||||
Microsoft Windows SDK for Windows 7 and .NET Framework 3.5
|
||||
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b
|
||||
Copy C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvars32.bat to
|
||||
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
|
||||
|
||||
For 64bit build:
|
||||
Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 (ISO) GRMSDKX_EN_DVD.iso
|
||||
http://www.microsoft.com/en-us/download/details.aspx?id=18950
|
||||
Copy C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvars64.bat to
|
||||
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
|
||||
|
||||
Python 2.3->2.5:
|
||||
|
||||
Microsoft Windows Software Development Kit Update for Windows Vista (version 6.0)
|
||||
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4377f86d-c913-4b5c-b87e-ef72e5b4e065
|
||||
** If you want to build Python 2.3, be sure to install the SDK compilers
|
||||
too - although we don't use them, this setup option installs some .lib
|
||||
files we do need.
|
||||
**
|
||||
|
||||
If you multiple SDK versions on a single machine, set the MSSDK environment
|
||||
variable to point at the one you want to use. Note that using the SDK for
|
||||
a particular platform (eg, Windows 7) doesn't force you to use that OS as your
|
||||
build environment. If the links above don't work, use google to find them.
|
||||
|
||||
Building:
|
||||
---------
|
||||
|
||||
To install the telldus extension, execute:
|
||||
python setup.py -q install
|
||||
|
||||
This will install the built extensions into your site-packages directory,
|
||||
create an appropriate .pth file, and should leave everything ready to use.
|
||||
There is no need to modify the registry.
|
||||
|
||||
To build or install debug (_d) versions of these extensions, ensure you have
|
||||
built or installed a debug version of Python itself, then pass the "--debug"
|
||||
flag to the build command - eg:
|
||||
python setup.py -q build --debug
|
||||
or to build and install a debug version:
|
||||
python setup.py -q build --debug install
|
||||
|
||||
To build 64bit versions of this:
|
||||
|
||||
* py2.5 and earlier - sorry, I've given up in disgust. Using VS2003 with
|
||||
the Vista SDK is just too painful to make work, and VS2005 is not used for
|
||||
any released versions of Python. See revision 1.69 of this file for the
|
||||
last version that attempted to support and document this process.
|
||||
|
||||
* 2.6 and later: On a 64bit OS, just build as you would on a 32bit platform.
|
||||
On a 32bit platform (ie, to cross-compile), you must use VS2008 to
|
||||
cross-compile Python itself. Note that by default, the 64bit tools are not
|
||||
installed with VS2008, so you may need to adjust your VS2008 setup (see "For 64bit build"). Then
|
||||
use:
|
||||
vcs
|
||||
setup.py build --plat-name=win-amd64
|
||||
|
||||
see the distutils cross-compilation documentation for more details.
|
||||
"""
|
||||
# Originally by Thomas Heller, started in 2000 or so.
|
||||
import os
|
||||
import shutil
|
||||
|
||||
is_py3k = sys.version_info > (3,) # get this out of the way early on...
|
||||
# We have special handling for _winreg so our setup3.py script can avoid
|
||||
# using the 'imports' fixer and therefore start much faster...
|
||||
if is_py3k:
|
||||
import winreg as _winreg
|
||||
else:
|
||||
import _winreg
|
||||
|
||||
try:
|
||||
from distutils import log
|
||||
except ImportError:
|
||||
class Log:
|
||||
def debug(self, msg, *args):
|
||||
print msg % args
|
||||
def info(self, msg, *args):
|
||||
print msg % args
|
||||
log = Log()
|
||||
|
||||
try:
|
||||
this_file = __file__
|
||||
except NameError:
|
||||
this_file = sys.argv[0]
|
||||
|
||||
this_file = os.path.abspath(this_file)
|
||||
# We get upset if the cwd is not our source dir, but it is a PITA to
|
||||
# insist people manually CD there first!
|
||||
if os.path.dirname(this_file):
|
||||
os.chdir(os.path.dirname(this_file))
|
||||
|
||||
|
||||
# We need to know the platform SDK dir before we can list the extensions.
|
||||
def find_platform_sdk_dir():
|
||||
# Finding the Platform SDK install dir is a treat. There can be some
|
||||
# dead ends so we only consider the job done if we find the "windows.h"
|
||||
# landmark.
|
||||
landmark = "include\\windows.h"
|
||||
# 1. The use might have their current environment setup for the
|
||||
# SDK, in which case the "MSSdk" env var is set.
|
||||
sdkdir = os.environ.get("MSSdk")
|
||||
if sdkdir:
|
||||
if DEBUG:
|
||||
print "PSDK: try %%MSSdk%%: '%s'" % sdkdir
|
||||
if os.path.isfile(os.path.join(sdkdir, landmark)):
|
||||
return sdkdir
|
||||
# 2. The "Install Dir" value in the
|
||||
# HKLM\Software\Microsoft\MicrosoftSDK\Directories registry key
|
||||
# sometimes points to the right thing. However, after upgrading to
|
||||
# the "Platform SDK for Windows Server 2003 SP1" this is dead end.
|
||||
try:
|
||||
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"Software\Microsoft\MicrosoftSDK\Directories")
|
||||
sdkdir, ignore = _winreg.QueryValueEx(key, "Install Dir")
|
||||
except EnvironmentError:
|
||||
pass
|
||||
else:
|
||||
if DEBUG:
|
||||
print r"PSDK: try 'HKLM\Software\Microsoft\MicrosoftSDK"\
|
||||
"\Directories\Install Dir': '%s'" % sdkdir
|
||||
if os.path.isfile(os.path.join(sdkdir, landmark)):
|
||||
return sdkdir
|
||||
# 3. Each installed SDK (not just the platform SDK) seems to have GUID
|
||||
# subkey of HKLM\Software\Microsoft\MicrosoftSDK\InstalledSDKs and
|
||||
# it *looks* like the latest installed Platform SDK will be the
|
||||
# only one with an "Install Dir" sub-value.
|
||||
try:
|
||||
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"Software\Microsoft\MicrosoftSDK\InstalledSDKs")
|
||||
i = 0
|
||||
while True:
|
||||
guid = _winreg.EnumKey(key, i)
|
||||
guidkey = _winreg.OpenKey(key, guid)
|
||||
try:
|
||||
sdkdir, ignore = _winreg.QueryValueEx(guidkey, "Install Dir")
|
||||
except EnvironmentError:
|
||||
pass
|
||||
else:
|
||||
if DEBUG:
|
||||
print r"PSDK: try 'HKLM\Software\Microsoft\MicrosoftSDK"\
|
||||
"\InstallSDKs\%s\Install Dir': '%s'"\
|
||||
% (guid, sdkdir)
|
||||
if os.path.isfile(os.path.join(sdkdir, landmark)):
|
||||
return sdkdir
|
||||
i += 1
|
||||
except EnvironmentError:
|
||||
pass
|
||||
# 4. Vista's SDK
|
||||
try:
|
||||
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
|
||||
r"Software\Microsoft\Microsoft SDKs\Windows")
|
||||
sdkdir, ignore = _winreg.QueryValueEx(key, "CurrentInstallFolder")
|
||||
except EnvironmentError:
|
||||
pass
|
||||
else:
|
||||
if DEBUG:
|
||||
print r"PSDK: try 'HKLM\Software\Microsoft\MicrosoftSDKs"\
|
||||
"\Windows\CurrentInstallFolder': '%s'" % sdkdir
|
||||
if os.path.isfile(os.path.join(sdkdir, landmark)):
|
||||
return sdkdir
|
||||
|
||||
# 5. Failing this just try a few well-known default install locations.
|
||||
progfiles = os.environ.get("ProgramFiles", r"C:\Program Files")
|
||||
defaultlocs = [
|
||||
os.path.join(progfiles, "Microsoft Platform SDK"),
|
||||
os.path.join(progfiles, "Microsoft SDK"),
|
||||
]
|
||||
for sdkdir in defaultlocs:
|
||||
if DEBUG:
|
||||
print "PSDK: try default location: '%s'" % sdkdir
|
||||
if os.path.isfile(os.path.join(sdkdir, landmark)):
|
||||
return sdkdir
|
||||
|
||||
|
||||
# Some nasty hacks to prevent most of our extensions using a manifest, as
|
||||
# the manifest - even without a reference to the CRT assembly - is enough
|
||||
# to prevent the extension from loading. For more details, see
|
||||
# http://bugs.python.org/issue7833 - that issue has a patch, but it is
|
||||
# languishing and will probably never be fixed for Python 2.6...
|
||||
if sys.version_info > (2,6):
|
||||
from distutils.spawn import spawn
|
||||
from distutils.msvc9compiler import MSVCCompiler
|
||||
MSVCCompiler._orig_spawn = MSVCCompiler.spawn
|
||||
MSVCCompiler._orig_link = MSVCCompiler.link
|
||||
|
||||
# We need to override this method for versions where issue7833 *has* landed
|
||||
# (ie, 2.7 and 3.2+)
|
||||
def manifest_get_embed_info(self, target_desc, ld_args):
|
||||
_want_assembly_kept = getattr(self, '_want_assembly_kept', False)
|
||||
if not _want_assembly_kept:
|
||||
return None
|
||||
for arg in ld_args:
|
||||
if arg.startswith("/MANIFESTFILE:"):
|
||||
orig_manifest = arg.split(":", 1)[1]
|
||||
if target_desc==self.EXECUTABLE:
|
||||
rid = 1
|
||||
else:
|
||||
rid = 2
|
||||
return orig_manifest, rid
|
||||
return None
|
||||
# always monkeypatch it in even though it will only be called in 2.7
|
||||
# and 3.2+.
|
||||
MSVCCompiler.manifest_get_embed_info = manifest_get_embed_info
|
||||
|
||||
def monkeypatched_spawn(self, cmd):
|
||||
is_link = cmd[0].endswith("link.exe") or cmd[0].endswith('"link.exe"')
|
||||
is_mt = cmd[0].endswith("mt.exe") or cmd[0].endswith('"mt.exe"')
|
||||
_want_assembly_kept = getattr(self, '_want_assembly_kept', False)
|
||||
if not _want_assembly_kept and is_mt:
|
||||
# We don't want mt.exe run...
|
||||
return
|
||||
if not _want_assembly_kept and is_link:
|
||||
# remove /MANIFESTFILE:... and add MANIFEST:NO
|
||||
# (but note that for winxpgui, which specifies a manifest via a
|
||||
# .rc file, this is ignored by the linker - the manifest specified
|
||||
# in the .rc file is still added)
|
||||
for i in range(len(cmd)):
|
||||
if cmd[i].startswith("/MANIFESTFILE:"):
|
||||
cmd[i] = "/MANIFEST:NO"
|
||||
break
|
||||
if _want_assembly_kept and is_mt:
|
||||
# We want mt.exe run with the original manifest
|
||||
for i in range(len(cmd)):
|
||||
if cmd[i] == "-manifest":
|
||||
cmd[i+1] = cmd[i+1] + ".orig"
|
||||
break
|
||||
self._orig_spawn(cmd)
|
||||
if _want_assembly_kept and is_link:
|
||||
# We want a copy of the original manifest so we can use it later.
|
||||
for i in range(len(cmd)):
|
||||
if cmd[i].startswith("/MANIFESTFILE:"):
|
||||
mfname = cmd[i][14:]
|
||||
shutil.copyfile(mfname, mfname + ".orig")
|
||||
break
|
||||
|
||||
def monkeypatched_link(self, target_desc, objects, output_filename, *args, **kw):
|
||||
# no manifests for 3.3+
|
||||
self._want_assembly_kept = sys.version_info < (3,3) and \
|
||||
(os.path.basename(output_filename).startswith("PyISAPI_loader.dll") or \
|
||||
os.path.basename(output_filename).startswith("perfmondata.dll") or \
|
||||
os.path.basename(output_filename).startswith("win32ui.pyd") or \
|
||||
target_desc==self.EXECUTABLE)
|
||||
try:
|
||||
return self._orig_link(target_desc, objects, output_filename, *args, **kw)
|
||||
finally:
|
||||
delattr(self, '_want_assembly_kept')
|
||||
MSVCCompiler.spawn = monkeypatched_spawn
|
||||
MSVCCompiler.link = monkeypatched_link
|
||||
|
||||
def find_telldus_dev_dir():
|
||||
landmark = "telldus-core.h"
|
||||
dev_dir = os.environ.get("TELLDUS_DEVDIR")
|
||||
if dev_dir:
|
||||
if DEBUG:
|
||||
print "Telldus dev dir:" % dev_dir
|
||||
if os.path.isfile(os.path.join(dev_dir, landmark)):
|
||||
return dev_dir
|
||||
|
||||
progfiles = os.environ.get("ProgramFiles", r"C:\Program Files")
|
||||
defaultlocs = [
|
||||
os.path.join(progfiles + ' (x86)', "Telldus", "Development"),
|
||||
os.path.join(progfiles, "Telldus", "Development"),
|
||||
]
|
||||
for dev_dir in defaultlocs:
|
||||
if DEBUG:
|
||||
print "Telldus dev dir: '%s'" % dev_dir
|
||||
if os.path.isfile(os.path.join(dev_dir, landmark)):
|
||||
return dev_dir
|
||||
if DEBUG:
|
||||
print "Telldus dev dir not found, make sure dev code is installed. Or set TELLDUS_DEVDIR."
|
||||
|
||||
sdk_dir = find_platform_sdk_dir()
|
||||
sdk_include_dir = os.path.join(sdk_dir, 'Include')
|
||||
|
||||
telldus_dev_dir = find_telldus_dev_dir()
|
||||
telldus_platform = os.environ.get("TELLDUS_PLATFORM", 'x86_64')
|
||||
telldus_library_dir = os.path.join(telldus_dev_dir, telldus_platform)
|
||||
|
||||
include_dirs = [sdk_include_dir, telldus_dev_dir]
|
||||
library_dirs = [telldus_library_dir]
|
||||
libraries = ['python%i%i' % (sys.version_info[0], sys.version_info[1]) , 'TelldusCore']
|
||||
define_macros = [('_WINDOWS', 1)]
|
||||
|
||||
else:
|
||||
include_dirs = ['/usr/include', '/usr/local/include']
|
||||
library_dirs = ['/usr/lib', '/usr/local/lib']
|
||||
libraries = ['telldus-core']
|
||||
define_macros = []
|
||||
|
||||
define_macros.extend([('DATA_LENGTH', 20), ('CALLBACK_LENGTH', 20)])
|
||||
|
||||
telldus = Extension(
|
||||
'telldus',
|
||||
include_dirs = include_dirs,
|
||||
libraries = libraries,
|
||||
library_dirs = library_dirs,
|
||||
define_macros = define_macros,
|
||||
sources = ['telldus.c']
|
||||
)
|
||||
|
||||
setup(
|
||||
name = 'telldus',
|
||||
version = '1.0',
|
||||
description = 'Python bindings for telldus',
|
||||
author='Oyvind Saltvik',
|
||||
author_email='oyvind.saltvik@gmail.com',
|
||||
url='http://github.com/fivethreeo/telldus/',
|
||||
ext_modules = [telldus]
|
||||
)
|
|
@ -1,843 +0,0 @@
|
|||
#include "Python.h"
|
||||
#include "datetime.h"
|
||||
#include <telldus-core.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* estrdup.c -- duplicate a string, die if error
|
||||
*
|
||||
* char *string;
|
||||
* char *newstring;
|
||||
* newstring = estrdup(string);
|
||||
*
|
||||
* estrdup returns a copy of its argument, located in memory
|
||||
* allocated from the heap. If it is unable to allocate the
|
||||
* necessary memory, estrdup executes PyErr_NoMemory();
|
||||
* (Generally, the routine error is not expected to return,
|
||||
* but if it does, estrdup will return NULL.)
|
||||
*/
|
||||
|
||||
int callbackLen = 0;
|
||||
|
||||
typedef struct {
|
||||
PyObject *func;
|
||||
int callbackId;
|
||||
} callbackInfo;
|
||||
|
||||
static callbackInfo callbackList[CALLBACK_LENGTH];
|
||||
|
||||
void
|
||||
addCallback(PyObject *func, int callbackId)
|
||||
{
|
||||
if (callbackLen < CALLBACK_LENGTH) {
|
||||
callbackList[callbackLen].func = func;
|
||||
callbackList[callbackLen].callbackId = callbackId;
|
||||
callbackLen++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
removeCallback(int callbackId)
|
||||
{
|
||||
int index = -1;
|
||||
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < callbackLen; i++)
|
||||
{
|
||||
if (callbackList[i].callbackId == callbackId)
|
||||
{
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
if (!(index == -1)) {
|
||||
for (j = index; j < callbackLen - 1; j++)
|
||||
{
|
||||
callbackList[j] = callbackList[j+1];
|
||||
}
|
||||
callbackLen--;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
hasCallback(int callbackId)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < callbackLen; i++)
|
||||
{
|
||||
if (callbackList[i].callbackId == callbackId)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
PyObject *
|
||||
getCallback(int callbackId)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < callbackLen; i++)
|
||||
{
|
||||
if (callbackList[i].callbackId == callbackId)
|
||||
{
|
||||
return callbackList[i].func;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
estrdup(char *s)
|
||||
{
|
||||
register char *t;
|
||||
|
||||
if (NULL == (t = malloc(strlen(s)+1))) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
strcpy(t, s);
|
||||
return(t);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdInit(PyObject *self)
|
||||
{
|
||||
tdInit();
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdClose(PyObject *self)
|
||||
{
|
||||
tdClose();
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdTurnOn(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdTurnOn(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdTurnOff(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdTurnOff(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdBell(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdBell(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdDim(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
unsigned char level;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "lb", &id, &level))
|
||||
return NULL;
|
||||
|
||||
if (level < 0 || level > 255)
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdDim(id, level));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdLearn(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdLearn(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdMethods(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
long supportedmethods;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ll", &id, &supportedmethods))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdMethods(id, supportedmethods));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
telldus_tdLastSentCommand(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
long supportedmethods;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ll", &id, &supportedmethods))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdLastSentCommand(id, supportedmethods));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdLastSentValue(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* value;
|
||||
char* retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
value = tdLastSentValue(id);
|
||||
retval = estrdup(value);
|
||||
tdReleaseString(value);
|
||||
return PyString_FromString(retval);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetNumberOfDevices(PyObject *self)
|
||||
{
|
||||
return PyLong_FromLong((long) tdGetNumberOfDevices());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetDeviceId(PyObject *self, PyObject *args)
|
||||
{
|
||||
long index;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &index))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdGetDeviceId(index));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetDeviceType(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdGetDeviceType(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetErrorString(PyObject *self, PyObject *args)
|
||||
{
|
||||
long errorno;
|
||||
char* errorString;
|
||||
char* retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &errorno))
|
||||
return NULL;
|
||||
|
||||
errorString = tdGetErrorString(errorno);
|
||||
retval = estrdup(errorString);
|
||||
tdReleaseString(errorString);
|
||||
return PyString_FromString(retval);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetName(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* name;
|
||||
char* retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
name = tdGetName(id);
|
||||
retval = estrdup(name);
|
||||
tdReleaseString(name);
|
||||
return PyString_FromString(retval);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSetName(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* name;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ls", &id, &name))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdSetName(id, name));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetProtocol(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* protocol;
|
||||
char* retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
protocol = tdGetProtocol(id);
|
||||
retval = estrdup(protocol);
|
||||
tdReleaseString(protocol);
|
||||
return PyString_FromString(retval);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSetProtocol(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* protocol;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ls", &id, &protocol))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdSetProtocol(id, protocol));
|
||||
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetModel(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* model;
|
||||
char* retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
model = tdGetModel(id);
|
||||
retval = estrdup(model);
|
||||
tdReleaseString(model);
|
||||
return PyString_FromString(retval);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSetModel(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* model;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ls", &id, &model))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdSetProtocol(id, model));
|
||||
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdGetDeviceParameter(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* name;
|
||||
char* defaultValue;
|
||||
char* param;
|
||||
char* retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "lss", &id, &name, &defaultValue))
|
||||
return NULL;
|
||||
|
||||
param = tdGetDeviceParameter(id, name, defaultValue);
|
||||
retval = estrdup(param);
|
||||
tdReleaseString(param);
|
||||
return PyString_FromString(retval);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSetDeviceParameter(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
char* name;
|
||||
char* value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "lss", &id, &name, &value))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdSetDeviceParameter(id, name, value));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdAddDevice(PyObject *self)
|
||||
{
|
||||
return PyLong_FromLong((long) tdAddDevice());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdRemoveDevice(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdRemoveDevice(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSendRawCommand(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *command;
|
||||
long reserved = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|l", &command, &reserved));
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromLong((long) tdSendRawCommand(command, reserved));
|
||||
}
|
||||
|
||||
static PyObject *DeviceEventCallback = NULL;
|
||||
|
||||
void
|
||||
telldus_deviceEventCallback(int deviceId, int method, const char *data, int callbackId, int context)
|
||||
{
|
||||
|
||||
PyObject * result;
|
||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||
|
||||
// now call the Python callback function
|
||||
result = PyObject_CallFunction(DeviceEventCallback, "llsl", deviceId, method, data, callbackId);
|
||||
|
||||
if (result == NULL) {
|
||||
// something went wrong so print to stderr
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
// take care of reference handling
|
||||
Py_XDECREF(result);
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdRegisterDeviceEvent(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
||||
int result;
|
||||
PyObject *func;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O:tdRegisterDeviceEvent", &func)) {
|
||||
PyErr_SetString(PyExc_StandardError, "Parse error!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyCallable_Check(func)) {
|
||||
// Error
|
||||
PyErr_SetString(PyExc_StandardError, "The object should be callable!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_XDECREF(DeviceEventCallback);
|
||||
// stick around till we need you
|
||||
Py_XINCREF(func);
|
||||
|
||||
DeviceEventCallback = func;
|
||||
|
||||
result = tdRegisterDeviceEvent((TDDeviceEvent) &telldus_deviceEventCallback, 0);
|
||||
|
||||
addCallback(func, result);
|
||||
|
||||
return PyLong_FromLong((long) result);
|
||||
}
|
||||
|
||||
static PyObject *DeviceChangeEventCallback = NULL;
|
||||
|
||||
void
|
||||
telldus_deviceChangeEventCallback(int deviceId, int changeEvent, int changeType, int callbackId, int context)
|
||||
{
|
||||
PyObject * result;
|
||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||
|
||||
// now call the Python callback function
|
||||
result = PyObject_CallFunction(DeviceChangeEventCallback, "llll", deviceId, changeEvent, changeType, callbackId);
|
||||
|
||||
if (result == NULL) {
|
||||
// something went wrong so print to stderr
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
// take care of reference handling
|
||||
Py_XDECREF(result);
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdRegisterDeviceChangeEvent(PyObject *self, PyObject *args)
|
||||
{
|
||||
int result;
|
||||
PyObject *func;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &func)) {
|
||||
PyErr_SetString(PyExc_StandardError, "Parse error!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyCallable_Check(func)) {
|
||||
// Error
|
||||
PyErr_SetString(PyExc_StandardError, "The object should be callable!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_XDECREF(DeviceChangeEventCallback);
|
||||
// stick around till we need you
|
||||
Py_XINCREF(func);
|
||||
|
||||
DeviceChangeEventCallback = func;
|
||||
|
||||
result = tdRegisterDeviceChangeEvent((TDDeviceChangeEvent) &telldus_deviceChangeEventCallback, 0);
|
||||
|
||||
addCallback(func, result);
|
||||
|
||||
return PyLong_FromLong((long) result);
|
||||
}
|
||||
|
||||
static PyObject *RawDeviceEventCallback = NULL;
|
||||
|
||||
void
|
||||
telldus_rawDeviceEventCallback(const char *data, int controllerId, int callbackId, int context)
|
||||
{
|
||||
PyObject * result;
|
||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||
|
||||
// now call the Python callback function
|
||||
result = PyObject_CallFunction(RawDeviceEventCallback, "sll", data, controllerId, callbackId);
|
||||
|
||||
if (result == NULL) {
|
||||
// something went wrong so print to stderr
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
// take care of reference handling
|
||||
Py_XDECREF(result);
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdRegisterRawDeviceEvent(PyObject *self, PyObject *args)
|
||||
{
|
||||
int result;
|
||||
PyObject *func;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &func)) {
|
||||
PyErr_SetString(PyExc_StandardError, "Parse error!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyCallable_Check(func)) {
|
||||
// Error
|
||||
PyErr_SetString(PyExc_StandardError, "The object should be callable!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_XDECREF(RawDeviceEventCallback);
|
||||
// stick around till we need you
|
||||
Py_XINCREF(func);
|
||||
|
||||
RawDeviceEventCallback = func;
|
||||
|
||||
result = tdRegisterRawDeviceEvent((TDRawDeviceEvent) &telldus_rawDeviceEventCallback, 0);
|
||||
|
||||
addCallback(func, result);
|
||||
|
||||
return PyLong_FromLong((long) result);
|
||||
}
|
||||
|
||||
static PyObject *SensorEventCallback = NULL;
|
||||
|
||||
void
|
||||
telldus_sensorEventCallback(const char *protocol, const char *model, int id, int dataType, const char *value, int timestamp, int callbackId, int context)
|
||||
{
|
||||
PyObject * result;
|
||||
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||
|
||||
// now call the Python callback function
|
||||
result = PyObject_CallFunction(SensorEventCallback, "ssllsll", protocol, model, id, dataType, value, timestamp, callbackId);
|
||||
|
||||
if (result == NULL) {
|
||||
// something went wrong so print to stderr
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
// take care of reference handling
|
||||
Py_XDECREF(result);
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdRegisterSensorEvent(PyObject *self, PyObject *args)
|
||||
{
|
||||
int result;
|
||||
PyObject *func;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &func)) {
|
||||
PyErr_SetString(PyExc_StandardError, "Parse error!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyCallable_Check(func)) {
|
||||
// Error
|
||||
PyErr_SetString(PyExc_StandardError, "The object should be callable!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_XDECREF(SensorEventCallback);
|
||||
// stick around till we need you
|
||||
Py_XINCREF(func);
|
||||
|
||||
SensorEventCallback = func;
|
||||
|
||||
result = tdRegisterSensorEvent((TDSensorEvent) &telldus_sensorEventCallback, 0);
|
||||
|
||||
addCallback(func, result);
|
||||
|
||||
return PyLong_FromLong((long) result);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdUnregisterCallback(PyObject *self, PyObject *args)
|
||||
{
|
||||
long id;
|
||||
PyObject *callback;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "l", &id))
|
||||
return NULL;
|
||||
|
||||
if (hasCallback(id) == 1) {
|
||||
callback = getCallback(id);
|
||||
Py_DECREF(callback);
|
||||
removeCallback(id);
|
||||
}
|
||||
|
||||
return PyLong_FromLong((long) tdUnregisterCallback(id));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSensor(PyObject *self, PyObject *args)
|
||||
{
|
||||
char protocol[DATA_LENGTH];
|
||||
char model[DATA_LENGTH];
|
||||
long sensorId = 0;
|
||||
long dataTypes = 0;
|
||||
|
||||
long result;
|
||||
|
||||
result = tdSensor(protocol, DATA_LENGTH, model, DATA_LENGTH, &sensorId, &dataTypes);
|
||||
|
||||
if (result == TELLSTICK_SUCCESS)
|
||||
{
|
||||
return Py_BuildValue("ssll", protocol, model, sensorId, dataTypes);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PyLong_FromLong(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
telldus_tdSensorValue(PyObject *self, PyObject *args)
|
||||
{
|
||||
char protocol[DATA_LENGTH];
|
||||
char model[DATA_LENGTH];
|
||||
long sensorId = 0;
|
||||
long dataType = 0;
|
||||
char value[DATA_LENGTH];
|
||||
long timestamp = 0;
|
||||
long result;
|
||||
|
||||
PyObject *floatObj = NULL;
|
||||
PyObject *timeTuple = NULL;
|
||||
PyObject *dateTime = NULL;
|
||||
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ssll", &protocol, &model, &sensorId, &dataType))
|
||||
return NULL;
|
||||
|
||||
result = tdSensorValue(protocol, model, sensorId, dataType, value, DATA_LENGTH, ×tamp);
|
||||
|
||||
if (result == TELLSTICK_SUCCESS)
|
||||
{
|
||||
|
||||
floatObj = PyFloat_FromDouble((double) timestamp);
|
||||
timeTuple = Py_BuildValue("(O)", floatObj);
|
||||
dateTime = PyDateTime_FromTimestamp(timeTuple);
|
||||
|
||||
Py_DECREF(floatObj);
|
||||
Py_DECREF(timeTuple);
|
||||
|
||||
return Py_BuildValue("sO", value, dateTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PyLong_FromLong(result);
|
||||
}
|
||||
}
|
||||
|
||||
static PyMethodDef telldus_methods[] = {
|
||||
{"tdInit", (PyCFunction) telldus_tdInit, METH_NOARGS, "Initiate telldus."},
|
||||
{"tdClose", (PyCFunction) telldus_tdClose, METH_NOARGS, "Close telldus."},
|
||||
{"tdTurnOn", (PyCFunction) telldus_tdTurnOn, METH_VARARGS, "Turn on device."},
|
||||
{"tdTurnOff", (PyCFunction) telldus_tdTurnOff, METH_VARARGS, "Turn off device."},
|
||||
{"tdBell", (PyCFunction) telldus_tdBell, METH_VARARGS, "Bell device."},
|
||||
{"tdDim", (PyCFunction) telldus_tdDim, METH_VARARGS, "Dim device."},
|
||||
{"tdLearn", (PyCFunction) telldus_tdLearn, METH_VARARGS, "Learn device."},
|
||||
{"tdMethods", (PyCFunction) telldus_tdMethods, METH_VARARGS, "Methods comment."},
|
||||
{"tdLastSentCommand", (PyCFunction) telldus_tdLastSentCommand, METH_VARARGS, "LastSentCommand comment."},
|
||||
{"tdLastSentValue", (PyCFunction) telldus_tdLastSentValue, METH_VARARGS, "LastSentValue comment."},
|
||||
{"tdGetNumberOfDevices", (PyCFunction) telldus_tdGetNumberOfDevices, METH_VARARGS, "GetNumberOfDevices comment."},
|
||||
{"tdGetDeviceId", (PyCFunction) telldus_tdGetDeviceId, METH_VARARGS, "GetDeviceId comment."},
|
||||
{"tdGetDeviceType", (PyCFunction) telldus_tdGetDeviceType, METH_VARARGS, "GetDeviceType comment."},
|
||||
{"tdGetErrorString", (PyCFunction) telldus_tdGetErrorString, METH_VARARGS, "GetErrorString comment."},
|
||||
{"tdGetName", (PyCFunction) telldus_tdGetName, METH_VARARGS, "GetName comment."},
|
||||
{"tdSetName", (PyCFunction) telldus_tdSetName, METH_VARARGS, "SetName comment."},
|
||||
{"tdGetProtocol", (PyCFunction) telldus_tdGetProtocol, METH_VARARGS, "GetProtocol comment."},
|
||||
{"tdSetProtocol", (PyCFunction) telldus_tdSetProtocol, METH_VARARGS, "SetProtocol comment."},
|
||||
{"tdGetModel", (PyCFunction) telldus_tdGetModel, METH_VARARGS, "GetModel comment."},
|
||||
{"tdSetModel", (PyCFunction) telldus_tdSetModel, METH_VARARGS, "SetModel comment."},
|
||||
{"tdGetDeviceParameter", (PyCFunction) telldus_tdGetDeviceParameter, METH_VARARGS, "GetDeviceParameter comment."},
|
||||
{"tdSetDeviceParameter", (PyCFunction) telldus_tdSetDeviceParameter, METH_VARARGS, "SetDeviceParameter comment."},
|
||||
{"tdAddDevice", (PyCFunction) telldus_tdAddDevice, METH_NOARGS, "AddDevice comment."},
|
||||
{"tdRemoveDevice", (PyCFunction) telldus_tdRemoveDevice, METH_VARARGS, "RemoveDevice comment."},
|
||||
{"tdSendRawCommand", (PyCFunction) telldus_tdSendRawCommand, METH_VARARGS, "SendRawCommand comment."},
|
||||
|
||||
{"tdRegisterDeviceEvent", (PyCFunction) telldus_tdRegisterDeviceEvent, METH_VARARGS, "RegisterDeviceEvent comment."},
|
||||
{"tdRegisterDeviceChangeEvent", (PyCFunction) telldus_tdRegisterDeviceChangeEvent, METH_VARARGS, "RegisterDeviceChangeEvent comment."},
|
||||
{"tdRegisterRawDeviceEvent", (PyCFunction) telldus_tdRegisterRawDeviceEvent, METH_VARARGS, "RegisterRawDeviceEvent comment."},
|
||||
{"tdRegisterSensorEvent", (PyCFunction) telldus_tdRegisterSensorEvent, METH_VARARGS, "RegisterSensorEvent comment."},
|
||||
{"tdUnregisterCallback", (PyCFunction) telldus_tdUnregisterCallback, METH_VARARGS, "UnregisterCallback comment."},
|
||||
{"tdSensor", (PyCFunction) telldus_tdSensor, METH_NOARGS, "Sensor comment."},
|
||||
{"tdSensorValue", (PyCFunction) telldus_tdSensorValue, METH_VARARGS, "SensorValue comment."},
|
||||
|
||||
{NULL, NULL, 0, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
void
|
||||
inittelldus(void)
|
||||
{
|
||||
PyObject *module;
|
||||
|
||||
PyObject *TELLSTICK_TURNON_GLUE;
|
||||
PyObject *TELLSTICK_TURNOFF_GLUE;
|
||||
PyObject *TELLSTICK_BELL_GLUE;
|
||||
PyObject *TELLSTICK_TOGGLE_GLUE;
|
||||
PyObject *TELLSTICK_DIM_GLUE;
|
||||
PyObject *TELLSTICK_LEARN_GLUE;
|
||||
PyObject *TELLSTICK_SUCCESS_GLUE;
|
||||
PyObject *TELLSTICK_ERROR_NOT_FOUND_GLUE;
|
||||
PyObject *TELLSTICK_ERROR_PERMISSION_DENIED_GLUE;
|
||||
PyObject *TELLSTICK_ERROR_DEVICE_NOT_FOUND_GLUE;
|
||||
PyObject *TELLSTICK_ERROR_METHOD_NOT_SUPPORTED_GLUE;
|
||||
PyObject *TELLSTICK_ERROR_COMMUNICATION_GLUE;
|
||||
PyObject *TELLSTICK_ERROR_UNKNOWN_GLUE;
|
||||
PyObject *TELLSTICK_TYPE_DEVICE_GLUE;
|
||||
PyObject *TELLSTICK_TYPE_GROUP_GLUE;
|
||||
PyObject *TELLSTICK_TEMPERATURE_GLUE;
|
||||
PyObject *TELLSTICK_HUMIDITY_GLUE;
|
||||
|
||||
/* Create the module and add the functions */
|
||||
|
||||
module = Py_InitModule("telldus", telldus_methods);
|
||||
|
||||
TELLSTICK_TURNON_GLUE = PyLong_FromLong((long) TELLSTICK_TURNON);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_TURNON", TELLSTICK_TURNON_GLUE);
|
||||
Py_DECREF(TELLSTICK_TURNON_GLUE);
|
||||
|
||||
TELLSTICK_TURNOFF_GLUE = PyLong_FromLong((long) TELLSTICK_TURNOFF);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_TURNOFF", TELLSTICK_TURNOFF_GLUE);
|
||||
Py_DECREF(TELLSTICK_TURNOFF_GLUE);
|
||||
|
||||
TELLSTICK_BELL_GLUE = PyLong_FromLong((long) TELLSTICK_BELL);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_BELL", TELLSTICK_BELL_GLUE);
|
||||
Py_DECREF(TELLSTICK_BELL_GLUE);
|
||||
|
||||
TELLSTICK_TOGGLE_GLUE = PyLong_FromLong((long) TELLSTICK_TOGGLE);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_TOGGLE", TELLSTICK_TOGGLE_GLUE);
|
||||
Py_DECREF(TELLSTICK_TOGGLE_GLUE);
|
||||
|
||||
TELLSTICK_DIM_GLUE = PyLong_FromLong((long) TELLSTICK_DIM);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_DIM", TELLSTICK_DIM_GLUE);
|
||||
Py_DECREF(TELLSTICK_DIM_GLUE);
|
||||
|
||||
TELLSTICK_LEARN_GLUE = PyLong_FromLong((long) TELLSTICK_LEARN);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_LEARN", TELLSTICK_LEARN_GLUE);
|
||||
Py_DECREF(TELLSTICK_LEARN_GLUE);
|
||||
|
||||
TELLSTICK_SUCCESS_GLUE = PyLong_FromLong((long) TELLSTICK_SUCCESS);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_SUCCESS", TELLSTICK_SUCCESS_GLUE);
|
||||
Py_DECREF(TELLSTICK_SUCCESS_GLUE);
|
||||
|
||||
TELLSTICK_ERROR_NOT_FOUND_GLUE = PyLong_FromLong((long) TELLSTICK_ERROR_NOT_FOUND);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_ERROR_NOT_FOUND", TELLSTICK_ERROR_NOT_FOUND_GLUE);
|
||||
Py_DECREF(TELLSTICK_ERROR_NOT_FOUND_GLUE);
|
||||
|
||||
TELLSTICK_ERROR_PERMISSION_DENIED_GLUE = PyLong_FromLong((long) TELLSTICK_ERROR_PERMISSION_DENIED);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_ERROR_PERMISSION_DENIED", TELLSTICK_ERROR_PERMISSION_DENIED_GLUE);
|
||||
Py_DECREF(TELLSTICK_ERROR_PERMISSION_DENIED_GLUE);
|
||||
|
||||
TELLSTICK_ERROR_DEVICE_NOT_FOUND_GLUE = PyLong_FromLong((long) TELLSTICK_ERROR_DEVICE_NOT_FOUND);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_ERROR_DEVICE_NOT_FOUND", TELLSTICK_ERROR_DEVICE_NOT_FOUND_GLUE);
|
||||
Py_DECREF(TELLSTICK_ERROR_DEVICE_NOT_FOUND_GLUE);
|
||||
|
||||
TELLSTICK_ERROR_METHOD_NOT_SUPPORTED_GLUE = PyLong_FromLong((long) TELLSTICK_ERROR_METHOD_NOT_SUPPORTED);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_ERROR_METHOD_NOT_SUPPORTED", TELLSTICK_ERROR_METHOD_NOT_SUPPORTED_GLUE);
|
||||
Py_DECREF(TELLSTICK_ERROR_METHOD_NOT_SUPPORTED_GLUE);
|
||||
|
||||
TELLSTICK_ERROR_COMMUNICATION_GLUE = PyLong_FromLong((long) TELLSTICK_ERROR_COMMUNICATION);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_ERROR_COMMUNICATION", TELLSTICK_ERROR_COMMUNICATION_GLUE);
|
||||
Py_DECREF(TELLSTICK_ERROR_COMMUNICATION_GLUE);
|
||||
|
||||
TELLSTICK_ERROR_UNKNOWN_GLUE = PyLong_FromLong((long) TELLSTICK_ERROR_UNKNOWN);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_ERROR_UNKNOWN", TELLSTICK_ERROR_UNKNOWN_GLUE);
|
||||
Py_DECREF(TELLSTICK_ERROR_UNKNOWN_GLUE);
|
||||
|
||||
TELLSTICK_TYPE_DEVICE_GLUE = PyLong_FromLong((long) TELLSTICK_TYPE_DEVICE);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_TYPE_DEVICE", TELLSTICK_TYPE_DEVICE_GLUE);
|
||||
Py_DECREF(TELLSTICK_TYPE_DEVICE_GLUE);
|
||||
|
||||
TELLSTICK_TYPE_GROUP_GLUE = PyLong_FromLong((long) TELLSTICK_TYPE_GROUP);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_TYPE_GROUP", TELLSTICK_TYPE_GROUP_GLUE);
|
||||
Py_DECREF(TELLSTICK_TYPE_GROUP_GLUE);
|
||||
|
||||
TELLSTICK_TEMPERATURE_GLUE = PyLong_FromLong((long) TELLSTICK_TEMPERATURE);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_TEMPERATURE", TELLSTICK_TEMPERATURE_GLUE);
|
||||
Py_DECREF(TELLSTICK_TEMPERATURE_GLUE);
|
||||
|
||||
TELLSTICK_HUMIDITY_GLUE = PyLong_FromLong((long) TELLSTICK_HUMIDITY);
|
||||
PyObject_SetAttrString(module, "TELLSTICK_HUMIDITY", TELLSTICK_HUMIDITY_GLUE);
|
||||
Py_DECREF(TELLSTICK_HUMIDITY_GLUE);
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
%module tellduscore
|
||||
%{
|
||||
#include "../../telldus-core/driver/libtelldus-core/telldus-core.h"
|
||||
%}
|
||||
|
||||
%include "../../telldus-core/driver/libtelldus-core/telldus-core.h"
|
|
@ -1,17 +0,0 @@
|
|||
Attribute VB_Name = "TellStickModule"
|
||||
Public Declare Function devTurnOn Lib "TellUsbD101.dll" (ByVal lngDeviceId As Long) As Boolean
|
||||
Public Declare Function devTurnOff Lib "TellUsbD101.dll" (ByVal lngDeviceId As Long) As Boolean
|
||||
Public Declare Function devBell Lib "TellUsbD101.dll" (ByVal lngDeviceId As Long) As Boolean
|
||||
Public Declare Function devDim Lib "TellUsbD101.dll" (ByVal lngDeviceId As Long, ByVal level As Byte) As Boolean
|
||||
Public Declare Function devMethods Lib "TellUsbD101.dll" (ByVal lngDeviceId As Long) As Long
|
||||
|
||||
Public Declare Function devGetDeviceId Lib "TellUsbD101.dll" (ByVal a As Long) As Long
|
||||
Public Declare Function devGetName Lib "TellUsbD101.dll" (ByVal i As Long) As String
|
||||
Public Declare Function devGetNumberOfDevices Lib "TellUsbD101.dll" () As Long
|
||||
|
||||
Public Const TELLSTICK_TURNON = 1
|
||||
Public Const TELLSTICK_TURNOFF = 2
|
||||
Public Const TELLSTICK_BELL = 4
|
||||
Public Const TELLSTICK_TOGGLE = 8
|
||||
Public Const TELLSTICK_DIM = 16
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
VERSION 5.00
|
||||
Begin VB.Form frmMain
|
||||
BorderStyle = 4 'Fixed ToolWindow
|
||||
Caption = "TellStick VB-example - simple"
|
||||
ClientHeight = 4680
|
||||
ClientLeft = 2040
|
||||
ClientTop = 3600
|
||||
ClientWidth = 3990
|
||||
Icon = "TellStick VB-example - simple.frx":0000
|
||||
LinkTopic = "Form1"
|
||||
MaxButton = 0 'False
|
||||
MinButton = 0 'False
|
||||
ScaleHeight = 4680
|
||||
ScaleWidth = 3990
|
||||
ShowInTaskbar = 0 'False
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "90%"
|
||||
Height = 465
|
||||
Index = 8
|
||||
Left = 3480
|
||||
TabIndex = 12
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "80%"
|
||||
Height = 465
|
||||
Index = 7
|
||||
Left = 3060
|
||||
TabIndex = 11
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "70%"
|
||||
Height = 465
|
||||
Index = 6
|
||||
Left = 2640
|
||||
TabIndex = 10
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "60%"
|
||||
Height = 465
|
||||
Index = 5
|
||||
Left = 2220
|
||||
TabIndex = 9
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "50%"
|
||||
Height = 465
|
||||
Index = 4
|
||||
Left = 1800
|
||||
TabIndex = 8
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "40%"
|
||||
Height = 465
|
||||
Index = 3
|
||||
Left = 1380
|
||||
TabIndex = 7
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "30%"
|
||||
Height = 465
|
||||
Index = 2
|
||||
Left = 960
|
||||
TabIndex = 6
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "20%"
|
||||
Height = 465
|
||||
Index = 1
|
||||
Left = 540
|
||||
TabIndex = 5
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdDim
|
||||
Caption = "10%"
|
||||
Height = 465
|
||||
Index = 0
|
||||
Left = 120
|
||||
TabIndex = 4
|
||||
Top = 4110
|
||||
Width = 420
|
||||
End
|
||||
Begin VB.CommandButton cmdBell
|
||||
Caption = "Bell"
|
||||
Height = 735
|
||||
Left = 1500
|
||||
Picture = "TellStick VB-example - simple.frx":0ECA
|
||||
Style = 1 'Graphical
|
||||
TabIndex = 3
|
||||
Top = 3285
|
||||
Width = 1000
|
||||
End
|
||||
Begin VB.ListBox deviceList
|
||||
Height = 3180
|
||||
Left = 60
|
||||
TabIndex = 2
|
||||
Top = 60
|
||||
Width = 3810
|
||||
End
|
||||
Begin VB.CommandButton cmdOff
|
||||
Caption = "Off"
|
||||
Height = 735
|
||||
Left = 120
|
||||
Picture = "TellStick VB-example - simple.frx":1794
|
||||
Style = 1 'Graphical
|
||||
TabIndex = 1
|
||||
Top = 3285
|
||||
Width = 1000
|
||||
End
|
||||
Begin VB.CommandButton cmdOn
|
||||
Caption = "On"
|
||||
Height = 735
|
||||
Left = 2900
|
||||
Picture = "TellStick VB-example - simple.frx":205E
|
||||
Style = 1 'Graphical
|
||||
TabIndex = 0
|
||||
Top = 3285
|
||||
Width = 1000
|
||||
End
|
||||
End
|
||||
Attribute VB_Name = "frmMain"
|
||||
Attribute VB_GlobalNameSpace = False
|
||||
Attribute VB_Creatable = False
|
||||
Attribute VB_PredeclaredId = True
|
||||
Attribute VB_Exposed = False
|
||||
Private Sub cmdBell_Click()
|
||||
Dim blnBell As Boolean
|
||||
blnBell = devBell(deviceList.ItemData(deviceList.ListIndex))
|
||||
End Sub
|
||||
|
||||
Private Sub cmdDim_Click(Index As Integer)
|
||||
Dim blnDim As Boolean
|
||||
Dim level As Byte
|
||||
Select Case Index
|
||||
Case "8"
|
||||
level = 230
|
||||
Case "7"
|
||||
level = 204
|
||||
Case "6"
|
||||
level = 179
|
||||
Case "5"
|
||||
level = 153
|
||||
Case "4"
|
||||
level = 128
|
||||
Case "3"
|
||||
level = 102
|
||||
Case "2"
|
||||
level = 77
|
||||
Case "1"
|
||||
level = 51
|
||||
Case "0"
|
||||
level = 25
|
||||
End Select
|
||||
blnDim = devDim(deviceList.ItemData(deviceList.ListIndex), level)
|
||||
End Sub
|
||||
|
||||
Private Sub cmdOff_Click()
|
||||
Dim blnOff As Boolean
|
||||
blnOff = devTurnOff(deviceList.ItemData(deviceList.ListIndex))
|
||||
End Sub
|
||||
|
||||
Private Sub cmdOn_Click()
|
||||
Dim blnOn As Boolean
|
||||
blnOn = devTurnOn(deviceList.ItemData(deviceList.ListIndex))
|
||||
End Sub
|
||||
|
||||
Private Sub deviceList_Click()
|
||||
Dim intMethods As Integer
|
||||
|
||||
intMethods = devMethods(deviceList.ItemData(deviceList.ListIndex))
|
||||
cmdOn.Enabled = (intMethods And TELLSTICK_TURNON)
|
||||
cmdOff.Enabled = (intMethods And TELLSTICK_TURNOFF)
|
||||
cmdBell.Enabled = (intMethods And TELLSTICK_BELL)
|
||||
|
||||
For a = 0 To 8
|
||||
cmdDim(a).Enabled = (intMethods And TELLSTICK_DIM)
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub Form_Load()
|
||||
|
||||
Dim numDevices As Integer, i As Integer
|
||||
numDevices = devGetNumberOfDevices()
|
||||
|
||||
For i = 0 To numDevices - 1
|
||||
Dim strName As String
|
||||
Dim intId As Integer
|
||||
|
||||
intId = devGetDeviceId(i)
|
||||
strName = devGetName(intId)
|
||||
deviceList.AddItem strName
|
||||
deviceList.ItemData(i) = intId
|
||||
Next
|
||||
|
||||
deviceList.ListIndex = 0
|
||||
|
||||
End Sub
|
Binary file not shown.
|
@ -1,36 +0,0 @@
|
|||
Type=Exe
|
||||
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\..\..\WINDOWS\system32\STDOLE2.TLB#OLE Automation
|
||||
Form=TellStick VB-example - simple.frm
|
||||
Module=TellStickModule; ..\TellStick.bas
|
||||
Startup="frmMain"
|
||||
HelpFile=""
|
||||
ExeName32="TellStick VB-example - simple.exe"
|
||||
Command32=""
|
||||
Name="TellStickExample"
|
||||
HelpContextID="0"
|
||||
CompatibleMode="0"
|
||||
MajorVer=1
|
||||
MinorVer=0
|
||||
RevisionVer=0
|
||||
AutoIncrementVer=0
|
||||
ServerSupportFiles=0
|
||||
VersionCompanyName="Telldus Technologies"
|
||||
CompilationType=0
|
||||
OptimizationType=0
|
||||
FavorPentiumPro(tm)=0
|
||||
CodeViewDebugInfo=0
|
||||
NoAliasing=0
|
||||
BoundsCheck=0
|
||||
OverflowCheck=0
|
||||
FlPointCheck=0
|
||||
FDIVCheck=0
|
||||
UnroundedFP=0
|
||||
StartMode=0
|
||||
Unattended=0
|
||||
Retained=0
|
||||
ThreadPerObject=0
|
||||
MaxNumberOfThreads=1
|
||||
DebugStartupOption=0
|
||||
|
||||
[MS Transaction Server]
|
||||
AutoRefresh=1
|
|
@ -1,351 +0,0 @@
|
|||
/**
|
||||
* @mainpage Telldus Core API
|
||||
*
|
||||
* \section Introduction
|
||||
*
|
||||
* This is the guide to Telldus TellStick SDK. Even though all examples are
|
||||
* written in C/C++ most of the code has a direct eqvivalent function in the
|
||||
* other languages. See \ref sec_other_languages how to use the library in one
|
||||
* of the supported languages by Telldus.
|
||||
*
|
||||
* \section Idea
|
||||
*
|
||||
* All of the devices used by TellStick must be predefined before they can be
|
||||
* used in any software. Under all platforms this can be done with the
|
||||
* software TelldusCenter but under Linux this can also be done by editing the
|
||||
* file <tt>/etc/tellstick.conf</tt> with your favorite text editor.
|
||||
*
|
||||
* Having the devices preconfigured is an advantage to both the developer and
|
||||
* the end user.
|
||||
*
|
||||
* \li The end user might use more then one program for controlling his/her
|
||||
* TellStick. By having the devices preconfigured he/she does not have to
|
||||
* reconfigure the same devices twice. If some settings change in one of the
|
||||
* devices, this change will affect all softwares using Telldus TellStick SDK.
|
||||
* \li Telldus continuously adds support for new devices. If a software
|
||||
* defines it's own devices, the developer will have to keep the software
|
||||
* up to date with new devices and settings implemented by Telldus. By querying
|
||||
* Telldus Tellstick SDK all the new devices will be available automaticly to
|
||||
* the end user.
|
||||
*
|
||||
* \section sec_basic_usage Basic usage (telldus-core)
|
||||
*
|
||||
* Telldus provides a non-gui library to list, query and control the devices
|
||||
* called telldus-core.
|
||||
* To initiate the library a call to tdInit() must be made. This call will
|
||||
* open up all controllers (e.g. a TellStick) and start listening for events from
|
||||
* them.
|
||||
* When you are done with telldus-core, call tdClose() to allow the library to
|
||||
* clean up after itself.
|
||||
*
|
||||
* \subsection sec_bu_listing Listing devices
|
||||
*
|
||||
* To list all of the configured devices, look at the following example:
|
||||
* \code
|
||||
* int intNumberOfDevices = tdGetNumberOfDevices();
|
||||
* for (int i = 0; i < intNumberOfDevices; i++) {
|
||||
* int id = tdGetDeviceId( i );
|
||||
* char *name = tdGetName( id );
|
||||
* printf("%d\t%s\n", id, name);
|
||||
* tdReleaseString(name);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* First, we call tdGetNumberOfDevices(). This returnes the total number of
|
||||
* devices configured. We then iterate over all of the devices with the index
|
||||
* in the variable \c i.
|
||||
* Since the devices could change between runs of the program we can not be
|
||||
* sure that the index points to the same device between two runs of the
|
||||
* program. That is why every device has it's own unique id that is safe to
|
||||
* store in a configuration file. Two different devices can never share the
|
||||
* same device id.
|
||||
*
|
||||
* The call to tdGetDeviceId() returns the id for a specific index. This
|
||||
* function should only be called in a loop iterating over all of the devices.
|
||||
* After we have found the id for a device it is safe to store this or use it
|
||||
* in the rest of the program.
|
||||
*
|
||||
* The next two lines of code queries the device for it's name with a call to
|
||||
* tdGetName() and then displays it to stdout. Finally we must release the
|
||||
* resource after we are done with it by calling tdReleaseString() on any
|
||||
* \c char pointer returned by telldus-core.
|
||||
*
|
||||
* \subsection sec_bu_sending Sending commands to TellStick
|
||||
*
|
||||
* \subsubsection sec_bu_sending_features Device features
|
||||
*
|
||||
* TellStick can control many different types of devices that
|
||||
* support different features. For example, a bell does not support turning
|
||||
* the on-signal and not all lamp switches support dimming.
|
||||
* Call tdMethods() to find out what a specific device supports:
|
||||
* \code
|
||||
* function checkFeatures( int id ) {
|
||||
* int supportedMethods = TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_BELL;
|
||||
* int methods = tdMethods( id, supportedMethods );
|
||||
* if ( methods & TELLSTICK_TURNON ) {
|
||||
* printf( "The device %d support tdTurnOn()\n", id );
|
||||
* }
|
||||
* if ( methods & TELLSTICK_TURNOFF ) {
|
||||
* printf( "The device %d support tdTurnOff()\n", id );
|
||||
* }
|
||||
* if ( methods & TELLSTICK_BELL ) {
|
||||
* printf( "The device %d support tdBell()\n", id );
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* By supplying the methods your application supports, the library can return
|
||||
* customized methods for your application, even if your application doesn't
|
||||
* support the same methods as the device accepts. One example is if your
|
||||
* application only supports ON and OFF, you can control a device that needs UP
|
||||
* and DOWN anyway by using just ON and OFF.
|
||||
* Let's say that the client application only supports turning on and
|
||||
* off. The call to query a device for it's methods should be:
|
||||
* \code
|
||||
* int methods = tdMethods( id, TELLSTICK_TURNON | TELLSTICK_TURNOFF );
|
||||
* \endcode
|
||||
* If the device in the above example is a device only supporing TELLSTICK_BELL,
|
||||
* the library will instead return TELLSTICK_TURNON, making the client application
|
||||
* still able to control the device.
|
||||
* When you know which features a device supports it is safe to call the
|
||||
* controlling functions described in \ref sec_bu_controlling_functions.
|
||||
*
|
||||
* When calling tdMethods() all of the supported methods should be passed in one
|
||||
* call. Do not call tdMethods() for each of the supported methods. Look at the
|
||||
* following example:
|
||||
* \code
|
||||
* //Correct
|
||||
* int methods = tdMethods( id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_BELL );
|
||||
*
|
||||
* //Wrong
|
||||
* int turnOn = tdMethods( id, TELLSTICK_TURNON );
|
||||
* int turnOff = tdMethods( id, TELLSTICK_TURNOFF );
|
||||
* int bell = tdMethods( id, TELLSTICK_BELL );
|
||||
* \endcode
|
||||
*
|
||||
* Another thing to note is if you are developing a library intended for
|
||||
* thirdparty use. You should not hardcode which methods are supported by the
|
||||
* library. It is always up to the application implementing the methods to
|
||||
* supply the methods it supports.
|
||||
*
|
||||
* \subsubsection sec_bu_controlling_functions Controlling functions
|
||||
*
|
||||
* TellStick has a couple of functions for controlling devices. Each of
|
||||
* them should only be called if the device support the feature.
|
||||
*
|
||||
* These functions all return zero if the call was successful and non-zero
|
||||
* otherwise.
|
||||
*
|
||||
* \paragraph tdTurnOn tdTurnOn()
|
||||
* Devices supporting \c TELLSTICK_TURNON. Most of the normal switches (for lamp
|
||||
* etc.) support this.
|
||||
* \paragraph tdTurnOff tdTurnOff()
|
||||
* Devices supporting \c TELLSTICK_TURNOFF. Almost all of the devices supporting
|
||||
* \c TELLSTICK_TURNON also support this.
|
||||
* \paragraph tdDim tdDim()
|
||||
* Devices supporting \c TELLSTICK_DIM. This is a quite unusual feature for
|
||||
* dimmers. Many dimmers on the market that are dimmable have no way for sending
|
||||
* a specific level which means it does not support this feature.
|
||||
* \paragraph tdBell tdBell()
|
||||
* Devices supporting \c TELLSTICK_BELL. This is mostly wireless doorbells.
|
||||
*
|
||||
* \subsubsection sec_bu_error_codes Error codes
|
||||
*
|
||||
* If any of the calls in \ref sec_bu_controlling_functions fails it returns
|
||||
* a non-zero error code. This values is one of the \c TELLSTICK_ERROR_* defines.
|
||||
* To translate the error code to a human readable string call the function
|
||||
* tdGetErrorString(). Example:
|
||||
* \code
|
||||
* printf("Error: %s\n", tdGetErrorString( TELLSTICK_METHOD_NOT_SUPPORTED ) );
|
||||
* //Error: The method you tried to use is not supported by the device
|
||||
*
|
||||
* int retval = tdTurnOn( deviceID );
|
||||
* if (retval != TELLSTICK_SUCCESS ) {
|
||||
* char *errorString = tdGetErrorString( retval );
|
||||
* printf("Error: %s\n", errorString );
|
||||
* tdReleaseString(errorString);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \subsection sec_bu_device_state Device states
|
||||
*
|
||||
* Since controllable devices only have a receiver and not a transmitter the communication is
|
||||
* one-way. This means that telldus-core will never know for sure which
|
||||
* state a reciever has. Instead, the library remembers which command was last
|
||||
* sent. Either sent from the TellStick itself, or sent from another controller (e.g. a remote control)
|
||||
* captured by the Tellstick Duo. In this way it "emulates" a two-way communication.
|
||||
*
|
||||
* To query the device state, use the function tdLastSentCommand()
|
||||
*
|
||||
* Example:
|
||||
* \code
|
||||
* char *name = tdGetName( id );
|
||||
* int state = tdLastSentCommand( id );
|
||||
* if (state == TELLSTICK_TURNON) {
|
||||
* printf("%s is on\n", name);
|
||||
* } else if (state == TELLSTICK_TURNOFF) {
|
||||
* printf("%s is off\n", name);
|
||||
* } else {
|
||||
* printf("%s is in an unknown state\n", name);
|
||||
* }
|
||||
* tdReleaseString(name);
|
||||
* \endcode
|
||||
*
|
||||
* \subsection sec_bu_sensors Sensors
|
||||
*
|
||||
* Retrieving sensor values can be done in two ways. Either by a polling
|
||||
* interface or by callbacks. The client application can implement one or both
|
||||
* of these interfaces. For callbacks, read more under \ref sec_events.
|
||||
*
|
||||
* Each of the sensors can have one or several value types. Currently only
|
||||
* temperature and humidity are implemented.
|
||||
*
|
||||
* There is no API to add, remove or edit sensors. Each sensor that
|
||||
* TellStick Duo has got any data from is added to an internal list. It is up to
|
||||
* the client application to filter and only show the sensors your are
|
||||
* interested in.
|
||||
*
|
||||
* To iterate over the list of sensors, call tdSensor() repeatedly as long as it
|
||||
* returns \c TELLSTICK_SUCCESS. The parameters \c protocol, \c model,
|
||||
* \c sensorId, and \c dataTypes are sent by reference and will be filled with
|
||||
* the values.
|
||||
*
|
||||
* Example:
|
||||
* \code
|
||||
* char protocol[DATA_LENGTH], model[DATA_LENGTH];
|
||||
* int sensorId = 0, dataTypes = 0;
|
||||
* while(tdSensor(protocol, DATA_LENGTH, model, DATA_LENGTH, &sensorId, &dataTypes) == TELLSTICK_SUCCESS) {
|
||||
* //Print the sensor
|
||||
* printf("%s,\t%s,\t%i\n", protocol, model, sensorId);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* The type of sensor values the sensor supports are stored as flags in the
|
||||
* parameter \c sensorId. Call tdSensorValue() for each type.
|
||||
*
|
||||
* Example:
|
||||
* \code
|
||||
* char value[DATA_LENGTH];
|
||||
* char timeBuf[80];
|
||||
* time_t timestamp = 0;
|
||||
* if (dataTypes & TELLSTICK_TEMPERATURE) {
|
||||
* tdSensorValue(protocol, model, sensorId, TELLSTICK_TEMPERATURE, value, DATA_LENGTH, (int *)×tamp);
|
||||
* strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp));
|
||||
* printf("Temperature:\t%sº\t(%s)\n", value, timeBuf);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \section sec_events Events
|
||||
*
|
||||
* To get events from either a TellStick Duo, another software changes the
|
||||
* status of a device, or new sensors values you have to register for a callback.
|
||||
*
|
||||
* \subsection sec_events_registering Registering for callbacks
|
||||
*
|
||||
* For each callback there is a corresponding register function:
|
||||
* \li tdRegisterDeviceEvent()
|
||||
* \li tdRegisterDeviceChangeEvent()
|
||||
* \li tdRegisterRawDeviceEvent()
|
||||
* \li tdRegisterSensorEvent()
|
||||
*
|
||||
* These all work in the same way. The first parameter is a function-pointer to
|
||||
* the callback function. The second parameter is an optional void pointer. This
|
||||
* can be anything and is dependent on the implementation. This object will be
|
||||
* sent back to each call to the callback function. The functions return an
|
||||
* integer which is an id to the specific callback. This is is sent as a
|
||||
* parameter in each call and should also be used for unregister the callback.
|
||||
*
|
||||
* Please note that the callback will be called by another thread than the
|
||||
* thread used by the application and some measures must be taken to synchronize
|
||||
* it with the main thread.
|
||||
*
|
||||
* Many devices (for example motion detectors) resends their messages many times
|
||||
* to ensure that they are received correctly. If a deviceeventcallback or
|
||||
* rawdeviceeventcallback in turn is calling a controlling function, for example
|
||||
* tdTurnOn, it may be neccessary to implement some solution to wait for the
|
||||
* device to finish its resending, before executing the controlling function.
|
||||
* See how this can be done in the python example.
|
||||
*
|
||||
* \subsection sec_events_callbacks Callbacks
|
||||
*
|
||||
* telldus-core currently implements four different callback function for
|
||||
* different purposes.
|
||||
*
|
||||
* \subsubsection sec_events_callbacks_deviceevent DeviceEvent
|
||||
*
|
||||
* This event is fired when the state of a device changes. This can either
|
||||
* occur via a remote control, but can as well occur via another software on the
|
||||
* computer.
|
||||
*
|
||||
* Parameters:
|
||||
* - int deviceId - The device id of the device that changed.
|
||||
* - int method - The new state. Can be TELLSTICK_TURNON, TELLSTICK_TURNOFF
|
||||
* etc.
|
||||
* - const char *data - For some methods this contains data. For TELLSTICK_DIM
|
||||
* this hold the current value.
|
||||
* - int callbackId - id of callback
|
||||
* - void *context - see \ref sec_events_registering for description
|
||||
*
|
||||
* \subsubsection sec_events_callbacks_devicechangeevent DeviceChangeEvent
|
||||
*
|
||||
* This event is fired when the data around a device is changed. It can only be
|
||||
* triggered by another software. Use this callback to keep your list of devices
|
||||
* in sync.
|
||||
*
|
||||
* Parameters:
|
||||
* - int deviceId - The device id of the device that changed.
|
||||
* - int changeEvent - What was changed. This can be:
|
||||
* - TELLSTICK_DEVICE_ADDED - A new device was added. The parameter deviceId
|
||||
* holds the id of the new device.
|
||||
* - TELLSTICK_DEVICE_REMOVED - A device was removed, the parameter deviceId
|
||||
* holds the id of the removed device.
|
||||
* - TELLSTICK_DEVICE_CHANGED - The settings of a device changed. The next
|
||||
* parameter holds what was changed.
|
||||
* - int changeType - If changeEvent is TELLSTICK_DEVICE_CHANGED this parameter
|
||||
* holds what was changed. It can be one of the following:
|
||||
* - TELLSTICK_CHANGE_NAME - Use tdGetName() to read the new name.
|
||||
* - TELLSTICK_CHANGE_PROTOCOL - Use tdGetProtocol() to read the new value.
|
||||
* - TELLSTICK_CHANGE_MODEL - Use tdGetModel() to read the new value.
|
||||
* - int callbackId - id of callback
|
||||
* - void *context - see \ref sec_events_registering for description
|
||||
*
|
||||
* \subsubsection sec_events_callbacks_rawdeviceevent RawDeviceEvent
|
||||
*
|
||||
* Use this callback with caution. It outputs everything from a TellStick Duo
|
||||
* without any preprocessing. This can be used to get events from devices not
|
||||
* already configured.
|
||||
*
|
||||
* Parameters:
|
||||
* - const char *data - raw device data
|
||||
* - int controllerId - id of receiving controller, can identify the TellStick if several exists in the system
|
||||
* - int callbackId - id of callback
|
||||
* - void *context - see \ref sec_events_registering for description
|
||||
*
|
||||
* \subsubsection sec_events_callbacks_sensorevent SensorEvent
|
||||
*
|
||||
* This event is fired when a new sensor value is retrieved.
|
||||
*
|
||||
* Parameters:
|
||||
* - const char *protocol - The sensors protocol
|
||||
* - const char *model - The model of the sensor
|
||||
* - int id - The unique id for the sensor.
|
||||
* - int dataType - Flags for which types of data the sensor supports
|
||||
* - const char *value - A human readable string of the data
|
||||
* - int timestamp - The timestamp when the latest value was received
|
||||
* - int callbackId - id of callback
|
||||
* - void *context - See \ref sec_events_registering for description
|
||||
*
|
||||
* \subsection sec_events_example Example
|
||||
*
|
||||
* \section sec_other_languages Notes using other languages than C/C++
|
||||
*
|
||||
* \subsection sec_ol_pyhon Python
|
||||
*
|
||||
* To use telldus-core in Python,
|
||||
* please have look at the <tt>ctypes</tt> library. It contains <tt>cdll</tt> and
|
||||
* <tt>windll</tt> to load any dynamic link libraries.
|
||||
*
|
||||
* There is also a third party library available:
|
||||
* https://github.com/erijo/tellcore-py
|
||||
*
|
||||
*/
|
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* @page TellStick TellStick protocol
|
||||
*
|
||||
* \section Introduction
|
||||
*
|
||||
* Telldus TellStick protocol looks like:<br>
|
||||
* <tt>[prefix[prefix parameters]][command][parameter 1]..[parameter n]['+']</tt>
|
||||
*
|
||||
* Each value in <tt>[</tt> and <tt>]</tt> is representing one byte.
|
||||
*
|
||||
* Command is one ascii character. Not all commands have parameters which
|
||||
* makes it optional. Prefix is always optional.
|
||||
* Note: Due to memory limitations, the parameters is limited in length to 79
|
||||
* bytes.
|
||||
*
|
||||
* An example command to turn on a ArcTech codeswitch A1 may look like:
|
||||
* <tt>S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+</tt>
|
||||
*
|
||||
* TellStick returns to a known command like this:<br>
|
||||
* <tt>['+'][command][parameters][13][10]</tt>
|
||||
*
|
||||
* <tt>[13]</tt> and <tt>[10]</tt> are the ascii characters 10 and 13.
|
||||
*
|
||||
* An example to query a TellStick on its firmware version:<br>
|
||||
* Command:<br>
|
||||
* <tt>V+</tt><br>
|
||||
* Response:<br>
|
||||
* <tt>+V2</tt><br>
|
||||
* The TellStick in the example has the firmware version 2.
|
||||
*
|
||||
* \section Commands
|
||||
*
|
||||
* \subsection sec_send S - Send command
|
||||
* This command tells TellStick to send a command. The parameters to this
|
||||
* command is the data-packet to send.
|
||||
*
|
||||
* Each of the characters in the parameters makes the antenna alternate
|
||||
* high/low/high etc. The time before the alternation is 10 us timer the ASCII
|
||||
* value. For example, $ has the ascii-value 36 and k has 107. The command:
|
||||
* <tt>['S']['$']['k']['$']['k']['$']['+']</tt> makes the following wavepattern on the antenna:
|
||||
* <pre>
|
||||
* _____ _____ _____
|
||||
* | | | | | |
|
||||
* | | | | | |
|
||||
* | |_______________| |_______________| |
|
||||
*
|
||||
* |<===>|<=============>|<===>|<=============>|<===>|
|
||||
* 360us 1070us 360us 1070us 360us
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* \subsection sec_send_extended T - Send command, extended
|
||||
*
|
||||
* The extended command was developed to overcome the limitations och the
|
||||
* length of the data to 79 bytes.
|
||||
* The idea is to have four fixed times on the pulses so the information about
|
||||
* what to send only needs 2 bits instead of 8 in the command <tt>S</tt>
|
||||
*
|
||||
* The parameters to the command is:<br>
|
||||
* <tt>[t0][t1][t2][t3][length][d1]..[dn]</tt>
|
||||
*
|
||||
* <tt>t0-t3</tt>: Times 1 to 4. The times are in the same form as <tt>S</tt>.
|
||||
* Each time is multiplied with the factor of 10.
|
||||
*
|
||||
* <tt>length</tt>: How many pulses to send. Since the data sent to TellStick
|
||||
* is sent in groups of four pulses (one byte) and the actual data might not
|
||||
* have pulses even divided with four.
|
||||
*
|
||||
* <tt>d1..dn</tt>: Each byte is the description for four pulses.
|
||||
*
|
||||
* Example:<br>
|
||||
* <tt>['T'][127][255][24][1][6][98][80]['+']</tt>
|
||||
*
|
||||
* <tt>T</tt>: Send extended.
|
||||
*
|
||||
* <tt>127,255,24,1</tt>: Times 1270 us, 2550 us, 24 us and 10 us
|
||||
*
|
||||
* <tt>6</tt>: Six pulses to send.
|
||||
*
|
||||
* <tt>98,80</tt>: The data in binary is <tt>10011000</tt>,<tt>10000000</tt>. If
|
||||
* we group it in groups of two bits we get <tt>10 01 10 00 10 00 00 00</tt>.
|
||||
* Since the length is only six pulses the last two pulses is discarded, giving:
|
||||
* <tt>10 01 10 00 10 00</tt>.
|
||||
*
|
||||
* Matching those bits to the times gives the following times:<br>
|
||||
* <tt>10 => 2 => t2 => 240 us</tt><br>
|
||||
* <tt>01 => 1 => t1 => 2550 us</tt><br>
|
||||
* <tt>10 => 2 => t2 => 240 us</tt><br>
|
||||
* <tt>00 => 0 => t0 => 1270 us</tt><br>
|
||||
* <tt>10 => 2 => t2 => 240 us</tt><br>
|
||||
* <tt>00 => 0 => t0 => 1270 us</tt><br>
|
||||
*
|
||||
* This is equal if you used <tt>S</tt>:<br>
|
||||
* <tt>['S'][24][255][24][127][24][127]['+']</tt>
|
||||
*
|
||||
* \subsection sec_version V - Firmware version
|
||||
* This command queries the TellStick on its firmware version.
|
||||
*
|
||||
* Example:<br>
|
||||
* <tt>» V+</tt><br>
|
||||
* <tt>« +V2</tt><br>
|
||||
* \section Prefixes
|
||||
* The prefixes are commands that can be prepended before some of the commands
|
||||
* and cannot be used standalone. They are used to alter the behavior of the
|
||||
* command.
|
||||
*
|
||||
* \subsection sec_debug D - Debug
|
||||
* \subsection sec_pause P - Pause
|
||||
* The pause is how low TellStick will wait between two packets. The value is
|
||||
* in ms.
|
||||
*
|
||||
* Example, % has the ascii-value 37. The following packet will be sent with a
|
||||
* pause of 37 ms between the packets:<br>
|
||||
* <tt>» P\%S$k$k$+</tt>
|
||||
*
|
||||
* \subsection sec_repeat R - Repeat
|
||||
* This tells TellStick how many times to send the packet.
|
||||
*
|
||||
* Example, ! has the ascii-value 33. The following packet will be sent 33
|
||||
* times:<br>
|
||||
* <tt>» R!S$k$k$+</tt>
|
||||
*/
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
* @page TellStickNet TellStick Net protocol
|
||||
*
|
||||
* \section Introduction
|
||||
*
|
||||
* TellStick Net will eventually support local access through the LAN. This is
|
||||
* unsupported by Telldus Technologies but can be useful in some cases. For
|
||||
* instance in mobile devices or when the internet is not available. Using
|
||||
* TellStick Net through Telldus Live! is still the prefered and supported
|
||||
* method.
|
||||
*
|
||||
* <em>This interface is still under development and is not ready for
|
||||
* production.</em>
|
||||
*
|
||||
* \section autodiscovery Auto discovery
|
||||
*
|
||||
* The TellStick Net can be auto discovered on the LAN using UDP broadcast.
|
||||
* Sending a package to the broadcast address 255.255.255.255 port 30303 will
|
||||
* be responded by any TellStick Net on the network. The packet should only
|
||||
* contain the single character 'D' (ascii number 68).
|
||||
*
|
||||
* The response from the device will be sent back to the same host and port as
|
||||
* the originated packet. So any dynamically port can be assigned by the host
|
||||
* implementing the auto discovery.
|
||||
* The returning packet is constructed in the following way:
|
||||
* <tt>product:mac address:activation code:firmware</tt>
|
||||
*
|
||||
* Example:<br>
|
||||
* <tt>TellStickNet:ABCDEFGHIJKL:ABDCEFGHIJ:2</tt><br>
|
||||
* Product: <tt>TellStick Net (TSNET)</tt><br>
|
||||
* Mac address: <tt>AB:CD:EF:GH:IJ:KL</tt><br>
|
||||
* Code for activation: <tt>ABCDEFGHIJ</tt><br>
|
||||
* Firmware version: <tt>2</tt>
|
||||
*
|
||||
* Use the source ip-address to determine the address to the device.
|
||||
*
|
||||
* \section messageformat Message format
|
||||
*
|
||||
* The message format used to communicate with TellStick Net is designed to be
|
||||
* easily parsed but still be flexible. It can be converted to and from json
|
||||
* without losing information.
|
||||
*
|
||||
* There exists four datatypes; string, integer, list and dictionary:
|
||||
*
|
||||
* - Strings are length-prefixed base sixteen (upper case) followed by a colon
|
||||
* and the string. For example 6:FooBar corresponds to 'FooBar'.
|
||||
*
|
||||
* - Integers are represented by an 'i' followed by the number in base 16
|
||||
* followed by an 's'. For example i3s corresponds to 3 and i-3s corresponds
|
||||
* to -3. Integers have no size limitation. i-0s is invalid. All encodings
|
||||
* with a leading zero, such as i03s, are invalid, other than i0s, which of
|
||||
* course corresponds to 0.
|
||||
*
|
||||
* - Lists are encoded as an 'l' followed by their elements (also encoded)
|
||||
* followed by an 's'. For example l3:foo3:bars corresponds to ['foo', 'bar'].
|
||||
*
|
||||
* - Dictionaries are encoded as a 'h' followed by a list of alternating keys and
|
||||
* their corresponding values followed by an 's'. For example,
|
||||
* h3:foo3:bar5:hello5:worlds corresponds to {'foo': 'bar', 'hello': 'world'}
|
||||
* and h3:fool3:bar3:bazss corresponds to {'foo': ['bar', 'baz']}. Keys must
|
||||
* be strings.
|
||||
*
|
||||
* Communication with TellStick Net is done over UDP on port 42314.
|
||||
* The first string sent contains the command to execute. The following python
|
||||
* example sends a disconnection command to a TellStick Net. This will reboot
|
||||
* the device.
|
||||
* \code
|
||||
* from socket import *
|
||||
* UDPSock = socket(AF_INET,SOCK_DGRAM)
|
||||
* UDPSock.sendto("A:disconnect", ("192.168.0.155",42314))
|
||||
* \endcode
|
||||
* \section tellstick_net_command_send Send command
|
||||
*
|
||||
* For readability the examples will be displayed in json format in this
|
||||
* documentation. They must be encoded using the TellStick Net message format
|
||||
* before sending to an actual TellStick Net.
|
||||
*
|
||||
* Sending RF-data uses the same encoding as TellStick \ref sec_send with the
|
||||
* difference that prefixes should be sent as a parameter and not in the
|
||||
* RF-data.
|
||||
*
|
||||
* The parameters are sent encoded in a dictionary, with the RF-data in the key
|
||||
* 'S'. Example sending Arctech Code switch A1 ON:<br>
|
||||
* <tt>{'S': '$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$k'}</tt>
|
||||
* The string sent will be encoded like this:<br>
|
||||
* <tt>4:sendh1:S32:$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$k$k$ks</tt>
|
||||
*
|
||||
* The same example as above but with a 20 ms pause between the 15 packages:<br>
|
||||
* <tt>{'S': '$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$k',
|
||||
* 'P': 20, 'R': 15}</tt>
|
||||
*
|
||||
* The command \ref sec_send_extended "\"Send extended\" (T)" is not implemented
|
||||
* since a TellStick Net can handle packages over 255 pulses.
|
||||
*/
|
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
|
27
driver/TellUsbD101/CMakeLists.txt
Normal file
27
driver/TellUsbD101/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
|
||||
SET( tellusbd101_SRCS
|
||||
Device.cpp
|
||||
linux/Device.cpp
|
||||
DeviceIkea.cpp
|
||||
DeviceNexa.cpp
|
||||
DeviceSartano.cpp
|
||||
DeviceWaveman.cpp
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS(
|
||||
-DOS_LINUX
|
||||
)
|
||||
|
||||
ADD_LIBRARY(tellusbd101 SHARED
|
||||
${tellusbd101_SRCS}
|
||||
${tellusbd101_MOC_SRCS}
|
||||
)
|
||||
|
||||
# TARGET_LINK_LIBRARIES(tellusbd101
|
||||
# ${MIDAS_LIBRARY}
|
||||
# )
|
||||
|
||||
INSTALL(TARGETS tellusbd101 LIBRARY
|
||||
DESTINATION lib
|
||||
)
|
||||
|
52
driver/TellUsbD101/Device.cpp
Normal file
52
driver/TellUsbD101/Device.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "Device.h"
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
Device::Device(int intDongleIndex)
|
||||
{
|
||||
this->intDongleIndex = intDongleIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
Device::~Device(void)
|
||||
{
|
||||
intDongleIndex = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn on, virtual
|
||||
*/
|
||||
void Device::turnOn(void){
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off, virtual
|
||||
*/
|
||||
void Device::turnOff(void){
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* Bell, virtual
|
||||
*/
|
||||
void Device::bell(void){
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* Dim, virtual
|
||||
*/
|
||||
void Device::dim(unsigned char level){
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* Methods, virtual
|
||||
*/
|
||||
int Device::methods(char* strModel){
|
||||
return 0;
|
||||
}
|
24
driver/TellUsbD101/Device.h
Normal file
24
driver/TellUsbD101/Device.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "TellUsbD101.h"
|
||||
|
||||
class Device
|
||||
{
|
||||
private:
|
||||
int intDongleIndex;
|
||||
protected:
|
||||
void send(char* strMessage);
|
||||
public:
|
||||
Device(int intDeviceIndex);
|
||||
virtual void turnOn(void);
|
||||
virtual void turnOff(void);
|
||||
virtual void bell(void);
|
||||
virtual void dim(unsigned char level);
|
||||
virtual int methods(char* strModel);
|
||||
static int getDongleIndex();
|
||||
|
||||
static void debugLog(char* debugstring);
|
||||
|
||||
public:
|
||||
~Device(void);
|
||||
};
|
175
driver/TellUsbD101/DeviceIkea.cpp
Normal file
175
driver/TellUsbD101/DeviceIkea.cpp
Normal file
|
@ -0,0 +1,175 @@
|
|||
// #include "StdAfx.h" //Needed?
|
||||
#include "DeviceIkea.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceIkea::DeviceIkea(int intNewSystem, int intNewUnits, int intNewFadeStyle, int intDeviceIndex):Device(intDeviceIndex){
|
||||
intSystem = intNewSystem;
|
||||
intUnits = intNewUnits;
|
||||
intFadeStyle = intNewFadeStyle;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
DeviceIkea::~DeviceIkea(void)
|
||||
{
|
||||
intSystem = -1;
|
||||
intUnits = -1;
|
||||
intFadeStyle = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn on this device
|
||||
*/
|
||||
void DeviceIkea::turnOn(void){
|
||||
try{
|
||||
string strCode = getStringCode(255);
|
||||
|
||||
char* strMessage = const_cast<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(int intSystem, int intUnits, int fadeStyle, int intDeviceIndex);
|
||||
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);
|
||||
};
|
||||
|
168
driver/TellUsbD101/DeviceNexa.cpp
Normal file
168
driver/TellUsbD101/DeviceNexa.cpp
Normal file
|
@ -0,0 +1,168 @@
|
|||
// #include "StdAfx.h"
|
||||
#include "DeviceNexa.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceNexa::DeviceNexa(int intNewHouse, int intNewCode, int intDeviceIndex):Device(intDeviceIndex){
|
||||
intHouse = intNewHouse;
|
||||
intCode = intNewCode;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
DeviceNexa::~DeviceNexa(void)
|
||||
{
|
||||
intHouse = -1;
|
||||
intCode = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn on this device
|
||||
*/
|
||||
void DeviceNexa::turnOn(void){
|
||||
|
||||
try{
|
||||
//char* model = getModel(intDeviceId);
|
||||
string strCode = getStringCode(intCode);
|
||||
string strHouse = getStringCode(intHouse);
|
||||
strCode.append(strHouse);
|
||||
|
||||
strCode.insert(0, "S");
|
||||
strCode.append("$k$k$kk$$kk$$kk$$k+"); //the "turn on"-code, keeps it like this, doesn't have to be regenerated each time
|
||||
|
||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off this device
|
||||
*/
|
||||
void DeviceNexa::turnOff(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intCode);
|
||||
string strHouse = getStringCode(intHouse);
|
||||
|
||||
strCode.append(strHouse);
|
||||
strCode.insert(0, "S");
|
||||
strCode.append("$k$k$kk$$kk$$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time
|
||||
|
||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a bell
|
||||
*/
|
||||
void DeviceNexa::bell(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intCode);
|
||||
|
||||
strCode.append("$kk$$kk$$kk$$k$k"); //the unit-code is always 7, doesn't have to be regenerated each time
|
||||
strCode.insert(0, "S");
|
||||
strCode.append("$kk$$kk$$kk$$kk$$k+"); //the "bell"-code, keeps it like this, doesn't have to be regenerated each time
|
||||
|
||||
char* strMessage = const_cast<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(int intHouse, int intCode, int intDeviceIndex);
|
||||
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);
|
||||
};
|
||||
|
115
driver/TellUsbD101/DeviceSartano.cpp
Normal file
115
driver/TellUsbD101/DeviceSartano.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
#include "DeviceSartano.h"
|
||||
#include "DeviceNexa.h"
|
||||
#include <string>
|
||||
#include <bitset>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
DeviceSartano::DeviceSartano(int intNewSystem, int intNewCode, int intDeviceIndex)
|
||||
:Device(intDeviceIndex)
|
||||
{
|
||||
intSystem = intNewSystem;
|
||||
intCode = intNewCode;
|
||||
}
|
||||
|
||||
|
||||
DeviceSartano::~DeviceSartano(void)
|
||||
{
|
||||
intSystem = -1;
|
||||
intCode = -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Turn on this device
|
||||
*/
|
||||
void DeviceSartano::turnOn(void){
|
||||
|
||||
try{
|
||||
string strSystem = getStringCode(intSystem);
|
||||
string strCode = getStringCode(intCode);
|
||||
strSystem.append(strCode);
|
||||
|
||||
strSystem.insert(0, "S");
|
||||
strSystem.append("$k$k$kk$$k+"); //the "turn on"-code, keeps it like this, doesn't have to be regenerated each time
|
||||
|
||||
char* strMessage = const_cast<char*>(strSystem.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off this device
|
||||
*/
|
||||
void DeviceSartano::turnOff(void){
|
||||
|
||||
try{
|
||||
string strSystem = getStringCode(intSystem);
|
||||
string strCode = getStringCode(intCode);
|
||||
strSystem.append(strCode);
|
||||
|
||||
strSystem.insert(0, "S");
|
||||
strSystem.append("$kk$$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time
|
||||
|
||||
char* strMessage = const_cast<char*>(strSystem.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(int intToConvert){
|
||||
|
||||
string strReturn = "";
|
||||
|
||||
try{
|
||||
bitset<5> bs ((long)intToConvert);
|
||||
|
||||
strReturn = bs.to_string();
|
||||
|
||||
int intPos = (int)strReturn.find("0");
|
||||
while (intPos < string::npos){
|
||||
strReturn.replace(intPos, 1, "$k");
|
||||
intPos = (int)strReturn.find("0", intPos + 1);
|
||||
}
|
||||
|
||||
intPos = (int)strReturn.find("1");
|
||||
while (intPos < string::npos){
|
||||
strReturn.replace(intPos, 1, "k$");
|
||||
intPos = (int)strReturn.find("1", intPos + 1);
|
||||
}
|
||||
|
||||
intPos = 0;
|
||||
while (intPos < (int)strReturn.length()){
|
||||
strReturn.insert(intPos, "$k");
|
||||
intPos = intPos + 4;
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
return strReturn;
|
||||
|
||||
}
|
||||
|
21
driver/TellUsbD101/DeviceSartano.h
Normal file
21
driver/TellUsbD101/DeviceSartano.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
#include "Device.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
class DeviceSartano : public Device
|
||||
{
|
||||
public:
|
||||
DeviceSartano(int intSystem, int intCode, int intDeviceIndex);
|
||||
virtual void turnOn(void);
|
||||
virtual void turnOff(void);
|
||||
virtual int methods(char* strModel);
|
||||
|
||||
~DeviceSartano(void);
|
||||
|
||||
protected:
|
||||
std::string getStringCode(int);
|
||||
|
||||
int intSystem;
|
||||
int intCode;
|
||||
};
|
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(int intNewHouse, int intNewCode, int intDeviceIndex)
|
||||
:DeviceNexa(intNewHouse, intNewCode, intDeviceIndex){
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn off this device
|
||||
*/
|
||||
void DeviceWaveman::turnOff(void){
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intCode);
|
||||
string strHouse = getStringCode(intHouse);
|
||||
|
||||
strCode.append(strHouse);
|
||||
strCode.insert(0, "S");
|
||||
strCode.append("$k$k$k$k$k$k$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time
|
||||
|
||||
char* strMessage = const_cast<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(int intHouse, int intCode, int intDeviceIndex);
|
||||
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
|
326
driver/TellUsbD101/TellUsbD101.cpp
Normal file
326
driver/TellUsbD101/TellUsbD101.cpp
Normal file
|
@ -0,0 +1,326 @@
|
|||
//DLL entry point
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TellUsbD101.h"
|
||||
#include "TelldusSettings.h"
|
||||
#include "Device.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <ole2.h>
|
||||
|
||||
void handleException(std::exception e);
|
||||
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
|
||||
//TODO:
|
||||
//delete on created objects
|
||||
//comment (just copy from the called methods)
|
||||
|
||||
bool __stdcall devTurnOn(int intDeviceId){
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
dev->turnOn();
|
||||
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool __stdcall devTurnOff(int intDeviceId){
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
dev->turnOff();
|
||||
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool __stdcall devBell(int intDeviceId){
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
dev->bell();
|
||||
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool __stdcall devDim(int intDeviceId, unsigned char level){
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
if (level == 0) {
|
||||
dev->turnOff();
|
||||
} else if (level == 255) {
|
||||
dev->turnOn();
|
||||
} else {
|
||||
dev->dim(level);
|
||||
}
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int __stdcall devGetNumberOfDevices(void){
|
||||
int intReturn = -1;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
intReturn = ts.getNumberOfDevices();
|
||||
}
|
||||
catch(exception e){
|
||||
intReturn = -1;
|
||||
handleException(e);
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
int __stdcall devGetDeviceId(int intDeviceIndex){
|
||||
int intReturn = -1;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
intReturn = ts.getDeviceId(intDeviceIndex);
|
||||
}
|
||||
catch(exception e){
|
||||
intReturn = -1;
|
||||
handleException(e);
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
//general settings:
|
||||
char * __stdcall devGetName(int intDeviceId){
|
||||
char* strReturn;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getName(intDeviceId);
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool __stdcall devSetName(int intDeviceId, char* strNewName){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.setName(intDeviceId, strNewName);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
char* __stdcall devGetVendor(int intDeviceId){
|
||||
char* strReturn = "";
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getVendor(intDeviceId);
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool __stdcall devSetVendor(int intDeviceId, char* strVendor){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.setVendor(intDeviceId, strVendor);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
char* __stdcall devGetModel(int intDeviceId){
|
||||
char* strReturn = "";
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
strReturn = ts.getModel(intDeviceId);
|
||||
strReturn = (char *)SysAllocStringByteLen (strReturn, lstrlen(strReturn));
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
handleException(e);
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
bool __stdcall devSetModel(int intDeviceId, char* strNewModel){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.setModel(intDeviceId, strNewModel);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
bool __stdcall devSetArguments(int intDeviceId, char* strArguments){
|
||||
|
||||
vector <int> vArguments;
|
||||
//int intArguments[] = new int[]; //bort?
|
||||
try{
|
||||
char* strTemp = strtok(strArguments, ",");
|
||||
|
||||
while(strTemp != NULL){
|
||||
vArguments.push_back(atoi(strTemp));
|
||||
strTemp = strtok(NULL, ",");
|
||||
}
|
||||
TelldusSettings ts;
|
||||
return ts.setArguments(intDeviceId, vArguments);
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int __stdcall devGetArgument(int intDeviceId, int intArgumentIndex){
|
||||
int intReturn;
|
||||
try{
|
||||
if(intArgumentIndex != -1){
|
||||
TelldusSettings ts;
|
||||
int* intArguments = ts.getArguments(intDeviceId);
|
||||
intReturn = intArguments[intArgumentIndex];
|
||||
}
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
int __stdcall devGetNumberOfArguments(int intDeviceId){
|
||||
int intReturn;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
intReturn = ts.getNumberOfArguments(intDeviceId);
|
||||
}
|
||||
catch(exception e){
|
||||
handleException(e);
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
int __stdcall devAddDevice(){
|
||||
int intNewDeviceId = -1;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
intNewDeviceId = ts.addDevice();
|
||||
}
|
||||
catch(exception e){
|
||||
intNewDeviceId = -1;
|
||||
handleException(e);
|
||||
}
|
||||
return intNewDeviceId;
|
||||
}
|
||||
|
||||
bool __stdcall devRemoveDevice(int intDeviceId){
|
||||
bool blnSuccess = false;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
blnSuccess = ts.removeDevice(intDeviceId);
|
||||
}
|
||||
catch(exception e){
|
||||
blnSuccess = false;
|
||||
handleException(e);
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
int __stdcall devMethods(int id){
|
||||
|
||||
int intMethods = 0;
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
char* strModel = ts.getModel(id);
|
||||
Device* dev = ts.getDevice(id, -1); //We send dongleIndex=-1 sice we wouldn't send any data!
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
24
driver/TellUsbD101/TellUsbD101.def
Normal file
24
driver/TellUsbD101/TellUsbD101.def
Normal file
|
@ -0,0 +1,24 @@
|
|||
LIBRARY TellUsbD101
|
||||
EXPORTS
|
||||
devGetNumberOfDevices @1
|
||||
devGetDeviceId @2
|
||||
|
||||
devGetName @3
|
||||
devGetVendor @4
|
||||
devGetModel @5
|
||||
devGetNumberOfArguments @6
|
||||
devGetArgument @7
|
||||
|
||||
devSetName @8
|
||||
devSetVendor @9
|
||||
devSetModel @10
|
||||
devSetArguments @11
|
||||
|
||||
devAddDevice @12
|
||||
devRemoveDevice @13
|
||||
|
||||
devMethods @14
|
||||
devTurnOn @16
|
||||
devTurnOff @17
|
||||
devBell @18
|
||||
devDim @19
|
82
driver/TellUsbD101/TellUsbD101.h
Normal file
82
driver/TellUsbD101/TellUsbD101.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
#ifndef TELLUSBD101_H
|
||||
#define TELLUSBD101_H
|
||||
|
||||
// The following ifdef block is the standard way of creating macros
|
||||
// which make exporting from a DLL simpler. All files within this DLL
|
||||
// are compiled with the TellUsbD101_EXPORTS symbol defined on the command line.
|
||||
// This symbol should not be defined on any project that uses this DLL.
|
||||
// This way any other project whose source files include this file see
|
||||
// TELLSTICK_API functions as being imported from a DLL, whereas this DLL
|
||||
// sees symbols defined with this macro as being exported.
|
||||
|
||||
#ifdef TellUsbD101_EXPORTS
|
||||
#define TELLSTICK_API __declspec(dllexport)
|
||||
#else
|
||||
#define TELLSTICK_API __declspec(dllimport)
|
||||
#endif
|
||||
#ifdef _WINDOWS
|
||||
#define WINAPI __stdcall
|
||||
#else
|
||||
#define WINAPI
|
||||
#endif
|
||||
|
||||
|
||||
extern "C" {
|
||||
TELLSTICK_API bool WINAPI devTurnOn(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devTurnOff(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devBell(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devDim(int intDeviceId, unsigned char level);
|
||||
TELLSTICK_API int WINAPI devGetNumberOfDevices();
|
||||
TELLSTICK_API char * WINAPI devGetName(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devSetName(int intDeviceId, const char* chNewName);
|
||||
TELLSTICK_API char* WINAPI devGetVendor(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devSetVendor(int intDeviceId, const char* chNewName);
|
||||
TELLSTICK_API char* WINAPI devGetModel(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devSetModel(int intDeviceId, const char* chNewName);
|
||||
TELLSTICK_API int WINAPI devGetArgument(int intDeviceId, int intArgumentIndex);
|
||||
TELLSTICK_API int WINAPI devGetNumberOfArguments(int intDeviceId);
|
||||
TELLSTICK_API bool WINAPI devSetArguments(int intDeviceId, const char* strArguments);
|
||||
TELLSTICK_API int WINAPI devAddDevice();
|
||||
TELLSTICK_API int WINAPI devAddDeviceWithArguments(char* strVendor, int* intArguments[], int intNumberOfArguments);
|
||||
TELLSTICK_API bool WINAPI devRemoveDevice(int intDeviceId);
|
||||
TELLSTICK_API int WINAPI devGetDeviceId(int intDeviceIndex);
|
||||
TELLSTICK_API int WINAPI devMethods(int id);
|
||||
}
|
||||
|
||||
#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
|
308
driver/TellUsbD101/TellUsbD101.vcproj
Normal file
308
driver/TellUsbD101/TellUsbD101.vcproj
Normal file
|
@ -0,0 +1,308 @@
|
|||
<?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=".\Device.cpp"
|
||||
>
|
||||
</File>
|
||||
<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=".\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=".\TelldusSettings.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=".\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>
|
669
driver/TellUsbD101/TelldusSettings.cpp
Normal file
669
driver/TellUsbD101/TelldusSettings.cpp
Normal file
|
@ -0,0 +1,669 @@
|
|||
#include "StdAfx.h"
|
||||
#include "TelldusSettings.h"
|
||||
#include "Device.h"
|
||||
#include "DeviceNexa.h"
|
||||
#include "DeviceWaveman.h"
|
||||
#include "DeviceSartano.h"
|
||||
#include "DeviceIkea.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
bool storeGlobal();
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
TelldusSettings::TelldusSettings(void)
|
||||
{
|
||||
strRegPathDevice = "SOFTWARE\\Telldus\\Devices\\";
|
||||
strRegPath = "SOFTWARE\\Telldus\\";
|
||||
intMaxRegValueLength = 1000;
|
||||
if (storeGlobal()) {
|
||||
rootKey = HKEY_LOCAL_MACHINE;
|
||||
} else {
|
||||
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
|
||||
strRegPath = "";
|
||||
strRegPathDevice = "";
|
||||
intMaxRegValueLength = -1;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of stored devices
|
||||
*/
|
||||
int TelldusSettings::getNumberOfDevices(void){
|
||||
|
||||
int intNumberOfDevices = 0;
|
||||
|
||||
try{
|
||||
|
||||
long lnExists = RegOpenKeyEx(rootKey, strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
string strNumSubKeys;
|
||||
DWORD dNumSubKeys;
|
||||
RegQueryInfoKey(hk, NULL, NULL, NULL, &dNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
intNumberOfDevices = (int)dNumSubKeys;
|
||||
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
intNumberOfDevices = -1;
|
||||
}
|
||||
return intNumberOfDevices;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the requested device
|
||||
*/
|
||||
Device* TelldusSettings::getDevice(int intDeviceId){
|
||||
|
||||
try{
|
||||
int intDongleIndex = Device::getDongleIndex();
|
||||
if(intDongleIndex != -1){
|
||||
return getDevice(intDeviceId, intDongleIndex);
|
||||
}
|
||||
else{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the requested device, when the index of the USB dongle is known
|
||||
* Note that the returned Device should be deleted when not in use anymore
|
||||
*/
|
||||
Device* TelldusSettings::getDevice(int intDeviceId, int intDongleIndex){
|
||||
|
||||
Device* dev = 0;
|
||||
|
||||
try{
|
||||
char* vendor = getVendor(intDeviceId);
|
||||
|
||||
int* args = getArguments(intDeviceId);
|
||||
|
||||
//each new brand must be added here
|
||||
if (strcmp(vendor, "Nexa") == 0){
|
||||
dev = new DeviceNexa((int)args[0], (int)args[1], intDongleIndex);
|
||||
} else if (strcmp(vendor, "Waveman") == 0) {
|
||||
dev = new DeviceWaveman((int)args[0], (int)args[1], intDongleIndex);
|
||||
} else if (strcmp(vendor, "Sartano") == 0) {
|
||||
dev = new DeviceSartano((int)args[0], (int)args[1], intDongleIndex);
|
||||
} else if (strcmp(vendor, "Ikea") == 0) {
|
||||
dev = new DeviceIkea((int)args[0], (int)args[1], (int)args[2], intDongleIndex);
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the name of the device
|
||||
*/
|
||||
char* TelldusSettings::getName(int intDeviceId){
|
||||
|
||||
char* strReturn = "";
|
||||
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(hk, "Name", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
strReturn = Buff;
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
strReturn = "";
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the name of the device
|
||||
*/
|
||||
bool TelldusSettings::setName(int intDeviceId, char* strNewName){
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
intMaxRegValueLength = (int)strlen(strNewName);
|
||||
RegSetValueEx(hk, "Name", 0, REG_SZ, (LPBYTE)strNewName, intMaxRegValueLength);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the device vendor
|
||||
*/
|
||||
char* TelldusSettings::getVendor(int intDeviceId){
|
||||
|
||||
char* strReturn = "";
|
||||
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, (LPCSTR)strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(hk, (LPCSTR)"Vendor", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
|
||||
strReturn = Buff;
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(exception e){
|
||||
strReturn = "";
|
||||
ofstream errorfile("c:\\errorlog.txt", ios::app);
|
||||
if(errorfile){
|
||||
errorfile << e.what() << endl;
|
||||
errorfile.close();
|
||||
}
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the device vendor
|
||||
*/
|
||||
bool TelldusSettings::setVendor(int intDeviceId, char* strVendor){
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
intMaxRegValueLength = (int)strlen(strVendor);
|
||||
RegSetValueEx(hk, "Vendor", 0, REG_SZ, (LPBYTE)strVendor, intMaxRegValueLength);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the device model
|
||||
*/
|
||||
char* TelldusSettings::getModel(int intDeviceId){
|
||||
|
||||
char* strReturn = "";
|
||||
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(hk, "Model", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
strReturn = Buff;
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
strReturn = "";
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the device model
|
||||
*/
|
||||
bool TelldusSettings::setModel(int intDeviceId, char* strVendor){
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
intMaxRegValueLength = (int)strlen(strVendor);
|
||||
RegSetValueEx(hk, "Model", 0, REG_SZ, (LPBYTE)strVendor, intMaxRegValueLength);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
int TelldusSettings::getDeviceId(int intDeviceIndex){
|
||||
int intReturn = -1;
|
||||
|
||||
try{
|
||||
|
||||
long lnExists = RegOpenKeyEx(rootKey, strRegPathDevice.c_str(), 0, KEY_READ, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
DWORD size;
|
||||
if (RegEnumKeyEx(hk, intDeviceIndex, (LPSTR)Buff, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
|
||||
intReturn = (int)_atoi64(Buff);
|
||||
}
|
||||
|
||||
delete Buff;
|
||||
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
intReturn = -1;
|
||||
}
|
||||
return intReturn;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Get number of device arguments
|
||||
*/
|
||||
int TelldusSettings::getNumberOfArguments(int intDeviceId){
|
||||
int intReturn = -1;
|
||||
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
DWORD dNumValues;
|
||||
RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL);
|
||||
intReturn = (int)dNumValues - 3; //total number of values - model, name and vendor
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
//error management
|
||||
}
|
||||
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get device arguments
|
||||
*/
|
||||
int* TelldusSettings::getArguments(int intDeviceId){
|
||||
vector <int> vReturn;
|
||||
int* intReturn = new int[];
|
||||
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
DWORD dNumValues;
|
||||
RegQueryInfoKey(hk, NULL, NULL, NULL, NULL, NULL, NULL, &dNumValues, NULL, NULL, NULL, NULL);
|
||||
|
||||
int intNumberOfArguments = (int)dNumValues - 3; //total number of values - model, name and vendor
|
||||
DWORD dwLength;
|
||||
char chConvertBuffer[20];
|
||||
int i = 0;
|
||||
|
||||
while(i < intNumberOfArguments){
|
||||
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
|
||||
_itoa(i, chConvertBuffer, 10);
|
||||
long lngStatus = RegQueryValueEx(hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
lngStatus = RegQueryValueEx(hk, chConvertBuffer, NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
int intReturn = (int)_atoi64(Buff);
|
||||
vReturn.push_back(intReturn);
|
||||
|
||||
i++;
|
||||
delete Buff;
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
|
||||
intReturn = new int[vReturn.size()];
|
||||
|
||||
int i = 0;
|
||||
while(i < (int)vReturn.size()){
|
||||
intReturn[i] = vReturn.at(i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
//error management
|
||||
}
|
||||
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set device arguments
|
||||
*/
|
||||
bool TelldusSettings::setArguments(int intDeviceId, int* intArguments[], int intNumberOfArguments){
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
char chConvertBuffer [20];
|
||||
long lnExists = RegOpenKeyEx(rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
int i = 0;
|
||||
while(i < intNumberOfArguments){
|
||||
_itoa(i, chConvertBuffer, 10);
|
||||
RegSetValueEx(hk, chConvertBuffer, 0, REG_SZ, (LPBYTE)intArguments[i], intMaxRegValueLength);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set device arguments
|
||||
*/
|
||||
bool TelldusSettings::setArguments(int intDeviceId, vector <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(rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
int i = 0;
|
||||
while(i < vArguments.size()){
|
||||
_itoa(i, chConvertBuffer, 10);
|
||||
_itoa(vArguments.at(i), chConvertBufferValue, 10);
|
||||
intMaxRegValueLength = (int)strlen(chConvertBufferValue);
|
||||
RegSetValueEx(hk, chConvertBuffer, 0, REG_SZ, (LPBYTE)chConvertBufferValue, intMaxRegValueLength);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw exception(); //couldn't open reg key
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add a new device
|
||||
*/
|
||||
int TelldusSettings::addDevice(){
|
||||
|
||||
int intDeviceId = -1;
|
||||
try{
|
||||
|
||||
DWORD dwDisp;
|
||||
intDeviceId = getNextDeviceId();
|
||||
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
|
||||
if(RegCreateKeyEx(rootKey,
|
||||
strCompleteRegPath.c_str(),
|
||||
0,
|
||||
NULL,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
NULL,
|
||||
&hk,
|
||||
&dwDisp)){
|
||||
//fail
|
||||
throw exception("Create Key failed");
|
||||
}
|
||||
|
||||
RegCloseKey(hk);
|
||||
|
||||
}
|
||||
catch(...){
|
||||
intDeviceId = -1;
|
||||
}
|
||||
return intDeviceId;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get next available device id
|
||||
*/
|
||||
int TelldusSettings::getNextDeviceId(){
|
||||
|
||||
int intReturn = -1;
|
||||
try{
|
||||
DWORD dwDisp;
|
||||
long lnExists = RegCreateKeyEx(rootKey, strRegPathDevice.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
NULL,
|
||||
&hk,
|
||||
&dwDisp); //create or open if already created
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
|
||||
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(hk, "LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
|
||||
if(lngStatus == ERROR_SUCCESS){
|
||||
|
||||
int intLast = (int)Buff[0];
|
||||
intReturn = intLast + 1;
|
||||
}
|
||||
else{
|
||||
intReturn = 1;
|
||||
}
|
||||
delete Buff;
|
||||
|
||||
DWORD dwVal = intReturn;
|
||||
|
||||
RegSetValueEx (hk, "LastUsedId", 0L, REG_DWORD, (CONST BYTE*) &dwVal, sizeof(DWORD));
|
||||
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
intReturn = -1;
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a device
|
||||
*/
|
||||
bool TelldusSettings::removeDevice(int intDeviceId){
|
||||
|
||||
bool blnSuccess = true;
|
||||
try{
|
||||
std::ostringstream ssRegPath;
|
||||
ssRegPath << strRegPathDevice << intDeviceId;
|
||||
string strCompleteRegPath = ssRegPath.str();
|
||||
|
||||
long lngSuccess = RegDeleteKey(rootKey, strCompleteRegPath.c_str());
|
||||
if(lngSuccess != ERROR_SUCCESS){
|
||||
blnSuccess = false;
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
blnSuccess = false;
|
||||
}
|
||||
|
||||
return blnSuccess;
|
||||
}
|
||||
|
||||
//only for debug reasons
|
||||
void TelldusSettings::debugLog(char* debugstring){
|
||||
ofstream debugfile("c:\\telldusdebug.txt", ios::app);
|
||||
if(debugfile){
|
||||
debugfile << debugstring << endl;
|
||||
debugfile.close();
|
||||
}
|
||||
}
|
||||
|
||||
//only for debug reasons
|
||||
void TelldusSettings::debugLog(int debugint){
|
||||
ofstream debugfile("c:\\telldusdebug.txt", ios::app);
|
||||
if(debugfile){
|
||||
debugfile << debugint << endl;
|
||||
debugfile.close();
|
||||
}
|
||||
}
|
||||
|
||||
bool TelldusSettings::storeGlobal() {
|
||||
bool blnReturn = false;
|
||||
try{
|
||||
long lnExists = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegPathDevice.c_str(), 0, KEY_QUERY_VALUE, &hk);
|
||||
|
||||
if(lnExists == ERROR_SUCCESS){
|
||||
|
||||
DWORD dwLength;
|
||||
char* Buff = new char[intMaxRegValueLength];
|
||||
|
||||
long lngStatus = RegQueryValueEx(hk, "SharedDevices", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
|
||||
if(lngStatus == ERROR_MORE_DATA){
|
||||
|
||||
|
||||
Buff = new char[dwLength];
|
||||
lngStatus = RegQueryValueEx(hk, "SharedDevices", NULL, NULL, (LPBYTE)Buff, &dwLength);
|
||||
}
|
||||
|
||||
if(lngStatus == ERROR_SUCCESS){
|
||||
|
||||
int intValue = (int)Buff[0];
|
||||
blnReturn = (intValue == 1);
|
||||
}
|
||||
delete Buff;
|
||||
}
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
return blnReturn;
|
||||
}
|
44
driver/TellUsbD101/TelldusSettings.h
Normal file
44
driver/TellUsbD101/TelldusSettings.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
#include "device.h"
|
||||
#include "devicenexa.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class TelldusSettings
|
||||
{
|
||||
public:
|
||||
TelldusSettings(void);
|
||||
int getNumberOfDevices(void);
|
||||
Device* getDevice(int intDeviceId);
|
||||
Device* getDevice(int intDeviceId, int intDongleIndex);
|
||||
char* getName(int intDeviceId);
|
||||
bool setName(int intDeviceId, char* strNewName);
|
||||
char* getVendor(int intDeviceId);
|
||||
bool setVendor(int intDeviceId, char* strVendor);
|
||||
char* getModel(int intDeviceId);
|
||||
bool setModel(int intDeviceId, char* strModel);
|
||||
int* getArguments(int intDeviceId);
|
||||
bool setArguments(int intDeviceId, int* intArguments[], int intNumberOfArguments);
|
||||
bool setArguments(int intDeviceId, vector <int> vArguments);
|
||||
int addDevice();
|
||||
int getDeviceId(int intDeviceIndex);
|
||||
bool removeDevice(int intDeviceId);
|
||||
void debugLog(char* debugstring);
|
||||
void debugLog(int debugint);
|
||||
int getNumberOfArguments(int intDeviceId);
|
||||
|
||||
~TelldusSettings(void);
|
||||
|
||||
private:
|
||||
int getNextDeviceId();
|
||||
bool storeGlobal();
|
||||
|
||||
//variables
|
||||
HKEY hk;
|
||||
HKEY rootKey;
|
||||
std::string strRegPathDevice;
|
||||
std::string strRegPath;
|
||||
int intMaxRegValueLength;
|
||||
};
|
85
driver/TellUsbD101/linux/Device.cpp
Normal file
85
driver/TellUsbD101/linux/Device.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
#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;
|
||||
|
||||
debugLog(strMessage);
|
||||
|
||||
if( 0 > ( fd = open( "/dev/tellstick", O_RDWR ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* adjust serial port parameters */
|
||||
bzero(&tio, sizeof(tio)); /* clear struct for new port settings */
|
||||
tio.c_cflag = B4800 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */
|
||||
tio.c_iflag = IGNPAR;
|
||||
tio.c_oflag = 0;
|
||||
tcflush(fd, TCIFLUSH);
|
||||
tcsetattr(fd,TCSANOW,&tio);
|
||||
|
||||
write(fd, strMessage, strlen(strMessage));
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the device index of the Telldus dongle (the first one if many are connected)
|
||||
* -1 if no such device exists
|
||||
*/
|
||||
int Device::getDongleIndex(){
|
||||
int intReturn = -1;
|
||||
/* FT_HANDLE fthHandle = 0;
|
||||
FT_STATUS ftStatus = FT_OK;
|
||||
|
||||
try{
|
||||
DWORD dwNumberOfDevices = 0;
|
||||
|
||||
ftStatus = FT_CreateDeviceInfoList(&dwNumberOfDevices);
|
||||
if (ftStatus == FT_OK) {
|
||||
for (int i = 0; i < (int)dwNumberOfDevices; i++) {
|
||||
|
||||
FT_PROGRAM_DATA pData;
|
||||
char ManufacturerBuf[32];
|
||||
char ManufacturerIdBuf[16];
|
||||
char DescriptionBuf[64];
|
||||
char SerialNumberBuf[16];
|
||||
|
||||
pData.Signature1 = 0x00000000;
|
||||
pData.Signature2 = 0xffffffff;
|
||||
pData.Version = 0x00000002; // EEPROM structure with FT232R extensions
|
||||
pData.Manufacturer = ManufacturerBuf;
|
||||
pData.ManufacturerId = ManufacturerIdBuf;
|
||||
pData.Description = DescriptionBuf;
|
||||
pData.SerialNumber = SerialNumberBuf;
|
||||
|
||||
ftStatus = FT_Open(i, &fthHandle);
|
||||
ftStatus = FT_EE_Read(fthHandle, &pData);
|
||||
if(ftStatus == FT_OK){
|
||||
if(pData.VendorId == 6017 && pData.ProductId == 3120){
|
||||
intReturn = i;
|
||||
ftStatus = FT_Close(fthHandle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ftStatus = FT_Close(fthHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}*/
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
//only for debugging purpose
|
||||
void Device::debugLog(char* debugstring){
|
||||
std::cout << debugstring << std::endl;
|
||||
}
|
||||
|
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
|
91
driver/TellUsbD101/win/Device.cpp
Normal file
91
driver/TellUsbD101/win/Device.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
#include "..\Device.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "..\StdAfx.h"
|
||||
#include "FTD2XX.H"
|
||||
|
||||
/*
|
||||
* Send message to the USB dongle
|
||||
*/
|
||||
void Device::send(char* strMessage){
|
||||
|
||||
try{
|
||||
FT_STATUS ftStatus = FT_OK;
|
||||
FT_HANDLE fthHandle = 0;
|
||||
|
||||
ftStatus = FT_Open(this->intDongleIndex, &fthHandle);
|
||||
int intBaudRate = 4800; //always 4800
|
||||
ftStatus = FT_SetBaudRate(fthHandle, intBaudRate);
|
||||
ULONG bytesWritten;
|
||||
|
||||
int intLen = (int)strlen(strMessage);
|
||||
ftStatus = FT_Write(fthHandle, strMessage, intLen, &bytesWritten);
|
||||
|
||||
ftStatus = FT_Close(fthHandle);
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the device index of the Telldus dongle (the first one if many are connected)
|
||||
* -1 if no such device exists
|
||||
*/
|
||||
int Device::getDongleIndex(){
|
||||
int intReturn = -1;
|
||||
FT_HANDLE fthHandle = 0;
|
||||
FT_STATUS ftStatus = FT_OK;
|
||||
|
||||
try{
|
||||
DWORD dwNumberOfDevices = 0;
|
||||
|
||||
ftStatus = FT_CreateDeviceInfoList(&dwNumberOfDevices);
|
||||
if (ftStatus == FT_OK) {
|
||||
for (int i = 0; i < (int)dwNumberOfDevices; i++) {
|
||||
|
||||
FT_PROGRAM_DATA pData;
|
||||
char ManufacturerBuf[32];
|
||||
char ManufacturerIdBuf[16];
|
||||
char DescriptionBuf[64];
|
||||
char SerialNumberBuf[16];
|
||||
|
||||
pData.Signature1 = 0x00000000;
|
||||
pData.Signature2 = 0xffffffff;
|
||||
pData.Version = 0x00000002; // EEPROM structure with FT232R extensions
|
||||
pData.Manufacturer = ManufacturerBuf;
|
||||
pData.ManufacturerId = ManufacturerIdBuf;
|
||||
pData.Description = DescriptionBuf;
|
||||
pData.SerialNumber = SerialNumberBuf;
|
||||
|
||||
ftStatus = FT_Open(i, &fthHandle);
|
||||
ftStatus = FT_EE_Read(fthHandle, &pData);
|
||||
if(ftStatus == FT_OK){
|
||||
if(pData.VendorId == 6017 && pData.ProductId == 3120){
|
||||
intReturn = i;
|
||||
ftStatus = FT_Close(fthHandle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ftStatus = FT_Close(fthHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
}
|
||||
return intReturn;
|
||||
}
|
||||
|
||||
//only for debugging purpose
|
||||
void Device::debugLog(char* debugstring){
|
||||
std::ofstream debugfile("c:\\telldusdebug.txt", std::ios::app);
|
||||
if(debugfile){
|
||||
debugfile << debugstring << std::endl;
|
||||
debugfile.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) 2001-2007 Future Technology Devices International Ltd.
|
||||
Copyright (c) 2001-2005 Future Technology Devices International Ltd.
|
||||
|
||||
Module Name:
|
||||
|
||||
|
@ -32,12 +32,6 @@ Revision History:
|
|||
25/08/05 awm Added FT_SetDeadmanTimeout.
|
||||
02/12/05 awm Removed obsolete references.
|
||||
05/12/05 awm Added FT_GetVersion, FT_GetVersionEx.
|
||||
08/09/06 awm Added FT_W32_GetCommMask.
|
||||
11/09/06 awm Added FT_Rescan.
|
||||
11/07/07 awm Added support for FT2232H and FT4232H.
|
||||
10/08/07 awm Added flags definitions.
|
||||
21/11/07 mja Added FT_GetComPortNumber.
|
||||
05/06/08 mja Added EEPROM extensions for FT2232H.
|
||||
|
||||
|
||||
--*/
|
||||
|
@ -87,8 +81,7 @@ enum {
|
|||
FT_EEPROM_NOT_PROGRAMMED,
|
||||
FT_INVALID_ARGS,
|
||||
FT_NOT_SUPPORTED,
|
||||
FT_OTHER_ERROR,
|
||||
FT_DEVICE_LIST_NOT_READY,
|
||||
FT_OTHER_ERROR
|
||||
};
|
||||
|
||||
|
||||
|
@ -181,7 +174,6 @@ typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD);
|
|||
|
||||
#define FT_EVENT_RXCHAR 1
|
||||
#define FT_EVENT_MODEM_STATUS 2
|
||||
#define FT_EVENT_LINE_STATUS 4
|
||||
|
||||
//
|
||||
// Timeouts
|
||||
|
@ -202,9 +194,7 @@ enum {
|
|||
FT_DEVICE_100AX,
|
||||
FT_DEVICE_UNKNOWN,
|
||||
FT_DEVICE_2232C,
|
||||
FT_DEVICE_232R,
|
||||
FT_DEVICE_2232H,
|
||||
FT_DEVICE_4232H
|
||||
FT_DEVICE_232R
|
||||
};
|
||||
|
||||
|
||||
|
@ -242,7 +232,7 @@ FTD2XX_API
|
|||
FT_STATUS WINAPI FT_Read(
|
||||
FT_HANDLE ftHandle,
|
||||
LPVOID lpBuffer,
|
||||
DWORD dwBytesToRead,
|
||||
DWORD nBufferSize,
|
||||
LPDWORD lpBytesReturned
|
||||
);
|
||||
|
||||
|
@ -250,7 +240,7 @@ FTD2XX_API
|
|||
FT_STATUS WINAPI FT_Write(
|
||||
FT_HANDLE ftHandle,
|
||||
LPVOID lpBuffer,
|
||||
DWORD dwBytesToWrite,
|
||||
DWORD nBufferSize,
|
||||
LPDWORD lpBytesWritten
|
||||
);
|
||||
|
||||
|
@ -426,8 +416,6 @@ typedef struct ft_program_data {
|
|||
// 0 = original
|
||||
// 1 = FT2232C extensions
|
||||
// 2 = FT232R extensions
|
||||
// 3 = FT2232H extensions
|
||||
// 4 = FT4232H extensions
|
||||
|
||||
WORD VendorId; // 0x0403
|
||||
WORD ProductId; // 0x6001
|
||||
|
@ -440,7 +428,7 @@ typedef struct ft_program_data {
|
|||
WORD SelfPowered; // 0 = bus powered, 1 = self powered
|
||||
WORD RemoteWakeup; // 0 = not capable, 1 = capable
|
||||
//
|
||||
// Rev4 (FT232B) extensions
|
||||
// Rev4 extensions
|
||||
//
|
||||
UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise
|
||||
UCHAR IsoIn; // non-zero if in endpoint is isochronous
|
||||
|
@ -450,7 +438,7 @@ typedef struct ft_program_data {
|
|||
UCHAR USBVersionEnable; // non-zero if chip uses USBVersion
|
||||
WORD USBVersion; // BCD (0x0200 => USB2)
|
||||
//
|
||||
// Rev 5 (FT2232) extensions
|
||||
// FT2232C extensions
|
||||
//
|
||||
UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise
|
||||
UCHAR IsoInA; // non-zero if in endpoint is isochronous
|
||||
|
@ -472,13 +460,15 @@ typedef struct ft_program_data {
|
|||
UCHAR IFBIsFastSer; // non-zero if interface is Fast serial
|
||||
UCHAR BIsVCP; // non-zero if interface is to use VCP drivers
|
||||
//
|
||||
// Rev 6 (FT232R) extensions
|
||||
// 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
|
||||
|
@ -487,63 +477,14 @@ typedef struct ft_program_data {
|
|||
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 RIsD2XX; // non-zero if using D2XX driver
|
||||
//
|
||||
// Rev 7 (FT2232H) Extensions
|
||||
//
|
||||
UCHAR PullDownEnable7; // non-zero if pull down enabled
|
||||
UCHAR SerNumEnable7; // non-zero if serial number to be used
|
||||
UCHAR ALSlowSlew; // non-zero if AL pins have slow slew
|
||||
UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input
|
||||
UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR AHSlowSlew; // non-zero if AH pins have slow slew
|
||||
UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input
|
||||
UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR BLSlowSlew; // non-zero if BL pins have slow slew
|
||||
UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input
|
||||
UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR BHSlowSlew; // non-zero if BH pins have slow slew
|
||||
UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input
|
||||
UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR IFAIsFifo7; // non-zero if interface is 245 FIFO
|
||||
UCHAR IFAIsFifoTar7; // non-zero if interface is 245 FIFO CPU target
|
||||
UCHAR IFAIsFastSer7; // non-zero if interface is Fast serial
|
||||
UCHAR AIsVCP7; // non-zero if interface is to use VCP drivers
|
||||
UCHAR IFBIsFifo7; // non-zero if interface is 245 FIFO
|
||||
UCHAR IFBIsFifoTar7; // non-zero if interface is 245 FIFO CPU target
|
||||
UCHAR IFBIsFastSer7; // non-zero if interface is Fast serial
|
||||
UCHAR BIsVCP7; // non-zero if interface is to use VCP drivers
|
||||
UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs
|
||||
//
|
||||
// Rev 8 (FT4232H) Extensions
|
||||
//
|
||||
UCHAR PullDownEnable8; // non-zero if pull down enabled
|
||||
UCHAR SerNumEnable8; // non-zero if serial number to be used
|
||||
UCHAR ASlowSlew; // non-zero if AL pins have slow slew
|
||||
UCHAR ASchmittInput; // non-zero if AL pins are Schmitt input
|
||||
UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR BSlowSlew; // non-zero if AH pins have slow slew
|
||||
UCHAR BSchmittInput; // non-zero if AH pins are Schmitt input
|
||||
UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR CSlowSlew; // non-zero if BL pins have slow slew
|
||||
UCHAR CSchmittInput; // non-zero if BL pins are Schmitt input
|
||||
UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR DSlowSlew; // non-zero if BH pins have slow slew
|
||||
UCHAR DSchmittInput; // non-zero if BH pins are Schmitt input
|
||||
UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
|
||||
UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN
|
||||
UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN
|
||||
UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN
|
||||
UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN
|
||||
UCHAR AIsVCP8; // non-zero if interface is to use VCP drivers
|
||||
UCHAR BIsVCP8; // non-zero if interface is to use VCP drivers
|
||||
UCHAR CIsVCP8; // non-zero if interface is to use VCP drivers
|
||||
UCHAR DIsVCP8; // non-zero if interface is to use VCP drivers
|
||||
|
||||
UCHAR RIsVCP; // non-zero if using VCP drivers
|
||||
|
||||
} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA;
|
||||
|
||||
|
@ -681,7 +622,7 @@ FT_STATUS WINAPI FT_CyclePort(
|
|||
|
||||
FTD2XX_API
|
||||
FT_HANDLE WINAPI FT_W32_CreateFile(
|
||||
LPCTSTR lpszName,
|
||||
LPCSTR lpszName,
|
||||
DWORD dwAccess,
|
||||
DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
|
@ -841,12 +782,6 @@ BOOL WINAPI FT_W32_SetCommMask(
|
|||
ULONG ulEventMask
|
||||
);
|
||||
|
||||
FTD2XX_API
|
||||
BOOL WINAPI FT_W32_GetCommMask(
|
||||
FT_HANDLE ftHandle,
|
||||
LPDWORD lpdwEventMask
|
||||
);
|
||||
|
||||
FTD2XX_API
|
||||
BOOL WINAPI FT_W32_SetCommState(
|
||||
FT_HANDLE ftHandle,
|
||||
|
@ -888,12 +823,6 @@ typedef struct _ft_device_list_info_node {
|
|||
FT_HANDLE ftHandle;
|
||||
} FT_DEVICE_LIST_INFO_NODE;
|
||||
|
||||
// Device information flags
|
||||
enum {
|
||||
FT_FLAGS_OPENED = 1,
|
||||
FT_FLAGS_HISPEED = 2
|
||||
};
|
||||
|
||||
|
||||
FTD2XX_API
|
||||
FT_STATUS WINAPI FT_CreateDeviceInfoList(
|
||||
|
@ -935,23 +864,6 @@ FT_STATUS WINAPI FT_GetLibraryVersion(
|
|||
);
|
||||
|
||||
|
||||
FTD2XX_API
|
||||
FT_STATUS WINAPI FT_Rescan(
|
||||
void
|
||||
);
|
||||
|
||||
FTD2XX_API
|
||||
FT_STATUS WINAPI FT_Reload(
|
||||
WORD wVid,
|
||||
WORD wPid
|
||||
);
|
||||
|
||||
FTD2XX_API
|
||||
FT_STATUS WINAPI FT_GetComPortNumber(
|
||||
FT_HANDLE ftHandle,
|
||||
LPLONG lpdwComPortNumber
|
||||
);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
|
@ -1,13 +0,0 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall -ltelldus-core
|
||||
|
||||
OBJS = main.o
|
||||
|
||||
all: ${OBJS}
|
||||
${CC} -o sensor ${CFLAGS} ${OBJS}
|
||||
|
||||
main.c:
|
||||
${CC} ${CFLAGS} -c main.c
|
||||
|
||||
clean:
|
||||
rm -f sensor main.o
|
|
@ -1,43 +0,0 @@
|
|||
#include <telldus-core.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void WINAPI sensorEvent(const char *protocol, const char *model, int sensorId, int dataType, const char *value, int ts, int callbackId, void *context) {
|
||||
char timeBuf[80];
|
||||
time_t timestamp = ts;
|
||||
|
||||
//Print the sensor
|
||||
printf("%s,\t%s,\t%i\n", protocol, model, sensorId);
|
||||
|
||||
//Retrieve the values the sensor supports
|
||||
if (dataType == TELLSTICK_TEMPERATURE) {
|
||||
strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp));
|
||||
printf("Temperature:\t%sº\t(%s)\n", value, timeBuf);
|
||||
|
||||
} else if (dataType == TELLSTICK_HUMIDITY) {
|
||||
strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp));
|
||||
printf("Humidity:\t%s%%\t(%s)\n", value, timeBuf);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int callbackId = 0;
|
||||
|
||||
tdInit();
|
||||
|
||||
//Register for callback
|
||||
callbackId = tdRegisterSensorEvent( (TDSensorEvent)&sensorEvent, 0 );
|
||||
|
||||
//Our own simple eventloop
|
||||
while(1) {
|
||||
sleep(100);
|
||||
}
|
||||
|
||||
//Cleanup
|
||||
tdUnregisterCallback( callbackId );
|
||||
tdClose();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall -ltelldus-core
|
||||
|
||||
OBJS = main.o
|
||||
|
||||
all: ${OBJS}
|
||||
${CC} -o sensor ${CFLAGS} ${OBJS}
|
||||
|
||||
main.c:
|
||||
${CC} ${CFLAGS} -c main.c
|
||||
|
||||
clean:
|
||||
rm -f sensor main.o
|
|
@ -1,38 +0,0 @@
|
|||
#include <telldus-core.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const int DATA_LENGTH = 20;
|
||||
|
||||
int main(void) {
|
||||
char protocol[DATA_LENGTH], model[DATA_LENGTH];
|
||||
int sensorId = 0, dataTypes = 0;
|
||||
char value[DATA_LENGTH];
|
||||
char timeBuf[80];
|
||||
time_t timestamp = 0;
|
||||
|
||||
|
||||
tdInit();
|
||||
|
||||
while(tdSensor(protocol, DATA_LENGTH, model, DATA_LENGTH, &sensorId, &dataTypes) == TELLSTICK_SUCCESS) {
|
||||
//Print the sensor
|
||||
printf("%s,\t%s,\t%i\n", protocol, model, sensorId);
|
||||
|
||||
//Retrieve the values the sensor supports
|
||||
if (dataTypes & TELLSTICK_TEMPERATURE) {
|
||||
tdSensorValue(protocol, model, sensorId, TELLSTICK_TEMPERATURE, value, DATA_LENGTH, (int *)×tamp);
|
||||
strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp));
|
||||
printf("Temperature:\t%sº\t(%s)\n", value, timeBuf);
|
||||
}
|
||||
if (dataTypes & TELLSTICK_HUMIDITY) {
|
||||
tdSensorValue(protocol, model, sensorId, TELLSTICK_HUMIDITY, value, DATA_LENGTH, (int *)×tamp);
|
||||
strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", localtime(×tamp));
|
||||
printf("Humidity:\t%s%%\t(%s)\n", value, timeBuf);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
tdClose();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall -ltelldus-core
|
||||
|
||||
OBJS = main.o
|
||||
|
||||
all: ${OBJS}
|
||||
${CC} -o callbacks ${CFLAGS} ${OBJS}
|
||||
|
||||
main.cpp:
|
||||
${CC} ${CFLAGS} -c main.cpp
|
||||
|
||||
clean:
|
||||
rm -f callbacks main.o
|
|
@ -1,77 +0,0 @@
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <telldus-core.h>
|
||||
|
||||
bool running;
|
||||
|
||||
class Events {
|
||||
public:
|
||||
Events();
|
||||
~Events();
|
||||
void deviceEvent(int deviceId, int method, const char *data);
|
||||
|
||||
static void deviceEventCallback(int deviceId, int method, const char *data, int callbackId, void *context);
|
||||
|
||||
private:
|
||||
int callbackId;
|
||||
};
|
||||
|
||||
Events::Events() {
|
||||
callbackId = tdRegisterDeviceEvent( reinterpret_cast<TDDeviceEvent>(&Events::deviceEventCallback), this );
|
||||
}
|
||||
|
||||
Events::~Events() {
|
||||
tdUnregisterCallback(callbackId);
|
||||
}
|
||||
|
||||
void Events::deviceEvent(int deviceId, int method, const char *data) {
|
||||
if (method == TELLSTICK_TURNON) {
|
||||
printf("ON event from device %i\n", deviceId);
|
||||
} else if (method == TELLSTICK_TURNOFF) {
|
||||
printf("OFF event from device %i\n", deviceId);
|
||||
} else {
|
||||
printf("Unknown event from device %i\n", deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
void Events::deviceEventCallback(int deviceId, int method, const char *data, int callbackId, void *context) {
|
||||
Events *e = reinterpret_cast<Events *>(context);
|
||||
if (e) {
|
||||
/** Please note!
|
||||
* We are here in another thread than the main. Some measures to syncronize
|
||||
* this must be taken!
|
||||
**/
|
||||
e->deviceEvent(deviceId, method, data);
|
||||
}
|
||||
}
|
||||
|
||||
void signalHandler(int sig) {
|
||||
if (sig == SIGINT) {
|
||||
printf("Shutting down\n");
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void run() {
|
||||
Events ev;
|
||||
|
||||
running = true;
|
||||
|
||||
printf("Listening for events, press control-c to quit...\n");
|
||||
//Our own simple eventloop
|
||||
while(running) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
tdInit();
|
||||
|
||||
signal(SIGINT, signalHandler);
|
||||
run();
|
||||
|
||||
tdClose();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SensorPollWin", "SensorPollWin\SensorPollWin.csproj", "{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Debug|x86.Build.0 = Debug|x86
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Release|x86.ActiveCfg = Release|x86
|
||||
{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,69 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SensorPollWin
|
||||
{
|
||||
unsafe class Program
|
||||
{
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern void tdInit();
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern void tdClose();
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdSensor(char* protocol, int protocolLength, char* model, int modelLength, int* id, int* dataTypes);
|
||||
|
||||
[DllImport("TelldusCore.dll")]
|
||||
public static extern int tdSensorValue(char* protocol, char* model, int id, int dataType, char* value, int valueLength, int* timestamp);
|
||||
|
||||
static unsafe void Main(string[] args)
|
||||
{
|
||||
int protocolstringsize = 20;
|
||||
int modelstringsize = 30;
|
||||
int valuestringsize = 20;
|
||||
char* protocol = (char*)Marshal.AllocHGlobal(Marshal.SystemDefaultCharSize * protocolstringsize);
|
||||
char* model = (char*)Marshal.AllocHGlobal(Marshal.SystemDefaultCharSize * modelstringsize);
|
||||
IntPtr id = Marshal.AllocHGlobal(sizeof(int));
|
||||
IntPtr dataType = Marshal.AllocHGlobal(sizeof(int));
|
||||
Console.WriteLine("getting sensors");
|
||||
|
||||
tdInit();
|
||||
while (tdSensor(protocol, protocolstringsize, model, modelstringsize, (int*)id, (int*)dataType) == 0)
|
||||
{
|
||||
Console.WriteLine("Sensor: " + System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(protocol))) + " " + System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(model))));
|
||||
|
||||
char* value = (char*)Marshal.AllocHGlobal(Marshal.SystemDefaultCharSize * valuestringsize);
|
||||
IntPtr timestamp = Marshal.AllocHGlobal(sizeof(int));
|
||||
if ((Marshal.ReadIntPtr(dataType).ToInt32() & 1) != 0)
|
||||
{
|
||||
tdSensorValue(protocol, model, Marshal.ReadIntPtr(id).ToInt32(), 1, value, valuestringsize, (int*)timestamp);
|
||||
Console.WriteLine("Temperature: " + System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(value))) + "C, " + datify(Marshal.ReadIntPtr(timestamp).ToInt32()));
|
||||
}
|
||||
if ((Marshal.ReadIntPtr(dataType).ToInt32() & 2) != 0)
|
||||
{
|
||||
tdSensorValue(protocol, model, Marshal.ReadIntPtr(id).ToInt32(), 2, value, valuestringsize, (int*)timestamp);
|
||||
Console.WriteLine("Humidity: " + System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(value))) + "%, " + datify(Marshal.ReadIntPtr(timestamp).ToInt32()));
|
||||
}
|
||||
Console.WriteLine("");
|
||||
Marshal.FreeHGlobal((IntPtr)value);
|
||||
Marshal.FreeHGlobal(timestamp);
|
||||
}
|
||||
Marshal.FreeHGlobal((IntPtr)protocol);
|
||||
Marshal.FreeHGlobal((IntPtr)model);
|
||||
Marshal.FreeHGlobal(id);
|
||||
Marshal.FreeHGlobal(dataType);
|
||||
tdClose();
|
||||
}
|
||||
|
||||
private static string datify(int timestamp){
|
||||
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
dateTime = dateTime.AddSeconds(timestamp);
|
||||
dateTime = dateTime.ToLocalTime();
|
||||
return dateTime.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SensorPollWin")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("SensorPollWin")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("31424c50-2c39-4b7c-a4e8-5a11bd6b8c1d")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -1,77 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{47D37594-BFDD-4A4E-9736-32EDAE2E22F0}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SensorPollWin</RootNamespace>
|
||||
<AssemblyName>SensorPollWin</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -1,94 +0,0 @@
|
|||
import java.io.*;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.ptr.*;
|
||||
import com.sun.jna.Callback;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.Memory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SensorsJNACallback
|
||||
{
|
||||
public interface CLibrary extends Library {
|
||||
|
||||
static int TELLSTICK_TEMPERATURE = 1;
|
||||
static int TELLSTICK_HUMIDITY = 2;
|
||||
|
||||
void tdInit();
|
||||
void tdClose();
|
||||
int tdRegisterSensorEvent(SensorCallback function, Pointer context);
|
||||
int tdUnregisterCallback(int callbackID);
|
||||
|
||||
public interface SensorCallback extends Callback{
|
||||
public void callbackfunction(Pointer protocol, Pointer model, int id, int dataType, Pointer value, int timestamp, int callbackId, Pointer context);
|
||||
}
|
||||
}
|
||||
|
||||
int callbackID;
|
||||
CLibrary lib;
|
||||
CLibrary.SensorCallback callback;
|
||||
|
||||
public SensorsJNACallback(){
|
||||
lib = (CLibrary)Native.loadLibrary("libtelldus-core.so.2", CLibrary.class);
|
||||
}
|
||||
|
||||
public void startListening(){
|
||||
|
||||
lib.tdInit();
|
||||
|
||||
//save reference to callback to avoid garbage collection
|
||||
CLibrary.SensorCallback callback = new CLibrary.SensorCallback(){
|
||||
|
||||
public void callbackfunction(Pointer protocol, Pointer model, int id, int dataType, Pointer value, int timestamp, int callbackId, Pointer context){
|
||||
System.out.println("Sensor: " + protocol.getString(0) + " " + model.getString(0));
|
||||
long timestampvalue = (long)timestamp * 1000;
|
||||
Date date = new Date(timestampvalue);
|
||||
|
||||
if(dataType == CLibrary.TELLSTICK_TEMPERATURE){
|
||||
System.out.println("Temperature: " + value.getString(0) + "C, " + date.toString());
|
||||
}
|
||||
else if(dataType == CLibrary.TELLSTICK_HUMIDITY){
|
||||
System.out.println("Humidity: " + value.getString(0) + "%, " + date.toString());
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
};
|
||||
|
||||
//register callback function for sensor events
|
||||
callbackID = lib.tdRegisterSensorEvent(callback, (Pointer)null);
|
||||
|
||||
while(true){
|
||||
try{
|
||||
//just wait for sensor callbacks
|
||||
Thread.currentThread().sleep(1000);
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopListening(){
|
||||
System.out.println("Exiting");
|
||||
lib.tdUnregisterCallback(callbackID);
|
||||
callback = null;
|
||||
lib.tdClose();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
final SensorsJNACallback sensorsjnacallback = new SensorsJNACallback();
|
||||
|
||||
//add shutdown hook to allow callback unregistration
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(){
|
||||
public void run(){
|
||||
sensorsjnacallback.stopListening();
|
||||
Runtime.getRuntime().halt(0);
|
||||
}
|
||||
});
|
||||
|
||||
sensorsjnacallback.startListening();
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
import java.io.*;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.ptr.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SensorsJNAPoll
|
||||
{
|
||||
public interface CLibrary extends Library {
|
||||
|
||||
static int TELLSTICK_TEMPERATURE = 1;
|
||||
static int TELLSTICK_HUMIDITY = 2;
|
||||
|
||||
void tdInit();
|
||||
void tdClose();
|
||||
int tdTurnOn(int deviceId);
|
||||
int tdTurnOff(int deviceId);
|
||||
int tdSensor(byte[] protocol, int protocolLength, byte[] model, int modelLength, IntByReference id,IntByReference dataTypes);
|
||||
int tdSensorValue(byte[] protocol, byte[] model, int id, int dataType, byte[] value, int valueLength, IntByReference timestamp);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
CLibrary lib = (CLibrary)Native.loadLibrary("libtelldus-core.so.2", CLibrary.class);
|
||||
lib.tdInit();
|
||||
|
||||
IntByReference id = new IntByReference();
|
||||
IntByReference dataTypes = new IntByReference();
|
||||
|
||||
System.out.println("getting sensors");
|
||||
System.out.println("");
|
||||
|
||||
byte protocol[] = new byte[20];
|
||||
byte model[] = new byte[20];
|
||||
|
||||
//check every sensor
|
||||
while(lib.tdSensor(protocol, 20, model, 20, id, dataTypes) == 0){
|
||||
System.out.println("Sensor: " + Native.toString(protocol) + " " + Native.toString(model));
|
||||
|
||||
byte value[] = new byte[20];
|
||||
IntByReference timestamp = new IntByReference();
|
||||
if((dataTypes.getValue() & CLibrary.TELLSTICK_TEMPERATURE) != 0){
|
||||
lib.tdSensorValue(protocol, model, id.getValue(), 1, value, 20, timestamp);
|
||||
long timestampvalue = (long)timestamp.getValue() * 1000;
|
||||
Date date = new Date(timestampvalue);
|
||||
System.out.println("Temperature: " + Native.toString(value) + "C, " + date.toString());
|
||||
}
|
||||
if((dataTypes.getValue() & CLibrary.TELLSTICK_HUMIDITY) != 0){
|
||||
lib.tdSensorValue(protocol, model, id.getValue(), 2, value, 20, timestamp);
|
||||
long timestampvalue = (long)timestamp.getValue() * 1000;
|
||||
Date date = new Date(timestampvalue);
|
||||
System.out.println("Humidity: " + Native.toString(value) + "%, " + date.toString());
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
lib.tdClose();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once 'HTTP/OAuth/Consumer.php';
|
||||
|
||||
define('PUBLIC_KEY', '');
|
||||
define('PRIVATE_KEY', '');
|
||||
|
||||
define('URL', 'http://api.telldus.com'); //https should be used in production!
|
||||
define('REQUEST_TOKEN', constant('URL').'/oauth/requestToken');
|
||||
define('AUTHORIZE_TOKEN', constant('URL').'/oauth/authorize');
|
||||
define('ACCESS_TOKEN', constant('URL').'/oauth/accessToken');
|
||||
define('REQUEST_URI', constant('URL').'/xml');
|
||||
|
||||
define('BASE_URL', 'http://'.$_SERVER["SERVER_NAME"].dirname($_SERVER['REQUEST_URI']));
|
||||
|
||||
define('TELLSTICK_TURNON', 1);
|
||||
define('TELLSTICK_TURNOFF', 2);
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once 'common.php';
|
||||
|
||||
$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), $_SESSION['token'], $_SESSION['tokenSecret']);
|
||||
|
||||
try {
|
||||
$consumer->getAccessToken(constant('ACCESS_TOKEN'));
|
||||
|
||||
$_SESSION['accessToken'] = $consumer->getToken();
|
||||
$_SESSION['accessTokenSecret'] = $consumer->getTokenSecret();
|
||||
|
||||
header('Location:index.php');
|
||||
} catch (Exception $e) {
|
||||
?>
|
||||
<p>Authorization failed!</p>
|
||||
<p><a href="index.php">Go back</a></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once 'common.php';
|
||||
|
||||
$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'));
|
||||
|
||||
$consumer->getRequestToken(constant('REQUEST_TOKEN'), constant('BASE_URL').'/getAccessToken.php');
|
||||
|
||||
$_SESSION['token'] = $consumer->getToken();
|
||||
$_SESSION['tokenSecret'] = $consumer->getTokenSecret();
|
||||
|
||||
$url = $consumer->getAuthorizeUrl(constant('AUTHORIZE_TOKEN'));
|
||||
header('Location:'.$url);
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once 'common.php';
|
||||
|
||||
if (isset($_GET['clear'])) {
|
||||
session_destroy();
|
||||
header('location:index.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['accessToken'])) {
|
||||
?>We have no access token, <a href="getRequestToken.php">connect us</a><?php
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
<p>We have access!</p>
|
||||
<p>
|
||||
In your system, store these values to do requests for this user:<br>
|
||||
Token: <?php echo $_SESSION['accessToken']; ?><br>
|
||||
Secret: <?php echo $_SESSION['accessTokenSecret']; ?>
|
||||
</p>
|
||||
<p><a href="index.php?clear">Clear the token and restart</a></p>
|
||||
<p><a href="index.php?listDevices">List users devices</a></p>
|
||||
<?php
|
||||
|
||||
if (isset($_GET['listDevices'])) {
|
||||
$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), $_SESSION['accessToken'], $_SESSION['accessTokenSecret']);
|
||||
$params = array(
|
||||
'supportedMethods' => constant('TELLSTICK_TURNON') | constant('TELLSTICK_TURNOFF'),
|
||||
);
|
||||
$response = $consumer->sendRequest(constant('REQUEST_URI').'/devices/list', $params, 'GET');
|
||||
echo '<pre>';
|
||||
echo( htmlentities($response->getBody()));
|
||||
}
|
||||
|
||||
?><p><a href="index.php?listClients">List users clients</a></p><?php
|
||||
|
||||
if (isset($_GET['listClients'])) {
|
||||
$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), $_SESSION['accessToken'], $_SESSION['accessTokenSecret']);
|
||||
$params = array();
|
||||
$response = $consumer->sendRequest(constant('REQUEST_URI').'/clients/list', $params, 'GET');
|
||||
echo '<pre>';
|
||||
echo( htmlentities($response->getBody()));
|
||||
}
|
||||
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
from ctypes import c_int, c_ubyte, c_void_p, POINTER, string_at #imports allowing the use of our library
|
||||
from threading import Timer
|
||||
import time
|
||||
import platform
|
||||
|
||||
#platform specific imports:
|
||||
if (platform.system() == 'Windows'):
|
||||
#Windows
|
||||
from ctypes import windll, WINFUNCTYPE
|
||||
lib = windll.LoadLibrary('TelldusCore.dll') #import our library
|
||||
else:
|
||||
#Linux
|
||||
from ctypes import cdll, CFUNCTYPE
|
||||
lib = cdll.LoadLibrary('libtelldus-core.so.2') #import our library
|
||||
|
||||
timers = {} #timerlist
|
||||
|
||||
def turnOn():
|
||||
print "turning on"
|
||||
lib.tdTurnOn(1)
|
||||
|
||||
def turnOff():
|
||||
print "turning off"
|
||||
lib.tdTurnOff(1)
|
||||
|
||||
#function to be called when a device event occurs
|
||||
def callbackfunction(deviceId, method, value, callbackId, context):
|
||||
global timers
|
||||
|
||||
print "callback!"
|
||||
|
||||
if (deviceId == 1):
|
||||
# is turning on deviceId 1 here, so just return if events for that device are picked up
|
||||
return
|
||||
|
||||
t = 0
|
||||
print "Received event for device %d" % (deviceId,)
|
||||
if (deviceId in timers):
|
||||
# a timer already exists for this device, it might be running so interrupt it
|
||||
# Many devices (for example motion detectors) resends their messages many times to ensure that they
|
||||
# are received correctly. In this example, we don't want to run the turnOn/turnOff methods every time, instead we
|
||||
# start a timer, and run the method when the timer is finished. For every incoming event on this device, the timer
|
||||
# is restarted.
|
||||
t = timers[deviceId]
|
||||
t.cancel()
|
||||
if (method == 1):
|
||||
#on
|
||||
t = Timer(0.5, turnOn) #start timer with 0.5 second delay (adjust the delay to suit your needs), then turn on
|
||||
else:
|
||||
#off
|
||||
t = Timer(0.5, turnOff) #start timer with 0.5 second delay (adjust the delay to suit your needs), then turn off
|
||||
|
||||
t.start()
|
||||
timers[deviceId] = t #put timer in list, to allow later cancellation
|
||||
|
||||
#function to be called when device event occurs, even for unregistered devices
|
||||
def rawcallbackfunction(data, controllerId, callbackId, context):
|
||||
print string_at(data)
|
||||
|
||||
if (platform.system() == 'Windows'):
|
||||
CMPFUNC = WINFUNCTYPE(None, c_int, c_int, POINTER(c_ubyte), c_int, c_void_p) #first is return type
|
||||
CMPFUNCRAW = WINFUNCTYPE(None, POINTER(c_ubyte), c_int, c_int, c_void_p)
|
||||
else:
|
||||
CMPFUNC = CFUNCTYPE(None, c_int, c_int, POINTER(c_ubyte), c_int, c_void_p)
|
||||
CMPFUNCRAW = CFUNCTYPE(None, POINTER(c_ubyte), c_int, c_int, c_void_p)
|
||||
|
||||
cmp_func = CMPFUNC(callbackfunction)
|
||||
cmp_funcraw = CMPFUNCRAW(rawcallbackfunction)
|
||||
|
||||
lib.tdInit()
|
||||
lib.tdRegisterDeviceEvent(cmp_func, 0)
|
||||
#lib.tdRegisterRawDeviceEvent(cmp_funcraw, 0) #uncomment this, and comment out tdRegisterDeviceEvent, to see data for not registered devices
|
||||
|
||||
print "Waiting for events..."
|
||||
while(1):
|
||||
time.sleep(0.5) #don't exit
|
|
@ -1,136 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import socket, ssl
|
||||
import time, os
|
||||
|
||||
from configobj import ConfigObj
|
||||
|
||||
from ServerList import *
|
||||
from TelldusCore import *
|
||||
from LiveMessage import *
|
||||
|
||||
class Client():
|
||||
def __init__(self):
|
||||
self.publicKey = ''
|
||||
self.privateKey = ''
|
||||
self.hashMethod = 'sha1'
|
||||
self.pongTimer = 0
|
||||
self.pingTimer = 0
|
||||
self.supportedMethods = 0
|
||||
self.tellduscore = TelldusCore()
|
||||
self.serverList = ServerList()
|
||||
|
||||
self.configPath = os.environ['HOME'] + '/.config/Telldus'
|
||||
self.configFilename = 'TelldusLive.conf'
|
||||
self.config = ConfigObj(self.configPath + '/' + self.configFilename)
|
||||
self.connect(self.serverList.popServer())
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
os.makedirs(self.configPath)
|
||||
except:
|
||||
pass
|
||||
self.config.write()
|
||||
|
||||
def connect(self, server):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.socket = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1, ca_certs="/etc/ssl/certs/ca-certificates.crt",cert_reqs=ssl.CERT_REQUIRED)
|
||||
self.socket.settimeout(5)
|
||||
self.socket.connect((server['address'], int(server['port'])))
|
||||
|
||||
uuid = ''
|
||||
try:
|
||||
uuid = self.config['uuid']
|
||||
except:
|
||||
pass
|
||||
|
||||
msg = LiveMessage('Register')
|
||||
msg.append({
|
||||
'key': self.publicKey,
|
||||
'uuid': uuid,
|
||||
'hash': self.hashMethod
|
||||
})
|
||||
msg.append({
|
||||
'protocol': 2,
|
||||
'version': '1',
|
||||
'os': 'linux',
|
||||
'os-version': 'unknown'
|
||||
})
|
||||
|
||||
self.socket.write(self.signedMessage(msg))
|
||||
self.pongTimer = time.time()
|
||||
self.pingTimer = time.time()
|
||||
while(1):
|
||||
try:
|
||||
resp = self.socket.read(1024)
|
||||
except ssl.SSLError:
|
||||
# Timeout, try again after some maintenance
|
||||
if (time.time() - self.pongTimer >= 360): # No pong received
|
||||
print("No pong received, disconnecting")
|
||||
break
|
||||
if (time.time() - self.pingTimer >= 120):
|
||||
# Time to ping
|
||||
msg = LiveMessage("Ping")
|
||||
self.socket.write(self.signedMessage(msg))
|
||||
self.pingTimer = time.time()
|
||||
|
||||
continue
|
||||
|
||||
if (resp == ''):
|
||||
print("no response")
|
||||
break
|
||||
|
||||
envelope = LiveMessage.fromByteArray(resp)
|
||||
if (not envelope.verifySignature(self.hashMethod, self.privateKey)):
|
||||
print "Signature failed"
|
||||
continue
|
||||
|
||||
self.pongTimer = time.time()
|
||||
self.handleMessage(LiveMessage.fromByteArray(envelope.argument(0).stringVal))
|
||||
|
||||
def handleCommand(self, args):
|
||||
if (args['action'].stringVal == 'turnon'):
|
||||
self.tellduscore.turnon(args['id'].intVal)
|
||||
elif (args['action'].stringVal == 'turnoff'):
|
||||
self.tellduscore.turnoff(args['id'].intVal)
|
||||
else:
|
||||
return
|
||||
|
||||
if ('ACK' in args):
|
||||
#Respond to ack
|
||||
msg = LiveMessage("ACK")
|
||||
msg.append(args['ACK'].intVal)
|
||||
self.socket.write(self.signedMessage(msg))
|
||||
|
||||
def handleMessage(self, message):
|
||||
if (message.name() == "notregistered"):
|
||||
params = message.argument(0).dictVal
|
||||
self.config['uuid'] = params['uuid'].stringVal
|
||||
self.config['activationUrl'] = params['url'].stringVal
|
||||
print "This client isn't activated, please activate it using this url:\n%s" % params['url'].stringVal
|
||||
return
|
||||
|
||||
if (message.name() == "registered"):
|
||||
params = message.argument(0).dictVal
|
||||
self.supportedMethods = params['supportedMethods'].intVal
|
||||
self.tellduscore.setSupportedMethods(self.supportedMethods)
|
||||
self.sendDevicesReport()
|
||||
return
|
||||
|
||||
if (message.name() == "command"):
|
||||
self.handleCommand(message.argument(0).dictVal)
|
||||
return
|
||||
|
||||
if (message.name() == "pong"):
|
||||
return
|
||||
|
||||
print "Did not understand: %s" % message.toByteArray()
|
||||
|
||||
|
||||
def sendDevicesReport(self):
|
||||
msg = LiveMessage("DevicesReport")
|
||||
msg.append(self.tellduscore.getList())
|
||||
self.socket.write(self.signedMessage(msg))
|
||||
|
||||
def signedMessage(self, message):
|
||||
return message.toSignedMessage(self.hashMethod, self.privateKey)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue