0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00

oda_count

This commit is contained in:
2025-12-26 21:48:15 +01:00
parent e579d3a2f1
commit b39a0e78ed
3 changed files with 9 additions and 4 deletions

View File

@@ -9,6 +9,8 @@ eon_count = 0
max_programs = 0
---@type integer
user_data_len = 0
---@type integer
oda_count = 0
---Starts the initialization sequence, also calls the on_init function
---@return nil

View File

@@ -405,7 +405,7 @@ int lua_set_rds_udg2(lua_State *localL) {
int lua_register_oda(lua_State *localL) {
if (!lua_isboolean(localL, 2)) return luaL_error(localL, "boolean expected, got %s", luaL_typename(localL, 2));
uint8_t id = mod->enc->state[mod->enc->program].user_oda.oda_len++;
if(mod->enc->state[mod->enc->program].user_oda.oda_len >= 32) return luaL_error(localL, "There can't be more than 32 registered ODAs");
if(mod->enc->state[mod->enc->program].user_oda.oda_len >= ODAS) return luaL_error(localL, "There can't be more than %d registered ODAs", ODAS);
if(mod->enc->state[mod->enc->program].user_oda.odas[id].group != 0) return luaL_error(localL, "internal error");
mod->enc->state[mod->enc->program].user_oda.odas[id].group = luaL_checkinteger(localL, 1);
switch (mod->enc->state[mod->enc->program].user_oda.odas[id].group) {
@@ -431,7 +431,7 @@ int lua_register_oda(lua_State *localL) {
int lua_set_oda_id_data(lua_State *localL) {
uint8_t idx = luaL_checkinteger(localL, 1);
if(idx >= 32) return luaL_error(localL, "There can't be more than 32 registered ODAs");
if(idx >= ODAS) return luaL_error(localL, "There can't be more than %d registered ODAs", ODAS);
if(mod->enc->state[mod->enc->program].user_oda.odas[idx].group == 0) return luaL_error(localL, "this oda is not registered");
mod->enc->state[mod->enc->program].user_oda.odas[idx].id_data = luaL_checkinteger(localL, 2);
return 0;
@@ -439,7 +439,7 @@ int lua_set_oda_id_data(lua_State *localL) {
int lua_set_oda_handler(lua_State *localL) {
uint8_t idx = luaL_checkinteger(localL, 1);
if(idx >= 32) return luaL_error(localL, "There can't be more than 32 registered ODAs");
if(idx >= ODAS) return luaL_error(localL, "There can't be more than %d registered ODAs", ODAS);
if(mod->enc->state[mod->enc->program].user_oda.odas[idx].group == 0) return luaL_error(localL, "this oda is not registered");
if(mod->enc->state[mod->enc->program].user_oda.odas[idx].group == 3) return luaL_error(localL, "this oda cannot have a handler");
luaL_checktype(localL, 2, LUA_TFUNCTION);
@@ -474,6 +474,8 @@ void init_lua(RDSModulator* rds_mod) {
lua_setglobal(L, "eon_count");
lua_pushinteger(L, LUA_USER_DATA);
lua_setglobal(L, "user_data_len");
lua_pushinteger(L, ODAS);
lua_setglobal(L, "oda_count");
lua_register(L, "set_rds_program_defaults", lua_set_rds_program_defaults);
lua_register(L, "reset_rds", lua_reset_rds);

View File

@@ -1,6 +1,7 @@
#pragma once
#include "common.h"
#define LUA_USER_DATA 1280
#define ODAS 32
/* The RDS error-detection code generator polynomial is
* x^10 + x^8 + x^7 + x^5 + x^4 + x^3 + x^0
@@ -118,7 +119,7 @@ typedef struct {
uint8_t oda_len;
uint8_t oda_pointer;
uint8_t oda_runner_pointer;
RDSODA odas[32];
RDSODA odas[ODAS];
} RDSODAState;
typedef struct {