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
------------------ ---------- -----------
``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.
================== ========== ===========
......@@ -174,11 +174,11 @@ static void setAddress(void)
uint8_t bdAddr[6] = { 0xCA, 0x4D, 0x10, 0x00, 0x00, 0x00 };
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) {
APP_TRACE_INFO0("mac.txt not found, generating random MAC");
epic_trng_read(bdAddr + 3, 3);
APP_TRACE_INFO0("ble_mac not set. Generating random MAC");
epic_csprng_read(bdAddr + 3, 3);
sprintf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x\n",
bdAddr[0],
......@@ -187,9 +187,9 @@ static void setAddress(void)
bdAddr[3],
bdAddr[4],
bdAddr[5]);
fs_write_file("mac.txt", buf, strlen(buf));
epic_config_set_string("ble_mac", buf);
} else {
APP_TRACE_INFO1("mac file contents: %s", buf);
APP_TRACE_INFO1("ble_mac: %s", buf);
}
int a, b, c, d, e, f;
......@@ -255,35 +255,17 @@ void RSV11_IRQHandler(void)
notify();
}
/*************************************************************************************************/
#define BLEMAXCFGBYTES 100
bool ble_shall_start(void)
{
int bleConfigFile = epic_file_open("ble.txt", "r");
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';
bool ble_enabled = config_get_boolean_with_default("ble_enable", false);
char bleActiveStr[] = "active=true";
cfgBuf[sizeof(bleActiveStr) - 1] = '\0';
if (strcmp(cfgBuf, "active=true") != 0) {
LOG_INFO("ble", "BLE is disabled.");
return false;
} else {
if (ble_enabled) {
LOG_INFO("ble", "BLE is enabled.");
return true;
} else {
LOG_INFO("ble", "BLE is disabled.");
}
return ble_enabled;
}
/*************************************************************************************************/
static void scheduleTimer(void)
......
......@@ -464,7 +464,8 @@ static void bleSetup(bleMsg_t *pMsg)
char buf[32];
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)
{
......
......@@ -4,11 +4,8 @@ import time
import buttons
import sys_ble
import interrupt
import config
CONFIG_NAME = "ble.txt"
MAC_NAME = "mac.txt"
ACTIVE_STRING = "active=true"
INACTIVE_STRING = "active=false"
ble_event = None
......@@ -18,18 +15,16 @@ def ble_callback(_):
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.enable_callback(interrupt.BLE)
sys_ble.set_bondable(True)
def load_mac():
if MAC_NAME in os.listdir("."):
with open(MAC_NAME) as f:
return f.read().strip()
try:
return config.get_string("ble_mac")
except OSError:
return None
def triangle(disp, x, y, left):
......@@ -41,9 +36,10 @@ def triangle(disp, x, y, left):
def toggle():
content = INACTIVE_STRING if is_active() else ACTIVE_STRING
with open(CONFIG_NAME, "w") as f:
f.write(content)
if is_active():
config.set_string("ble_enable", "false")
else:
config.set_string("ble_enable", "true")
disp.clear()
disp.print("resetting", posy=0, fg=[0, 255, 255])
......@@ -54,12 +50,14 @@ def toggle():
def is_active():
with open(CONFIG_NAME, "r") as f:
state = f.readlines()[0]
if len(state) < len(ACTIVE_STRING):
return False
state = state[0 : len(ACTIVE_STRING)]
return state == ACTIVE_STRING
try:
active = config.get_string("ble_enable")
if active == "true" or active == "1":
return True
except OSError:
pass
return False
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