diff --git a/src/main/java/ru/r2cloud/jradio/geoscan/Geoscan.java b/src/main/java/ru/r2cloud/jradio/geoscan/Geoscan.java index 9173fbb3..73872834 100644 --- a/src/main/java/ru/r2cloud/jradio/geoscan/Geoscan.java +++ b/src/main/java/ru/r2cloud/jradio/geoscan/Geoscan.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ru.r2cloud.jradio.Beacon; import ru.r2cloud.jradio.BeaconSource; import ru.r2cloud.jradio.ByteInput; import ru.r2cloud.jradio.blocks.AdditiveScrambler; @@ -14,19 +15,25 @@ import ru.r2cloud.jradio.crc.Crc16Cc11xx; import ru.r2cloud.jradio.fec.ccsds.UncorrectableException; -public class Geoscan extends BeaconSource { +public class Geoscan extends BeaconSource { private static final Logger LOG = LoggerFactory.getLogger(Geoscan.class); private final AdditiveScrambler scrambler; + private final Class clazz; - public Geoscan(ByteInput demod) { - super(new CorrelateSyncword(new SoftToHard(demod), 4, "10010011000010110101000111011110", 66 * 8)); + public Geoscan(ByteInput demod, Class clazz) { + this(demod, clazz, 66); + } + + public Geoscan(ByteInput demod, Class clazz, int beaconSizeBytes) { + super(new CorrelateSyncword(new SoftToHard(demod), 4, "10010011000010110101000111011110", beaconSizeBytes * 8)); scrambler = new AdditiveScrambler(0x21, 0x1ff, 8, 8); + this.clazz = clazz; } @Override - protected GeoscanBeacon parseBeacon(byte[] raw) throws UncorrectableException, IOException { + protected T parseBeacon(byte[] raw) throws UncorrectableException, IOException { raw = UnpackedToPacked.pack(raw); scrambler.shuffle(raw); if (Crc16Cc11xx.calculate(raw, 0, raw.length) != 0) { @@ -38,7 +45,13 @@ protected GeoscanBeacon parseBeacon(byte[] raw) throws UncorrectableException, I // cutoff crc byte[] payload = new byte[raw.length - 2]; System.arraycopy(raw, 0, payload, 0, payload.length); - GeoscanBeacon result = new GeoscanBeacon(); + T result; + try { + result = clazz.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + LOG.error("unable to init beacon", e); + return null; + } result.readExternal(payload); return result; } diff --git a/src/main/java/ru/r2cloud/jradio/sstk1/StratosatTk1.java b/src/main/java/ru/r2cloud/jradio/sstk1/StratosatTk1.java deleted file mode 100644 index 853eb230..00000000 --- a/src/main/java/ru/r2cloud/jradio/sstk1/StratosatTk1.java +++ /dev/null @@ -1,46 +0,0 @@ -package ru.r2cloud.jradio.sstk1; - -import java.io.IOException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import ru.r2cloud.jradio.BeaconSource; -import ru.r2cloud.jradio.ByteInput; -import ru.r2cloud.jradio.blocks.AdditiveScrambler; -import ru.r2cloud.jradio.blocks.CorrelateSyncword; -import ru.r2cloud.jradio.blocks.SoftToHard; -import ru.r2cloud.jradio.blocks.UnpackedToPacked; -import ru.r2cloud.jradio.crc.Crc16Cc11xx; -import ru.r2cloud.jradio.fec.ccsds.UncorrectableException; - -public class StratosatTk1 extends BeaconSource { - - private static final Logger LOG = LoggerFactory.getLogger(StratosatTk1.class); - private final AdditiveScrambler scrambler; - - public StratosatTk1(ByteInput demod) { - this(demod, 66); - } - - public StratosatTk1(ByteInput demod, int beaconSizeBytes) { - super(new CorrelateSyncword(new SoftToHard(demod), 4, "10010011000010110101000111011110", beaconSizeBytes * 8)); - scrambler = new AdditiveScrambler(0x21, 0x1ff, 8, 8); - } - - @Override - protected StratosatTk1Beacon parseBeacon(byte[] raw) throws UncorrectableException, IOException { - raw = UnpackedToPacked.pack(raw); - scrambler.shuffle(raw); - if (Crc16Cc11xx.calculate(raw, 0, raw.length) != 0) { - if (LOG.isDebugEnabled()) { - LOG.debug("crc mismatch"); - } - return null; - } - StratosatTk1Beacon result = new StratosatTk1Beacon(); - result.readExternal(raw); - return result; - } - -} diff --git a/src/test/java/ru/r2cloud/jradio/geoscan/GeoscanTest.java b/src/test/java/ru/r2cloud/jradio/geoscan/GeoscanTest.java index d6c64d47..c840f46a 100644 --- a/src/test/java/ru/r2cloud/jradio/geoscan/GeoscanTest.java +++ b/src/test/java/ru/r2cloud/jradio/geoscan/GeoscanTest.java @@ -10,15 +10,14 @@ import ru.r2cloud.jradio.source.WavFileSource; public class GeoscanTest { - - - private Geoscan input; + + private Geoscan input; @Test public void testDecodeTelemetry() throws Exception { WavFileSource source = new WavFileSource(GeoscanTest.class.getClassLoader().getResourceAsStream("geoscan.wav")); FskDemodulator demod = new FskDemodulator(source, 9600, 5000.0f, 1, 2000.0f, true); - input = new Geoscan(demod); + input = new Geoscan<>(demod, GeoscanBeacon.class); assertTrue(input.hasNext()); AssertJson.assertObjectsEqual("GeoscanBeacon.json", input.next()); } @@ -30,5 +29,4 @@ public void stop() throws Exception { } } - } diff --git a/src/test/java/ru/r2cloud/jradio/sstk1/StratosatTk1Test.java b/src/test/java/ru/r2cloud/jradio/sstk1/StratosatTk1Test.java index 1eabf025..51f8cf64 100644 --- a/src/test/java/ru/r2cloud/jradio/sstk1/StratosatTk1Test.java +++ b/src/test/java/ru/r2cloud/jradio/sstk1/StratosatTk1Test.java @@ -11,17 +11,18 @@ import ru.r2cloud.jradio.AssertJson; import ru.r2cloud.jradio.demod.FskDemodulator; +import ru.r2cloud.jradio.geoscan.Geoscan; import ru.r2cloud.jradio.source.WavFileSource; public class StratosatTk1Test { - private StratosatTk1 input; + private Geoscan input; @Test public void testDecodeTelemetry() throws Exception { WavFileSource source = new WavFileSource(StratosatTk1Test.class.getClassLoader().getResourceAsStream("sstk1.wav")); FskDemodulator demod = new FskDemodulator(source, 9600, 5000.0f, 1, 2000.0f, true); - input = new StratosatTk1(demod); + input = new Geoscan<>(demod, StratosatTk1Beacon.class); assertTrue(input.hasNext()); input.next(); AssertJson.assertObjectsEqual("StratosatTk1.json", input.next()); diff --git a/src/test/resources/expected/StratosatTk1.json b/src/test/resources/expected/StratosatTk1.json index 9f319e8f..041f7103 100644 --- a/src/test/resources/expected/StratosatTk1.json +++ b/src/test/resources/expected/StratosatTk1.json @@ -104,9 +104,7 @@ 0, 0, 0, - 0, - -85, - -3 + 0 ], "beginSample": 1796, "beginMillis": 0,