Skip to content
Snippets Groups Projects
Commit 747803cc authored by schneider's avatar schneider
Browse files

change(ble): Use card10.cfg instead of ble.txt and mac.txt

parent 3e24328f
No related branches found
No related tags found
1 merge request!402New pairing database
Pipeline #4728 passed
...@@ -43,5 +43,9 @@ Option name Type Description ...@@ -43,5 +43,9 @@ Option name Type Description
------------------ ---------- ----------- ------------------ ---------- -----------
``default_app`` String Full path to the exectutable file of the default application. If this option is not set,``apps/analog_clock/__init__.py`` is used. ``default_app`` String Full path to the exectutable file of the default application. If this option is not set,``apps/analog_clock/__init__.py`` is used.
------------------ ---------- ----------- ------------------ ---------- -----------
``ble_enable`` Boolean Activate the BLE interface. Turn off for more privacy or to conserve energy.
------------------ ---------- -----------
``ble_mac`` Boolean MAC address used for BLE. Format: ``ca:4d:10:xx:xx:xx``.
------------------ ---------- -----------
``ble_log_enable`` Boolean Activate HCI level logging of BLE data. Creates a new btsnoop compatible log file named ``ble.log`` in the ``logs`` folder after each boot if BLE is activated. Keeps the last 10 files. ``ble_log_enable`` Boolean Activate HCI level logging of BLE data. Creates a new btsnoop compatible log file named ``ble.log`` in the ``logs`` folder after each boot if BLE is activated. Keeps the last 10 files.
================== ========== =========== ================== ========== ===========
...@@ -174,11 +174,11 @@ static void setAddress(void) ...@@ -174,11 +174,11 @@ static void setAddress(void)
uint8_t bdAddr[6] = { 0xCA, 0x4D, 0x10, 0x00, 0x00, 0x00 }; uint8_t bdAddr[6] = { 0xCA, 0x4D, 0x10, 0x00, 0x00, 0x00 };
char buf[32]; char buf[32];
int result = fs_read_text_file("mac.txt", buf, sizeof(buf)); int result = epic_config_get_string("ble_mac", buf, sizeof(buf));
if (result < 0) { if (result < 0) {
APP_TRACE_INFO0("mac.txt not found, generating random MAC"); APP_TRACE_INFO0("ble_mac not set. Generating random MAC");
epic_trng_read(bdAddr + 3, 3); epic_csprng_read(bdAddr + 3, 3);
sprintf(buf, sprintf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x\n", "%02x:%02x:%02x:%02x:%02x:%02x\n",
bdAddr[0], bdAddr[0],
...@@ -187,9 +187,9 @@ static void setAddress(void) ...@@ -187,9 +187,9 @@ static void setAddress(void)
bdAddr[3], bdAddr[3],
bdAddr[4], bdAddr[4],
bdAddr[5]); bdAddr[5]);
fs_write_file("mac.txt", buf, strlen(buf)); epic_config_set_string("ble_mac", buf);
} else { } else {
APP_TRACE_INFO1("mac file contents: %s", buf); APP_TRACE_INFO1("ble_mac: %s", buf);
} }
int a, b, c, d, e, f; int a, b, c, d, e, f;
...@@ -255,35 +255,17 @@ void RSV11_IRQHandler(void) ...@@ -255,35 +255,17 @@ void RSV11_IRQHandler(void)
notify(); notify();
} }
/*************************************************************************************************/ /*************************************************************************************************/
#define BLEMAXCFGBYTES 100
bool ble_shall_start(void) bool ble_shall_start(void)
{ {
int bleConfigFile = epic_file_open("ble.txt", "r"); bool ble_enabled = config_get_boolean_with_default("ble_enable", false);
if (bleConfigFile < 0) {
LOG_INFO("ble", "can not open ble.txt -> BLE is not started");
epic_file_close(bleConfigFile);
return false;
}
char cfgBuf[BLEMAXCFGBYTES + 1];
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES);
epic_file_close(bleConfigFile);
if (readNum < 0) {
LOG_WARN("ble", "can not read ble.txt -> BLE is not started");
return false;
}
cfgBuf[readNum] = '\0';
char bleActiveStr[] = "active=true"; if (ble_enabled) {
cfgBuf[sizeof(bleActiveStr) - 1] = '\0';
if (strcmp(cfgBuf, "active=true") != 0) {
LOG_INFO("ble", "BLE is disabled.");
return false;
} else {
LOG_INFO("ble", "BLE is enabled."); LOG_INFO("ble", "BLE is enabled.");
return true; } else {
LOG_INFO("ble", "BLE is disabled.");
} }
return ble_enabled;
} }
/*************************************************************************************************/ /*************************************************************************************************/
static void scheduleTimer(void) static void scheduleTimer(void)
......
...@@ -464,7 +464,8 @@ static void bleSetup(bleMsg_t *pMsg) ...@@ -464,7 +464,8 @@ static void bleSetup(bleMsg_t *pMsg)
char buf[32]; char buf[32];
char a, b, c, d, e, f, K; char a, b, c, d, e, f, K;
if (fs_read_text_file("mac.txt", buf, sizeof(buf)) > 0) int result = epic_config_get_string("ble_mac", buf, sizeof(buf));
if (result == 0)
{ {
if (sscanf(buf, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", &K,&K,&K,&K,&K,&K, &a, &b, &c, &d, &e, &f) == 12) if (sscanf(buf, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", &K,&K,&K,&K,&K,&K, &a, &b, &c, &d, &e, &f) == 12)
{ {
......
...@@ -4,11 +4,8 @@ import time ...@@ -4,11 +4,8 @@ import time
import buttons import buttons
import sys_ble import sys_ble
import interrupt import interrupt
import config
CONFIG_NAME = "ble.txt"
MAC_NAME = "mac.txt"
ACTIVE_STRING = "active=true"
INACTIVE_STRING = "active=false"
ble_event = None ble_event = None
...@@ -18,18 +15,16 @@ def ble_callback(_): ...@@ -18,18 +15,16 @@ def ble_callback(_):
def init(): def init():
if CONFIG_NAME not in os.listdir("."):
with open(CONFIG_NAME, "w") as f:
f.write(INACTIVE_STRING)
interrupt.set_callback(interrupt.BLE, ble_callback) interrupt.set_callback(interrupt.BLE, ble_callback)
interrupt.enable_callback(interrupt.BLE) interrupt.enable_callback(interrupt.BLE)
sys_ble.set_bondable(True) sys_ble.set_bondable(True)
def load_mac(): def load_mac():
if MAC_NAME in os.listdir("."): try:
with open(MAC_NAME) as f: return config.get_string("ble_mac")
return f.read().strip() except OSError:
return None
def triangle(disp, x, y, left): def triangle(disp, x, y, left):
...@@ -41,9 +36,10 @@ def triangle(disp, x, y, left): ...@@ -41,9 +36,10 @@ def triangle(disp, x, y, left):
def toggle(): def toggle():
content = INACTIVE_STRING if is_active() else ACTIVE_STRING if is_active():
with open(CONFIG_NAME, "w") as f: config.set_string("ble_enable", "false")
f.write(content) else:
config.set_string("ble_enable", "true")
disp.clear() disp.clear()
disp.print("resetting", posy=0, fg=[0, 255, 255]) disp.print("resetting", posy=0, fg=[0, 255, 255])
...@@ -54,12 +50,14 @@ def toggle(): ...@@ -54,12 +50,14 @@ def toggle():
def is_active(): def is_active():
with open(CONFIG_NAME, "r") as f: try:
state = f.readlines()[0] active = config.get_string("ble_enable")
if len(state) < len(ACTIVE_STRING): if active == "true" or active == "1":
return False return True
state = state[0 : len(ACTIVE_STRING)] except OSError:
return state == ACTIVE_STRING pass
return False
def headline(): def headline():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment