WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
spacepacketutils.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) ATTX LLC 2025. All Rights Reserved.
3 *
4 * This software and associated documentation (the "Software") are the
5 * proprietary and confidential information of ATTX, LLC. The Software is
6 * furnished under a license agreement between ATTX and the user organization
7 * and may be used or copied only in accordance with the terms of the agreement.
8 * Refer to 'license/attx_license.adoc' for standard license terms.
9 *
10 * EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11 * INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12 * REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13 * transmitted in any form or by any means, for any purpose, without the express
14 * written permission of ATTX, LLC.
15 ******************************************************************************/
16/*
17Space packet utils header file
18
19Author: Ryan Hughes
20
21CRC calculation functionality is adapted from cFS under the Apache 2.0 license
22https://github.com/nasa/cFE/blob/5dc12a7d2ac296ba59a3c3862936697587e67652/modules/es/fsw/src/cfe_es_api.c#L1575
23*/
24
25#ifndef COMMUNICATION_SPACEPACKETUTILS_HPP
26#define COMMUNICATION_SPACEPACKETUTILS_HPP
27
28#include <cstddef>
29#include <stdint.h>
30#include <algorithm>
31#include <cstdio>
32#include "architecture/Time.h"
33
34#include "types.h"
35
36namespace warpos {
37// CCSDS packet version number is 0 for standard telemetry and telecommand applications
38// Maximum length of the packet version number is 3 bits
39static const uint8 CCSDS_PACKET_VERSION_NUM = 0;
40
42static const uint32 CCSDS_PRI_HDR_LEN_BYTES = 6;
43
45static const uint32 CCSDS_SEC_HDR_LEN_BYTES = 8;
46
48static const uint32 CCSDS_FULL_HDR_LEN_BYTES = CCSDS_PRI_HDR_LEN_BYTES + CCSDS_SEC_HDR_LEN_BYTES;
49
51static const uint32 CRC16_LEN_BYTES = 2;
52
60int16 computeCRC16(uint32 &crc, const uint8 *packet_ptr, size_t length,
61 uint32 input_crc = 0);
62
70int16 validateCRC16(const uint32 &crc, const uint8 *packet_ptr, size_t length,
71 uint32 input_crc = 0);
72
78int16 computeFletcher8Checksum(const uint8* packet_ptr, uint8 length, uint16 &checksum);
79
85int16 validateFletcher8Checksum(const uint8* packet_ptr, uint8 length, const uint16 &checksum);
86
101int16 writeCCSDSHeader(uint8 *header, bool is_tlm, uint16 apid, uint8 seq_flag,
102 uint16 seq_count, uint16 data_len, clockwerk::Time timestamp, uint8 instance);
103
115int16 readCCSDSHeader(uint8 *header, bool &is_tlm, uint16 &apid,
116 uint8 &seq_flag, uint16 &seq_count, uint16 &data_len,
117 clockwerk::Time &timestamp, uint8 &instance);
118
122template <class T>
124{
125 char* const p = reinterpret_cast<char*>(&in);
126 for (size_t i = 0; i < sizeof(T) / 2; ++i)
127 std::swap(p[i], p[sizeof(T) - i - 1]);
128
129 return in;
130}
131
132template <class T, std::size_t N>
133std::array<T, N> changeEndian(const std::array<T, N>& in) {
134 std::array<T, N> out;
135 for (std::size_t i = 0; i < N; ++i)
136 out[i] = changeEndian(in[i]);
137 return out;
138}
139
140} // namespace clockwerk
141
142#endif
unsigned long uint32
Fastest unsigned integer of (at least) 32 bits width.
Definition half.hpp:510
Definition DeadReckon.cpp:20
int16 computeFletcher8Checksum(const uint8 *packet_ptr, uint8 length, uint16 &checksum)
Function to calculate the fletcher 8 checksum.
Definition spacepacketutils.cpp:97
int16 validateCRC16(const uint32 &crc, const uint8 *packet_ptr, size_t length, uint32 input_crc)
Function to validate the CRC16 checksum for a packet.
Definition spacepacketutils.cpp:81
int16 readCCSDSHeader(uint8 *header, bool &is_tlm, uint16 &apid, uint8 &seq_flag, uint16 &seq_count, uint16 &data_len, clockwerk::Time &timestamp, uint8 &instance)
Function to read the CCSDS packet header and extract its contents.
Definition spacepacketutils.cpp:188
T changeEndian(T in)
Change the endianness of a number.
Definition spacepacketutils.hpp:123
int16 validateFletcher8Checksum(const uint8 *packet_ptr, uint8 length, const uint16 &checksum)
Function to validate the fletcher8 checksum for a packet.
Definition spacepacketutils.cpp:110
int16 writeCCSDSHeader(uint8 *header, bool is_tlm, uint16 apid, uint8 seq_flag, uint16 seq_count, uint16 data_len, clockwerk::Time timestamp, uint8 instance)
Function to write the CCSDS packet header.
Definition spacepacketutils.cpp:126
int16 computeCRC16(uint32 &crc, const uint8 *packet_ptr, size_t length, uint32 input_crc)
Function to compute the CRC16 checksum for a packet.
Definition spacepacketutils.cpp:50