From e68a26793644c37c0a37ae554fdd4635fac67691 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Wed, 17 Jul 2019 20:32:22 +0200
Subject: [PATCH] feat(ble): Read MAC from file

---
 epicardium/modules/ble.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/epicardium/modules/ble.c b/epicardium/modules/ble.c
index 5139fc96..4f275832 100644
--- a/epicardium/modules/ble.c
+++ b/epicardium/modules/ble.c
@@ -99,9 +99,22 @@ static void WsfInit(void)
 void SetAddress(uint8_t event)
 {
     uint8_t bdAddr[6] = {0x02, 0x02, 0x44, 0x8B, 0x05, 0x00};
+    char buf[32];
 
     switch (event) {
     case APP_UI_RESET_CMPL:
+        fs_read_text_file("mac.txt", buf, sizeof(buf));
+        printf("mac file: %s\n", buf);
+        int a, b, c, d, e, f;
+        if(sscanf(buf, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f) == 6) {
+            bdAddr[0] = f;
+            bdAddr[1] = e;
+            bdAddr[2] = d;
+            bdAddr[3] = c;
+            bdAddr[4] = b;
+            bdAddr[5] = a;
+        }
+
         printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
         HciVsSetBdAddr(bdAddr);
         break;
-- 
GitLab