Skip to content
Snippets Groups Projects

Battery Voltage

Merged rahix requested to merge rahix/batt into master
All threads resolved!
Files
9
+ 54
2
#include "epicardium.h"
#include "modules/log.h"
#include "fs_util.h"
@@ -7,6 +8,7 @@
#include "ble_api.h"
#include "hci_vs.h"
#include "att_api.h"
#include "trng.h"
#include "FreeRTOS.h"
#include "timers.h"
@@ -92,8 +94,27 @@ static void setAddress(void)
uint8_t bdAddr[6] = { 0x02, 0x02, 0x44, 0x8B, 0x05, 0x00 };
char buf[32];
fs_read_text_file("mac.txt", buf, sizeof(buf));
APP_TRACE_INFO1("mac file contents: %s", buf);
int result = fs_read_text_file("mac.txt", buf, sizeof(buf));
if (result == -1) {
APP_TRACE_INFO0("mac.txt not found, generating random MAC");
bdAddr[0] = 0xCA;
bdAddr[1] = 0x4D;
bdAddr[2] = 0x10;
TRNG_Read(MXC_TRNG, bdAddr + 3, 3);
sprintf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x\n",
bdAddr[0],
bdAddr[1],
bdAddr[2],
bdAddr[3],
bdAddr[4],
bdAddr[5]);
fs_write_file("mac.txt", buf, strlen(buf));
} else {
APP_TRACE_INFO1("mac file contents: %s", buf);
}
int a, b, c, d, e, f;
if (sscanf(buf, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f) == 6) {
bdAddr[0] = f;
@@ -152,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;
Loading