Chau Vo / device_configuration

Dependents:   F103-Web-Server

Fork of my_eeprom_funcs by Chau Vo

Revision:
20:858384cac44a
Parent:
19:5671f3c25342
Child:
21:23ae23754f0b
--- a/device_configuration.cpp	Tue Aug 23 11:05:38 2016 +0000
+++ b/device_configuration.cpp	Mon Aug 29 21:29:38 2016 +0000
@@ -44,7 +44,12 @@
 // enable modes
 uint16_t u16EnableTcpServer = DEFAULT_ENABLE_FLAG_VALUE, u16EnableTcpClient = DEFAULT_DISABLE_FLAG_VALUE; // flags for enabling TCP server/client and UDP (UDP is always on for configuration)
 uint16_t u16EnableUdpServer = DEFAULT_DISABLE_FLAG_VALUE, u16EnableUdpClient = DEFAULT_DISABLE_FLAG_VALUE;
-// extra
+// time period between UART data package before sending through Ethernet interface
+uint16_t u16InterDataPeriod;
+// special character to signal sending data
+uint16_t u16SpecialChar;
+
+// extra, not actually in EEPROM
 uint8_t u8IpAddr[4]; // keep device ip address in 8-bits
 uint8_t u8MacAddr[6]; // keep mac in 8-bits
 uint8_t u8RemoteTcpServerIpAddr[4]; // remote TCP server ip address in 8-bits
@@ -73,7 +78,8 @@
             uint16_t tcp_port, uint16_t udp_port,
             uint16_t* remote_tcp_ip, uint16_t remote_tcp_port, uint16_t auto_transmit, uint16_t transmit_period,
             uint16_t* remote_udp_ip, uint16_t remote_udp_port,
-            uint16_t enable_tcp_server, uint16_t enable_tcp_client, uint16_t enable_udp_server, uint16_t enable_udp_client) {
+            uint16_t enable_tcp_server, uint16_t enable_tcp_client, uint16_t enable_udp_server, uint16_t enable_udp_client,
+            uint16_t inter_data_period, uint16_t special_char) {
     // Write network configuration
     // 4-byte IP address + 4-byte subnet + 4-byte gateway + 3-byte MAC
     // + local TCP server port + local UDP port
@@ -140,6 +146,12 @@
     writeEEPROMHalfWord(ENABLE_UDP_SERVER_POS, enable_udp_server);
     writeEEPROMHalfWord(ENABLE_UDP_CLIENT_POS, enable_udp_client);
     
+    // Serial inter-data period
+    writeEEPROMHalfWord(INTER_DATA_PERIOD_POS, inter_data_period);
+    
+    // Special char
+    writeEEPROMHalfWord(SPECIAL_CHAR_POS, special_char);
+    
     disableEEPROMWriting();
     
     INFO("Successful");
@@ -231,6 +243,11 @@
         u16EnableUdpServer = readEEPROMHalfWord(ENABLE_UDP_SERVER_POS);
         u16EnableUdpClient = readEEPROMHalfWord(ENABLE_UDP_CLIENT_POS);
         
+        // Serial inter-data period
+        u16InterDataPeriod = readEEPROMHalfWord(INTER_DATA_PERIOD_POS);
+        // Special character
+        u16SpecialChar = readEEPROMHalfWord(SPECIAL_CHAR_POS);
+        
         sprintf(strIpAddr, "%d.%d.%d.%d", u8IpAddr[0], u8IpAddr[1], u8IpAddr[2], u8IpAddr[3]);
         sprintf(strIpSubnet, "%d.%d.%d.%d", (uint8_t)u16IpSubnet[0], (uint8_t)u16IpSubnet[1], (uint8_t)u16IpSubnet[2], (uint8_t)u16IpSubnet[3]);
         sprintf(strIpGateway, "%d.%d.%d.%d", (uint8_t)u16IpGateway[0], (uint8_t)u16IpGateway[1], (uint8_t)u16IpGateway[2], (uint8_t)u16IpGateway[3]);
@@ -265,6 +282,9 @@
         u16EnableUdpServer = DEFAULT_DISABLE_FLAG_VALUE;
         u16EnableUdpClient = DEFAULT_DISABLE_FLAG_VALUE;
         
+        u16InterDataPeriod = DEFAULT_INTER_DATA_PERIOD;
+        u16SpecialChar = DEFAULT_SPECIAL_CHARACTER;
+        
     }
     
     INFO("Successful");
@@ -287,6 +307,9 @@
     INFO("TCP client: %s", (u16EnableTcpClient == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
     INFO("UDP server: %s", (u16EnableUdpServer == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
     INFO("UDP client: %s", (u16EnableUdpClient == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
+    
+    INFO("Serial inter-data period: %d", u16InterDataPeriod);
+    INFO("Special character: %.2x", u16SpecialChar);
 }
 
 void reset_default_device_configuration() {
@@ -312,6 +335,9 @@
     uint16_t enable_udp_server = DEFAULT_DISABLE_FLAG_VALUE;
     uint16_t enable_udp_client = DEFAULT_DISABLE_FLAG_VALUE;
     
+    uint16_t inter_data_period = DEFAULT_INTER_DATA_PERIOD;
+    uint16_t special_char = DEFAULT_SPECIAL_CHARACTER;
+    
     // erase the device configured flag
     erase_device_configuration();
     
@@ -320,5 +346,6 @@
             tcp_port, udp_port,
             remote_tcp_ip, remote_tcp_port, auto_transmit, transmit_period,
             remote_udp_ip, remote_udp_port,
-            enable_tcp_server, enable_tcp_client, enable_udp_server, enable_udp_client);
+            enable_tcp_server, enable_tcp_client, enable_udp_server, enable_udp_client,
+            inter_data_period, special_char);
 }