Sensos Module Updated
Fork of Middleware by
Threads.cpp@4:c59485faea9f, 2015-12-10 (annotated)
- Committer:
- Jorge_Beltran
- Date:
- Thu Dec 10 03:03:11 2015 +0000
- Revision:
- 4:c59485faea9f
- Parent:
- 1:fd355dc296b1
Updated Sensors Module Added GetLightFuncion
Who changed what in which revision?
User | Revision | Line number | New 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 "Initial.h" |
RoHe | 0:d1ff330c5128 | 16 | #include "rtos.h" |
RoHe | 0:d1ff330c5128 | 17 | #include "Ether.h" |
RoHe | 0:d1ff330c5128 | 18 | #include "EthernetInterface.h" |
RoHe | 0:d1ff330c5128 | 19 | |
RoHe | 0:d1ff330c5128 | 20 | static void sw2_press(void) |
RoHe | 0:d1ff330c5128 | 21 | { |
RoHe | 1:fd355dc296b1 | 22 | ledBLUE= !ledBLUE; |
RoHe | 0:d1ff330c5128 | 23 | |
RoHe | 0:d1ff330c5128 | 24 | } |
RoHe | 0:d1ff330c5128 | 25 | |
RoHe | 0:d1ff330c5128 | 26 | static void led_thread(void const *argument) |
RoHe | 0:d1ff330c5128 | 27 | { |
RoHe | 0:d1ff330c5128 | 28 | while (true) { |
RoHe | 0:d1ff330c5128 | 29 | if(_isConnectedServer1 == true && _isConnectedServer2 == true) { |
RoHe | 0:d1ff330c5128 | 30 | //Color GREEN |
RoHe | 0:d1ff330c5128 | 31 | ledRED=1;//OFF |
RoHe | 0:d1ff330c5128 | 32 | ledBLUE=1;//OFF |
RoHe | 0:d1ff330c5128 | 33 | ledGREEN = !ledGREEN; |
RoHe | 1:fd355dc296b1 | 34 | } else { |
RoHe | 0:d1ff330c5128 | 35 | //Color RED |
RoHe | 0:d1ff330c5128 | 36 | ledGREEN=1;//OFF |
RoHe | 0:d1ff330c5128 | 37 | ledBLUE =1; //OFF |
RoHe | 0:d1ff330c5128 | 38 | ledRED = !ledRED; |
RoHe | 0:d1ff330c5128 | 39 | } |
RoHe | 0:d1ff330c5128 | 40 | Thread::wait(1000); |
RoHe | 0:d1ff330c5128 | 41 | } |
RoHe | 0:d1ff330c5128 | 42 | } |
RoHe | 0:d1ff330c5128 | 43 | |
RoHe | 1:fd355dc296b1 | 44 | |
RoHe | 1:fd355dc296b1 | 45 | static void messsageFromClient(void const *argument) |
RoHe | 0:d1ff330c5128 | 46 | { |
RoHe | 0:d1ff330c5128 | 47 | |
RoHe | 0:d1ff330c5128 | 48 | while (true) { |
RoHe | 1:fd355dc296b1 | 49 | pc.printf("Wait for new connection...\n\r"); |
RoHe | 1:fd355dc296b1 | 50 | TCPSocketConnection client; |
RoHe | 1:fd355dc296b1 | 51 | serverTCP.accept(client); |
RoHe | 1:fd355dc296b1 | 52 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
RoHe | 1:fd355dc296b1 | 53 | |
RoHe | 1:fd355dc296b1 | 54 | pc.printf("Connection from: %s\n\r", client.get_address()); |
RoHe | 1:fd355dc296b1 | 55 | char buffer[256]; |
RoHe | 1:fd355dc296b1 | 56 | while (true) { |
RoHe | 1:fd355dc296b1 | 57 | int n = client.receive(buffer, sizeof(buffer)); |
RoHe | 1:fd355dc296b1 | 58 | if (n <= 0) break; |
RoHe | 0:d1ff330c5128 | 59 | |
RoHe | 1:fd355dc296b1 | 60 | // print received message to terminal |
RoHe | 1:fd355dc296b1 | 61 | buffer[n] = '\0'; |
RoHe | 1:fd355dc296b1 | 62 | pc.printf("Received message from Client :'%s'\n\r",buffer); |
RoHe | 1:fd355dc296b1 | 63 | |
RoHe | 1:fd355dc296b1 | 64 | // printing message sending to terminal |
RoHe | 1:fd355dc296b1 | 65 | //char* bufferReply = "reply:get:status"; |
RoHe | 1:fd355dc296b1 | 66 | // strcat(bufferReply, ":"); |
RoHe | 1:fd355dc296b1 | 67 | char* bufferReply = stringManager.processString(buffer,eth.getIPAddress()); //eth.getIPAddress() = address server |
RoHe | 1:fd355dc296b1 | 68 | //char* bufferReply="reply:get:status:192.168.1.71:window:1:0\0"; |
RoHe | 1:fd355dc296b1 | 69 | pc.printf("Sending message to Client: '%s'\n\r",bufferReply); |
RoHe | 1:fd355dc296b1 | 70 | |
RoHe | 1:fd355dc296b1 | 71 | //Sending to Client |
RoHe | 1:fd355dc296b1 | 72 | client.send_all(bufferReply, strlen(bufferReply)); |
RoHe | 1:fd355dc296b1 | 73 | if (n <= 0) break; |
RoHe | 0:d1ff330c5128 | 74 | } |
RoHe | 1:fd355dc296b1 | 75 | client.close(); |
RoHe | 0:d1ff330c5128 | 76 | Thread::wait(500); |
RoHe | 0:d1ff330c5128 | 77 | } |
RoHe | 0:d1ff330c5128 | 78 | |
RoHe | 0:d1ff330c5128 | 79 | } |
RoHe | 0:d1ff330c5128 | 80 | |
RoHe | 0:d1ff330c5128 | 81 | |
RoHe | 0:d1ff330c5128 | 82 |