A minimal, embedded-friendly C library implementing the CCSDS Unsegmented Time Code (CUC) — a pure binary count of seconds and binary fractions of a second from a defined epoch.
The library is deliberately small and dependency-free (only <stdint.h>,
<stddef.h>, <stdbool.h>), uses caller-supplied buffers (no heap), and keeps
its core encode/decode path integer-only so it fits comfortably on
microcontrollers.
- CCSDS 301.0-B-4 — Time Code Formats, Section 3.2 (CCSDS Unsegmented
Time Code). See
docs/ccsds_cuc.mdfor a field-by-field summary.
- Encode/decode the P-field (1 or 2 octets) and T-field separately, or as a combined self-identified code.
- Full format range: 1–7 basic (second) octets, 0–10 fractional octets.
- Both CCSDS 1958 TAI epoch (Level 1) and agency-defined epoch (Level 2).
- Format-independent time value (
cuc_time_t) using a Q0.64 binary fraction. - Optional
doubleconversion helpers, removable with-DCUC_NO_FLOAT. - Explicit, checked error codes; no dynamic allocation.
EmbeddedCUCTime/
├── include/
│ └── cuc.h # Public API
├── src/
│ └── cuc.c # Implementation
├── examples/
│ └── cuc_example.c # Encode/decode demo
├── tests/
│ ├── cunit.h # Minimal test framework
│ └── unit_tests.c # Unit tests
├── docs/
│ └── ccsds_cuc.md # CUC format reference notes
├── tools/
│ └── coverage-html.sh # Coverage report helper
├── Makefile
└── README.md
make # static library, example and test binaries in build/make lib # produces build/libcuc.amake example
./build/examples/cuc_examplemake run # or: make ctest && ./build/tests/ctestRequires gcovr (pip install gcovr):
make coverage-html # writes build/coverage/index.htmlmake cleanSee the examples.
- No heap usage: all buffers are caller-supplied.
- Largest CUC code:
CUC_OCTETS_MAX= 19 octets (2 P-field + 17 T-field). - State:
cuc_time_tandcuc_format_tare small plain structs.
- CUC is not UTC-based; leap-second corrections do not apply (use CDS/CCS for UTC-based time — not yet implemented here).
- The fractional value is stored to 64 bits (Q0.64). Encodings that request more than 8 fractional octets carry those extra low octets as zero.
- Integer seconds fit in
uint64_t; a field configured for fewer octets rolls over modulo 256 per octet, exactly as the standard specifies. - This library implements the CUC format only. CDS, CCS and ASCII time codes from CCSDS 301.0-B-4 are out of scope for this initial version.
- CCSDS 301.0-B-4, Time Code Formats, Blue Book, Issue 4, November 2010.
See the LICENSE file.