Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832 EthernetInterface mbed-rtos mbed ConfigFile
main.cpp@6:6cbb21cc3884, 2015-06-12 (annotated)
- Committer:
- dwini
- Date:
- Fri Jun 12 12:47:37 2015 +0000
- Revision:
- 6:6cbb21cc3884
- Parent:
- 5:7a32c081a3fa
- Child:
- 7:23c8d34000eb
Add retry to ethernet setup. Does not seem to work. Needs to be revised.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dwini | 0:bef69e35f486 | 1 | #include "mbed.h" |
dwini | 0:bef69e35f486 | 2 | #include "C12832.h" |
dwini | 1:8efef658d90b | 3 | #include "Log.h" |
dwini | 1:8efef658d90b | 4 | #include "TcpDaemon.h" |
dwini | 3:254a2671a8e3 | 5 | #include "StatusIndicator.h" |
dwini | 0:bef69e35f486 | 6 | |
dwini | 1:8efef658d90b | 7 | #define TCP_SERVER_PORT 6666 |
dwini | 0:bef69e35f486 | 8 | #define LCD_LINE_HEIGHT 12 |
dwini | 0:bef69e35f486 | 9 | |
dwini | 0:bef69e35f486 | 10 | Serial pc(USBTX,USBRX); |
dwini | 1:8efef658d90b | 11 | DigitalOut error_led(LED1); |
dwini | 0:bef69e35f486 | 12 | C12832 lcd(p5, p7, p6, p8, p11); |
dwini | 0:bef69e35f486 | 13 | |
dwini | 1:8efef658d90b | 14 | using namespace MachineVision; |
dwini | 1:8efef658d90b | 15 | |
dwini | 0:bef69e35f486 | 16 | void setLcdServerInfo(char * ip) { |
dwini | 0:bef69e35f486 | 17 | lcd.cls(); |
dwini | 0:bef69e35f486 | 18 | lcd.locate(0,0); |
dwini | 1:8efef658d90b | 19 | lcd.printf("IP: %s", ip); |
dwini | 1:8efef658d90b | 20 | lcd.locate(0,14); |
dwini | 1:8efef658d90b | 21 | lcd.printf("Port: %d", TCP_SERVER_PORT); |
dwini | 0:bef69e35f486 | 22 | } |
dwini | 0:bef69e35f486 | 23 | |
dwini | 0:bef69e35f486 | 24 | int main (void) { |
dwini | 0:bef69e35f486 | 25 | pc.baud(115200); |
dwini | 3:254a2671a8e3 | 26 | |
dwini | 6:6cbb21cc3884 | 27 | lcd.cls(); |
dwini | 6:6cbb21cc3884 | 28 | lcd.locate(0,0); |
dwini | 6:6cbb21cc3884 | 29 | lcd.printf("Starting ..."); |
dwini | 6:6cbb21cc3884 | 30 | |
dwini | 6:6cbb21cc3884 | 31 | while (true) { |
dwini | 6:6cbb21cc3884 | 32 | // Setup ethernet interface |
dwini | 6:6cbb21cc3884 | 33 | EthernetInterface eth; |
dwini | 6:6cbb21cc3884 | 34 | Log::v("Bringing ethernet interface online\r\n"); |
dwini | 6:6cbb21cc3884 | 35 | |
dwini | 6:6cbb21cc3884 | 36 | // eth.init(); //Use DHCP |
dwini | 6:6cbb21cc3884 | 37 | int success = eth.init("10.0.0.1", "255.255.255.0", "10.0.0.254"); |
dwini | 0:bef69e35f486 | 38 | |
dwini | 6:6cbb21cc3884 | 39 | if (success < 0 || eth.connect() < 0) { // Default timeout of 15 seconds |
dwini | 6:6cbb21cc3884 | 40 | Log::w("Could not bring ethernet interface online\r\n"); |
dwini | 6:6cbb21cc3884 | 41 | setLcdServerInfo("No ip address"); |
dwini | 6:6cbb21cc3884 | 42 | } else { |
dwini | 6:6cbb21cc3884 | 43 | Log::v("IP Address is %s\r\n", eth.getIPAddress()); |
dwini | 6:6cbb21cc3884 | 44 | |
dwini | 6:6cbb21cc3884 | 45 | // Set ip on LCD |
dwini | 6:6cbb21cc3884 | 46 | setLcdServerInfo(eth.getIPAddress()); |
dwini | 6:6cbb21cc3884 | 47 | |
dwini | 6:6cbb21cc3884 | 48 | // Start the daemon |
dwini | 6:6cbb21cc3884 | 49 | StatusIndicator status_indicator(p23, p24, p25); |
dwini | 6:6cbb21cc3884 | 50 | TcpDaemon daemon(TCP_SERVER_PORT, LED2, LED3, p14, &status_indicator); |
dwini | 6:6cbb21cc3884 | 51 | Log::v("TCP daemon listening @ TCP_SERVER_PORT = %d\r\n", TCP_SERVER_PORT); |
dwini | 6:6cbb21cc3884 | 52 | daemon.startListening(); |
dwini | 6:6cbb21cc3884 | 53 | } |
dwini | 6:6cbb21cc3884 | 54 | |
dwini | 6:6cbb21cc3884 | 55 | pc.printf("Fail"); |
dwini | 0:bef69e35f486 | 56 | } |
dwini | 0:bef69e35f486 | 57 | } |