Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
multipass
Commits
0319d8f5
Commit
0319d8f5
authored
3 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
BME680 BSEC: support state (de)serialization across application restarts
parent
df10feba
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/bme680-bsec/main.cc
+65
-0
65 additions, 0 deletions
src/app/bme680-bsec/main.cc
src/driver/Kconfig
+10
-2
10 additions, 2 deletions
src/driver/Kconfig
with
75 additions
and
2 deletions
src/app/bme680-bsec/main.cc
+
65
−
0
View file @
0319d8f5
...
...
@@ -3,6 +3,15 @@
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include
"config.h"
#ifdef CONFIG_driver_bme680_bsec_save_state
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define BSEC_STATE_PATH TOSTRING(CONFIG_driver_bme680_bsec_state_path)
#include
<stdio.h>
#endif
#include
"arch.h"
#include
"driver/gpio.h"
#include
"driver/stdout.h"
...
...
@@ -20,10 +29,18 @@
const
char
*
accuracy
[]
=
{
"(unreliable)"
,
"(calibration required)"
,
"(auto-trim in progress)"
,
""
};
#ifdef CONFIG_driver_bme680_bsec_save_state
// For (de)serialization of library state across application restarts
uint8_t
serialized_state
[
BSEC_MAX_STATE_BLOB_SIZE
];
uint8_t
work_buffer
[
BSEC_MAX_STATE_BLOB_SIZE
];
#endif
void
loop
(
void
)
{
static
bsec_bme_settings_t
sensor_settings
;
static
uint16_t
iteration
=
0
;
struct
bme680_field_data
data
;
bsec_input_t
bsec_inputs
[
BSEC_MAX_PHYSICAL_SENSOR
];
bsec_output_t
bsec_outputs
[
BSEC_NUMBER_OUTPUTS
];
...
...
@@ -177,6 +194,32 @@ void loop(void)
kout
<<
endl
;
}
}
#ifdef CONFIG_driver_bme680_bsec_save_state
if
(
++
iteration
==
600
)
{
uint32_t
serialized_state_size
;
status
=
bsec_get_state
(
0
,
serialized_state
,
BSEC_MAX_STATE_BLOB_SIZE
,
work_buffer
,
BSEC_MAX_STATE_BLOB_SIZE
,
&
serialized_state_size
);
if
(
status
<
0
)
{
kout
<<
"bsec_get_state error: "
<<
status
<<
endl
;
return
;
}
if
(
status
>
0
)
{
kout
<<
"bsec_get_state warning: "
<<
status
<<
endl
;
}
FILE
*
f
=
fopen
(
BSEC_STATE_PATH
,
"w"
);
if
(
f
==
NULL
)
{
perror
(
"fopen"
);
return
;
}
if
(
fwrite
(
serialized_state
,
sizeof
(
uint8_t
),
serialized_state_size
,
f
)
<
serialized_state_size
)
{
perror
(
"fwrite"
);
}
if
(
fclose
(
f
)
==
EOF
)
{
perror
(
"fclose"
);
}
iteration
=
0
;
}
#endif
}
int
main
(
void
)
...
...
@@ -215,6 +258,28 @@ int main(void)
}
kout
<<
"BSEC init OK"
<<
endl
;
#ifdef CONFIG_driver_bme680_bsec_save_state
FILE
*
f
=
fopen
(
BSEC_STATE_PATH
,
"r"
);
if
(
f
!=
NULL
)
{
size_t
serialized_state_size
=
fread
(
serialized_state
,
BSEC_MAX_STATE_BLOB_SIZE
,
sizeof
(
uint8_t
),
f
);
if
(
serialized_state_size
>
0
)
{
bsec_status
=
bsec_set_state
(
serialized_state
,
BSEC_MAX_STATE_BLOB_SIZE
,
work_buffer
,
BSEC_MAX_STATE_BLOB_SIZE
);
if
(
bsec_status
<
0
)
{
kout
<<
"bsec_set_state error: "
<<
bsec_status
<<
endl
;
}
if
(
bsec_status
>
0
)
{
kout
<<
"bsec_set_state warning: "
<<
bsec_status
<<
endl
;
}
}
if
(
fclose
(
f
)
==
EOF
)
{
perror
(
"fclose"
);
}
}
else
{
// file doesn't exist. that's harmless.
perror
(
"fopen"
);
}
#endif
/*
* Output configuration. The BME680 BSEC library supports several virtual
* sensors such as raw temperature, compensated temperature, or IAQ. Each
...
...
This diff is collapsed.
Click to expand it.
src/driver/Kconfig
+
10
−
2
View file @
0319d8f5
...
...
@@ -37,11 +37,10 @@ depends on meta_driver_i2c && !driver_bme280
config driver_bme680_bsec
bool "with BSEC (proprietary library for IAQ calculation)"
depends on driver_bme680 &&
(arch_msp430fr5994lp ||
arch_posix
)
depends on driver_bme680 && arch_posix
# incompatible with avr-gcc 5:
# /usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: avr:6 architecture of input file `...' is incompatible with avr:5 output
config driver_bme680_bsec_path
string "BSEC library path"
default "bme680-bsec-lite" if arch_arduino_nano
...
...
@@ -49,6 +48,15 @@ default "bme680-bsec" if arch_msp430fr5994lp
default "bme680-bsec-armv6" if arch_posix
depends on driver_bme680_bsec
config driver_bme680_bsec_save_state
bool "Save and Load library state (requires stdio)"
depends on driver_bme680_bsec
config driver_bme680_bsec_state_path
string "BSEC state path"
default "/boot/bme680-bsec.state" if arch_posix
depends on driver_bme680_bsec_save_state
config driver_ccs811
bool "CCS811 VOC Sensor"
depends on meta_driver_i2c
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment