Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HardwareReport: Added GPS #133

Merged
merged 4 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 116 additions & 2 deletions HardwareReport/HardwareReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ function load_airspeed(log) {
// Load GPS
let gps
const max_num_gps = 2
function load_gps() {
function load_gps(log) {

for (let i = 0; i < max_num_gps; i++) {
let index = String(i+1)
Expand All @@ -1191,9 +1191,122 @@ function load_gps() {
pos: get_param_array(params, pos_names),
node_id: params["GPS_CAN_NODEID" + (i+1)] }
}
continue
}
const new_prefix = "GPS" + (i+1)
const new_type_name = new_prefix + "_TYPE"
if (new_type_name in params) {
// New per-instance params for 4.6+
const type = params[new_type_name]
if (type != 0) {
const pos_names = get_param_name_vector3(new_prefix + "_POS_")
gps[i] = { type: type,
pos: get_param_array(params, pos_names),
node_id: params[new_prefix + "_CAN_NODEID"] }
}
}
}

if ('MSG' in log.messageTypes) {
const messages = log.get("MSG").Message

// 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.
const regex_gps_device = /(?<=as\s)(\S+)/i;
const regex_gps_number = /(?<=GPS\s)(\S)/
for (const message of messages) {
if (message.startsWith("GPS")) {
const num_match = message.match(regex_gps_number)
const device_match = message.match(regex_gps_device)
if ((num_match != null) && (device_match != null)) {
const gps_num = parseInt(num_match[0]) - 1
gps[gps_num].device = device_match[0]
}
}
}
}

function print_gps(inst, gps_info) {
let fieldset = document.createElement("fieldset")

let heading = document.createElement("legend")
heading.innerHTML = "GPS " + (inst+1)
fieldset.appendChild(heading)

// Try and decode the type param
let types = []
types[0] = "None"
types[1] = "AUTO"
types[2] = "uBlox"
types[5] = "NMEA"
types[6] = "SiRF"
types[7] = "HIL"
types[8] = "SwiftNav"
types[9] = "DroneCAN"
types[10] = "SBF"
types[11] = "GSOF"
types[13] = "ERB"
types[14] = "MAV"
types[15] = "NOVA"
types[16] = "HemisphereNMEA"
types[17] = "uBlox-MovingBaseline-Base"
types[18] = "uBlox-MovingBaseline-Rover"
types[19] = "MSP"
types[20] = "AllyStar"
types[21] = "ExternalAHRS"
types[22] = "DroneCAN-MovingBaseline-Base"
types[23] = "DroneCAN-MovingBaseline-Rover"
types[24] = "UnicoreNMEA"
types[25] = "UnicoreMovingBaselineNMEA"
types[26] = "SBF-DualAntenna"

if (types[gps_info.type] != null) {
fieldset.appendChild(document.createTextNode("Type " + gps_info.type + ": " + types[gps_info.type]))
fieldset.appendChild(document.createElement("br"))
}

fieldset.appendChild(document.createTextNode(gps_info.device))
fieldset.appendChild(document.createElement("br"))

// If DroneCAN type we can print the node name
if ((gps_info.type == 9) || (gps_info.type == 22) || (gps_info.type == 23)) {

// Can't tell which bus, so give up if the node ID is found on both
let can_device
let can_count = 0
for (const [driver_num, can_driver] of Object.entries(can)) {
if (gps_info.node_id in can_driver) {
can_device = can_driver[gps_info.node_id][0]
can_count++
}
}

if ((can_device != null) && (can_count == 1)) {
fieldset.appendChild(document.createTextNode("Name: " + can_device.name))
fieldset.appendChild(document.createElement("br"))
}
}

return fieldset
}

let section = document.getElementById("GPS")
let table = document.createElement("table")
section.appendChild(table)

let have_section = false
for (let i = 0; i < gps.length; i++) {
if ((gps[i] != null) && ("device" in gps[i])) {
have_section = true
let colum = document.createElement("td")

colum.appendChild(print_gps(i, gps[i]))
table.appendChild(colum)
}
}

section.previousElementSibling.hidden = !have_section
section.hidden = !have_section
}

// Load Rangefinder
Expand Down Expand Up @@ -1435,7 +1548,7 @@ function load_params(log) {
load_compass(log)
load_baro(log)
load_airspeed(log)
load_gps()
load_gps(log)
load_flow()
load_viso()

Expand Down Expand Up @@ -2431,6 +2544,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 = []
Expand Down
3 changes: 3 additions & 0 deletions HardwareReport/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ <h3 hidden>Compasses</h3>
<h3 hidden>Barometers</h3>
<p id="BARO"></p>

<h3 hidden>GPS</h3>
<p id="GPS"></p>
IamPete1 marked this conversation as resolved.
Show resolved Hide resolved

<h3 hidden>Airspeed Sensors</h3>
<p id="ARSPD"></p>

Expand Down