d5d5bad97c SEN5X: fix version parsing, VOC index reporting, and read-buffer handling (#11114)
* SEN5X: validate read lengths and initialize read buffers

readBuffer() returns the number of data bytes written (0 on error).
Check the return value against the number of bytes each caller
consumes before parsing, and zero-initialize the destination buffers:
findModel (5), getMeasurements (2), readValues (16), readPNValues
(20), and vocStateFromSensor (SEN5X_VOC_STATE_BUFFER_SIZE). This also
resolves maybe-uninitialized compiler warnings.

Small simplifications in the same area:

- Assign the converted measurement values directly; the isnan()
  checks on integer intermediates always took the conversion branch,
  so this preserves behavior.
- Fold a redundant state comparison in wakeUp() that immediately
  followed the assignment of the same value.
- Add an explicit 'return false' to the non-FSCom branches of
  loadState() and saveState().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* SEN5X: correct version parsing, VOC index gating, and cleaning wait

- getVersion() requested 3 raw I2C bytes (2 data bytes) but parsed
  versionBuffer[0..6], so the hardware and protocol versions came from
  the buffer's initialized-but-unwritten tail. Request the full
  12-byte reply (8 data bytes, the layout used by Sensirion's
  embedded-i2c-sen5x driver) and validate the received length before
  parsing. Also make the error message specific to the version read.
- Use floating-point division when deriving major.minor version
  numbers so minor versions below 10 are preserved (integer division
  reported e.g. firmware 2.2 as 2.00).
- Gate pm_voc_idx on vocIndex rather than noxIndex, so SEN54 devices
  (VOC but no NOx) report their VOC index.
- Widen the millis() snapshot in startCleaning() to uint32_t so the
  10-second fan-cleaning wait always measures elapsed time correctly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* SEN5X: add size checks to I2C helpers, stage VOC state, handle unavailable readings

- readBuffer(): accept only request sizes that are a multiple of 3
  (2 data bytes + 1 CRC per group), keeping the read loop's size
  arithmetic in bounds for any future caller. Current callers all
  comply.
- sendCommand(): likewise accept only even payload sizes on the write
  side.
- vocStateFromSensor(): read into a staging buffer and copy to
  vocState only after the full transfer verifies, so the stored state
  stays consistent if a read fails partway through.
- readValues()/readPNValues(): the sensor reports unavailable values
  as 0xFFFF (unsigned) / 0x7FFF (signed); map these to the
  UINT16_MAX / UINT32_MAX / FLT_MAX sentinels that getMetrics()
  checks, so unavailable channels are omitted from telemetry rather
  than scaled into numeric readings. Guard the cumulative-to-binned
  PN subtraction so the sentinels are preserved.
- readPNValues(): convert #/cm3 to #/0.1l as raw * 10, retaining the
  0.1-resolution digit that dividing before multiplying discarded.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* SEN5X: size read buffers in data bytes and document I2C helper conventions

readBuffer()'s size parameter is the raw I2C transfer size including
CRC bytes, while only the verified data bytes (2/3 of the request) are
written to the destination. Two call sites sized their buffers in raw
units (findModel: 48 for 32 data bytes; getMeasurements: 3 for 2);
both were safe over-allocations. Size them in data bytes so every call
site reflects the same convention, and document the raw-vs-data
contracts on the readBuffer() and sendCommand() declarations.

No functional change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* SEN5X: use named defines for I2C reply buffer sizes

Follow the SEN5X_VOC_STATE_BUFFER_SIZE pattern for all reply reads,
per review feedback: define each reply's payload size in data bytes,
size the destination buffer with it, request <size> + <size> / 2 raw
bytes, and compare the received count against the same define.

The version and product-name guards now compare against the full
reply size rather than the bytes parsed (previously 7 and 5);
readBuffer() returns either 0 or the full data count, so the
conditions accept and reject the same transfers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* SEN5X: document I2C helper size requirements instead of checking at runtime

Per review feedback: drop the runtime even-size and multiple-of-3
checks from sendCommand()/readBuffer() and state the requirements in
@brief/@param documentation on the declarations. All callers pass
sizes derived from the SEN5X_*_BUFFER_SIZE defines, which satisfy
both requirements.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* SEN5X: name the sensor's invalid-value constants

Per review feedback, define SEN5X_UINT_INVALID (0xFFFF) and
SEN5X_INT_INVALID (0x7FFF) for the values the sensor reports when a
reading is unavailable, and use them in the readValues()/readPNValues()
conversions in place of the numeric literals.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: oscgonfer <oscgonfer@users.noreply.github.com>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
2026-08-12 06:56:46 +00:00
2026-08-06 14:05:07 +00:00
2021-10-09 17:15:12 +11:00
2026-08-06 14:05:07 +00:00
2024-09-24 15:24:08 -05:00
2026-08-11 14:56:11 +02:00
2026-07-01 19:01:27 -05:00
2026-01-29 10:06:58 -06:00
2024-11-28 06:26:51 -06:00
2024-09-04 15:33:28 -07:00
2026-07-28 11:09:40 +00:00
2026-01-29 10:06:58 -06:00
2026-01-29 10:06:58 -06:00
2026-07-01 19:01:27 -05:00
2025-01-13 12:24:05 +08:00
2026-01-29 10:06:58 -06:00

Meshtastic Logo

Meshtastic Firmware

GitHub release downloads CI CLA assistant Fiscal Contributors Vercel

meshtastic%2Ffirmware | Trendshift

Overview

This repository contains the official device firmware for Meshtastic, an open-source LoRa mesh networking project designed for long-range, low-power communication without relying on internet or cellular infrastructure. The firmware supports various hardware platforms, including ESP32, nRF52, RP2040/RP2350, and Linux-based devices.

Meshtastic enables text messaging, location sharing, and telemetry over a decentralized mesh network, making it ideal for outdoor adventures, emergency preparedness, and remote operations.

Get Started

Join our community and help improve Meshtastic! 🚀

Stats

Alt

S
Description
No description provided
Readme GPL-3.0
72 MiB
0 Stars 1 Watchers 0 Forks
2026-09-01 21:05:50 +08:00
Languages
C++ 72.5%
C 23.7%
Python 2%
Shell 1.2%
Batchfile 0.2%
Other 0.2%