@@ -12,68 +12,41 @@ A lightweight C daemon for Raspberry Pi that reads raw CAN frames from a SocketC
1212
1313## Architecture
1414
15- ```
16- ┌──────────────────────────────────────────────────────────────────────┐
17- │ STARTUP │
18- │ │
19- │ can_telem.conf ──┐ │
20- │ CLI flags ───┼──► Parse config & credentials │
21- │ INFLUX_TOKEN ───┘ │ │
22- │ ├──► Load format.json → signal hash table│
23- │ ├──► Open SocketCAN (e.g. can0) │
24- │ ├──► Init CSV writer → /mnt/usb/ │
25- │ ├──► Init InfluxDB → libcurl │
26- │ └──► Init serial radio → /dev/ttyUSB0 │
27- └──────────────────────────────────────────────────────────────────────┘
28-
29- ┌──────────────────────────────────────────────────────────────────────┐
30- │ RUNTIME LOOP (poll) │
31- │ │
32- │ ┌───────────┐ ┌──────────────────┐ │
33- │ │ CAN frame│───►│ decoder_extract() │ │
34- │ │ arrives │ └────────┬─────────┘ │
35- │ └───────────┘ │ │
36- │ ┌────────┴──────────────────┐ │
37- │ │ │ │
38- │ ▼ ▼ │
39- │ ┌──────────────────┐ ┌─────────────────────┐ │
40- │ │ writer_append() │ │ influx_accumulate() │ │
41- │ │ → CSV row on │ │ serial_radio_ │ │
42- │ │ USB drive │ │ accumulate() │ │
43- │ └──────────────────┘ └──────────┬──────────┘ │
44- │ │ │
45- │ ┌───────────┐ │ │
46- │ │poll() 200 │ ┌───────────────────────────┘ │
47- │ │ms timeout │───►│ │
48- │ └───────────┘ ├──► influx_tick() │
49- │ │ Flush batch → InfluxDB Cloud (HTTPS/libcurl) │
50- │ │ │
51- │ └──► serial_radio_tick() │
52- │ Flush latest values → /dev/ttyUSB0 │
53- │ Format: <ts_ns>,<signal>,<value>\n │
54- └──────────────────────────────────────────────────────────────────────┘
55- ```
15+ ``` mermaid
16+ flowchart TD
17+ ConfFile[/"can_telem.conf"/]
18+ CLIFlags[/"CLI flags"/]
19+ Token[/"INFLUX_TOKEN"/]
5620
57- ### Data flow detail
21+ ConfFile & CLIFlags & Token --> ParseConfig[Parse config & credentials]
5822
59- ```
60- CAN frame (SocketCAN)
61- │
62- ┌─────────────▼──────────────┐
63- │ Lookup CAN ID in hash table│
64- │ → list of signal_def_t │
65- └─────────────┬──────────────┘
66- │ (one frame can carry N signals)
67- ┌────────────┼─────────────┐
68- ▼ ▼ ▼
69- ┌──────────┐ ┌──────────┐ ┌──────────┐
70- │ writer │ │ influx │ │ radio │
71- │ (always) │ │(optional)│ │(optional)│
72- └────┬─────┘ └────┬─────┘ └────┬─────┘
73- │ │ │
74- per-signal batched mean last value
75- CSV append → InfluxDB → UART radio
76- /mnt/usb/*.csv every N sec every N ms
23+ subgraph Startup
24+ ParseConfig --> LoadFormat[Load format.json\n→ signal hash table]
25+ ParseConfig --> OpenCAN[Open SocketCAN\ne.g. can0]
26+ ParseConfig --> InitCSV[Init CSV writer\n→ /mnt/usb/]
27+ ParseConfig --> InitInflux[Init InfluxDB\n→ libcurl]
28+ ParseConfig --> InitRadio[Init serial radio\n→ /dev/ttyUSB0]
29+ end
30+
31+ LoadFormat & OpenCAN & InitCSV & InitInflux & InitRadio --> PollLoop
32+
33+ subgraph Runtime [Runtime Loop]
34+ PollLoop[poll 200ms timeout]
35+
36+ PollLoop -->|CAN frame arrives| Decode[decoder_extract]
37+ Decode --> Lookup[Lookup CAN ID in hash table\n→ signal_def_t list\none frame can carry N signals]
38+
39+ Lookup --> Writer[writer_append\nper-signal CSV append\n/mnt/usb/*.csv]
40+ Lookup --> InfluxAcc[influx_accumulate\nbatched mean]
41+ Lookup --> RadioAcc[serial_radio_accumulate\nlast value]
42+
43+ Writer & InfluxAcc & RadioAcc --> PollLoop
44+
45+ PollLoop -->|timer expires| InfluxTick[influx_tick\nFlush batch → InfluxDB Cloud\nHTTPS / libcurl\nevery N sec]
46+ PollLoop -->|timer expires| RadioTick[serial_radio_tick\nFlush latest values → /dev/ttyUSB0\nFormat: ts_ns,signal,value\nevery N ms]
47+
48+ InfluxTick & RadioTick --> PollLoop
49+ end
7750```
7851
7952---
0 commit comments