Skip to content

Commit

Permalink
Attempt to fix WinUSB problem with NXT (#1663)
Browse files Browse the repository at this point in the history
* Attempt to fix WinUSB problem with NXT
* Fix Centos build, temporary disable installer build on CentOS7
  • Loading branch information
iakov committed Jun 8, 2023
1 parent 3fa2047 commit f7f363b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/centos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: |
yum install -y epel-release centos-release-scl
yum install -y libusbx-devel curl wget devtoolset-${{ matrix.gcc-version }}-{gcc-c++,make,libasan-devel,libubsan-devel} \
rh-git227-git-core ccache zlib-devel rsync rh-python3${{ matrix.python-minor }}-python-{devel,pip} mesa-libGL-devel systemd-devel fontconfig p7zip which
rh-git227-git-core ccache zlib-devel rsync rh-python3${{ matrix.python-minor }}-python-{devel,pip,urllib3} mesa-libGL-devel systemd-devel fontconfig p7zip which
yum install -y libxkbcommon-x11 qt5-qtbase-gui #no desire to enumerate all required libraries for QtIFw
yum install -y pulseaudio-libs-glib2 # to run TS and 2D-model even with `minimal` platform
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
python3 -m pip install -U pip
python3 -m pip install aqtinstall
aqt install-qt linux desktop ${{ matrix.qt-version }} -O /Qt -m qtscript --archives qtbase qtmultimedia qtsvg qtscript qttools qtserialport qtimageformats icu qtwayland
aqt install-tool linux desktop tools_ifw -O /Qt
# aqt install-tool linux desktop tools_ifw -O /Qt
echo "Qt5_Dir=$(ls -1d /Qt/5*/* | head -n 1)" >> $GITHUB_ENV
echo "IQTA_TOOLS=/Qt/Tools" >> $GITHUB_ENV
Expand All @@ -123,7 +123,8 @@ jobs:
set -xueo pipefail
uname -a
rsync --version
ls "$IQTA_TOOLS/" "$Qt5_Dir/"
# ls "$IQTA_TOOLS/"
ls "$Qt5_Dir/"
qmake --version && qmake -query
python3 --version
which g++
Expand Down Expand Up @@ -174,10 +175,11 @@ jobs:
run: |
set -vx
cd "$GITHUB_WORKSPACE"/installer
export TRIK_PYTHON3_VERSION_MINOR="${{ matrix.python-minor }}"
bash -xv ./build-trik-studio.sh "${Qt5_Dir}/bin" $(ls -1d "${IQTA_TOOLS}"/QtInstallerFramework/*/bin | head -n 1) "${{ env.BUILD_DIR }}"
export TRIK_PYTHON3_VERSION_MINOR=${{ matrix.python-minor }}
# bash -xv ./build-trik-studio.sh "${Qt5_Dir}/bin" $(ls -1d "${IQTA_TOOLS}"/QtInstallerFramework/*/bin | head -n 1) "${{ env.BUILD_DIR }}"
- name: Push installer
if: false
uses: actions/upload-artifact@v2
with:
name: trik-studio-auto-installer-linux-qt${{ matrix.qt-version }}
Expand All @@ -199,7 +201,7 @@ jobs:
run: echo "GITHUB_REF_SLUG=${{ env.CURRENT_TAG }}" >> $GITHUB_ENV

- name: Deploy installer
if: ${{ matrix.deploy-installer && github.event_name != 'pull_request' && github.repository_owner == 'trikset' }}
if: ${{ false && matrix.deploy-installer && github.event_name != 'pull_request' && github.repository_owner == 'trikset' }}
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.DL_PRIVATE_SSH_KEY }}" > ~/.ssh/id_rsa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,22 @@ bool UsbRobotCommunicationThread::connectImpl(bool firmwareMode, int vid, int pi

// old tool libnxt says that it should be 1
const int possibleConfigurations = device_descriptor.bNumConfigurations;
bool configurationFound = false;
int configurationFound = 0;
bool interfaceFound = false;
for (int configuration = 0; configuration <= possibleConfigurations; configuration++) {
const int err = libusb_set_configuration(mHandle, configuration);
if (err < 0 && err != LIBUSB_ERROR_NOT_FOUND && err != LIBUSB_ERROR_INVALID_PARAM) {
if (err < 0) {
QLOG_ERROR() << "libusb_set_configuration for NXT returned" << err << "for configuration" << configuration;
} else if (err >= 0) {
configurationFound = true;
libusb_config_descriptor *config_descriptor = new libusb_config_descriptor;
}
if (err >= 0
|| err != LIBUSB_ERROR_NOT_FOUND
|| err != LIBUSB_ERROR_INVALID_PARAM
// Seems like a WinUSB driver supports only one configuration
// and sometimes even complains on libusb_set_configuration API call
// Probably, this line for LIBUSB_ERROR_NOT_SUPPORTED is redundant or obsolete in 2023
|| err != LIBUSB_ERROR_NOT_SUPPORTED) {
configurationFound = configuration + 1; // Encode number as boolean value
auto config_descriptor = new libusb_config_descriptor;
const int err = libusb_get_active_config_descriptor(devices[i], &config_descriptor);
if (err >= 0) {
const int possibleInterfaces = config_descriptor->bNumInterfaces;
Expand Down Expand Up @@ -155,20 +162,20 @@ bool UsbRobotCommunicationThread::connectImpl(bool firmwareMode, int vid, int pi
}

if (!configurationFound) {
QLOG_ERROR() << "No appropriate configuration found among all possible configurations. Giving up.";
emit connected(false, tr("USB Device configuration problem. Try to restart TRIK Studio and re-plug NXT."));
QLOG_ERROR() << "No appropriate configuration found among all possible configurations. Giving up.";
libusb_close(mHandle);
mHandle = nullptr;
libusb_free_device_list(devices, 1);
emit connected(false, tr("USB Device configuration problem. Try to restart TRIK Studio and re-plug NXT."));
return false;
}

if (!interfaceFound) {
QLOG_ERROR() << "No appropriate interface found among possible interfaces. Giving up.";
emit connected(false, tr("NXT device is already used by another software."));
libusb_close(mHandle);
mHandle = nullptr;
libusb_free_device_list(devices, 1);
emit connected(false, tr("NXT device is already used by another software."));
return false;
}

Expand All @@ -186,14 +193,14 @@ bool UsbRobotCommunicationThread::connectImpl(bool firmwareMode, int vid, int pi
const bool correctFirmwareResponce = !firmwareMode ||
(handshakeResponse.length() == 4 && handshakeResponse[2] == '\n' && handshakeResponse[3] == '\r');
if (handshakeResponse.isEmpty() || !correctFirmwareResponce) {
emit connected(false, tr("NXT handshake procedure failed. Please contact developers."));
libusb_close(mHandle);
mHandle = nullptr;
libusb_free_device_list(devices, 1);
emit connected(false, tr("NXT handshake procedure failed. Please contact developers."));
return false;
}

QLOG_INFO() << "Connected successfully!";
QLOG_INFO() << "NXTUSB: Connected successfully with configuration" << (configurationFound - 1);
emit connected(true, QString());

if (!firmwareMode) {
Expand Down
4 changes: 2 additions & 2 deletions qrtranslations/fr/plugins/robots/nxtKit_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<context>
<name>nxt::communication::UsbRobotCommunicationThread</name>
<message>
<location filename="../../../../plugins/robots/common/nxtKit/src/communication/usbRobotCommunicationThread.cpp" line="+159"/>
<location filename="../../../../plugins/robots/common/nxtKit/src/communication/usbRobotCommunicationThread.cpp" line="+169"/>
<source>USB Device configuration problem. Try to restart TRIK Studio and re-plug NXT.</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -52,7 +52,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+20"/>
<location line="+17"/>
<source>Cannot find NXT device. Check robot connected and turned on and try again.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions qrtranslations/ru/plugins/robots/nxtKit_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<context>
<name>nxt::communication::UsbRobotCommunicationThread</name>
<message>
<location filename="../../../../plugins/robots/common/nxtKit/src/communication/usbRobotCommunicationThread.cpp" line="+159"/>
<location filename="../../../../plugins/robots/common/nxtKit/src/communication/usbRobotCommunicationThread.cpp" line="+169"/>
<source>USB Device configuration problem. Try to restart TRIK Studio and re-plug NXT.</source>
<translation>Проблема конфигурации USB-устройства. Попробуйте перезапустить TRIK Studio и перевоткнуть NXT в компьютер.</translation>
</message>
Expand All @@ -52,7 +52,7 @@
<translation>Процедура рукопожатия с NXT не была успешной. Пожалуйста, попробуйте еще раз, если эта ошибка снова появится, обратитесь к разработчикам.</translation>
</message>
<message>
<location line="+20"/>
<location line="+17"/>
<source>Cannot find NXT device. Check robot connected and turned on and try again.</source>
<translation>Устройство NXT не найдено. Проверьте, что робот включен и подключен к компьютеру и попробуйте еще раз.</translation>
</message>
Expand Down

0 comments on commit f7f363b

Please sign in to comment.