From 12c4535e060aeb73554cdcf7ceef2313b2207846 Mon Sep 17 00:00:00 2001 From: Yury Shuvakin Date: Fri, 16 Sep 2022 03:22:47 +0300 Subject: [PATCH] Implemented network settings --- commands.cpp | 31 ++++ commands.h | 3 + datatypes.h | 4 +- qml/Screens/BmsServiceScreen.qml | 11 +- qml/Screens/NetworkSettingsScreen.qml | 212 ++++++++++++++++++++++++++ qml/Screens/qmldir | 1 + qml/qml_items.qrc | 1 + translations/cubo_en.ts | 56 +++++-- translations/cubo_it.ts | 56 +++++-- translations/cubo_ru.qm | Bin 20442 -> 20915 bytes translations/cubo_ru.ts | 56 +++++-- 11 files changed, 401 insertions(+), 30 deletions(-) create mode 100644 qml/Screens/NetworkSettingsScreen.qml 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 c84772bf48f3e4f7b60928773886b945d21c8a99..fbb637e2b136cd951ca6adaa67488449318cf2be 100644 GIT binary patch delta 1644 zcmZ`(3s6*L7(I9I-DUT(%POESC=V9_K|z)Ud9Q%H1VR!?9ks@EQ^!Zjf=EQGA{oAF zT+~q+G7(EG8wOuxLy5d>vZf46!xus}>g0pc8k^|gIu7GZcjnHS@BZK8eCPZAd+B|l zsZMy$-L@EjKM?vE@g*QE7?5g#C=dMz*kW~1o^1ilHxUwO1%lQgvm}1CN&{v_p5+LhiT?Bfc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p4z{DbKdWL&*eGieBOh?&-;a4 zfgT%xu|Uikaxr-wkZXXXlVmsf6QD^1VhhNZfN879Jf1%R!Y2WiE97Kykc)&MDXR9+UD+#ElnU4A-uqSChrn6eBlv05PPSzJ5t3GmEOJa+Ni`jrsW zP{~4S1WQ~v&ld?{HBZ3w?hE0*E?{)6aADF}R`*co+L8%4okF)G8%Vw*4A_`);#4v4 zi)Fy5S1NLZNKb+I&h_)ut6V%>U&Yr8#7jA$K)`A7MpXtdaiQ4L836=e6>k?(GnYeB zgWH+jeknd=CcPP?>4VfUd7G3K^ALzAkY0XW0wPaK#fRgW{t2lpleS=!KL2tk5T7O8 z+Qhz0Yn5(wxv87ujx6qJ0_>gg$l>dO)GP8R9qUzl<*-3MnCh07?tTuK@wB{pHtS8< zFK;;24NSNuS6jydGyjsSi|l}HtX!{}fP_nO{Y2hRE7#a&c!4qRYG&VL*$L&EqKU!4 zuzpS5amo?Zs=1k0ibSXdnqN;)kLU`mkk?E{FKC@Zmat)Vt#AHQbnuh=`5X*TH2HMG*}5#0rEF3W7xwTH9Z1f60Tc#~t3q{LZ|aimL>g<)*FBSTr+MjiDD z%6oTvc)wKHdz^7S?q0=rpp=8!uG}cAWx&nK!*80Yi%S`NG@bKUsTzk?bC^5S5m`U5 z9E%#W=}$Ibhq`=#y4h>g>|ud`F-pyzOx_S=%q~@r3wplE*~N3=d5C>bE=SK=|8F_ZYP|MPWia{ER=Umo~Cdvli&*IXAPSNBW&j zw}Ht;`uDdUr`{*@J*N&*?;1bD%k&S5X@~S1hBSW<1Z5ZkMcSkL49{=v;lk`QtlW2r z4Nfw=(Ns4M5WhC$r`M5I!&~FoAbX0T=wv;m`pr-&__)#)6(7n$o@hg79|glo7dB-@gh8A;SWgHtFirmware 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