diff --git a/commands.cpp b/commands.cpp index 5d04fad..592c1b8 100644 --- a/commands.cpp +++ b/commands.cpp @@ -254,6 +254,17 @@ void Commands::processPacket(QByteArray data) emit pingCanRx(devs, false); } break; + case COMM_GET_BMS_NET_SETTINGS: + { + QStringList settings; + settings << vb.mid(0, 250); + settings << vb.mid(250, 250); + settings << vb.mid(500, 50); + settings << vb.mid(550, 50); + settings << vb.mid(600, 50); + emit netSettingsReceived(settings); + break; + } default: break; } @@ -323,6 +334,26 @@ void Commands::getExpansionTemp() vb.vbAppendInt8(COMM_GET_BMS_EXP_TEMP); emitData(vb); } + +void Commands::getNetSettings() +{ + VByteArray vb; + vb.vbAppendInt8(COMM_GET_BMS_NET_SETTINGS); + emitData(vb); +} + +void Commands::setNetSettings(QStringList settings) +{ + VByteArray vb; + vb.vbAppendInt8(COMM_SET_BMS_NET_SETTINGS); + vb.append(settings.at(0).leftJustified(250, '\0', true)); + vb.append(settings.at(1).leftJustified(250, '\0', true)); + vb.append(settings.at(2).leftJustified(50, '\0', true)); + vb.append(settings.at(3).leftJustified(50, '\0', true)); + vb.append(settings.at(4).leftJustified(50, '\0', true)); + emitData(vb); +} + void Commands::sendTerminalCmd(QString cmd) { VByteArray vb; diff --git a/commands.h b/commands.h index d83f32a..b98b51c 100644 --- a/commands.h +++ b/commands.h @@ -71,6 +71,7 @@ signals: void bmsConfigCheckResult(QStringList paramsNotSet); void valuesSetupReceived(BMS_VALUES values); void pingCanRx(QVector devs, bool isTimeout); + void netSettingsReceived(QStringList settings); public slots: void processPacket(QByteArray data); @@ -80,6 +81,8 @@ public slots: void getCells(); void getAux(); void getExpansionTemp(); + void getNetSettings(); + void setNetSettings(QStringList settings); void sendTerminalCmd(QString cmd); void setDetect(disp_pos_mode mode); void samplePrint(debug_sampling_mode mode, int sample_len, int dec); diff --git a/datatypes.h b/datatypes.h index 691c1bd..f8a17dd 100644 --- a/datatypes.h +++ b/datatypes.h @@ -415,7 +415,9 @@ typedef enum { COMM_STORE_BMS_CONF = 150, COMM_GET_BMS_CELLS, COMM_GET_BMS_AUX, - COMM_GET_BMS_EXP_TEMP + COMM_GET_BMS_EXP_TEMP, + COMM_GET_BMS_NET_SETTINGS = 154, + COMM_SET_BMS_NET_SETTINGS = 156 } COMM_PACKET_ID; typedef struct { diff --git a/qml/Screens/BmsServiceScreen.qml b/qml/Screens/BmsServiceScreen.qml index 93c23a8..d43d114 100644 --- a/qml/Screens/BmsServiceScreen.qml +++ b/qml/Screens/BmsServiceScreen.qml @@ -22,6 +22,12 @@ RowLayout { property string title: qsTr("Firmware update") } + Screens.NetworkSettingsScreen { + id: networkSettingsScreen + property string title: qsTr("Network settings") + } + + Layout.fillWidth: true Layout.fillHeight: true } @@ -30,7 +36,7 @@ RowLayout { spacing: 20 Repeater { - model: [terminalScreen.title, firmwareUpdateScreen.title] + model: [terminalScreen.title, firmwareUpdateScreen.title, networkSettingsScreen.title] delegate: Controls.LinkLabel { text: modelData onClicked: stack.currentIndex = index @@ -41,6 +47,7 @@ RowLayout { Layout.fillHeight: true } - Layout.preferredWidth: 180 + Layout.minimumWidth: 180 + Layout.maximumWidth: 180 } } diff --git a/qml/Screens/NetworkSettingsScreen.qml b/qml/Screens/NetworkSettingsScreen.qml new file mode 100644 index 0000000..270b4c5 --- /dev/null +++ b/qml/Screens/NetworkSettingsScreen.qml @@ -0,0 +1,212 @@ +import QtQuick 2.12 +import QtQuick.Layouts 1.12 + +import Controls 1.0 as Controls +import Cubo 1.0 + +ColumnLayout { + spacing: 10 + + Controls.Frame { + padding: 35 + topPadding: 20 + bottomPadding: 20 + + RowLayout { + anchors.fill: parent + spacing: 20 + + Controls.SubtitleLabel { + id: firstUrlLabel + text: qsTr("Url 1") + + TextMetrics { + id: firstUrlMetrics + font: firstUrlLabel.font + text: firstUrlLabel.text + } + + Layout.preferredWidth: getMaxLabelWidth() + } + + Controls.TextField { + id: firstUrlField + validator: RegExpValidator { regExp: /.{0,250}/ } + Layout.fillWidth: true + } + } + + Layout.fillWidth: true + } + + Controls.Frame { + padding: 35 + topPadding: 20 + bottomPadding: 20 + + RowLayout { + anchors.fill: parent + spacing: 20 + + Controls.SubtitleLabel { + id: secondUrlLabel + text: qsTr("Url 2") + + TextMetrics { + id: secondUrlMetrics + font: secondUrlLabel.font + text: secondUrlLabel.text + } + + Layout.preferredWidth: getMaxLabelWidth() + } + + Controls.TextField { + id: secondUrlField + validator: RegExpValidator { regExp: /.{0,250}/ } + Layout.fillWidth: true + } + } + + Layout.fillWidth: true + } + + Controls.Frame { + padding: 35 + topPadding: 20 + bottomPadding: 20 + + RowLayout { + anchors.fill: parent + spacing: 20 + + Controls.SubtitleLabel { + id: apnLabel + text: qsTr("APN") + + TextMetrics { + id: apnMetrics + font: apnLabel.font + text: apnLabel.text + } + + Layout.preferredWidth: getMaxLabelWidth() + } + + Controls.TextField { + id: apnField + validator: RegExpValidator { regExp: /.{0,50}/ } + Layout.fillWidth: true + } + } + + Layout.fillWidth: true + } + + Controls.Frame { + padding: 35 + topPadding: 20 + bottomPadding: 20 + + RowLayout { + anchors.fill: parent + spacing: 20 + + Controls.SubtitleLabel { + id: userLabel + text: qsTr("User") + + TextMetrics { + id: userMetrics + font: userLabel.font + text: userLabel.text + } + + Layout.preferredWidth: getMaxLabelWidth() + } + + Controls.TextField { + id: userField + validator: RegExpValidator { regExp: /.{0,50}/ } + Layout.fillWidth: true + } + } + + Layout.fillWidth: true + } + + Controls.Frame { + padding: 35 + topPadding: 20 + bottomPadding: 20 + + RowLayout { + anchors.fill: parent + spacing: 20 + + Controls.SubtitleLabel { + id: passwordLabel + text: qsTr("Password") + + TextMetrics { + id: passwordMetrics + font: passwordLabel.font + text: passwordLabel.text + } + + Layout.preferredWidth: getMaxLabelWidth() + } + + Controls.TextField { + id: passwordField + validator: RegExpValidator { regExp: /.{0,50}/ } + Layout.fillWidth: true + } + } + + Layout.fillWidth: true + } + + Controls.Button { + text: qsTr("Apply") + onClicked: { + if (!BmsInterface.isPortConnected()) + return + + var settings = [ + firstUrlField.text, + secondUrlField.text, + apnField.text, + userField.text, + passwordField.text, + ] + + BmsInterface.commands().setNetSettings(settings) + } + } + + Connections { + target: BmsInterface.commands() + onNetSettingsReceived: { + if (settings.length < 5) { + return + } + + firstUrlField.text = settings[0] + secondUrlField.text = settings[1] + apnField.text = settings[2] + userField.text = settings[3] + passwordField.text = settings[4] + } + } + + onVisibleChanged: if (visible) { + if (BmsInterface.isPortConnected()) { + BmsInterface.commands().getNetSettings() + } + } + + function getMaxLabelWidth() { + return Math.max(firstUrlMetrics.width, secondUrlMetrics.width, apnMetrics.width, userMetrics.width, passwordMetrics.width) + } +} diff --git a/qml/Screens/qmldir b/qml/Screens/qmldir index b1e6ce1..5771621 100644 --- a/qml/Screens/qmldir +++ b/qml/Screens/qmldir @@ -10,3 +10,4 @@ MessageDialog 1.0 MessageDialog.qml StatusPopup 1.0 StatusPopup.qml TerminalScreen 1.0 TerminalScreen.qml FirmwareUpdateScreen 1.0 FirmwareUpdateScreen.qml +NetworkSettingsScreen 1.0 NetworkSettingsScreen.qml diff --git a/qml/qml_items.qrc b/qml/qml_items.qrc index df8193c..57f92e4 100644 --- a/qml/qml_items.qrc +++ b/qml/qml_items.qrc @@ -44,5 +44,6 @@ Screens/TerminalScreen.qml Screens/FirmwareUpdateScreen.qml Controls/ProgressBar.qml + Screens/NetworkSettingsScreen.qml diff --git a/translations/cubo_en.ts b/translations/cubo_en.ts index ee3b9f5..26803db 100644 --- a/translations/cubo_en.ts +++ b/translations/cubo_en.ts @@ -218,6 +218,11 @@ Firmware update + + + Network settings + + BmsSettingsScreen @@ -482,45 +487,45 @@ Wait, please. - - + + Buffer erase - + Buffer erase timeout - + CRC/Size write - + CRC/Size write timeout - + Firmware data write - + Firmware data write timeout - + Firmware update completed! Reconnect to the board if you want to continue working with it. - + Cancelled @@ -739,6 +744,39 @@ Reconnect to the board if you want to continue working with it. + + NetworkSettingsScreen + + + Url 1 + + + + + Url 2 + + + + + APN + + + + + User + + + + + Password + + + + + Apply + + + QObject diff --git a/translations/cubo_it.ts b/translations/cubo_it.ts index 69db95b..eea02ed 100644 --- a/translations/cubo_it.ts +++ b/translations/cubo_it.ts @@ -218,6 +218,11 @@ Firmware update + + + Network settings + + BmsSettingsScreen @@ -482,45 +487,45 @@ Wait, please. - - + + Buffer erase - + Buffer erase timeout - + CRC/Size write - + CRC/Size write timeout - + Firmware data write - + Firmware data write timeout - + Firmware update completed! Reconnect to the board if you want to continue working with it. - + Cancelled @@ -739,6 +744,39 @@ Reconnect to the board if you want to continue working with it. + + NetworkSettingsScreen + + + Url 1 + + + + + Url 2 + + + + + APN + + + + + User + + + + + Password + + + + + Apply + + + QObject diff --git a/translations/cubo_ru.qm b/translations/cubo_ru.qm index c84772b..fbb637e 100644 Binary files a/translations/cubo_ru.qm and b/translations/cubo_ru.qm differ diff --git a/translations/cubo_ru.ts b/translations/cubo_ru.ts index 321d217..cfa3486 100644 --- a/translations/cubo_ru.ts +++ b/translations/cubo_ru.ts @@ -230,6 +230,11 @@ Firmware update Обновление прошивки + + + Network settings + Настройки сети + BmsSettingsScreen @@ -499,38 +504,38 @@ Wait, please. Конфигурация BMS установлена - - + + Buffer erase Стирание буфера - + Buffer erase timeout Таймаут стирания буфера - + CRC/Size write Запись контрольной суммы - + CRC/Size write timeout Таймаут записи контрольной суммы - + Firmware data write Запись данных прошивки - + Firmware data write timeout Таймаут записи данных прошивки - + Firmware update completed! Reconnect to the board if you want to continue working with it. @@ -543,7 +548,7 @@ Reconnect to the board if you want to continue working with it. Обновление прошивки завершено - + Cancelled Отменено @@ -774,6 +779,39 @@ Reconnect to the board if you want to continue working with it. Ок + + NetworkSettingsScreen + + + Url 1 + + + + + Url 2 + + + + + APN + + + + + User + Пользователь + + + + Password + Пароль + + + + Apply + Применить + + QObject