DESERT 3.5.1
Loading...
Searching...
No Matches
ahoitypes.h
Go to the documentation of this file.
1//
2// Copyright (c) 2019 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29#ifndef AHOIPACKETTYPES_H
30#define AHOIPACKETTYPES_H
31
32#include <map>
33#include <stdint.h>
34#include <sys/types.h>
35
36namespace ahoi
37{
38
39enum class Command {
40 send,
41 confirm,
42 id,
43 batvol,
44 reset,
45 agc,
46 rxgain,
47 txgain,
54 sfdstat,
56 allstat,
58};
59
60extern std::map<ahoi::Command, uint8_t> commands_id;
61
62// TYPES AND VARIABLE
63constexpr uint AHOI_TYPE_ACK = ((1 << (8 * sizeof(uint8_t) - 1)) - 1);
64constexpr uint AHOI_SERIAL_ACK = ((1 << (8 * sizeof(uint8_t))) - 1);
65constexpr uint AHOI_ADDR_BCAST = ((1 << (8 * sizeof(uint8_t))) - 1);
66
67// maximum payload length of a packet
68constexpr uint PAYLOAD_MAXLEN = 128;
69
70// PACKET STRUCTS
71// packet header
72struct __attribute__((__packed__)) header_t {
73 uint8_t src; // source address
74 uint8_t dst; // destination address
75 uint8_t type; // packet type
76 uint8_t status; // status flags
77 uint8_t dsn; // sequence number
78 uint8_t len; // payload length in bytes
79};
80
81struct __attribute__((__packed__)) footer_t {
82 uint8_t power;
83 uint8_t rssi;
84 uint8_t biterrors;
85 uint8_t agcMean;
86 uint8_t agcMin;
87 uint8_t agcMax;
88};
89
90struct __attribute__((__packed__)) packet_t {
91 ahoi::header_t header;
92 uint8_t payload[PAYLOAD_MAXLEN];
93 ahoi::footer_t footer;
94};
95
96constexpr uint MAX_PKT_LEN = (sizeof(packet_t));
97constexpr uint HEADER_LEN = (sizeof(header_t));
98constexpr uint FOOTER_LEN = (sizeof(footer_t));
99
100constexpr uint MM_PAYLOAD_CRC_LEN = 2; /* bytes */
101constexpr uint MM_HEADER_CRC_LEN = 1; /* bytes */
102
103// ack setup
104constexpr uint ACK_NONE = 0x00; // do not request ack
105constexpr uint ACK_PLAIN = 0x01; // request ack
106constexpr uint ACK_RANGING = 0x02; // request ack with ranging info
107
108// STRUCT FOR COMMAND PACKETS
109struct __attribute__((__packed__)) agc_cmd {
110 bool en; // agc enable/disable (true/false)
111};
112
113struct __attribute__((__packed__)) batvoltage_rsp {
114 uint16_t voltage;
115};
116
117struct __attribute__((__packed__)) config_rsp {
118 char descr[1];
119};
120
121struct __attribute__((__packed__)) filterraw_cmd {
122 uint8_t stage; // filter stage
123 uint8_t value; // raw value
124};
125
126struct __attribute__((__packed__)) filterraw_rsp {
127 struct __attribute__((__packed__)) {
128 uint8_t stage; // filter stage
129 uint8_t value; // raw value
130 } stages[1];
131};
132
133struct __attribute__((__packed__)) freqsetup_numbands_cmd {
134 uint8_t numBands;
135};
136
137struct __attribute__((__packed__)) freqsetup_numcarriers_cmd {
138 uint8_t numCarriers;
139};
140
141struct __attribute__((__packed__)) id_cmd {
142 uint8_t id; // modem id (optional)
143};
144
145struct __attribute__((__packed__)) packetstat_rsp {
146 uint16_t numTx; // sent packets
147 uint16_t numSync; // successful syncs
148 uint16_t numSfd; // successful sfds
149 uint16_t numRxComplete; // received (intact) packets
150 uint16_t numRxHeaderBadCrc; // crc
151 uint16_t numRxHeaderBitErr; // repairable bit errors
152 uint16_t numRxHeaderBitErrFatal; // non-repairable bit errors
153 uint16_t numRxPayloadBadCrc; // crc
154 uint16_t numRxPayloadBitErr; // repairable bit errors
155 uint16_t numRxPayloadBitErrFatal; // non-repairable bit errors
156 uint16_t numRxCritError; // critical errors (unexpected behavior)
157};
158
159struct __attribute__((__packed__)) peakwinlen_cmd {
160 uint16_t winlen; // length in micro seconds
161};
162
163struct __attribute__((__packed__)) powerlevel_rsp {
164 uint8_t power; // power value (only for reply)
165};
166
167struct __attribute__((__packed__)) rxgain_cmd {
168 uint8_t stage; // filter stage
169 uint8_t level; // gain level
170};
171
172struct __attribute__((__packed__)) rxgain_rsp {
173 struct __attribute__((__packed__)) {
174 uint8_t stage; // filter stage
175 uint8_t level; // gain level
176 uint8_t num; // number of levels
177 } stages[1];
178};
179
180struct __attribute__((__packed__)) rxthresh_cmd {
181 uint8_t rxThresh; // in % of max amplitude
182};
183
184struct __attribute__((__packed__)) sample_cmd {
185 uint8_t trigger; // the required trigger (ACI_SAMPLE_TRIGGER_*)
186 uint16_t numSamples; // total number of samples (including delay)
187 uint16_t numDelay; // additional samples after the trigger event
188};
189
190struct __attribute__((__packed__)) sniff_cmd {
191 bool en;
192};
193
194struct __attribute__((__packed__)) spreadcode_cmd {
195 uint8_t codelen; // code length (1, ..., max code len)
196};
197
198struct __attribute__((__packed__)) synclen_cmd {
199 uint8_t txlen;
200 uint8_t rxlen;
201};
202
203struct __attribute__((__packed__)) test_dirac_cmd {
204 uint8_t rep; // number of repetitions
205};
206
207struct __attribute__((__packed__)) test_freq_cmd {
208 uint8_t freqNum; // frequency number "n * df" (0 < n <= FREQ_LIST_NUM)
209 uint8_t lvl; // loudness level (% of max. (<=100), 0 == gain compensated)
210};
211
212struct __attribute__((__packed__)) test_noise_cmd {
213 bool gc; // gain compensation?
214 uint8_t step; // stepping (only every nth frequency)
215 uint8_t dur; // duration in multiple of symbol (>= 1)
216};
217
218struct __attribute__((__packed__)) test_sweep_cmd {
219 bool gc; // gain compensation?
220 uint8_t gap; // gap between frequencies in multiple of symbol
221};
222
223struct __attribute__((__packed__)) transducer_cmd {
224 uint8_t type; // transducer to use
225};
226
227struct __attribute__((__packed__)) transducer_rsp {
228 uint8_t type; // currently used transducer
229 char descr[1]; // textual description of tansducer type
230};
231
232struct __attribute__((__packed__)) txgain_cmd {
233 uint8_t lvl;
234};
235} // namespace ahoi
236
237#endif
struct __attribute__((__packed__)) header_t
Definition ahoitypes.h:72
constexpr uint AHOI_ADDR_BCAST
Definition ahoitypes.h:65
constexpr uint ACK_NONE
Definition ahoitypes.h:104
constexpr uint PAYLOAD_MAXLEN
Definition ahoitypes.h:68
constexpr uint FOOTER_LEN
Definition ahoitypes.h:98
constexpr uint HEADER_LEN
Definition ahoitypes.h:97
constexpr uint AHOI_SERIAL_ACK
Definition ahoitypes.h:64
constexpr uint AHOI_TYPE_ACK
Definition ahoitypes.h:63
constexpr uint ACK_PLAIN
Definition ahoitypes.h:105
std::map< ahoi::Command, uint8_t > commands_id
constexpr uint MM_HEADER_CRC_LEN
Definition ahoitypes.h:101
constexpr uint MM_PAYLOAD_CRC_LEN
Definition ahoitypes.h:100
constexpr uint MAX_PKT_LEN
Definition ahoitypes.h:96
Command
Definition ahoitypes.h:39
constexpr uint ACK_RANGING
Definition ahoitypes.h:106