Skip to content
Snippets Groups Projects
Verified Commit af026115 authored by rahix's avatar rahix
Browse files

chore(ble): Move ble_shall_start() into ble module


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent d4295ca4
No related branches found
No related tags found
No related merge requests found
#include "epicardium.h"
#include "modules/log.h"
#include "fs_util.h"
......@@ -172,6 +173,37 @@ void wsf_ble_signal_event(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';
char bleActiveStr[] = "active=true";
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.");
return true;
}
}
/*************************************************************************************************/
static void scheduleTimer(void)
{
bool_t timerRunning;
......
......@@ -9,46 +9,6 @@
#include <stdlib.h>
#include <string.h>
#define BLEMAXCFGBYTES 100
int bleShallStart(void)
{
int bleConfigFile = epic_file_open("ble.txt", "r");
if (bleConfigFile < 0) {
LOG_INFO(
"startup",
"can not open ble.txt -> BLE is not started"
);
epic_file_close(bleConfigFile);
return 0;
}
char cfgBuf[BLEMAXCFGBYTES + 1];
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES);
epic_file_close(bleConfigFile);
if (readNum < 0) {
LOG_INFO(
"startup",
"can not read ble.txt -> BLE is not started"
);
return 0;
}
cfgBuf[readNum] = '\0';
char bleActiveStr[] = "active=true";
cfgBuf[sizeof(bleActiveStr) - 1] = '\0';
if (strcmp(cfgBuf, "active=true") != 0) {
LOG_INFO(
"startup",
"ble.txt is not \"active=true\" -> BLE is not started"
);
return 0;
}
LOG_INFO("startup", "ble.txt is \"active=true\" -> BLE is starting");
return 1;
}
int main(void)
{
LOG_INFO("startup", "Epicardium startup ...");
......@@ -100,7 +60,7 @@ int main(void)
}
/* BLE */
if (bleShallStart()) {
if (ble_shall_start()) {
if (xTaskCreate(
vBleTask,
(const char *)"BLE",
......
......@@ -5,6 +5,7 @@
#include "semphr.h"
#include <stdint.h>
#include <stdbool.h>
/* ---------- Dispatcher --------------------------------------------------- */
void vApiDispatcher(void *pvParameters);
......@@ -33,6 +34,7 @@ void vPmicTask(void *pvParameters);
/* ---------- BLE ---------------------------------------------------------- */
void vBleTask(void *pvParameters);
bool ble_shall_start(void);
void ble_uart_write(uint8_t *pValue, uint8_t len);
/* ---------- Display ------------------------------------------------------ */
......
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