Compare commits

...

7 Commits

Author SHA1 Message Date
unlogisch04
f46d20f5cb add Serial Buffer to limit the data written in 1 cycle 2026-03-23 19:57:46 +01:00
dependabot[bot]
939ad705ce Bump actions/upload-artifact from 6 to 7 (#517)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-02 15:01:06 +03:00
Sapphire
7d800efdbf Don't set m_LastPacketTimestamp on handshake when we are connected (#513)
If another tracker is trying to find the server, they will send the
handshake packet to the whole network, which prevents us from realising
if the connection to server has timed out.
2026-01-25 07:07:30 +02:00
Butterscotch!
12f4b22dac Revert "Unfuck accelerometer" (#480)
* Revert "Unfuck accelerometer"

This reverts commit 0425f66561.

* Bump protocol version
2026-01-07 08:56:52 +03:00
dependabot[bot]
6cd29c7cea Bump actions/checkout from 5 to 6 (#497)
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-15 11:09:31 +03:00
dependabot[bot]
33dc84c00b Bump actions/cache from 4 to 5 (#504)
Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-15 11:08:07 +03:00
dependabot[bot]
37658155c7 Bump actions/upload-artifact from 5 to 6 (#503)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-15 11:07:54 +03:00
9 changed files with 201 additions and 11 deletions

View File

@@ -14,7 +14,7 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: jidicula/clang-format-action@v4.14.0
with:
clang-format-version: "17"
@@ -33,8 +33,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/cache@v4
- uses: actions/checkout@v6
- uses: actions/cache@v5
with:
path: |
~/.cache/pip
@@ -58,7 +58,7 @@ jobs:
run: python ./ci/build.py
- name: Upload binaries
uses: actions/upload-artifact@v5
uses: actions/upload-artifact@v7
with:
name: binaries
path: ./build/*.bin

View File

@@ -96,7 +96,7 @@
// Not recommended for production
#define ENABLE_INSPECTION false
#define PROTOCOL_VERSION 21
#define PROTOCOL_VERSION 22
#ifndef FIRMWARE_VERSION
#define FIRMWARE_VERSION "UNKNOWN"

110
src/logging/LogBuffer.cpp Normal file
View File

@@ -0,0 +1,110 @@
#include "LogBuffer.h"
namespace SlimeVR::Logging {
bool LogBuffer::addLog(const char* message) {
size_t len = strlen(message);
// Need space for message + null terminator + length prefix (2 bytes)
size_t required = len + 3;
if (required > getAvailableSpace()) {
// Buffer full, drop the message or overwrite oldest
return false;
}
// Write length as 2-byte prefix (little endian)
m_Buffer[m_WritePos] = (len >> 8) & 0xFF;
m_WritePos = (m_WritePos + 1) % MAX_BUFFER_SIZE;
m_Buffer[m_WritePos] = len & 0xFF;
m_WritePos = (m_WritePos + 1) % MAX_BUFFER_SIZE;
// Write message
for (size_t i = 0; i < len; i++) {
m_Buffer[m_WritePos] = message[i];
m_WritePos = (m_WritePos + 1) % MAX_BUFFER_SIZE;
}
// Write null terminator
m_Buffer[m_WritePos] = '\0';
m_WritePos = (m_WritePos + 1) % MAX_BUFFER_SIZE;
return true;
}
void LogBuffer::processCycle() {
size_t bytesWritten = 0;
while (m_WritePos != m_ReadPos && bytesWritten < MAX_BYTES_PER_CYCLE) {
size_t msgLen = getNextMessageLength();
if (msgLen == 0 || bytesWritten + msgLen > MAX_BYTES_PER_CYCLE) {
// Message too large for this cycle or corrupted
break;
}
// Skip length prefix
m_ReadPos = (m_ReadPos + 2) % MAX_BUFFER_SIZE;
// Read and print message
for (size_t i = 0; i < msgLen; i++) {
Serial.write(m_Buffer[m_ReadPos]);
m_ReadPos = (m_ReadPos + 1) % MAX_BUFFER_SIZE;
}
// Skip null terminator
m_ReadPos = (m_ReadPos + 1) % MAX_BUFFER_SIZE;
bytesWritten += msgLen;
}
}
size_t LogBuffer::getPendingBytes() const {
if (m_WritePos >= m_ReadPos) {
return m_WritePos - m_ReadPos;
} else {
return MAX_BUFFER_SIZE - m_ReadPos + m_WritePos;
}
}
void LogBuffer::flushAll() {
while (m_WritePos != m_ReadPos) {
size_t msgLen = getNextMessageLength();
if (msgLen == 0) {
break; // Corrupted buffer
}
// Skip length prefix
m_ReadPos = (m_ReadPos + 2) % MAX_BUFFER_SIZE;
// Read and print message
for (size_t i = 0; i < msgLen; i++) {
Serial.write(m_Buffer[m_ReadPos]);
m_ReadPos = (m_ReadPos + 1) % MAX_BUFFER_SIZE;
}
// Skip null terminator
m_ReadPos = (m_ReadPos + 1) % MAX_BUFFER_SIZE;
}
}
size_t LogBuffer::getAvailableSpace() const {
size_t used = getPendingBytes();
return MAX_BUFFER_SIZE - used - 1; // -1 to distinguish full from empty
}
size_t LogBuffer::getNextMessageLength() const {
if (m_WritePos == m_ReadPos) {
return 0;
}
size_t pos = m_ReadPos;
uint8_t highByte = m_Buffer[pos];
pos = (pos + 1) % MAX_BUFFER_SIZE;
uint8_t lowByte = m_Buffer[pos];
return (highByte << 8) | lowByte;
}
} // namespace SlimeVR::Logging

46
src/logging/LogBuffer.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef LOGGING_LOGBUFFER_H
#define LOGGING_LOGBUFFER_H
#include <Arduino.h>
namespace SlimeVR::Logging {
class LogBuffer {
public:
static constexpr size_t MAX_BUFFER_SIZE = 4096; // Total buffer size
static constexpr size_t MAX_BYTES_PER_CYCLE = 512; // Max bytes to output per cycle
static LogBuffer& getInstance() {
static LogBuffer instance;
return instance;
}
// Add a log message to the buffer
bool addLog(const char* message);
// Process buffered logs up to MAX_BYTES_PER_CYCLE
void processCycle();
// Check if there are pending logs
bool hasPendingLogs() const { return m_WritePos != m_ReadPos; }
// Get number of bytes pending
size_t getPendingBytes() const;
// Force flush all pending logs (for critical errors or shutdown)
void flushAll();
private:
LogBuffer() : m_Buffer{0}, m_WritePos(0), m_ReadPos(0) {}
char m_Buffer[MAX_BUFFER_SIZE];
volatile size_t m_WritePos;
volatile size_t m_ReadPos;
size_t getAvailableSpace() const;
size_t getNextMessageLength() const;
};
} // namespace SlimeVR::Logging
#endif

View File

@@ -63,6 +63,23 @@ void Logger::log(Level level, const char* format, va_list args) const {
strcat(buf, m_Tag);
}
Serial.printf("[%-5s] [%s] %s\n", levelToString(level), buf, buffer);
// Format complete log message
char fullMessage[384]; // Enough for header + message
snprintf(fullMessage, sizeof(fullMessage), "[%-5s] [%s] %s\n", levelToString(level), buf, buffer);
// Add to buffer or write directly for critical messages
if (level >= ERROR) {
// Critical messages: write immediately and flush buffer
LogBuffer::getInstance().flushAll();
Serial.print(fullMessage);
} else {
// Normal messages: add to buffer
if (!LogBuffer::getInstance().addLog(fullMessage)) {
// Buffer full, try to make space
LogBuffer::getInstance().processCycle();
// Try again
LogBuffer::getInstance().addLog(fullMessage);
}
}
}
} // namespace SlimeVR::Logging

View File

@@ -4,6 +4,7 @@
#include <Arduino.h>
#include "Level.h"
#include "LogBuffer.h"
#include "debug.h"
namespace SlimeVR::Logging {
@@ -79,12 +80,20 @@ private:
strcat(buf, m_Tag);
}
Serial.printf("[%-5s] [%s] %s", levelToString(level), buf, str);
// Build array log message
char header[256];
snprintf(header, sizeof(header), "[%-5s] [%s] %s", levelToString(level), buf, str);
// For arrays, we'll output directly to avoid excessive buffering
// But for critical levels, flush first
if (level >= ERROR) {
LogBuffer::getInstance().flushAll();
}
Serial.print(header);
for (size_t i = 0; i < size; i++) {
Serial.print(array[i]);
}
Serial.println();
}

View File

@@ -159,6 +159,9 @@ void loop() {
OTA::otaUpdate();
networkManager.update();
// Process buffered logs
SlimeVR::Logging::LogBuffer::getInstance().processCycle();
#if DEBUG_MEASURE_SENSOR_TIME_TAKEN
sensorMeasurer.before();
#endif

View File

@@ -664,7 +664,6 @@ void Connection::update() {
return;
}
m_LastPacketTimestamp = millis();
int len = m_UDP.read(m_Packet, sizeof(m_Packet));
#ifdef DEBUG_NETWORK
@@ -679,6 +678,12 @@ void Connection::update() {
(void)packetSize;
#endif
if (static_cast<ReceivePacketType>(m_Packet[3]) == ReceivePacketType::Handshake) {
m_Logger.warn("Handshake received again, ignoring");
return;
}
m_LastPacketTimestamp = millis();
switch (static_cast<ReceivePacketType>(m_Packet[3])) {
case ReceivePacketType::HeartBeat:
sendHeartbeat();
@@ -688,8 +693,7 @@ void Connection::update() {
break;
case ReceivePacketType::Handshake:
// Assume handshake successful
m_Logger.warn("Handshake received again, ignoring");
// handled above
break;
case ReceivePacketType::Command:

View File

@@ -33,6 +33,7 @@ SensorStatus Sensor::getSensorState() {
void Sensor::setAcceleration(Vector3 a) {
acceleration = a;
sensorOffset.sandwich(acceleration);
newAcceleration = true;
}