feat: save received data from BLE to flash

This commit is contained in:
Dien-Nhung Nguyen-Phu
2024-06-23 19:44:32 +07:00
parent 8274cab154
commit 86e6f0db4d
6 changed files with 181 additions and 35 deletions

View File

@@ -1,5 +1,9 @@
#include "utils.h"
#include "../../data.h"
#include "../../power.h"
#include "../../leddrv.h"
static const uint16_t ServiceUUID = 0xFEE0;
static const gattAttrType_t service = {2, (uint8_t *)&ServiceUUID};
@@ -16,7 +20,35 @@ static gattAttribute_t attr_table[] = {
static bStatus_t receive(uint8_t *val, uint16_t len)
{
/* TODO: implement data receiving here*/
static uint16_t c, data_len, n;
static uint8_t *data;
if (len != LEGACY_TRANSFER_WIDTH) {
return ATT_ERR_INVALID_VALUE_SIZE;
}
if (c == 0) {
if (memcmp(val, "wang\0\0", 6)) {
return ATT_ERR_INVALID_VALUE;
} else {
data = malloc(sizeof(data_legacy_t));
}
}
memcpy(data + c * len, val, len);
if (c == 1) {
data_legacy_t *d = (data_legacy_t *)data;
n = bigendian16_sum(d->sizes, 8);
data_len = LEGACY_HEADER_SIZE + LED_ROWS * n;
data = realloc(data, data_len);
}
if (c > 2 && ((c+1) * LEGACY_TRANSFER_WIDTH) >= data_len) {
data_flatSave(data, data_len);
reset_jump();
}
c++;
return SUCCESS;
}
static bStatus_t write_handler(uint16 connHandle, gattAttribute_t *pAttr,