Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Matrix
Fork of Alarmsystem_log_funksjon_funker_ikke by
Diff: main.cpp
- Revision:
- 15:272fb4e610dc
- Parent:
- 14:8e7aaf0cf5d7
- Child:
- 16:3d2e29aa5df5
--- a/main.cpp Tue Feb 20 08:35:16 2018 +0000
+++ b/main.cpp Tue Feb 20 14:06:31 2018 +0000
@@ -3,7 +3,8 @@
#include <RtosTimer.h>
#include <math.h>
#include "mbed_error.h"
-#include<string>
+#include <string>
+#include <iostream>
/////DEFINISJONER/////
#define Inn 4
@@ -28,6 +29,7 @@
int tilstand = 0;
int TilstandSjekk(int, int);
volatile bool running = true;
+volatile bool admin = false;
string password = ("admin");
string keyinput;
//volatile int Klokke = 0;
@@ -35,11 +37,13 @@
/////FUNKSJON DEKLARASJONER/////
void Alarmf();
-Thread monitoring;
+Thread Alarm;
+Thread Sone;
int Tilstandssjekk();
-int admin_access_granted();
-int sone_monitor();
-int read_keyinput();
+void admin_access_granted();
+void sone_monitor();
+void password_check();
+//void read_keyinput();
//void Alarm();
//Ticker AlarmBlink; // 10Hz blinking for alarmfunksjon på lys og telling
@@ -47,26 +51,31 @@
/////MAIN/////
int main()
{
- pc.printf("Write admin access password:\n");
- pc.scanf("%s",keyinput);
- if(keyinput == password){
- monitoring(sone_monitor);
- admin_access_granted();
- while(1) {
- RtosTimer Alarm(Alarmf);
+ while(1) {
+ if(admin == false) {
+ password_check();
+ }
+ while(admin) {
+ Alarm.start(Alarmf);
+ sone_monitor();
read_keyinput();
-
- }//while-end
- }//if-end
-}//main-end
-
+ }//if-end
+ }//main-end
+}
/////FUNKSJONER/////
void Alarmf(void)
{
- Driftslys = !Driftslys;
+ while(1) {
+ if(running == true) {
+ Driftslys = !Driftslys;
+ Thread::wait(50);
+ } else {
+ Driftslys = 1;
+ }
+ }
}
int TilstandSjekk(int i, int tilstand)
@@ -74,7 +83,7 @@
if(tilstand == 0) {
//pc.printf("Vi er i funksjonen normaldrift i sone: %d \n", i);
//AlarmBlink.detach();
- Alarm.stop();
+ running = false;
double n = 2; // We want 2^i
double Y = 1;
for(int k=1; k<=i; k++) Y = Y*n;
@@ -87,7 +96,7 @@
if(tilstand == 1) { //Hvis dør 1 er åpen...
//pc.printf("Vi er i funksjonen tilstandssjekk dor 1, med verdi: %d\n", i);
//Alarm();
- Alarm.start(50);
+ running = true;
double n = 2; // We want 2^i
double Y = 1;
for(int k=1; k<=i; k++) Y = Y*n;
@@ -99,7 +108,7 @@
if(tilstand == 2) { //Hvis dør 2 er åpen...
//pc.printf("Vi er i funksjonen tilstandssjekk dor 2, med verdi: %d\n", i);
//Alarm();
- Alarm.start(50);
+ running = true;
double n = 2; // We want 2^i
double Y = 1;
for(int k=1; k<=i; k++) Y = Y*n;
@@ -111,7 +120,7 @@
if(tilstand == 3) { //Hvis begge dører er åpne
//pc.printf("Vi er i funksjonen tilstandssjekk alle dorer, med verdi: %d \n", i);;
// Alarm();
- Alarm.start(50);
+ running = true;
double n = 2; // We want 2^i
double Y = 1;
for(int k=1; k<=i; k++) Y = Y*n;
@@ -123,13 +132,14 @@
}
return 0;
}
-sone_monitor()
+void sone_monitor()
{
Soner[0] = _Sone1;
//Soner[1] = _Sone2;
//Soner[2] = _Sone3;
//Soner[3] = _Sone4;
for(int i=0; i < Inn; i++) {
+ read_keyinput(i);
//pc.printf("%f\n", Soner[i]);
if((Soner[i] > 0.75 )&&( Soner[i] < 0.83)) { //Tilstand1, Dør 1 åpen
//pc.printf("Vi er i Tilstand1\n");
@@ -161,22 +171,97 @@
//while(sysclock == 0);
//Tid++;
}
-admin_access_granted()
+void admin_access_granted()
+{
+ admin = true;
+ pc.printf("Admin access granted\n");//info
+ pc.printf("Folgende kommandoer kan brukes: \n");// liste over funksjoner tilgjenglig.
+ pc.printf("Status sone og dor(sone forst, dor etter) Kommando: 1,2 \n");// funksjon 1 - request spesific status
+ pc.printf("Status alle soner og dorer. Kommando: Status \n");// funksjon 1 - request status all
+ pc.printf("Reset hele systemet. Kommando: 'Reset' \n");// funksjon 4 - request log all
+}
+void password_check()
{
- pc.printf("Admin access granted\n");//info
- pc.printf("Following commands are available\n");// liste over funksjoner tilgjenglig.
- pc.printf("#req_sta_sone(1-4)_door(1-2)\n");// funksjon 1 - request spesific status
- pc.printf("#req_sta_all\n");// funksjon 1 - request status all
- pc.printf("#reset_sone(1-4)_door(1-2)\n");// funksjon 3 - request spesific log
- pc.printf("#reset_all\n");// funksjon 4 - request log all
+ if(pc.readable() == 1) {
+ pc.printf("Write password: ");
+ string b;
+ char s;
+ for(int i = 0; i < 5; i++) {
+ s = pc.getc();
+ pc.printf("%c", s);
+ b += s;
+ if(b == password) {
+ admin_access_granted();
+ }
+ }
+ }
}
-read_keyinput()
-{
- serial.readabl
- pc.scanf("%s", keyinput);
-/*void Alarm()
+void read_keyinput(int i)
{
- Driftslys = !Driftslys;
- wait(0.05);
- }*/
\ No newline at end of file
+ if(pc.readable() == 1) {
+ pc.printf("Du skriver: ");
+ string read;
+ char c;
+ for(i = 0; i < 6; i++) {
+ c = pc.getc();
+ pc.printf("%c", c);
+ read += c;
+ switch(read) {
+ case "1, 1":
+ request_status_sone_dor(1, 1);
+ break;
+ case "1, 2":
+ request_status_sone_dor(1, 2);
+ break;
+ case "2, 1":
+ request_status_sone_dor(2, 1);
+ break;
+ case "2, 2":
+ request_status_sone_dor(2, 2);
+ break;
+ case "3, 1":
+ request_status_sone_dor(3, 1);
+ break;
+ case "3, 2":
+ request_status_sone_dor(3, 2);
+ break;
+ case "4, 1":
+ request_status_sone_dor(4, 1);
+ break;
+ case "4, 2":
+ request_status_sone_dor(4, 2);
+ break;
+ case "Status":
+ request_status();
+ break;
+ case "Reset":
+ request_reset();
+ break;
+ }
+ }
+ }
+}
+
+void request_status_sone_dor(int sone, int dor)
+{
+ double n = 2; // We want 2^i
+ double Y = 1;
+ for(int k=1; k<=sone; k++) Y = Y*n;
+ if(dor == 1) {
+ if (Alarmutganger1 == Y) pc.printf("Dor: %d i sone: %d er lukket", dor, Y);
+ else pc.printf("Dor: %d i sone: %d er apnet", dor, Y);
+ }
+ if(dor == 2) {
+ if (AlarmUtganger2 == Y) pc.printf("Dor: %d i sone: %d er lukket", dor, Y);
+ else pc.printf("Dor: %d i sone: %d er apnet", dor, Y);
+ }
+}
+
+void request_status() {
+ int dor1[Inn] = {
+ dor1[Inn] = AlarmUtganger2;
+
+
+//BusOut AlarmUtganger1(p21, p22, p23, p24); //1 - Dør 1 Sone 1, 2 - Dør 1 Sone 2, 4 - Dør 1 Sone 3, 8 - Dør 1 Sone 4
+//BusOut AlarmUtganger2(p25, p26, p27, p28); //1 - Dør 2 Sone 1, 2 - Dør 2 Sone 2, 4 - Dør 2 Sone 3, 8 - Dør 2 Sone 4
\ No newline at end of file
