DESERT 3.5.1
Loading...
Searching...
No Matches
DESERT_Addons/uwmphy_modem/msocket.h
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.
36#ifndef MSOCKET_H
37#define MSOCKET_H
38
39#include <uwmconnector.h>
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <string>
45#include <string.h>
46#include <sys/types.h>
47#include <sys/socket.h>
48#include <netinet/in.h>
49#include <arpa/inet.h>
50#include <netdb.h>
51#include <fcntl.h>
52#include <errno.h>
53
54
55
60class Msocket : public UWMconnector
61{
62 int sockfd;
63 int portno;
64 int rc;
65 pthread_t thread_id;
66 struct sockaddr_in serv_addr;
69 std::string server_host;
73 struct hostent *server;
74 char msg_tx
77
82 void error(const char *);
83
84public:
93 Msocket(UWMdriver *, std::string);
94
99
107 virtual int openConnection();
108
112 virtual void closeConnection();
113
120 virtual int writeToModem(std::string);
121
128 int
130 {
131 return sockfd;
132 }
133};
134
139extern "C" {
140void *read_process_msocket(void *);
141}
142
143#endif /* MSOCKET_H */
void * read_process_msocket(void *)
Function to read from the modem via a TCP/IP connection (it must be called as a pure C function).
Header of the class needed by UWMPhy_modem to handle the physical connection between NS-Miracle and a...
#define _MAX_MSG_LENGTH
Variable defining the maximum length of the messages \ exchanged between host and modem.
Class used to manage host/modem string exchange via TCP/IP connection (this class is a derived class ...
virtual int writeToModem(std::string)
Method for writing to the modem.
~Msocket()
Class destructor.
pthread_t thread_id
Id of a parallel thread.
char msg_tx[_MAX_MSG_LENGTH]
Message to be transmitted host to modem.
int rc
Indicator of the thread creation.
int getSocket()
Method to read the pointer to the socket where to write (it is needed by the reading function invoked...
struct sockaddr_in serv_addr
Structure to contain the Internet address to be used.
struct hostent * server
Structure to define the server host.
virtual int openConnection()
Method to open the connection with the modem.
virtual void closeConnection()
Method to close the connection with the modem.
Msocket(UWMdriver *, std::string)
Class constructor.
std::string server_host
Name of the server host on the Internet to which we want to be connected as client.
void error(const char *)
Method report errors.
The class needed by UWMPhy_modem to manage string exchange with the modem.
The class needed by UWMPhy_modem to handle the different transmissions cases and corresponding protoc...