Skip to content

Commit

Permalink
optionally store baud rate in rx metadata
Browse files Browse the repository at this point in the history
some transmitters can support different baud rates. storing baud rate in
each beacon can help with rx signal analysis
  • Loading branch information
dernasherbrezon committed Jan 29, 2024
1 parent 0bc1d2f commit ddf5c24
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/main/java/ru/r2cloud/jradio/BeaconInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,19 @@ private T readProtocolv2() throws Exception {
}

private T readProtocolv3() throws Exception {
T result = readProtocolv2();
int length = is.readInt();
byte[] raw = new byte[length];
is.readFully(raw);
T result = clazz.getDeclaredConstructor().newInstance();
result.readExternal(raw);
result.setBeginMillis(is.readLong());
result.setBeginSample(is.readLong());
RxMetadata meta = new RxMetadata();
meta.setRssi(is.readFloat());
meta.setSnr(is.readFloat());
meta.setFrequencyError(is.readLong());
meta.setBaud(is.readInt());
result.setRxMeta(meta);
result.setEndSample(is.readLong());
return result;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ru/r2cloud/jradio/BeaconOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ public void write(Beacon beacon) throws IOException {
} else {
dos.writeLong(0);
}
if (meta.getBaud() != null) {
dos.writeInt(meta.getBaud());
} else {
dos.writeInt(0);
}
} else {
dos.writeFloat(0.0f);
dos.writeFloat(0.0f);
dos.writeLong(0);
dos.writeInt(0);
}
dos.writeLong(beacon.getEndSample());
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/ru/r2cloud/jradio/RxMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ public class RxMetadata {
private Float rssi;
private Float snr;
private Long frequencyError;
private Integer baud;

public Integer getBaud() {
return baud;
}

public void setBaud(Integer baud) {
this.baud = baud;
}

public Float getRssi() {
return rssi;
Expand Down Expand Up @@ -41,7 +50,10 @@ public String toString() {
result.append(" snr=").append(snr);
}
if (frequencyError != null) {
result.append("frequencyError=").append(frequencyError);
result.append(" frequencyError=").append(frequencyError);
}
if (baud != null) {
result.append("baud=").append(baud);
}
result.append(" ]");
return result.toString();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/ru/r2cloud/jradio/sink/SnrCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public static void enrichSnr(FloatInput source, List<Beacon> beacons, long bandw
}

if (snrTotal > 0) {
RxMetadata meta = new RxMetadata();
RxMetadata meta = cur.getRxMeta();
if (meta == null) {
meta = new RxMetadata();
}
meta.setSnr(sumSnr / snrTotal);
cur.setRxMeta(meta);
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/ru/r2cloud/jradio/BeaconInputStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void testReadWrite() throws Exception {
meta.setRssi(1.23f);
meta.setSnr(1.22f);
meta.setFrequencyError(1001l);
meta.setBaud(9600);
data.setRxMeta(meta);
data.setEndSample(2L);

Expand All @@ -43,6 +44,7 @@ public void testReadWrite() throws Exception {
assertEquals(data.getRxMeta().getRssi(), actual.getRxMeta().getRssi(), 0.0001);
assertEquals(data.getRxMeta().getSnr(), actual.getRxMeta().getSnr(), 0.0001);
assertEquals(data.getRxMeta().getFrequencyError(), actual.getRxMeta().getFrequencyError());
assertEquals(data.getRxMeta().getBaud(), actual.getRxMeta().getBaud());
assertEquals(data.getEndSample(), actual.getEndSample());
assertArrayEquals(data.getRawData(), actual.getRawData());
assertFalse(bis.hasNext());
Expand Down

0 comments on commit ddf5c24

Please sign in to comment.