Sensos Module Updated

Dependents:   SmartLabProyect

Fork of Middleware by Roberto Herrera

Committer:
RoHe
Date:
Sat Dec 05 17:43:29 2015 +0000
Revision:
0:d1ff330c5128
Child:
1:fd355dc296b1
MiddleWare GUS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RoHe 0:d1ff330c5128 1 /*
RoHe 0:d1ff330c5128 2
RoHe 0:d1ff330c5128 3 Thread.cpp
RoHe 0:d1ff330c5128 4
RoHe 0:d1ff330c5128 5 Only to improve the clarity of main .cpp
RoHe 0:d1ff330c5128 6 This don't have any new classes
RoHe 0:d1ff330c5128 7
RoHe 0:d1ff330c5128 8 All the multiple task are here
RoHe 0:d1ff330c5128 9 for Smart Room project asked by
RoHe 0:d1ff330c5128 10 Gustavo Torres
RoHe 0:d1ff330c5128 11
RoHe 0:d1ff330c5128 12 Last update by RoHe 16/11/2015
RoHe 0:d1ff330c5128 13
RoHe 0:d1ff330c5128 14 */
RoHe 0:d1ff330c5128 15 #include "Threads.h"
RoHe 0:d1ff330c5128 16
RoHe 0:d1ff330c5128 17 #include "Initial.h"
RoHe 0:d1ff330c5128 18 #include "rtos.h"
RoHe 0:d1ff330c5128 19 #include "Ether.h"
RoHe 0:d1ff330c5128 20 #include "EthernetInterface.h"
RoHe 0:d1ff330c5128 21
RoHe 0:d1ff330c5128 22 static void sw2_press(void)
RoHe 0:d1ff330c5128 23 {
RoHe 0:d1ff330c5128 24 ledGREEN= !ledGREEN;
RoHe 0:d1ff330c5128 25
RoHe 0:d1ff330c5128 26 }
RoHe 0:d1ff330c5128 27
RoHe 0:d1ff330c5128 28 static void led_thread(void const *argument)
RoHe 0:d1ff330c5128 29 {
RoHe 0:d1ff330c5128 30 while (true) {
RoHe 0:d1ff330c5128 31 if(_isConnectedServer1 == true && _isConnectedServer2 == true) {
RoHe 0:d1ff330c5128 32 //Color GREEN
RoHe 0:d1ff330c5128 33 ledRED=1;//OFF
RoHe 0:d1ff330c5128 34 ledBLUE=1;//OFF
RoHe 0:d1ff330c5128 35 ledGREEN = !ledGREEN;
RoHe 0:d1ff330c5128 36 } else if(_isConnectedServer1 == true && _isConnectedServer2 == false) {
RoHe 0:d1ff330c5128 37 //Color BLUE
RoHe 0:d1ff330c5128 38 ledGREEN=1;//OFF
RoHe 0:d1ff330c5128 39 ledRED = 1; //OFF
RoHe 0:d1ff330c5128 40 ledBLUE = !ledBLUE;
RoHe 0:d1ff330c5128 41 } else if(_isConnectedServer1 == false && _isConnectedServer2 == true) {
RoHe 0:d1ff330c5128 42 //Color YELLOW = RED and GREEN
RoHe 0:d1ff330c5128 43 ledBLUE =1; //OFF
RoHe 0:d1ff330c5128 44 ledRED = !ledRED;
RoHe 0:d1ff330c5128 45 ledGREEN = !ledGREEN;
RoHe 0:d1ff330c5128 46 } else if(_isConnectedServer1 == false && _isConnectedServer2 == false) {
RoHe 0:d1ff330c5128 47 //Color RED
RoHe 0:d1ff330c5128 48 ledGREEN=1;//OFF
RoHe 0:d1ff330c5128 49 ledBLUE =1; //OFF
RoHe 0:d1ff330c5128 50 ledRED = !ledRED;
RoHe 0:d1ff330c5128 51 }
RoHe 0:d1ff330c5128 52 Thread::wait(1000);
RoHe 0:d1ff330c5128 53 }
RoHe 0:d1ff330c5128 54 }
RoHe 0:d1ff330c5128 55
RoHe 0:d1ff330c5128 56 /*
RoHe 0:d1ff330c5128 57 static bool conect_Server(void)
RoHe 0:d1ff330c5128 58 {
RoHe 0:d1ff330c5128 59 ////////////////////// Body of the funtion////////////////////////
RoHe 0:d1ff330c5128 60 while (socketTCP1.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) < 0) {
RoHe 0:d1ff330c5128 61 wait(0.5);
RoHe 0:d1ff330c5128 62 return false;
RoHe 0:d1ff330c5128 63 }
RoHe 0:d1ff330c5128 64 return true;
RoHe 0:d1ff330c5128 65 ////////////////////// end if the funtion////////////////////////
RoHe 0:d1ff330c5128 66 }
RoHe 0:d1ff330c5128 67 */
RoHe 0:d1ff330c5128 68 static void receivedFromServer1(void const *argument)
RoHe 0:d1ff330c5128 69 {
RoHe 0:d1ff330c5128 70
RoHe 0:d1ff330c5128 71 while (true) {
RoHe 0:d1ff330c5128 72 // Receive message from server1
RoHe 0:d1ff330c5128 73 n1 = socketTCP1.receive(buf1, 256);
RoHe 0:d1ff330c5128 74 buf1[n1] = '\0';
RoHe 0:d1ff330c5128 75
RoHe 0:d1ff330c5128 76 if(n1>0) {
RoHe 0:d1ff330c5128 77 //pc.printf("Received message from server1 IF: '%s'\n\r", buf1);
RoHe 0:d1ff330c5128 78 socketTCP1.close();
RoHe 0:d1ff330c5128 79 //isConnectedServer1=false;
RoHe 0:d1ff330c5128 80 } else {
RoHe 0:d1ff330c5128 81 //_isConnectedServer1==false; //quiere decir que se desconecto del servidor
RoHe 0:d1ff330c5128 82 //pc.printf("Not received1 ELSE value of lenght: '%u'\n\r",strlen(buf1));
RoHe 0:d1ff330c5128 83 socketTCP1.close();
RoHe 0:d1ff330c5128 84 //isConnectedServer1=false;
RoHe 0:d1ff330c5128 85 }
RoHe 0:d1ff330c5128 86 Thread::wait(500);
RoHe 0:d1ff330c5128 87 }
RoHe 0:d1ff330c5128 88
RoHe 0:d1ff330c5128 89 }
RoHe 0:d1ff330c5128 90
RoHe 0:d1ff330c5128 91
RoHe 0:d1ff330c5128 92