mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-31 01:09:18 +02:00
flags
This commit is contained in:
+80
-49
@@ -11,37 +11,52 @@ koffi.proto('void callback_tp(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_ta(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_ms(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_ecc(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_country(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_af(void *rds, uint32_t af, void *user_data)');
|
||||
koffi.proto('void callback_ps(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_rt(void *rds, int flag, void *user_data)');
|
||||
koffi.proto('void callback_ptyn(void *rds, void *user_data)');
|
||||
koffi.proto('void callback_ct(void *rds, void *ct, void *user_data)');
|
||||
|
||||
const rdsparser = {
|
||||
new: lib.func('void* rdsparser_new()'),
|
||||
clear: lib.func('void rdsparser_clear(void *rds)'),
|
||||
free: lib.func('void rdsparser_free(void *rds)'),
|
||||
parse_string: lib.func('bool rdsparser_parse_string(void *rds, const char *input)'),
|
||||
get_pi: lib.func('int32_t rdsparser_get_pi(void *rds)'),
|
||||
get_pty: lib.func('int8_t rdsparser_get_pty(void *rds)'),
|
||||
get_tp: lib.func('int8_t rdsparser_get_tp(void *rds)'),
|
||||
get_ta: lib.func('int8_t rdsparser_get_ta(void *rds)'),
|
||||
get_ms: lib.func('int8_t rdsparser_get_ms(void *rds)'),
|
||||
get_ecc: lib.func('int8_t rdsparser_get_ecc(void *rds)'),
|
||||
get_ps: lib.func('void* rdsparser_get_ps(void *rds)'),
|
||||
get_rt: lib.func('void* rdsparser_get_rt(void *rds, int flag)'),
|
||||
get_ptyn: lib.func('void* rdsparser_get_ptyn(void *rds)'),
|
||||
register_pi: lib.func('void rdsparser_register_pi(void *rds, callback_pi *cb)'),
|
||||
register_pty: lib.func('void rdsparser_register_pty(void *rds, callback_pty *cb)'),
|
||||
register_tp: lib.func('void rdsparser_register_tp(void *rds, callback_tp *cb)'),
|
||||
register_ta: lib.func('void rdsparser_register_ta(void *rds, callback_ta *cb)'),
|
||||
register_ms: lib.func('void rdsparser_register_ms(void *rds, callback_ms *cb)'),
|
||||
register_ecc: lib.func('void rdsparser_register_ecc(void *rds, callback_ecc *cb)'),
|
||||
register_af: lib.func('void rdsparser_register_af(void *rds, callback_af *cb)'),
|
||||
register_ps: lib.func('void rdsparser_register_ps(void *rds, callback_ps *cb)'),
|
||||
register_rt: lib.func('void rdsparser_register_rt(void *rds, callback_rt *cb)'),
|
||||
register_ptyn: lib.func('void rdsparser_register_ptyn(void *rds, callback_ptyn *cb)'),
|
||||
string_get_content: lib.func(unicode_type + '* rdsparser_string_get_content(void *string)'),
|
||||
string_get_length: lib.func('uint8_t rdsparser_string_get_length(void *string)')
|
||||
new: lib.func('void* rdsparser_new()'),
|
||||
free: lib.func('void rdsparser_free(void *rds)'),
|
||||
clear: lib.func('void rdsparser_clear(void *rds)'),
|
||||
parse_string: lib.func('bool rdsparser_parse_string(void *rds, const char *input)'),
|
||||
get_pi: lib.func('int32_t rdsparser_get_pi(void *rds)'),
|
||||
get_pty: lib.func('int8_t rdsparser_get_pty(void *rds)'),
|
||||
get_tp: lib.func('int8_t rdsparser_get_tp(void *rds)'),
|
||||
get_ta: lib.func('int8_t rdsparser_get_ta(void *rds)'),
|
||||
get_ms: lib.func('int8_t rdsparser_get_ms(void *rds)'),
|
||||
get_ecc: lib.func('int16_t rdsparser_get_ecc(void *rds)'),
|
||||
get_country: lib.func('int rdsparser_get_country(void *rds)'),
|
||||
get_ps: lib.func('void* rdsparser_get_ps(void *rds)'),
|
||||
get_rt: lib.func('void* rdsparser_get_rt(void *rds, int flag)'),
|
||||
get_ptyn: lib.func('void* rdsparser_get_ptyn(void *rds)'),
|
||||
register_pi: lib.func('void rdsparser_register_pi(void *rds, callback_pi *cb)'),
|
||||
register_pty: lib.func('void rdsparser_register_pty(void *rds, callback_pty *cb)'),
|
||||
register_tp: lib.func('void rdsparser_register_tp(void *rds, callback_tp *cb)'),
|
||||
register_ta: lib.func('void rdsparser_register_ta(void *rds, callback_ta *cb)'),
|
||||
register_ms: lib.func('void rdsparser_register_ms(void *rds, callback_ms *cb)'),
|
||||
register_ecc: lib.func('void rdsparser_register_ecc(void *rds, callback_ecc *cb)'),
|
||||
register_country: lib.func('void rdsparser_register_country(void *rds, callback_country *cb)'),
|
||||
register_af: lib.func('void rdsparser_register_af(void *rds, callback_af *cb)'),
|
||||
register_ps: lib.func('void rdsparser_register_ps(void *rds, callback_ps *cb)'),
|
||||
register_rt: lib.func('void rdsparser_register_rt(void *rds, callback_rt *cb)'),
|
||||
register_ptyn: lib.func('void rdsparser_register_ptyn(void *rds, callback_ptyn *cb)'),
|
||||
register_ct: lib.func('void rdsparser_register_ct(void *rds, callback_ct *cb)'),
|
||||
string_get_content: lib.func(unicode_type + '* rdsparser_string_get_content(void *string)'),
|
||||
string_get_length: lib.func('uint8_t rdsparser_string_get_length(void *string)'),
|
||||
ct_get_year: lib.func('uint16_t rdsparser_ct_get_year(void *ct)'),
|
||||
ct_get_month: lib.func('uint8_t rdsparser_ct_get_month(void *ct)'),
|
||||
ct_get_day: lib.func('uint8_t rdsparser_ct_get_day(void *ct)'),
|
||||
ct_get_hour: lib.func('uint8_t rdsparser_ct_get_hour(void *ct)'),
|
||||
ct_get_minute: lib.func('uint8_t rdsparser_ct_get_minute(void *ct)'),
|
||||
ct_get_offset: lib.func('int8_t rdsparser_ct_get_offset(void *ct)'),
|
||||
pty_lookup_short: lib.func('const char* rdsparser_pty_lookup_short(int8_t pty, bool rbds)'),
|
||||
pty_lookup_long: lib.func('const char* rdsparser_pty_lookup_long(int8_t pty, bool rbds)'),
|
||||
country_lookup_name: lib.func('const char* rdsparser_country_lookup_name(int country)'),
|
||||
country_lookup_iso: lib.func('const char* rdsparser_country_lookup_iso(int country)')
|
||||
}
|
||||
|
||||
const decode_unicode = function(string)
|
||||
@@ -56,41 +71,48 @@ const callbacks = {
|
||||
pi: koffi.register(rds => (
|
||||
value = rdsparser.get_pi(rds)
|
||||
//console.log('PI: ' + value.toString(16).toUpperCase())
|
||||
), 'callback_pi *'),
|
||||
), 'callback_pi*'),
|
||||
|
||||
pty: koffi.register(rds => (
|
||||
value = rdsparser.get_pty(rds),
|
||||
dataToSend.pty = value
|
||||
), 'callback_pty *'),
|
||||
), 'callback_pty*'),
|
||||
|
||||
tp: koffi.register(rds => (
|
||||
value = rdsparser.get_tp(rds),
|
||||
dataToSend.tp = value
|
||||
), 'callback_tp *'),
|
||||
), 'callback_tp*'),
|
||||
|
||||
ta: koffi.register(rds => (
|
||||
value = rdsparser.get_ta(rds)
|
||||
//console.log('TA: ' + value)
|
||||
), 'callback_ta *'),
|
||||
), 'callback_ta*'),
|
||||
|
||||
ms: koffi.register(rds => (
|
||||
value = rdsparser.get_ms(rds)
|
||||
//console.log('MS: ' + value)
|
||||
), 'callback_ms *'),
|
||||
), 'callback_ms*'),
|
||||
|
||||
af: koffi.register((rds, value) => (
|
||||
dataToSend.af.push(value)
|
||||
), 'callback_af *'),
|
||||
), 'callback_af*'),
|
||||
|
||||
ecc: koffi.register(rds => (
|
||||
value = rdsparser.get_ecc(rds)
|
||||
//console.log('ECC: ' + value.toString(16).toUpperCase())
|
||||
), 'callback_ecc *'),
|
||||
), 'callback_ecc*'),
|
||||
|
||||
country: koffi.register(rds => (
|
||||
value = rdsparser.get_country(rds),
|
||||
display = rdsparser.country_lookup_name(value),
|
||||
iso = rdsparser.country_lookup_iso(value),
|
||||
dataToSend.country_name = display,
|
||||
dataToSend.country_iso = iso
|
||||
), 'callback_country*'),
|
||||
|
||||
ps: koffi.register(rds => (
|
||||
value = decode_unicode(rdsparser.get_ps(rds)),
|
||||
dataToSend.ps = value
|
||||
), 'callback_ps *'),
|
||||
), 'callback_ps*'),
|
||||
|
||||
rt: koffi.register((rds, flag) => {
|
||||
const value = decode_unicode(rdsparser.get_rt(rds, flag));
|
||||
@@ -102,14 +124,26 @@ const callbacks = {
|
||||
if (flag === 1) {
|
||||
dataToSend.rt1 = value;
|
||||
}
|
||||
}, 'callback_rt *'),
|
||||
}, 'callback_rt*'),
|
||||
|
||||
ptyn: koffi.register((rds, flag) => (
|
||||
value = decode_unicode(rdsparser.get_ptyn(rds))
|
||||
/*console.log('PTYN: ' + value)*/
|
||||
), 'callback_ptyn *')
|
||||
};
|
||||
), 'callback_ptyn*'),
|
||||
|
||||
ct: koffi.register((rds, ct) => (
|
||||
year = rdsparser.ct_get_year(ct),
|
||||
month = String(rdsparser.ct_get_month(ct)).padStart(2, '0'),
|
||||
day = String(rdsparser.ct_get_day(ct)).padStart(2, '0'),
|
||||
hour = String(rdsparser.ct_get_hour(ct)).padStart(2, '0'),
|
||||
minute = String(rdsparser.ct_get_minute(ct)).padStart(2, '0'),
|
||||
offset = rdsparser.ct_get_offset(ct),
|
||||
tz_sign = (offset >= 0 ? '+' : '-'),
|
||||
tz_hour = String(Math.abs(Math.floor(offset / 60))).padStart(2, '0'),
|
||||
tz_minute = String(Math.abs(offset % 60)).padStart(2, '0')
|
||||
//console.log('CT: ' + year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ' (' + tz_sign + tz_hour + ':' + tz_minute + ')')
|
||||
), 'callback_ct*')
|
||||
};
|
||||
|
||||
let rds = rdsparser.new()
|
||||
rdsparser.register_pi(rds, callbacks.pi);
|
||||
@@ -118,10 +152,12 @@ rdsparser.register_tp(rds, callbacks.tp);
|
||||
rdsparser.register_ta(rds, callbacks.ta);
|
||||
rdsparser.register_ms(rds, callbacks.ms);
|
||||
rdsparser.register_ecc(rds, callbacks.ecc);
|
||||
rdsparser.register_country(rds, callbacks.country);
|
||||
rdsparser.register_af(rds, callbacks.af);
|
||||
rdsparser.register_ps(rds, callbacks.ps);
|
||||
rdsparser.register_rt(rds, callbacks.rt);
|
||||
rdsparser.register_ptyn(rds, callbacks.ptyn);
|
||||
rdsparser.register_ct(rds, callbacks.ct);
|
||||
|
||||
const updateInterval = 75;
|
||||
const clientUpdateIntervals = new Map(); // Store update intervals for each client
|
||||
@@ -132,14 +168,15 @@ var dataToSend = {
|
||||
freq: 87.500.toFixed(3),
|
||||
signal: 0,
|
||||
st: false,
|
||||
rds: '',
|
||||
ps: '',
|
||||
tp: false,
|
||||
pty: 0,
|
||||
af: [],
|
||||
rt0: '',
|
||||
rt1: '',
|
||||
users: ''
|
||||
country_name: '',
|
||||
country_iso: 'UN',
|
||||
users: '',
|
||||
};
|
||||
|
||||
const initialData = {
|
||||
@@ -147,13 +184,14 @@ const initialData = {
|
||||
freq: 87.500.toFixed(3),
|
||||
signal: 0,
|
||||
st: false,
|
||||
rds: '',
|
||||
ps: '',
|
||||
tp: false,
|
||||
pty: 0,
|
||||
af: [],
|
||||
rt0: '',
|
||||
rt1: '',
|
||||
country_name: '',
|
||||
country_iso: 'UN',
|
||||
users: ''
|
||||
};
|
||||
|
||||
@@ -217,19 +255,13 @@ function handleData(ws, receivedData) {
|
||||
break;
|
||||
|
||||
case receivedLine.startsWith('R'):
|
||||
modifiedData = receivedLine.slice(1, -1).toUpperCase();
|
||||
// Ensure modifiedData is exactly 18 characters long
|
||||
if (modifiedData.length < 18) {
|
||||
modifiedData = modifiedData.padEnd(18, '0'); // Add zeroes at the end
|
||||
} else if (modifiedData.length > 18) {
|
||||
modifiedData = modifiedData.slice(0, 18); // Truncate to 18 characters
|
||||
}
|
||||
modifiedData = receivedLine.slice(1);
|
||||
|
||||
dataToSend.rds = modifiedData;
|
||||
if (rdsBuffer.length > 1000) {
|
||||
rdsBuffer.shift();
|
||||
}
|
||||
rdsBuffer.push(modifiedData);
|
||||
//console.log("\"" + modifiedData + "\",");
|
||||
|
||||
if (rdsBuffer.length > 1) {
|
||||
handleBuffer();
|
||||
@@ -247,7 +279,6 @@ function handleData(ws, receivedData) {
|
||||
}
|
||||
|
||||
function showOnlineUsers(currentUsers) {
|
||||
console.log(currentUsers);
|
||||
dataToSend.users = currentUsers;
|
||||
initialData.users = currentUsers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user