Repo. for the ELEC351 Coursework - Oliver Thompson
Dependencies: BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client
Diff: Network.hpp
- Revision:
- 20:2ce28a5032d5
- Parent:
- 19:c3b396b65f2a
--- a/Network.hpp Thu Dec 13 16:09:54 2018 +0000 +++ b/Network.hpp Wed Jan 02 12:12:30 2019 +0000 @@ -3,32 +3,17 @@ #define _NETWORK_ #include "mbed.h" - #include "FATFileSystem.h" - #include "sample_hardware.hpp" - #include "EthernetInterface.h" - #include "TCPServer.h" - //#include "messageStruct.hpp" - //#include "LCD.hpp" - #include "TCPSocket.h" - #include <iostream> - #include <string> - #include "ntp-client/NTPClient.h" - - - - - #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" #define HTTP_MESSAGE_BODY1 "" \ @@ -72,39 +57,36 @@ #define IP "10.0.0.10" - #define NETMASK "255.0.0.0" - #define GATEWAY "10.0.0.2" +EthernetInterface eth; +NTPClient ntp(ð); -EthernetInterface eth; -NTPClient ntp(ð); +Mail<time_and_date,5> Serial2Net; // Serial -> Net Mailbox 5 Elements Wide Time&Date + class Network { //friend class LCD_Data; private: - float temp; //current temperature of sensor - float pressure; //current pressure of sensor - float fLDR; //current light level from LDR + double temp; //current temperature of sensor + double pressure; //current pressure of sensor + double fLDR; //current light level from LDR string time; - - void update_temp(double t) //use this function to update the current temperature value - { - temp = 5; - } - - void update_pressure(double p) //use this function to update the current pressure value - { - pressure = 4; - } - - void update_LDR(double L) - { - fLDR = 3; - } - + + void update_temp(double t) //use this function to update the current temperature value + { + temp = t; + } + void update_pressure(double p) //use this function to update the current pressure value + { + pressure = p; + } + void update_LDR(double L) + { + fLDR = L; + } public: EventQueue Network_Queue; @@ -116,16 +98,34 @@ //Configure an ethernet connection eth.set_network(IP, NETMASK, GATEWAY); eth.connect(); - + } ~Network(){ //deconstructor - } - void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox + void getSerial2Net() // Queue Consumer + { + if (!Serial2Net.empty()) + { + osEvent evt = Serial2Net.get(); + switch (evt.status) + { + case osEventMail: + //Normal status + time_and_date *time_copy = (time_and_date*)evt.value.p; + time = time_copy->current_time; // Update the internal clock + Serial2Net.free(time_copy); // Free up the space in the memory Pool + default: + //All other errors (see cmsis_os.h for meaning of error code) + //printf("Serial2Net->get() returned %02x status\n\r", evt.status); + } + } + } + + void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox { update_temp(msg.temp); // Include message class passing of data update_pressure(msg.pressure); @@ -140,8 +140,6 @@ void NetPush(){ - - //Now setup a web server TCPServer srv; //TCP/IP Server @@ -166,7 +164,7 @@ srv.accept(&clt_sock, &clt_addr); - printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); + //printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); @@ -218,20 +216,10 @@ response += time; response += HTTP_MESSAGE_BODY5; - - - - - //Send static HTML response (as a C string) - clt_sock.send(response.c_str(), response.size()+6); - - - - - + clt_sock.send(response.c_str(), response.size()); } }; @@ -243,4 +231,4 @@ Network m_oNet; #endif - \ No newline at end of file +