add save option

This commit is contained in:
2025-03-14 22:35:23 +01:00
parent 45b01d6c19
commit 99ea4e242b
4 changed files with 25 additions and 13 deletions
+5 -1
View File
@@ -366,7 +366,11 @@ void process_ascii_cmd(RDSModulator* enc, unsigned char *str) {
unsigned char *cmd, *arg; unsigned char *cmd, *arg;
uint16_t cmd_len = _strnlen((const char*)str, CTL_BUFFER_SIZE); uint16_t cmd_len = _strnlen((const char*)str, CTL_BUFFER_SIZE);
// Process commands with = delimiter at position 2 (format: X=y...) if (str[0] == '*') {
saveToFile(enc->enc);
return;
}
if (cmd_len > 1 && str[1] == '=') { if (cmd_len > 1 && str[1] == '=') {
cmd = str; cmd = str;
cmd[1] = 0; cmd[1] = 0;
+1
View File
@@ -1,4 +1,5 @@
#include "modulator.h" #include "modulator.h"
#include "rds.h"
#define CMD_BUFFER_SIZE 255 #define CMD_BUFFER_SIZE 255
#define CTL_BUFFER_SIZE (CMD_BUFFER_SIZE * 2) #define CTL_BUFFER_SIZE (CMD_BUFFER_SIZE * 2)
#define READ_TIMEOUT_MS 100 #define READ_TIMEOUT_MS 100
+15 -12
View File
@@ -4,8 +4,10 @@
#include "lib.h" #include "lib.h"
#include <time.h> #include <time.h>
void saveToFile(const char *filename, RDSEncoder *emp) { void saveToFile(RDSEncoder *emp) {
FILE *file = fopen(filename, "wb"); char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
FILE *file = fopen(encoderPath, "wb");
if (file == NULL) { if (file == NULL) {
perror("Error opening file"); perror("Error opening file");
return; return;
@@ -14,8 +16,10 @@ void saveToFile(const char *filename, RDSEncoder *emp) {
fclose(file); fclose(file);
} }
void loadFromFile(const char *filename, RDSEncoder *emp) { void loadFromFile(RDSEncoder *emp) {
FILE *file = fopen(filename, "rb"); char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
FILE *file = fopen(encoderPath, "rb");
if (file == NULL) { if (file == NULL) {
perror("Error opening file"); perror("Error opening file");
return; return;
@@ -24,8 +28,10 @@ void loadFromFile(const char *filename, RDSEncoder *emp) {
fclose(file); fclose(file);
} }
int fileExists(const char *filename) { int rdssaved() {
FILE *file = fopen(filename, "rb"); char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
FILE *file = fopen(encoderPath, "rb");
if (file) { if (file) {
fclose(file); fclose(file);
return 1; return 1;
@@ -404,13 +410,10 @@ void init_rds_encoder(RDSEncoder* enc) {
init_rtplus(enc, GROUP_11A); init_rtplus(enc, GROUP_11A);
char encoderPath[256]; if (rdssaved()) {
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME")); loadFromFile(enc);
if (fileExists(encoderPath)) {
loadFromFile(encoderPath, enc);
} else { } else {
saveToFile(encoderPath, enc); saveToFile(enc);
} }
} }
+4
View File
@@ -279,6 +279,10 @@ typedef struct
#define IS_TYPE_B(a) (a[1] & INT16_11) #define IS_TYPE_B(a) (a[1] & INT16_11)
void saveToFile(RDSEncoder *emp);
void loadFromFile(RDSEncoder *emp);
int rdssaved();
void init_rds_encoder(RDSEncoder* enc); void init_rds_encoder(RDSEncoder* enc);
void get_rds_bits(RDSEncoder* enc, uint8_t *bits); void get_rds_bits(RDSEncoder* enc, uint8_t *bits);
void set_rds_rt1(RDSEncoder* enc, unsigned char *rt1); void set_rds_rt1(RDSEncoder* enc, unsigned char *rt1);