Skip to content

Commit

Permalink
Fix invalid model reference in CAN bus stats and remove translations
Browse files Browse the repository at this point in the history
Should refer to 'textModel' not 'model'.

Translations aren't needed as this page is just for debugging.
  • Loading branch information
blammit committed Jul 20, 2023
1 parent 8974358 commit a3de9d6
Showing 1 changed file with 25 additions and 79 deletions.
104 changes: 25 additions & 79 deletions pages/settings/PageCanbusStatus.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,12 @@ Page {

property string gateway: "can0"

function _packetsText(packets) {
//: %1 = number of packets transferred
//% "Packets: %1"
return qsTrId("settings_canbus_packets").arg(packets)
}

function _droppedPacketsText(dropped, total) {
if (total) {
//: %1 = number of dropped packets, %2 = percentage of packets that were dropped
//% "Dropped: %1 (%2%)"
return qsTrId("settings_canbus_dropped_packets_percentage").arg(dropped).arg(_percentage(dropped, total))
}
//: %1 = number of dropped packets
//% "Dropped: %1"
return qsTrId("settings_canbus_dropped_packets").arg(dropped)
}

function _overrunsText(overruns, total) {
if (total) {
//: %1 = number of overrun errors, %2 = percentage of packets with overrun errors
//% "Overruns: %1 (%2%)"
return qsTrId("settings_canbus_overruns_percentage").arg(overruns).arg(_percentage(overruns, total))
}
//: %1 = number of overrun errors
//% "Overruns: %1"
return qsTrId("settings_canbus_overruns").arg(overruns)
}

function _errorsText(errors, total) {
if (total) {
//: %1 = number of errors, %2 = percentage of packets with errors
//% "Errors: %1 (%2%)"
return qsTrId("settings_canbus_errors_percentage").arg(errors).arg(_percentage(errors, total))
}
//: %1 = number of errors
//% "Errors: %1"
return qsTrId("settings_canbus_errors").arg(errors)
}

function _percentage(count, total) {
if (!total) {
return ""
}
let perc = count / total * 100
return perc.toFixed(2)
return " (" + perc.toFixed(2) + "%)"
}

Timer {
Expand Down Expand Up @@ -85,54 +46,44 @@ Page {
stateGroup.visible = stats.linkinfo !== undefined
if (stats.linkinfo) {
if (stats.linkinfo.info_data.berr_counter !== undefined) {
stateGroup.model = [
stateGroup.textModel = [
stats.linkinfo.info_data.state,
//% "TEC: %1"
qsTrId("settings_canbus_tec").arg(stats.linkinfo.info_data.berr_counter.tx),
//% "REC: %1"
qsTrId("settings_canbus_rec").arg(stats.linkinfo.info_data.berr_counter.rx),
"TEC: " + stats.linkinfo.info_data.berr_counter.tx,
"REC: " + stats.linkinfo.info_data.berr_counter.rx,
]
} else {
stateGroup.model = [
stateGroup.textModel = [
stats.linkinfo.info_data.state,
//% "TEC: N/A"
qsTrId("settings_canbus_tec_na"),
//% "REC: N/A"
qsTrId("settings_canbus_rec_na"),
"TEC: N/A",
"REC: N/A"
]
}

busOffCounters.visible = stats.linkinfo.info_xstats !== undefined
if (stats.linkinfo.info_xstats) {
busOffCounters.model = [
//: %1 = CAN bus statistics: 'bus_off' value
//% "Bus off: %1"
qsTrId("settings_canbus_bus_off").arg(stats.linkinfo.info_xstats.bus_off),
//: %1 = CAN bus statistics: 'error_passive' value
//% "Error passive: %1"
qsTrId("settings_canbus_error_passive").arg(stats.linkinfo.info_xstats.error_passive),
//: %1 = CAN bus statistics: 'error_warning' value
//% "Bus warning: %1"
qsTrId("settings_canbus_error_warning").arg(stats.linkinfo.info_xstats.error_warning),
busOffCounters.textModel = [
"Bus off: " + stats.linkinfo.info_xstats.bus_off,
"Err passive: " + stats.linkinfo.info_xstats.error_passive,
"Bus warn: " + stats.linkinfo.info_xstats.error_warning,
]
}
}

rxGroup.model = [
_packetsText(stats.stats64.rx.packets),
_droppedPacketsText(stats.stats64.rx.dropped, stats.stats64.rx.packets)
rxGroup.textModel = [
"packets: " + stats.stats64.rx.packets,
"dropped: " + stats.stats64.rx.dropped + _percentage(stats.stats64.rx.dropped, stats.stats64.rx.packets)
]
rxErrorGroup.model = [
_overrunsText(stats.stats64.rx.over_errors, stats.stats64.rx.packets),
_errorsText(stats.stats64.rx.errors, stats.stats64.rx.packets)
rxErrorGroup.textModel = [
"overruns: " + stats.stats64.rx.over_errors + _percentage(stats.stats64.rx.over_errors, stats.stats64.rx.packets),
"errors: " + stats.stats64.rx.errors + _percentage(stats.stats64.rx.errors, stats.stats64.rx.packets)
]

txGroup.model = [
_packetsText(stats.stats64.tx.packets),
_droppedPacketsText(stats.stats64.tx.dropped, stats.stats64.tx.packets)
txGroup.textModel = [
"packets: " + stats.stats64.tx.packets,
"dropped: " + stats.stats64.tx.dropped + _percentage(stats.stats64.tx.dropped, stats.stats64.tx.packets)
]
txErrorGroup.model = [
_errorsText(stats.stats64.tx.errors, stats.stats64.tx.packets)
txErrorGroup.textModel = [
"errors: " + stats.stats64.tx.errors + _percentage(stats.stats64.tx.errors, stats.stats64.tx.packets)
]
}
}
Expand All @@ -144,18 +95,15 @@ Page {

//% "State"
text: qsTrId("settings_state")
}

ListTextGroup {
id: busOffCounters
bottomContent.children: ListTextGroup {
id: busOffCounters
}
}

ListTextGroup {
id: rxGroup

text: "RX"
height: implicitHeight + rxErrorGroup.height

bottomContent.children: ListTextGroup {
id: rxErrorGroup
}
Expand All @@ -165,8 +113,6 @@ Page {
id: txGroup

text: "TX"
height: implicitHeight + txErrorGroup.height

bottomContent.children: ListTextGroup {
id: txErrorGroup
}
Expand Down

0 comments on commit a3de9d6

Please sign in to comment.