Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
80e3b8f2
Commit
80e3b8f2
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(ess): Send notifications when doing single read
parent
405a656e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!428
Environmental Sensing Service
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/ble/ess.c
+66
-60
66 additions, 60 deletions
epicardium/ble/ess.c
with
66 additions
and
60 deletions
epicardium/ble/ess.c
+
66
−
60
View file @
80e3b8f2
...
...
@@ -173,6 +173,45 @@ WSF_CT_ASSERT(
((
sizeof
(
ESSSvcAttrList
)
/
sizeof
(
ESSSvcAttrList
[
0
]))
==
ESS_END_HDL
-
ESS_START_HDL
+
1
));
static
void
sendNotification
(
dmConnId_t
connId
,
uint16_t
handle
,
uint16_t
cccidx
)
{
if
(
connId
!=
DM_CONN_ID_NONE
)
{
uint16_t
len
;
uint8_t
*
value
;
uint8_t
ret
=
AttsGetAttr
(
handle
,
&
len
,
&
value
);
if
(
ret
==
ATT_SUCCESS
)
{
if
(
AttsCccEnabled
(
connId
,
cccidx
))
{
AttsHandleValueNtf
(
connId
,
handle
,
len
,
value
);
}
}
}
}
static
void
setAttrFromBME680
(
struct
bme680_sensor_data
*
data
)
{
int16_t
temperature
;
uint16_t
humidity
;
uint32_t
pressure
;
temperature
=
data
->
temperature
*
100
;
AttsSetAttr
(
ESS_TEMPERATURE_VAL_HDL
,
sizeof
(
temperature
),
(
uint8_t
*
)
&
temperature
);
humidity
=
data
->
humidity
*
100
;
AttsSetAttr
(
ESS_HUMIDITY_VAL_HDL
,
sizeof
(
humidity
),
(
uint8_t
*
)
&
humidity
);
pressure
=
data
->
pressure
*
1000
;
AttsSetAttr
(
ESS_PRESSURE_VAL_HDL
,
sizeof
(
pressure
),
(
uint8_t
*
)
&
pressure
);
}
/*
* BLE ESS read callback.
*
...
...
@@ -184,40 +223,39 @@ static uint8_t readESSCB(
uint16_t
offset
,
attsAttr_t
*
pAttr
)
{
int16_t
temperature
;
uint16_t
humidity
;
uint32_t
pressure
;
struct
bme680_sensor_data
data
;
int
ret
=
epic_bme680_read_sensors
(
&
data
);
if
(
ret
!=
0
)
{
return
ATT_ERR_UNDEFINED
;
}
setAttrFromBME680
(
&
data
);
/* Send notifications (if enabled) for the _other_ characteristics. */
switch
(
handle
)
{
case
ESS_TEMPERATURE_VAL_HDL
:
temperature
=
data
.
temperature
*
100
;
AttsSetAttr
(
ESS_TEMPERATURE_VAL_HDL
,
sizeof
(
temperature
),
(
uint8_t
*
)
&
temperature
sendNotification
(
connId
,
ESS_HUMIDITY_VAL_HDL
,
BLE_ESS_HUMI_CCC_IDX
);
sendNotification
(
connId
,
ESS_PRESSURE_VAL_HDL
,
BLE_ESS_PRES_CCC_IDX
);
APP_TRACE_INFO1
(
"ble-ess: read temperature: %d
\n
"
,
temperature
);
return
ATT_SUCCESS
;
case
ESS_HUMIDITY_VAL_HDL
:
humidity
=
data
.
humidity
*
100
;
AttsSetAttr
(
ESS_HUMIDITY_VAL_HDL
,
sizeof
(
humidity
),
(
uint8_t
*
)
&
humidity
sendNotification
(
connId
,
ESS_TEMPERATURE_VAL_HDL
,
BLE_ESS_TEMP_CCC_IDX
);
sendNotification
(
connId
,
ESS_PRESSURE_VAL_HDL
,
BLE_ESS_PRES_CCC_IDX
);
APP_TRACE_INFO1
(
"ble-ess: read humidity: %u
\n
"
,
humidity
);
return
ATT_SUCCESS
;
case
ESS_PRESSURE_VAL_HDL
:
pressure
=
data
.
pressure
*
1000
;
AttsSetAttr
(
ESS_PRESSURE_VAL_HDL
,
sizeof
(
pressure
),
(
uint8_t
*
)
&
pressure
sendNotification
(
connId
,
ESS_TEMPERATURE_VAL_HDL
,
BLE_ESS_TEMP_CCC_IDX
);
sendNotification
(
connId
,
ESS_HUMIDITY_VAL_HDL
,
BLE_ESS_HUMI_CCC_IDX
);
APP_TRACE_INFO1
(
"ble-ess: read pressure: %u
\n
"
,
pressure
);
return
ATT_SUCCESS
;
...
...
@@ -238,50 +276,18 @@ static attsGroup_t svcESSGroup = {
void
bleESS_update
(
void
)
{
int16_t
temperature
=
0
;
AttsSetAttr
(
ESS_TEMPERATURE_VAL_HDL
,
sizeof
(
temperature
),
(
uint8_t
*
)
&
temperature
);
uint16_t
humidity
=
0
;
AttsSetAttr
(
ESS_HUMIDITY_VAL_HDL
,
sizeof
(
humidity
),
(
uint8_t
*
)
&
humidity
);
uint32_t
pressure
=
0
;
AttsSetAttr
(
ESS_PRESSURE_VAL_HDL
,
sizeof
(
pressure
),
(
uint8_t
*
)
&
pressure
);
struct
bme680_sensor_data
data
;
int
ret
=
epic_bme680_read_sensors
(
&
data
);
if
(
ret
!=
0
)
{
return
;
}
setAttrFromBME680
(
&
data
);
/* Send notifications (if enabled) for all characteristics. */
dmConnId_t
connId
=
AppConnIsOpen
();
if
(
connId
!=
DM_CONN_ID_NONE
)
{
if
(
AttsCccEnabled
(
connId
,
BLE_ESS_TEMP_CCC_IDX
))
{
AttsHandleValueNtf
(
connId
,
ESS_TEMPERATURE_VAL_HDL
,
sizeof
(
temperature
),
(
uint8_t
*
)
&
temperature
);
}
if
(
AttsCccEnabled
(
connId
,
BLE_ESS_HUMI_CCC_IDX
))
{
AttsHandleValueNtf
(
connId
,
ESS_HUMIDITY_VAL_HDL
,
sizeof
(
humidity
),
(
uint8_t
*
)
&
humidity
);
}
if
(
AttsCccEnabled
(
connId
,
BLE_ESS_PRES_CCC_IDX
))
{
AttsHandleValueNtf
(
connId
,
ESS_PRESSURE_VAL_HDL
,
sizeof
(
pressure
),
(
uint8_t
*
)
&
pressure
);
}
}
sendNotification
(
connId
,
ESS_TEMPERATURE_VAL_HDL
,
BLE_ESS_TEMP_CCC_IDX
);
sendNotification
(
connId
,
ESS_HUMIDITY_VAL_HDL
,
BLE_ESS_HUMI_CCC_IDX
);
sendNotification
(
connId
,
ESS_PRESSURE_VAL_HDL
,
BLE_ESS_PRES_CCC_IDX
);
}
/*
...
...
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