no description
Fork of Middleware by
Revision 1:32a08ca33b00, committed 2015-12-07
- Comitter:
- Jorge_Beltran
- Date:
- Mon Dec 07 01:50:01 2015 +0000
- Parent:
- 0:d1ff330c5128
- Commit message:
- SensorsForGusProject
Changed in this revision
diff -r d1ff330c5128 -r 32a08ca33b00 Initial.h --- a/Initial.h Sat Dec 05 17:43:29 2015 +0000 +++ b/Initial.h Mon Dec 07 01:50:01 2015 +0000 @@ -19,13 +19,28 @@ static Serial pc(USBTX, USBRX); static DigitalOut ledRED(LED1); -static DigitalOut ledGREEN(LED2); +static DigitalOut ledGREEN(LED2); static DigitalOut ledBLUE(LED3); -static DigitalIn enable1(D8); +//START PIR SENSOR INPUT INIT +static DigitalIn PIR1(D0); +static DigitalIn PIR2(D1); +//END PIR SENSOR INPUT INIT +//START WINDOW SENSOR INPUT +static DigitalIn W1(D2); +static DigitalIn W2(D3); +static DigitalIn W3(D4); +//END WINDOW SENSOR INPUT INIT +//START DOOR SENSOR INPUT +static DigitalIn DOORSensor(D5); +//END DOOR SENSOR INPUT INIT +//START LIGHT CONTROL OUTPUT +static DigitalOut LightControl(D6); +//END LIGHT CONTROL OUTPUT static InterruptIn sw2(SW2); static TCPSocketConnection socketTCP1; static TCPSocketConnection socketTCP2; static UDPSocket socketUDP; +static TCPSocketServer serverTCP; //sstatic TCPSocketConnection socket; static char *cad; static char *s_myIP;
diff -r d1ff330c5128 -r 32a08ca33b00 SensorPIR.cpp --- a/SensorPIR.cpp Sat Dec 05 17:43:29 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - -Drivers.cpp - -Only to improve the clarity of main .cpp -This don't have any new classes - -All the multiple task are here -for Smart Room project asked by -Gustavo Torres - -Last update by RoHe 16/11/2015 - -*/ - -#include "SensorPIR.h" - -Drivers::Drivers() -{ - varInt=5; -} - -bool Drivers::is_good(void) -{ - return true; -} - -int Drivers::getVar(void) -{ - return varInt; -} - -char* Drivers::echo(void) -{ - return "Hello from Library"; -} - -/*Defines*/ -//Serial UARTPIR(USBTX, USBRX); -//DigitalOut dout(LED1); -//DigitalIn enable2(D1); -//DigitalIn enable3(D2); -//DigitalIn enable4(D3); - -/*Functions*/ -int GetPersonStatus(int RoomPrescence) { - bool print = 0; - bool RoomStatus = 0; - wait(2); //Wait for sensor to take snap shot of still room - - switch(RoomPrescence) - { - case 1: - if(enable1==1 /*|| enable2==1 || enable3==1 || enable4==1*/) - { - RoomStatus = 1; - ledGREEN=1; - if(print == 0) - { - pc.printf("Presencia detectada\n\r"); - print = 1; - } - } - else - { - RoomStatus = 0; - ledGREEN=0; - if(print == 1) - { - pc.printf("Ninguna presencia detectada\n\r"); - print = 0; - } - } - break; - - case 2: - /*ADD NEW ROOM*/ - break; - - default: - /*Do Nothing*/ - break; - } - return RoomStatus; -} \ No newline at end of file
diff -r d1ff330c5128 -r 32a08ca33b00 SensorPIR.h --- a/SensorPIR.h Sat Dec 05 17:43:29 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - -Database.cpp - -Only to improve the clarity of main .cpp -This don't have any new classes - -All the multiple task are here -for Smart Room project asked by -Gustavo Torres - -Last update by RoHe 16/11/2015 - -*/ -#include "mbed.h" -#include "Initial.h" - -#ifndef SENSORPIR_H_ -#define SENSORPIR_H_ - -class Drivers { - -public: - Drivers(); - bool is_good(void); - int getVar(void); - char* echo(void); - -private: - int varInt; -}; - - - -/*Extern Defines*/ - -/*Extern Variables*/ - -/*Extern Functions*/ -extern int GetPersonStatus(int RoomPrescence); - - - -#endif
diff -r d1ff330c5128 -r 32a08ca33b00 Sensors.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sensors.cpp Mon Dec 07 01:50:01 2015 +0000 @@ -0,0 +1,100 @@ +#include "Sensors.h" +#include "Initial.h" + + +/*Functions*/ + +//PRESCENCE DETECTION FUNCTION +bool GetPrescenceStatus(){ + static bool RoomStatus = FALSE; + + if(PIR1==TRUE || PIR2==TRUE) + { + RoomStatus = TRUE; + } + else + { + RoomStatus = FALSE; + } + + return RoomStatus; +} + +//DOOR STATUS FUNCION +bool GetDoorStatus(){ + static bool DoorStatus = CLOSED; + + if(DOORSensor == TRUE) + DoorStatus = OPEN; + else + DoorStatus = CLOSED; + + return DoorStatus; +} + + +//WINDOW STATUS FUNCTION +int GetWindowStatus(int window){ + static int WindowStatus = CLOSED; + + switch(window) + { + case 1: + if(W1) + WindowStatus = OPEN; + else + WindowStatus = CLOSED; + break; + case 2: + if(W2) + WindowStatus = OPEN; + else + WindowStatus = CLOSED; + break; + case 3: + if(W3) + WindowStatus = OPEN; + else + WindowStatus = CLOSED; + break; + default: + WindowStatus = BAD_PARAMETER; + break; + } + + return WindowStatus; +} + +//LIGHT CONTROL FUNCTION +int SetLight(bool Light){ + static int LightStatus = 0; + + switch(Light) + { + case 0: + LightStatus = OFF; + LightControl = OFF; + break; + case 1: + LightStatus = ON; + LightControl = ON; + break; + default: + LightStatus = BAD_PARAMETER; + break; + } + + return LightStatus; +} + +//PERSON COUNTER FUNCTION +unsigned int GetPersonStatus(){ + static unsigned int PersonNumber = 0; + + //TODO Insert code here + /*** TODO ***/ + /*** TODO ***/ + /*** TODO ***/ + + return PersonNumber; +} \ No newline at end of file
diff -r d1ff330c5128 -r 32a08ca33b00 Sensors.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sensors.h Mon Dec 07 01:50:01 2015 +0000 @@ -0,0 +1,58 @@ +#include "mbed.h" + +/*Macros*/ +#define BAD_PARAMETER (-1) +#define OFF 0 +#define ON 1 +#define FALSE 0 +#define TRUE 1 +#define CLOSED 0 +#define OPEN 1 + +/*Extern Variables*/ + + +/*Extern Functions*/ +//////////////////////////////////////////////////// +extern bool GetPrescenceStatus(); +/* GetPrescenceStatus: +Input parameters -> void +Output parameters -> bool RoomStatus; 0-> No Prescence Detected + 1-> Prescence Detected +*/ + +//////////////////////////////////////////////////// +extern bool GetDoorStatus(); +/* GetDoorStatus: +Input parameters -> void +Output parameters -> bool DoorStatus; 0-> Door Closed + 1-> Door Open +*/ + +//////////////////////////////////////////////////// +extern int GetWindowStatus(int window); +/* GetWindowStatus: +Input parameters -> int window +Output parameters -> int WindowStatus; -1-> Bad parameter or error + 0-> Window Closed + 1-> Window Open +*/ + +//////////////////////////////////////////////////// +extern int SetLight(bool Light); +/* SetLight: +Input parameters -> bool Light; 0-> Light is OFF + 1-> Light is ON + +Output parameters -> int WindowStatus; -1-> Bad parameter or error + 0-> Light is OFF + 1-> Light is ON +*/ + +//////////////////////////////////////////////////// +extern unsigned int GetPersonStatus(); +/* GetPersonStatus: +Input parameters -> void + +Output parameters -> unsigned int PersonNumber; 0 - 4294967296. +*/ \ No newline at end of file
diff -r d1ff330c5128 -r 32a08ca33b00 Threads.cpp --- a/Threads.cpp Sat Dec 05 17:43:29 2015 +0000 +++ b/Threads.cpp Mon Dec 07 01:50:01 2015 +0000 @@ -65,28 +65,35 @@ ////////////////////// end if the funtion//////////////////////// } */ -static void receivedFromServer1(void const *argument) +static void messsageFromClient(void const *argument) { while (true) { - // Receive message from server1 - n1 = socketTCP1.receive(buf1, 256); - buf1[n1] = '\0'; - - if(n1>0) { - //pc.printf("Received message from server1 IF: '%s'\n\r", buf1); - socketTCP1.close(); - //isConnectedServer1=false; - } else { - //_isConnectedServer1==false; //quiere decir que se desconecto del servidor - //pc.printf("Not received1 ELSE value of lenght: '%u'\n\r",strlen(buf1)); - socketTCP1.close(); - //isConnectedServer1=false; - } + pc.printf("Wait for new connection...\n\r"); + TCPSocketConnection client; + serverTCP.accept(client); + client.set_blocking(false, 1500); // Timeout after (1.5)s + + pc.printf("Connection from: %s\n\r", client.get_address()); + char buffer[256]; + while (true) { + int n = client.receive(buffer, sizeof(buffer)); + if (n <= 0) break; + + // print received message to terminal + buffer[n] = '\0'; + pc.printf("Received message from Client :'%s'\n\r",buffer); + + // print reversed message to terminal + pc.printf("Sending message to Client: '%s'\n\r",buffer); + + // Echo received message back to client + client.send_all(buffer, n); + if (n <= 0) break; + } + client.close(); Thread::wait(500); } } - -