Last active
September 22, 2023 09:37
-
-
Save system1357/1598673b3dfe81b831660150b1f7f57a to your computer and use it in GitHub Desktop.
RDS Group 4 CT(time) generation script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
uint16_t blocks[3]; | |
void main(){ | |
// Check time | |
time_t now; | |
struct tm *utc; | |
now = time(NULL); | |
utc = gmtime (&now); | |
// Generate CT group | |
int l = utc->tm_mon <= 1 ? 1 : 0; | |
int mjd = 14956 + utc->tm_mday + | |
(int)((utc->tm_year - l) * 365.25) + | |
(int)((utc->tm_mon + 2 + l*12) * 30.6001); | |
// 0x4400 means TP(Traffic Program) bit is set to on | |
// If you don't want this, change to 0x4000 | |
// PTY can also be calculated, but it's irrelevant in group 4 data | |
blocks[0] = 0x4400 | (mjd>>15); | |
blocks[1] = (mjd<<1) | (utc->tm_hour>>4); | |
blocks[2] = (utc->tm_hour & 0xF)<<12 | utc->tm_min<<6; | |
utc = localtime(&now); | |
//Beware that RDS timezone offset is calculated per half an hour | |
int offset = utc->tm_gmtoff / (30 * 60); | |
blocks[2] |= abs(offset); | |
if(offset < 0) blocks[2] |= 0x20; | |
printf("Generated CT: %04X %04X %04X\n", blocks[0], blocks[1], blocks[2]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment