Commit c9f00a94 authored by Thomas Edwards's avatar Thomas Edwards
Browse files

Ready for push, debug info on

parent ec827d64
......@@ -208,7 +208,7 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
std::vector<double>* filter1_win;
data_obs_vector* data = // Data to hold the
new data_obs_vector(5); // filtered value
new data_obs_vector(5); // filtered value
// Placeholder when filtering
data_obs_vector* filter_data_temp = new data_obs_vector(5);
......@@ -323,7 +323,7 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
int filter2_count = filter2_block_step; // Apply straight ahead first time
float total_blocks = 0;
//
// =================================================
// Continuously run concatenated filters one and two.
// =================================================
//
......@@ -364,13 +364,15 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// --------------------------------------------------------------
std::cerr << "-----------------------------------" << std::endl;
timestamp=tofilter1.back()->get_time("%Y-%m-%d %H:%M:%S",true);
// Determine number of blocks
float num_blocks = (elapsed_time_last_block/(1e9/16.));
total_blocks += num_blocks;
// Debug printing
std::cerr << "Total blocks: " << total_blocks << std::endl;
std::cerr << "Data in que: " << tofilter1.size() << std::endl;
std::cerr << "Blocks*8: " << round(8*(total_blocks)) << std::endl;
// --------------------------------------------------------------
// Given the elapsed time, can we run some number of filters to
......@@ -388,55 +390,47 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
time_block_check = round(8*(total_blocks));
bool run_the_filter = ((tofilter1.size() <= (time_block_check + 1)) && (tofilter1.size() >= (time_block_check - 1))) && (int(total_blocks/16) >= 1) && (tofilter1.size() >= 129);
while (run_the_filter) {
// Try to just run as normal
// try {
// if (tofilter1.size() != 129) {
// throw std::out_of_range("Filter not perfect");
// }
// filter1_win = &filter1_wins.at(129);
// // Filter data
// filter_data_temp->filter_fir_sym(&tofilter1, filter1_win);
// points_to_drop = 8+filter1_win->size()-128;
// } catch (const std::out_of_range &oor) {
// Use the time_block_check information to assume if we are over or under
// this is just the +/- part, so we can expand or reduce the filter to match
int filter_jitter = 0;
if (tofilter1.size() % 8 != 0 ){
slip_count++;
} else {
slip_count = 0;
}
// Use the time_block_check information to assume if we are over or under
// this is just the +/- part, so we can expand or reduce the filter to match
int filter_jitter = 0;
// Checking the filter size for perfectly divisible by 8
if (tofilter1.size() % 8 != 0 ){
slip_count++;
} else {
slip_count = 0;
}
if (slip_count > slip_limit) {
std::cerr << "[!!!] Slipping data to fit time!" << std::endl;
slip_count = 0;
filter_jitter = tofilter1.size() % 8;
if (filter_jitter > 4) {
filter_jitter -= 8;
}
// Check slip count to see if we need to slip
if (slip_count > slip_limit) {
std::cerr << "[!!!] Slipping data to fit time!" << std::endl;
slip_count = 0;
filter_jitter = tofilter1.size() % 8;
// make the remainder a +/- 4 instead of 0 to 8
if (filter_jitter > 4) {
filter_jitter -= 8;
}
// Debug printing
// std::cerr << "-----------------------------------" << std::endl;
std::cerr << "Latest timestamp: " << timestamp << " | ";
std::cerr << "No. Rec: " << tofilter1.size() << " | ";
std::cerr << "Elapsed time: ";
std::cerr << elapsed_time_last_block << " | ";
std::cerr << "Expected blocks: " << num_blocks << " | ";
std::cerr << "Slip count: " << slip_count << " | ";
std::cerr << "Filters: " << total_blocks/16. << std::endl;
std::cerr << "Data in que: " << tofilter1.size() << " | blocks*8: " << time_block_check << " | Run the filter?: " << run_the_filter << std::endl;
std::cerr << "OOR err, Filter Jitter: " << filter_jitter << " | ";
// Filter data
filter1_win = &filter1_wins.at(129+filter_jitter);
filter1_slice = std::vector<data_obs*>(tofilter1.begin(), tofilter1.begin()+129+filter_jitter);
filter_data_temp->filter_fir_sym(&filter1_slice, filter1_win);
points_to_drop = 8+filter_jitter;
// Debug printing
std::cerr << "points_to_drop: " << points_to_drop << std::endl;
// }
}
// Debug printing
std::cerr << "Latest timestamp: " << timestamp << " | ";
std::cerr << "No. Rec: " << tofilter1.size() << " | ";
std::cerr << "Elapsed time: ";
std::cerr << elapsed_time_last_block << " | ";
std::cerr << "Expected blocks: " << num_blocks << " | ";
std::cerr << "Slip count: " << slip_count << " | ";
std::cerr << "Filters: " << total_blocks/16. << std::endl;
std::cerr << "Data in que: " << tofilter1.size() << " | blocks*8: " << time_block_check << " | Run the filter?: " << run_the_filter << std::endl;
std::cerr << "OOR err, Filter Jitter: " << filter_jitter << " | ";
// Filter data
filter1_win = &filter1_wins.at(129+filter_jitter);
filter1_slice = std::vector<data_obs*>(tofilter1.begin(), tofilter1.begin()+129+filter_jitter);
filter_data_temp->filter_fir_sym(&filter1_slice, filter1_win);
points_to_drop = 8+filter_jitter;
// Debug printing
std::cerr << "points_to_drop: " << points_to_drop << std::endl;
// Append this data to the queue for filter 2
tofilter2.push_back(new data_obs_vector(filter_data_temp));
......@@ -448,14 +442,13 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
delete(tofilter1[ix]);
}
tofilter1.erase(tofilter1.begin(), tofilter1.begin() + points_to_drop);
// remove a time block and update our estimate
// total_blocks = round(total_blocks);
// total_blocks--;
// Debug printing
std::cerr << "Total blocks (post filter): " << total_blocks << std::endl;
// remove a time block and update our estimate
time_block_check = round(8*(total_blocks));
// std::cerr << "Filter blocks and data check (after filter): " << tofilter1.size() << " " << time_block_check << std::endl;
run_the_filter = ((tofilter1.size() <= (time_block_check + 1)) && (tofilter1.size() >= (time_block_check - 1))) && (int(total_blocks/16) >= 1) && (tofilter1.size() >= 129);
// run_the_filter = (tofilter1.size() == (time_block_check)) && (int(total_blocks/16) >= 1) && (tofilter1.size() >= 129);
// Wait until filter2 queue is filled
if (tofilter2.size() == filter2_block_len) {
......@@ -482,7 +475,9 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// Check the data: Do we have too much or too little?
// --------------------------------------------------------------
if (tofilter1.size() > max_filter1) {
std::cerr << "[!!!] Too much data!" << std::endl;
std::cerr << "[!!!] Too much data!" << std::endl;
// [TODO] Reset everthing, try to start again
} else if (tofilter1.size() < min_filter1) {
std::cerr << "[!!!] Not enough data!" << std::endl;
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment