Repository navigation
Expand file tree
/
Copy pathngham_packets.h
More file actions
69 lines (54 loc) · 1.97 KB
/
Copy pathngham_packets.h
File metadata and controls
69 lines (54 loc) · 1.97 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
//**************************************************************//
// NGHam protocol - Jon Petter Skagmo, LA3JPA, 2014. //
// Licensed under LGPL. //
//**************************************************************//
#ifndef NGHAM_PACKETS_H
#define NGHAM_PACKETS_H
#include "stdint.h"
// Possible packet conditions
#define PKT_CONDITION_OK 0 // Successfully received packet
#define PKT_CONDITION_FAIL 1 // Receiption failed after receiving the packet
#define PKT_CONDITION_PREFAIL 2 // Reception failed before receiving the whole packet
// Packet priority in transmission
#define PKT_PRIORITY_NORMAL 0
#define PKT_PRIORITY_FIRST_IN_SLOT 10 // Should be put first in the next time slot for timing purposes
// Size of payload in packet struct
#define PKT_PL_SIZE 512
// Basic "not available"-values
#define RSSI_NA 0xff
#define TIMESTAMP_NA 0xffffffff
#define ERRORS_NA 0xff
// If the following flag is set in a packet, NGHam extensions are used and first byte is type
#define NGHAM_FLAG_TYPE_EXTENSION 0x01
#define SPP_PL_MAX 255 // Not a power of two, so no ring buffers!
#define NGHAM_PL_MAX 220
// Ensure compatibility when used with MinGW etc.
#ifdef _WIN32
#define ATTRIBUTE_PACKED __attribute__ ((packed,gcc_struct))
#else
#define ATTRIBUTE_PACKED __attribute__ ((packed))
#endif
// Bytes in addition to payload
#define RX_PKT_OVERHEAD 15
#define TX_PKT_OVERHEAD 4
typedef struct ATTRIBUTE_PACKED{
uint16_t pl_len;
uint8_t rs_size_nr;
uint32_t timestamp_raw;
// Aligns with NGHam-SPP packet from here
uint32_t timestamp_toh_us; // Time stamp of sync word detection
uint8_t noise; // Same as above
uint8_t rssi; // In dBm + 200
uint8_t errors; // Recovered symbols
uint8_t ngham_flags;
uint8_t pl[PKT_PL_SIZE];
}rx_pkt_t;
typedef struct ATTRIBUTE_PACKED{
uint16_t pl_len;
uint8_t priority;
uint8_t ngham_flags;
uint8_t pl[PKT_PL_SIZE];
}tx_pkt_t;
void rx_pkt_init(rx_pkt_t *p);
void tx_pkt_init(tx_pkt_t *p);
#endif