Skip to content

Commit

Permalink
Merge pull request #1 from sovcik/sync2
Browse files Browse the repository at this point in the history
Fixed packet RX
  • Loading branch information
sovcik committed May 9, 2016
2 parents 301a4f1 + 68d2d4e commit 38aa2bc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion JPigpio/src/jpigpio/SocketLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions JPigpio/src/jpigpio/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
12 changes: 10 additions & 2 deletions JPigpio/src/jpigpio/packet/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion JPigpio/src/jpigpio/packet/Rf433rx.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;

Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions JPigpio/src/tests/Test_Rf433Rx.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 38aa2bc

Please sign in to comment.