Machine Vision Status TCP Server
Dependencies: C12832 EthernetInterface mbed-rtos mbed ConfigFile
TcpDaemon.h
- Committer:
- dwini
- Date:
- 2015-06-14
- Revision:
- 7:23c8d34000eb
- Parent:
- 5:7a32c081a3fa
- Child:
- 8:845dfadaa70d
File content as of revision 7:23c8d34000eb:
#ifndef TCP_DAEMON_HEADER #define TCP_DAEMON_HEADER #include "mbed.h" #include "EthernetInterface.h" #include "PlcStatusIndicator.h" #define MAX_BACKLOG 1 #define TRIGGER_MSG "TRIGGER\r\n" #define STR_FAIL "FAIL\r\n" #define STR_OK "OK\r\n" #define STR_CLEAR "CLEAR\r\n" namespace MachineVision{ class TcpDaemon{ public: const static int BUFFER_SIZE = 512; const static int TCP_TIMEOUT = 250; const static int TCP_ACCEPT_TIMEOUT = 500; const static int MAX_READ_TIMEOUTS = 10; // Maximum number of times to retry to read for rest of message private: int server_port; TCPSocketServer server; TCPSocketConnection client; char buffer[BUFFER_SIZE+1]; bool keepListening; DigitalOut accept_led; DigitalOut receive_led; // Status Indicator PlcStatusIndicator * status_indicator; public: /* * TcpDaemon constructor * * @server_port the port the daemon will be listening on */ TcpDaemon(int server_port, PinName accept_led_pin, PinName receive_led_pin, PlcStatusIndicator * indicator); /* * Make the daemon start listening for incoming connections */ void startListening(); private: /* * Bind to server socket * * @return true on success */ bool bindSocket(); /* * Listen for incoming connections */ void doListen(); }; } #endif