diff --git a/src/main/java/io/github/dsheirer/dsp/NRZDecoder.java b/src/main/java/io/github/dsheirer/dsp/NRZDecoder.java index 2c1e9e68..a93e9c01 100644 --- a/src/main/java/io/github/dsheirer/dsp/NRZDecoder.java +++ b/src/main/java/io/github/dsheirer/dsp/NRZDecoder.java @@ -1,77 +1,76 @@ /******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see + * sdr-trunk + * Copyright (C) 2014-2018 Dennis Sheirer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * ******************************************************************************/ package io.github.dsheirer.dsp; +import io.github.dsheirer.bits.IBinarySymbolProcessor; import io.github.dsheirer.sample.Listener; -public class NRZDecoder implements Listener +public class NRZDecoder implements IBinarySymbolProcessor { - public final static boolean MODE_NORMAL = true; - public final static boolean MODE_INVERTED = false; - - private Listener mListener; - private boolean mMode = MODE_NORMAL; - private boolean mPrevious; + public final static boolean MODE_NORMAL = true; + public final static boolean MODE_INVERTED = false; - /** - * Non Return To Zero (NRZ) and NRZ Inverted (NRZ-I) Decoder. - * - * Use default constructor for NRZ output. Use the alternate constructor - * with the MODE_INVERTED argument for NRZ-I output. - * - * Performs XOR of incoming bit with previous output and sends the result - * to the registered listener. - */ - public NRZDecoder( boolean mode ) - { - mMode = mode; - } - - public NRZDecoder() - { - this( MODE_NORMAL ); - } - - public void dispose() - { - mListener = null; - } + private IBinarySymbolProcessor mListener; + private boolean mMode = MODE_NORMAL; + private boolean mPrevious; - @Override - public void receive( Boolean bit ) + /** + * Non Return To Zero (NRZ) and NRZ Inverted (NRZ-I) Decoder. + * + * Use default constructor for NRZ output. Use the alternate constructor + * with the MODE_INVERTED argument for NRZ-I output. + * + * Performs XOR of incoming bit with previous output and sends the result + * to the registered listener. + */ + public NRZDecoder(boolean mode) { - boolean result = mPrevious ^ bit; - - if( mListener != null ) - { - mListener.receive( mMode ? result : !result ); - } - - mPrevious = result; + mMode = mode; } - public void setListener( Listener listener ) - { - mListener = listener; - } - - public void removeListener( Listener listener ) - { - mListener = null; - } + public NRZDecoder() + { + this(MODE_NORMAL); + } + + public void dispose() + { + mListener = null; + } + + @Override + public void receive(boolean symbol) + { + boolean result = mPrevious ^ symbol; + + if(mListener != null) + { + mListener.receive(mMode ? result : !result); + } + + mPrevious = result; + } + + public void setListener(IBinarySymbolProcessor listener) + { + mListener = listener; + } + + public void removeListener(Listener listener) + { + mListener = null; + } } diff --git a/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/DecoderPaneFactory.java b/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/DecoderPaneFactory.java index 15153790..a78202c8 100644 --- a/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/DecoderPaneFactory.java +++ b/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/DecoderPaneFactory.java @@ -27,6 +27,7 @@ public class DecoderPaneFactory DecoderType.FLEETSYNC2, DecoderType.LJ_1200, DecoderType.LTR_NET, + DecoderType.MDC1200, DecoderType.MPT1327, DecoderType.TAIT_1200); @@ -43,6 +44,8 @@ public class DecoderPaneFactory return new LJ1200Pane(); case LTR_NET: return new LTRNetPane(); + case MDC1200: + return new MDC1200Pane(); case MPT1327: return new MPT1327Pane(); case TAIT_1200: diff --git a/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/MDC1200Pane.java b/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/MDC1200Pane.java new file mode 100644 index 00000000..80953de9 --- /dev/null +++ b/src/main/java/io/github/dsheirer/instrument/gui/viewer/decoder/MDC1200Pane.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * sdr-trunk + * Copyright (C) 2014-2018 Dennis Sheirer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * + ******************************************************************************/ +package io.github.dsheirer.instrument.gui.viewer.decoder; + +import io.github.dsheirer.dsp.symbol.ISyncDetectListener; +import io.github.dsheirer.module.decode.DecoderType; +import io.github.dsheirer.module.decode.mdc1200.MDCDecoderInstrumented; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MDC1200Pane extends AbstractAFSK1200Pane +{ + private final static Logger mLog = LoggerFactory.getLogger(MDC1200Pane.class); + + private MDCDecoderInstrumented mDecoder; + + public MDC1200Pane() + { + super(DecoderType.MDC1200); + } + + protected MDCDecoderInstrumented getDecoder() + { + if(mDecoder == null) + { + mDecoder = new MDCDecoderInstrumented(); + mDecoder.getMessageFramer().setSyncDetectListener(new ISyncDetectListener() + { + @Override + public void syncDetected() + { + mLog.debug("Sync Detected!"); + } + }); + } + + return mDecoder; + } +} diff --git a/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoder.java b/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoder.java index 735871fa..f4910c4a 100644 --- a/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoder.java +++ b/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoder.java @@ -1,19 +1,17 @@ /******************************************************************************* - * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see + * sdr-trunk + * Copyright (C) 2014-2018 Dennis Sheirer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * ******************************************************************************/ package io.github.dsheirer.module.decode.mdc1200; @@ -21,183 +19,60 @@ import io.github.dsheirer.alias.AliasList; import io.github.dsheirer.bits.MessageFramer; import io.github.dsheirer.bits.SyncPattern; import io.github.dsheirer.dsp.NRZDecoder; -import io.github.dsheirer.dsp.filter.Filters; -import io.github.dsheirer.dsp.filter.fir.real.RealFIRFilter_RB_RB; -import io.github.dsheirer.dsp.filter.halfband.real.HalfBandFilter_RB_RB; -import io.github.dsheirer.dsp.fsk.FSK2Decoder; -import io.github.dsheirer.dsp.fsk.FSK2Decoder.Output; -import io.github.dsheirer.instrument.Instrumentable; -import io.github.dsheirer.instrument.tap.Tap; -import io.github.dsheirer.instrument.tap.TapGroup; -import io.github.dsheirer.instrument.tap.stream.BinaryTap; -import io.github.dsheirer.instrument.tap.stream.FloatBufferTap; -import io.github.dsheirer.instrument.tap.stream.FloatTap; -import io.github.dsheirer.module.decode.Decoder; +import io.github.dsheirer.dsp.afsk.AFSK1200Decoder; import io.github.dsheirer.module.decode.DecoderType; -import io.github.dsheirer.sample.Listener; -import io.github.dsheirer.sample.real.IFilteredRealBufferListener; -import io.github.dsheirer.sample.real.RealBuffer; - -import java.util.ArrayList; -import java.util.List; +import io.github.dsheirer.module.decode.afsk.AbstractAFSKDecoder; /** - * MDC1200 Decoder - 1200 baud 2FSK decoder that can process 48k sample rate - * complex or floating point samples and output fully framed MDC1200 messages + * MDC1200 Decoder - 1200 baud 2FSK decoder */ -public class MDCDecoder extends Decoder implements IFilteredRealBufferListener, - Instrumentable +public class MDCDecoder extends AbstractAFSKDecoder { - /* Decimated sample rate ( 48,000 / 2 = 24,000 ) feeding the decoder */ - private static final int sDECIMATED_SAMPLE_RATE = 24000; - - /* Baud or Symbol Rate */ - private static final int sSYMBOL_RATE = 1200; + private static final int MESSAGE_LENGTH = 304; - /* Message length */ - private static final int sMESSAGE_LENGTH = 304; - - /* Instrumentation Taps */ - private ArrayList mAvailableTaps; - private static final String INSTRUMENT_BANDPASS_FILTER_TO_FSK2_DEMOD = - "Tap Point: Bandpass Filter > < FSK2 Decoder"; - private static final String INSTRUMENT_FSK2_DECODER_TO_NRZ_DECODER = - "Tap Point: FSK2 Decoder > < NRZI Decoder"; - private static final String INSTRUMENT_NRZI_DECODER_TO_MESSAGE_FRAMER = - "Tap Point: NRZ Decoder > < Message Framer"; - - private FSK2Decoder mFSKDecoder; - private HalfBandFilter_RB_RB mDecimationFilter; - private RealFIRFilter_RB_RB mBandPassFilter; private NRZDecoder mNRZDecoder; private MessageFramer mMessageFramer; private MDCMessageProcessor mMessageProcessor; - - public MDCDecoder( AliasList aliasList ) - { - /* Decimation filter: 48000 / 2 = 24000 */ - mDecimationFilter = new HalfBandFilter_RB_RB( - Filters.FIR_HALF_BAND_31T_ONE_EIGHTH_FCO.getCoefficients(), 1.0f, true ); - /* Bandpass filter - predefined */ - mBandPassFilter = new RealFIRFilter_RB_RB( - Filters.FIRBP_1200FSK_24000FS.getCoefficients(), 1.02f ); - mDecimationFilter.setListener( mBandPassFilter ); + public MDCDecoder(AliasList aliasList) + { + super(AFSK1200Decoder.Output.INVERTED); + init(aliasList); + } - /* 2FSK Decoder */ - mFSKDecoder = new FSK2Decoder( sDECIMATED_SAMPLE_RATE, - sSYMBOL_RATE, Output.NORMAL ); - mBandPassFilter.setListener( mFSKDecoder ); + protected MDCDecoder(AFSK1200Decoder decoder, AliasList aliasList) + { + super(decoder); + init(aliasList); + } - /* NRZ Decoder */ - mNRZDecoder = new NRZDecoder( NRZDecoder.MODE_INVERTED ); - mFSKDecoder.setListener( mNRZDecoder ); - - /* Message Framer */ - mMessageFramer = new MessageFramer( SyncPattern.MDC1200.getPattern(), - sMESSAGE_LENGTH ); - mNRZDecoder.setListener( mMessageFramer ); - - /* Message Processor */ - mMessageProcessor = new MDCMessageProcessor( aliasList ); - mMessageFramer.addMessageListener( mMessageProcessor ); + private void init(AliasList aliasList) + { + mNRZDecoder = new NRZDecoder(NRZDecoder.MODE_INVERTED); + getDecoder().setSymbolProcessor(mNRZDecoder); + mMessageFramer = new MessageFramer(SyncPattern.MDC1200.getPattern(), MESSAGE_LENGTH); + mNRZDecoder.setListener(mMessageFramer); + mMessageProcessor = new MDCMessageProcessor(aliasList); + mMessageFramer.addMessageListener(mMessageProcessor); mMessageProcessor.addMessageListener(getMessageListener()); - } - + } + public void dispose() { - super.dispose(); - - mDecimationFilter.dispose(); - mBandPassFilter.dispose(); - mFSKDecoder.dispose(); - mNRZDecoder.dispose(); - mMessageFramer.dispose(); - mMessageProcessor.dispose(); + super.dispose(); + mNRZDecoder.dispose(); + mMessageFramer.dispose(); + mMessageProcessor.dispose(); } - /* Instrumentation */ - @Override - public List getTapGroups() + @Override + public DecoderType getDecoderType() { - if( mAvailableTaps == null ) - { - mAvailableTaps = new ArrayList(); - - TapGroup group = new TapGroup( "MDC-1200 Decoder" ); - - group.add( - new FloatTap( INSTRUMENT_BANDPASS_FILTER_TO_FSK2_DEMOD, 0, 0.5f ) ); - group.add( - new BinaryTap( INSTRUMENT_FSK2_DECODER_TO_NRZ_DECODER, 0, 0.025f ) ); - group.add( - new BinaryTap( INSTRUMENT_NRZI_DECODER_TO_MESSAGE_FRAMER, 0, 0.025f ) ); - - mAvailableTaps.add( group ); - mAvailableTaps.addAll( mFSKDecoder.getTapGroups() ); - } - - return mAvailableTaps; + return DecoderType.MDC1200; } - @Override - public void registerTap( Tap tap ) + public MessageFramer getMessageFramer() { - mFSKDecoder.registerTap( tap ); - - switch( tap.getName() ) - { - case INSTRUMENT_BANDPASS_FILTER_TO_FSK2_DEMOD: - /* wire the tap between the bandpass filter and the demod */ - FloatBufferTap floatTap = (FloatBufferTap)tap; - mBandPassFilter.setListener( floatTap ); - floatTap.setListener( mFSKDecoder ); - break; - case INSTRUMENT_FSK2_DECODER_TO_NRZ_DECODER: - /* wire between FSK2 decoder and NRZ decoder */ - BinaryTap binTap = (BinaryTap)tap; - mFSKDecoder.setListener( binTap ); - binTap.setListener( mNRZDecoder ); - break; - case INSTRUMENT_NRZI_DECODER_TO_MESSAGE_FRAMER: - /* wire between demod and framer */ - BinaryTap binInvTap = (BinaryTap)tap; - mNRZDecoder.setListener( binInvTap ); - binInvTap.setListener( mMessageFramer ); - break; - default: - } + return mMessageFramer; } - - @Override - public void unregisterTap( Tap tap ) - { - mFSKDecoder.unregisterTap( tap ); - - switch( tap.getName() ) - { - case INSTRUMENT_BANDPASS_FILTER_TO_FSK2_DEMOD: - mBandPassFilter.setListener( mFSKDecoder ); - break; - case INSTRUMENT_FSK2_DECODER_TO_NRZ_DECODER: - mFSKDecoder.setListener( mNRZDecoder ); - break; - case INSTRUMENT_NRZI_DECODER_TO_MESSAGE_FRAMER: - mNRZDecoder.setListener( mMessageFramer ); - break; - default: - } - } - - @Override - public DecoderType getDecoderType() - { - return DecoderType.MDC1200; - } - - @Override - public Listener getFilteredRealBufferListener() - { - return mDecimationFilter; - } } diff --git a/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoderInstrumented.java b/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoderInstrumented.java new file mode 100644 index 00000000..1e2bdafd --- /dev/null +++ b/src/main/java/io/github/dsheirer/module/decode/mdc1200/MDCDecoderInstrumented.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * sdr-trunk + * Copyright (C) 2014-2018 Dennis Sheirer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see + * + ******************************************************************************/ +package io.github.dsheirer.module.decode.mdc1200; + +import io.github.dsheirer.dsp.afsk.AFSK1200DecoderInstrumented; +import io.github.dsheirer.instrument.gui.viewer.chart.IInstrumentedAFSK1200Decoder; +import io.github.dsheirer.sample.buffer.ReusableBuffer; +import javafx.beans.property.SimpleIntegerProperty; + +/** + * Instrumented version of the AFSK-1200 decoder for use with DemodulatorViewerFX + */ +public class MDCDecoderInstrumented extends MDCDecoder implements IInstrumentedAFSK1200Decoder +{ + public SimpleIntegerProperty bufferCount = new SimpleIntegerProperty(); + + public MDCDecoderInstrumented() + { + super(new AFSK1200DecoderInstrumented(false), null); + } + + @Override + public SimpleIntegerProperty getBufferCountProperty() + { + return bufferCount; + } + + public AFSK1200DecoderInstrumented getAFSK1200Decoder() + { + return (AFSK1200DecoderInstrumented)getDecoder(); + } + + @Override + public void receive(ReusableBuffer reusableBuffer) + { + super.receive(reusableBuffer); + + bufferCount.setValue(bufferCount.intValue() + 1); + } +}