From 68a38fba7d4bec74e2b49e385172a9de0e18ac86 Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Mon, 23 Jun 2025 13:31:50 +0300 Subject: [PATCH] Send vendor information on handshake (#461) * Send vendor information on handshake Embed vendor information into build parameters & defines so SlimeVR vendors can maintain their own firmware updates without adding new boards Bump protocol version to 21 * Fix build flags quotes * Report in GET TEST if magnetometer is not found * Remove vendor flags from platformio.ini * Fix 0 byte string sending and check for lengths * Formatting * Make sure the size assert actually works * Formatting * Update src/globals.h Co-authored-by: unlogisch04 <98281608+unlogisch04@users.noreply.github.com> * Log vendor information * Formatting --------- Co-authored-by: gorbit99 Co-authored-by: unlogisch04 <98281608+unlogisch04@users.noreply.github.com> --- platformio-tools.ini | 13 +++++++++++++ src/debug.h | 2 +- src/globals.h | 20 ++++++++++++++++++++ src/main.cpp | 32 ++++++++++++++++++++++++++++++++ src/network/connection.cpp | 22 +++++++++++++++++++--- src/serial/serialcommands.cpp | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 4 deletions(-) diff --git a/platformio-tools.ini b/platformio-tools.ini index e95a343..ba718e1 100644 --- a/platformio-tools.ini +++ b/platformio-tools.ini @@ -20,6 +20,11 @@ board = esp12e build_flags = ${env.build_flags} -D BOARD=BOARD_SLIMEVR + -D VENDOR_NAME='"SlimeVR"' + -D VENDOR_URL='"https://slimevr.dev"' + -D PRODUCT_NAME='"SlimeVR Tracker"' + -D UPDATE_ADDRESS='"SlimeVR/SlimeVR-Tracker-ESP"' + -D UPDATE_NAME='"BOARD_SLIMEVR-firmware"' [env:BOARD_SLIMEVR_V1_2] platform = espressif8266 @ 4.2.1 @@ -27,6 +32,11 @@ board = esp12e build_flags = ${env.build_flags} -D BOARD=BOARD_SLIMEVR_V1_2 + -D VENDOR_NAME='"SlimeVR"' + -D VENDOR_URL='"https://slimevr.dev"' + -D PRODUCT_NAME='"SlimeVR Tracker v1.2"' + -D UPDATE_ADDRESS='"SlimeVR/SlimeVR-Tracker-ESP"' + -D UPDATE_NAME='"BOARD_SLIMEVR_V1_2-firmware"' [env:BOARD_SLIMEVR_DEV] platform = espressif8266 @ 4.2.1 @@ -34,6 +44,8 @@ board = esp12e build_flags = ${env.build_flags} -D BOARD=BOARD_SLIMEVR_DEV + -D VENDOR_NAME='"SlimeVR"' + -D PRODUCT_NAME='"SlimeVR Tracker (dev)"' [env:BOARD_GLOVE_IMU_SLIMEVR_DEV] platform = espressif32 @ 6.7.0 @@ -44,6 +56,7 @@ build_flags = ${env.build_flags} -DESP32C3 -D BOARD=BOARD_GLOVE_IMU_SLIMEVR_DEV + -D PRODUCT_NAME='"SlimeVR Glove (dev)"' board = lolin_c3_mini [env:BOARD_NODEMCU] diff --git a/src/debug.h b/src/debug.h index cf49ea4..307eea7 100644 --- a/src/debug.h +++ b/src/debug.h @@ -94,7 +94,7 @@ // Not recommended for production #define ENABLE_INSPECTION false -#define PROTOCOL_VERSION 20 +#define PROTOCOL_VERSION 21 #ifndef FIRMWARE_VERSION #define FIRMWARE_VERSION "UNKNOWN" diff --git a/src/globals.h b/src/globals.h index 5f6da82..2198cc7 100644 --- a/src/globals.h +++ b/src/globals.h @@ -52,3 +52,23 @@ #ifndef EXPERIMENTAL_BNO_DISABLE_ACCEL_CALIBRATION #define EXPERIMENTAL_BNO_DISABLE_ACCEL_CALIBRATION true #endif + +#ifndef VENDOR_NAME +#define VENDOR_NAME "Unknown" +#endif + +#ifndef VENDOR_URL +#define VENDOR_URL "" +#endif + +#ifndef PRODUCT_NAME +#define PRODUCT_NAME "DIY SlimeVR Tracker" +#endif + +#ifndef UPDATE_ADDRESS +#define UPDATE_ADDRESS "" +#endif + +#ifndef UPDATE_NAME +#define UPDATE_NAME "" +#endif diff --git a/src/main.cpp b/src/main.cpp index 9f8ce15..706cb02 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -66,6 +66,38 @@ void setup() { logger.info("SlimeVR v" FIRMWARE_VERSION " starting up..."); + char vendorBuffer[512]; + size_t writtenLength; + + if (strlen(VENDOR_URL) == 0) { + sprintf( + vendorBuffer, + "Vendor: %s, product: %s%n", + VENDOR_NAME, + PRODUCT_NAME, + &writtenLength + ); + } else { + sprintf( + vendorBuffer, + "Vendor: %s (%s), product: %s%n", + VENDOR_NAME, + VENDOR_URL, + PRODUCT_NAME, + &writtenLength + ); + } + + if (strlen(UPDATE_ADDRESS) > 0 && strlen(UPDATE_NAME) > 0) { + sprintf( + vendorBuffer + writtenLength, + ", firmware update url: %s, name: %s", + UPDATE_ADDRESS, + UPDATE_NAME + ); + } + logger.info("%s", vendorBuffer); + statusManager.setStatus(SlimeVR::Status::LOADING, true); ledManager.setup(); diff --git a/src/network/connection.cpp b/src/network/connection.cpp index dd906df..edada9f 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -23,6 +23,8 @@ #include "connection.h" +#include + #include "GlobalVars.h" #include "logging/Logger.h" #include "packets.h" @@ -163,10 +165,14 @@ bool Connection::sendPacketNumber() { } bool Connection::sendShortString(const char* str) { - uint8_t size = strlen(str); + size_t size = strlen(str); - MUST_TRANSFER_BOOL(sendByte(size)); - MUST_TRANSFER_BOOL(sendBytes((const uint8_t*)str, size)); + assert(size <= 255); + + MUST_TRANSFER_BOOL(sendByte(static_cast(size))); + if (size > 0) { + MUST_TRANSFER_BOOL(sendBytes((const uint8_t*)str, size)); + } return true; } @@ -373,6 +379,16 @@ void Connection::sendTrackerDiscovery() { // Tracker type to hint the server if it's a glove or normal tracker or // something else MUST_TRANSFER_BOOL(sendByte(static_cast(TRACKER_TYPE))); + static_assert(std::string_view{VENDOR_NAME}.size() <= 255); + MUST_TRANSFER_BOOL(sendShortString(VENDOR_NAME)); + static_assert(std::string_view{VENDOR_URL}.size() <= 255); + MUST_TRANSFER_BOOL(sendShortString(VENDOR_URL)); + static_assert(std::string_view{PRODUCT_NAME}.size() <= 255); + MUST_TRANSFER_BOOL(sendShortString(PRODUCT_NAME)); + static_assert(std::string_view{UPDATE_ADDRESS}.size() <= 255); + MUST_TRANSFER_BOOL(sendShortString(UPDATE_ADDRESS)); + static_assert(std::string_view{UPDATE_NAME}.size() <= 255); + MUST_TRANSFER_BOOL(sendShortString(UPDATE_NAME)); return true; }, 0 diff --git a/src/serial/serialcommands.cpp b/src/serial/serialcommands.cpp index 00ce408..4d5f537 100644 --- a/src/serial/serialcommands.cpp +++ b/src/serial/serialcommands.cpp @@ -155,6 +155,39 @@ void printState() { statusManager.getStatus(), WiFiNetwork::getWiFiState() ); + + char vendorBuffer[512]; + size_t writtenLength; + + if (strlen(VENDOR_URL) == 0) { + sprintf( + vendorBuffer, + "Vendor: %s, product: %s%n", + VENDOR_NAME, + PRODUCT_NAME, + &writtenLength + ); + } else { + sprintf( + vendorBuffer, + "Vendor: %s (%s), product: %s%n", + VENDOR_NAME, + VENDOR_URL, + PRODUCT_NAME, + &writtenLength + ); + } + + if (strlen(UPDATE_ADDRESS) > 0 && strlen(UPDATE_NAME) > 0) { + sprintf( + vendorBuffer + writtenLength, + ", firmware update url: %s, name: %s", + UPDATE_ADDRESS, + UPDATE_NAME + ); + } + logger.info("%s", vendorBuffer); + for (auto& sensor : sensorManager.getSensors()) { logger.info( "Sensor[%d]: %s (%.3f %.3f %.3f %.3f) is working: %s, had data: %s", @@ -296,6 +329,8 @@ void cmdGet(CmdParser* parser) { const char* mag = sensor0->getAttachedMagnetometer(); if (mag) { logger.info("[TEST] Sensor[0] magnetometer: %s", mag); + } else { + logger.info("[TEST] Sensor[0] has no magnetometer attached"); } if (!sensor0->getHadData()) {