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(); } 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)); } 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; + } } 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; 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);