Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
e86c7b6e
Commit
e86c7b6e
authored
Jun 18, 2020
by
schneider
Browse files
refact(ble): Simplify bonding storage
parent
7e8f17f0
Changes
1
Show whitespace changes
Inline
Side-by-side
epicardium/ble/app/common/app_db.c
View file @
e86c7b6e
...
...
@@ -95,12 +95,6 @@ static appDb_t appDb;
/*! When all records are allocated use this index to determine which to overwrite */
static
appDbRec_t
*
pAppDbNewRec
=
appDb
.
rec
;
/* Timer to delay writing to persistent storage until a burst of store() calls has finished */
static
TimerHandle_t
store_timer
;
static
StaticTimer_t
store_timer_buffer
;
static
void
store_callback
();
#define STORE_DELAY pdMS_TO_TICKS(5000)
/*************************************************************************************************/
/*!
* \brief Initialize the device database.
...
...
@@ -117,32 +111,12 @@ void AppDbInit(void)
memset
(
&
appDb
,
0
,
sizeof
(
appDb
));
}
epic_file_close
(
fd
);
}
store_timer
=
xTimerCreateStatic
(
"appdb_store_timer"
,
STORE_DELAY
,
pdFALSE
,
NULL
,
store_callback
,
&
store_timer_buffer
);
}
/* TODO this should actually put tasks into a queue. On the other end of the queue */
/* a worker task can read tasks off the queue and execute them */
static
void
store
(
void
)
{
LOG_INFO
(
"appDb"
,
"store() called, resetting timer"
);
if
(
xTimerReset
(
store_timer
,
10
)
!=
pdPASS
)
{
/* (Re)start the timer */
/* Store timer could not be reset, write to persistent storage anyway */
store_callback
();
}
}
static
void
store_callback
(
)
static
void
AppDbStore
(
void
)
{
LOG_INFO
(
"appDb"
,
"
STORE_DELAY passed,
writing to persistent storage"
);
LOG_INFO
(
"appDb"
,
"writing to persistent storage"
);
int
fd
=
epic_file_open
(
"pairings.bin"
,
"w"
);
if
(
fd
>=
0
)
{
...
...
@@ -198,7 +172,6 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
pRec
->
peerAddedToRl
=
FALSE
;
pRec
->
peerRpao
=
FALSE
;
store
();
return
(
appDbHdl_t
)
pRec
;
}
...
...
@@ -263,7 +236,6 @@ appDbHdl_t AppDbGetNextRecord(appDbHdl_t hdl)
void
AppDbDeleteRecord
(
appDbHdl_t
hdl
)
{
((
appDbRec_t
*
)
hdl
)
->
inUse
=
FALSE
;
store
();
}
/*************************************************************************************************/
...
...
@@ -281,7 +253,7 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask)
{
((
appDbRec_t
*
)
hdl
)
->
valid
=
TRUE
;
((
appDbRec_t
*
)
hdl
)
->
keyValidMask
=
keyMask
;
s
tore
();
AppDbS
tore
();
}
/*************************************************************************************************/
...
...
@@ -371,7 +343,6 @@ void AppDbDeleteAllRecords(void)
{
pRec
->
inUse
=
FALSE
;
}
store
();
}
/*************************************************************************************************/
...
...
@@ -518,7 +489,6 @@ void AppDbSetKey(appDbHdl_t hdl, dmSecKeyIndEvt_t *pKey)
default:
break
;
}
store
();
}
/*************************************************************************************************/
...
...
@@ -551,7 +521,6 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value)
WSF_ASSERT
(
idx
<
APP_DB_NUM_CCCD
);
((
appDbRec_t
*
)
hdl
)
->
cccTbl
[
idx
]
=
value
;
store
();
}
/*************************************************************************************************/
...
...
@@ -581,7 +550,6 @@ uint8_t AppDbGetDiscStatus(appDbHdl_t hdl)
void
AppDbSetDiscStatus
(
appDbHdl_t
hdl
,
uint8_t
status
)
{
((
appDbRec_t
*
)
hdl
)
->
discStatus
=
status
;
store
();
}
/*************************************************************************************************/
...
...
@@ -611,7 +579,6 @@ uint16_t *AppDbGetHdlList(appDbHdl_t hdl)
void
AppDbSetHdlList
(
appDbHdl_t
hdl
,
uint16_t
*
pHdlList
)
{
memcpy
(((
appDbRec_t
*
)
hdl
)
->
hdlList
,
pHdlList
,
sizeof
(((
appDbRec_t
*
)
hdl
)
->
hdlList
));
store
();
}
/*************************************************************************************************/
...
...
@@ -654,7 +621,6 @@ void AppDbSetDevName(uint8_t len, char *pStr)
len
=
(
len
<=
sizeof
(
appDb
.
devName
))
?
len
:
sizeof
(
appDb
.
devName
);
memcpy
(
appDb
.
devName
,
pStr
,
len
);
store
();
}
/*************************************************************************************************/
...
...
@@ -684,7 +650,6 @@ bool_t AppDbGetPeerAddrRes(appDbHdl_t hdl)
void
AppDbSetPeerAddrRes
(
appDbHdl_t
hdl
,
uint8_t
addrRes
)
{
((
appDbRec_t
*
)
hdl
)
->
peerAddrRes
=
addrRes
;
store
();
}
/*************************************************************************************************/
...
...
@@ -715,7 +680,6 @@ void AppDbSetPeerSignCounter(appDbHdl_t hdl, uint32_t signCounter)
{
if
(((
appDbRec_t
*
)
hdl
)
->
peerSignCounter
!=
signCounter
)
{
((
appDbRec_t
*
)
hdl
)
->
peerSignCounter
=
signCounter
;
store
();
}
}
...
...
@@ -746,7 +710,6 @@ bool_t AppDbGetPeerAddedToRl(appDbHdl_t hdl)
void
AppDbSetPeerAddedToRl
(
appDbHdl_t
hdl
,
bool_t
peerAddedToRl
)
{
((
appDbRec_t
*
)
hdl
)
->
peerAddedToRl
=
peerAddedToRl
;
store
();
}
/*************************************************************************************************/
...
...
@@ -776,6 +739,5 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl)
void
AppDbSetPeerRpao
(
appDbHdl_t
hdl
,
bool_t
peerRpao
)
{
((
appDbRec_t
*
)
hdl
)
->
peerRpao
=
peerRpao
;
store
();
}
/* clang-format on */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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