Nico De Witte / Mbed 2 deprecated tcp_machine_vision_server_single_client

Dependencies:   C12832 EthernetInterface mbed-rtos mbed ConfigFile

main.cpp

Committer:
dwini
Date:
2015-06-12
Revision:
6:6cbb21cc3884
Parent:
5:7a32c081a3fa
Child:
7:23c8d34000eb

File content as of revision 6:6cbb21cc3884:

#include "mbed.h"
#include "C12832.h"
#include "Log.h"
#include "TcpDaemon.h"
#include "StatusIndicator.h"

#define TCP_SERVER_PORT 6666
#define LCD_LINE_HEIGHT 12

Serial pc(USBTX,USBRX);
DigitalOut error_led(LED1);
C12832 lcd(p5, p7, p6, p8, p11);

using namespace MachineVision;

void setLcdServerInfo(char * ip) {
    lcd.cls();
    lcd.locate(0,0);
    lcd.printf("IP: %s", ip);
    lcd.locate(0,14);
    lcd.printf("Port: %d", TCP_SERVER_PORT);
}

int main (void) {
    pc.baud(115200);

    lcd.cls();
    lcd.locate(0,0);
    lcd.printf("Starting ...");

    while (true) {
        // Setup ethernet interface    
        EthernetInterface eth;
        Log::v("Bringing ethernet interface online\r\n");
        
        // eth.init();         //Use DHCP
        int success = eth.init("10.0.0.1", "255.255.255.0", "10.0.0.254");
        
        if (success < 0 || eth.connect() < 0) {    // Default timeout of 15 seconds
            Log::w("Could not bring ethernet interface online\r\n");
            setLcdServerInfo("No ip address");
        } else {
            Log::v("IP Address is %s\r\n", eth.getIPAddress());
            
            // Set ip on LCD
            setLcdServerInfo(eth.getIPAddress());
        
            // Start the daemon
            StatusIndicator status_indicator(p23, p24, p25);
            TcpDaemon daemon(TCP_SERVER_PORT, LED2, LED3, p14, &status_indicator);
            Log::v("TCP daemon listening @ TCP_SERVER_PORT = %d\r\n", TCP_SERVER_PORT);
            daemon.startListening();
        }
        
        pc.printf("Fail");
    }
}