Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NXT support for Linux #1882

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
url = https://bitbucket.org/codeimproved/qslog.git
[submodule "installer/nxt-tools"]
path = installer/nxt-tools
url = https://github.com/trikset/nxt-tools
url = https://github.com/trikset/nxt-tools.git
branch = main
[submodule "trik-checkapp"]
path = thirdparty/checkapp/checkapp
url = https://github.com/trikset/trik-checkapp
Expand Down
2 changes: 1 addition & 1 deletion installer/nxt-tools
Submodule nxt-tools updated 4377 files
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ cd "$(dirname "$0")"
source "$INSTALLER_ROOT"/utils/common_utils.sh
mkdir "$PWD"/../data/bin
cd "$PWD"/../data/bin
rsync -a "$INSTALLER_ROOT"/nxt-tools/linux/nxt-tools ./
rsync -a "$INSTALLER_ROOT"/nxt-tools ./
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ source "$INSTALLER_ROOT"/utils/common_utils.sh

cd "$PWD"/../data

rsync -aR "$INSTALLER_ROOT"/nxt-tools/win/./nxt-tools .
rsync -aR "$INSTALLER_ROOT"/./nxt-tools .
dos2unix nxt-tools/compile.sh
rm -rf bin
28 changes: 21 additions & 7 deletions plugins/robots/generators/nxt/nxtOsekCGenerator/nxtFlashTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,25 @@ bool NxtFlashTool::uploadProgram(const QFileInfo &fileInfo)
mCompileState = idle;
mSource = fileInfo;

#ifdef Q_OS_WIN
mCompileProcess.setWorkingDirectory(path());
mCompileProcess.start("cmd", { "/c", path("compile.bat")
+ " " + fileInfo.completeBaseName()
+ " " + fileInfo.absolutePath() });
#else
mCompileProcess.start("sh", { path("compile.sh") , fileInfo.absolutePath()});
#endif

auto osType = PlatformInfo::osType();
if (osType == "windows") {
auto line = path("compile.bat")
+ " " + fileInfo.completeBaseName()
+ " " + fileInfo.absolutePath()
+ " " + path("gnuarm");
mCompileProcess.start("cmd", { "/c", line});
}
else if (osType == "linux") {
auto line = "./compile.sh . " + fileInfo.absolutePath() +
" GNUARM_ROOT="+SettingsManager::value("pathToArmNoneEabi").toString();
mCompileProcess.start("/bin/bash", {"-c", line});
}
else {
QLOG_INFO() << "Platform: " << osType << "not supported for upload program";
return false;
}
information(tr("Uploading program started. Please don't disconnect robot during the process"));
return true;
}
Expand Down Expand Up @@ -291,6 +301,10 @@ void NxtFlashTool::readNxtCompileData()
"If you sure in their validness contact developers"));
} else {
error(tr("Could not upload program. Make sure the robot is connected and ON"));
if (PlatformInfo::osType() == "linux") {
error(tr("If you are using GNU/Linux visit "
"https://help.trikset.com/nxt/run-upload-programs to get instructions"));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* limitations under the License. */

#include "nxtOsekCGeneratorPlugin.h"

#include <QtCore/QDir>
#include <QtCore/QDateTime>
#include <QtWidgets/QApplication>
Expand All @@ -22,6 +21,7 @@
#include <qrkernel/platformInfo.h>
#include <qrutils/singleton.h>

#include "QsLog.h"
#include "nxtOsekCMasterGenerator.h"

using namespace nxt::osekC;
Expand All @@ -37,6 +37,12 @@ NxtOsekCGeneratorPlugin::NxtOsekCGeneratorPlugin()
, mMasterGenerator(nullptr)
, mCommunicator(utils::Singleton<communication::UsbRobotCommunicationThread>::instance())
{
const QString key = "pathToArmNoneEabi";
const QString defaultPath = QDir(PlatformInfo::invariantSettingsPath("pathToNxtTools")).absolutePath()
+"/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi";
if (qReal::SettingsManager::value(key).isNull()) {
qReal::SettingsManager::setValue(key, defaultPath);
}
initActions();
initHotKeyActions();
}
Expand Down Expand Up @@ -96,7 +102,6 @@ void NxtOsekCGeneratorPlugin::onCurrentDiagramChanged(const TabInfo &info)
void NxtOsekCGeneratorPlugin::init(const kitBase::KitPluginConfigurator &configurator)
{
RobotsGeneratorPluginBase::init(configurator);

mFlashTool.reset(new NxtFlashTool(*mMainWindowInterface->errorReporter(), *mCommunicator));
connect(&*mFlashTool, &NxtFlashTool::uploadingComplete, this, &NxtOsekCGeneratorPlugin::onUploadingComplete);
}
Expand Down Expand Up @@ -223,21 +228,27 @@ void NxtOsekCGeneratorPlugin::uploadProgram()
void NxtOsekCGeneratorPlugin::checkNxtTools()
{
const QDir dir(PlatformInfo::invariantSettingsPath("pathToNxtTools"));
if (!dir.exists()) {
mNxtToolsPresent = false;
} else {
QDir gnuarm(dir.absolutePath() + "/gnuarm/bin");
QDir nexttool(dir.absolutePath() + "/nexttool");
QDir nxtOSEK(dir.absolutePath() + "/nxtOSEK");

#ifdef Q_OS_WIN
QFile compile1(dir.absolutePath() + "/compile.bat");
QFile compile2(dir.absolutePath() + "/compile.sh");
mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists()
&& compile1.exists() && compile2.exists();
#else
QFile compile(dir.absolutePath() + "/compile.sh");
mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists() && compile.exists();
#endif
auto compilePath = dir.absolutePath() + "/compile.sh";

auto nxtToolsPresent = dir.exists()
&& QFileInfo::exists(dir.absolutePath() + "/gnuarm")
&& QFileInfo::exists(dir.absolutePath() + "/nexttool")
&& QFileInfo::exists(dir.absolutePath() + "/nxtOSEK")
&& QFileInfo::exists(compilePath) && QFileInfo(compilePath).isFile();

if (!nxtToolsPresent) {
mNxtToolsPresent = false;
QLOG_ERROR() << "Missing" << dir.absolutePath() << "or mandatory subdirectory" <<
dir.entryList(QDir::Filter::NoFilter, QDir::SortFlag::DirsFirst | QDir::SortFlag::Name);
return;
}

auto osType = PlatformInfo::osType();
if (osType == "linux") {
mNxtToolsPresent = true;
}
else if (osType == "windows") {
auto compileBatPath = dir.absolutePath() + "/compile.bat";
mNxtToolsPresent = QFileInfo::exists(compileBatPath) && QFileInfo(compileBatPath).isFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

#include "nxtAdditionalPreferences.h"
#include "ui_nxtAdditionalPreferences.h"

#include <qrkernel/settingsManager.h>
#include <utils/widgets/comPortPicker.h>
#include "QsLog.h"
#include <QOperatingSystemVersion>
#include <qrkernel/platformInfo.h>

using namespace nxt;
using namespace qReal;
Expand All @@ -28,6 +30,13 @@ NxtAdditionalPreferences::NxtAdditionalPreferences(const QString &realRobotName,
{
mUi->setupUi(this);
mUi->robotImagePicker->configure("nxtRobot2DImage", tr("2D robot image:"));
if (PlatformInfo::osType() == "linux") {
mUi->compilerPicker->configure("pathToArmNoneEabi", tr("Path to arm-none-eabi:"));
setTextOnGeneratorLabel();
}
else {
mUi->generatorSettingsGroupBox->setVisible(false);
}
connect(mUi->manualComPortCheckbox, &QCheckBox::toggled
, this, &NxtAdditionalPreferences::manualComPortCheckboxChecked);
}
Expand All @@ -37,18 +46,44 @@ NxtAdditionalPreferences::~NxtAdditionalPreferences()
delete mUi;
}

void NxtAdditionalPreferences::setColorOnGeneratorLabel(QColor color){
QPalette palette = mUi->generatorLabel->palette();
palette.setColor(mUi->generatorLabel->foregroundRole(), color);
mUi->generatorLabel->setPalette(palette);
}

void NxtAdditionalPreferences::setTextOnGeneratorLabel(){
if (!mUi->compilerPicker->isSavedDirExist()){
mUi->generatorLabel->setText(tr("WARNING: Current directory doesn't exist. \nOpen "
"<a href=\"https://help.trikset.com/nxt/run-upload-programs\">link</a>"
" for instructions"));
mUi->generatorLabel->setTextFormat(Qt::RichText);
mUi->generatorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
mUi->generatorLabel->setOpenExternalLinks(true);
setColorOnGeneratorLabel(QColor("red"));
}
else {
mUi->generatorLabel->setText("Current directory exist.");
setColorOnGeneratorLabel(QColor("black"));
}
}

void NxtAdditionalPreferences::save()
{
SettingsManager::setValue("NxtBluetoothPortName", selectedPortName());
SettingsManager::setValue("NxtManualComPortCheckboxChecked", mUi->manualComPortCheckbox->isChecked());
mUi->robotImagePicker->save();
mUi->compilerPicker->save();
setTextOnGeneratorLabel();
emit settingsChanged();
}

void NxtAdditionalPreferences::restoreSettings()
{
ui::ComPortPicker::populate(*mUi->comPortComboBox, "NxtBluetoothPortName");
mUi->robotImagePicker->restore();
mUi->compilerPicker->restore();
setTextOnGeneratorLabel();

if (mUi->comPortComboBox->count() == 0) {
mUi->comPortComboBox->hide();
Expand All @@ -72,7 +107,11 @@ void NxtAdditionalPreferences::restoreSettings()

void NxtAdditionalPreferences::onRobotModelChanged(kitBase::robotModel::RobotModelInterface * const robotModel)
{
QLOG_DEBUG() << robotModel->name();
mUi->bluetoothSettingsGroupBox->setVisible(robotModel->name() == mBluetoothRobotName);
if (PlatformInfo::osType() == "linux") {
mUi->generatorSettingsGroupBox->setVisible(robotModel->name() == "NxtOsekCGeneratorRobotModel");
}
}

void NxtAdditionalPreferences::manualComPortCheckboxChecked(bool state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private slots:

private:
QString selectedPortName() const;

void setColorOnGeneratorLabel(QColor color);
void setTextOnGeneratorLabel();
Ui::NxtAdditionalPreferences *mUi;
const QString mBluetoothRobotName;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>414</width>
<height>164</height>
<width>401</width>
<height>284</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -27,22 +27,33 @@
<number>0</number>
</property>
<item>
<widget class="qReal::ui::ImagePicker" name="robotImagePicker">
</widget>
<widget class="qReal::ui::ImagePicker" name="robotImagePicker" native="true"/>
</item>
<item>
<widget class="QGroupBox" name="bluetoothSettingsGroupBox">
<widget class="QGroupBox" name="generatorSettingsGroupBox">
<property name="title">
<string>Bluetooth Settings</string>
<string>nxtOSEK Generator Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="comPortLabel">
<widget class="QLabel" name="generatorLabel">
<property name="text">
<string>COM Port:</string>
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="qReal::ui::dirPicker" name="compilerPicker" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="bluetoothSettingsGroupBox">
<property name="title">
<string>Bluetooth Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="1">
<widget class="QComboBox" name="comPortComboBox">
<property name="sizePolicy">
Expand All @@ -53,16 +64,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="directInputComPortLabel">
<property name="text">
<string>COM Port:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="directInputComPortLineEdit"/>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="noComPortsFoundLabel">
<property name="text">
Expand All @@ -73,13 +74,30 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="directInputComPortLineEdit"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="manualComPortCheckbox">
<property name="text">
<string>Specify COM port manually</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="comPortLabel">
<property name="text">
<string>COM Port:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="directInputComPortLabel">
<property name="text">
<string>COM Port:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand All @@ -92,6 +110,12 @@
<header>qrutils/widgets/imagePicker.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qReal::ui::dirPicker</class>
<extends>QWidget</extends>
<header>qrutils/widgets/dirPicker.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
Loading
Loading