Morgan Du
/
Serial-to-Ethernet
Transfer data between UART ports and Ethernet.
Transfer data between UART ports and Ethernet.
- Support multiple UART ports.
- Support fixed IP address and DHCP.
- Support TCP server and TCP client modes.
- Support a simple web server for UART and Ethernet configuration.
ste_config.h@2:35f2cc8b05fa, 2017-09-27 (annotated)
- Committer:
- morgandu
- Date:
- Wed Sep 27 07:38:37 2017 +0000
- Revision:
- 2:35f2cc8b05fa
- Parent:
- 0:11bc39d0f367
- Child:
- 7:cbb5a2a2a0d2
* Add more comments.; * Add README.md; * Update Mbed OS to 5.5.7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
morgandu | 0:11bc39d0f367 | 1 | /* |
morgandu | 0:11bc39d0f367 | 2 | * Copyright (c) 2017 Nuvoton Tecnology Corp. All rights reserved. |
morgandu | 0:11bc39d0f367 | 3 | * |
morgandu | 0:11bc39d0f367 | 4 | * Header for Serial-To-Ethernet configuration. |
morgandu | 0:11bc39d0f367 | 5 | * |
morgandu | 0:11bc39d0f367 | 6 | */ |
morgandu | 0:11bc39d0f367 | 7 | |
morgandu | 0:11bc39d0f367 | 8 | #ifndef _STE_CONFIG_H |
morgandu | 0:11bc39d0f367 | 9 | #define _STE_CONFIG_H |
morgandu | 0:11bc39d0f367 | 10 | |
morgandu | 0:11bc39d0f367 | 11 | #include "mbed.h" |
morgandu | 0:11bc39d0f367 | 12 | #include "EthernetInterface.h" |
morgandu | 0:11bc39d0f367 | 13 | #include "TCPSocket.h" |
morgandu | 0:11bc39d0f367 | 14 | #include "TCPServer.h" |
morgandu | 0:11bc39d0f367 | 15 | #include "BufferedSerial.h" |
morgandu | 0:11bc39d0f367 | 16 | #include "FATFileSystem.h" |
morgandu | 0:11bc39d0f367 | 17 | #include "NuSDBlockDevice.h" |
morgandu | 0:11bc39d0f367 | 18 | |
morgandu | 2:35f2cc8b05fa | 19 | /* Define ENABLE_WEB_CONFIG to active a simple web server for |
morgandu | 2:35f2cc8b05fa | 20 | UART ports and Ethernet port configuration. */ |
morgandu | 2:35f2cc8b05fa | 21 | #define ENABLE_WEB_CONFIG |
morgandu | 0:11bc39d0f367 | 22 | |
morgandu | 2:35f2cc8b05fa | 23 | /* Maximum UART ports supported. |
morgandu | 2:35f2cc8b05fa | 24 | It should be 1, 2, or 3. Please also define |
morgandu | 2:35f2cc8b05fa | 25 | mapping table "port_config[]" in main.c */ |
morgandu | 0:11bc39d0f367 | 26 | #define MAX_UART_PORTS 2 |
morgandu | 0:11bc39d0f367 | 27 | |
morgandu | 0:11bc39d0f367 | 28 | /* Default UART baud */ |
morgandu | 0:11bc39d0f367 | 29 | #define DEFAULT_UART_BAUD 115200 |
morgandu | 0:11bc39d0f367 | 30 | |
morgandu | 0:11bc39d0f367 | 31 | /* Network base port number to listen. |
morgandu | 2:35f2cc8b05fa | 32 | The base port maps to the 1st UART port, |
morgandu | 0:11bc39d0f367 | 33 | the (base port + 1) maps to the 2nd UART port, etc. */ |
morgandu | 0:11bc39d0f367 | 34 | #define NET_PORT_BASE 10001 |
morgandu | 0:11bc39d0f367 | 35 | |
morgandu | 2:35f2cc8b05fa | 36 | /* Files in SD card to store settings via web configuration */ |
morgandu | 0:11bc39d0f367 | 37 | #define SER_CONFIG_FILE "/fs/STE_SER.TXT" // for serial ports |
morgandu | 0:11bc39d0f367 | 38 | #define NET_CONFIG_FILE "/fs/STE_NET.TXT" // for network |
morgandu | 0:11bc39d0f367 | 39 | |
morgandu | 2:35f2cc8b05fa | 40 | /* Maximum size of server address for web configuration */ |
morgandu | 0:11bc39d0f367 | 41 | #define MAX_SERVER_ADDRESS_SIZE 63 |
morgandu | 0:11bc39d0f367 | 42 | |
morgandu | 2:35f2cc8b05fa | 43 | /* Maximum size of IP address for web configuration */ |
morgandu | 0:11bc39d0f367 | 44 | #define MAX_IPV4_ADDRESS_SIZE 15 |
morgandu | 0:11bc39d0f367 | 45 | |
morgandu | 2:35f2cc8b05fa | 46 | |
morgandu | 0:11bc39d0f367 | 47 | /* Functions and global variables declaration. */ |
morgandu | 0:11bc39d0f367 | 48 | |
morgandu | 0:11bc39d0f367 | 49 | typedef enum { |
morgandu | 0:11bc39d0f367 | 50 | NET_SERVER_MODE = 0, |
morgandu | 0:11bc39d0f367 | 51 | NET_CLIENT_MODE |
morgandu | 0:11bc39d0f367 | 52 | } E_NetMode; |
morgandu | 0:11bc39d0f367 | 53 | |
morgandu | 0:11bc39d0f367 | 54 | typedef enum { |
morgandu | 0:11bc39d0f367 | 55 | IP_STATIC_MODE = 0, |
morgandu | 0:11bc39d0f367 | 56 | IP_DHCP_MODE |
morgandu | 0:11bc39d0f367 | 57 | } E_IPMode; |
morgandu | 0:11bc39d0f367 | 58 | |
morgandu | 0:11bc39d0f367 | 59 | typedef struct { |
morgandu | 0:11bc39d0f367 | 60 | E_IPMode mode; |
morgandu | 0:11bc39d0f367 | 61 | char ip[MAX_IPV4_ADDRESS_SIZE+1]; |
morgandu | 0:11bc39d0f367 | 62 | char mask[MAX_IPV4_ADDRESS_SIZE+1]; |
morgandu | 0:11bc39d0f367 | 63 | char gateway[MAX_IPV4_ADDRESS_SIZE+1]; |
morgandu | 0:11bc39d0f367 | 64 | } S_NET_CONFIG; |
morgandu | 0:11bc39d0f367 | 65 | |
morgandu | 0:11bc39d0f367 | 66 | typedef struct { |
morgandu | 0:11bc39d0f367 | 67 | E_NetMode mode; // Network server or client mode |
morgandu | 0:11bc39d0f367 | 68 | int port; // Network port number |
morgandu | 0:11bc39d0f367 | 69 | BufferedSerial *pserial; // UART number |
morgandu | 0:11bc39d0f367 | 70 | int baud; // UART baud |
morgandu | 0:11bc39d0f367 | 71 | int data; // UART data bits |
morgandu | 0:11bc39d0f367 | 72 | int stop; // UART stop bits |
morgandu | 0:11bc39d0f367 | 73 | mbed::SerialBase::Parity parity; // UART parity bit |
morgandu | 0:11bc39d0f367 | 74 | char server_addr[MAX_SERVER_ADDRESS_SIZE+1]; // Server address for TCP client mode |
morgandu | 0:11bc39d0f367 | 75 | unsigned short server_port; // Server port for TCP client mode |
morgandu | 0:11bc39d0f367 | 76 | } S_PORT_CONFIG; |
morgandu | 0:11bc39d0f367 | 77 | |
morgandu | 0:11bc39d0f367 | 78 | extern RawSerial output; // for debug output |
morgandu | 0:11bc39d0f367 | 79 | extern EthernetInterface eth; |
morgandu | 0:11bc39d0f367 | 80 | extern S_PORT_CONFIG port_config[MAX_UART_PORTS]; |
morgandu | 0:11bc39d0f367 | 81 | extern S_NET_CONFIG net_config; |
morgandu | 0:11bc39d0f367 | 82 | |
morgandu | 0:11bc39d0f367 | 83 | extern bool SD_Card_Mounted; |
morgandu | 0:11bc39d0f367 | 84 | void start_httpd(void); |
morgandu | 0:11bc39d0f367 | 85 | |
morgandu | 0:11bc39d0f367 | 86 | #endif |