-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPacket.h
More file actions
83 lines (71 loc) · 2.52 KB
/
Packet.h
File metadata and controls
83 lines (71 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Copyright © 2020-2025 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
//
// m17ref is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// m17ref is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// with this software. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#pragma once
#include <cstdint>
#include <string.h>
#include <memory>
#include "Callsign.h"
using SM17RefPacket = struct __attribute__((__packed__)) reflector_tag {
char magic[4];
uint8_t cscode[6];
char mod;
}; // 11 bytes (but sometimes 4 or 10 bytes)
#define MAX_PACKET_SIZE 859
class CPacket
{
public:
CPacket();
// get pointer to different parts
uint8_t *GetData() { return data; }
const uint8_t *GetCData() const { return data; }
uint8_t *GetDstAddress();
const uint8_t *GetCDstAddress() const;
uint8_t *GetSrcAddress();
const uint8_t *GetCSrcAddress() const;
uint8_t *GetMetaData();
const uint8_t *GetCMetaData() const;
uint8_t *GetVoiceData(bool firsthalf = true);
const uint8_t *GetCVoiceData(bool firsthalf = true) const;
// get various 16 bit value in host byte order
uint16_t GetStreamId() const;
uint16_t GetFrameType() const;
uint16_t GetFrameNumber() const;
uint16_t GetCRC(bool first = true) const;
// set 16 bit values in network byte order
void SetStreamId(uint16_t sid);
void SetFrameType(uint16_t ft);
void SetFrameNumber(uint16_t fn);
// get the state data
size_t GetSize() const { return size; }
bool IsStreamData() const { return isstream; }
bool IsPacketData() const { return not isstream; }
bool IsLastPacket() const;
// set state data
void SetSize(size_t n) { size = n; }
void SetType(bool iss) { isstream = iss; }
void Initialize(size_t n, bool iss);
// calculate and set CRC value(s)
void CalcCRC();
private:
uint16_t Get16At(size_t pos) const;
void Set16At(size_t pos, uint16_t val);
bool isstream;
size_t size;
uint8_t data[MAX_PACKET_SIZE+1];
};