0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-27 04:43:52 +01:00

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

View File

@@ -366,7 +366,11 @@ void process_ascii_cmd(RDSModulator* enc, unsigned char *str) {
unsigned char *cmd, *arg;
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] == '=') {
cmd = str;
cmd[1] = 0;

View File

@@ -1,4 +1,5 @@
#include "modulator.h"
#include "rds.h"
#define CMD_BUFFER_SIZE 255
#define CTL_BUFFER_SIZE (CMD_BUFFER_SIZE * 2)
#define READ_TIMEOUT_MS 100

View File

@@ -4,8 +4,10 @@
#include "lib.h"
#include <time.h>
void saveToFile(const char *filename, RDSEncoder *emp) {
FILE *file = fopen(filename, "wb");
void saveToFile(RDSEncoder *emp) {
char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
FILE *file = fopen(encoderPath, "wb");
if (file == NULL) {
perror("Error opening file");
return;
@@ -14,8 +16,10 @@ void saveToFile(const char *filename, RDSEncoder *emp) {
fclose(file);
}
void loadFromFile(const char *filename, RDSEncoder *emp) {
FILE *file = fopen(filename, "rb");
void loadFromFile(RDSEncoder *emp) {
char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
FILE *file = fopen(encoderPath, "rb");
if (file == NULL) {
perror("Error opening file");
return;
@@ -24,8 +28,10 @@ void loadFromFile(const char *filename, RDSEncoder *emp) {
fclose(file);
}
int fileExists(const char *filename) {
FILE *file = fopen(filename, "rb");
int rdssaved() {
char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
FILE *file = fopen(encoderPath, "rb");
if (file) {
fclose(file);
return 1;
@@ -404,13 +410,10 @@ void init_rds_encoder(RDSEncoder* enc) {
init_rtplus(enc, GROUP_11A);
char encoderPath[256];
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
if (fileExists(encoderPath)) {
loadFromFile(encoderPath, enc);
if (rdssaved()) {
loadFromFile(enc);
} else {
saveToFile(encoderPath, enc);
saveToFile(enc);
}
}

View File

@@ -279,6 +279,10 @@ typedef struct
#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 get_rds_bits(RDSEncoder* enc, uint8_t *bits);
void set_rds_rt1(RDSEncoder* enc, unsigned char *rt1);