From 7409edc21fcd455aacc09f8c99ed79709ea2e3d7 Mon Sep 17 00:00:00 2001 From: SantamRC Date: Sat, 13 Apr 2024 02:36:01 +0530 Subject: [PATCH] Updated Code --- HardwareReport/HardwareReport.js | 65 +++++++++++++------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/HardwareReport/HardwareReport.js b/HardwareReport/HardwareReport.js index 345e6db5..2391b7e1 100644 --- a/HardwareReport/HardwareReport.js +++ b/HardwareReport/HardwareReport.js @@ -1166,37 +1166,41 @@ function load_airspeed(log) { } // Load GPS +let gps; const max_num_gps = 2 let num_gps = 0 function load_gps(log) { - let gps = [] - - // for (let i = 0; i < max_num_gps; i++) { - // let index = String(i+1) - // if (i == 0) { - // index = "" - // } - // const type_name = "GPS_TYPE" + index - // if (type_name in params) { - // const type = params[type_name] - // if (type != 0) { - // const pos_names = get_param_name_vector3("GPS_POS" + (i+1) + "_") - // gps[i] = { type: type, - // pos: get_param_array(params, pos_names), - // node_id: params["GPS_CAN_NODEID" + (i+1)] } - // } - // } - // } + let gps_instances = [] + + for (let i = 0; i < max_num_gps; i++) { + let index = String(i + 1) + if (i == 0) { + index = "" + } + const type_name = "GPS_TYPE" + index + if (type_name in params) { + const type = params[type_name] + if (type != 0) { + const pos_names = get_param_name_vector3("GPS_POS" + (i + 1) + "_") + gps[i] = { + type: type, + pos: get_param_array(params, pos_names), + node_id: params["GPS_CAN_NODEID" + (i + 1)] + } + } + } + } let messages = log.get("MSG").Message let section = document.getElementById("GPS") let gps_num = 0 + // This regular expression is used to get the word after "as" to get the GPS device name. (?<=as\s) will exclude the "as" and a whitespace from the regex and then (\S+) will match the next word. let regex = /(?<=as\s)(\S+)/i; for (let i = 0; i < messages.length; i++) { if (messages[i].startsWith("GPS")) { let gps_device = messages[i].match(regex)[0]; - gps[gps_num++] = { gps: gps_device } + gps_instances[gps_num++] = { gps: gps_device } } } @@ -1209,38 +1213,22 @@ function load_gps(log) { heading.innerHTML = "GPS " + inst fieldset.appendChild(heading) - // const id = decode_devid(params.id, DEVICE_TYPE_BARO) - // print_device(fieldset, id) - fieldset.appendChild(document.createTextNode(params.gps)) fieldset.appendChild(document.createElement("br")) - // fieldset.appendChild(document.createElement("br")) - // fieldset.appendChild(document.createTextNode("Wind compensation: " + (params.wind_cmp ? "\u2705" : "\u274C"))) - - // if ("all_healthy" in params) { - // fieldset.appendChild(document.createElement("br")) - // fieldset.appendChild(document.createTextNode("Health: " + (params.all_healthy ? "\u2705" : "\u274C"))) - // } - return fieldset } - // let primary = params["BARO_PRIMARY"] - // section.appendChild(document.createTextNode("Primary: " + (primary+1))) - // section.appendChild(document.createElement("br")) - // section.appendChild(document.createElement("br")) - let table = document.createElement("table") section.appendChild(table) let have_section = false - for (let i = 0; i < gps.length; i++) { - if (gps[i] != null) { + for (let i = 0; i < gps_instances.length; i++) { + if (gps_instances[i] != null) { have_section = true let colum = document.createElement("td") - colum.appendChild(print_gps(i + 1, gps[i])) + colum.appendChild(print_gps(i + 1, gps_instances[i])) table.appendChild(colum) } } @@ -2384,6 +2372,7 @@ function reset() { setup_section(document.getElementById("DroneCAN")) setup_section(document.getElementById("WAYPOINTS")) setup_section(document.getElementById("FILES")) + setup_section(document.getElementById("GPS")) ins = [] compass = []