Skip to content

Commit b303615

Browse files
committed
Cleaned up some files
1 parent 44787eb commit b303615

File tree

3 files changed

+157
-220
lines changed

3 files changed

+157
-220
lines changed

trunk-recorder/gr_blocks/transmission_sink.cc

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
#include "transmission_sink.h"
2525
#include "../../trunk-recorder/call.h"
26-
#include <boost/math/special_functions/round.hpp>
2726
#include <boost/filesystem.hpp>
27+
#include <boost/math/special_functions/round.hpp>
2828
#include <climits>
2929
#include <cmath>
3030
#include <cstring>
@@ -62,11 +62,11 @@ transmission_sink::transmission_sink(int n_channels, unsigned int sample_rate, i
6262
: sync_block("transmission_sink",
6363
io_signature::make(1, n_channels, sizeof(int16_t)),
6464
io_signature::make(0, 0, 0)),
65-
d_sample_rate(sample_rate),
65+
d_sample_rate(sample_rate),
6666
d_nchans(n_channels),
67-
d_current_call(NULL),
67+
d_current_call(NULL),
6868
d_fp(0) {
69-
69+
7070
if ((bits_per_sample != 8) && (bits_per_sample != 16)) {
7171
throw std::runtime_error("Invalid bits per sample (supports 8 and 16)");
7272
}
@@ -77,15 +77,12 @@ transmission_sink::transmission_sink(int n_channels, unsigned int sample_rate, i
7777
state = AVAILABLE;
7878
}
7979

80-
81-
// static int rec_counter=0;
8280
void transmission_sink::create_filename() {
8381
time_t work_start_time = d_start_time;
8482
std::stringstream temp_path_stream;
8583
tm *ltm = localtime(&work_start_time);
8684
// Found some good advice on Streams and Strings here: https://blog.sensecodons.com/2013/04/dont-let-stdstringstreamstrcstr-happen.html
87-
//temp_path_stream << d_current_call_temp_dir << "/" << d_current_call_short_name << "/" << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday;
88-
85+
8986
temp_path_stream << d_current_call_temp_dir << "/" << d_current_call_short_name;
9087
std::string temp_path_string = temp_path_stream.str();
9188
boost::filesystem::create_directories(temp_path_string);
@@ -120,7 +117,6 @@ bool transmission_sink::start_recording(Call *call) {
120117
}
121118
d_current_call = call;
122119
d_current_call_num = call->get_call_num();
123-
d_current_call_recorder_num = 0; // call->get_recorder()->get_num();
124120
d_current_call_freq = call->get_freq();
125121
d_current_call_talkgroup = call->get_talkgroup();
126122
d_current_call_talkgroup_display = call->get_talkgroup_display();
@@ -134,8 +130,7 @@ bool transmission_sink::start_recording(Call *call) {
134130
d_prior_transmission_length = 0;
135131
d_error_count = 0;
136132
d_spike_count = 0;
137-
d_last_write_time = std::chrono::steady_clock::now(); // we want to make sure the call doesn't get cleaned up before data starts coming in.
138-
133+
d_last_write_time = std::chrono::steady_clock::now(); // we want to make sure the call doesn't get cleaned up before data starts coming in.
139134

140135
this->clear_transmission_list();
141136
d_conventional = call->is_conventional();
@@ -182,9 +177,9 @@ bool transmission_sink::open_internal(const char *filename) {
182177
BOOST_LOG_TRIVIAL(error) << "wav open failed" << std::endl;
183178
return false;
184179
}
185-
if(std::setvbuf(d_fp, nullptr, _IOFBF, 1000000) != 0) {
186-
BOOST_LOG_TRIVIAL(error) << "setvbuf failed"; // POSIX version sets errno
187-
}
180+
if (std::setvbuf(d_fp, nullptr, _IOFBF, 1000000) != 0) {
181+
BOOST_LOG_TRIVIAL(error) << "setvbuf failed"; // POSIX version sets errno
182+
}
188183
d_sample_count = 0;
189184

190185
if (!wavheader_write(d_fp, d_sample_rate, d_nchans, d_bytes_per_sample)) {
@@ -209,7 +204,7 @@ bool transmission_sink::open_internal(const char *filename) {
209204

210205
void transmission_sink::set_source(long src) {
211206
if (curr_src_id == -1) {
212-
207+
213208
BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tUnit ID set via Control Channel, ext: " << src << "\tcurrent: " << curr_src_id << "\t samples: " << d_sample_count;
214209

215210
curr_src_id = src;
@@ -310,10 +305,9 @@ int transmission_sink::work(int noutput_items, gr_vector_const_void_star &input_
310305

311306
// It is possible the P25 Frame Assembler passes a TDU after the call has timed out.
312307
// In this case, the termination tag will be transferred on a blank sample and can safely be ignored.
313-
if(noutput_items == 1){
308+
if (noutput_items == 1) {
314309
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tDropping " << noutput_items << " samples - current_call is null\t Rec State: " << format_state(this->state) << "\tSince close: " << its_been;
315-
}
316-
else{
310+
} else {
317311
BOOST_LOG_TRIVIAL(error) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tDropping " << noutput_items << " samples - current_call is null\t Rec State: " << format_state(this->state) << "\tSince close: " << its_been;
318312
}
319313

@@ -350,19 +344,19 @@ int transmission_sink::work(int noutput_items, gr_vector_const_void_star &input_
350344
long grp_id = pmt::to_long(tags[i].value);
351345

352346
if ((state == RECORDING) || (state == IDLE)) {
353-
if(d_current_call_talkgroup_encoded != grp_id) {
347+
if (d_current_call_talkgroup_encoded != grp_id) {
354348
if (!d_conventional) {
355349
BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tGROUP MISMATCH - Recorder TG: " << d_current_call_talkgroup_encoded << " Received TG: " << grp_id << " Recorder state: " << format_state(state) << " incoming: " << noutput_items;
356-
if (d_sample_count > 0) {
357-
BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tEnding Transmission and IGNORING Rest - count: " << d_sample_count;
358-
end_transmission();
359-
}
350+
if (d_sample_count > 0) {
351+
BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tEnding Transmission and IGNORING Rest - count: " << d_sample_count;
352+
end_transmission();
353+
}
360354
state = IGNORE;
361355
} else {
362356
BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tGroup Mismatch - Recorder Received TG: " << grp_id << " Recorder state: " << format_state(state) << " incoming samples: " << noutput_items;
363357
}
364358
}
365-
}
359+
}
366360
}
367361
if (pmt::eq(src_id_key, tags[i].key)) {
368362
long src_id = pmt::to_long(tags[i].value);
@@ -471,14 +465,14 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu
471465
return noutput_items;
472466
}
473467

474-
if (state == IGNORE ) {
475-
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tResetting state from IGNORE to IDLE: " << noutput_items;
476-
state = IDLE;
468+
if (state == IGNORE) {
469+
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tResetting state from IGNORE to IDLE: " << noutput_items;
470+
state = IDLE;
477471
}
478472
if (d_sample_count > 0) {
479473
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tTERMINATING! - count: " << d_sample_count;
480474
end_transmission();
481-
475+
482476
if (noutput_items > 1) {
483477
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tTERM - there were some items to output: " << noutput_items;
484478
}
@@ -489,43 +483,41 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu
489483
return noutput_items;
490484
}
491485

492-
if (state == IGNORE ) {
486+
if (state == IGNORE) {
493487
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tIGNORE missing count: " << noutput_items;
494-
return noutput_items;
488+
return noutput_items;
495489
}
496490

497491
if (state == IDLE) {
498-
//BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tIDLE but haven't seen Group ID yet, missing count: " << noutput_items;
499-
//return noutput_items;
500-
if (d_fp) {
501-
// if we are already recording a file for this call, close it before starting a new one.
502-
BOOST_LOG_TRIVIAL(info) << "WAV - Weird! we have an existing FP, but STATE was IDLE: " << current_filename << std::endl;
492+
// BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tIDLE but haven't seen Group ID yet, missing count: " << noutput_items;
493+
// return noutput_items;
494+
if (d_fp) {
495+
// if we are already recording a file for this call, close it before starting a new one.
496+
BOOST_LOG_TRIVIAL(info) << "WAV - Weird! we have an existing FP, but STATE was IDLE: " << current_filename << std::endl;
503497

504-
close_wav(false);
505-
}
498+
close_wav(false);
499+
}
506500

507-
time_t current_time = time(NULL);
508-
if (current_time == d_start_time) {
509-
d_start_time = current_time + 1;
510-
} else {
511-
d_start_time = current_time;
512-
}
501+
time_t current_time = time(NULL);
502+
if (current_time == d_start_time) {
503+
d_start_time = current_time + 1;
504+
} else {
505+
d_start_time = current_time;
506+
}
513507

514-
// create a new filename, based on the current time and source.
515-
create_filename();
516-
if (!open_internal(current_filename)) {
517-
BOOST_LOG_TRIVIAL(error) << "can't open file";
518-
return noutput_items;
519-
}
508+
// create a new filename, based on the current time and source.
509+
create_filename();
510+
if (!open_internal(current_filename)) {
511+
BOOST_LOG_TRIVIAL(error) << "can't open file";
512+
return noutput_items;
513+
}
520514

521-
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tStarting new Transmission \tSrc ID: " << curr_src_id;
515+
BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tStarting new Transmission \tSrc ID: " << curr_src_id;
522516

523-
// curr_src_id = d_current_call->get_current_source_id();
524-
state = RECORDING;
525-
517+
// curr_src_id = d_current_call->get_current_source_id();
518+
state = RECORDING;
526519
}
527520

528-
529521
if (!d_fp) // drop output on the floor
530522
{
531523
BOOST_LOG_TRIVIAL(error) << "Wav - Dropping items, no fp or Current Call: " << noutput_items << " Filename: " << current_filename << " Current sample count: " << d_sample_count << std::endl;
@@ -551,8 +543,8 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu
551543
}
552544
}
553545

554-
d_stop_time = time(NULL);
555-
d_last_write_time = std::chrono::steady_clock::now();
546+
d_stop_time = time(NULL);
547+
d_last_write_time = std::chrono::steady_clock::now();
556548

557549
if (nwritten < noutput_items) {
558550
BOOST_LOG_TRIVIAL(error) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tFailed to Write! Wrote: " << nwritten << " of " << noutput_items;
@@ -590,13 +582,7 @@ double transmission_sink::total_length_in_seconds() {
590582
}
591583

592584
double transmission_sink::length_in_seconds() {
593-
// std::cout << "Filename: "<< current_filename << "Sample #: " <<
594-
// d_sample_count << " rate: " << d_sample_rate << " bytes: " <<
595-
// d_bytes_per_sample << "\n";
596585
return (double)d_sample_count / (double)d_sample_rate;
597-
598-
// return (double) ( d_sample_count * d_bytes_per_sample_new * 8) / (double)
599-
// d_sample_rate;
600586
}
601587

602588
void transmission_sink::do_update() {}

trunk-recorder/gr_blocks/transmission_sink.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ class BLOCKS_API transmission_sink : virtual public sync_block {
5252
bool d_termination_flag;
5353
time_t d_start_time;
5454
time_t d_stop_time;
55-
std::chrono::time_point<std::chrono::steady_clock> d_last_write_time;
55+
std::chrono::time_point<std::chrono::steady_clock> d_last_write_time;
5656
long d_spike_count;
5757
long d_error_count;
5858
long curr_src_id;
5959
long next_src_id;
6060
char current_filename[255];
6161
Call *d_current_call;
6262
long d_current_call_num;
63-
long d_current_call_recorder_num;
6463
std::string d_current_call_short_name;
6564
std::string d_current_call_temp_dir;
6665
double d_current_call_freq;
@@ -69,7 +68,6 @@ class BLOCKS_API transmission_sink : virtual public sync_block {
6968
long d_current_call_talkgroup_encoded;
7069
std::string d_current_call_talkgroup_display;
7170

72-
7371
protected:
7472
unsigned d_sample_count;
7573
int d_bytes_per_sample;
@@ -144,8 +142,7 @@ class BLOCKS_API transmission_sink : virtual public sync_block {
144142
State get_state();
145143
time_t get_start_time();
146144
time_t get_stop_time();
147-
std::chrono::time_point<std::chrono::steady_clock> get_last_write_time();
148-
145+
std::chrono::time_point<std::chrono::steady_clock> get_last_write_time();
149146
};
150147

151148
} /* namespace blocks */

0 commit comments

Comments
 (0)