Skip to content

Commit 3ce6f75

Browse files
add sequence flags type
1 parent e194960 commit 3ce6f75

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Build & run (host):
1919

2020
3. Run tests:
2121

22-
./tests/test_packet
22+
./tests/ctest
2323

2424
Notes
2525
- This is a minimal, small-footprint implementation designed for embedded use.

examples/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int main(void) {
77
const uint8_t payload[] = {'H', 'e', 'l', 'l', 'o', ' ', 'S', 'P'};
88
sp_packet_t pkt;
99
sp_packet_init(&pkt);
10-
sp_set_primary_header(&pkt, 0 /*version*/, 0 /*type*/, 1 /*sec hdr*/, 0x100, 0 /*seq flags*/, 1);
10+
sp_set_primary_header(&pkt, 0 /*version*/, 0 /*type*/, 1 /*sec hdr*/, 0x100, SP_SEQ_FLAG_UNSEGMENTED /*seq flags*/, 1);
1111
/* Example with a minimal secondary header containing flags and zero extra
1212
* bytes. flags byte LSB=1 requests CRC; byte1=0 indicates zero remaining sec
1313
* header bytes.
@@ -35,7 +35,7 @@ int main(void) {
3535
return 2;
3636
}
3737

38-
printf("Parsed APID=0x%03X seq=%u payload_len=%u\n", parsed.ph.apid,
38+
printf("Parsed APID=0x%03X seq count=%u payload_len=%u\n", parsed.ph.apid,
3939
parsed.ph.seq_count, parsed.payload_len);
4040
printf("Payload as ASCII: ");
4141
fwrite(parsed.payload, 1, parsed.payload_len, stdout);

include/space_packet.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
#include <stddef.h>
88
#include <stdint.h>
99

10+
typedef enum {
11+
SP_SEQ_FLAG_UNSEGMENTED = 0,
12+
SP_SEQ_FLAG_FIRST_SEGMENT = 1,
13+
SP_SEQ_FLAG_CONTINUING_SEGMENT = 2,
14+
SP_SEQ_FLAG_LAST_SEGMENT = 3
15+
} sp_seq_flag_t;
16+
1017
/* Primary header is 6 bytes (CCSDS-like):
1118
* - bytes 0-1: version(3), type(1), sec_hdr(1), apid(11)
1219
* - bytes 2-3: seq_flags(2), seq_count(14)
@@ -28,11 +35,11 @@ typedef struct {
2835
#endif
2936
/* sequence control */
3037
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
31-
unsigned seq_flags : 2;
38+
sp_seq_flag_t seq_flags : 2;
3239
unsigned seq_count : 14;
3340
#else
3441
unsigned seq_count : 14;
35-
unsigned seq_flags : 2;
42+
sp_seq_flag_t seq_flags : 2;
3643
#endif
3744
uint16_t packet_length;
3845
} sp_primary_header_t;
@@ -81,7 +88,7 @@ void sp_set_primary_header(sp_packet_t *pkt,
8188
uint8_t type,
8289
uint8_t sec_hdr_flag,
8390
uint16_t apid,
84-
uint8_t seq_flags,
91+
sp_seq_flag_t seq_flags,
8592
uint16_t seq_count);
8693

8794
/* Set secondary header pointer and length (application-owned memory). */

src/space_packet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void sp_set_primary_header(sp_packet_t *pkt,
190190
uint8_t type,
191191
uint8_t sec_hdr_flag,
192192
uint16_t apid,
193-
uint8_t seq_flags,
193+
sp_seq_flag_t seq_flags,
194194
uint16_t seq_count) {
195195
if (!pkt) return;
196196
pkt->ph.version = (unsigned)(version & 0x7);

tests/unit_tests.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static int test_roundtrip_with_secheader_crc(void) {
4545

4646
sp_packet_t pkt = {0};
4747
pkt.ph.apid = 0x123;
48+
pkt.ph.seq_flags = SP_SEQ_FLAG_UNSEGMENTED;
4849
pkt.ph.seq_count = 0x3;
4950
pkt.ph.sec_hdr_flag = 1;
5051
pkt.sec_hdr = sec_hdr;
@@ -70,6 +71,11 @@ static int test_roundtrip_with_secheader_crc(void) {
7071
}
7172

7273
ASSERT_EQ_INT(parsed.ph.apid, pkt.ph.apid);
74+
ASSERT_EQ_INT(parsed.ph.seq_count, pkt.ph.seq_count);
75+
ASSERT_EQ_INT(parsed.ph.seq_flags, pkt.ph.seq_flags);
76+
ASSERT_EQ_INT(parsed.ph.sec_hdr_flag, pkt.ph.sec_hdr_flag);
77+
ASSERT_EQ_INT(parsed.sec_hdr_len, pkt.sec_hdr_len);
78+
ASSERT_EQ_MEM(parsed.sec_hdr, pkt.sec_hdr, pkt.sec_hdr_len);
7379
ASSERT_EQ_INT(parsed.payload_len, pkt.payload_len);
7480
ASSERT_EQ_MEM(parsed.payload, pkt.payload, pkt.payload_len);
7581

0 commit comments

Comments
 (0)