From ddf5c24372ba0a14ccb5d59de256933ae8ff4a5f Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Mon, 29 Jan 2024 20:47:29 +0000 Subject: [PATCH] optionally store baud rate in rx metadata some transmitters can support different baud rates. storing baud rate in each beacon can help with rx signal analysis --- .../java/ru/r2cloud/jradio/BeaconInputStream.java | 14 +++++++++++++- .../java/ru/r2cloud/jradio/BeaconOutputStream.java | 6 ++++++ src/main/java/ru/r2cloud/jradio/RxMetadata.java | 14 +++++++++++++- .../java/ru/r2cloud/jradio/sink/SnrCalculator.java | 5 ++++- .../ru/r2cloud/jradio/BeaconInputStreamTest.java | 2 ++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/r2cloud/jradio/BeaconInputStream.java b/src/main/java/ru/r2cloud/jradio/BeaconInputStream.java index 2b834df7..cc715165 100644 --- a/src/main/java/ru/r2cloud/jradio/BeaconInputStream.java +++ b/src/main/java/ru/r2cloud/jradio/BeaconInputStream.java @@ -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; } diff --git a/src/main/java/ru/r2cloud/jradio/BeaconOutputStream.java b/src/main/java/ru/r2cloud/jradio/BeaconOutputStream.java index 4a3621f4..7c38dd4b 100644 --- a/src/main/java/ru/r2cloud/jradio/BeaconOutputStream.java +++ b/src/main/java/ru/r2cloud/jradio/BeaconOutputStream.java @@ -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()); } diff --git a/src/main/java/ru/r2cloud/jradio/RxMetadata.java b/src/main/java/ru/r2cloud/jradio/RxMetadata.java index 1ca93929..f9f28344 100644 --- a/src/main/java/ru/r2cloud/jradio/RxMetadata.java +++ b/src/main/java/ru/r2cloud/jradio/RxMetadata.java @@ -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; @@ -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(); diff --git a/src/main/java/ru/r2cloud/jradio/sink/SnrCalculator.java b/src/main/java/ru/r2cloud/jradio/sink/SnrCalculator.java index d9d6b84f..51dce0a8 100644 --- a/src/main/java/ru/r2cloud/jradio/sink/SnrCalculator.java +++ b/src/main/java/ru/r2cloud/jradio/sink/SnrCalculator.java @@ -87,7 +87,10 @@ public static void enrichSnr(FloatInput source, List 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); } diff --git a/src/test/java/ru/r2cloud/jradio/BeaconInputStreamTest.java b/src/test/java/ru/r2cloud/jradio/BeaconInputStreamTest.java index 364c00cb..65798e68 100644 --- a/src/test/java/ru/r2cloud/jradio/BeaconInputStreamTest.java +++ b/src/test/java/ru/r2cloud/jradio/BeaconInputStreamTest.java @@ -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); @@ -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());