rs485 to ethernet

Dependencies:   BufferedSerialttt

Fork of Serial-to-Ethernet by Morgan Du

Committer:
morgandu
Date:
Fri May 05 07:40:19 2017 +0000
Revision:
0:11bc39d0f367
Child:
2:1af7ad1f058a
The first version.; ; Support multiple UART ports.; Support TCP server and TCP client mode.; Support static IP or DHCP.; Support fix configuration, or a web server for dynamic configuration.

Who changed what in which revision?

UserRevisionLine numberNew 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 0:11bc39d0f367 19
morgandu 0:11bc39d0f367 20 //#define ENABLE_WEB_CONFIG // Define this to active a simple web sever for
morgandu 0:11bc39d0f367 21 // UART ports and Ethernet port parameters configuration.
morgandu 0:11bc39d0f367 22
morgandu 0:11bc39d0f367 23 /* Maximum UART ports supported */
morgandu 0:11bc39d0f367 24 #define MAX_UART_PORTS 2
morgandu 0:11bc39d0f367 25
morgandu 0:11bc39d0f367 26 /* Default UART baud */
morgandu 0:11bc39d0f367 27 #define DEFAULT_UART_BAUD 115200
morgandu 0:11bc39d0f367 28
morgandu 0:11bc39d0f367 29 /* Network base port number to listen.
morgandu 0:11bc39d0f367 30 So the base port maps to the 1st UART port,
morgandu 0:11bc39d0f367 31 the (base port + 1) maps to the 2nd UART port, etc. */
morgandu 0:11bc39d0f367 32 #define NET_PORT_BASE 10001
morgandu 0:11bc39d0f367 33
morgandu 0:11bc39d0f367 34 /* Path and Filename of configuration files */
morgandu 0:11bc39d0f367 35 #define SER_CONFIG_FILE "/fs/STE_SER.TXT" // for serial ports
morgandu 0:11bc39d0f367 36 #define NET_CONFIG_FILE "/fs/STE_NET.TXT" // for network
morgandu 0:11bc39d0f367 37
morgandu 0:11bc39d0f367 38 /* Maximum size of server address */
morgandu 0:11bc39d0f367 39 #define MAX_SERVER_ADDRESS_SIZE 63
morgandu 0:11bc39d0f367 40
morgandu 0:11bc39d0f367 41 /* Maximum size of IP address */
morgandu 0:11bc39d0f367 42 #define MAX_IPV4_ADDRESS_SIZE 15
morgandu 0:11bc39d0f367 43
morgandu 0:11bc39d0f367 44 /* Functions and global variables declaration. */
morgandu 0:11bc39d0f367 45
morgandu 0:11bc39d0f367 46 typedef enum {
morgandu 0:11bc39d0f367 47 NET_SERVER_MODE = 0,
morgandu 0:11bc39d0f367 48 NET_CLIENT_MODE
morgandu 0:11bc39d0f367 49 } E_NetMode;
morgandu 0:11bc39d0f367 50
morgandu 0:11bc39d0f367 51 typedef enum {
morgandu 0:11bc39d0f367 52 IP_STATIC_MODE = 0,
morgandu 0:11bc39d0f367 53 IP_DHCP_MODE
morgandu 0:11bc39d0f367 54 } E_IPMode;
morgandu 0:11bc39d0f367 55
morgandu 0:11bc39d0f367 56 typedef struct {
morgandu 0:11bc39d0f367 57 E_IPMode mode;
morgandu 0:11bc39d0f367 58 char ip[MAX_IPV4_ADDRESS_SIZE+1];
morgandu 0:11bc39d0f367 59 char mask[MAX_IPV4_ADDRESS_SIZE+1];
morgandu 0:11bc39d0f367 60 char gateway[MAX_IPV4_ADDRESS_SIZE+1];
morgandu 0:11bc39d0f367 61 } S_NET_CONFIG;
morgandu 0:11bc39d0f367 62
morgandu 0:11bc39d0f367 63 typedef struct {
morgandu 0:11bc39d0f367 64 E_NetMode mode; // Network server or client mode
morgandu 0:11bc39d0f367 65 int port; // Network port number
morgandu 0:11bc39d0f367 66 BufferedSerial *pserial; // UART number
morgandu 0:11bc39d0f367 67 int baud; // UART baud
morgandu 0:11bc39d0f367 68 int data; // UART data bits
morgandu 0:11bc39d0f367 69 int stop; // UART stop bits
morgandu 0:11bc39d0f367 70 mbed::SerialBase::Parity parity; // UART parity bit
morgandu 0:11bc39d0f367 71 char server_addr[MAX_SERVER_ADDRESS_SIZE+1]; // Server address for TCP client mode
morgandu 0:11bc39d0f367 72 unsigned short server_port; // Server port for TCP client mode
morgandu 0:11bc39d0f367 73 } S_PORT_CONFIG;
morgandu 0:11bc39d0f367 74
morgandu 0:11bc39d0f367 75 extern RawSerial output; // for debug output
morgandu 0:11bc39d0f367 76 extern EthernetInterface eth;
morgandu 0:11bc39d0f367 77 extern S_PORT_CONFIG port_config[MAX_UART_PORTS];
morgandu 0:11bc39d0f367 78 extern S_NET_CONFIG net_config;
morgandu 0:11bc39d0f367 79
morgandu 0:11bc39d0f367 80 extern bool SD_Card_Mounted;
morgandu 0:11bc39d0f367 81 void start_httpd(void);
morgandu 0:11bc39d0f367 82
morgandu 0:11bc39d0f367 83 #endif