Added board firmware update functionality

This commit is contained in:
Yury Shuvakin
2022-09-13 15:20:09 +03:00
parent d28efef208
commit 4dd1f95193
21 changed files with 908 additions and 225 deletions

View File

@@ -0,0 +1,38 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import Utils 1.0
ProgressBar {
id: control
padding: 2
background: Rectangle {
implicitWidth: 250
implicitHeight: 26
border.width: 1
border.color: Palette.borderColor
color: Palette.screenBackgroundColor
radius: 5
}
contentItem: Item {
implicitWidth: 250
implicitHeight: 24
Rectangle {
width: control.visualPosition * parent.width
height: parent.height
radius: 5
color: Palette.alternativeBackgroundColor
}
Text {
text: Math.floor((control.value / control.to) * 100) + '%'
anchors.centerIn: parent
color: Palette.textColor
font.pixelSize: 18
font.weight: Font.Bold
}
}
}

View File

@@ -25,3 +25,4 @@ MenuItemDelegate 1.0 MenuItemDelegate.qml
ScrollIndicator 1.0 ScrollIndicator.qml
OutlineImageButton 1.0 OutlineImageButton.qml
ImageButton 1.0 ImageButton.qml
ProgressBar 1.0 ProgressBar.qml

View File

@@ -131,17 +131,8 @@ ApplicationWindow {
RowLayout {
id: topBar
property var labels: [
qsTr("AKB monitor"),
qsTr("Cell monitor"),
qsTr("BMS settings"),
qsTr("Visualization"),
qsTr("Information output"),
qsTr("Terminal"),
]
Label {
text: topBar.labels[stack.currentIndex]
text: stack.itemAt(stack.currentIndex).title
font.pixelSize: 38
font.weight: Font.Bold
color: Palette.textColor
@@ -316,12 +307,15 @@ ApplicationWindow {
Layout.bottomMargin: 30
Screens.AkbMonitorScreen {
property string title: qsTr("AKB monitor")
}
Screens.CellMonitorScreen {
property string title: qsTr("Cell monitor")
}
Screens.BmsSettingsScreen {
property string title: qsTr("BMS settings")
onNeedWait: {
if (active) {
busyPopup.text = text
@@ -333,10 +327,12 @@ ApplicationWindow {
}
Screens.VisualizationScreen {
property string title: qsTr("Visualization")
}
Screens.DebugInformationScreen {
id: debugScreen
property string title: qsTr("Information output")
}
Screens.BmsServiceScreen {
@@ -357,8 +353,6 @@ ApplicationWindow {
serialLabel.text = "-"
firmwareLabel.text = "-"
}
debugScreen.printMessage(BmsInterface.getConnectedPortName(), true)
}
onMessageDialog: {
@@ -389,6 +383,22 @@ ApplicationWindow {
}
}
}
onFwUploadStatus: {
if (isOngoing) {
if (!progressPopup.opened) {
progressPopup.open()
}
progressPopup.text = status
progressPopup.progress = progress
} else {
progressPopup.close()
BmsInterface.emitMessageDialog(qsTr("Firmware update"), status, true)
}
}
onBmsConfigurationStored: busyPopup.close()
}
Connections {
@@ -440,7 +450,6 @@ ApplicationWindow {
onOpened: {
hideStatusTimer.start()
busyPopup.close()
}
}
@@ -477,6 +486,8 @@ ApplicationWindow {
font.pixelSize: 20
Layout.alignment: Qt.AlignCenter
horizontalAlignment: Text.AlignHCenter
leftPadding: 10
rightPadding: 10
background: Rectangle {
color: Palette.textColor
@@ -490,6 +501,48 @@ ApplicationWindow {
onClosed: hideBusyTimer.stop()
}
Popup {
id: progressPopup
x: (parent.width - width) / 2
y: (parent.height - height) / 2
modal: true
closePolicy: Popup.NoAutoClose
property alias text: progressText.text
property alias progress: progressBar.value
background: Rectangle {
color: "transparent"
}
ColumnLayout {
Controls.ProgressBar {
id: progressBar
Layout.alignment: Qt.AlignCenter
Layout.preferredWidth: 500
}
Controls.SubtitleLabel {
text: "asdfzasdf"
id: progressText
color: Palette.alternativeTextColor
maximumLineCount: 3
wrapMode: Text.Wrap
font.pixelSize: 20
Layout.alignment: Qt.AlignCenter
horizontalAlignment: Text.AlignHCenter
leftPadding: 10
rightPadding: 10
background: Rectangle {
color: Palette.textColor
opacity: 0.3
radius: 6
}
}
}
}
Timer {
id: hideBusyTimer
interval: 30000

View File

@@ -1,74 +1,46 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Controls 1.0 as Controls
import Cubo 1.0
import Screens 1.0 as Screens
ColumnLayout {
RowLayout {
spacing: 20
Keys.onReturnPressed: sendButton.clicked()
Keys.onEnterPressed: sendButton.clicked()
property string title: stack.itemAt(stack.currentIndex).title
Controls.Frame {
Flickable {
id: outputFlickable
clip: true
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
StackLayout {
id: stack
TextArea.flickable: Controls.TextArea {
id: outputArea
}
Screens.TerminalScreen {
id: terminalScreen
property string title: qsTr("Terminal")
}
ScrollBar.horizontal: Controls.ScrollBar {}
ScrollBar.vertical: Controls.ScrollBar {}
Screens.FirmwareUpdateScreen {
id: firmwareUpdateScreen
property string title: qsTr("Firmware update")
}
Layout.fillWidth: true
Layout.fillHeight: true
}
RowLayout {
ColumnLayout {
spacing: 20
Controls.Button {
text: qsTr("Clear")
Layout.preferredWidth: 120
onClicked: outputArea.clear()
}
Controls.TextField {
id: commandField
implicitHeight: 52
Layout.fillWidth: true
}
Controls.Button {
id: sendButton
text: qsTr("Send")
Layout.preferredWidth: 120
onClicked: {
BmsInterface.commands().sendTerminalCmd(commandField.text)
commandField.clear()
Repeater {
model: [terminalScreen.title, firmwareUpdateScreen.title]
delegate: Controls.LinkLabel {
text: modelData
onClicked: stack.currentIndex = index
}
}
Controls.Button {
text: qsTr("Help")
Layout.preferredWidth: 120
onClicked: BmsInterface.commands().sendTerminalCmd("help")
Item {
Layout.fillHeight: true
}
Layout.fillWidth: true
}
Connections {
target: BmsInterface.commands()
onPrintReceived: {
outputArea.append(str)
outputArea.cursorPosition = outputArea.length
}
Layout.preferredWidth: 180
}
}

View File

@@ -38,6 +38,7 @@ ColumnLayout {
Connections {
target: BmsInterface
onStatusMessage: printMessage(msg, isGood)
onPortConnectedChanged: printMessage(BmsInterface.getConnectedPortName(), true)
}
function printMessage(msg, isGood) {

View File

@@ -0,0 +1,126 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Dialogs 1.2
import Qt.labs.settings 1.1
import Controls 1.0 as Controls
import Cubo 1.0
ColumnLayout {
spacing: 20
Controls.Frame {
padding: 35
ColumnLayout {
anchors.fill: parent
spacing: 20
Controls.TitleLabel {
text: qsTr("Board information")
Layout.fillWidth: true
}
RowLayout {
spacing: 10
Controls.ContentLabel {
text: qsTr("Firmware")
}
Controls.DotSeparator {
Layout.fillWidth: true
}
Controls.ContentLabel {
id: firmwareLabel
}
Layout.fillWidth: true
}
RowLayout {
spacing: 10
Controls.ContentLabel {
text: qsTr("Hardware")
}
Controls.DotSeparator {
Layout.fillWidth: true
}
Controls.ContentLabel {
id: hardwareLabel
}
Layout.fillWidth: true
}
RowLayout {
spacing: 10
Controls.ContentLabel {
text: qsTr("UUID")
}
Controls.DotSeparator {
Layout.fillWidth: true
}
Controls.ContentLabel {
id: uuidLabel
}
Layout.fillWidth: true
}
}
Layout.fillWidth: true
}
Controls.Button {
text: qsTr("Upload firmware")
onClicked: firmwareFileDialog.open()
FileDialog {
id: firmwareFileDialog
title: qsTr("Select firmware file")
folder: shortcuts.documents
nameFilters: [ qsTr("Firmware files (*.bin)"), qsTr("All files (*)") ]
onAccepted: {
if (BmsInterface.isPortConnected()) {
updateHelper.uploadFirmware(firmwareFileDialog.fileUrl.toString().replace(/^(file:\/{3})/, ""), BmsInterface)
}
}
}
Settings {
category: "firmwareUpdate"
property alias folder: firmwareFileDialog.folder
}
}
Item {
Layout.fillWidth: true
}
FirmwareUpdateHelper {
id: updateHelper
}
Connections {
target: BmsInterface.commands()
onFwVersionReceived: {
firmwareLabel.text = major + "." + minor
hardwareLabel.text = hw
uuidLabel.text = bufferToHex(uuid)
}
}
function bufferToHex(buffer) {
return [...new Uint8Array(buffer)]
.map(b => b.toString(16).padStart(2, "0"))
.join("").toUpperCase();
}
}

View File

@@ -0,0 +1,74 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Controls 1.0 as Controls
import Cubo 1.0
ColumnLayout {
spacing: 20
Keys.onReturnPressed: sendButton.clicked()
Keys.onEnterPressed: sendButton.clicked()
Controls.Frame {
Flickable {
id: outputFlickable
clip: true
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
TextArea.flickable: Controls.TextArea {
id: outputArea
}
ScrollBar.horizontal: Controls.ScrollBar {}
ScrollBar.vertical: Controls.ScrollBar {}
}
Layout.fillWidth: true
Layout.fillHeight: true
}
RowLayout {
spacing: 20
Controls.Button {
text: qsTr("Clear")
Layout.preferredWidth: 120
onClicked: outputArea.clear()
}
Controls.TextField {
id: commandField
implicitHeight: 52
Layout.fillWidth: true
}
Controls.Button {
id: sendButton
text: qsTr("Send")
Layout.preferredWidth: 120
onClicked: {
BmsInterface.commands().sendTerminalCmd(commandField.text)
commandField.clear()
}
}
Controls.Button {
text: qsTr("Help")
Layout.preferredWidth: 120
onClicked: BmsInterface.commands().sendTerminalCmd("help")
}
Layout.fillWidth: true
}
Connections {
target: BmsInterface.commands()
onPrintReceived: {
outputArea.append(str)
outputArea.cursorPosition = outputArea.length
}
}
}

View File

@@ -8,3 +8,5 @@ DebugInformationScreen 1.0 DebugInformationScreen.qml
ConnectionDialog 1.0 ConnectionDialog.qml
MessageDialog 1.0 MessageDialog.qml
StatusPopup 1.0 StatusPopup.qml
TerminalScreen 1.0 TerminalScreen.qml
FirmwareUpdateScreen 1.0 FirmwareUpdateScreen.qml

View File

@@ -41,5 +41,8 @@
<file>Controls/ScrollIndicator.qml</file>
<file>Controls/OutlineImageButton.qml</file>
<file>Controls/ImageButton.qml</file>
<file>Screens/TerminalScreen.qml</file>
<file>Screens/FirmwareUpdateScreen.qml</file>
<file>Controls/ProgressBar.qml</file>
</qresource>
</RCC>