You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 06:23:53 +01:00
Add PS & RT progressive correction
This commit is contained in:
@@ -23,6 +23,8 @@ const rdsparser = {
|
|||||||
free: lib.func('void rdsparser_free(void *rds)'),
|
free: lib.func('void rdsparser_free(void *rds)'),
|
||||||
clear: lib.func('void rdsparser_clear(void *rds)'),
|
clear: lib.func('void rdsparser_clear(void *rds)'),
|
||||||
parse_string: lib.func('bool rdsparser_parse_string(void *rds, const char *input)'),
|
parse_string: lib.func('bool rdsparser_parse_string(void *rds, const char *input)'),
|
||||||
|
set_text_correction: lib.func('bool rdsparser_set_text_correction(void *rds, uint8_t text, uint8_t type, uint8_t error)'),
|
||||||
|
set_text_progressive: lib.func('bool rdsparser_set_text_progressive(void *rds, uint8_t string, bool state)'),
|
||||||
get_pi: lib.func('int32_t rdsparser_get_pi(void *rds)'),
|
get_pi: lib.func('int32_t rdsparser_get_pi(void *rds)'),
|
||||||
get_pty: lib.func('int8_t rdsparser_get_pty(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_tp: lib.func('int8_t rdsparser_get_tp(void *rds)'),
|
||||||
@@ -46,6 +48,7 @@ const rdsparser = {
|
|||||||
register_ptyn: lib.func('void rdsparser_register_ptyn(void *rds, callback_ptyn *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)'),
|
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_content: lib.func(unicode_type + '* rdsparser_string_get_content(void *string)'),
|
||||||
|
string_get_errors: lib.func('uint8_t* rdsparser_string_get_errors(void *string)'),
|
||||||
string_get_length: lib.func('uint8_t rdsparser_string_get_length(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_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_month: lib.func('uint8_t rdsparser_ct_get_month(void *ct)'),
|
||||||
@@ -67,6 +70,13 @@ const decode_unicode = function(string)
|
|||||||
return Buffer.from(array, 'utf-8').toString();
|
return Buffer.from(array, 'utf-8').toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const decode_errors = function(string) {
|
||||||
|
let errors = rdsparser.string_get_errors(string);
|
||||||
|
let length = rdsparser.string_get_length(string);
|
||||||
|
let array = koffi.decode(errors, koffi.array('uint8_t', length));
|
||||||
|
return Uint8Array.from(array).toString();
|
||||||
|
};
|
||||||
|
|
||||||
const callbacks = {
|
const callbacks = {
|
||||||
pi: koffi.register(rds => (
|
pi: koffi.register(rds => (
|
||||||
value = rdsparser.get_pi(rds)
|
value = rdsparser.get_pi(rds)
|
||||||
@@ -110,19 +120,22 @@ const callbacks = {
|
|||||||
), 'callback_country*'),
|
), 'callback_country*'),
|
||||||
|
|
||||||
ps: koffi.register(rds => (
|
ps: koffi.register(rds => (
|
||||||
value = decode_unicode(rdsparser.get_ps(rds)),
|
ps = rdsparser.get_ps(rds),
|
||||||
dataToSend.ps = value
|
dataToSend.ps = decode_unicode(ps),
|
||||||
|
dataToSend.ps_errors = decode_errors(ps)
|
||||||
), 'callback_ps*'),
|
), 'callback_ps*'),
|
||||||
|
|
||||||
rt: koffi.register((rds, flag) => {
|
rt: koffi.register((rds, flag) => {
|
||||||
const value = decode_unicode(rdsparser.get_rt(rds, flag));
|
const rt = rdsparser.get_rt(rds, flag);
|
||||||
|
|
||||||
if (flag === 0) {
|
if (flag === 0) {
|
||||||
dataToSend.rt0 = value;
|
dataToSend.rt0 = decode_unicode(rt);
|
||||||
|
dataToSend.rt0_errors = decode_errors(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag === 1) {
|
if (flag === 1) {
|
||||||
dataToSend.rt1 = value;
|
dataToSend.rt1 = decode_unicode(rt);
|
||||||
|
dataToSend.rt1_errors = decode_errors(rt);
|
||||||
}
|
}
|
||||||
}, 'callback_rt*'),
|
}, 'callback_rt*'),
|
||||||
|
|
||||||
@@ -146,6 +159,12 @@ const callbacks = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let rds = rdsparser.new()
|
let rds = rdsparser.new()
|
||||||
|
rdsparser.set_text_correction(rds, 0, 0, 2);
|
||||||
|
rdsparser.set_text_correction(rds, 0, 1, 2);
|
||||||
|
rdsparser.set_text_correction(rds, 1, 0, 2);
|
||||||
|
rdsparser.set_text_correction(rds, 1, 1, 2);
|
||||||
|
rdsparser.set_text_progressive(rds, 0, true)
|
||||||
|
rdsparser.set_text_progressive(rds, 1, true)
|
||||||
rdsparser.register_pi(rds, callbacks.pi);
|
rdsparser.register_pi(rds, callbacks.pi);
|
||||||
rdsparser.register_pty(rds, callbacks.pty);
|
rdsparser.register_pty(rds, callbacks.pty);
|
||||||
rdsparser.register_tp(rds, callbacks.tp);
|
rdsparser.register_tp(rds, callbacks.tp);
|
||||||
@@ -217,8 +236,10 @@ function handleData(ws, receivedData) {
|
|||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case receivedLine.startsWith('P'):
|
case receivedLine.startsWith('P'):
|
||||||
modifiedData = receivedLine.substring(1, 5);
|
modifiedData = receivedLine.slice(1);
|
||||||
dataToSend.pi = modifiedData;
|
if (dataToSend.pi.length > modifiedData.length || dataToSend.pi == '?') {
|
||||||
|
dataToSend.pi = modifiedData;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case receivedLine.startsWith('T'):
|
case receivedLine.startsWith('T'):
|
||||||
@@ -241,7 +262,7 @@ function handleData(ws, receivedData) {
|
|||||||
dataToSend.st = false;
|
dataToSend.st = false;
|
||||||
|
|
||||||
if (!isNaN(parsedValue)) {
|
if (!isNaN(parsedValue)) {
|
||||||
dataToSend.signal = parsedValue.toFixed(1);
|
dataToSend.signal = parsedValue.toFixed(2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case receivedData.startsWith('Ss'):
|
case receivedData.startsWith('Ss'):
|
||||||
@@ -250,7 +271,7 @@ function handleData(ws, receivedData) {
|
|||||||
dataToSend.st = true;
|
dataToSend.st = true;
|
||||||
|
|
||||||
if (!isNaN(parsedValue)) {
|
if (!isNaN(parsedValue)) {
|
||||||
dataToSend.signal = parsedValue.toFixed(1);
|
dataToSend.signal = parsedValue.toFixed(2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -285,4 +306,4 @@ function showOnlineUsers(currentUsers) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
handleData, showOnlineUsers
|
handleData, showOnlineUsers
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -579,4 +579,8 @@ select option {
|
|||||||
|
|
||||||
select:hover {
|
select:hover {
|
||||||
background: var(--color-5);
|
background: var(--color-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#data-ps, #data-rt0, #data-rt1 {
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|||||||
33
web/main.js
33
web/main.js
@@ -150,6 +150,31 @@ function divideByHundred(a) {
|
|||||||
a = a / 100;
|
a = a / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHTML(unsafeText) {
|
||||||
|
let div = document.createElement('div');
|
||||||
|
div.innerText = unsafeText;
|
||||||
|
return div.innerHTML.replace(' ', ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function processString(string, errors) {
|
||||||
|
var output = '';
|
||||||
|
const max_alpha = 70;
|
||||||
|
const alpha_range = 50;
|
||||||
|
const max_error = 10;
|
||||||
|
errors = errors.split(',');
|
||||||
|
|
||||||
|
for (let i = 0; i < string.length; i++) {
|
||||||
|
alpha = parseInt(errors[i]) * (alpha_range / (max_error + 1));
|
||||||
|
if (alpha) {
|
||||||
|
output += "<span style='opacity: " + (max_alpha - alpha) + "%'>" + escapeHTML(string[i]) + "</span>";
|
||||||
|
} else {
|
||||||
|
output += escapeHTML(string[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
function updatePanels(parsedData) {
|
function updatePanels(parsedData) {
|
||||||
// Assuming sortedAf is your array
|
// Assuming sortedAf is your array
|
||||||
const sortedAf = parsedData.af.sort(compareNumbers);
|
const sortedAf = parsedData.af.sort(compareNumbers);
|
||||||
@@ -189,12 +214,12 @@ function updatePanels(parsedData) {
|
|||||||
listContainer.scrollTop = scrollTop;
|
listContainer.scrollTop = scrollTop;
|
||||||
document.querySelector('#data-frequency').textContent = parsedData.freq;
|
document.querySelector('#data-frequency').textContent = parsedData.freq;
|
||||||
document.querySelector('#data-pi').innerHTML = parsedData.pi === '?' ? "<span class='text-gray'>?</span>" : parsedData.pi;
|
document.querySelector('#data-pi').innerHTML = parsedData.pi === '?' ? "<span class='text-gray'>?</span>" : parsedData.pi;
|
||||||
document.querySelector('#data-ps').innerHTML = parsedData.ps === '?' ? "<span class='text-gray'>?</span>" : parsedData.ps;
|
document.querySelector('#data-ps').innerHTML = parsedData.ps === '?' ? "<span class='text-gray'>?</span>" : processString(parsedData.ps, parsedData.ps_errors);
|
||||||
document.querySelector('#data-tp').innerHTML = parsedData.tp === false ? "<span class='text-gray'>TP</span>" : "TP";
|
document.querySelector('#data-tp').innerHTML = parsedData.tp === false ? "<span class='text-gray'>TP</span>" : "TP";
|
||||||
document.querySelector('#data-pty').innerHTML = europe_programmes[parsedData.pty];
|
document.querySelector('#data-pty').innerHTML = europe_programmes[parsedData.pty];
|
||||||
document.querySelector('#data-st').innerHTML = parsedData.st === false ? "<span class='text-gray'>ST</span>" : "ST";
|
document.querySelector('#data-st').innerHTML = parsedData.st === false ? "<span class='text-gray'>ST</span>" : "ST";
|
||||||
document.querySelector('#data-rt0').innerHTML = parsedData.rt0;
|
document.querySelector('#data-rt0').innerHTML = processString(parsedData.rt0, parsedData.rt0_errors);
|
||||||
document.querySelector('#data-rt1').innerHTML = parsedData.rt1;
|
document.querySelector('#data-rt1').innerHTML = processString(parsedData.rt1, parsedData.rt1_errors);
|
||||||
|
|
||||||
document.querySelector('#data-flag').innerHTML = '<i title="' + parsedData.country_name + '" class="flag-sm flag-sm-' + parsedData.country_iso + '"></i>';
|
document.querySelector('#data-flag').innerHTML = '<i title="' + parsedData.country_name + '" class="flag-sm flag-sm-' + parsedData.country_iso + '"></i>';
|
||||||
|
|
||||||
@@ -378,4 +403,4 @@ async function copyToClipboard(textToCopy) {
|
|||||||
textArea.remove();
|
textArea.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user