mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-09-02 00:38:50 +00:00
patch file CLRF fixup and repeater-observer hybrid first implementation
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/sys/ring_buffer.h>
|
||||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#define CLI_REPLY_SIZE 256
|
||||
@@ -32,64 +31,6 @@ LOG_MODULE_REGISTER(zephcore_observer_main, CONFIG_ZEPHCORE_MAIN_LOG_LEVEL);
|
||||
#include <ZephyrMQTTPublisher.h>
|
||||
#include "observer_creds.h"
|
||||
|
||||
/* ========== observer_creds_load / observer_creds_save ========== */
|
||||
|
||||
extern "C" bool observer_creds_load(struct ObserverCreds *creds,
|
||||
const char *base_path)
|
||||
{
|
||||
char path[96];
|
||||
snprintf(path, sizeof(path), "%s/obs_creds", base_path);
|
||||
|
||||
struct fs_file_t f;
|
||||
fs_file_t_init(&f);
|
||||
|
||||
int rc = fs_open(&f, path, FS_O_READ);
|
||||
if (rc < 0) {
|
||||
LOG_DBG("obs_creds not found (%d) — using defaults", rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t n = fs_read(&f, creds, sizeof(*creds));
|
||||
fs_close(&f);
|
||||
|
||||
if (n != (ssize_t)sizeof(*creds)) {
|
||||
LOG_WRN("obs_creds truncated (%d/%d) — resetting", (int)n,
|
||||
(int)sizeof(*creds));
|
||||
memset(creds, 0, sizeof(*creds));
|
||||
observer_creds_init(creds);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" bool observer_creds_save(const struct ObserverCreds *creds,
|
||||
const char *base_path)
|
||||
{
|
||||
char path[96];
|
||||
snprintf(path, sizeof(path), "%s/obs_creds", base_path);
|
||||
|
||||
struct fs_file_t f;
|
||||
fs_file_t_init(&f);
|
||||
|
||||
int rc = fs_open(&f, path, FS_O_WRITE | FS_O_CREATE | FS_O_TRUNC);
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Cannot open %s for write: %d", path, rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t n = fs_write(&f, creds, sizeof(*creds));
|
||||
fs_close(&f);
|
||||
|
||||
if (n != (ssize_t)sizeof(*creds)) {
|
||||
LOG_ERR("obs_creds write failed (%d/%d)", (int)n,
|
||||
(int)sizeof(*creds));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ========== LED (optional) ========== */
|
||||
|
||||
#if DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
|
||||
|
||||
Reference in New Issue
Block a user