Benjamin Leverett / Mbed 2 deprecated Final_Project_2

Dependencies:   mbed mbed-rtos 4DGL-uLCD-SE SDFileSystem ATParser

Files at this revision

API Documentation at this revision

Comitter:
chenchen2020
Date:
Mon Apr 20 02:19:40 2020 +0000
Child:
1:8eb0ee57df9f
Commit message:
4180_Final_Project_Fengrui_Zuo

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
ATParser.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Mon Apr 20 02:19:40 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ATParser.lib	Mon Apr 20 02:19:40 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/NetworkSocketAPI/code/ATParser/#c08984860329
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Apr 20 02:19:40 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/neilt6/code/SDFileSystem/#e4d2567200db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 20 02:19:40 2020 +0000
@@ -0,0 +1,120 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "ATParser.h"
+#include "uLCD_4DGL.h"
+#include "SDFileSystem.h"
+//#include "wave_player.h"
+#include <string>
+#include <iostream> 
+using namespace std;
+
+//General setups
+DigitalOut cmdMode(p18);
+Serial pc(USBTX, USBRX);
+BufferedSerial ble(p13,p14);
+DigitalOut cmdstuff(p18);
+uLCD_4DGL uLCD(p28,p27,p30);
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+//AT command data handlers
+char delimiter[] = "\r\n";
+int buffer_size = 256;
+int timeout = 100;
+bool debug = false;
+ATParser at(ble, delimiter, buffer_size, timeout, debug);
+char buffer[10];
+volatile int risk_level = 0;
+
+//RTOS
+Mutex mutex_lock;
+
+//Global Data points and arrays
+int averageCount = 0;
+volatile int RSSI_array[15];
+
+
+int calculate_average(volatile int *input, int size){
+    int average;
+    for(int i = 0; i< size; i++){
+        average = average + input[i];
+    }
+    average = average/size;
+    return average;
+}
+
+void parse_RSSI(){
+    if(buffer[0] == '-'){
+        pc.printf("RSSI: ");
+        pc.putc(buffer[1]);
+        pc.putc(buffer[2]);
+        pc.printf("\n");
+        int digit1 = buffer[1] - 48;
+        int digit2 = buffer[2] - 48;
+        int total = 10*digit1 + digit2;
+        if (averageCount <= 15){
+            RSSI_array[averageCount] = total;
+        }
+        averageCount++;
+        
+        if(averageCount > 15 && buffer[0] == '-'){
+            averageCount = 0;
+            int average = calculate_average(RSSI_array, 15);
+            if(average < 55){
+                risk_level = 3;
+            }else if(average > 55 && average < 70) {
+                risk_level = 2;
+            }else if(average > 70 && average < 90) {
+                risk_level = 1;
+            }
+            else{
+               risk_level = 0; 
+            }
+        }
+        pc.printf("Risk level: ");
+        pc.printf("%i\n", risk_level);
+    }else{
+        pc.printf("Disconnected\n");
+        
+    }
+}
+
+void speaker_alarm(){
+ 
+}
+
+void logging_SD_card(){
+ 
+}
+
+void blink_leds(){
+ 
+}
+
+void display_ulcd(){
+
+}
+ 
+int main()
+{
+    cmdstuff = 1;
+    at.send("AT") && at.recv("OK");
+    at.send("AT+AB ChangeDefaultBaud [9600]", 3) && at.recv("OK");
+    pc.baud(9600);
+    ble.baud(9600);
+    
+    //Thread SD_Thread();
+    //Thread ULCD_Thread();
+    //Thread LED_Thread();
+    //Thread Speaker_Thread();
+    
+    while(1) {
+        //wait(0.05);
+        at.send("AT+BLEGETRSSI") && at.read(buffer, 10);
+        /*for(int i = 0; i < 10; i++){
+            pc.putc(buffer[i]);
+        }*/
+        parse_RSSI();
+        //pc.putc("\n");
+        //pc.putc();   
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Apr 20 02:19:40 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Apr 20 02:19:40 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file