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
49481393
Commit
49481393
authored
Apr 07, 2021
by
Thomas Edwards
Browse files
Added some rounding on the total block number to constrain overflows
parent
d36a0443
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Filter_Obs.cpp
View file @
49481393
...
...
@@ -220,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
// =====================================================================
...
...
@@ -237,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
)
{
...
...
@@ -323,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
...
...
@@ -384,31 +370,26 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
float
num_blocks
=
(
elapsed_time_last_block
/
(
1e9
/
16.
));
// std::cerr << "Expected blocks: " << num_blocks << " | ";
// Assume we can run a filter every 16 blocks
// total_blocks += round(elapsed_time_last_block/((1./16)*1e9));
total_blocks
+=
num_blocks
;
// std::cerr << "Filters: " << total_blocks/16. << std::endl;
std
::
cerr
<<
"Total blocks: "
<<
total_blocks
<<
std
::
endl
;
// --------------------------------------------------------------
// Given the elapsed time, can we run some number of filters to
// reduce the amount of data down to what we expect?
// --------------------------------------------------------------
// int check_blocks = check_time_diff/(1e9/16);
int
check_filters
=
total_blocks
/
16
;
// std::cerr << "Check Filters: " << check_filters << std::endl;
// If we find more than one block elapsed, then we've probably skipped some data. Let's hold off and get some extra data first.
if
(
round
(
num_blocks
)
>
1
)
{
std
::
cerr
<<
"[!!!] Time skip detected! Waiting for more data."
<<
std
::
endl
;
check_filters
=
0
;
}
// See if we can run at least one filter
if
(
check_filters
>=
1
)
{
else
if
(
int
(
total_blocks
/
16
)
>=
1
)
{
// save information on how many points we need to drop later
int
points_to_drop
=
0
;
// Check if we have (8*(blocks) +/- 1) data in the filter que
time_block_check
=
round
(
8
*
(
total_blocks
));
bool
run_the_filter
=
((
tofilter1
.
size
()
<=
(
time_block_check
+
1
))
&&
(
tofilter1
.
size
()
>=
(
time_block_check
-
1
)))
&&
(
check_filters
>=
1
);
bool
run_the_filter
=
((
tofilter1
.
size
()
<=
(
time_block_check
+
1
))
&&
(
tofilter1
.
size
()
>=
(
time_block_check
-
1
)))
&&
(
int
(
total_blocks
/
16
)
>=
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
)
{
// Try to just run as normal
...
...
@@ -421,27 +402,26 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// 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
=
tofilter1
.
size
()
-
time_block_check
;
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
<<
" | "
;
// Assume we can run a filter every 16 blocks
// total_blocks += round(elapsed_time_last_block/((1./16)*1e9));
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
<<
" | "
;
// 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 << "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
(
128
+
filter_jitter
);
filter1_slice
=
std
::
vector
<
data_obs
*>
(
tofilter1
.
begin
(),
tofilter1
.
begin
()
+
128
+
filter_jitter
);
filter_data_temp
->
filter_fir_sym
(
&
filter1_slice
,
filter1_win
);
points_to_drop
=
8
+
filter_jitter
;
std
::
cerr
<<
"points_to_drop: "
<<
points_to_drop
<<
std
::
endl
;
// 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
));
...
...
@@ -452,11 +432,12 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
}
tofilter1
.
erase
(
tofilter1
.
begin
(),
tofilter1
.
begin
()
+
points_to_drop
);
// remove a time block and update our estimate
total_blocks
=
round
(
total_blocks
);
total_blocks
--
;
std
::
cerr
<<
"Total blocks (post filter): "
<<
total_blocks
<<
std
::
endl
;
time_block_check
=
round
(
8
*
(
total_blocks
));
check_filters
=
total_blocks
/
16
;
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
);
// 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
);
// Wait until filter2 queue is filled
if
(
tofilter2
.
size
()
==
filter2_block_len
)
{
...
...
@@ -487,14 +468,13 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
}
else
if
(
tofilter1
.
size
()
<
min_filter1
)
{
std
::
cerr
<<
"[!!!] Not enough data!"
<<
std
::
endl
;
}
else
{
std
::
cerr
<<
"[!!!] Enough to run filter! But for some reason we didn't!"
<<
std
::
endl
;
//
std::cerr << "[!!!] Enough to run filter! But for some reason we didn't!" << std::endl;
}
}
// --------------------------------------------------------------
// Otherwise keep getting data
// --------------------------------------------------------------
// rotate the time block edge now that we've finished handling the block
last_timeblock_edge
=
this_timeblock_edge
;
}
...
...
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