Webserver only w/o any other functions, single thread. Running on STM32F013+W5500

Dependencies:   NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed

Fork of F103-Serial-to-Ethernet by Chau Vo

Revision:
42:d0ff08711ca5
Parent:
41:a50a534a2fbb
Child:
43:48ca8c6f6f49
--- a/main.cpp	Thu Jun 16 09:12:20 2016 +0000
+++ b/main.cpp	Thu Jun 16 19:22:36 2016 +0000
@@ -1,6 +1,3 @@
-/*
- * Firmware supports NNIO and RPC protocols
- */
 #include "mbed.h"
 #include "rtos.h"
 #include "mbed_rpc.h"
@@ -22,8 +19,8 @@
 #define SERVER_PORT 80
 
 
-/** Debug option
- *
+/*
+ * Debug option
  */
 #if 1
 //Enable debug
@@ -56,7 +53,7 @@
                                      0x3212, 0x3313, 0x3414, 0x3515, // IP_Gateway
                                      0x4212, // TCP server port, not used
                                      0x5212, // UDP server port, not used
-                                     0x8888, // 1st run? 0xA5A5 = configured
+                                     0x8888, // 1st run? 0xA5A5 = static IP has been configured
                                      0x6212, 0x6313, 0x6414, // MAC
 
                                      // this section is for the TCP server that this device connects to in TCP client mode
@@ -67,29 +64,42 @@
                                      // this section is for selecting protocol, not used
                                      0xA212, // 0xA5A5 = enable TCP server
                                      0xA313, // 0xA5A5 = eanble TCP client
-                                     0xA414  // 0xA5A5 = enable UDP server
+                                     0xA414  // 0xA5A5 = enable UDP server, always enabled for configuration
                                     };
 
 
 /*
-* Variables for network configuration, TCP server
-*/
-uint8_t u8mac[6], u8ip_addr[4];// keep mac and ip address in 8-bits
-uint16_t u16mac_addr[3], u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4]; // 16-bits, directly loaded from eeprom
-char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16]; // for printf, converted from 16-bits u16ip_xxx
-uint16_t configured_ip = 0;  // static ip configured flag
+ * Variables for network configuration, TCP server
+ */
+// Device configuration
+uint16_t u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4], u16mac_addr[3]; // 16-bits, directly loaded from eeprom
+char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16], str_mac_addr[16]; // for printf and RPC, converted from 16-bits u16ip_xxx
+uint8_t u8ip_addr[4];// keep ip address in 8-bits
+uint16_t configured_ip = 0;  // flag indicates a static ip has been configured 0xA5A5
+uint8_t u8mac[6]; // mac in 8-bits
 
-const uint16_t tcp_server_local_port = 10000; // fixed, change to 7000 if internet required
-const uint16_t udp_server_local_port = 11000; // fixed
+// TCP/UDP server
+uint16_t tcp_server_local_port = 10000; // change to 7000 if internet required
+uint16_t udp_server_local_port = 11000;
 
-// TCP client: this section is used for the TCP server that this device connects to in TCP client mode
-// this device will transmit status every transmit_time_period
+// TCP client
+// this section is used to set the TCP server that this device connects to in TCP client mode.
+// this device will update its status to the server every transmit_time_period.
 uint16_t auto_transmit_flag = 0, transmit_time_period = 1000; // auto transmit status, time period = 1s
 uint16_t u16server_ip_addr[4]; // directly loaded from eeprom
 uint8_t u8server_ip_addr[4]; // server ip address in 8-bits
 char str_server_ip_addr[16];// for printf, converted from 16-bits u16server_ip_addr
 uint16_t u16tcp_server_port; // directly loaded from eeprom
-uint16_t u16enable_tcp_client, u16enable_tcp_server;// flags for enabling TCP client or TCP server
+uint16_t u16enable_tcp_server, u16enable_tcp_client;// flags for enabling TCP client or TCP server
+
+// Corresponding RPC variables
+RPCVariable<char*> rpcIPAddress(str_ip_addr, 16, "ipaddr");
+RPCVariable<char*> rpcSubnet(str_ip_subnet, 16, "subnet");
+RPCVariable<char*> rpcGateway(str_ip_gateway, 16, "gateway");
+RPCVariable<char*> rpcMac(str_mac_addr, 16, "mac");
+RPCVariable<unsigned short> rpcLocalTCPServerPort(&tcp_server_local_port, "localtcpserverport");
+RPCVariable<unsigned short> rpcLocalUDPPort(&udp_server_local_port, "localudpport");
+RPCVariable<unsigned short> rpcEnableTCPServer(&u16enable_tcp_server, "enabletcpserver");
 
 
 // Serial
@@ -97,15 +107,11 @@
 // Watchdog
 Watchdog wdt;
 
-float speed;
-RPCVariable<float> rpcSpeed(&speed, "speed");
-char stripaddr[20];
-RPCVariable<char*> rpcIPAddress(stripaddr, 20, "ipaddr");
 
 
 /*
-* Threads
-*/
+ * Threads
+ */
 // WDT reset
 void wdt_reset_thread(void const* args)
 {
@@ -133,8 +139,8 @@
 // Main code
 int main()
 {
-    int n, ret;
-
+    int ret;
+    
     Thread::wait(500); // turn on delay
 
     /*
@@ -193,8 +199,8 @@
 
 
 /*
-* W5500 Ethernet init
-*/
+ * W5500 Ethernet init
+ */
 int ethernet_init(void)
 {
     int dhcp_ret, ret;