Skip to content
Snippets Groups Projects
Commit 77d19af5 authored by Hauke Mehrtens's avatar Hauke Mehrtens
Browse files

BLE: FileTrans: Allow to deactivate File transfer


This allows to deactivate the File Transfer in the ble.txt

Signed-off-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
parent dc975c7b
No related branches found
No related tags found
No related merge requests found
#define _POSIX_C_SOURCE 200809
#include "epicardium.h"
#include "modules/log.h"
......@@ -13,6 +14,7 @@
#include "timers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
......@@ -170,28 +172,60 @@ void wsf_ble_signal_event(void)
}
/*************************************************************************************************/
#define BLEMAXCFGBYTES 100
bool ble_shall_start(void)
int ble_get_option(const char *name, char *buf, size_t buf_len)
{
char *saveptr1, *saveptr2;
char *token, *str1, *name_parsed, *option;
char cfgBuf[BLEMAXCFGBYTES + 1];
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;
return bleConfigFile;
}
char cfgBuf[BLEMAXCFGBYTES + 1];
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES);
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES - 1);
epic_file_close(bleConfigFile);
if (readNum < 0) {
LOG_WARN("ble", "can not read ble.txt -> BLE is not started");
return false;
return readNum;
}
cfgBuf[readNum] = '\0';
char bleActiveStr[] = "active=true";
cfgBuf[sizeof(bleActiveStr) - 1] = '\0';
str1 = cfgBuf;
while (TRUE) {
token = strtok_r(str1, "\n", &saveptr1);
if (token == NULL)
break;
str1 = NULL;
name_parsed = strtok_r(token, "=", &saveptr2);
if (name_parsed == NULL)
continue;
if (strcmp(token, name_parsed) != 0)
continue;
option = strtok_r(NULL, "=", &saveptr2);
if (option == NULL)
return -ENOENT;
strncpy(buf, option, buf_len - 1);
buf[buf_len - 1] = '\0';
return 0;
}
return -ENOENT;
}
bool ble_shall_start(void)
{
char buf[10];
int ret;
ret = ble_get_option("active", buf, sizeof(buf));
if (ret)
return false;
if (strcmp(cfgBuf, "active=true") != 0) {
if (strcmp(buf, "true") != 0) {
LOG_INFO("ble", "BLE is disabled.");
return false;
} else {
......
......@@ -407,10 +407,23 @@ static attsGroup_t fileTransCfgGroup = {
.endHandle = FILE_TRANS_END_HDL,
};
bool ble_fileTrans_start(void)
{
char buf[10];
int ret;
/* if the option is not there activate it for now */
ret = ble_get_option("fileTrans", buf, sizeof(buf));
if (ret)
return true;
return !strcmp("true", buf);
}
/*
* This registers and starts the BLE file transfer service.
*/
void bleFileTransfer_init(void)
{
if (ble_fileTrans_start())
AttsAddGroup(&fileTransCfgGroup);
}
......@@ -66,6 +66,7 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result);
void vBleTask(void *pvParameters);
bool ble_shall_start(void);
void ble_uart_write(uint8_t *pValue, uint8_t len);
int ble_get_option(const char *name, char *buf, size_t buf_len);
/* ---------- Hardware (Peripheral) Locks ---------------------------------- */
void hwlock_init(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment