Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Achim Morschhauser
GeomagLogger
Commits
7017370b
Commit
7017370b
authored
Mar 31, 2021
by
Thomas Edwards
Browse files
Cleaned up a lot of old commented code
parent
85121759
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Filter_Obs.cpp
View file @
7017370b
...
...
@@ -213,8 +213,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
data_obs_vector
*
filter_data_temp
=
new
data_obs_vector
(
5
);
// Time of current and previous samples
long
last_msec
=
0
;
long
this_msec
=
0
;
struct
timespec
last_timespec
;
struct
timespec
this_timespec
;
struct
timespec
last_timeblock_edge
;
...
...
@@ -222,12 +220,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// Timestamp as string for logging
std
::
string
timestamp
;
struct
time_block
{
struct
timespec
start
;
struct
timespec
end
;
int
num_records
;
};
// =====================================================================
// Filter1 downsamples to 16 Hz with a cut-off frequency of 5 Hz
// =====================================================================
...
...
@@ -239,12 +231,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// Time window between two blocks
long
filter1_delta_t_msec
=
(
1.0
/
filter1_freq
)
*
1e9
;
// Contains the number of points per block of data
std
::
vector
<
int
>
filter1_blocks_info
;
// contains time block information
std
::
vector
<
time_block
>
time_block_info
;
time_block
this_timeblock
;
if
(
freq_in
==
128
)
{
...
...
@@ -325,8 +311,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
tofilter1
.
push_back
(
new
data_obs_vector
(
data
));
// record the time
data
->
get_time
(
&
this_timespec
);
this_timeblock
.
start
=
this_timespec
;
time_block_info
.
push_back
(
this_timeblock
);
last_timeblock_edge
=
this_timespec
;
// Initialize counters
...
...
@@ -349,9 +333,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
tofilter1
.
back
()
->
get_time
(
&
last_timespec
);
data
->
get_time
(
&
this_timespec
);
last_msec
=
last_timespec
.
tv_nsec
;
this_msec
=
this_timespec
.
tv_nsec
;
//counter++;
data
->
string
(
&
datastr
,
5
);
...
...
@@ -368,51 +349,12 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// One data point is produced from filter1 for each block of
// data, corresponding to its output filter frequency
// Check here if we hit the next block
if
(
(
this_
m
sec
%
filter1_delta_t_msec
)
<
(
last_
m
sec
%
filter1_delta_t_msec
)
)
{
if
(
(
this_
timespec
.
tv_n
sec
%
filter1_delta_t_msec
)
<
(
last_
timespec
.
tv_n
sec
%
filter1_delta_t_msec
)
)
{
// Keep track of the time blocks, end the last one and start the next
this_timeblock_edge
=
this_timespec
;
// time_block_info.back().end = this_timespec;
// time_block_info.back().num_records = filter1_block_numdata;
// filter1_block_numdata = 0;
// this_timeblock.start = this_timespec;
// BEFORE adding new time block info, CHECK if the blocks work as expected
// long long elapsed_time_last_block = (((this_timeblock.start.tv_sec - time_block_info.back().start.tv_sec) * 1e9) + (this_timeblock.start.tv_nsec - time_block_info.back().start.tv_nsec));
long
long
elapsed_time_last_block
=
(((
this_timeblock_edge
.
tv_sec
-
last_timeblock_edge
.
tv_sec
)
*
1e9
)
+
(
this_timeblock_edge
.
tv_nsec
-
last_timeblock_edge
.
tv_nsec
));
// time_block_info.push_back(this_timeblock);
// Timeblock debug printing
// save the first time in the block information
// // Print out the entire time block info vec
// struct timespec first_time_in_block = time_block_info.front().start;
// for (int ix = 0; ix < time_block_info.size(); ix++) {
// // calculate the difference between first and last
// long long time_diff = (((time_block_info[ix].start.tv_sec - first_time_in_block.tv_sec) * 1e9) + (time_block_info[ix].start.tv_nsec - first_time_in_block.tv_nsec));
// std::cerr << " | " << time_diff;
// }
// std::cerr << std::endl;
// // show the difference between the first and last block
// std::cerr << "Elapsed time:";
// long long time_diff = (((time_block_info.back().start.tv_sec - time_block_info.front().start.tv_sec) * 1e9) + (time_block_info.back().start.tv_nsec - time_block_info.front().start.tv_nsec));
// std::cerr << " | " << time_diff << std::endl;
// Cross time block edge
// ---- YES: Given the elapsed time, can we run some number of filters to reduce the amount of data down to what we expect?
// ---- ---- YES (8*(blocks) +/- 1): Run those filters!
// ---- ---- NO: Check the data.
// ---- ---- ---- TOO MUCH DATA: PANIC!
// ---- ---- ---- NOT ENOUGH DATA: Wait for more
// ---- NO: Keep getting data
// --------------------------------------------------------------
// Degbugging monitoring info
// --------------------------------------------------------------
...
...
@@ -420,14 +362,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// timestamp=tofilter1.back()->get_time("%Y-%m-%d %H:%M:%S",true);
// std::cerr << "Latest timestamp: " << timestamp << " | ";
// std::cerr << "No. Rec: " << tofilter1.size() << " | ";
// std::cerr << "Elapsed time: ";
// long long check_time_diff = (((time_block_info.back().start.tv_sec - time_block_info.front().start.tv_sec) * 1e9) + (time_block_info.back().start.tv_nsec - time_block_info.front().start.tv_nsec));
// std::cerr << check_time_diff << " | ";
// // Assume 128 Hz being downsampled to 16 Hz. That means 1 block ever 1e9/16 ns
// int num_blocks = check_time_diff/(1e9/16);
// std::cerr << "Expected blocks: " << num_blocks << " | ";
// Assume we can run a filter every 16 blocks
// std::cerr << "Filters: " << num_blocks/16 << std::endl;
total_blocks
+=
round
(
elapsed_time_last_block
/
((
1.
/
16
)
*
1e9
));
// std::cerr << "Filters: " << total_blocks/16. << std::endl;
...
...
@@ -448,7 +382,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
bool
run_the_filter
=
((
tofilter1
.
size
()
<=
(
time_block_check
+
1
))
&&
(
tofilter1
.
size
()
>=
(
time_block_check
-
1
)))
&&
(
check_filters
>=
1
);
// std::cerr << "Data in que: " << tofilter1.size() << " | blocks*8: " << time_block_check << " | Run the filter?: " << run_the_filter << std::endl;
while
(
run_the_filter
)
{
// std::cerr << "Run the filter! " << std::endl;
// Try to just run as normal
try
{
filter1_win
=
&
filter1_wins
.
at
(
tofilter1
.
size
());
...
...
@@ -467,11 +400,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
std
::
cerr
<<
"Latest timestamp: "
<<
timestamp
<<
" | "
;
std
::
cerr
<<
"OOR err, Filter Jitter: "
<<
filter_jitter
<<
" | "
;
// // DEBUG: Test the vector copy constructor
// std::vector <data_obs*> test_vec;
// test_vec = std::vector<data_obs*>(tofilter1.begin(), tofilter1.begin() + 128); // Filter1 queue
// std::cerr << "Test vec size: " << test_vec.size() << std::endl;
// Filter data
filter1_win
=
&
filter1_wins
.
at
(
128
+
filter_jitter
);
filter1_slice
=
std
::
vector
<
data_obs
*>
(
tofilter1
.
begin
(),
tofilter1
.
begin
()
+
128
+
filter_jitter
);
...
...
@@ -482,10 +410,7 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// Append this data to the queue for filter 2
tofilter2
.
push_back
(
new
data_obs_vector
(
filter_data_temp
));
// Drop the oldest data points, as determined by the oldest block
// for (int ix = 0; ix < filter1_blocks_info.front(); ix++) {
// delete(tofilter1[ix]);
// }
// Drop the oldest data points, as determined by the oldest block
for
(
int
ix
=
0
;
ix
<
points_to_drop
;
ix
++
)
{
delete
(
tofilter1
[
ix
]);
}
...
...
@@ -497,13 +422,8 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// 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
)))
&&
(
check_filters
>=
1
);
// // Drop the oldest block information
// time_block_info.erase(time_block_info.begin());
// filter1_blocks_info.erase(filter1_blocks_info.begin());
// Wait until filter2 queue is filled
if
(
tofilter2
.
size
()
==
filter2_block_len
)
{
// Wait for downsampling and apply filter2
if
(
filter2_count
==
filter2_block_step
)
{
//data->filter_fir_sym(&tofilter2,&filter2_win);
...
...
@@ -514,11 +434,9 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
}
else
{
filter2_count
++
;
}
// Delete oldest data from filter2
delete
(
tofilter2
[
0
]);
tofilter2
.
erase
(
tofilter2
.
begin
());
}
}
}
else
{
...
...
@@ -537,7 +455,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// Otherwise keep getting data
// --------------------------------------------------------------
// rotate the time block edge now that we've finished handling the block
last_timeblock_edge
=
this_timeblock_edge
;
}
...
...
@@ -546,113 +463,6 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
filter1_block_numdata
++
;
tofilter1
.
push_back
(
new
data_obs_vector
(
data
));
// //fprintf(stderr, "number of elements in filter1: %lu\n", tofilter1.size());
// //fprintf(stderr, "number of blocks in filter1: %lu\n", filter1_block_count);
// // Save number of data in this block
// filter1_blocks_info.push_back(filter1_block_numdata);
// filter1_block_numdata = 0;
// // Wait until filter1 queue is filled
// if (filter1_block_count == filter1_block_len) {
// try {
// filter1_win = &filter1_wins.at(tofilter1.size());
// // Filter data
// filter_data_temp->filter_fir_sym(&tofilter1, filter1_win);
// } catch (const std::out_of_range &oor) {
// // if we get here, it means we don't have enough data to filter. A block probably got shortened.
// // In this case, set data value to NaN
// filter_data_temp->set_values_MD();
// std::cerr << "Set values to MD!"
// << std::endl;
// filter_data_temp->median_time(&tofilter1);
// timestamp=filter_data_temp->get_time
// ("%Y-%m-%d %H:%M:%S",true);
// std::cerr << "[" << timestamp << "]: "
// << "no filter1 - "
// << tofilter1.size()
// << std::endl;
// }
// //std::string tmp_str;
// //filter_data_temp->string(&tmp_str,5);
// //std::cerr << "DEBUG ADD FILTER2: " << tmp_str << std::endl;
// // Append this data to the queue for filter 2
// tofilter2.push_back(new data_obs_vector(filter_data_temp));
// /*
// filter_data_temp->string(&datastr,5);
// std::cerr << "FILTER 1 APPLIED: " << std::endl;
// std::cerr << filter_data_temp->get_sec() << "."
// << filter_data_temp->get_msec() << " "
// << datastr << " "
// << counter << " "
// << filter2_count << std::endl;
// */
// // Drop the oldest data points, as determined by the oldest block
// for (int ix = 0; ix < filter1_blocks_info.front(); ix++) {
// delete(tofilter1[ix]);
// }
// tofilter1.erase(tofilter1.begin(), tofilter1.begin() + filter1_blocks_info.front());
// // Drop the oldest block information
// time_block_info.erase(time_block_info.begin());
// filter1_blocks_info.erase(filter1_blocks_info.begin());
// // Wait until filter2 queue is filled
// if (tofilter2.size() == filter2_block_len) {
// // Wait for downsampling and apply filter2
// if (filter2_count == filter2_block_step) {
// //data->filter_fir_sym(&tofilter2,&filter2_win);
// filter_data_temp->filter_fir_sym(&tofilter2, &filter2_win);
// /*
// filter_data_temp->string(&datastr,5);
// std::cerr << "FILTER 2 APPLIED: " << std::endl;
// std::cerr << filter_data_temp->get_sec()
// << "." << filter_data_temp->get_msec() << " "
// << datastr << " "
// << " " << counter
// << " " << filter2_block_step
// << std::endl;
// */
// //counter = 0;
// buffer_out->put(filter_data_temp);
// filter2_count = 1;
// } else {
// filter2_count++;
// }
// // Delete oldest data from filter2
// delete(tofilter2[0]);
// tofilter2.erase(tofilter2.begin());
// }
// } else { // No filter was applied, blocks of filter1 are being filled
// // Increase number of blocks counter
// filter1_block_count++;
// }
// }
// filter1_block_numdata++;
// tofilter1.push_back(new data_obs_vector(data));
}
return
(
0
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment