no description

Fork of Middleware by Roberto Herrera

Threads.cpp

Committer:
Jorge_Beltran
Date:
2015-12-07
Revision:
1:32a08ca33b00
Parent:
0:d1ff330c5128

File content as of revision 1:32a08ca33b00:

/*

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 "Threads.h"

#include "Initial.h"
#include "rtos.h"
#include "Ether.h"
#include "EthernetInterface.h"

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

}

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 if(_isConnectedServer1 == true && _isConnectedServer2 == false) {
            //Color BLUE
            ledGREEN=1;//OFF
            ledRED = 1; //OFF
            ledBLUE = !ledBLUE;
        } else if(_isConnectedServer1 == false && _isConnectedServer2 == true) {
            //Color YELLOW  = RED and GREEN
            ledBLUE =1; //OFF
            ledRED = !ledRED;
            ledGREEN = !ledGREEN;
        } else if(_isConnectedServer1 == false && _isConnectedServer2 == false) {
            //Color RED
            ledGREEN=1;//OFF
            ledBLUE =1; //OFF
            ledRED = !ledRED;
        }
        Thread::wait(1000);
    }
}

/*
static bool conect_Server(void)
{
 ////////////////////// Body of the funtion////////////////////////
     while (socketTCP1.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) < 0) {
         wait(0.5);
         return false;
    }
return true;
 ////////////////////// end if the funtion////////////////////////
}
*/
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);
            
            // 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);
    }

}