diff --git a/Hal.iml b/Hal.iml index 53b6e61a..45384d36 100755 --- a/Hal.iml +++ b/Hal.iml @@ -10,11 +10,14 @@ - + + + + diff --git a/arduino/PowerTransmitter/PowerTransmitter/PowerTransmitter.ino b/arduino/PowerTransmitter/PowerTransmitter/PowerTransmitter.ino index 077dd204..65f51c97 100755 --- a/arduino/PowerTransmitter/PowerTransmitter/PowerTransmitter.ino +++ b/arduino/PowerTransmitter/PowerTransmitter/PowerTransmitter.ino @@ -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) { diff --git a/external/tellstick-driver/DPInst32.exe b/external/tellstick-driver/DPInst32.exe deleted file mode 100755 index 86955a2c..00000000 Binary files a/external/tellstick-driver/DPInst32.exe and /dev/null differ diff --git a/external/tellstick-driver/DPInst64.exe b/external/tellstick-driver/DPInst64.exe deleted file mode 100755 index 5fa618ac..00000000 Binary files a/external/tellstick-driver/DPInst64.exe and /dev/null differ diff --git a/external/tellstick-driver/FTDIBUS.INF b/external/tellstick-driver/FTDIBUS.INF deleted file mode 100755 index bfbb90dc..00000000 --- a/external/tellstick-driver/FTDIBUS.INF +++ /dev/null @@ -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" diff --git a/external/tellstick-driver/amd64/ftbusui.dll b/external/tellstick-driver/amd64/ftbusui.dll deleted file mode 100755 index b9e28586..00000000 Binary files a/external/tellstick-driver/amd64/ftbusui.dll and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftcserco.dll b/external/tellstick-driver/amd64/ftcserco.dll deleted file mode 100755 index f2929154..00000000 Binary files a/external/tellstick-driver/amd64/ftcserco.dll and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftd2xx.lib b/external/tellstick-driver/amd64/ftd2xx.lib deleted file mode 100755 index 0d68cf79..00000000 Binary files a/external/tellstick-driver/amd64/ftd2xx.lib and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftd2xx64.dll b/external/tellstick-driver/amd64/ftd2xx64.dll deleted file mode 100755 index 9044b423..00000000 Binary files a/external/tellstick-driver/amd64/ftd2xx64.dll and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftdibus.sys b/external/tellstick-driver/amd64/ftdibus.sys deleted file mode 100755 index f13ca478..00000000 Binary files a/external/tellstick-driver/amd64/ftdibus.sys and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftlang.dll b/external/tellstick-driver/amd64/ftlang.dll deleted file mode 100755 index 66de070d..00000000 Binary files a/external/tellstick-driver/amd64/ftlang.dll and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftser2k.sys b/external/tellstick-driver/amd64/ftser2k.sys deleted file mode 100755 index 9b90f5de..00000000 Binary files a/external/tellstick-driver/amd64/ftser2k.sys and /dev/null differ diff --git a/external/tellstick-driver/amd64/ftserui2.dll b/external/tellstick-driver/amd64/ftserui2.dll deleted file mode 100755 index fe73f250..00000000 Binary files a/external/tellstick-driver/amd64/ftserui2.dll and /dev/null differ diff --git a/external/tellstick-driver/ftdi_linux.zip b/external/tellstick-driver/ftdi_linux.zip new file mode 100755 index 00000000..29243481 Binary files /dev/null and b/external/tellstick-driver/ftdi_linux.zip differ diff --git a/external/tellstick-driver/ftdibus.cat b/external/tellstick-driver/ftdibus.cat deleted file mode 100755 index decf3af3..00000000 Binary files a/external/tellstick-driver/ftdibus.cat and /dev/null differ diff --git a/external/tellstick-driver/i386/ftbusui.dll b/external/tellstick-driver/i386/ftbusui.dll deleted file mode 100755 index 98659a15..00000000 Binary files a/external/tellstick-driver/i386/ftbusui.dll and /dev/null differ diff --git a/external/tellstick-driver/i386/ftcserco.dll b/external/tellstick-driver/i386/ftcserco.dll deleted file mode 100755 index 3a282692..00000000 Binary files a/external/tellstick-driver/i386/ftcserco.dll and /dev/null differ diff --git a/external/tellstick-driver/i386/ftd2xx.dll b/external/tellstick-driver/i386/ftd2xx.dll deleted file mode 100755 index ebd11b59..00000000 Binary files a/external/tellstick-driver/i386/ftd2xx.dll and /dev/null differ diff --git a/external/tellstick-driver/i386/ftd2xx.lib b/external/tellstick-driver/i386/ftd2xx.lib deleted file mode 100755 index 10cce73b..00000000 Binary files a/external/tellstick-driver/i386/ftd2xx.lib and /dev/null differ diff --git a/external/tellstick-driver/i386/ftdibus.sys b/external/tellstick-driver/i386/ftdibus.sys deleted file mode 100755 index 9538b1a6..00000000 Binary files a/external/tellstick-driver/i386/ftdibus.sys and /dev/null differ diff --git a/external/tellstick-driver/i386/ftlang.dll b/external/tellstick-driver/i386/ftlang.dll deleted file mode 100755 index a7b5fa5c..00000000 Binary files a/external/tellstick-driver/i386/ftlang.dll and /dev/null differ diff --git a/external/tellstick-driver/i386/ftser2k.sys b/external/tellstick-driver/i386/ftser2k.sys deleted file mode 100755 index ff7c63af..00000000 Binary files a/external/tellstick-driver/i386/ftser2k.sys and /dev/null differ diff --git a/external/tellstick-driver/i386/ftserui2.dll b/external/tellstick-driver/i386/ftserui2.dll deleted file mode 100755 index 3e1a5a35..00000000 Binary files a/external/tellstick-driver/i386/ftserui2.dll and /dev/null differ diff --git a/src/se/koc/hal/plugin/tellstick/TellstickParser.java b/src/se/koc/hal/plugin/tellstick/TellstickParser.java index df8a44f8..21d65442 100755 --- a/src/se/koc/hal/plugin/tellstick/TellstickParser.java +++ b/src/se/koc/hal/plugin/tellstick/TellstickParser.java @@ -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> 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); } } diff --git a/src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java b/src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java index 0acc29bb..6d6c525c 100755 --- a/src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java +++ b/src/se/koc/hal/plugin/tellstick/TellstickSerialComm.java @@ -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){ - listener.stateChange(protocol); + 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