MAIN

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Files at this revision

API Documentation at this revision

Comitter:
J_Satchell
Date:
Mon May 15 11:38:07 2017 +0000
Parent:
36:af6abc6f7590
Commit message:
fff

Changed in this revision

Data.hpp Show annotated file Show diff for this revision Revisions of this file
log.cpp Show annotated file Show diff for this revision Revisions of this file
prompt.cpp Show annotated file Show diff for this revision Revisions of this file
sensor.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Data.hpp	Mon May 15 08:58:08 2017 +0000
+++ b/Data.hpp	Mon May 15 11:38:07 2017 +0000
@@ -11,7 +11,7 @@
         float tempCelsius;
         float humi;
         float pressure;
-        uint32_t seconds, minutes, hours; 
+        time_t logtime;
 };
 
 #endif
\ No newline at end of file
--- a/log.cpp	Mon May 15 08:58:08 2017 +0000
+++ b/log.cpp	Mon May 15 11:38:07 2017 +0000
@@ -1,5 +1,5 @@
 #include "Data.hpp"
-
+/* log holds all functions for storing records in circular buffer*/
 Data queue_array[120];
 int rear = 0;
 int front = 0;
@@ -11,6 +11,7 @@
 
 }
 
+/*pushes new record on front of queue*/
 void log_push(Data data)
 {
     rear = (rear + 1) % 120;
@@ -22,6 +23,7 @@
     queue_array[rear] = data;    
 }
 
+/*deletes a record*/
 Data log_pop()
 {
     Data record;
@@ -33,6 +35,7 @@
         
 }
 
+/*gets length of array*/
 int log_length()
 {
     
@@ -43,6 +46,7 @@
     
 }
 
+/*gets a specific record*/
 Data log_get(int index)
 {
     
--- a/prompt.cpp	Mon May 15 08:58:08 2017 +0000
+++ b/prompt.cpp	Mon May 15 11:38:07 2017 +0000
@@ -2,15 +2,24 @@
 #include "log.hpp"
 #include "Data.hpp"
 
+/* prompt deals with all user inputs and what functions should run in response */
 Serial serial(USBTX, USBRX);
 Mutex mutex_p;
 
+/*function for writing out a record with time struct to format time*/
+void prompt_write_entry(Data entry){
+            ;
+            time_t currenttime = entry.logtime;
+            tm* timenew = localtime(&currenttime);
+                        
+            serial.printf("%4.2fC %3.1f%% %6.1f %i %i %i \r\n", entry.tempCelsius, entry.humi, entry.pressure, timenew->tm_hour, timenew->tm_min, timenew->tm_sec);
+            
+    }
 
 void readline(char* buffer)
 {
     int i = 0;
-    while (1)
-    {
+    while (1) {
         char c = serial.getc();
         serial.putc(c);
         buffer[i] = c;
@@ -31,28 +40,72 @@
 
 
 void prompt_interpret(char* cmd)
-{   mutex_p.lock();
+{
+    mutex_p.lock();
+    int input;
     int n = log_length();
-       n = (n - 1);
-    if (strcmp(cmd, "help") == 0){
-        serial.printf("Commands:\r\n  help -\r\n READ ALL - Show all records \r\n");
+    int hours;
+    int minutes;
+    int seconds;
+    n = (n - 1);
+    if (strcmp(cmd, "help") == 0) {
+        serial.printf("Commands:\r\n  help -\r\n READ ALL - Show all records \r\n READ <n> = Show specified amount of records \r\n SETTIME <hh> <mm> <ss> = Set the time \r\n DELETE ALL = Deletes all records \r\n DELETE <n> = deletes the oldest record \r\n ");
+    } else if (strcmp(cmd, "READ ALL") == 0) {
+        serial.printf("\r\n");
+        for (int i = n - 1; i >= 1; i--) {
+            Data entry = log_get(i);
+            prompt_write_entry(entry);
         }
-    else if (strcmp(cmd, "READ ALL") == 0)
-        {serial.printf("\r\n");
-        for (int i = n - 1; i >= 1; i--){ 
-        Data entry = log_get(i);
-        serial.printf("%4.2fC %3.1f%% %6.1f %i %i %i \r\n", entry.tempCelsius, entry.humi, entry.pressure, entry.seconds, entry.minutes, entry.hours);
+    } else if (sscanf(cmd, "READ %i", &input) == 1) {
+        serial.printf("\r\n");
+        
+        int n = log_length();
+        if (input > n){
+            input = n;
+            }
+        for (int i = input - 1; i >= 1; i--) {
+            Data entry = log_get(i);
+            prompt_write_entry(entry);
+        }
+    }
+    else if (sscanf(cmd, "SETTIME %i %i %i", &hours, &minutes, &seconds) == 3){
+            serial.printf("\r\n");
+            time_t currenttime = time(0);
+            tm* timenew = localtime(&currenttime);
+            
+            timenew->tm_hour = hours;
+            timenew->tm_min = minutes;
+            timenew->tm_sec = seconds;
+            
+            set_time(mktime(timenew));
+        }  
+        else if (strcmp(cmd, "DELETE_ALL") == 0) {
+        serial.printf("\r\n");
+        for (int i = n - 1; i >= 1; i--) {
+            log_pop();
+            
         }
         }
-    else{
+        else if (sscanf(cmd, "DELETE %i", &input) == 1) {
+        serial.printf("\r\n");
+        
+        int n = log_length();
+        if (input > n){
+            input = n;
+            }
+        for (int i = input - 1; i >= 1; i--) {
+            log_pop();
+             }
+    }
+    
+    else {
         serial.printf("Unknown command!\r\n");
-        }
-        mutex_p.unlock();
+    }
+    mutex_p.unlock();
 }
 void prompt_run()
-{
-    while (1)
     {
+    while (1) {
         char buffer[64];
         readline(buffer);
 
--- a/sensor.cpp	Mon May 15 08:58:08 2017 +0000
+++ b/sensor.cpp	Mon May 15 11:38:07 2017 +0000
@@ -42,12 +42,10 @@
     entry.tempCelsius = tempCelsius;
     entry.humi = humi;
     entry.pressure= barometer.pressure();
-    entry.seconds = seconds;
-    entry.minutes = minutes;
-    entry.hours = hours;
+    entry.logtime = time(0);
     log_push(entry);
     mutex_s.unlock();
-    Thread::wait(15000);
+    Thread::wait(1000);
     
     }