|
| 1 | +# open-sent-c |
| 2 | + |
| 3 | +[](https://github.com/ucandevices/open-sent-c/actions/workflows/test.yml) |
| 4 | + |
| 5 | +A portable C implementation of the SAE J2716 SENT (Single Edge Nibble Transmission) |
| 6 | +protocol for embedded systems and host-side tooling. |
| 7 | + |
| 8 | +## Layout |
| 9 | + |
| 10 | +``` |
| 11 | +. |
| 12 | +├── *.h public API headers |
| 13 | +└── implementation/ library sources (.c) and platform ports |
| 14 | +``` |
| 15 | + |
| 16 | +The protocol layer (`sent_protocol`, `sent_encoder`, `sent_decoder`, `sent_crc`) |
| 17 | +is MCU-agnostic and uses the `hal.h` function-pointer interface to talk to |
| 18 | +hardware. Platform-specific ports live alongside the protocol code: |
| 19 | + |
| 20 | +- `hal_stm32f042.{h,c}` — STM32F042 (TIM input-capture RX, software TX) port |
| 21 | +- `hal_host.{h,c}` — host-side stub for unit tests |
| 22 | + |
| 23 | +## Public API |
| 24 | + |
| 25 | +- `sent_protocol.h` — frame/config types, nibble packing |
| 26 | +- `sent_encoder.h` — frame → tick intervals → microsecond timestamps |
| 27 | +- `sent_decoder.h` — microsecond timestamps → decoded frame |
| 28 | +- `sent_crc.h` — SAE J2716 4-bit CRC |
| 29 | +- `mode_manager.h` — RX/TX/STOPPED state machine + statistics |
| 30 | +- `hal.h` / `hal_config.h` — RX/TX HAL interfaces a port must implement |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +The library has no build system of its own — drop the headers on your |
| 35 | +include path and compile the relevant `.c` files in `implementation/` |
| 36 | +into your project. Pick the HAL port that matches your target (or write |
| 37 | +your own against `hal.h`). |
| 38 | + |
| 39 | +## Testing |
| 40 | + |
| 41 | +Unit tests live in `implementation/Tests/` and are built with plain GCC |
| 42 | +(`-std=c99`). They use a single-header framework (`test.h`) with no external |
| 43 | +dependencies. |
| 44 | + |
| 45 | +```sh |
| 46 | +cd implementation/Tests |
| 47 | +make run # build and run all tests |
| 48 | +make coverage # run tests + enforce 100% line and branch coverage |
| 49 | +``` |
| 50 | + |
| 51 | +Coverage is measured with **gcov/gcovr**. The `make coverage` target requires |
| 52 | +both tools to be on `PATH` (`apt-get install gcc gcovr` on Debian/Ubuntu) and |
| 53 | +fails if either metric drops below 100%. |
| 54 | + |
| 55 | +### CI |
| 56 | + |
| 57 | +A GitHub Actions workflow (`.github/workflows/test.yml`) runs on every push |
| 58 | +and pull request to `master`/`main`: |
| 59 | + |
| 60 | +1. Builds the test binary with `-O0 --coverage`. |
| 61 | +2. Runs all 126 tests — the job fails on any failing test. |
| 62 | +3. Generates a gcovr XML + text report and uploads it as a build artifact. |
| 63 | + |
| 64 | +Genuinely unreachable branches (dead code protected by configuration |
| 65 | +invariants) are annotated with `/* GCOV_EXCL_BR_LINE */` or suppressed via |
| 66 | +gcovr pattern filters so they do not inflate the denominator. |
| 67 | + |
| 68 | +### Coverage artifacts |
| 69 | + |
| 70 | +After each CI run the coverage report is uploaded as a GitHub Actions artifact |
| 71 | +named **`coverage`** and retained for 90 days. To download it: |
| 72 | + |
| 73 | +1. Open the [Actions tab](https://github.com/ucandevices/open-sent-c/actions). |
| 74 | +2. Click any completed workflow run. |
| 75 | +3. Scroll to the **Artifacts** section at the bottom of the page and download `coverage.zip`. |
| 76 | + |
| 77 | +The zip contains: |
| 78 | +- `coverage.txt` — human-readable summary table |
| 79 | +- `coverage.xml` — Cobertura XML (compatible with SonarQube, Codecov, VS Code extensions) |
| 80 | + |
| 81 | +## Reference integration |
| 82 | + |
| 83 | +[**SENTToUSB**](https://github.com/ucandevices/SENTToUSB) is a reference |
| 84 | +firmware project that integrates this library on an STM32F042 to expose a |
| 85 | +SENT sensor as a USB CDC / CAN device. It demonstrates the full stack: |
| 86 | +HAL port (`hal_stm32f042`) wired to real hardware timers and CAN-frame |
| 87 | +transport over USB. |
| 88 | + |
| 89 | +## License |
| 90 | + |
| 91 | +MIT — see [LICENSE](LICENSE). |
0 commit comments