@@ -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 << " \t current: " << 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 << " \t current: " << 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 << " \t current: " << 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
253259void 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;
0 commit comments