bristlemouth / bm_protocol

Primary Bristlemouth firmware repository
https://www.bristlemouth.org/
Apache License 2.0
12 stars 8 forks source link

fix: print the bridge network config in a single pass #151

Closed towynlin closed 3 months ago

towynlin commented 3 months ago

Previously the internal cbor stream handler would build a whole publish packet for every character or two!

This resulted in spotter console logs having the bridge network config being slowly printed a little at a time while other lines interrupt it.

Example spotter console log line with a couple nodes attached:

2024-07-19T07:42:38.207Z [BRIDGE_CFG] [INFO] Bridge network config: [[3126851968281441696, "bridge-dbg", 1499363141, 3152952663, {"sampleIntervalMs": 300000, "sampleDurationMs": 240000, "subsampleIntervalMs": 60000, "subsampleDurationMs": 30000, "subsampleEnabled": 0, "bridgePowerControllerEnabled": 0, "alignmentInterval5Min": 1, "ticksSamplingEnabled": 0, "samplesPerReport": 2, "transmitAggregations": 1, "currentReadingPeriodMs": 60000, "softReadingPeriodMs": 500, "rbrCodaReadingPeriodMs": 500, "turbidityReadingPeriodMs": 1000}], [10047966341406729948, "serial_bridge-dbg", 1499363141, 1985325339, {"sensorsPollIntervalMs": 10000, "sensorsCheckIntervalS": 60, "currentAggPeriodMin": 0.f, "nSkipReadings": 0, "readingIntervalMs": 60000, "payloadWdToS": 70, "plUartBaudRate": 9600, "dfu_confirm": 0, "rbrCodaType": 2}], [816502619147696319, "rbr_coda_example-dbg", 553272471, 3352688053, {"sensorsPollIntervalMs": 60000, "rbrCodaType": 2}]]

Notice that currentAggPeriodMin is 0.f which is annoying to parse in production tooling but we've determined that fixing it isn't worth the effort. It's the way tinycbor does "pretty" output. There are json output functions too, but we'd have to convert most numbers to strings, especially node IDs to prevent them from being rounded, because all json numbers are floating point under the hood.