Updated Tellstick drivers and Switched from System.ou.print to Logger

Former-commit-id: 62d5bf468e366ecf4056602de469c151311c9a12
This commit is contained in:
Ziver Koc 2015-11-20 21:29:55 +01:00
parent c2138902f0
commit aa656cdc05
27 changed files with 125 additions and 199 deletions

View file

@ -10,11 +10,14 @@
<sourceFolder url="file://$MODULE_DIR$/external/sphinx4-5prealpha-src/sphinx4-core/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/external/sphinx4-5prealpha-src/sphinx4-core/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/external/sphinx4-5prealpha-src/sphinx4-data/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/lib/java-speech-api-master/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/sphinx4-core/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/sphinx4-core/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/sphinx4-data/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/sphinx4-samples/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/lib/java-speech-api-master/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/sphinx4-data" />
<excludeFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/sphinx4-samples" />
<excludeFolder url="file://$MODULE_DIR$/lib/sphinx4-5prealpha-src/tests" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />

View file

@ -41,10 +41,12 @@ void loop()
{
currentTime = millis();
uint16_t lux = LightSensor.GetLightIntensity();
if(lux > 100 && !light){
//Serial.print("lux=");
//Serial.println(lux);
if(lux > 40 && !light){
light = true;
impulseCount++;
}else if(lux < 100){
}else if(lux < 40){
light = false;
}
if(currentTime - previousTime > 60000) {

Binary file not shown.

Binary file not shown.

View file

@ -1,135 +0,0 @@
; FTDIBUS.INF
;
; Copyright © 2000-2013 Future Technology Devices International Limited
;
; USB serial converter driver installation file for Windows 2000, XP, Server 2003, Vista, Server 2008,
; Windows 7, Server 2008 R2 and Windows 8 (x86 and x64).
;
;
; THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED ``AS IS'' AND ANY EXPRESS
; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED
; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
; THE POSSIBILITY OF SUCH DAMAGE.
; FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS.
; FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED.
; IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE RESPONSIBILITY OF
; THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL RE-CERTIFICATION AS A RESULT OF
; MAKING THESE CHANGES.
;
[Version]
Signature="$Windows NT$"
DriverPackageType=PlugAndPlay
DriverPackageDisplayName=%DESC%
Class=USB
ClassGUID={36fc9e60-c465-11cf-8056-444553540000}
Provider=%TELLDUS%
CatalogFile=ftdibus.cat
DriverVer=01/18/2013,2.08.28
[SourceDisksNames]
1=%DriversDisk%,,,
[SourceDisksFiles]
ftdibus.sys = 1,i386
ftbusui.dll = 1,i386
ftd2xx.dll = 1,i386
FTLang.Dll = 1,i386
[SourceDisksFiles.amd64]
ftdibus.sys = 1,amd64
ftbusui.dll = 1,amd64
ftd2xx64.dll = 1,amd64
ftd2xx.dll = 1,i386
FTLang.Dll = 1,amd64
[DestinationDirs]
FtdiBus.NT.Copy = 10,system32\drivers
FtdiBus.NT.Copy2 = 10,system32
FtdiBus.NTamd64.Copy = 10,system32\drivers
FtdiBus.NTamd64.Copy2 = 10,system32
FtdiBus.NTamd64.Copy3 = 10,syswow64
[Manufacturer]
%Telldus%=TelldusHw,NTamd64
[TelldusHw]
%USB\VID_1781&PID_0c30.DeviceDesc%=FtdiBus.NT,USB\VID_1781&PID_0c30
%USB\VID_1781&PID_0c31.DeviceDesc%=FtdiBus.NT,USB\VID_1781&PID_0c31
[TelldusHw.NTamd64]
%USB\VID_1781&PID_0c30.DeviceDesc%=FtdiBus.NTamd64,USB\VID_1781&PID_0c30
%USB\VID_1781&PID_0c31.DeviceDesc%=FtdiBus.NTamd64,USB\VID_1781&PID_0c31
[ControlFlags]
ExcludeFromSelect=*
[FtdiBus.NT]
CopyFiles=FtdiBus.NT.Copy,FtdiBus.NT.Copy2
AddReg=FtdiBus.NT.AddReg
[FtdiBus.NTamd64]
CopyFiles=FtdiBus.NTamd64.Copy,FtdiBus.NTamd64.Copy2,FtdiBus.NTamd64.Copy3
AddReg=FtdiBus.NT.AddReg
[FtdiBus.NT.Services]
AddService = FTDIBUS, 0x00000002, FtdiBus.NT.AddService
[FtdiBus.NTamd64.Services]
AddService = FTDIBUS, 0x00000002, FtdiBus.NT.AddService
[FtdiBus.NT.AddService]
DisplayName = %SvcDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\system32\drivers\ftdibus.sys
LoadOrderGroup = Base
AddReg = FtdiBus.NT.AddService.AddReg
[FtdiBus.NT.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,ftdibus.sys
HKR,,EnumPropPages32,,"ftbusui.dll,FTBUSUIPropPageProvider"
[FtdiBus.NT.AddService.AddReg]
;HKR,Parameters,"LocIds",1,31,00,00,00,32,00,00,00,00
;HKR,Parameters,"RetryResetCount",0x10001,50
[FtdiBus.NT.Copy]
ftdibus.sys
[FtdiBus.NT.Copy2]
ftbusui.dll
ftd2xx.dll
FTLang.dll
[FtdiBus.NTamd64.Copy]
ftdibus.sys
[FtdiBus.NTamd64.Copy2]
ftbusui.dll
ftd2xx.dll,ftd2xx64.dll
FTLang.dll
[FtdiBus.NTamd64.Copy3]
ftd2xx.dll
[Strings]
Telldus="TELLDUS"
DESC="Telldus Technologies USB-driver"
DriversDisk="Telldus Technologies AB Drivers Disk"
USB\VID_1781&PID_0c30.DeviceDesc="Telldus TellStick"
USB\VID_1781&PID_0c31.DeviceDesc="Telldus TellStick Duo"
SvcDesc="Telldus Technologies USB-driver"
ClassName="USB"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
external/tellstick-driver/ftdi_linux.zip vendored Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -25,13 +25,17 @@ package se.koc.hal.plugin.tellstick;
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
import zutil.converters.Converter;
import zutil.log.LogUtil;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by Ziver on 2015-02-18.
*/
public class TellstickParser {
private static final Logger logger = LogUtil.getLogger();
private static HashMap<String, Class<? extends TellstickProtocol>> protocolMap;
static {
@ -61,19 +65,19 @@ public class TellstickParser {
protocol.decode(Converter.hexToByte(binData));
if(!protocol.equals(previus)) {
previus = protocol;
System.out.println("Decoded: " + protocol);
logger.finest("Decoded: " + protocol);
return protocol;
}
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.WARNING, null, e);
}
} else {
System.out.println("Unknown protocol: " + data);
logger.warning("Unknown protocol: " + data);
}
} else if (data.startsWith("+S") || data.startsWith("+T")) {
// This is confirmation of send commands
}else {
System.out.println("Unknown prefix: " + data);
logger.severe("Unknown prefix: " + data);
}
return null;
@ -90,7 +94,7 @@ public class TellstickParser {
tmp.getProtocolName() + "-" + tmp.getModelName(),
protClass);
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.SEVERE, null, e);
}
}

View file

@ -23,53 +23,72 @@
package se.koc.hal.plugin.tellstick;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.fazecast.jSerialComm.SerialPort;
import zutil.log.InputStreamLogger;
import zutil.log.LogUtil;
import zutil.log.OutputStreamLogger;
import zutil.struct.TimedHashSet;
/**
* This version of the TwoWaySerialComm example makes use of the
* SerialPortEventListener to avoid polling.
*/
public class TellstickSerialComm extends Thread{
public static TellstickSerialComm instance;
private static final long TRANSMISSION_UNIQUENESS_TTL = 100; // milliseconds
private static final Logger logger = LogUtil.getLogger();
private static TellstickSerialComm instance;
private com.fazecast.jSerialComm.SerialPort serial;
private SerialPort serial;
private BufferedReader in;
private Writer out;
private BufferedWriter out;
private TimedHashSet set; // To check for retransmissions
private TellstickParser parser = new TellstickParser();
private TellstickChangeListener listener;
public TellstickSerialComm(){
set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
}
public void connect(String portName) throws Exception {
serial = SerialPort.getCommPort(portName);
serial.setBaudRate(115200);
serial.setBaudRate(9600);
if(!serial.openPort())
throw new IOException("Could not open port: "+portName);
serial.setComPortTimeouts(
SerialPort.TIMEOUT_READ_SEMI_BLOCKING,
5000, 0);
SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
in = new BufferedReader(new InputStreamReader(serial.getInputStream(), "UTF-8"));
out = new BufferedWriter(new OutputStreamWriter(serial.getOutputStream(), "UTF-8"));
in = new BufferedReader(new InputStreamReader(new InputStreamLogger(serial.getInputStream()), "UTF-8"));
out = new BufferedWriter(new OutputStreamWriter(new OutputStreamLogger(serial.getOutputStream()), "UTF-8"));
this.start();
}
public void run() {
try {
String data;
while ((data = in.readLine()) != null) {
System.out.println("> " + data);
TellstickProtocol protocol = parser.decode(data);
if (protocol == null && (data.startsWith("+S") || data.startsWith("+T"))) {
if ((data.startsWith("+S") || data.startsWith("+T"))) {
synchronized (this) {
this.notifyAll();
}
}
else if(listener != null){
else {
if(!set.contains(data)) {
TellstickProtocol protocol = parser.decode(data);
set.add(data);
if (listener != null) {
listener.stateChange(protocol);
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
logger.log(Level.SEVERE, null, e);
}
}
@ -78,18 +97,18 @@ public class TellstickSerialComm extends Thread{
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
logger.log(Level.SEVERE, null, e);
}
}
public void write(String data) {
try {
System.out.println("< "+data);
for(int i=0; i<data.length();i++)
out.write(0xFF & data.charAt(i));
out.write('\n');
out.flush();
} catch (IOException e) {
e.printStackTrace();
logger.log(Level.SEVERE, null, e);
}
}
@ -104,7 +123,7 @@ public class TellstickSerialComm extends Thread{
instance = new TellstickSerialComm();
instance.connect("COM6");
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.SEVERE, null, e);
}
}
return instance;

View file

@ -0,0 +1,56 @@
package se.koc.hal.plugin.tellstick;
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
import zutil.db.DBConnection;
import zutil.log.LogUtil;
import java.sql.SQLException;
import java.util.logging.Logger;
/**
* Created by Ziver on 2015-11-19.
*/
public class TelstickSerialCommNexaOnOffTest {
public static void main(String[] args) {
try {
System.out.println("Connecting to db...");
TellstickSerialComm comm = new TellstickSerialComm();
// http://developer.telldus.com/doxygen/TellStick.html
System.out.println("Connecting to com port...");
//comm.connect("COM5");
comm.connect("/dev/ttyUSB1");
Thread.sleep(1000);
NexaSelfLearning nexa = new NexaSelfLearning();
//nexa.setHouse(11772006);
nexa.setHouse(15087918);
nexa.setGroup(0);
nexa.setUnit(0);
System.out.println("Up and Running");
while(true) {
Thread.sleep(2000);
nexa.setEnable(true);
nexa.setUnit(0);
comm.write(nexa);
Thread.sleep(2000);
nexa.setUnit(1);
comm.write(nexa);
Thread.sleep(2000);
nexa.setEnable(false);
nexa.setUnit(0);
comm.write(nexa);
Thread.sleep(2000);
nexa.setUnit(1);
comm.write(nexa);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -4,32 +4,34 @@ import se.koc.hal.plugin.tellstick.TellstickSerialComm;
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
import zutil.db.DBConnection;
import zutil.log.CompactLogFormatter;
import zutil.log.LogUtil;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by Ziver on 2015-11-19.
*/
public class TelstickSerialCommTest {
private static final Logger logger = LogUtil.getLogger();
public static void main(String[] args) {
try {
LogUtil.setGlobalFormatter(new CompactLogFormatter());
LogUtil.setGlobalLevel(Level.FINEST);
logger.info("Connecting to db...");
final DBConnection db = new DBConnection(DBConnection.DBMS.SQLite, "hal.db");
// http://developer.telldus.com/doxygen/TellStick.html
logger.info("Setting up Tellstick listeners...");
TellstickSerialComm comm = new TellstickSerialComm();
comm.setListener(new TellstickChangeListener() {
boolean toggle = false;
@Override
public void stateChange(TellstickProtocol protocol) {
if(toggle) {
toggle = false;
return;
}
toggle = true;
if(protocol instanceof Oregon0x1A2D){
System.out.println("Oregon0x1A2D= Temperature: "+((Oregon0x1A2D)protocol).getTemperature() +
"Humidity: "+((Oregon0x1A2D)protocol).getHumidity());
logger.info("Power used: "+ ((Oregon0x1A2D)protocol).getTemperature() +" pulses");
try {
db.exec("INSERT INTO power_meter (timestamp, pulses) VALUES("+System.currentTimeMillis()+","+(int)((Oregon0x1A2D)protocol).getTemperature()+")");
} catch (SQLException e) {
@ -38,37 +40,12 @@ public class TelstickSerialCommTest {
}
}
});
logger.info("Connecting to com port...");
//comm.connect("COM5");
comm.setDaemon(false);
comm.connect("/dev/ttyUSB1");
Thread.sleep(1000);
NexaSelfLearning nexa = new NexaSelfLearning();
//nexa.setHouse(11772006);
nexa.setHouse(15087918);
nexa.setGroup(0);
nexa.setUnit(0);
while(true) {
Thread.sleep(1000);
/*nexa.setEnable(true);
nexa.setUnit(0);
comm.write(nexa);
Thread.sleep(2000);
nexa.setUnit(1);
comm.write(nexa);
Thread.sleep(2000);
nexa.setEnable(false);
nexa.setUnit(0);
comm.write(nexa);
Thread.sleep(2000);
nexa.setUnit(1);
comm.write(nexa);
Thread.sleep(2000);*/
}
logger.info("Up and Running");
} catch (Exception e) {
e.printStackTrace();
}