87 std::string serialized{
""};
89 uint8_t *raw_pck = (uint8_t *) packet;
94 for (uint i = 0; i <
header_size + packet->header.len; i++) {
95 if (*raw_pck ==
dle) {
98 serialized += *raw_pck++;
118 ahoi::header_t header;
122 header.status = 0x00;
126 ahoi::packet_t packet;
127 packet.header = header;
135 ahoi::header_t header;
139 header.status = 0x00;
143 ahoi::packet_t packet;
144 packet.header = header;
152 ahoi::header_t header;
156 header.status = 0x00;
160 ahoi::packet_t packet;
161 packet.header = header;
169 ahoi::header_t header;
173 header.status = 0x00;
177 ahoi::packet_t packet;
178 packet.header = header;
186 ahoi::header_t header;
190 header.status = 0x00;
194 ahoi::packet_t packet;
195 packet.header = header;
203 ahoi::header_t header;
207 header.status = 0x00;
211 ahoi::packet_t packet;
212 packet.header = header;
220 ahoi::header_t header;
224 header.status = 0x00;
228 ahoi::packet_t packet;
229 packet.header = header;
237 ahoi::header_t header;
241 header.status = 0x00;
245 ahoi::packet_t packet;
246 packet.header = header;
254 ahoi::header_t header;
258 header.status = 0x00;
262 ahoi::packet_t packet;
263 packet.header = header;
271 ahoi::header_t header;
275 header.status = 0x00;
279 ahoi::packet_t packet;
280 packet.header = header;
288 ahoi::header_t header;
292 header.status = 0x00;
296 ahoi::packet_t packet;
297 packet.header = header;
305 ahoi::header_t header;
309 header.status = 0x00;
313 ahoi::packet_t packet;
314 packet.header = header;
322 ahoi::header_t header;
326 header.status = 0x00;
330 ahoi::packet_t packet;
331 packet.header = header;
339 ahoi::header_t header;
343 header.status = 0x00;
347 ahoi::packet_t packet;
348 packet.header = header;
356 ahoi::header_t header;
360 header.status = 0x00;
364 ahoi::packet_t packet;
365 packet.header = header;
373 ahoi::header_t header;
377 header.status = 0x00;
381 ahoi::packet_t packet;
382 packet.header = header;
389 std::vector<char>::iterator end, std::vector<char>::iterator &rsp_beg,
390 std::vector<char>::iterator &rsp_end)
392 std::string cmd =
"";
400 auto it = std::find(beg, end,
dle);
403 if (*(it + 1) ==
dle)
405 else if (*(it + 1) ==
stx)
407 else if (*(it + 1) ==
etx)
411 it = std::find(it + 1, end,
dle);
414 if (std::distance(rsp_beg, rsp_end) <
ahoi::HEADER_LEN || rsp_end < rsp_beg)
415 return std::string(
"");
417 return std::string(&(*rsp_beg), std::distance(rsp_beg, rsp_end));
422 std::vector<char>::iterator &c_beg, std::vector<char>::iterator &c_end)
429 while (it < buffer.end() - 1) {
431 it_1 = std::find(it, c_end,
dle);
432 if ((it_2 = std::find(std::next(it_1, 1), c_end,
dle)) ==
433 std::next(it_1, 1)) {
435 it = buffer.erase(it_2);
441std::shared_ptr<ahoi::packet_t>
443 std::vector<char>::iterator c_beg, std::vector<char>::iterator c_end)
445 std::shared_ptr<ahoi::packet_t> pck = std::make_shared<ahoi::packet_t>();
446 std::shared_ptr<ahoi::header_t> head = std::make_shared<ahoi::header_t>();
447 std::shared_ptr<ahoi::footer_t> foot = std::make_shared<ahoi::footer_t>();
449 auto it = std::next(c_beg,
beg_del.size());
453 auto it_n = std::next(it, 1);
456 std::copy(it, it_n, &(head->src));
459 it_n = std::next(it, 1);
462 std::copy(it, it_n, &(head->dst));
465 it_n = std::next(it, 1);
468 std::copy(it, it_n, &(head->type));
471 it_n = std::next(it, 1);
474 std::copy(it, it_n, &(head->status));
477 it_n = std::next(it, 1);
480 std::copy(it, it_n, &(head->dsn));
483 it_n = std::next(it, 1);
486 std::copy(it, it_n, &(head->len));
491 uint len = head->len;
492 it = std::next(it, 1);
494 std::memcpy(&(pck->payload), &*it, (
size_t) len);
501 if (it < c_end +
end_del.size()) {
503 it_n = std::next(it, 1);
506 std::copy(it, it_n, &(foot->power));
509 it_n = std::next(it, 1);
512 std::copy(it, it_n, &(foot->rssi));
515 it_n = std::next(it, 1);
518 std::copy(it, it_n, &(foot->biterrors));
521 it_n = std::next(it, 1);
524 std::copy(it, it_n, &(foot->agcMean));
527 it_n = std::next(it, 1);
530 std::copy(it, it_n, &(foot->agcMin));
533 it_n = std::next(it, 1);
536 std::copy(it, it_n, &(foot->agcMax));
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.
UwInterpreterAhoi(int id)
Constructor of the interpreter class.
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.
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 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.
constexpr uint HEADER_LEN
std::map< ahoi::Command, uint8_t > commands_id
Interpreter for commands and responses for ahoi! modems, TUHH, Hamburg.