Skip to content

Commit 6b4971e

Browse files
authored
Dev/grant test (#1097)
* Update transmission_sink.cc * cached src id * Update transmission_sink.cc * Update transmission_sink.cc * Update transmission_sink.cc * less chatty * Update transmission_sink.cc
1 parent af942e1 commit 6b4971e

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

trunk-recorder/gr_blocks/transmission_sink.cc

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ bool transmission_sink::start_recording(Call *call) {
168168

169169

170170
curr_src_id = d_current_call->get_current_source_id();
171+
cached_src_id = -1;
171172
d_sample_count = 0;
172173

173174
// when a wav_sink first gets associated with a call, set its lifecycle to idle;
@@ -237,25 +238,32 @@ void transmission_sink::set_source(long src) {
237238
BOOST_LOG_TRIVIAL(info) << loghdr << "Unit ID set via Control Channel, ext: " << src << "\tcurrent: " << curr_src_id << "\t samples: " << d_sample_count;
238239

239240
curr_src_id = src;
240-
}
241-
else if (d_conventional && (src != curr_src_id)) {
242-
if ((state == RECORDING) && (d_sample_count > 0)) {
243-
gr::thread::scoped_lock guard(d_mutex);
244-
BOOST_LOG_TRIVIAL(error) << loghdr << "Unit ID externally set, ext: " << src << "\tcurrent: " << curr_src_id << "\t samples: " << d_sample_count;
245-
end_transmission();
246-
state = IDLE;
247-
curr_src_id = src;
248-
}
241+
} else if (src != curr_src_id) {
242+
if (d_conventional) {
243+
if ((state == RECORDING) && (d_sample_count > 0)) {
244+
gr::thread::scoped_lock guard(d_mutex);
245+
BOOST_LOG_TRIVIAL(error) << loghdr << "Unit ID externally set, ext: " << src << "\tcurrent: " << curr_src_id << "\t samples: " << d_sample_count;
246+
end_transmission();
247+
state = IDLE;
248+
curr_src_id = src;
249+
}
249250

251+
} else {
252+
// this is a trunked system, where the existing source ID does not match the ID that just came in as a GRANT message
253+
BOOST_LOG_TRIVIAL(error) << loghdr << "Unit ID externally set from GRANT: " << src << "\t caching, doesn't match current: " << curr_src_id << "\t samples: " << d_sample_count << "\t state: " << format_state(state);
254+
cached_src_id = src;
255+
}
250256
}
251257
}
252258

253259
void transmission_sink::end_transmission() {
260+
std::string loghdr = log_header(d_current_call_short_name,d_current_call_num,d_current_call_talkgroup_display,d_current_call_freq);
261+
254262
if (d_sample_count > 0) {
255263
if (d_fp) {
256264
close_wav(false);
257265
} else {
258-
BOOST_LOG_TRIVIAL(error) << "Ending transmission, sample_count is greater than 0 but d_fp is null" << std::endl;
266+
BOOST_LOG_TRIVIAL(error) << loghdr << "Ending transmission, sample_count is greater than 0 but d_fp is null" << std::endl;
259267
}
260268

261269
const std::int64_t dur_ms = (d_nchans > 0)
@@ -269,7 +277,20 @@ void transmission_sink::end_transmission() {
269277

270278
// Build Transmission using the canonical fields
271279
Transmission transmission;
272-
transmission.source = curr_src_id; // Source ID for the Call
280+
281+
// if we don't have a curr_src_id and we cached one in the previous transmission, use it
282+
if ((curr_src_id == -1) && (cached_src_id != -1 )) {
283+
transmission.source = cached_src_id;
284+
BOOST_LOG_TRIVIAL(info) << loghdr << "Using cached ID: " << cached_src_id << " for Transmission: " << sizeof(transmission_list);
285+
cached_src_id = -1;
286+
287+
} else {
288+
transmission.source = curr_src_id; // Source ID for the Call
289+
}
290+
// if the Src ID was cached in the previous transmission, but we got it on the Voice channel, the reset the cache.
291+
if ((cached_src_id != -1) && (curr_src_id == cached_src_id)) {
292+
cached_src_id = -1;
293+
}
273294
transmission.start_time = d_start_time; // Start time of the Call
274295
transmission.stop_time = d_stop_time; // when the Call eneded
275296
transmission.start_time_ms = d_start_time_ms;

trunk-recorder/gr_blocks/transmission_sink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class BLOCKS_API transmission_sink : virtual public sync_block {
5959
long d_spike_count;
6060
long d_error_count;
6161
long curr_src_id;
62+
long cached_src_id;
6263
unsigned int d_current_color_code;
6364
std::string current_filename;
6465
Call *d_current_call;

0 commit comments

Comments
 (0)