aboutsummaryrefslogtreecommitdiff
path: root/src/ble
diff options
context:
space:
mode:
authorFrançois Cartegnie <281376+fcartegnie@users.noreply.github.com>2024-07-09 08:46:46 +0200
committerGitHub <noreply@github.com>2024-07-09 08:46:46 +0200
commitb25d62d1362cfd711e6617a9212e3eddc4e9fddd (patch)
tree7bb91449ca4b586cf7739a6d727855338f3ab410 /src/ble
parenta6c62295e92b3d960700508a445be1fba71a3cc2 (diff)
parent86e6f0db4d8349a7efbd98ac5fe5453fb58bd82c (diff)
Merge pull request #31 from kienvo/ble-save
feat: Save received data from BLE to flash
Diffstat (limited to 'src/ble')
-rw-r--r--src/ble/profile/legacy.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/ble/profile/legacy.c b/src/ble/profile/legacy.c
index fc775e5..2957aa5 100644
--- a/src/ble/profile/legacy.c
+++ b/src/ble/profile/legacy.c
@@ -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,