Skip to content

Commit 9493d4e

Browse files
author
zhitm
committed
Add RXE compilation on Linux for NXT
1 parent 5d86691 commit 9493d4e

File tree

15 files changed

+245
-80
lines changed

15 files changed

+245
-80
lines changed

.gitmodules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
url = https://bitbucket.org/codeimproved/qslog.git
2626
[submodule "installer/nxt-tools"]
2727
path = installer/nxt-tools
28-
url = https://github.com/trikset/nxt-tools
28+
url = https://github.com/zhitm/nxt-tools.git
29+
branch = main
2930
[submodule "trik-checkapp"]
3031
path = thirdparty/checkapp/checkapp
3132
url = https://github.com/trikset/trik-checkapp

installer/nxt-tools

installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-linux-gnu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ cd "$(dirname "$0")"
66
source "$INSTALLER_ROOT"/utils/common_utils.sh
77
mkdir "$PWD"/../data/bin
88
cd "$PWD"/../data/bin
9-
rsync -a "$INSTALLER_ROOT"/nxt-tools/linux/nxt-tools ./
9+
rsync -a "$INSTALLER_ROOT"/nxt-tools ./

installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-win32.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ source "$INSTALLER_ROOT"/utils/common_utils.sh
77

88
cd "$PWD"/../data
99

10-
rsync -aR "$INSTALLER_ROOT"/nxt-tools/win/./nxt-tools .
10+
rsync -aR "$INSTALLER_ROOT"/./nxt-tools .
1111
dos2unix nxt-tools/compile.sh
1212
rm -rf bin

plugins/robots/generators/nxt/nxtOsekCGenerator/nxtFlashTool.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <thirdparty/runExtensions.h>
2828
#include <nxtKit/communication/nxtCommandConstants.h>
2929
#include <nxtKit/communication/usbRobotCommunicationThread.h>
30+
#include <QOperatingSystemVersion>
3031

3132
using namespace nxt;
3233
using namespace qReal;
@@ -222,15 +223,26 @@ bool NxtFlashTool::uploadProgram(const QFileInfo &fileInfo)
222223
mCompileState = idle;
223224
mSource = fileInfo;
224225

225-
#ifdef Q_OS_WIN
226226
mCompileProcess.setWorkingDirectory(path());
227-
mCompileProcess.start("cmd", { "/c", path("compile.bat")
228-
+ " " + fileInfo.completeBaseName()
229-
+ " " + fileInfo.absolutePath() });
230-
#else
231-
mCompileProcess.start("sh", { path("compile.sh") , fileInfo.absolutePath()});
232-
#endif
233227

228+
switch(QOperatingSystemVersion::currentType()) {
229+
default:
230+
break;
231+
case QOperatingSystemVersion::OSType::Windows: {
232+
auto pathToNxtTools = path().replace("\\", "/");
233+
auto line = path("compile.bat")
234+
+ " " + fileInfo.completeBaseName()
235+
+ " " + fileInfo.absolutePath() + " " + pathToNxtTools+"gnuarm";
236+
mCompileProcess.start("cmd", { "/c", line});
237+
}
238+
break;
239+
case QOperatingSystemVersion::OSType::Unknown: {
240+
auto line = "./compile.sh . " + fileInfo.absolutePath() +
241+
" GNUARM_ROOT="+SettingsManager::value("pathToArmNoneEabi").toString();
242+
mCompileProcess.start("/bin/bash", {"-c", line});
243+
}
244+
break;
245+
}
234246
information(tr("Uploading program started. Please don't disconnect robot during the process"));
235247
return true;
236248
}
@@ -291,6 +303,10 @@ void NxtFlashTool::readNxtCompileData()
291303
"If you sure in their validness contact developers"));
292304
} else {
293305
error(tr("Could not upload program. Make sure the robot is connected and ON"));
306+
if (QOperatingSystemVersion::currentType() == QOperatingSystemVersion::OSType::Unknown) {
307+
error(tr("If you are using GNU/Linux visit "
308+
"https://help.trikset.com/nxt/run-upload-programs to get instructions"));
309+
}
294310
}
295311
}
296312

plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
* limitations under the License. */
1414

1515
#include "nxtOsekCGeneratorPlugin.h"
16-
1716
#include <QtCore/QDir>
1817
#include <QtCore/QDateTime>
1918
#include <QtWidgets/QApplication>
2019

2120
#include <qrkernel/settingsManager.h>
2221
#include <qrkernel/platformInfo.h>
2322
#include <qrutils/singleton.h>
23+
#include <QOperatingSystemVersion>
2424

25+
#include "QsLog.h"
2526
#include "nxtOsekCMasterGenerator.h"
2627

2728
using namespace nxt::osekC;
@@ -37,6 +38,12 @@ NxtOsekCGeneratorPlugin::NxtOsekCGeneratorPlugin()
3738
, mMasterGenerator(nullptr)
3839
, mCommunicator(utils::Singleton<communication::UsbRobotCommunicationThread>::instance())
3940
{
41+
const QString key = "pathToArmNoneEabi";
42+
const QString defaultPath = QDir(PlatformInfo::invariantSettingsPath("pathToNxtTools")).absolutePath()
43+
+"/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi";
44+
if (qReal::SettingsManager::value(key).isNull()) {
45+
qReal::SettingsManager::setValue(key, defaultPath);
46+
}
4047
initActions();
4148
initHotKeyActions();
4249
}
@@ -96,7 +103,6 @@ void NxtOsekCGeneratorPlugin::onCurrentDiagramChanged(const TabInfo &info)
96103
void NxtOsekCGeneratorPlugin::init(const kitBase::KitPluginConfigurator &configurator)
97104
{
98105
RobotsGeneratorPluginBase::init(configurator);
99-
100106
mFlashTool.reset(new NxtFlashTool(*mMainWindowInterface->errorReporter(), *mCommunicator));
101107
connect(&*mFlashTool, &NxtFlashTool::uploadingComplete, this, &NxtOsekCGeneratorPlugin::onUploadingComplete);
102108
}
@@ -223,21 +229,31 @@ void NxtOsekCGeneratorPlugin::uploadProgram()
223229
void NxtOsekCGeneratorPlugin::checkNxtTools()
224230
{
225231
const QDir dir(PlatformInfo::invariantSettingsPath("pathToNxtTools"));
226-
if (!dir.exists()) {
232+
const QDir gnuarm(dir.absolutePath() + "/gnuarm");
233+
const QDir nexttool(dir.absolutePath() + "/nexttool");
234+
const QDir nxtOSEK(dir.absolutePath() + "/nxtOSEK");
235+
236+
if (!dir.exists() || !gnuarm.exists() || !nexttool.exists() || !nxtOSEK.exists()) {
227237
mNxtToolsPresent = false;
238+
QLOG_ERROR() << "Missing" << dir.absolutePath() << "or mandatory subdirectory" <<
239+
dir.entryList(QDir::Filter::NoFilter, QDir::SortFlag::DirsFirst | QDir::SortFlag::Name);
228240
} else {
229-
QDir gnuarm(dir.absolutePath() + "/gnuarm/bin");
230-
QDir nexttool(dir.absolutePath() + "/nexttool");
231-
QDir nxtOSEK(dir.absolutePath() + "/nxtOSEK");
232-
233-
#ifdef Q_OS_WIN
234-
QFile compile1(dir.absolutePath() + "/compile.bat");
235-
QFile compile2(dir.absolutePath() + "/compile.sh");
236-
mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists()
237-
&& compile1.exists() && compile2.exists();
238-
#else
239-
QFile compile(dir.absolutePath() + "/compile.sh");
240-
mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists() && compile.exists();
241-
#endif
241+
switch(QOperatingSystemVersion::currentType()) {
242+
default:
243+
break;
244+
245+
case QOperatingSystemVersion::OSType::Windows: {
246+
QFile compile1(dir.absolutePath() + "/compile.bat");
247+
QFile compile2(dir.absolutePath() + "/compile.sh");
248+
mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists()
249+
&& compile1.exists() && compile2.exists();
250+
}
251+
break;
252+
case QOperatingSystemVersion::OSType::Unknown: {
253+
QFile compile(dir.absolutePath() + "/compile.sh");
254+
mNxtToolsPresent = nexttool.exists() && nxtOSEK.exists() && compile.exists();
255+
}
256+
break;
257+
}
242258
}
243259
}

plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
#include "nxtAdditionalPreferences.h"
1616
#include "ui_nxtAdditionalPreferences.h"
17-
1817
#include <qrkernel/settingsManager.h>
1918
#include <utils/widgets/comPortPicker.h>
19+
#include "QsLog.h"
20+
#include <QOperatingSystemVersion>
21+
2022

2123
using namespace nxt;
2224
using namespace qReal;
@@ -28,6 +30,8 @@ NxtAdditionalPreferences::NxtAdditionalPreferences(const QString &realRobotName,
2830
{
2931
mUi->setupUi(this);
3032
mUi->robotImagePicker->configure("nxtRobot2DImage", tr("2D robot image:"));
33+
mUi->compilerPicker->configure("pathToArmNoneEabi", tr("Path to arm-none-eabi:"));
34+
setTextOnGeneratorLabel();
3135
connect(mUi->manualComPortCheckbox, &QCheckBox::toggled
3236
, this, &NxtAdditionalPreferences::manualComPortCheckboxChecked);
3337
}
@@ -37,18 +41,44 @@ NxtAdditionalPreferences::~NxtAdditionalPreferences()
3741
delete mUi;
3842
}
3943

44+
void NxtAdditionalPreferences::setColorOnGeneratorLabel(QColor color){
45+
QPalette palette = mUi->generatorLabel->palette();
46+
palette.setColor(mUi->generatorLabel->foregroundRole(), color);
47+
mUi->generatorLabel->setPalette(palette);
48+
}
49+
50+
void NxtAdditionalPreferences::setTextOnGeneratorLabel(){
51+
if (!mUi->compilerPicker->isSavedDirExist()){
52+
mUi->generatorLabel->setText(tr("WARNING: Current directory doesn't exist. \nOpen "
53+
"<a href=\"https://help.trikset.com/nxt/run-upload-programs\">link</a>"
54+
" for instructions"));
55+
mUi->generatorLabel->setTextFormat(Qt::RichText);
56+
mUi->generatorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
57+
mUi->generatorLabel->setOpenExternalLinks(true);
58+
setColorOnGeneratorLabel(QColor("red"));
59+
}
60+
else {
61+
mUi->generatorLabel->setText("Current directory exist.");
62+
setColorOnGeneratorLabel(QColor("black"));
63+
}
64+
}
65+
4066
void NxtAdditionalPreferences::save()
4167
{
4268
SettingsManager::setValue("NxtBluetoothPortName", selectedPortName());
4369
SettingsManager::setValue("NxtManualComPortCheckboxChecked", mUi->manualComPortCheckbox->isChecked());
4470
mUi->robotImagePicker->save();
71+
mUi->compilerPicker->save();
72+
setTextOnGeneratorLabel();
4573
emit settingsChanged();
4674
}
4775

4876
void NxtAdditionalPreferences::restoreSettings()
4977
{
5078
ui::ComPortPicker::populate(*mUi->comPortComboBox, "NxtBluetoothPortName");
5179
mUi->robotImagePicker->restore();
80+
mUi->compilerPicker->restore();
81+
setTextOnGeneratorLabel();
5282

5383
if (mUi->comPortComboBox->count() == 0) {
5484
mUi->comPortComboBox->hide();
@@ -72,7 +102,11 @@ void NxtAdditionalPreferences::restoreSettings()
72102

73103
void NxtAdditionalPreferences::onRobotModelChanged(kitBase::robotModel::RobotModelInterface * const robotModel)
74104
{
105+
QLOG_DEBUG() << robotModel->name();
75106
mUi->bluetoothSettingsGroupBox->setVisible(robotModel->name() == mBluetoothRobotName);
107+
if (QOperatingSystemVersion::currentType() == QOperatingSystemVersion::OSType::Unknown) {
108+
mUi->generatorSettingsGroupBox->setVisible(robotModel->name() == "NxtOsekCGeneratorRobotModel");
109+
}
76110
}
77111

78112
void NxtAdditionalPreferences::manualComPortCheckboxChecked(bool state)

plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ private slots:
4242

4343
private:
4444
QString selectedPortName() const;
45-
45+
void setColorOnGeneratorLabel(QColor color);
46+
void setTextOnGeneratorLabel();
4647
Ui::NxtAdditionalPreferences *mUi;
4748
const QString mBluetoothRobotName;
4849
};

plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.ui

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>414</width>
10-
<height>164</height>
9+
<width>401</width>
10+
<height>284</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -27,22 +27,33 @@
2727
<number>0</number>
2828
</property>
2929
<item>
30-
<widget class="qReal::ui::ImagePicker" name="robotImagePicker">
31-
</widget>
30+
<widget class="qReal::ui::ImagePicker" name="robotImagePicker" native="true"/>
3231
</item>
3332
<item>
34-
<widget class="QGroupBox" name="bluetoothSettingsGroupBox">
33+
<widget class="QGroupBox" name="generatorSettingsGroupBox">
3534
<property name="title">
36-
<string>Bluetooth Settings</string>
35+
<string>nxtOSEK Generator Settings</string>
3736
</property>
38-
<layout class="QGridLayout" name="gridLayout_4">
37+
<layout class="QGridLayout" name="gridLayout">
3938
<item row="1" column="0">
40-
<widget class="QLabel" name="comPortLabel">
39+
<widget class="QLabel" name="generatorLabel">
4140
<property name="text">
42-
<string>COM Port:</string>
41+
<string>TextLabel</string>
4342
</property>
4443
</widget>
4544
</item>
45+
<item row="0" column="0">
46+
<widget class="qReal::ui::dirPicker" name="compilerPicker" native="true"/>
47+
</item>
48+
</layout>
49+
</widget>
50+
</item>
51+
<item>
52+
<widget class="QGroupBox" name="bluetoothSettingsGroupBox">
53+
<property name="title">
54+
<string>Bluetooth Settings</string>
55+
</property>
56+
<layout class="QGridLayout" name="gridLayout_4">
4657
<item row="1" column="1">
4758
<widget class="QComboBox" name="comPortComboBox">
4859
<property name="sizePolicy">
@@ -53,16 +64,6 @@
5364
</property>
5465
</widget>
5566
</item>
56-
<item row="2" column="0">
57-
<widget class="QLabel" name="directInputComPortLabel">
58-
<property name="text">
59-
<string>COM Port:</string>
60-
</property>
61-
</widget>
62-
</item>
63-
<item row="2" column="1">
64-
<widget class="QLineEdit" name="directInputComPortLineEdit"/>
65-
</item>
6667
<item row="0" column="0" colspan="2">
6768
<widget class="QLabel" name="noComPortsFoundLabel">
6869
<property name="text">
@@ -73,13 +74,30 @@
7374
</property>
7475
</widget>
7576
</item>
77+
<item row="2" column="1">
78+
<widget class="QLineEdit" name="directInputComPortLineEdit"/>
79+
</item>
7680
<item row="3" column="0" colspan="2">
7781
<widget class="QCheckBox" name="manualComPortCheckbox">
7882
<property name="text">
7983
<string>Specify COM port manually</string>
8084
</property>
8185
</widget>
8286
</item>
87+
<item row="1" column="0">
88+
<widget class="QLabel" name="comPortLabel">
89+
<property name="text">
90+
<string>COM Port:</string>
91+
</property>
92+
</widget>
93+
</item>
94+
<item row="2" column="0">
95+
<widget class="QLabel" name="directInputComPortLabel">
96+
<property name="text">
97+
<string>COM Port:</string>
98+
</property>
99+
</widget>
100+
</item>
83101
</layout>
84102
</widget>
85103
</item>
@@ -92,6 +110,12 @@
92110
<header>qrutils/widgets/imagePicker.h</header>
93111
<container>1</container>
94112
</customwidget>
113+
<customwidget>
114+
<class>qReal::ui::dirPicker</class>
115+
<extends>QWidget</extends>
116+
<header>qrutils/widgets/dirPicker.h</header>
117+
<container>1</container>
118+
</customwidget>
95119
</customwidgets>
96120
<resources/>
97121
<connections/>

0 commit comments

Comments
 (0)