Kristof T'Jonck / Mbed 2 deprecated Project2

Dependencies:   C12832 EthernetInterface LM75B mbed-rtos mbed

Fork of app-board-LM75B by Chris Styles

Committer:
gimohd
Date:
Thu Mar 23 12:51:27 2017 +0000
Revision:
6:77a4c45f6416
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gimohd 6:77a4c45f6416 1 #ifndef Communication_H
gimohd 6:77a4c45f6416 2 #define Communication_H
gimohd 6:77a4c45f6416 3 #include <mbed.h>
gimohd 6:77a4c45f6416 4 #include <string>
gimohd 6:77a4c45f6416 5 #include "Packet.h"
gimohd 6:77a4c45f6416 6
gimohd 6:77a4c45f6416 7 #include "EthernetInterface.h"
gimohd 6:77a4c45f6416 8
gimohd 6:77a4c45f6416 9 #define FRAME_BYTE_1 0xAA
gimohd 6:77a4c45f6416 10 #define FRAME_BYTE_2 0x55
gimohd 6:77a4c45f6416 11 #define SERVER_PORT 4000
gimohd 6:77a4c45f6416 12
gimohd 6:77a4c45f6416 13 //const char * address = "192.168.0.114";
gimohd 6:77a4c45f6416 14 //const char * mask = "255.255.255.0";
gimohd 6:77a4c45f6416 15 //const char * gateway = "192.168.0.1";
gimohd 6:77a4c45f6416 16
gimohd 6:77a4c45f6416 17 /** Communication class.
gimohd 6:77a4c45f6416 18 * Utilised to make use of the EthernetInterface to receive packets
gimohd 6:77a4c45f6416 19 * with the help of a TCPSocketServer, but also to send packets to other clients
gimohd 6:77a4c45f6416 20 * with a TCPSocketConnection
gimohd 6:77a4c45f6416 21 * @ref TCPSocketConnection
gimohd 6:77a4c45f6416 22 * @ref TCPSocketServer
gimohd 6:77a4c45f6416 23 * @ref EthernetInterface
gimohd 6:77a4c45f6416 24 */
gimohd 6:77a4c45f6416 25 class Communication{
gimohd 6:77a4c45f6416 26 public:
gimohd 6:77a4c45f6416 27
gimohd 6:77a4c45f6416 28 /** Default Constructor
gimohd 6:77a4c45f6416 29 * Creates an object of the Communication class, which
gimohd 6:77a4c45f6416 30 * will automaticly connect to the EthernetInterface.
gimohd 6:77a4c45f6416 31 *
gimohd 6:77a4c45f6416 32 * @ref EthernetInterface
gimohd 6:77a4c45f6416 33 */
gimohd 6:77a4c45f6416 34 Communication();
gimohd 6:77a4c45f6416 35
gimohd 6:77a4c45f6416 36 /** Destructor
gimohd 6:77a4c45f6416 37 * Destroys all the objects using memory with this class
gimohd 6:77a4c45f6416 38 * and disconnects the connections made by the class.
gimohd 6:77a4c45f6416 39 */
gimohd 6:77a4c45f6416 40 ~Communication();
gimohd 6:77a4c45f6416 41
gimohd 6:77a4c45f6416 42 /** Connects to internet with the help of the EthernetInterface
gimohd 6:77a4c45f6416 43 * and manualy sets the ip address, it also generates a TCPSocketServer
gimohd 6:77a4c45f6416 44 * to be able to receive data.
gimohd 6:77a4c45f6416 45 *
gimohd 6:77a4c45f6416 46 * @ref EthernetInterface
gimohd 6:77a4c45f6416 47 * @ref TCPSocketServer
gimohd 6:77a4c45f6416 48 */
gimohd 6:77a4c45f6416 49 void connect();
gimohd 6:77a4c45f6416 50
gimohd 6:77a4c45f6416 51 /** Creates a TCPSocketConnection "client" to receive a Packet from a client
gimohd 6:77a4c45f6416 52 * by accepting it with the TCPSocketServer "server"
gimohd 6:77a4c45f6416 53 * @param buffer The reference to a std::string buffer that has to be
gimohd 6:77a4c45f6416 54 * filled with the received data Packet.
gimohd 6:77a4c45f6416 55 *
gimohd 6:77a4c45f6416 56 * @ref Packet
gimohd 6:77a4c45f6416 57 * @ref TCPSocketServer
gimohd 6:77a4c45f6416 58 * @ref TCPSocketConnection
gimohd 6:77a4c45f6416 59 */
gimohd 6:77a4c45f6416 60 std::string getData();
gimohd 6:77a4c45f6416 61
gimohd 6:77a4c45f6416 62 /** Uses the TCPSocketServer "server" to receive a Packet from a client
gimohd 6:77a4c45f6416 63 *
gimohd 6:77a4c45f6416 64 * @param data the string from a packet that contains the data that has to be sent to
gimohd 6:77a4c45f6416 65 * a client.
gimohd 6:77a4c45f6416 66 *
gimohd 6:77a4c45f6416 67 * @ref Packet
gimohd 6:77a4c45f6416 68 * @ref TCPSocketServer
gimohd 6:77a4c45f6416 69 */
gimohd 6:77a4c45f6416 70 void sendDataPacket(std::string data);
gimohd 6:77a4c45f6416 71
gimohd 6:77a4c45f6416 72 /**
gimohd 6:77a4c45f6416 73 * Sets the ID where the MBED has to connect to
gimohd 6:77a4c45f6416 74 *
gimohd 6:77a4c45f6416 75 */
gimohd 6:77a4c45f6416 76 void setOwnID(int i);
gimohd 6:77a4c45f6416 77
gimohd 6:77a4c45f6416 78 int getOwnID();
gimohd 6:77a4c45f6416 79
gimohd 6:77a4c45f6416 80 private:
gimohd 6:77a4c45f6416 81
gimohd 6:77a4c45f6416 82 /**
gimohd 6:77a4c45f6416 83 * An instance of the TCPSocketServer to be able to receive data.
gimohd 6:77a4c45f6416 84 *
gimohd 6:77a4c45f6416 85 * @ref TCPSocketServer
gimohd 6:77a4c45f6416 86 */
gimohd 6:77a4c45f6416 87 TCPSocketServer * server;
gimohd 6:77a4c45f6416 88
gimohd 6:77a4c45f6416 89 /**
gimohd 6:77a4c45f6416 90 * An instance of the EthernetInterface class that will make it possible
gimohd 6:77a4c45f6416 91 * to connect to the internet.
gimohd 6:77a4c45f6416 92 *
gimohd 6:77a4c45f6416 93 * @ref EthernetInterface
gimohd 6:77a4c45f6416 94 */
gimohd 6:77a4c45f6416 95 EthernetInterface * eth;
gimohd 6:77a4c45f6416 96 int ownID;
gimohd 6:77a4c45f6416 97 };
gimohd 6:77a4c45f6416 98
gimohd 6:77a4c45f6416 99 #endif