ladsidfs

Dependencies:   BMP280 LGLCDv2

Fork of 0NicksCoursework_copywithserialtime by Liam Grazier

Files at this revision

API Documentation at this revision

Comitter:
liam_grazier
Date:
Tue Jan 09 05:43:43 2018 +0000
Parent:
7:dd303488e55d
Child:
9:e27b3f34de24
Commit message:
dfshjsdfjhdf;

Changed in this revision

Components/components.cpp Show annotated file Show diff for this revision Revisions of this file
Components/components.hpp Show annotated file Show diff for this revision Revisions of this file
Network/network.cpp Show annotated file Show diff for this revision Revisions of this file
Network/network.hpp Show annotated file Show diff for this revision Revisions of this file
README.md Show diff for this revision Revisions of this file
Time/DandTEdit_RTC_Fin.cpp Show annotated file Show diff for this revision Revisions of this file
Time/DandTEdit_RTC_Fin.hpp Show annotated file Show diff for this revision Revisions of this file
components.cpp Show diff for this revision Revisions of this file
components.hpp Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
network.cpp Show diff for this revision Revisions of this file
network.hpp Show diff for this revision Revisions of this file
serialtx/stx.cpp Show annotated file Show diff for this revision Revisions of this file
serialtx/stx.hpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/components.cpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,371 @@
+#include "mbed.h"
+#include "components.hpp"
+#include "lglcd.h"
+#include "time.h"
+#include "stdio.h"
+#define RED_DONE 1
+#define YELLOW_DONE 2
+//Digital outputs
+DigitalIn onBoardSwitch(USER_BUTTON);
+DigitalOut onBoardLED(LED1);
+DigitalOut redLED(PE_15);
+DigitalOut yellowLED(PB_10);
+DigitalOut greenLED(PB_11);
+SDBlockDevice sd(PB_5, D12, D13, D10);// miso, sclk, cs 
+Mutex Lock1;
+Mutex Lock2;
+Mutex Remove;
+//Inputs
+time_t rawtime;
+struct tm * timeinfo;
+int year, month ,day, hour, minute, second;
+char input = 0; 
+char jtime[32];
+char jdate[32];
+char jdate1[32];
+DigitalIn  SW1(PE_12);
+DigitalIn  SW2(PE_14);
+//Serial pc(USBTX, USBRX);
+AnalogIn adcIn(PA_0);
+//Environmental Sensor driver
+#ifdef BME
+BME280 sensor(D14, D15);
+#else
+BMP280 sensor(D14, D15);
+#endif
+lglcd mylcd(D7,D6,D5,D4,D3,D2);
+
+//POWER ON SELF TEST
+void post() 
+{
+    //posttest 
+}
+void runanalysis(void){
+    while(1){     
+Lock1.lock();
+double temp = sensor.getTemperature();
+double pressure = sensor.getPressure();
+double lightin = adcIn;
+char TEM[6];
+char PRE[5];  
+char LIGHT[6];
+//printf("REFRESH SENSORS\n\r");
+sprintf(TEM,"%.2f", temp);
+sprintf(PRE,"%.2f", pressure);
+sprintf(LIGHT,"%.2f", lightin);
+mylcd.setline(1,1);
+mylcd.write("L:");
+if(lightin > 0.7 && lightin < 0.9)
+{
+mylcd.setline(1,4);
+ mylcd.write("|||||||||MAX");    
+}
+else if(lightin > 0.55 && lightin < 0.69)
+{
+mylcd.setline(1,4);
+ mylcd.write("|||||||     ");
+}
+else if(lightin > 0.5 && lightin < 0.54)
+{
+mylcd.setline(1,4);
+ mylcd.write("|||||       ");
+}
+else if(lightin > 0.4 && lightin < 0.54)
+{
+mylcd.setline(1,4);
+ mylcd.write("|||         ");
+}
+else if(lightin > 0.3 && lightin < 0.39)
+{
+mylcd.setline(1,4);
+ mylcd.write("||          ");
+} 
+else if(lightin > 0.06 && lightin < 0.29)
+{
+mylcd.setline(1,4);
+ mylcd.write("LOW LIGHT    ");
+} 
+else if(lightin < 0.05)
+{
+mylcd.setline(1,4);
+mylcd.write("             ");
+mylcd.setline(1,4);
+mylcd.write("disconnected");
+}
+mylcd.setline(2,1);
+mylcd.write("P:");
+mylcd.write(PRE);
+mylcd.setline(2,10);
+mylcd.write("T:");
+mylcd.write(TEM);
+wait(0.01);
+Lock1.unlock();
+Thread::signal_wait(SIG_READY);
+}
+}
+void sdwrite(void)
+{
+    while(1)
+    {
+        Lock2.lock();
+double P = sensor.getPressure();
+double L = adcIn;
+double t = sensor.getTemperature();
+char tem[6];
+char pre[5];  
+char light[6];
+char com[1];
+strcpy(com, ",");
+sprintf(pre,"%.2f", P);
+sprintf(tem,"%.2f",t);
+printf(tem);
+sprintf(light,"%.2f\n\r", L);
+time_t seconds = time(NULL);
+strftime(jdate1, 32, "%F", localtime(&seconds));
+strftime(jdate, 32, "%F\n\r", localtime(&seconds));
+strftime(jtime, 32, "%X\n\r", localtime(&seconds));
+FATFileSystem fs("sd", &sd);
+char filename[32];
+char suffix[4];
+char prefix[4];
+strcpy(prefix,"/sd/");
+strcpy(suffix,".txt");
+Lock1.lock();
+sprintf(filename,"%s%s%s",prefix,jdate1,suffix);
+Lock1.unlock();
+FILE* fp = fopen(filename,"a");
+    if (fp == NULL) {
+        errorCode(FATAL);
+        printf("SD FAIL\n\r");
+        mylcd.clear();
+        mylcd.setline(1,0);
+        mylcd.write("SD FAIL");
+    }
+    if (fp != NULL){
+    //printf("SD Success\n\r");
+  //  fprintf(fp,"%s\n\r", "*C,  mbar,   light level 0-1 scale");
+    fprintf(fp,"%s",jdate);//date
+    fprintf(fp,"%s",com);
+    fprintf(fp,"%s",jtime);//time
+    fprintf(fp,"%s",com);
+    fprintf(fp,"%s",pre);
+    fprintf(fp,"%s",com);
+    fprintf(fp,"%s",tem);
+    fprintf(fp,"%s",com);
+    fprintf(fp,"%s\n\r",light);
+    wait(0.01);
+    }
+      fclose(fp);      
+      Lock2.unlock(); 
+      Thread::signal_wait(SIG_READY2);   
+
+}
+}
+void sdrun(void)
+{
+if ( sd.init() != 0) {
+printf("Init failed\n\r");
+mylcd.clear();
+mylcd.setline(1,1);
+mylcd.write("CANNOT INIT SD");        
+errorCode(FATAL);
+}
+if( sd.init() == 0){
+printf("Init Success \n\r");
+mylcd.clear();
+mylcd.setline(1,1);
+mylcd.write("SD GOOD MAN");
+wait(0.5); //flash the SD error / good code! 
+}
+}
+void sdcheck(void){
+if ( sd.init() != 0) {
+printf("Init failed \n\r");
+mylcd.clear();
+mylcd.setline(1,1);
+mylcd.write("CANNOT INIT SD\n\r");        
+errorCode(FATAL);
+}
+if( sd.init() == 0){
+//printf("SD Good\n\r");
+}
+}
+void sdremove(void)
+{
+    while(1){
+    Thread::signal_wait(SIG_REMOVE); 
+    mylcd.clear();  
+    Remove.lock();
+                sd.deinit();
+                mylcd.clear();
+                Lock1.lock();
+                mylcd.setline(2,0);
+                greenLED = 1;
+                mylcd.write("R");
+                Lock1.unlock();
+                printf("SD REMOVED\n\r");
+                errorCode(FATAL);
+    Remove.unlock();
+}
+}
+void lcdstart(void){
+    mylcd.clear();
+    mylcd.setline(1,1);
+    mylcd.write("INIT. SYSTEM");
+    mylcd.setline(2,1);
+    mylcd.write("ELEC351");
+    }
+void errorCode(ELEC350_ERROR_CODE err)
+{
+    switch (err) {
+      case OK:
+        greenLED = 1;
+        wait(1.0);
+        greenLED = 0;
+        return;                
+      case FATAL:
+        while(1) {
+            redLED = 1;
+            wait(0.1);
+            redLED = 0;
+            wait(0.1);                
+        }
+    }
+}
+
+///dougs code
+
+void DispTime(void)
+{
+    time_t Count = time(NULL);                      //Read the RTC Time
+    printf("Current Time - %s\n\r", ctime(&Count)); //Print the current time
+}
+
+void setuptime(void)
+{
+
+    /*Initialising the time for our program to easy edit*/
+    time ( &rawtime );
+    timeinfo = localtime ( &rawtime );
+    
+    /*Setting the time to the deadline time*/
+    /*Same as button Code*/
+    //Set the initialisation time to: Tuesday 9th January 2018, 16:00:00.
+    //set_time(1515513600);
+    //Initialisation of the times.
+    time ( &rawtime );
+    timeinfo = localtime ( &rawtime ); 
+    //Displays the initialisation time
+    DispTime();
+    /*End the initialisation */
+   
+}
+
+    void runtime(void){
+    while(1) //When added to the main code this will be changed to a while "SETDATE"
+    {  
+            /*promts the user to input which edit they would like*/
+            printf ("What part do you want to edit? Time(T)/All(A).\n\r"); 
+            fflush(stdout); 
+            scanf ("%s",&input);
+            /*Switch case input*/
+            switch(input)
+            {
+            case 'T':
+                //Sequential Entering, Hour, Minute, Second respectively
+                printf ("Enter hour:(00-23) \n\r"); 
+                fflush(stdout); 
+                scanf ("%d",&hour);
+
+                printf ("Enter minute:(00-59) \n\r"); 
+                fflush(stdout); 
+                scanf ("%d",&minute);
+
+                printf ("Enter second:(00-59) \n\r"); 
+                fflush(stdout); 
+                scanf ("%d",&second);
+                
+            break;
+        
+            /*Case A ----- All values Update sequence*/
+            case 'A':
+                printf ("Enter year:(0-9999) \n\r"); fflush(stdout); scanf ("%d",&year);
+                printf ("Enter month:(01-12) \n\r"); fflush(stdout); scanf ("%d",&month);      
+                printf ("Enter day:(01-31) \n\r"); fflush(stdout); scanf ("%d",&day);
+                printf ("Enter hour:(00-23)\n\r"); fflush(stdout); scanf ("%d",&hour);
+                printf ("Enter minute:(00-59) \n\r"); fflush(stdout); scanf ("%d",&minute);
+                printf ("Enter second:(00-59) \n\r"); fflush(stdout); scanf ("%d",&second);
+            break;
+        
+            /*default to reset ----- Month Update sequence*/
+            default:
+                printf  ("Invalid\n\r");
+                set_time(1515513600);
+        }  
+        /*Updating all the timings after the user has input all the data*/
+        /*Put here as once the user has finished editing it does a batch update*/
+            timeinfo->tm_year = year - 1900;
+            timeinfo->tm_mon = month - 1;
+            timeinfo->tm_mday = day;
+            timeinfo->tm_hour = hour;
+            timeinfo->tm_min = minute;
+            timeinfo->tm_sec = second;
+            time_t CurrTime = mktime(timeinfo); //Convert the to UNIX time
+            set_time(CurrTime);                 //Sets time using the UNIX time
+            DispTime();  
+            return;                       //Display the new time
+        }
+    }
+
+void rundate(void){
+    while(1) //When added to the main code this will be changed to a while "SETDATE"
+    {
+    
+            /*promts the user to input which edit they would like*/
+            printf ("What part do you want to edit? Date(D)/All(A).\n\r"); 
+            fflush(stdout); 
+            scanf ("%s",&input);
+            /*Switch case input*/
+            switch(input)
+            {
+            /*Case D ----- Date Update sequence*/  
+            case 'D': 
+                //Sequential Entering, Day, Month, Year respectively 
+                printf ("Enter day:(01-31) \n\r"); 
+                fflush(stdout); 
+                scanf ("%d",&day); 
+                printf ("Enter month:(01-12) \n\r"); 
+                fflush(stdout); 
+                scanf ("%d",&month);
+                printf ("Enter year:(1970-9999) \n\r"); 
+                fflush(stdout); 
+                scanf ("%d",&year);                       
+            break;    
+            /*Case A ----- All values Update sequence*/
+            case 'A':
+                printf ("Enter year:(0-9999) \n\r"); fflush(stdout); scanf ("%d",&year);
+                printf ("Enter month:(01-12) \n\r"); fflush(stdout); scanf ("%d",&month);      
+                printf ("Enter day:(01-31) \n\r"); fflush(stdout); scanf ("%d",&day);
+                printf ("Enter hour:(00-23)\n\r"); fflush(stdout); scanf ("%d",&hour);
+                printf ("Enter minute:(00-59) \n\r"); fflush(stdout); scanf ("%d",&minute);
+                printf ("Enter second:(00-59) \n\r"); fflush(stdout); scanf ("%d",&second);
+            break;
+            /*default to reset ----- Month Update sequence*/
+            default:
+                printf  ("Invalid\n\r");
+                set_time(1515513600);
+        }  
+        /*Updating all the timings after the user has input all the data*/
+        /*Put here as once the user has finished editing it does a batch update*/
+            timeinfo->tm_year = year - 1900;
+            timeinfo->tm_mon = month - 1;
+            timeinfo->tm_mday = day;
+            timeinfo->tm_hour = hour;
+            timeinfo->tm_min = minute;
+            timeinfo->tm_sec = second;
+            time_t CurrTime = mktime(timeinfo); //Convert the to UNIX time
+            set_time(CurrTime);                 //Sets time using the UNIX time
+            DispTime();  
+            return;                       //Display the new time
+        }
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Components/components.hpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,44 @@
+#ifndef __sample_hardware__
+#define __sample_hardware__
+#define SIG_READY 1
+#define SIG_READY2 1
+#define SIG_REMOVE 1
+#define SIG_NET 1
+//#define BME
+#ifdef BME
+#include "BME280.h"
+#else
+#include "BMP280.h"
+#endif
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+//dougs
+void DispTime(void);
+void setuptime(void);
+void runtime(void);
+void rundate(void);
+///
+void runanalysis(void);
+void sdrun(void);
+void sdcheck(void);
+void lcdstart(void);
+void sdwrite(void);
+void sdremove(void);
+enum ELEC350_ERROR_CODE {OK, FATAL};
+extern DigitalOut onBoardLED;
+extern DigitalOut redLED;
+extern DigitalOut yellowLED;
+extern DigitalOut greenLED;
+extern DigitalIn  onBoardSwitch;
+extern DigitalIn  SW1;
+extern DigitalIn  SW2;
+//extern Serial pc;
+extern AnalogIn adcIn;
+#ifdef BME
+extern BME280 sensor;
+#else
+extern BMP280 sensor;
+#endif
+extern void post();
+extern void errorCode(ELEC350_ERROR_CODE err);
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Network/network.cpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,148 @@
+#if !FEATURE_LWIP
+    #error [NOT_SUPPORTED] LWIP not supported for this target
+#endif
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "TCPServer.h"
+#include "TCPSocket.h"
+ char realtime[32];
+#include <iostream>
+#include <string> 
+#include "BMP280.h"
+#include "components.hpp"
+#include "network.hpp"
+Mutex Net;
+#define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
+#define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
+#define HTTP_MESSAGE_BODY1 ""                                    \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <h1>Sensor Data</h1>" "\r\n"                              \
+"      <p>Light Level LDR value: " "\r\n" 
+                 
+#define HTTP_Pressure1 ""                                        \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <h1> </h1>" "\r\n"                                        \
+"      <p>Pressure(mbar): " "\r\n"                
+
+#define HTTP_Pressure2 ""                                        \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
+"</html>"
+#define HTTP_TIME ""                                     \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <h1> </h1>" "\r\n"                                        \
+"      <p>Time: " "\r\n"       
+                 
+#define HTTP_Temperature1 ""                                     \
+"<html>" "\r\n"                                                  \
+"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
+"    <div style=\"margin:auto\">" "\r\n"                         \
+"      <h1> </h1>" "\r\n"                                        \
+"      <p>Temperature(Degrees Celcius): " "\r\n"       
+
+#define HTTP_Temperature2 ""                                     \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
+"</html>"
+#define HTTP_MESSAGE_TIME ""                                    \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
+"</html>"
+#define HTTP_MESSAGE_BODY2 ""                                    \
+       "</p>" "\r\n"                                             \
+"    </div>" "\r\n"                                              \
+"  </body>" "\r\n"                                               \
+"</html>"
+
+
+#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n"   \
+                      HTTP_HEADER_FIELDS "\r\n" \
+                      "\r\n"                    \
+                      HTTP_MESSAGE_BODY "\r\n"
+
+#define IP        "10.0.0.10"
+#define NETMASK   "255.0.0.0"
+#define GATEWAY   "10.0.0.1"
+void dispstralltime(){
+    time_t seconds = time(NULL);
+    strftime(realtime, 32, "%c\n\r", localtime(&seconds));
+   }
+void networksend(void)
+{   
+    // interrupt routine setup
+    Net.lock();
+    printf("Network Enabled\n\r");//n
+    //Configure an ethernet connection
+    EthernetInterface eth;
+    eth.set_network(IP, NETMASK, GATEWAY);
+    eth.connect();
+//
+    Net.unlock();
+    //Now setup a web server
+    TCPServer srv;           //TCP/IP Server
+    TCPSocket clt_sock;      //Socket for communication
+    SocketAddress clt_addr;  //Address of incoming connection
+    
+    /* Open the server on ethernet stack */
+    srv.open(&eth);
+    
+    /* Bind the HTTP port (TCP 80) to the server */
+    srv.bind(eth.get_ip_address(), 80);
+    
+    /* Can handle 5 simultaneous connections */
+    srv.listen(5);
+    
+    while (true) {
+        Net.lock();
+        using namespace std;
+        //Block and wait on an incoming connection
+        srv.accept(&clt_sock, &clt_addr);
+//        printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
+        
+        double temp = sensor.getTemperature();
+        double pres = sensor.getPressure();
+        //Uses a C++ string to make it easier to concatinate
+        string response;
+        //This is a C string
+        char adcIn_str[64];
+        char pres_str[64];
+        char temp_str[64];
+        dispstralltime();              
+        //Read the LDR value
+        float u = adcIn;
+        float b = pres;
+        float a = temp;
+        
+        //Convert to a C String
+        sprintf(adcIn_str, "%5.3f", u );
+        sprintf(pres_str, "%4.2f", b);
+        sprintf(temp_str, "%3.1f", a);
+        
+        //Build the C++ string response
+        response += HTTP_TIME;
+        response += realtime;
+        response += HTTP_MESSAGE_BODY1;
+        response += adcIn_str;
+        response += HTTP_Temperature1;
+        response += temp_str;
+        response += HTTP_Temperature2;
+        response += HTTP_Pressure1;
+        response += pres_str;
+        response += HTTP_Pressure2;
+        response += HTTP_MESSAGE_TIME;
+        response += HTTP_MESSAGE_BODY2;       
+        //Send static HTML response (as a C string)
+        clt_sock.send(response.c_str(), response.size()+6); 
+        Net.unlock();   
+        Thread::signal_wait(SIG_NET);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Network/network.hpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,7 @@
+#ifndef __network__
+#define __network__
+void networksend(void);
+void dispstralltime(void);
+#include "time.h"
+#include "stdio.h"
+#endif
\ No newline at end of file
--- a/README.md	Sun Jan 07 21:29:12 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-# Getting started with Blinky on mbed OS
-
-This guide reviews the steps required to get Blinky working on an mbed OS platform.
-
-Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
-
-## Import the example application
-
-From the command-line, import the example:
-
-```
-mbed import mbed-os-example-blinky
-cd mbed-os-example-blinky
-```
-
-### Now compile
-
-Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
-
-```
-mbed compile -m K64F -t ARM
-```
-
-Your PC may take a few minutes to compile your code. At the end, you see the following result:
-
-```
-[snip]
-+----------------------------+-------+-------+------+
-| Module                     | .text | .data | .bss |
-+----------------------------+-------+-------+------+
-| Misc                       | 13939 |    24 | 1372 |
-| core/hal                   | 16993 |    96 |  296 |
-| core/rtos                  |  7384 |    92 | 4204 |
-| features/FEATURE_IPV4      |    80 |     0 |  176 |
-| frameworks/greentea-client |  1830 |    60 |   44 |
-| frameworks/utest           |  2392 |   512 |  292 |
-| Subtotals                  | 42618 |   784 | 6384 |
-+----------------------------+-------+-------+------+
-Allocated Heap: unknown
-Allocated Stack: unknown
-Total Static RAM memory (data + bss): 7168 bytes
-Total RAM memory (data + bss + heap + stack): 7168 bytes
-Total Flash memory (text + data + misc): 43402 bytes
-Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
-```
-
-### Program your board
-
-1. Connect your mbed device to the computer over USB.
-1. Copy the binary file to the mbed device.
-1. Press the reset button to start the program.
-
-The LED on your platform turns on and off.
-
-## Export the project to Keil MDK, and debug your application
-
-From the command-line, run the following command:
-
-```
-mbed export -m K64F -i uvision
-```
-
-To debug the application:
-
-1. Start uVision.
-1. Import the uVision project generated earlier.
-1. Compile your application, and generate an `.axf` file.
-1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger).
-1. Set breakpoints, and start a debug session.
-
-![Image of uVision](img/uvision.png)
-
-## Troubleshooting
-
-1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0`
-
- ```
- mbed --version
- ```
-
- If not, you can update it:
-
- ```
- pip install mbed-cli --upgrade
- ```
-
-2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size.
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Time/DandTEdit_RTC_Fin.cpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,16 @@
+///*DandTEdit_RTC_Fin.cpp*/
+///*RTC Timer serial inputs*/
+///*Version to get the input data*/
+//
+///*Elec 351 Coursework Semester 2*/
+///* Designed and built by Doug Tilley, Liam Grazier, Alex Baron */
+///*http://www.cplusplus.com/reference/ctime/ - with reference to*/ 
+//#include "mbed.h"
+//#include "stdio.h"      /* IO Functions*/
+//#include "time.h"       /* RTC Time functions*/
+//#include "DandTEdit_RTC_Fin.hpp" /*Headerfile*/
+//
+//
+///*Function to display the time*/
+//
+////PROGRAM END 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Time/DandTEdit_RTC_Fin.hpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,13 @@
+///*DandTEdit_RTC_Fin.hpp*/
+///*Header file for DandTEdit_RTC_Fin.cpp*/
+//
+//#ifndef __DandTEdit_RTC_Fin__ //safeguards
+//#define __DandTEdit_RTC_Fin__
+////
+//#include "mbed.h"
+//#include <stdio.h> 
+//#include <time.h>
+//
+//  //Setting up our time, structures and variables.
+//
+//#endif
\ No newline at end of file
--- a/components.cpp	Sun Jan 07 21:29:12 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,184 +0,0 @@
-#include "mbed.h"
-#include "components.hpp"
-#include "lglcd.h"
-#include "stdio.h"
-#define RED_DONE 1
-#define YELLOW_DONE 2
-//Digital outputs
-DigitalIn onBoardSwitch(USER_BUTTON);
-DigitalOut onBoardLED(LED1);
-DigitalOut redLED(PE_15);
-DigitalOut yellowLED(PB_10);
-DigitalOut greenLED(PB_11);
-SDBlockDevice sd(PB_5, D12, D13, D10);// miso, sclk, cs 
-Mutex Lock1;
-Mutex Lock2;
-Mutex Remove;
-//Inputs
-
-DigitalIn  SW1(PE_12);
-DigitalIn  SW2(PE_14);
-//Serial pc(USBTX, USBRX);
-AnalogIn adcIn(PA_0);
-
-//Environmental Sensor driver
-#ifdef BME
-BME280 sensor(D14, D15);
-#else
-BMP280 sensor(D14, D15);
-#endif
-lglcd mylcd(D7,D6,D5,D4,D3,D2);
-
-//POWER ON SELF TEST
-void post() 
-{
-    //posttest 
-}
-void runanalysis(void){
-    while(1){     
-Lock1.lock();
-double temp = sensor.getTemperature();
-double pressure = sensor.getPressure();
-double lightin = adcIn;
-char TEM[6];
-char PRE[5];  
-char LIGHT[6];
-printf("REFRESH SENSORS\n\r");
-sprintf(TEM,"%.2f", temp);
-sprintf(PRE,"%.2f", pressure);
-sprintf(LIGHT,"%.2f", lightin);
-mylcd.setline(1,1);
-mylcd.write("L:");
-if(lightin > 0.7 && lightin < 0.9)
-{
-mylcd.setline(1,4);
- mylcd.write("|||||||||MAX");    
-}
-else if(lightin > 0.55 && lightin < 0.69)
-{
-mylcd.setline(1,4);
- mylcd.write("|||||||     ");
-}
-else if(lightin > 0.5 && lightin < 0.54)
-{
-mylcd.setline(1,4);
- mylcd.write("|||||       ");
-}
-else if(lightin > 0.4 && lightin < 0.54)
-{
-mylcd.setline(1,4);
- mylcd.write("|||         ");
-}
-else if(lightin > 0.3 && lightin < 0.39)
-{
-mylcd.setline(1,4);
- mylcd.write("||          ");
-} 
-else if(lightin > 0.06 && lightin < 0.29)
-{
-mylcd.setline(1,4);
- mylcd.write("LOW LIGHT    ");
-} 
-else if(lightin < 0.05)
-{
-mylcd.setline(1,4);
-mylcd.write("             ");
-mylcd.setline(1,4);
-mylcd.write("disconnected");
-}
-mylcd.setline(2,1);
-mylcd.write("P:");
-mylcd.write(PRE);
-mylcd.setline(2,10);
-mylcd.write("T:");
-mylcd.write(TEM);
-wait(0.01);
-Lock1.unlock();
-Thread::signal_wait(SIG_READY);
-}
-}
-void sdwrite(void)
-{
-    while(1)
-    {
-        Lock2.lock();
-        FATFileSystem fs("sd", &sd);
-FILE* fp = fopen("/sd/test.csv","a");
-    if (fp == NULL) {
-        errorCode(FATAL);
-        printf("SD FAIL\n\r");
-        mylcd.clear();
-        mylcd.setline(1,0);
-        mylcd.write("SD FAIL");
-    }
-    if (fp != NULL){
-    printf("SD Success\n\r");
-    fprintf(fp, "hello,hello,hello\n\r");
-    wait(0.01);
-    }
-      fclose(fp);      
-      Lock2.unlock(); 
-      Thread::signal_wait(SIG_READY2);   
-
-}
-}
-void sdrun(void)
-{
-if ( sd.init() != 0) {
-printf("Init failed \n");
-mylcd.clear();
-mylcd.setline(1,1);
-mylcd.write("CANNOT INIT SD");        
-errorCode(FATAL);
-}
-if( sd.init() == 0){
-printf("Init Success \n");
-mylcd.clear();
-mylcd.setline(1,1);
-mylcd.write("SD GOOD MAN");
-wait(0.5); //flash the SD error / good code! 
-}
-}
-void sdcheck(void){
-if ( sd.init() != 0) {
-printf("Init failed \n\r");
-mylcd.clear();
-mylcd.setline(1,1);
-mylcd.write("CANNOT INIT SD\n\r");        
-errorCode(FATAL);
-}
-if( sd.init() == 0){
-printf("SD Good\n\r");
-}
-}
-void sdremove(void)
-{
-    Thread::signal_wait(SIG_REMOVE); 
-    mylcd.clear();  
-    Remove.lock();
-                sd.deinit();
-                mylcd.clear();
-                mylcd.setline(1,0);
-                greenLED = 1;
-                mylcd.write("R");
-                printf("SD REMOVED");
-                errorCode(FATAL);
-    Remove.unlock();
-}
-void errorCode(ELEC350_ERROR_CODE err)
-{
-    switch (err) {
-      case OK:
-        greenLED = 1;
-        wait(1.0);
-        greenLED = 0;
-        return;                
-      case FATAL:
-        while(1) {
-            redLED = 1;
-            wait(0.1);
-            redLED = 0;
-            wait(0.1);                
-        }
-    };
-}
\ No newline at end of file
--- a/components.hpp	Sun Jan 07 21:29:12 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-#ifndef __sample_hardware__
-#define __sample_hardware__
-#define SIG_READY 1
-#define SIG_READY2 1
-#define SIG_REMOVE 1
-#define SIG_NET 1
-//#define BME
-#ifdef BME
-#include "BME280.h"
-#else
-#include "BMP280.h"
-#endif
-#include "SDBlockDevice.h"
-#include "FATFileSystem.h"
-void runanalysis(void);
-void sdrun(void);
-void sdcheck(void);
-void sdwrite(void);
-void sdremove(void);
-enum ELEC350_ERROR_CODE {OK, FATAL};
-extern DigitalOut onBoardLED;
-extern DigitalOut redLED;
-extern DigitalOut yellowLED;
-extern DigitalOut greenLED;
-extern DigitalIn  onBoardSwitch;
-extern DigitalIn  SW1;
-extern DigitalIn  SW2;
-//extern Serial pc;
-extern AnalogIn adcIn;
-#ifdef BME
-extern BME280 sensor;
-#else
-extern BMP280 sensor;
-#endif
-extern void post();
-extern void errorCode(ELEC350_ERROR_CODE err);
-#endif
\ No newline at end of file
--- a/main.cpp	Sun Jan 07 21:29:12 2018 +0000
+++ b/main.cpp	Tue Jan 09 05:43:43 2018 +0000
@@ -2,24 +2,28 @@
 #include "mbed.h"
 #include "network.hpp"
 #include "lglcd.h"
-InterruptIn sw1(USER_BUTTON);
+#include "stx.hpp"
 Thread samplesThread(osPriorityNormal);
 Thread sdThread(osPriorityLow);
-Thread sdRemoveThread(osPriorityLow);
-//Thread rtThread;
-//Thread stxThread;
+Thread sdRemoveThread(osPriorityHigh);
+Thread timebuttonThread(osPriorityNormal);
+Thread stxThread(osPriorityLow);
 Thread netThread(osPriorityRealtime);
+Mutex SD;
 void inter1();
 void inter2();
 void inter3();
 void inter4();
-// This is a very short demo that demonstrates all the hardware used in the coursework.
-// You will need a network connection set up (covered elsewhere). The host PC should have the address 10.0.0.1
+void inter5();
+void inter6();
 Ticker samples;
 Ticker remov;
 InterruptIn sdex(USER_BUTTON);
 Ticker storage;
 Ticker netTick;
+Ticker serielTick;
+Ticker buttonTick;
+int T = 5;
 void inter1(){
  sdcheck();
  samplesThread.signal_set(SIG_READY);          
@@ -28,27 +32,37 @@
  sdThread.signal_set(SIG_READY2);  
 }
 void inter3(){
- printf("CHECK REMOVE BUTTON\n\r");
+  //printf("CHECK REMOVE BUTTON\n\r");
  if(sdex == 1){
+    //printf("BUTTON IN");
  sdRemoveThread.signal_set(SIG_REMOVE);
  }
  }
  void inter4(){
  netThread.signal_set(SIG_NET);
 }
+void inter5(){
+ stxThread.signal_set(SIG_SX);
+}
+//void inter6(){
+// timebuttonThread.signal_set(SIG_button);    
+//}
 int main(){
+lglcd mylcd(D7,D6,D5,D4,D3,D2);
+setuptime();
 sdrun();
-lglcd mylcd(D7,D6,D5,D4,D3,D2);
-mylcd.clear();
+lcdstart();
+welcomemsg();
 sdThread.start(sdwrite);
-storage.attach(&inter2,10); //runs send to sd  based on last number (5) in this case (every 5 seconds)
+storage.attach(&inter2,T); //runs send to sd  based on last number (10) in this case (every 10 seconds)
 samplesThread.start(runanalysis); 
-samples.attach(&inter1,1);   //runs analysis based on last number (1) in this case (every 1 second)
+samples.attach(&inter1,T);   //runs analysis based on last number (1) in this case (every 1 second)
 sdRemoveThread.start(sdremove);
-remov.attach(&inter3,3);//checks sd remove key every second
+remov.attach(&inter3,3);//checks sd remove key every 3 second
 netThread.start(networksend);
 netTick.attach(&inter4,0.01);
-
-
- 
+stxThread.start(useseriel);
+serielTick.attach(&inter5,0.1);
+//timebuttonThread.start(//insertnamehere);
+//buttonTick.attach(&inter6,0.3); 
 }
\ No newline at end of file
--- a/network.cpp	Sun Jan 07 21:29:12 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-#if !FEATURE_LWIP
-    #error [NOT_SUPPORTED] LWIP not supported for this target
-#endif
-
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "TCPServer.h"
-#include "TCPSocket.h"
-#include <iostream>
-#include <string> 
-#include "BMP280.h"
-#include "components.hpp"
-#include "network.hpp"
-Mutex Net;
-#define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
-#define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
-#define HTTP_MESSAGE_BODY1 ""                                    \
-"<html>" "\r\n"                                                  \
-"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
-"    <div style=\"margin:auto\">" "\r\n"                         \
-"      <h1>Sensor Data</h1>" "\r\n"                              \
-"      <p>Light Level LDR value: " "\r\n" 
-                 
-#define HTTP_Pressure1 ""                                        \
-"<html>" "\r\n"                                                  \
-"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
-"    <div style=\"margin:auto\">" "\r\n"                         \
-"      <h1> </h1>" "\r\n"                                        \
-"      <p>Pressure(mbar): " "\r\n"                
-
-#define HTTP_Pressure2 ""                                        \
-       "</p>" "\r\n"                                             \
-"    </div>" "\r\n"                                              \
-"  </body>" "\r\n"                                               \
-"</html>"
-
-                 
-#define HTTP_Temperature1 ""                                     \
-"<html>" "\r\n"                                                  \
-"  <body style=\"display:flex;text-align:center\">" "\r\n"       \
-"    <div style=\"margin:auto\">" "\r\n"                         \
-"      <h1> </h1>" "\r\n"                                        \
-"      <p>Temperature(Degrees Celcius): " "\r\n"       
-
-#define HTTP_Temperature2 ""                                     \
-       "</p>" "\r\n"                                             \
-"    </div>" "\r\n"                                              \
-"  </body>" "\r\n"                                               \
-"</html>"
-
-#define HTTP_MESSAGE_BODY2 ""                                    \
-       "</p>" "\r\n"                                             \
-"    </div>" "\r\n"                                              \
-"  </body>" "\r\n"                                               \
-"</html>"
-
-#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n"   \
-                      HTTP_HEADER_FIELDS "\r\n" \
-                      "\r\n"                    \
-                      HTTP_MESSAGE_BODY "\r\n"
-
-#define IP        "10.0.0.10"
-#define NETMASK   "255.0.0.0"
-#define GATEWAY   "10.0.0.1"
-
-AnalogIn pres();
-AnalogIn temp();
-
-void networksend(void)
-{   
-    // interrupt routine setup
-    printf("Basic HTTP server example\n");//n
-    
-    //Configure an ethernet connection
-    EthernetInterface eth;
-    eth.set_network(IP, NETMASK, GATEWAY);
-    eth.connect();
-    printf("The target IP address is '%s'\n", eth.get_ip_address());
-    
-    //Now setup a web server
-    TCPServer srv;           //TCP/IP Server
-    TCPSocket clt_sock;      //Socket for communication
-    SocketAddress clt_addr;  //Address of incoming connection
-    
-    /* Open the server on ethernet stack */
-    srv.open(&eth);
-    
-    /* Bind the HTTP port (TCP 80) to the server */
-    srv.bind(eth.get_ip_address(), 80);
-    
-    /* Can handle 5 simultaneous connections */
-    srv.listen(5);
-    
-    while (true) {
-        Net.lock();
-        using namespace std;
-        //Block and wait on an incoming connection
-        srv.accept(&clt_sock, &clt_addr);
-        printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
-        
-        double temp = sensor.getTemperature();
-        double pres = sensor.getPressure();
-        //Uses a C++ string to make it easier to concatinate
-        string response;
-        //This is a C string
-        char adcIn_str[64];
-        char pres_str[64];
-        char temp_str[64];
-               
-        //Read the LDR value
-        float u = adcIn;
-        float b = pres;
-        float a = temp;
-        
-        //Convert to a C String
-        sprintf(adcIn_str, "%5.3f", u );
-        sprintf(pres_str, "%4.2f", b);
-        sprintf(temp_str, "%3.1f", a);
-        printf("LDR: %5.3f\n\r", u);
-        
-        //Build the C++ string response
-        response = HTTP_MESSAGE_BODY1;
-        response += adcIn_str;
-        response += HTTP_Temperature1;
-        response += temp_str;
-        response += HTTP_Temperature2;
-        response += HTTP_Pressure1;
-        response += pres_str;
-        response += HTTP_Pressure2;
-        response += HTTP_MESSAGE_BODY2;       
-        //Send static HTML response (as a C string)
-        clt_sock.send(response.c_str(), response.size()+6); 
-        Net.unlock();   
-    }
-}
--- a/network.hpp	Sun Jan 07 21:29:12 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-#ifndef __network__
-#define __network__
-void networksend(void);
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serialtx/stx.cpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,109 @@
+#include "mbed.h"
+#include "stx.hpp"
+#include "components.hpp"
+Mutex Sx;
+char buffer[255];
+int empty = 0; 
+void welcomemsg(void){
+printf("WELCOME TO ELEC351 ENVIRONMENTAL SERIAL INTERFACE\n\rFOR ASSISTANCE TYPE HELP\n\r");
+}
+void datain(void){
+    if(empty == 0){
+     Sx.lock();
+     scanf("%s", &buffer);
+     Sx.unlock();
+     }
+    }
+void printcommandlist(){
+    Sx.lock();
+    printf("Command List:\n\r READALL\n\r DELETEALL\n\r SETDATE\n\r DISPLAYTIME\n\r SETTIME\n\r SETT\n\r STATEON(Sampling State)\n\r STATEOFF(Sampling State)\n\r LOGGINGON\n\r LOGGINGOFF\n\r COMMANDLIST\n\r" );
+    Sx.unlock();
+    }
+void readdata(){
+    if (buffer != ""){
+     if (strstr(buffer, "READALL")){
+        readalldata();
+        }
+        else if(strstr(buffer, "COMMANDLIST")){
+        printcommandlist();   
+        }
+        else if(strstr(buffer, "DISPLAYTIME")){
+        printcommandlist();   
+        }
+        else if(strstr(buffer, "HELP")){
+        help();   
+        }
+        else if(strstr(buffer, "DELETEALL")){
+        deletealldata();
+        }
+        else if(strstr(buffer, "SETDATE")){////////COME BACK HERE LATE
+        rundate();
+        }
+        else if(strstr(buffer, "SETTIME")){////////COME BACK HERE LATE
+        runtime();
+        }
+        else if(strstr(buffer, "SETT")){////////COME BACK HERE LATE
+        setT();
+        }
+        else if(strstr(buffer, "STATEON")){
+        stateon();
+        }
+        else if(strstr(buffer, "STATEOFF")){
+        stateoff();
+        }
+        else if(strstr(buffer, "LOGGINGON")){
+        loggingon();
+        }
+        else if(strstr(buffer, "LOGGINGOFF")){
+        loggingoff();
+        }
+        else
+        {
+        printf("UNRECOGNISED\n\r");
+        }
+       }
+       }
+void help(){
+    printf("HELP: \n\rFOR COMMAND LIST, type COMMANDLIST\n\r");
+    }    
+void readalldata(){
+    printf("read all data\n\r");
+    } //displays date, tim, temperature, presure, ligt
+void deletealldata(){
+    printf("delete all data \n\r");
+    } //deletes all memory from th iternal memory
+void setdate(){
+    printf("Set Date\n\r");
+    } //sets the day month and year
+void settime(){
+printf("Set Time\n\r");
+} //sets the clock hours, minutes, seconds
+void setT()
+{
+    printf("Set Sampling Period 'T'\n\r");
+    } //sets the sampling period to <T> seconds
+void stateon(){
+    printf("Set Sampling ON\n\r");
+    } //turns ampling ON and OFF
+void stateoff(){
+    printf("Set Sampling OFF\n\r");
+    } 
+void loggingon(){
+    
+    printf("Logging On\n\r");
+    } 
+void loggingoff(){
+    
+    printf("Logging Off\n\r");
+    }    
+    //turns diagnostic logging ON and OFF
+void useseriel(){
+  
+    help();
+    while(true){
+     Thread::signal_wait(SIG_SX);
+     datain();
+     readdata();
+                }
+        }   
+           
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serialtx/stx.hpp	Tue Jan 09 05:43:43 2018 +0000
@@ -0,0 +1,20 @@
+#ifndef __stx__
+#define __stx__
+#define SIG_SX 1
+void welcomemsg(void);
+void datain();
+void useseriel();
+void readalldata(); //displays date, tim, temperature, presure, ligt
+void deletealldata(); //deletes all memory from th iternal memory
+void setdate(); //sets the day month and year
+void settime(); //sets the clock hours, minutes, seconds
+void setT(); //sets the sampling period to <T> seconds
+void stateon(); //turns ampling ON and OFF
+void stateoff(); //turns ampling ON and OFF
+void help();
+void loggingon();
+void loggingoff(); //turns diagnostic logging ON and OFF  
+void deleten();//deletes the <n> records
+void readdata();
+void printcommandlist();
+#endif
\ No newline at end of file