From 6fdab5f85524341d8cf3e0d036d4af2e7a0a9a7d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 4 Oct 2026 12:18:03 +0000 Subject: [PATCH 1/4] Add CUC quick start code snapshot to README Co-authored-by: Michal-Pogorzelec <80826463+Michal-Pogorzelec@users.noreply.github.com> --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da5b65f..f24f7d0 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,23 @@ make clean ## Quick Start -See the examples. +Minimal CUC setup (from `examples/cuc_example.c`): + +```c +#include "cuc.h" + +cuc_format_t fmt = {CUC_EPOCH_CCSDS, 4, 2}; +cuc_time_t time = cuc_time_from_seconds(1234567.25); + +uint8_t buf[CUC_OCTETS_MAX]; +size_t written = 0; +if (cuc_encode(&time, &fmt, buf, sizeof(buf), &written) != CUC_OK) +{ + /* handle error */ +} +``` + +See `examples/cuc_example.c` for a full encode/decode flow. ## Memory Usage From 91fe964eddc029ec8faadaa682ecebfe13233abd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 4 Oct 2026 12:20:25 +0000 Subject: [PATCH 2/4] Add decode path to README quick start snippet Co-authored-by: Michal-Pogorzelec <80826463+Michal-Pogorzelec@users.noreply.github.com> --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index f24f7d0..f801f47 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,14 @@ if (cuc_encode(&time, &fmt, buf, sizeof(buf), &written) != CUC_OK) { /* handle error */ } + +cuc_format_t decoded_fmt; +cuc_time_t decoded; +size_t consumed = 0; +if (cuc_decode(buf, written, &decoded_fmt, &decoded, &consumed) != CUC_OK) +{ + /* handle error */ +} ``` See `examples/cuc_example.c` for a full encode/decode flow. From 349e8f63f0b1c73e1db1ba1a6c5f9ea210a59975 Mon Sep 17 00:00:00 2001 From: Michal Pogorzelec <80826463+Michal-Pogorzelec@users.noreply.github.com> Date: Sun, 4 Oct 2026 14:31:39 +0200 Subject: [PATCH 3/4] Refactor cuc_time_t initialization in README.md Updated cuc_time_t initialization to use struct initializer. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f801f47..abd1c41 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Minimal CUC setup (from `examples/cuc_example.c`): #include "cuc.h" cuc_format_t fmt = {CUC_EPOCH_CCSDS, 4, 2}; -cuc_time_t time = cuc_time_from_seconds(1234567.25); +cuc_time_t time = {UINT64_C(1234567), UINT64_C(1) << 62}; uint8_t buf[CUC_OCTETS_MAX]; size_t written = 0; From 3ff9f3346c41c6e258aadac6976950031369ce9c Mon Sep 17 00:00:00 2001 From: Michal Pogorzelec Date: Sun, 4 Oct 2026 14:37:16 +0200 Subject: [PATCH 4/4] refactor(example): update cuc_example.c for clarity and integer-only usage --- examples/cuc_example.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/cuc_example.c b/examples/cuc_example.c index 1bf1513..d283c5f 100644 --- a/examples/cuc_example.c +++ b/examples/cuc_example.c @@ -5,6 +5,11 @@ * Encodes a time value into a self-identified CUC code and decodes it back, * printing the intermediate octets. Demonstrates CCSDS 301.0-B-4, Section 3.2. * + * The example stays integer-only, like the codec itself, so it builds and runs + * unchanged on targets without an FPU and under -DCUC_NO_FLOAT. The optional + * cuc_time_to_seconds() / cuc_time_from_seconds() helpers are deliberately + * unused here. + * * OpenSpaceCode — https://github.com/OpenSpaceCode */ @@ -16,7 +21,10 @@ int main(void) { /* 4 octets of seconds, 2 octets of fraction, CCSDS 1958 TAI epoch. */ cuc_format_t fmt = {CUC_EPOCH_CCSDS, 4, 2}; - cuc_time_t time = cuc_time_from_seconds(1234567.25); + + /* 1234567.25 s since the epoch. The fraction is an unsigned Q0.64 binary + * fraction of a second, so a quarter second is 2^64 / 4, i.e. 1 << 62. */ + cuc_time_t time = {UINT64_C(1234567), UINT64_C(1) << 62}; uint8_t buf[CUC_OCTETS_MAX]; size_t written = 0; @@ -42,8 +50,15 @@ int main(void) return 1; } - printf("decoded: %.3f s (%u basic + %u fractional octets)\n", - cuc_time_to_seconds(&decoded), + /* Render the Q0.64 fraction as milliseconds without floating point. Scaling + * only the top 32 bits keeps the product inside uint64_t, and the discarded + * low bits are worth less than 2^-32 s. */ + uint32_t fraction_hi = (uint32_t)(decoded.fraction >> 32); + uint32_t milliseconds = (uint32_t)(((uint64_t)fraction_hi * 1000u) >> 32); + + printf("decoded: %llu.%03u s (%u basic + %u fractional octets)\n", + (unsigned long long)decoded.seconds, + milliseconds, decoded_fmt.basic_octets, decoded_fmt.fraction_octets); return 0;