DESERT 3.5.1
Loading...
Searching...
No Matches
DESERT_Addons/uwmphy_modem/uwmconnector.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2017 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
36#include "uwmconnector.h"
37#include "uwmdriver.h"
38
39#include <cctype>
40
41static void
42hexdump(std::string name, std::string str)
43{
44 int len = str.size();
45 const char *data = str.c_str();
46
47 std::cout << name << "[" << len << "]: " << std::hex;
48 for (int i = 0; i < len; i++) {
49 std::cout.fill('0');
50 std::cout.width(2);
51 std::cout << std::right << (int) data[i];
52
53 if (std::isalnum(data[i]) || std::ispunct(data[i]))
54 std::cout << "(" << data[i] << ")";
55 std::cout << " ";
56 }
57
58 std::cout.width(0);
59 std::cout << std::dec << std::endl;
60}
61
62static std::string
63hex2bin(std::string hex)
64{
65 size_t len = (hex.size() + 2) / 3;
66 std::stringstream ss(std::stringstream::in | std::stringstream::out);
67 std::string result;
68
69 ss << hex;
70 for (int i = 0; i < len; i++) {
71 int code;
72 ss >> std::hex >> code;
73 result.push_back(code);
74 }
75
76 return result;
77}
78
79UWMconnector::UWMconnector(UWMdriver *pmDriver_, std::string pathToDevice_)
80{
81
82 // Members initialization
83 pmDriver = pmDriver_;
84 pathToDevice = pathToDevice_;
85}
86
88{
89}
90
91void
93{
94}
95
96void
98{
99 driver_queue_length = length;
100}
101
102std::string
104{
105
106 std::string return_str;
107
108 if (!queueMsg.empty()) {
109 msgModem tmp_ = queueMsg.front();
110 return_str = tmp_.msg_rx;
111 queueMsg.pop();
112 if (return_str.find("-") == std::string::npos &&
113 return_str.find("OK") == std::string::npos &&
114 return_str.find("INITATION NOISE") == std::string::npos &&
115 return_str.find("INITATION LISTEN") == std::string::npos) {
116 pmDriver->printOnLog(LOG_LEVEL_ERROR, "UWMCONNECTOR", return_str);
117 }
118 } else {
119 return_str = "";
120 }
121
122 return return_str;
123}
static void hexdump(std::string name, std::string str)
static std::string hex2bin(std::string hex)
Header of the class needed by UWMPhy_modem to handle the physical connection between NS-Miracle and a...
Header of the class needed by UWMPhy_modem to handle the different transmissions cases and correspond...
UWMdriver * pmDriver
Pointer to UWMdriver object that contains this UWMconnector.
std::string pathToDevice
The path to be connected with the modem device.
std::queue< msgModem > queueMsg
Queue used to buffer incoming strings from the modem.
virtual void closeConnection()
Method to close the connection with the modem.
std::string readFromModem()
Method to check the receiving modem buffer.
UWMconnector(UWMdriver *, std::string)
Class constructor.
The class needed by UWMPhy_modem to handle the different transmissions cases and corresponding protoc...
void printOnLog(log_level_t log_level, std::string module, std::string message)