Skip to content

Commit

Permalink
#1506 Unifies recording filename prefixes across baseband, mbe and bi…
Browse files Browse the repository at this point in the history
…nary recordings.
  • Loading branch information
Dennis Sheirer committed Apr 8, 2023
1 parent 8d1f704 commit ced7b51
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* ******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2018 Dennis Sheirer
* *****************************************************************************
* Copyright (C) 2014-2023 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
Expand All @@ -15,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* *****************************************************************************
* ****************************************************************************
*/

package io.github.dsheirer.preference;
Expand All @@ -30,7 +29,7 @@ public enum TimestampFormat
TIMESTAMP_DEFAULT("yyyy-MM-dd HH:mm:ss", "Timestamp: yyyy-MM-dd HH:mm:ss"),
TIMESTAMP_COLONS("yyyy:MM:dd:HH:mm:ss", "Timestamp Colons: yyyy:MM:dd:HH:mm:ss"),
TIMESTAMP_MILLIS("yyyy:MM:dd:HH:mm:ss.SSS", "Timestamp Milliseconds: yyyy:MM:dd:HH:mm:ss.SSS"),
TIMESTAMP_COMPACT("yyyyMMddHHmmss", "Timestamp Compact: yyyyMMddHHmmss"),
TIMESTAMP_COMPACT("yyyyMMddHHmmss", "Timestamp Compact: yyyyMMdd_HHmmss"),
DATE_DASHES("yyyy-MM-dd", "Date Dashes: YYYY-MM-DD"),
DATE_COLONS("yyyy:MM:dd", "Date Colons: YYYY:MM:DD"),
DATE_COMPACT("yyyyMMdd", "Date Compact: YYYYMMDD"),
Expand Down
74 changes: 33 additions & 41 deletions src/main/java/io/github/dsheirer/record/RecorderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import io.github.dsheirer.record.wave.NativeBufferWaveRecorder;
import io.github.dsheirer.source.config.SourceConfigTuner;
import io.github.dsheirer.source.config.SourceConfigTunerMultipleFrequency;
import io.github.dsheirer.source.config.SourceConfiguration;
import io.github.dsheirer.util.StringUtils;
import io.github.dsheirer.util.TimeStamp;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -57,47 +57,43 @@ public static List<Module> getRecorders(UserPreferences userPreferences, Channel

for(RecorderType recorderType: channel.getRecordConfiguration().getRecorders())
{
long frequency = getFrequency(channel);

switch(recorderType)
{
case BASEBAND:
if(channel.isStandardChannel())
{
recorderModules.add(getBasebandRecorder(channel.toString(), userPreferences));
recorderModules.add(getBasebandRecorder(channel.toString(), frequency, userPreferences));
}
break;
case DEMODULATED_BIT_STREAM:
if(channel.isStandardChannel() && channel.getDecodeConfiguration().getDecoderType().providesBitstream())
{
recorderModules.add(new BinaryRecorder(getRecordingBasePath(userPreferences),
getRecordingNameFromChannel(channel), channel.getDecodeConfiguration().getDecoderType().getProtocol()));
StringUtils.replaceIllegalCharacters(channel.toString()),
channel.getDecodeConfiguration().getDecoderType().getProtocol(),
frequency));
}
break;
case TRAFFIC_BASEBAND:
if(channel.isTrafficChannel())
{
recorderModules.add(getBasebandRecorder(channel.toString(), userPreferences));
recorderModules.add(getBasebandRecorder(channel.toString(), frequency, userPreferences));
}
break;
case TRAFFIC_DEMODULATED_BIT_STREAM:
if(channel.isTrafficChannel() && channel.getDecodeConfiguration().getDecoderType().providesBitstream())
{
recorderModules.add(new BinaryRecorder(getRecordingBasePath(userPreferences),
getRecordingNameFromChannel(channel), channel.getDecodeConfiguration().getDecoderType().getProtocol()));
StringUtils.replaceIllegalCharacters(channel.toString()),
channel.getDecodeConfiguration().getDecoderType().getProtocol(),
frequency));
}
break;
case MBE_CALL_SEQUENCE:
if(channel.isStandardChannel() && channel.getSourceConfiguration() instanceof SourceConfigTuner)
{
long frequency = 0;

if(channel.getSourceConfiguration() instanceof SourceConfigTuner)
{
frequency = ((SourceConfigTuner)channel.getSourceConfiguration()).getFrequency();
}
else if(channel.getSourceConfiguration() instanceof SourceConfigTunerMultipleFrequency)
{
frequency = ((SourceConfigTunerMultipleFrequency)channel.getSourceConfiguration()).getFrequencies().get(0);
}

switch(channel.getDecodeConfiguration().getDecoderType())
{
Expand All @@ -119,19 +115,12 @@ else if(channel.getSourceConfiguration() instanceof SourceConfigTunerMultipleFre
case TRAFFIC_MBE_CALL_SEQUENCE:
if(channel.isTrafficChannel() && channel.getSourceConfiguration() instanceof SourceConfigTuner)
{
long frequency = 0;

if(channel.getSourceConfiguration() instanceof SourceConfigTuner)
{
frequency = ((SourceConfigTuner)channel.getSourceConfiguration()).getFrequency();
}
else if(channel.getSourceConfiguration() instanceof SourceConfigTunerMultipleFrequency)
{
frequency = ((SourceConfigTunerMultipleFrequency)channel.getSourceConfiguration()).getFrequencies().get(0);
}

switch(channel.getDecodeConfiguration().getDecoderType())
{
case DMR:
recorderModules.add(new DMRCallSequenceRecorder(userPreferences, frequency,
channel.getSystem(), channel.getSite()));
break;
case P25_PHASE1:
recorderModules.add(new P25P1CallSequenceRecorder(userPreferences, frequency,
channel.getSystem(), channel.getSite()));
Expand All @@ -150,24 +139,22 @@ else if(channel.getSourceConfiguration() instanceof SourceConfigTunerMultipleFre
}

/**
* Creates a recording file name from the channel frequency and the channel configuration.
* @param channel to process
* @return recording file name.
* Extract the frequency from the channel configuration
* @param channel with a source configuration
* @return frequency
*/
private static String getRecordingNameFromChannel(Channel channel)
private static long getFrequency(Channel channel)
{
if(channel.getSourceConfiguration() != null)
if(channel.getSourceConfiguration() instanceof SourceConfigTuner)
{
SourceConfiguration sourceConfiguration = channel.getSourceConfiguration();

if(sourceConfiguration instanceof SourceConfigTuner sourceConfigTuner)
{
long frequency = sourceConfigTuner.getFrequency();
return frequency + "_" + channel.toString();
}
return ((SourceConfigTuner)channel.getSourceConfiguration()).getFrequency();
}
else if(channel.getSourceConfiguration() instanceof SourceConfigTunerMultipleFrequency)
{
return ((SourceConfigTunerMultipleFrequency)channel.getSourceConfiguration()).getFrequencies().get(0);
}

return StringUtils.replaceIllegalCharacters(channel.toString());
return 0;
}

/**
Expand All @@ -181,11 +168,16 @@ public static Path getRecordingBasePath(UserPreferences userPreferences)
/**
* Constructs a baseband recorder for use in a processing chain.
*/
public static ComplexSamplesWaveRecorder getBasebandRecorder(String channelName, UserPreferences userPreferences)
public static ComplexSamplesWaveRecorder getBasebandRecorder(String channelName, long frequency, UserPreferences userPreferences)
{
StringBuilder sb = new StringBuilder();
sb.append(getRecordingBasePath(userPreferences));
sb.append(File.separator).append(StringUtils.replaceIllegalCharacters(channelName)).append("_baseband");
sb.append(File.separator);
sb.append(TimeStamp.getTimeStamp("_"));
sb.append("_");
sb.append(frequency);
sb.append("_");
sb.append(StringUtils.replaceIllegalCharacters(channelName)).append("_baseband");

return new ComplexSamplesWaveRecorder(BASEBAND_SAMPLE_RATE, sb.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ public class BinaryRecorder extends Module implements IByteBufferListener
private BinaryWriter mBinaryWriter = new BinaryWriter();
private int mBytesRecordedCounter;
private Protocol mProtocol;
private long mFrequency;

/**
* Constructs a binary recorder.
*
* @param baseRecordingPath where the recording should be created
* @param recordingIdentifier to include in the recording file name.
* @param protocol to include as a values in the recording file name
* @param frequency in hertz
*/
public BinaryRecorder(Path baseRecordingPath, String recordingIdentifier, Protocol protocol)
public BinaryRecorder(Path baseRecordingPath, String recordingIdentifier, Protocol protocol, long frequency)
{
mBaseRecordingPath = baseRecordingPath;
mRecordingIdentifier = recordingIdentifier;
mBufferProcessor.setListener(mBinaryWriter);
mProtocol = protocol;
mFrequency = frequency;
}

public void start()
Expand Down Expand Up @@ -120,6 +123,8 @@ private Path getRecordingPath()
StringBuilder sb = new StringBuilder();
sb.append(TimeStamp.getTimeStamp("_"));
sb.append("_");
sb.append(mFrequency);
sb.append("_");
sb.append(mProtocol.getBitRate()).append("BPS_");
sb.append(mProtocol.getFileNameLabel()).append("_");
sb.append(mRecordingIdentifier.trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.util.Dispatcher;
import io.github.dsheirer.util.ThreadPool;
import io.github.dsheirer.util.TimeStamp;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -85,8 +84,6 @@ public void start()
{
StringBuilder sb = new StringBuilder();
sb.append(mFilePrefix);
sb.append("_");
sb.append(TimeStamp.getTimeStamp("_"));
sb.append(".wav");
mFile = Paths.get(sb.toString());

Expand Down

0 comments on commit ced7b51

Please sign in to comment.