diff --git a/epicardium/main.c b/epicardium/main.c index e22d95cbcc258cb963d8d3f476e64e3570365768..4eb1b5273e7d4687ff5f2266b6f751b94a7bdde4 100644 --- a/epicardium/main.c +++ b/epicardium/main.c @@ -30,6 +30,40 @@ TaskHandle_t dispatcher_task_id; void vBleTask(void *pvParameters); +#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"); + return 0; + } + + char cfgBuf[BLEMAXCFGBYTES+1]; + int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES); + LOG_INFO("startup", "readNum %i", readNum); + if (readNum < 0) { + LOG_INFO("startup", "can not read ble.txt -> BLE is not started"); + return 0; + } + cfgBuf[readNum] = '\0'; + + LOG_INFO("startup", "faa %s", cfgBuf); + + char bleActiveStr[] = "active=true"; + cfgBuf[sizeof(bleActiveStr)-1] = '\0'; + LOG_INFO("startup", "foe %i %s", sizeof(bleActiveStr), cfgBuf); + + 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 ..."); @@ -118,15 +152,17 @@ int main(void) } /* BLE */ - if (xTaskCreate( - vBleTask, - (const char *)"BLE", - configMINIMAL_STACK_SIZE * 10, - NULL, - tskIDLE_PRIORITY + 1, - NULL) != pdPASS) { - LOG_CRIT("startup", "Failed to create %s task!", "BLE"); - abort(); + if (bleShallStart()) { + if (xTaskCreate( + vBleTask, + (const char *)"BLE", + configMINIMAL_STACK_SIZE * 10, + NULL, + tskIDLE_PRIORITY + 1, + NULL) != pdPASS) { + LOG_CRIT("startup", "Failed to create %s task!", "BLE"); + abort(); + } } /* light sensor */