Skip to content

Commit

Permalink
Merge pull request #480 from leee/leee-max-duration
Browse files Browse the repository at this point in the history
Add maximum call duration to split long calls
  • Loading branch information
robotastic committed May 21, 2021
2 parents f3e3203 + 52b2c1c commit dcbbc4e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ This file is used to configure how Trunk Recorder is setup. It defines the SDRs
}
```
Here are the different arguments:
- **ver** - the version of formatting for the config file. **This should be set to 2**. Trunk Recorder will not start without this set.
- **ver** - the version of formatting for the config file. **This should be set to 2**. Trunk Recorder will not start without this set.
- **sources** - an array of JSON objects that define the different SDRs available. The following options are used to configure each Source:
- **center** - the center frequency in Hz to tune the SDR to
- **rate** - the sampling rate to set the SDR to, in samples / second
Expand All @@ -113,7 +113,7 @@ Here are the different arguments:
- **analogLevels** - the amount of amplification that will be applied to the analog audio. The value should be between 1-32. The default value is 8.
- **digitalLevels** - the amount of amplification that will be applied to the digital audio. The value should be between 1-16. The default value is 1.
- **modulation** - the type of modulation that the system uses. The options are *qpsk* & *fsk4*. It is possible to have a mix of sources using fsk4 and qpsk demodulation.
- **squelch** - Squelch in DB, this needs to be set for all convetional systems. The squelch setting is also used for analog talkgroups in a SmartNet system. I generally use -60 for my rtl-sdr. Defaults to 0, which is disabled.
- **squelch** - Squelch in DB, this needs to be set for all convetional systems. The squelch setting is also used for analog talkgroups in a SmartNet system. I generally use -60 for my rtl-sdr. Defaults to 0, which is disabled.
- **maxDev** - Allows you to set the maximum deviation for analog channels. The default is 4000. If you analog recordings sound good or if you have a completely digital system, then there is no need to tough this.
- **channels** - *(For conventional systems)* an array of the channel frequencies, in Hz, used for the system. The channels get assigned a virtual talkgroup number based upon their position in the array. Squelch levels need to be specified for the Source(s) being used.
- **alphatags** - *(Optional, For conventional systems)* an array of the alpha tags, these will be outputed to the logfiles *talkgroupDisplayFormat* is set to include tags. Alpha tags will be applied to the *channels* in the order the values appear in the array.
Expand All @@ -130,6 +130,7 @@ Here are the different arguments:
- **audioArchive** - should the recorded audio files be kept after successfully uploading them. The options are *true* and *false* (without quotes). The default is *true*.
- **callLog** - should a json file with the call details be kept after successful uploads. The options are *true* and *false* (without quotes). The default is *true*.
- **minDuration** - the minimum call (transmission) duration in seconds (decimals allowed), calls below this number will have recordings deleted and will not be uploaded. The default is *0* (no minimum duration).
- **maxDuration** - If a call is being recorded and the duration exceeds this value in seconds, the call will stop recording and a new call will pick up where the previous on left off. The default is *0* or "no timeout".
- **bandplan** - [SmartNet only] this is the SmartNet bandplan that will be used. The options are *800_standard*, *800_reband*, *800_splinter*, and *400_custom*. *800_standard* is the default.
- **bandplanBase** - [SmartNet, 400_custom only] this is for the *400_custom* bandplan only. This is the base frequency, specified in Hz.
- **bandplanHigh** - [SmartNet, 400_custom only] this is the highest channel in the system, specified in Hz.
Expand Down
1 change: 1 addition & 0 deletions trunk-recorder/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Config {
bool log_file;
int control_message_warn_rate;
float control_message_warn_updates;
int max_duration;
int control_retune_limit;
bool broadcast_signals;
};
Expand Down
34 changes: 29 additions & 5 deletions trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ bool load_config(string config_file) {
BOOST_LOG_TRIVIAL(info) << "Hide Unknown Talkgroups: " << system->get_hideUnknown();
system->set_min_duration(node.second.get<double>("minDuration", 0));
BOOST_LOG_TRIVIAL(info) << "Minimum Call Duration (in seconds): " << system->get_min_duration();
system->set_max_duration(node.second.get<double>("maxDuration", 0));
BOOST_LOG_TRIVIAL(info) << "Maximum Call Duration (in seconds): " << system->get_max_duration();

systems.push_back(system);
BOOST_LOG_TRIVIAL(info);
Expand Down Expand Up @@ -742,9 +744,18 @@ void stop_inactive_recorders() {
call->reset_idle_count();
}

// if no additional recording has happened in the past X periods, stop and open new file
// if no additional recording has happened in the past X periods, or the call has gone on for longer than max_duration, stop and open new file
if (call->get_idle_count() > 5) {
Recorder *recorder = call->get_recorder();
Recorder * recorder = call->get_recorder();
call->end_call();
stats.send_call_end(call);
call->restart_call();
if (recorder != NULL) {
stats.send_recorder(recorder);
}
} else if (call->get_current_length() > call->get_system()->get_max_duration() && call->get_system()->get_max_duration() > 0) {
BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t Restarting this call as it has a duration more than maximum duration of " << call->get_system()->get_max_duration() << "\tTG: " << call->get_talkgroup_display() << "\tFreq: " << FormatFreq(call->get_freq()) << "\tCall Duration: " << call->get_current_length() << "s";
Recorder * recorder = call->get_recorder();
call->end_call();
stats.send_call_end(call);
call->restart_call();
Expand All @@ -753,7 +764,7 @@ void stop_inactive_recorders() {
}
}
} else if (!call->get_recorder()->is_active()) {
// P25 Conventional Recorders need a have the graph unlocked before they can start recording.
// P25 Conventional Recorders need a have the graph unlocked before they can start recording.
Recorder *recorder = call->get_recorder();
recorder->start(call);
call->set_state(recording);
Expand All @@ -773,6 +784,19 @@ void stop_inactive_recorders() {
}
it = calls.erase(it);
delete call;
} else if (call->get_current_length() > call->get_system()->get_max_duration() && call->get_system()->get_max_duration() > 0) {
BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t Restarting this call as it has a duration more than maximum duration of " << call->get_system()->get_max_duration() << "\tTG: " << call->get_talkgroup_display() << "\tFreq: " << FormatFreq(call->get_freq()) << "\tCall Duration: " << call->get_current_length() << "s";
if (call->get_state() == recording) {
ended_recording = true;
}
Recorder *recorder = call->get_recorder();
call->end_call();
stats.send_call_end(call);
if (recorder != NULL) {
stats.send_recorder(recorder);
}
it = calls.erase(it);
delete call;
} else {
++it;
} // if rx is active
Expand Down Expand Up @@ -1351,7 +1375,7 @@ bool monitor_system() {
rec = source->create_digital_conventional_recorder(tb);
call->set_recorder((Recorder *)rec.get());
calls.push_back(call);

}

// break out of the for loop
Expand Down Expand Up @@ -1442,7 +1466,7 @@ int main(int argc, char **argv) {
logging::trivial::severity >= logging::trivial::info

);

boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");

boost::log::add_common_attributes();
Expand Down
8 changes: 8 additions & 0 deletions trunk-recorder/systems/system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ void System::set_min_duration(double duration) {
this->min_call_duration = duration;
}

double System::get_max_duration() {
return this->max_call_duration;
}

void System::set_max_duration(double duration) {
this->max_call_duration = duration;
}

System::System(int sys_num) {
this->sys_num = sys_num;
sys_id = 0;
Expand Down
3 changes: 3 additions & 0 deletions trunk-recorder/systems/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class System {
int max_dev;
double filter_width;
double min_call_duration;
double max_call_duration;

bool qpsk_mod;
double squelch_db;
Expand Down Expand Up @@ -99,6 +100,8 @@ class System {
void set_bcfy_system_id(int bcfy_system_id);
double get_min_duration();
void set_min_duration(double duration);
double get_max_duration();
void set_max_duration(double duration);
bool get_audio_archive();
void set_audio_archive(bool);
bool get_record_unknown();
Expand Down

0 comments on commit dcbbc4e

Please sign in to comment.