Skip to content

Commit 44c239e

Browse files
Update README to follow EmbeddedSpaceWire structure with missing sections
Co-authored-by: Michal-Pogorzelec <80826463+Michal-Pogorzelec@users.noreply.github.com>
1 parent c54059e commit 44c239e

1 file changed

Lines changed: 172 additions & 53 deletions

File tree

README.md

Lines changed: 172 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,239 @@
1-
# Embedded-SDLP
1+
# EmbeddedSDLP
22

3-
A minimal Space Data Link Protocol (SDLP) implementation in C designed for embedded and resource-constrained space applications.
3+
Minimal, embedded-optimized implementation of **CCSDS Space Data Link Protocol (SDLP)** for TM (Telemetry) and TC (Telecommand) frame handling, following international standards.
44

5-
## Overview
5+
## Standards Compliance
66

7-
EmbeddedSDLP provides a lightweight implementation of TM (Telemetry) and TC (Telecommand) frame handling based on CCSDS standards. It's designed for use in spacecraft, CubeSats, and other space systems where code size and reliability are critical.
7+
- **CCSDS 132.0-B-3**: TM Space Data Link Protocol
8+
- **CCSDS 232.0-B-4**: TC Space Data Link Protocol
89

910
## Features
1011

12+
### Core Protocol Implementation
13+
1114
- **Telemetry (TM) Frame Handling**: Create, encode, and decode TM frames with CRC validation
1215
- **Telecommand (TC) Frame Handling**: Create, encode, and decode TC frames with CRC validation
13-
- **Minimal Dependencies**: Pure C99 with no external dependencies
14-
- **Embedded-Friendly**: Small memory footprint and predictable behavior
1516
- **CRC16 Error Detection**: Built-in frame error control field (FECF) for data integrity
1617
- **Configurable**: Support for virtual channels, spacecraft IDs, and frame sequence numbers
18+
- **TC Segment Header**: Optional MAP-based segmentation support (enabled with `TC_SEGMENT_HEADER_ENABLED`)
19+
20+
### Design Principles
21+
22+
- **Minimal footprint**: Small library size (stripped)
23+
- **Zero allocation**: Stack-based, no dynamic memory
24+
- **Embedded-optimized**: Pure C99, no external dependencies
25+
- **Portable**: Standard C99, big-endian network byte order
26+
- **Reliable**: CRC-16-CCITT frame error control
27+
28+
## Project Structure
29+
30+
```
31+
EmbeddedSDLP/
32+
├── include/
33+
│ ├── sdlp_common.h # Common definitions and CRC
34+
│ ├── sdlp_tm.h # TM frame definitions
35+
│ └── sdlp_tc.h # TC frame definitions
36+
├── src/
37+
│ ├── sdlp_common.c # CRC16 implementation
38+
│ ├── sdlp_tm.c # TM frame implementation
39+
│ └── sdlp_tc.c # TC frame implementation
40+
├── examples/
41+
│ ├── tm_example.c # TM frame example
42+
│ └── tc_example.c # TC frame example
43+
├── docs/
44+
│ ├── 132x0b3_TM_SDLP.pdf # CCSDS 132.0-B-3 standard
45+
│ └── 232x0b4e1c1_TC_SDLP.pdf # CCSDS 232.0-B-4 standard
46+
├── Makefile
47+
└── README.md
48+
```
1749

1850
## Building
1951

20-
Build the library and examples using Make:
52+
### Build Everything
2153

2254
```bash
23-
make all # Build library and examples
24-
make lib # Build library only
25-
make examples # Build examples only
26-
make test # Run example programs
27-
make clean # Clean build artifacts
55+
make all
2856
```
2957

3058
This will create:
3159
- `libsdlp.a` - Static library
3260
- `bin/tm_example` - TM frame example
3361
- `bin/tc_example` - TC frame example
3462

35-
## Usage
63+
### Build Library Only
64+
65+
```bash
66+
make lib
67+
# Produces: libsdlp.a (static)
68+
```
3669

37-
### Telemetry (TM) Example
70+
### Build Examples
71+
72+
```bash
73+
make examples
74+
```
75+
76+
### Run Tests
77+
78+
```bash
79+
make test
80+
```
81+
82+
### Clean
83+
84+
```bash
85+
make clean # Remove build artifacts
86+
```
87+
88+
## Quick Start
89+
90+
### Create and Send a TM Frame
3891

3992
```c
4093
#include "sdlp_tm.h"
4194

42-
sdlp_tm_frame_t frame;
4395
uint8_t buffer[1500];
4496
size_t encoded_size;
4597

4698
// Create a TM frame
47-
const char *data = "Temperature: 25C";
99+
const char *data = "Temperature: 25C, Voltage: 3.3V";
100+
sdlp_tm_frame_t frame;
48101
sdlp_tm_create_frame(&frame, 0x123, 2, (uint8_t *)data, strlen(data));
49102

50103
// Encode frame to buffer
51-
sdlp_tm_encode_frame(&frame, buffer, sizeof(buffer), &encoded_size);
104+
if (sdlp_tm_encode_frame(&frame, buffer, sizeof(buffer), &encoded_size) == SDLP_SUCCESS) {
105+
printf("TM frame encoded: %zu bytes\n", encoded_size);
106+
}
107+
```
52108
53-
// Decode frame from buffer
109+
### Parse an Incoming TM Frame
110+
111+
```c
54112
sdlp_tm_frame_t decoded;
55-
sdlp_tm_decode_frame(buffer, encoded_size, &decoded);
113+
if (sdlp_tm_decode_frame(buffer, encoded_size, &decoded) == SDLP_SUCCESS) {
114+
printf("Spacecraft ID: 0x%03X, Data: %.*s\n",
115+
decoded.header.spacecraft_id,
116+
(int)decoded.data_length, decoded.data);
117+
}
56118
```
57119

58-
### Telecommand (TC) Example
120+
### Create and Send a TC Frame
59121

60122
```c
61123
#include "sdlp_tc.h"
62124

63-
sdlp_tc_frame_t frame;
64125
uint8_t buffer[1500];
65126
size_t encoded_size;
66127

67128
// Create a TC frame
68-
const char *cmd = "ENABLE_SENSOR";
69-
sdlp_tc_create_frame(&frame, 0x456, 1, 0, (uint8_t *)cmd, strlen(cmd));
129+
const char *cmd = "SET_MODE SAFE";
130+
sdlp_tc_frame_t frame;
131+
sdlp_tc_create_frame(&frame, 0x123, 1, 42, (uint8_t *)cmd, strlen(cmd));
70132

71133
// Encode frame to buffer
72-
sdlp_tc_encode_frame(&frame, buffer, sizeof(buffer), &encoded_size);
134+
if (sdlp_tc_encode_frame(&frame, buffer, sizeof(buffer), &encoded_size) == SDLP_SUCCESS) {
135+
printf("TC frame encoded: %zu bytes\n", encoded_size);
136+
}
137+
```
73138
74-
// Decode frame from buffer
139+
### Parse an Incoming TC Frame
140+
141+
```c
75142
sdlp_tc_frame_t decoded;
76-
sdlp_tc_decode_frame(buffer, encoded_size, &decoded);
143+
if (sdlp_tc_decode_frame(buffer, encoded_size, &decoded) == SDLP_SUCCESS) {
144+
printf("Spacecraft ID: 0x%03X, Command: %.*s\n",
145+
decoded.header.spacecraft_id,
146+
(int)decoded.data_length, decoded.data);
147+
}
77148
```
78149

79-
## API Overview
150+
## API Reference
151+
152+
### Common
80153

81-
### Common Functions
82-
- `sdlp_crc16()` - Calculate CRC16 checksum
154+
```c
155+
// Calculate CRC-16-CCITT checksum
156+
uint16_t sdlp_crc16(const uint8_t *data, size_t length);
157+
```
83158
84159
### TM Functions
85-
- `sdlp_tm_create_frame()` - Create a TM frame with data
86-
- `sdlp_tm_encode_frame()` - Encode frame to byte buffer
87-
- `sdlp_tm_decode_frame()` - Decode frame from byte buffer
160+
161+
```c
162+
// Create a TM frame with payload data
163+
int sdlp_tm_create_frame(sdlp_tm_frame_t *frame, uint16_t spacecraft_id,
164+
uint8_t virtual_channel_id, const uint8_t *data,
165+
uint16_t data_length);
166+
167+
// Encode a TM frame into a byte buffer
168+
int sdlp_tm_encode_frame(const sdlp_tm_frame_t *frame, uint8_t *buffer,
169+
size_t buffer_size, size_t *encoded_size);
170+
171+
// Decode a TM frame from a byte buffer (validates CRC)
172+
int sdlp_tm_decode_frame(const uint8_t *buffer, size_t buffer_size,
173+
sdlp_tm_frame_t *frame);
174+
```
88175

89176
### TC Functions
90-
- `sdlp_tc_create_frame()` - Create a TC frame with data
91-
- `sdlp_tc_encode_frame()` - Encode frame to byte buffer
92-
- `sdlp_tc_decode_frame()` - Decode frame from byte buffer
93177

94-
All functions return `SDLP_SUCCESS` (0) on success or a negative error code on failure.
178+
```c
179+
// Create a TC frame with command data
180+
int sdlp_tc_create_frame(sdlp_tc_frame_t *frame, uint16_t spacecraft_id,
181+
uint8_t virtual_channel_id, uint8_t frame_seq_num,
182+
const uint8_t *data, uint16_t data_length);
183+
184+
// Encode a TC frame into a byte buffer
185+
int sdlp_tc_encode_frame(const sdlp_tc_frame_t *frame, uint8_t *buffer,
186+
size_t buffer_size, size_t *encoded_size);
187+
188+
// Decode a TC frame from a byte buffer (validates CRC)
189+
int sdlp_tc_decode_frame(const uint8_t *buffer, size_t buffer_size,
190+
sdlp_tc_frame_t *frame);
191+
192+
// Set TC segment header fields (requires TC_SEGMENT_HEADER_ENABLED)
193+
int sdlp_tc_set_segment_header(sdlp_tc_frame_t *frame,
194+
sdlp_tc_seq_flag_t sequence_flags, uint8_t map_id);
195+
```
196+
197+
All functions return `SDLP_SUCCESS` (0) on success or a negative error code on failure:
198+
- `SDLP_ERROR_INVALID_PARAM` (-1): NULL pointer or invalid parameter
199+
- `SDLP_ERROR_BUFFER_TOO_SMALL` (-2): Output buffer too small
200+
- `SDLP_ERROR_INVALID_FRAME` (-3): Frame structure invalid
201+
- `SDLP_ERROR_CRC_MISMATCH` (-4): CRC validation failed
95202
96-
## Project Structure
203+
## Protocol Stack
97204
98205
```
99-
.
100-
├── include/ # Header files
101-
│ ├── sdlp_common.h # Common definitions and CRC
102-
│ ├── sdlp_tm.h # TM frame definitions
103-
│ └── sdlp_tc.h # TC frame definitions
104-
├── src/ # Implementation files
105-
│ ├── sdlp_common.c
106-
│ ├── sdlp_tm.c
107-
│ └── sdlp_tc.c
108-
├── examples/ # Example programs
109-
│ ├── tm_example.c
110-
│ └── tc_example.c
111-
└── Makefile # Build configuration
206+
┌─────────────────────────────────────┐
207+
│ User Data (telemetry / command) │ Mission payload
208+
├─────────────────────────────────────┤
209+
│ TM / TC Frame (header + FECF) │ Spacecraft ID, Virtual Channel, CRC
210+
├─────────────────────────────────────┤
211+
│ Physical Link (RF, serial, fiber) │ Bit transmission
212+
└─────────────────────────────────────┘
112213
```
113214
114-
## Requirements
215+
## Memory Usage (Estimated)
216+
217+
- **Library (stripped)**: < 5 KB
218+
- **Per TM frame buffer**: `TM_PRIMARY_HEADER_SIZE` (6) + data + 2 bytes FECF
219+
- **Per TC frame buffer**: `TC_PRIMARY_HEADER_SIZE` (5) + data + 2 bytes FECF
220+
- **Maximum data per frame**: 1024 bytes (`TM_MAX_DATA_SIZE` / `TC_MAX_DATA_SIZE`)
221+
222+
## Limitations and Extensions
223+
224+
Current implementation focuses on core protocol features:
225+
226+
- No automatic retransmission handling
227+
- No flow control or bandwidth management
228+
- No segmentation beyond optional TC segment header
229+
- Single static frame counter (not thread-safe)
230+
231+
These can be extended as needed for specific mission requirements.
232+
233+
## References
115234
116-
- C compiler with C99 support (gcc, clang, etc.)
117-
- Make
235+
- CCSDS 132.0-B-3: TM Space Data Link Protocol ([docs/132x0b3_TM_SDLP.pdf](docs/132x0b3_TM_SDLP.pdf))
236+
- CCSDS 232.0-B-4: TC Space Data Link Protocol ([docs/232x0b4e1c1_TC_SDLP.pdf](docs/232x0b4e1c1_TC_SDLP.pdf))
118237
119238
## License
120239

0 commit comments

Comments
 (0)