Sensos Module Updated

Dependents:   SmartLabProyect

Fork of Middleware by Roberto Herrera

Threads.cpp

Committer:
RoHe
Date:
2015-12-09
Revision:
1:fd355dc296b1
Parent:
0:d1ff330c5128

File content as of revision 1:fd355dc296b1:

/*

Thread.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 "Initial.h"
#include "rtos.h"
#include "Ether.h"
#include "EthernetInterface.h"

static void sw2_press(void)
{
    ledBLUE= !ledBLUE;

}

static void led_thread(void const *argument)
{
    while (true) {
        if(_isConnectedServer1 == true && _isConnectedServer2 == true) {
            //Color GREEN
            ledRED=1;//OFF
            ledBLUE=1;//OFF
            ledGREEN = !ledGREEN;
        } else {
            //Color RED
            ledGREEN=1;//OFF
            ledBLUE =1; //OFF
            ledRED = !ledRED;
        }
        Thread::wait(1000);
    }
}


static void messsageFromClient(void const *argument)
{

    while (true) {
        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);

            // printing message sending to terminal
            //char* bufferReply = "reply:get:status";
            // strcat(bufferReply, ":");
            char* bufferReply = stringManager.processString(buffer,eth.getIPAddress()); //eth.getIPAddress() = address server
            //char* bufferReply="reply:get:status:192.168.1.71:window:1:0\0";
            pc.printf("Sending message to Client: '%s'\n\r",bufferReply);

            //Sending to Client
            client.send_all(bufferReply, strlen(bufferReply));
            if (n <= 0) break;
        }
        client.close();
        Thread::wait(500);
    }

}