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
d36a0443
Commit
d36a0443
authored
Apr 06, 2021
by
Thomas Edwards
Browse files
Wokring stall fix, lots of debug info
parent
070f87ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Filter_Obs.cpp
View file @
d36a0443
...
...
@@ -220,6 +220,12 @@ 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
// =====================================================================
...
...
@@ -231,6 +237,12 @@ 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
)
{
...
...
@@ -311,14 +323,16 @@ 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
in
t
time_block_check
=
0
;
floa
t
time_block_check
=
0
;
int
filter1_block_count
=
1
;
int
filter1_block_numdata
=
1
;
int
filter2_count
=
filter2_block_step
;
// Apply straight ahead first time
in
t
total_blocks
=
0
;
floa
t
total_blocks
=
0
;
//
// Continuously run concatenated filters one and two.
...
...
@@ -333,6 +347,7 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
tofilter1
.
back
()
->
get_time
(
&
last_timespec
);
data
->
get_time
(
&
this_timespec
);
//counter++;
data
->
string
(
&
datastr
,
5
);
...
...
@@ -359,11 +374,18 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// Degbugging monitoring info
// --------------------------------------------------------------
// std::cerr << "-----------------------------------" << std::endl;
//
timestamp=tofilter1.back()->get_time("%Y-%m-%d %H:%M:%S",true);
timestamp
=
tofilter1
.
back
()
->
get_time
(
"%Y-%m-%d %H:%M:%S"
,
true
);
// std::cerr << "Latest timestamp: " << timestamp << " | ";
// std::cerr << "No. Rec: " << tofilter1.size() << " | ";
total_blocks
+=
round
(
elapsed_time_last_block
/
((
1.
/
16
)
*
1e9
));
// std::cerr << "Elapsed time: ";
// std::cerr << elapsed_time_last_block << " | ";
// Assume 128 Hz being downsampled to 16 Hz. That means 1 block ever 1e9/16 ns
// int num_blocks = round(elapsed_time_last_block/(1e9/16));
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;
// --------------------------------------------------------------
...
...
@@ -373,12 +395,19 @@ int Filter_Obs::lowpass_PLASMON_1Hz(buffer_obs* buffer_in,
// 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
)
{
// 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
=
8
*
(
total_blocks
);
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
);
// std::cerr << "Data in que: " << tofilter1.size() << " | blocks*8: " << time_block_check << " | Run the filter?: " << run_the_filter << std::endl;
while
(
run_the_filter
)
{
...
...
@@ -392,13 +421,19 @@ 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
<<
"Data in que: "
<<
tofilter1
.
size
()
<<
" | blocks*8: "
<<
time_block_check
<<
" | Run the filter?: "
<<
run_the_filter
<<
std
::
endl
;
std
::
cerr
<<
"Elapsed time between blocks: "
<<
elapsed_time_last_block
<<
std
::
endl
;
std
::
cerr
<<
"Blocks since last check: "
<<
round
(
elapsed_time_last_block
/
((
1.
/
16
)
*
1e9
))
<<
" | "
;
std
::
cerr
<<
"Assumed total blocks: "
<<
total_blocks
<<
" | "
;
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: "
;
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
<<
" | "
;
// Filter data
...
...
@@ -418,13 +453,14 @@ 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
--
;
time_block_check
=
8
*
(
total_blocks
);
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;
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
);
// 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);
...
...
@@ -435,9 +471,11 @@ 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
{
...
...
@@ -456,6 +494,7 @@ 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
;
}
...
...
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