mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-27 12:53:53 +01:00
make save file smaller
This commit is contained in:
33
src/rds.c
33
src/rds.c
@@ -112,16 +112,29 @@ void saveToFile(RDSEncoder *emp, const char *option) {
|
|||||||
tempEncoder.program = emp->program;
|
tempEncoder.program = emp->program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RDSEncoderFile rdsEncoderfile;
|
||||||
|
rdsEncoderfile.file_starter = 225;
|
||||||
|
rdsEncoderfile.file_middle = 160;
|
||||||
|
rdsEncoderfile.file_ender = 95;
|
||||||
|
memcpy(&(rdsEncoderfile.data[emp->program]), &(tempEncoder.data[emp->program]), sizeof(RDSData));
|
||||||
|
memcpy(&(rdsEncoderfile.rtpData[emp->program]), &(tempEncoder.rtpData[emp->program]), sizeof(RDSRTPlusData));
|
||||||
|
memcpy(&(rdsEncoderfile.odas[emp->program]), &(tempEncoder.odas[emp->program]), sizeof(RDSODA)*MAX_ODAS);
|
||||||
|
memcpy(&(rdsEncoderfile.oda_state[emp->program]), &(tempEncoder.oda_state[emp->program]), sizeof(RDSODAState));
|
||||||
|
memcpy(&(rdsEncoderfile.encoder_data[emp->program]), &(tempEncoder.encoder_data[emp->program]), sizeof(RDSODAState));
|
||||||
|
rdsEncoderfile.program = tempEncoder.program;
|
||||||
|
|
||||||
file = fopen(encoderPath, "wb");
|
file = fopen(encoderPath, "wb");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("Error opening file");
|
perror("Error opening file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fwrite(&tempEncoder, sizeof(RDSEncoder), 1, file);
|
fwrite(&RDSEncoderFile, sizeof(RDSEncoderFile), 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadFromFile(RDSEncoder *emp) {
|
void loadFromFile(RDSEncoder *enc) {
|
||||||
|
RDSEncoderFile rdsEncoderfile;
|
||||||
|
|
||||||
char encoderPath[256];
|
char encoderPath[256];
|
||||||
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
|
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
|
||||||
FILE *file = fopen(encoderPath, "rb");
|
FILE *file = fopen(encoderPath, "rb");
|
||||||
@@ -129,8 +142,22 @@ void loadFromFile(RDSEncoder *emp) {
|
|||||||
perror("Error opening file");
|
perror("Error opening file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fread(emp, sizeof(RDSEncoder), 1, file);
|
fread(&rdsEncoderfile, sizeof(RDSEncoderFile), 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
|
if (rdsEncoderfile.file_starter != 225 || rdsEncoderfile.file_ender != 95 || rdsEncoderfile.file_middle != 160) {
|
||||||
|
fprintf(stderr, "Invalid file format\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < PROGRAMS; i++) {
|
||||||
|
memcpy(&(enc->data[i]), &(rdsEncoderfile.data[i]), sizeof(RDSData));
|
||||||
|
memcpy(&(enc->rtpData[i]), &(rdsEncoderfile.rtpData[i]), sizeof(RDSRTPlusData));
|
||||||
|
memcpy(&(enc->odas[i]), &(rdsEncoderfile.odas[i]), sizeof(RDSODA) * MAX_ODAS);
|
||||||
|
memcpy(&(enc->oda_state[i]), &(rdsEncoderfile.oda_state[i]), sizeof(RDSODAState));
|
||||||
|
memcpy(&(enc->encoder_data[i]), &(rdsEncoderfile.encoder_data[i]), sizeof(RDSODAState));
|
||||||
|
}
|
||||||
|
enc->program = rdsEncoderfile.program;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rdssaved() {
|
int rdssaved() {
|
||||||
|
|||||||
32
src/rds.h
32
src/rds.h
@@ -42,37 +42,37 @@ typedef struct {
|
|||||||
uint8_t afs[MAX_AFS];
|
uint8_t afs[MAX_AFS];
|
||||||
} RDSAFs;
|
} RDSAFs;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t enabled : 1;
|
|
||||||
uint16_t pi;
|
uint16_t pi;
|
||||||
uint8_t pin[4];
|
uint8_t enabled : 1;
|
||||||
char ps[8];
|
|
||||||
uint8_t ta : 1;
|
uint8_t ta : 1;
|
||||||
uint8_t tp : 1;
|
uint8_t tp : 1;
|
||||||
|
uint8_t pin[4];
|
||||||
|
char ps[8];
|
||||||
RDSAFs af;
|
RDSAFs af;
|
||||||
} RDSEONs;
|
} RDSEONs;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char text[255];
|
|
||||||
uint8_t destination : 4;
|
uint8_t destination : 4;
|
||||||
|
char text[255];
|
||||||
} RDSMessage;
|
} RDSMessage;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
RDSMessage messages[100];
|
|
||||||
uint8_t dps2msg : 7;
|
uint8_t dps2msg : 7;
|
||||||
uint8_t dps2msg_auto : 1;
|
uint8_t dps2msg_auto : 1;
|
||||||
uint8_t rt2msg : 7;
|
uint8_t rt2msg : 7;
|
||||||
uint8_t rt2msg_auto : 1;
|
uint8_t rt2msg_auto : 1;
|
||||||
|
RDSMessage messages[100];
|
||||||
} RDSMessages;
|
} RDSMessages;
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char command[35];
|
|
||||||
uint8_t days : 7; // let's say that here it will be stored by bits, so 0b1000000 is monday and so on
|
uint8_t days : 7; // let's say that here it will be stored by bits, so 0b1000000 is monday and so on
|
||||||
uint8_t pty: 5;
|
uint8_t pty: 5;
|
||||||
uint16_t execution_hours[12];
|
uint16_t execution_hours[12];
|
||||||
uint16_t execution_minutes[12];
|
uint16_t execution_minutes[12];
|
||||||
|
char command[35];
|
||||||
} RDSSchedulerItem;
|
} RDSSchedulerItem;
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
RDSSchedulerItem items[49];
|
|
||||||
uint8_t enabled : 1;
|
uint8_t enabled : 1;
|
||||||
|
RDSSchedulerItem items[49];
|
||||||
} RDSScheduler;
|
} RDSScheduler;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t dsn;
|
uint8_t dsn;
|
||||||
@@ -105,10 +105,10 @@ typedef struct {
|
|||||||
uint8_t dps1_numberofrepeats : 7;
|
uint8_t dps1_numberofrepeats : 7;
|
||||||
uint8_t dps1_numberofrepeats_clear : 1;
|
uint8_t dps1_numberofrepeats_clear : 1;
|
||||||
uint8_t dps2_numberofrepeats;
|
uint8_t dps2_numberofrepeats;
|
||||||
uint8_t dps_label_period; // One transmission of a part of the dynamic ps
|
uint8_t dps_label_period;
|
||||||
uint8_t dps_restart : 1;
|
uint8_t dps_restart : 1;
|
||||||
uint8_t dps_speed : 1; // Low is 8 transmissions, high is 4
|
uint8_t dps_speed : 1;
|
||||||
uint8_t static_ps_period; // One Transmission of static ps
|
uint8_t static_ps_period;
|
||||||
|
|
||||||
uint8_t shortrt : 1;
|
uint8_t shortrt : 1;
|
||||||
uint8_t rt1_enabled : 1;
|
uint8_t rt1_enabled : 1;
|
||||||
@@ -224,6 +224,18 @@ typedef struct {
|
|||||||
RDSRTPlusData rtpData[PROGRAMS];
|
RDSRTPlusData rtpData[PROGRAMS];
|
||||||
uint8_t program : 3;
|
uint8_t program : 3;
|
||||||
} RDSEncoder;
|
} RDSEncoder;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t file_starter; // Always is 225 first polish radio programme am frequency
|
||||||
|
RDSData data[PROGRAMS];
|
||||||
|
RDSRTPlusData rtpData[PROGRAMS];
|
||||||
|
RDSODA odas[PROGRAMS][MAX_ODAS];
|
||||||
|
uint8_t file_middle; // Always is 160, average of both
|
||||||
|
RDSODAState oda_state[PROGRAMS];
|
||||||
|
RDSEncoderData encoder_data[PROGRAMS];
|
||||||
|
uint8_t program : 3;
|
||||||
|
uint8_t file_ender; // Always is 95 my freq
|
||||||
|
} RDSEncoderFile;
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
#define GROUP_TYPE_0 ( 0 << 4)
|
#define GROUP_TYPE_0 ( 0 << 4)
|
||||||
|
|||||||
Reference in New Issue
Block a user