GNU Radio's SATNOGS Package
ax25.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
4 *
5 * Copyright (C) 2016-2023, Libre Space Foundation <http://libre.space>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * SPDX-License-Identifier: GNU General Public License v3.0 or later
21 */
22
23
24#ifndef INCLUDE_SATNOGS_AX25_H_
25#define INCLUDE_SATNOGS_AX25_H_
26
28#include <CRC.h>
29#include <cstddef>
30#include <cstdint>
31
32namespace gr {
33
34namespace satnogs {
35
36class ax25
37{
38public:
39 static constexpr size_t min_addr_len = 14;
40 static constexpr size_t max_addr_len = (2 * 7 + 8 * 7);
41 static constexpr size_t max_ctrl_len = 2;
42 static constexpr size_t pid_len = 1;
43 static constexpr size_t max_header_len = (max_addr_len + max_ctrl_len + pid_len);
44 static constexpr uint8_t sync_flag = 0x7e;
45 static constexpr size_t callsign_max_len = 6;
46
47 /**
48 * AX.25 Frame types
49 */
50 enum class frame_type {
51 I_FRAME, //!< Information frame
52 S_FRAME, //!< Supervisory frame
53 U_FRAME, //!< Unnumbered frame
54 UI_FRAME //!< Unnumbered information frame
55 };
56
57 static uint16_t crc(const uint8_t* buffer, size_t len)
58 {
59 const auto& crc = CRC::CRC_16_X25();
60 return CRC::Calculate(buffer, len, crc);
61 }
62
63 static bool crc_valid(const uint8_t* buffer, size_t len)
64 {
65 const auto& crc = CRC::CRC_16_X25();
66 auto fcs = CRC::Calculate(buffer, len - sizeof(uint16_t), crc);
67 uint16_t recv_fcs = (((uint16_t)buffer[len - 1]) << 8) | buffer[len - 2];
68 return recv_fcs == fcs;
69 }
70};
71
72} // namespace satnogs
73} // namespace gr
74
75#endif /* INCLUDE_SATNOGS_AX25_H_ */
static const Parameters< crcpp_uint16, 16 > & CRC_16_X25()
Returns a set of parameters for CRC-16 X-25 (aka CRC-16 IBM-SDLC, CRC-16 ISO-HDLC,...
Definition: CRC.h:1767
static CRCType Calculate(const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > &parameters)
Computes a CRC.
Definition: CRC.h:463
Definition: ax25.h:37
static constexpr size_t callsign_max_len
Definition: ax25.h:45
static constexpr size_t max_addr_len
Definition: ax25.h:40
static constexpr size_t min_addr_len
Definition: ax25.h:39
static constexpr size_t max_ctrl_len
Definition: ax25.h:41
static constexpr uint8_t sync_flag
Definition: ax25.h:44
static constexpr size_t max_header_len
Definition: ax25.h:43
static uint16_t crc(const uint8_t *buffer, size_t len)
Definition: ax25.h:57
frame_type
Definition: ax25.h:50
static constexpr size_t pid_len
Definition: ax25.h:42
static bool crc_valid(const uint8_t *buffer, size_t len)
Definition: ax25.h:63
Definition: crc.h:44
Definition: amsat_duv_decoder.h:29