From d5a3f409ebcc2fb59f8aee924257880ab7901ea9 Mon Sep 17 00:00:00 2001 From: Jozef Sovcik Date: Mon, 9 May 2016 20:05:46 +0200 Subject: [PATCH 1/5] major multithreading issue fixed --- JPigpio/src/jpigpio/SocketLock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JPigpio/src/jpigpio/SocketLock.java b/JPigpio/src/jpigpio/SocketLock.java index 5e9688b..ca77993 100644 --- a/JPigpio/src/jpigpio/SocketLock.java +++ b/JPigpio/src/jpigpio/SocketLock.java @@ -81,7 +81,7 @@ public synchronized int sendCmd(int cmd, int p1, int p2, int p3, byte[] ext) thr // specified timeout while (w > 0 && a < 16){ w -= 10; - try{ wait(10); } catch (InterruptedException e) {} + try{ Thread.sleep(10); } catch (InterruptedException e) {} a = in.available(); } From 10bf357eb9c22e42508bd52f6ae01af14515d70a Mon Sep 17 00:00:00 2001 From: Jozef Sovcik Date: Mon, 9 May 2016 20:06:25 +0200 Subject: [PATCH 2/5] some config changes + setter for tx/rx repeat --- JPigpio/src/jpigpio/packet/Protocol.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/JPigpio/src/jpigpio/packet/Protocol.java b/JPigpio/src/jpigpio/packet/Protocol.java index 93c43a6..6dbbb76 100644 --- a/JPigpio/src/jpigpio/packet/Protocol.java +++ b/JPigpio/src/jpigpio/packet/Protocol.java @@ -16,7 +16,7 @@ public class Protocol { */ public int DGRM_LENGTH = DATA_SIZE*2; - public int DGRM_REPEAT = 3; + public int DGRM_REPEAT = 5; /** * repeat transmission of each datagram this many times to make sure at least one got through */ @@ -107,8 +107,16 @@ public void setDataSize(int size){ * @param repeatCount Count how many times datagram is going to be transmitted. */ public void setRepeatCount(int repeatCount){ - DGRM_REPEAT = 3; + DGRM_REPEAT = repeatCount; DGRM_REPEAT_TX = DGRM_REPEAT; DGRM_REPEAT_RX = DGRM_REPEAT; } + + public void setRxRepeatCount(int rxRepeatCount) { + DGRM_REPEAT_RX = rxRepeatCount; + } + + public void setTxRepeatCount(int txRepeatCount) { + DGRM_REPEAT_TX = txRepeatCount; + } } From 45ed440ac13d09cb3d5fce9682a2fe2715b24eef Mon Sep 17 00:00:00 2001 From: Jozef Sovcik Date: Mon, 9 May 2016 20:07:24 +0200 Subject: [PATCH 3/5] bitwise OR vs OR... --- JPigpio/src/jpigpio/packet/Rf433rx.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/JPigpio/src/jpigpio/packet/Rf433rx.java b/JPigpio/src/jpigpio/packet/Rf433rx.java index 2fd99e4..640075d 100644 --- a/JPigpio/src/jpigpio/packet/Rf433rx.java +++ b/JPigpio/src/jpigpio/packet/Rf433rx.java @@ -176,9 +176,11 @@ else if (trans == 3) { // 1 160->500 pulses = ""; if (dataByte >= protocol.DGRM_LENGTH) { //datagram complete? + //System.out.println("#1 datagram received: "+datagram.toString()); if (Utils.tickDiff(messageTick, (int) lastTick) > protocol.DGRM_RX_TIMEOUT || messageTick == 0) { repeatCount = 0; + duplicate = false; } else if (duplicate) repeatCount++; @@ -188,8 +190,11 @@ else if (trans == 3) { // 1 160->500 } // if no datagram error (or ignoring datagram errors) and not duplicate - if ((protocol.DGRM_KEEP_ON_ENCODING_ERROR | !datagramError) && !duplicate) + // System.out.println("#2 conditions: "+ protocol.DGRM_KEEP_ON_ENCODING_ERROR + " : " + datagramError + " # " + duplicate); + if ((protocol.DGRM_KEEP_ON_ENCODING_ERROR || !datagramError) && !duplicate) { + // System.out.println("#3 datagram processed: "+datagram.toString()); datagrams.add(Utils.nibbles2bytes(datagram)); + } state = RX_STATE_IDLE; //messageTick = messageTick; From 592d5b31355dbe87783b295b6f621a3a9f333038 Mon Sep 17 00:00:00 2001 From: Jozef Sovcik Date: Mon, 9 May 2016 20:34:28 +0200 Subject: [PATCH 4/5] minor changes to test --- JPigpio/src/tests/Test_Rf433Rx.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/JPigpio/src/tests/Test_Rf433Rx.java b/JPigpio/src/tests/Test_Rf433Rx.java index d9265dc..67e49b3 100644 --- a/JPigpio/src/tests/Test_Rf433Rx.java +++ b/JPigpio/src/tests/Test_Rf433Rx.java @@ -21,17 +21,18 @@ public static void main(String[] args) throws PigpioException, InterruptedExcept int port = 8888; int waitForData = 20000; // milliseconds to wait for packets - int waitStep = 2000; + int waitStep = 1000; // protocol defines message length, repetition of messages, signal levels etc. Protocol protocol = new Protocol(); - protocol.setRepeatCount(2); // setting this to lowe value than transmitter means duplicates will be reported + protocol.setRepeatCount(5); + protocol.setRxRepeatCount(1); // setting this to lower than TX repeat count value means duplicates will be reported protocol.setDataSize(16); // connect to gpigpiod instance JPigpio pigpio = new PigpioSocket(host,port); - pigpio.gpioInitialize(); + //pigpio.gpioInitialize(); Rf433rx rf433rx = new Rf433rx(pigpio, GPIO_RX, protocol); From 68d2d4e2b807409f6e5d3d8e9186bf0be164e91e Mon Sep 17 00:00:00 2001 From: Jozef Sovcik Date: Mon, 9 May 2016 20:55:17 +0200 Subject: [PATCH 5/5] removing debug printouts --- JPigpio/src/jpigpio/Utils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JPigpio/src/jpigpio/Utils.java b/JPigpio/src/jpigpio/Utils.java index 8d48f78..c6a599a 100644 --- a/JPigpio/src/jpigpio/Utils.java +++ b/JPigpio/src/jpigpio/Utils.java @@ -17,9 +17,9 @@ public static void addShutdown(JPigpio pigpio) { public static int mapToInt(int value, int sourceLow, int sourceHigh, int targetLow, int targetHigh) { double pos = (value-sourceLow)/(double)(sourceHigh - sourceLow); - System.out.println("Pos: " + pos); - System.out.println("tHigh - tLow = " + (targetHigh - targetLow)); - System.out.println("r = " + (targetLow + ((targetHigh - targetLow) * pos))); + //System.out.println("Pos: " + pos); + //System.out.println("tHigh - tLow = " + (targetHigh - targetLow)); + //System.out.println("r = " + (targetLow + ((targetHigh - targetLow) * pos))); return (int)(targetLow + ((targetHigh - targetLow) * pos)); }