tracking down a parsing error
This commit is contained in:
parent
b813294ea5
commit
f07264a138
|
@ -21,11 +21,12 @@ wasm-bindgen = "0.2.84"
|
|||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||
# code size when deploying.
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
nexrad2 = { version = "0.1.0", path = "../nexrad2" }
|
||||
nexrad2 = { version = "0.1.0", path = "../nexrad2", default-features = false, features = ["bzip-impl-bzip2-rs", "serde_derive"] }
|
||||
log = "0.4"
|
||||
web-sys = "0.3"
|
||||
js-sys = "0.3"
|
||||
wasm-logger = "0.2"
|
||||
serde-wasm-bindgen = "0.6"
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.34"
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::io::Cursor;
|
|||
use js_sys::Uint8Array;
|
||||
use log::info;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use nexrad2::Nexrad2Chunk;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
|
@ -12,13 +13,13 @@ extern "C" {
|
|||
|
||||
#[wasm_bindgen]
|
||||
pub fn __nxrd_browser_init() {
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
utils::set_panic_hook();
|
||||
info!("nexrad-browser initialized successfully");
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn load_ar2(buf: &JsValue) {
|
||||
pub fn load_ar2(buf: &JsValue) -> JsValue {
|
||||
|
||||
info!("loading archive 2 file");
|
||||
info!("load 01: convert to uint8array");
|
||||
|
@ -31,4 +32,5 @@ pub fn load_ar2(buf: &JsValue) {
|
|||
let loaded = nexrad2::parse_nx2_chunk(&mut cursor).unwrap();
|
||||
info!("load 05: dump");
|
||||
info!("Loaded: {:#?}", loaded);
|
||||
serde_wasm_bindgen::to_value(&loaded).unwrap()
|
||||
}
|
|
@ -20,6 +20,8 @@
|
|||
Something went wrong while loading the canvas. Sorry :/
|
||||
</canvas>
|
||||
|
||||
<input type="file" id="file" style="display: none;" />
|
||||
|
||||
<script src="bootstrap.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -105,30 +105,135 @@ function zulu() {
|
|||
let command_buf = "";
|
||||
let buf_response_mode = false;
|
||||
|
||||
function exec() {
|
||||
let radar_inoperative = true;
|
||||
let site_string = "SITE INFORMATION UNAVAILABLE";
|
||||
let icao = "INOP";
|
||||
|
||||
let selected_mode = "INOP";
|
||||
|
||||
let delay_string = "DELAY UNAVAILABLE";
|
||||
|
||||
let display_buf = [];
|
||||
|
||||
function recalcDisplayBuf() {
|
||||
display_buf = [];
|
||||
let line = 0;
|
||||
for (let i = 0; i < command_buf.length; i++) {
|
||||
let char = command_buf[i];
|
||||
if (char === "\n") { line += 1; continue; }
|
||||
if (display_buf.length < line+1) { display_buf[line] = ""; }
|
||||
display_buf[line] += char;
|
||||
}
|
||||
}
|
||||
|
||||
function cmd_err(err) {
|
||||
buf_response_mode = true;
|
||||
command_buf = err;
|
||||
recalcDisplayBuf();
|
||||
}
|
||||
|
||||
let ar2 = undefined;
|
||||
|
||||
async function load() {
|
||||
const file = document.getElementById("file").files[0];
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('load', (event) => {
|
||||
let data = event.target.result;
|
||||
let loaded = wasm.load_ar2(data);
|
||||
console.log(loaded);
|
||||
cmd_err("");
|
||||
|
||||
ar2 = loaded;
|
||||
});
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
function exec(command) {
|
||||
console.log("exec1!");
|
||||
}
|
||||
|
||||
document.onkeyup = (e) => {
|
||||
if (e.key.toUpperCase() === "ESCAPE") {
|
||||
command_buf = "";
|
||||
} else if (e.key.toUpperCase() === "ENTER") {
|
||||
command_buf = "";
|
||||
exec();
|
||||
} else if (e.key.toUpperCase() === "BACKSPACE") {
|
||||
command_buf = command_buf.slice(0, command_buf.length-1);
|
||||
exec();
|
||||
let tokens = command.split(" ");
|
||||
|
||||
if (tokens[0] === "MODE" && tokens[1] === "SET") {
|
||||
let mode = tokens[2];
|
||||
let valid_modes = ["REF", "VEL", "SW", "ZDR", "PHI", "RHO", "CFP"];
|
||||
if (!valid_modes.includes(mode)) {
|
||||
cmd_err("INVALID MODE");
|
||||
return;
|
||||
} else if (radar_inoperative) {
|
||||
cmd_err("RADAR INOPERATIVE\nCANNOT SET MODE");
|
||||
return;
|
||||
} else {
|
||||
if (e.key.length !== 1) { return; }
|
||||
if (buf_response_mode) {
|
||||
buf_response_mode = false;
|
||||
command_buf = "";
|
||||
selected_mode = mode;
|
||||
return;
|
||||
}
|
||||
command_buf += e.key.toUpperCase();
|
||||
}
|
||||
|
||||
if (tokens[0] === "CLF" && tokens[1] === "OV") {
|
||||
document.getElementById("file").click();
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokens[0] === "CLF" && tokens[1] === "RELOAD") {
|
||||
// TRIGGER RELOAD
|
||||
cmd_err("SYSTEM PROCESSING");
|
||||
load();
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "TEST UNSET INOP") {
|
||||
radar_inoperative = false;
|
||||
icao = "TEST";
|
||||
site_string = "TEST VCP 000 TEST AIR MODE";
|
||||
selected_mode = "REF";
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "TEST INVALID COMMAND") {
|
||||
cmd_err("TEST SUCCESSFUL");
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_err("UNRECOGNIZED COMMAND");
|
||||
}
|
||||
|
||||
function shouldNewline() {
|
||||
if (command_buf.startsWith("MODE SET")) { return true; }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
let ar2_date = undefined;
|
||||
|
||||
function convertDate() {
|
||||
if (ar2 !== undefined) {
|
||||
let unix_timestamp_millis = 86400000 * ar2.volume_header_record.date + ar2.volume_header_record.time;
|
||||
ar2_date = new Date(unix_timestamp_millis);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
function reRender() {
|
||||
if (ar2 !== undefined) {
|
||||
radar_inoperative = false;
|
||||
icao = ar2.volume_header_record.icao;
|
||||
site_string = `${icao} VCP INFORMATION UNAVAILABLE`;
|
||||
selected_mode = "REF";
|
||||
} else {
|
||||
radar_inoperative = true;
|
||||
icao = "INOP";
|
||||
site_string = "SITE INFORMATION UNAVAILABLE";
|
||||
selected_mode = "INOP";
|
||||
}
|
||||
|
||||
convertDate();
|
||||
if (ar2_date !== undefined) {
|
||||
const delay = Date.now() - ar2_date;
|
||||
const SEC = 1000, MIN = 60 * SEC, HRS = 60 * MIN;
|
||||
const humanDiff = `${Math.floor(delay/HRS)}:${Math.floor((delay%HRS)/MIN).toLocaleString('en-US', {minimumIntegerDigits: 2})}:${Math.floor((delay%MIN)/SEC).toLocaleString('en-US', {minimumIntegerDigits: 2})}`;
|
||||
delay_string = "SITE DELAY " + humanDiff;
|
||||
}
|
||||
|
||||
//document.getElementById("input-detection").focus();
|
||||
rescaleCanvas(canvas, ctx);
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
@ -146,28 +251,114 @@ setInterval(() => {
|
|||
|
||||
ctx.font = get_font_size();
|
||||
ctx.fillStyle = green;
|
||||
ctx.fillText(`NEXRAD KLSX ${zulu()}`, x0 + 50, y0 + 50);
|
||||
ctx.fillText(`NEXRAD ${icao} ${zulu()}`, x0 + 50, y0 + 50);
|
||||
|
||||
if (radar_inoperative) {
|
||||
ctx.fillStyle = blinkyColor;
|
||||
ctx.fillText("RADR INOP NO DATA LOADED", x0 + 50, y0 + 50 + preferences.FCS);
|
||||
ctx.fillStyle = green;
|
||||
}
|
||||
|
||||
ctx.textAlign = "right";
|
||||
ctx.fillText("RADAR SITE", xfull - 75, y0 + 50);
|
||||
ctx.fillText("KLSX VCP35 Clear Air Mode", xfull - 75, y0 + 50 + preferences.FCS);
|
||||
ctx.fillText(`${site_string}`, xfull - 75, y0 + 50 + preferences.FCS);
|
||||
ctx.fillText(`${delay_string}`, xfull - 75, y0 + 50 + preferences.FCS * 2);
|
||||
|
||||
ctx.fillText("MODE", xfull - 75, y0 + canvas.height / 3);
|
||||
ctx.fillText(" REF VEL SW ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
ctx.fillText(" ZDR PHI RHO ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS * 2);
|
||||
ctx.fillText(" CFP ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS * 3);
|
||||
|
||||
// this hurts me physically
|
||||
|
||||
if (selected_mode === "REF") {
|
||||
ctx.fillStyle = white;
|
||||
|
||||
ctx.fillText(" >RADR INOP<", xfull - 75, y0 + canvas.height / 3 + preferences.FCS * 3);
|
||||
|
||||
ctx.fillText(">REF< ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" REF ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
}
|
||||
|
||||
if (selected_mode === "VEL") {
|
||||
ctx.fillStyle = white;
|
||||
ctx.fillText(" >VEL< ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" VEL ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
}
|
||||
|
||||
if (selected_mode === "SW") {
|
||||
ctx.fillStyle = white;
|
||||
ctx.fillText(" >SW <", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" SW ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS);
|
||||
}
|
||||
|
||||
if (selected_mode === "ZDR") {
|
||||
ctx.fillStyle = white;
|
||||
ctx.fillText(">ZDR< ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*2);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" ZDR ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*2);
|
||||
}
|
||||
|
||||
if (selected_mode === "PHI") {
|
||||
ctx.fillStyle = white;
|
||||
ctx.fillText(" >PHI< ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*2);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" PHI ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*2);
|
||||
}
|
||||
|
||||
if (selected_mode === "RHO") {
|
||||
ctx.fillStyle = white;
|
||||
ctx.fillText(" >RHO<", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*2);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" RHO ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*2);
|
||||
}
|
||||
|
||||
if (selected_mode === "CFP") {
|
||||
ctx.fillStyle = white;
|
||||
ctx.fillText(" >CFP< ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*3);
|
||||
ctx.fillStyle = green;
|
||||
} else {
|
||||
ctx.fillText(" CFP ", xfull - 75, y0 + canvas.height / 3 + preferences.FCS*3);
|
||||
}
|
||||
|
||||
if (radar_inoperative) {
|
||||
ctx.fillStyle = red;
|
||||
ctx.fillText(" >RADR INOP<", xfull - 75, y0 + canvas.height / 3 + preferences.FCS * 3);
|
||||
ctx.fillStyle = green;
|
||||
}
|
||||
|
||||
|
||||
ctx.textAlign = "left";
|
||||
|
||||
ctx.fillText(command_buf, x0 + 50, y0 + canvas.height / 2);
|
||||
}, 10);
|
||||
for (let line = 0; line < display_buf.length; line++) {
|
||||
ctx.fillText(display_buf[line], x0 + 50, y0 + canvas.height / 2 + (preferences.FCS * line));
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(reRender, 10);
|
||||
|
||||
document.onkeyup = (e) => {
|
||||
if (e.key.toUpperCase() === "ESCAPE") {
|
||||
command_buf = "";
|
||||
} else if (e.key.toUpperCase() === "ENTER") {
|
||||
let command = command_buf.replace("\n", " ");
|
||||
command_buf = "";
|
||||
exec(command);
|
||||
} else if (e.key.toUpperCase() === "BACKSPACE") {
|
||||
command_buf = command_buf.slice(0, command_buf.length - 1);
|
||||
} else if (e.key.toUpperCase() === " " && shouldNewline()) {
|
||||
command_buf += "\n";
|
||||
} else {
|
||||
if (e.key.length !== 1) { return; }
|
||||
if (buf_response_mode) {
|
||||
buf_response_mode = false;
|
||||
command_buf = "";
|
||||
}
|
||||
command_buf += e.key.toUpperCase();
|
||||
}
|
||||
recalcDisplayBuf();
|
||||
reRender();
|
||||
}
|
|
@ -9,10 +9,11 @@ edition = "2021"
|
|||
|
||||
bzip2-rs = { version = "0.1", optional = true }
|
||||
bzip2 = { version = "0.4", optional = true }
|
||||
serde = { version = "1", features = ["derive"], optional = true }
|
||||
|
||||
log = "0.4"
|
||||
|
||||
[features]
|
||||
default = ["bzip-impl-bzip2-rs"]
|
||||
bzip-impl-libbzip2 = ["bzip2"]
|
||||
bzip-impl-bzip2-rs = ["bzip2-rs"]
|
||||
serde_derive = ["serde"]
|
|
@ -16,12 +16,14 @@ pub mod bzip;
|
|||
pub mod message2;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Nexrad2Chunk {
|
||||
pub volume_header_record: VolumeHeaderRecord,
|
||||
pub chunks: Vec<Vec<Message>>
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
/// The Volume Header Record as defined by 2620010H (Build 19.0) section 7.3.3 Volume Header Record
|
||||
pub struct VolumeHeaderRecord {
|
||||
/// A character constant of which the last 2 characters identify the version.
|
||||
|
@ -168,23 +170,20 @@ pub fn parse_nx2_chunk(cursor: &mut (impl Read + Seek)) -> Result<Nexrad2Chunk,
|
|||
message_segment_num: u16::from_be_bytes(message_header[14..].try_into().unwrap()),
|
||||
};
|
||||
|
||||
if message_header.message_type == 0 {
|
||||
debug!("Reached EOF on chunk");
|
||||
break;
|
||||
}
|
||||
|
||||
debug!("Message: {:#?}", message_header);
|
||||
|
||||
let mut body_buf = vec![0u8; MESSAGE_BODY_SIZE];
|
||||
|
||||
decompressed.read_exact(&mut body_buf).map_err(|e| NexradParseError::TcmChunkReadFailed(e))?;
|
||||
|
||||
if message_header.message_type == 0 { trace!("extra segment message"); continue; }
|
||||
|
||||
trace!("Message: {:#?}", message_header);
|
||||
|
||||
let message = match message_header.message_type {
|
||||
2 => {
|
||||
Message::Msg02(Msg02RDAStatusData::from_body(body_buf[0..68].try_into().unwrap())?)
|
||||
},
|
||||
unknown => {
|
||||
warn!("unrecognized message type {}", unknown);
|
||||
trace!("unrecognized message type {}", unknown);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
@ -192,7 +191,7 @@ pub fn parse_nx2_chunk(cursor: &mut (impl Read + Seek)) -> Result<Nexrad2Chunk,
|
|||
messages.push(message);
|
||||
}
|
||||
|
||||
debug!("{} messages loaded from chunk", messages.len());
|
||||
trace!("{} messages loaded from chunk", messages.len());
|
||||
|
||||
records.push(messages);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ pub const DEFAULT_MESSAGE_SIZE: usize = 2432;
|
|||
pub const MESSAGE_BODY_SIZE: usize = DEFAULT_MESSAGE_SIZE - LEGACY_CTM_HEADER_LEN - MESSAGE_HEADER_SIZE;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct MessageHeader {
|
||||
pub message_size: u16,
|
||||
pub rda_redundant_channel: u8,
|
||||
|
@ -31,6 +32,7 @@ pub trait FromBody<const BODY_SIZE: usize> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Message {
|
||||
Msg02(Msg02RDAStatusData)
|
||||
}
|
|
@ -4,6 +4,7 @@ use crate::NexradParseError;
|
|||
pub const MSG_RDA_STATUS_DATA: u8 = 2;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Msg02RDAStatusData {
|
||||
rda_status: u16,
|
||||
operability_status: u16,
|
||||
|
|
|
@ -7,4 +7,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
simple_logger = "4"
|
||||
nexrad2 = { version = "0.1", path = "../nexrad2" }
|
||||
nexrad2 = { version = "0.1", path = "../nexrad2", default-features = false, features = ["bzip-impl-libbzip2"] }
|
Loading…
Reference in New Issue