-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdwproto.h
61 lines (50 loc) · 1.87 KB
/
dwproto.h
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
/*
* libdeca - UWB Library for Qorvo/Decawave DW3000
*
* Copyright (C) 2016 - 2024 Bruno Randolf (br@einfach.org)
*
* This source code is licensed under the GNU Lesser General Public License,
* Version 3. See the file LICENSE.txt for more details.
*/
#ifndef DECA_PROTOCOL_H
#define DECA_PROTOCOL_H
#include "dwmac.h"
#include "mac802154.h"
#define DWMAC_PROTO_MSG_MASK 0xF0
#define DWMAC_PROTO_SHORT_LEN (sizeof(struct prot_short) + MAC154_FCS_LEN)
#define DWMAC_PROTO_LONG_LEN (sizeof(struct prot_long) + MAC154_FCS_LEN)
#define DWMAC_PROTO_LONG_SRC_LEN (sizeof(struct prot_long_src) + MAC154_FCS_LEN)
/* for convienient access to mac154 header and buffer and "our protocol"
* function or packet type */
struct prot_short {
struct mac154_hdr_short hdr;
uint8_t func; // frame type
uint8_t pbuf[0];
} __attribute__((packed));
struct prot_long {
struct mac154_hdr_long hdr;
uint8_t func; // frame type
uint8_t pbuf[0];
} __attribute__((packed));
struct prot_long_src {
struct mac154_hdr_long_src hdr;
uint8_t func; // frame type
uint8_t pbuf[0];
} __attribute__((packed));
/* return pointer to space after header and func */
void* dwprot_short_prepare(struct txbuf* tx, size_t len, uint8_t func,
uint16_t dst);
void* dwprot_long_prepare(struct txbuf* tx, size_t len, uint8_t func,
uint64_t dst);
/** prepare either short or long */
void* dwprot_prepare(struct txbuf* tx, size_t len, uint8_t func, uint64_t dst);
void* dwprot_long_src_prepare(struct txbuf* tx, size_t len, uint8_t func,
uint64_t src);
void dwprot_rx_handler(const struct rxbuf* rx);
/** get from either short or long */
uint64_t dwprot_get_src(const uint8_t* buf);
uint8_t dwprot_get_func(const uint8_t* buf);
const void* dwprot_get_payload(const uint8_t* buf);
bool dwprot_check_min_len(const uint8_t* buf, size_t len);
size_t dwprot_get_payload_len(const uint8_t* buf, size_t len);
#endif