DESERT 3.5.1
Loading...
Searching...
No Matches
uwinterpreterahoi.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
37#ifndef UWINTERPRETERAHOI_H
38#define UWINTERPRETERAHOI_H
39
40#include <memory>
41#include <string>
42#include <vector>
43#include <array>
44
45#include "ahoitypes.h"
46
54{
55
56public:
61 UwInterpreterAhoi(int id);
62
67
73 std::string serializePacket(ahoi::packet_t *packet);
74
80 std::string buildSend(ahoi::packet_t pck);
81
87 std::string buildID(int id);
88
93 std::string buildBatVol();
94
99 std::string buildReset();
100
105 std::string buildRange();
106
111 std::string buildAgc();
112
117 std::string buildRangeDelay();
118
123 std::string buildDistance();
124
129 std::string buildRxGain();
130
135 std::string buildTxGain();
136
141 std::string buildPacketStat();
142
147 std::string buildPacketStatReset();
148
153 std::string buildSyncStat();
154
159 std::string buildSyncStatReset();
160
165 std::string buildSfdStat();
166
171 std::string buildSfdStatReset();
172
177 std::string buildAllStat();
178
183 std::string buildAllStatReset();
184
192 std::string findResponse(std::vector<char>::iterator beg,
193 std::vector<char>::iterator end,
194 std::vector<char>::iterator &rsp_beg,
195 std::vector<char>::iterator &rsp_end);
196
203 void fixEscapes(std::vector<char> &buffer,
204 std::vector<char>::iterator &c_beg,
205 std::vector<char>::iterator &c_end);
206
215 std::shared_ptr<ahoi::packet_t> parseResponse(
216 std::vector<char>::iterator c_beg,
217 std::vector<char>::iterator c_end);
218
219private:
220 uint8_t id;
221 uint8_t sn;
223 static uint header_size;
224 static uint footer_size;
226 static const uint8_t dle; /*< Escaping sequence */
227 static const uint8_t stx;
228 static const uint8_t etx;
230 std::array<uint8_t, 2> beg_del;
231 std::array<uint8_t, 2> end_del;
232};
233
234#endif
Class used for building syntactically compliant commands to send to the ahoi! modems and interpreting...
std::string buildReset()
Method that builds the command.
std::string buildAgc()
Method that builds the command.
std::string buildBatVol()
Method that builds the command.
std::string buildSfdStat()
Method that builds the command.
std::string buildDistance()
Method that builds the command.
static const uint8_t etx
Ending sequence.
std::string buildID(int id)
Method that builds the command to ask the modem its own ID number.
void fixEscapes(std::vector< char > &buffer, std::vector< char >::iterator &c_beg, std::vector< char >::iterator &c_end)
Method that erases an escape (DLE) char if part of 2-cahrs escape sequence.
std::string buildSyncStat()
Method that builds the command.
std::string buildRangeDelay()
Method that builds the command.
std::string buildAllStatReset()
Method that builds the command.
std::string buildSfdStatReset()
Method that builds the command.
~UwInterpreterAhoi()
Destructor of the interpreter class.
std::shared_ptr< ahoi::packet_t > parseResponse(std::vector< char >::iterator c_beg, std::vector< char >::iterator c_end)
Method that parses a region of memory where a response was previously found.
std::array< uint8_t, 2 > beg_del
Beginning delimiter.
static uint footer_size
Standard ahoi! packet has 6 bytes of header.
std::string buildPacketStat()
Method that builds the command.
static uint header_size
Standard ahoi! packet has 6 bytes of header.
static const uint8_t dle
std::string buildAllStat()
Method that builds the command.
std::string buildSyncStatReset()
Method that builds the command.
std::string serializePacket(ahoi::packet_t *packet)
Serialize the provided packet.
uint8_t id
Identifier of the modem: to fill the src addres field.
uint8_t sn
Sequence number for commands tranmission: at end restart.
std::array< uint8_t, 2 > end_del
Ending delimiter.
std::string buildRange()
Method that builds the command.
std::string findResponse(std::vector< char >::iterator beg, std::vector< char >::iterator end, std::vector< char >::iterator &rsp_beg, std::vector< char >::iterator &rsp_end)
Method that looks for ahoi! modem responses.
std::string buildTxGain()
Method that builds the command.
std::string buildRxGain()
Method that builds the command.
std::string buildPacketStatReset()
Method that builds the command.
static const uint8_t stx
Starting sequence.
std::string buildSend(ahoi::packet_t pck)
Method that builds the command to send a given message.