time information from rds spy and stop executing in case of error, and also double click to reload

This commit is contained in:
2026-01-02 18:33:18 +01:00
parent 0066252626
commit 3da022a4c2
3 changed files with 70 additions and 14 deletions

View File

@@ -20,6 +20,7 @@ local rtb_display = ""
local lps_display = ""
local current_menu = 1
local menu_extended = false
local pty_rds = {
"None", "News", "Current Affairs",
@@ -496,8 +497,8 @@ local function crc(data)
return crc
end
function render_menu()
out = string.format("Menu %d\r\n------\r\n", current_menu)
local function render_menu()
local out = string.format("Menu %d%s\r\n------\r\n", current_menu, menu_extended and " (extended)" or "")
set_font_size(26)
if current_menu == 1 then
set_font_size(72) -- largest as i can do, this is directly from the public's wants (https://pira.cz/forum/index.php?topic=1124.0)
@@ -532,8 +533,7 @@ function render_menu()
end
out = out .. string.format("ODA: %s\r\n", oda_string:sub(1, #oda_string-2))
elseif current_menu == 4 then
if time_display_offset > 2 then
out = out .. string.format("RDS-System time offset: %d seconds\r\n", time_display_offset)
if time_display_offset > 2 then out = out .. string.format("RDS-System time offset: %d seconds\r\n", time_display_offset)
else out = out .. string.format("RDS-System time offset: ~0\r\n") end
out = out .. string.format("Local time: %s\r\n", time_display_local)
out = out .. string.format("UTC time: %s\r\n", time_display_utc)
@@ -547,7 +547,10 @@ function render_menu()
end
function event(event)
current_menu = event
if event > event_count then menu_extended = true else
menu_extended = false
current_menu = event
end
render_menu()
end
@@ -569,6 +572,9 @@ function command(cmd, param)
db.add_value("PTY.Name", string.format("%s / %s", pty_rds[pty+1], pty_rbds[pty+1]))
db.add_value("ECC", string.format("%X", ecc))
db.add_value("LPS", lps_display)
db.add_value("LocalTime", time_display_local)
db.add_value("UTCTime", time_display_utc)
-- TODO time error
elseif cmd:lower() == "resetdata" then
ert_string = string.rep("_", 128)
rt_a = string.rep("_", 64)
@@ -671,7 +677,14 @@ local function getDayOfWeek(year, month, day)
return ((h + 5) % 7) + 1
end
function group(stream, b_corr, a, b, c, d)
---@param stream integer
---@param b_corr boolean
---@param a integer
---@param b integer
---@param c integer
---@param d integer
---@param time timetable
function group(stream, b_corr, a, b, c, d, time)
if stream ~= 0 and a ~= 0 then return
elseif stream ~= 0 and not db.load_boolean("rdsspy.ini", "General", "Tunnelling", false) then return end
@@ -782,7 +795,6 @@ function group(stream, b_corr, a, b, c, d)
else lps_display = lps:gsub("%s+$", "") end
elseif group_type == 4 and group_version == 0 then
if d < 0 or c < 0 then return end
local system_time = os.time()
local mjd = ((b & 7) << 15) | c >> 1
local year = math.floor((mjd - 15078.2) / 365.25)
local month = math.floor((mjd - 14956.1 - math.floor(year * 365.25)) / 30.6001)
@@ -802,11 +814,12 @@ function group(stream, b_corr, a, b, c, d)
local weekday_table = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
time_display_utc = string.format("%d/%02d/%02d (%s) - %02d:%02d", utc_year, utc_month, utc_day, weekday_table[getDayOfWeek(utc_year, utc_month, utc_day)], utc_hour, utc_minute)
time_display_offset = os.difftime(system_time, epoch+1735689600)
if offset_sign == 0 then epoch = epoch + (offset*1800)
else epoch = epoch - (offset*1800) end
local systemepoch = dateToEpoch(time.year, time.month, time.day) + (time.hour * 3600) + (time.minute * 60) + time.second + (time.centisecond * 0.01)
time_display_offset = math.floor(math.abs(epoch - systemepoch))
local local_year, local_month, local_day, local_hour, local_minute = epochToDate(epoch)
time_display_local = string.format("%d/%02d/%02d (%s) - %02d:%02d", local_year, local_month, local_day, weekday_table[getDayOfWeek(local_year, local_month, local_day)], local_hour, local_minute)
end

View File

@@ -12,7 +12,7 @@ typedef struct {
uint8_t Month;
uint8_t Day;
uint8_t Hour;
uint8_t Minutes;
uint8_t Minute;
uint8_t Second;
uint8_t Centisecond;
uint16_t RFU;
@@ -81,6 +81,7 @@ static const unsigned char EBU[127] = {
};
static unsigned int console_mode = 0;
static unsigned int stop_execution = 0;
const char* int_to_string(int value) {
static char buffer[16];
@@ -113,7 +114,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int offset = 0;
if(HIWORD(wParam) == BN_DOUBLECLICKED) offset = BUTTON_COUNT;
if (controlId == IDC_MAIN_BUTTON) InitLua();
if (controlId == IDC_MAIN_BUTTON && HIWORD(wParam) == BN_DOUBLECLICKED) InitLua();
else if (controlId > IDC_MAIN_BUTTON && controlId <= IDC_MAIN_BUTTON + BUTTON_COUNT) lua_event((controlId - IDC_MAIN_BUTTON) + offset);
}
break;
@@ -156,7 +157,7 @@ void CreatePluginWindow(HWND hOwner) {
HWND hButton = CreateWindowEx(
0, "BUTTON", "Reload",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_NOTIFY,
10, WINDOW_HEIGHT-62,
70, 30, hWnd,
(HMENU)IDC_MAIN_BUTTON, hInst, NULL
@@ -463,6 +464,7 @@ int lua_LoadBoolean(lua_State* localL) {
}
void lua_call_command(const char* Cmd, const char* Param) {
if(stop_execution != 0) return;
lua_getglobal(L, "command");
if (lua_isfunction(L, -1)) {
@@ -473,11 +475,13 @@ void lua_call_command(const char* Cmd, const char* Param) {
snprintf(msg_buffer, sizeof(msg_buffer), "Lua error: %s at '%s'\n", lua_tostring(L, -1), "command");
AppendText(msg_buffer);
lua_pop(L, 1);
stop_execution = 1;
}
} else lua_pop(L, 1);
}
void lua_call_group() {
if(stop_execution != 0) return;
lua_getglobal(L, "group");
if (lua_isfunction(L, -1)) {
@@ -487,16 +491,35 @@ void lua_call_group() {
lua_pushinteger(L, Group.Blk2);
lua_pushinteger(L, Group.Blk3);
lua_pushinteger(L, Group.Blk4);
if (lua_pcall(L, 6, 0, 0) != LUA_OK) {
lua_newtable(L);
lua_pushinteger(L, Group.Year);
lua_setfield(L, -2, "year");
lua_pushinteger(L, Group.Month);
lua_setfield(L, -2, "month");
lua_pushinteger(L, Group.Day);
lua_setfield(L, -2, "day");
lua_pushinteger(L, Group.Hour);
lua_setfield(L, -2, "hour");
lua_pushinteger(L, Group.Minute);
lua_setfield(L, -2, "minute");
lua_pushinteger(L, Group.Second);
lua_setfield(L, -2, "second");
lua_pushinteger(L, Group.Centisecond);
lua_setfield(L, -2, "centisecond");
if (lua_pcall(L, 7, 0, 0) != LUA_OK) {
char msg_buffer[255];
snprintf(msg_buffer, sizeof(msg_buffer), "Lua error: %s at '%s'\r\n", lua_tostring(L, -1), "group");
AppendText(msg_buffer);
lua_pop(L, 1);
stop_execution = 1;
}
} else lua_pop(L, 1);
}
void lua_event(int event) {
if(stop_execution != 0) return;
lua_getglobal(L, "event");
if (lua_isfunction(L, -1)) {
@@ -506,6 +529,7 @@ void lua_event(int event) {
snprintf(msg_buffer, sizeof(msg_buffer), "Lua error: %s at '%s'\r\n", lua_tostring(L, -1), "event");
AppendText(msg_buffer);
lua_pop(L, 1);
stop_execution = 1;
}
} else lua_pop(L, 1);
}
@@ -583,6 +607,9 @@ void InitLua() {
lua_register(L, "set_console", lua_set_console);
lua_register(L, "set_console_mode", lua_set_console_mode);
lua_pushinteger(L, BUTTON_COUNT);
lua_setglobal(L, "event_count");
lua_newtable(L);
lua_pushcfunction(L, lua_ReadValue);
@@ -624,6 +651,7 @@ void InitLua() {
lua_setglobal(L, "db");
console_mode = 0;
stop_execution = 0;
char path[MAX_PATH];
char fullPath[MAX_PATH];
@@ -640,11 +668,13 @@ void InitLua() {
snprintf(msg_buffer, sizeof(msg_buffer), "Lua error loading file: %s\r\n", lua_tostring(L, -1));
AppendText(msg_buffer);
lua_pop(L, 1);
stop_execution = 1;
} else {
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
snprintf(msg_buffer, sizeof(msg_buffer), "Lua error: %s\r\n", lua_tostring(L, -1));
AppendText(msg_buffer);
lua_pop(L, 1);
stop_execution = 1;
}
}
}

View File

@@ -1,11 +1,23 @@
---@meta
---@type integer
event_count = 0
---This function should be defined by the user in the script
---EXIT, CONFIGURE, SHOW, MINIMIZE, RESTORE commands are not sent to the script
---@param cmd string
---@param param string
function command(cmd, param) end
---@class timetable
---@field year integer
---@field month integer
---@field day integer
---@field hour integer
---@field minute integer
---@field second integer
---@field centisecond integer
---This function should be defined by the user in the script
---@param stream integer
---@param block_b_correction boolean
@@ -13,7 +25,8 @@ function command(cmd, param) end
---@param b integer
---@param c integer
---@param d integer
function group(stream, block_b_correction, a, b, c, d) end
---@param time timetable
function group(stream, block_b_correction, a, b, c, d, time) end
---This function should be defined by the user in the script
---@param event integer