Project tcp/ws and utilities

Dependencies:   ConfigEthernet ConfigFile ConfigurationFile EthernetInterface TCP_COMM WS_COMM WebSocketClient mbed-rtos mbed

Committer:
13075593
Date:
Sun Apr 03 15:48:23 2016 +0000
Revision:
1:466e1c826abe
Parent:
0:3fecf050f488
Ethernet project for tcp/websocket communication;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
13075593 0:3fecf050f488 1 #include "mbed.h"
13075593 0:3fecf050f488 2 #include "rtos.h"
13075593 0:3fecf050f488 3 #include "PC_Comm.h"
13075593 0:3fecf050f488 4 #include "ConfigurationFile.h"
13075593 0:3fecf050f488 5 #include "ConfigEthernet.h"
13075593 0:3fecf050f488 6 #include "TCP_COMM.h"
13075593 0:3fecf050f488 7 #include "Websocket.h"
13075593 0:3fecf050f488 8 #include "WebSocket_COMM.h"
13075593 0:3fecf050f488 9
13075593 0:3fecf050f488 10
13075593 0:3fecf050f488 11 DigitalOut myled(LED1);
13075593 0:3fecf050f488 12 Serial *pc;
13075593 0:3fecf050f488 13
13075593 0:3fecf050f488 14 LocalFileSystem local("local");
13075593 0:3fecf050f488 15 const char* ECHO_SERVER_ADDRESS = "192.168.0.101 ";
13075593 0:3fecf050f488 16 const int ECHO_SERVER_PORT = 7;
13075593 0:3fecf050f488 17
13075593 0:3fecf050f488 18 void testServer()
13075593 0:3fecf050f488 19 {
13075593 0:3fecf050f488 20 printf("Read Config File\n");
13075593 0:3fecf050f488 21 ConfigurationFile config;
13075593 0:3fecf050f488 22 config.readConfigurationFile("/local/server.cfg");
13075593 0:3fecf050f488 23 config.readServerEthernetConfiguration();
13075593 0:3fecf050f488 24
13075593 0:3fecf050f488 25 printf("Init Ethernet connection \n");
13075593 0:3fecf050f488 26 ConfigEthernet ethernet(config.getIP(),config.getMask(),config.getGateway());
13075593 0:3fecf050f488 27 ethernet.initConnection();
13075593 0:3fecf050f488 28
13075593 0:3fecf050f488 29 TCP_Communication tcp();
13075593 0:3fecf050f488 30 }
13075593 0:3fecf050f488 31
13075593 0:3fecf050f488 32 void testSocket()
13075593 0:3fecf050f488 33 {
13075593 0:3fecf050f488 34 printf("Read Config File\n");
13075593 0:3fecf050f488 35 ConfigurationFile config;
13075593 0:3fecf050f488 36 config.readConfigurationFile("/local/server.cfg");
13075593 0:3fecf050f488 37 config.readServerEthernetConfiguration();
13075593 0:3fecf050f488 38
13075593 0:3fecf050f488 39 printf("Init Ethernet connection \n");
13075593 0:3fecf050f488 40 ConfigEthernet ethernet(config.getIP(),config.getMask(),config.getGateway());
13075593 0:3fecf050f488 41 ethernet.initConnection();
13075593 0:3fecf050f488 42
13075593 0:3fecf050f488 43 // Create TCP Object
13075593 0:3fecf050f488 44 printf("Create TCP Socket Object \n");
13075593 0:3fecf050f488 45 TCP_Communication tcp(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
13075593 0:3fecf050f488 46
13075593 0:3fecf050f488 47 // Init TCP Socket Connexion
13075593 0:3fecf050f488 48 printf("Init Socket connexion \n");
13075593 0:3fecf050f488 49 tcp.initSocket();
13075593 0:3fecf050f488 50
13075593 0:3fecf050f488 51 // Send Data with Socket
13075593 0:3fecf050f488 52 printf("Send Data to server\n");
13075593 0:3fecf050f488 53 tcp.sendDataSocket("Hello World");
13075593 0:3fecf050f488 54 tcp.sendDataSocket("Hello Wolrd 1!!!");
13075593 0:3fecf050f488 55 tcp.sendDataSocket("Hello Wolrd 2!!!");
13075593 0:3fecf050f488 56 tcp.sendDataSocket("Hello Wolrd 3!!!");
13075593 0:3fecf050f488 57 }
13075593 0:3fecf050f488 58
13075593 0:3fecf050f488 59 void testWebSocket()
13075593 0:3fecf050f488 60 {
13075593 0:3fecf050f488 61
13075593 0:3fecf050f488 62 printf("Read Config File\n");
13075593 0:3fecf050f488 63 ConfigurationFile config;
13075593 0:3fecf050f488 64 config.readConfigurationFile("/local/server.cfg");
13075593 0:3fecf050f488 65 config.readServerEthernetConfiguration();
13075593 0:3fecf050f488 66
13075593 0:3fecf050f488 67 printf("Init Ethernet connection \n");
13075593 0:3fecf050f488 68 ConfigEthernet ethernet(config.getIP(),config.getMask(),config.getGateway());
13075593 0:3fecf050f488 69 ethernet.initConnection();
13075593 0:3fecf050f488 70
13075593 0:3fecf050f488 71 WebSocket_Communication ws(config.getURL());
13075593 0:3fecf050f488 72 ws.initWebSocket();
13075593 0:3fecf050f488 73 ws.sendDataWebSocket("Hello Socket Server !");
13075593 0:3fecf050f488 74
13075593 0:3fecf050f488 75 }
13075593 0:3fecf050f488 76
13075593 0:3fecf050f488 77
13075593 0:3fecf050f488 78 int main()
13075593 0:3fecf050f488 79 {
13075593 0:3fecf050f488 80 //testWebSocket();
13075593 0:3fecf050f488 81 testSocket();
13075593 0:3fecf050f488 82 //Thread::wait(osWaitForever);
13075593 0:3fecf050f488 83 }