Used with eeprom_flash to write network configuration to STM32F103 flash

Dependents:   F103-Web-Server

Fork of my_eeprom_funcs by Chau Vo

Committer:
olympux
Date:
Sun Aug 21 17:46:55 2016 +0000
Revision:
18:d88314ae7979
Parent:
17:574f90b11417
Child:
19:5671f3c25342
added UDP client

Who changed what in which revision?

UserRevisionLine numberNew contents of line
olympux 1:6bdc99dd8e0a 1 #include "mbed.h"
olympux 16:700377cd9d29 2 #include "device_configuration.h"
olympux 1:6bdc99dd8e0a 3
olympux 1:6bdc99dd8e0a 4
olympux 11:250b05a5266d 5 /*
olympux 10:f37acffddef9 6 * Debug option
olympux 10:f37acffddef9 7 */
olympux 16:700377cd9d29 8 #if 0
olympux 4:944a4646b825 9 //Enable debug
olympux 4:944a4646b825 10 #include <cstdio>
olympux 16:700377cd9d29 11 #define INFO(x, ...) std::printf(""x"\r\n", ##__VA_ARGS__);
olympux 16:700377cd9d29 12 #define DBG(x, ...) std::printf("[dev_conf: DBG]"x"\r\n", ##__VA_ARGS__);
olympux 16:700377cd9d29 13 #define WARN(x, ...) std::printf("[dev_conf: WARN]"x"\r\n", ##__VA_ARGS__);
olympux 16:700377cd9d29 14 #define ERR(x, ...) std::printf("[dev_conf: ERR]"x"\r\n", ##__VA_ARGS__);
olympux 4:944a4646b825 15 #else
olympux 4:944a4646b825 16 //Disable debug
olympux 16:700377cd9d29 17 #define INFO(x, ...)
olympux 4:944a4646b825 18 #define DBG(x, ...)
olympux 4:944a4646b825 19 #define WARN(x, ...)
olympux 4:944a4646b825 20 #define ERR(x, ...)
olympux 16:700377cd9d29 21 #endif
olympux 4:944a4646b825 22
olympux 16:700377cd9d29 23
olympux 16:700377cd9d29 24 /*
olympux 16:700377cd9d29 25 * Variables for network configuration
olympux 16:700377cd9d29 26 */
olympux 16:700377cd9d29 27 // Device configuration
olympux 16:700377cd9d29 28 uint16_t u16IpAddr[4], u16IpSubnet[4], u16IpGateway[4], u16MacAddr[3]; // 16-bits variables to be compatible with eeprom functions
olympux 16:700377cd9d29 29 char strIpAddr[16], strIpSubnet[16], strIpGateway[16], strMacAddr[20]; // RPC variables, converted from 16-bits u16ip_xxx
olympux 16:700377cd9d29 30 uint16_t u16DeviceConfiguredFlag = 0; // flag indicates whether device has been configured (0xA5A5) or not
olympux 16:700377cd9d29 31 // TCP server/UDP
olympux 16:700377cd9d29 32 uint16_t u16LocalTcpServerPort = DEFAULT_LOCAL_TCP_SERVER_PORT;
olympux 18:d88314ae7979 33 uint16_t u16LocalUdpServerPort = DEFAULT_LOCAL_UDP_SERVER_PORT;
olympux 16:700377cd9d29 34 // TCP client mode, set parameters of the remote TCP server this device connects to.
olympux 16:700377cd9d29 35 // When enabled, this device will send its status to the server every transmit_time_period.
olympux 16:700377cd9d29 36 uint16_t u16RemoteTcpServerIpAddr[4]; // 16-bit variable to be compatible with eeprom functions
olympux 16:700377cd9d29 37 char strRemoteTcpServerIpAddr[16]; // RPC variable, converted from 16-bits u16server_ip_addr
olympux 16:700377cd9d29 38 uint16_t u16RemoteTcpServerPort; // 16-bit variable to be compatible with eeprom functions
olympux 16:700377cd9d29 39 uint16_t u16AutoTransmitFlag = 0, u16TransmitPeriod = DEFAULT_TRANSMIT_PERIOD; // auto transmit status, time period = 1s
olympux 18:d88314ae7979 40 // UDP client mode
olympux 18:d88314ae7979 41 uint16_t u16RemoteUdpServerIpAddr[4]; // 16-bit variable to be compatible with eeprom functions
olympux 18:d88314ae7979 42 char strRemoteUdpServerIpAddr[16]; // RPC variable, converted from 16-bits u16server_ip_addr
olympux 18:d88314ae7979 43 uint16_t u16RemoteUdpServerPort; // 16-bit variable to be compatible with eeprom functions
olympux 16:700377cd9d29 44 // enable modes
olympux 18:d88314ae7979 45 uint16_t u16EnableTcpServer = 0, u16EnableTcpClient = 0; // flags for enabling TCP server/client and UDP (UDP is always on for configuration)
olympux 18:d88314ae7979 46 uint16_t u16EnableUdpServer = DEFAULT_ENABLE_FLAG_VALUE, u16EnableUdpClient = 0;
olympux 16:700377cd9d29 47 // extra
olympux 16:700377cd9d29 48 uint8_t u8IpAddr[4]; // keep device ip address in 8-bits
olympux 16:700377cd9d29 49 uint8_t u8MacAddr[6]; // keep mac in 8-bits
olympux 16:700377cd9d29 50 uint8_t u8RemoteTcpServerIpAddr[4]; // remote TCP server ip address in 8-bits
olympux 18:d88314ae7979 51 uint8_t u8RemoteUdpServerIpAddr[4]; // remote UDP server ip address in 8-bits
olympux 4:944a4646b825 52
olympux 12:613ab276bf37 53 /*!
olympux 12:613ab276bf37 54 * Function to write module network configuration
olympux 12:613ab276bf37 55 * @param <char *buf> configuration buffer
olympux 16:700377cd9d29 56 * @note 4x16-bit IP address
olympux 16:700377cd9d29 57 * @note 4x16-bit subnet
olympux 16:700377cd9d29 58 * @note 4x16-bit gateway
olympux 16:700377cd9d29 59 * @note 3x16-bit MAC
olympux 16:700377cd9d29 60 * @note 16-bit TCP local port
olympux 16:700377cd9d29 61 * @note 16-bit UDP local port
olympux 12:613ab276bf37 62 */
olympux 18:d88314ae7979 63 void write_device_configuration(uint16_t* ip, uint16_t* subnet, uint16_t* gateway, uint16_t* mac,
olympux 18:d88314ae7979 64 uint16_t tcp_port, uint16_t udp_port,
olympux 18:d88314ae7979 65 uint16_t* remote_tcp_ip, uint16_t remote_tcp_port, uint16_t auto_transmit, uint16_t transmit_period,
olympux 18:d88314ae7979 66 uint16_t* remote_udp_ip, uint16_t remote_udp_port,
olympux 18:d88314ae7979 67 uint16_t enable_tcp_server, uint16_t enable_tcp_client, uint16_t enable_udp_server, uint16_t enable_udp_client) {
olympux 1:6bdc99dd8e0a 68 // Write network configuration
olympux 1:6bdc99dd8e0a 69 // 4-byte IP address + 4-byte subnet + 4-byte gateway + 3-byte MAC
olympux 16:700377cd9d29 70 // + local TCP server port + local UDP port
olympux 1:6bdc99dd8e0a 71
olympux 16:700377cd9d29 72 INFO("Saving network configuration for this device...");
olympux 16:700377cd9d29 73
olympux 16:700377cd9d29 74 enableEEPROMWriting();
olympux 6:241d1539914a 75
olympux 6:241d1539914a 76 // erase first_run flag
olympux 16:700377cd9d29 77 writeEEPROMHalfWord(DEVICE_CONFIGURED_FLAG_POS, DEFAULT_ENABLE_FLAG_VALUE);
olympux 6:241d1539914a 78
olympux 1:6bdc99dd8e0a 79 // IP address
olympux 16:700377cd9d29 80 writeEEPROMHalfWord(IP_ADDRESS_POS+2*0, ip[0]);
olympux 16:700377cd9d29 81 writeEEPROMHalfWord(IP_ADDRESS_POS+2*1, ip[1]);
olympux 16:700377cd9d29 82 writeEEPROMHalfWord(IP_ADDRESS_POS+2*2, ip[2]);
olympux 16:700377cd9d29 83 writeEEPROMHalfWord(IP_ADDRESS_POS+2*3, ip[3]);
olympux 1:6bdc99dd8e0a 84
olympux 1:6bdc99dd8e0a 85 // IP subnet
olympux 16:700377cd9d29 86 writeEEPROMHalfWord(IP_SUBNET_POS+2*0, subnet[0]);
olympux 16:700377cd9d29 87 writeEEPROMHalfWord(IP_SUBNET_POS+2*1, subnet[1]);
olympux 16:700377cd9d29 88 writeEEPROMHalfWord(IP_SUBNET_POS+2*2, subnet[2]);
olympux 16:700377cd9d29 89 writeEEPROMHalfWord(IP_SUBNET_POS+2*3, subnet[3]);
olympux 1:6bdc99dd8e0a 90
olympux 1:6bdc99dd8e0a 91 // IP gateway
olympux 16:700377cd9d29 92 writeEEPROMHalfWord(IP_GATEWAY_POS+2*0, gateway[0]);
olympux 16:700377cd9d29 93 writeEEPROMHalfWord(IP_GATEWAY_POS+2*1, gateway[1]);
olympux 16:700377cd9d29 94 writeEEPROMHalfWord(IP_GATEWAY_POS+2*2, gateway[2]);
olympux 16:700377cd9d29 95 writeEEPROMHalfWord(IP_GATEWAY_POS+2*3, gateway[3]);
olympux 1:6bdc99dd8e0a 96
olympux 1:6bdc99dd8e0a 97 // MAC address
olympux 16:700377cd9d29 98 writeEEPROMHalfWord(MAC_ADDRESS_POS+2*0, mac[0]);
olympux 16:700377cd9d29 99 writeEEPROMHalfWord(MAC_ADDRESS_POS+2*1, mac[1]);
olympux 16:700377cd9d29 100 writeEEPROMHalfWord(MAC_ADDRESS_POS+2*2, mac[2]);
olympux 16:700377cd9d29 101
olympux 16:700377cd9d29 102 // Ports
olympux 16:700377cd9d29 103 writeEEPROMHalfWord(LOCAL_TCP_SERVER_PORT_POS, tcp_port);
olympux 18:d88314ae7979 104 writeEEPROMHalfWord(LOCAL_UDP_SERVER_PORT_POS, udp_port);
olympux 16:700377cd9d29 105
olympux 16:700377cd9d29 106 // Remote TCP server
olympux 18:d88314ae7979 107 writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*0, remote_tcp_ip[0]);
olympux 18:d88314ae7979 108 writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*1, remote_tcp_ip[1]);
olympux 18:d88314ae7979 109 writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*2, remote_tcp_ip[2]);
olympux 18:d88314ae7979 110 writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*3, remote_tcp_ip[3]);
olympux 1:6bdc99dd8e0a 111
olympux 18:d88314ae7979 112 // Remote TCP server port
olympux 18:d88314ae7979 113 writeEEPROMHalfWord(REMOTE_TCP_SERVER_PORT_POS, remote_tcp_port);
olympux 16:700377cd9d29 114
olympux 16:700377cd9d29 115 // Auto transmit
olympux 16:700377cd9d29 116 writeEEPROMHalfWord(AUTO_TRANSMIT_FLAG_POS, auto_transmit);
olympux 16:700377cd9d29 117 writeEEPROMHalfWord(AUTO_TRANSMIT_TIME_PERIOD_POS, transmit_period);
olympux 16:700377cd9d29 118
olympux 18:d88314ae7979 119 // Remote UDP server
olympux 18:d88314ae7979 120 writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*0, remote_udp_ip[0]);
olympux 18:d88314ae7979 121 writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*1, remote_udp_ip[1]);
olympux 18:d88314ae7979 122 writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*2, remote_udp_ip[2]);
olympux 18:d88314ae7979 123 writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*3, remote_udp_ip[3]);
olympux 18:d88314ae7979 124
olympux 18:d88314ae7979 125 // Remote UDP server port
olympux 18:d88314ae7979 126 writeEEPROMHalfWord(REMOTE_UDP_SERVER_PORT_POS, remote_udp_port);
olympux 18:d88314ae7979 127
olympux 16:700377cd9d29 128 // Enable modes
olympux 16:700377cd9d29 129 writeEEPROMHalfWord(ENABLE_TCP_SERVER_POS, enable_tcp_server);
olympux 16:700377cd9d29 130 writeEEPROMHalfWord(ENABLE_TCP_CLIENT_POS, enable_tcp_client);
olympux 18:d88314ae7979 131 writeEEPROMHalfWord(ENABLE_UDP_SERVER_POS, enable_udp_server);
olympux 18:d88314ae7979 132 writeEEPROMHalfWord(ENABLE_UDP_CLIENT_POS, enable_udp_client);
olympux 16:700377cd9d29 133
olympux 16:700377cd9d29 134 disableEEPROMWriting();
olympux 16:700377cd9d29 135
olympux 16:700377cd9d29 136 INFO("Successful");
olympux 1:6bdc99dd8e0a 137 }
olympux 1:6bdc99dd8e0a 138
olympux 10:f37acffddef9 139 /*!
olympux 10:f37acffddef9 140 * Function to load module network configuration
olympux 10:f37acffddef9 141 */
olympux 16:700377cd9d29 142 void read_device_configuration(void) {
olympux 16:700377cd9d29 143 mbed_mac_address((char *)u8MacAddr);
olympux 1:6bdc99dd8e0a 144
olympux 16:700377cd9d29 145 INFO("Loading network configuration...");
olympux 1:6bdc99dd8e0a 146
olympux 16:700377cd9d29 147 // check if configured
olympux 16:700377cd9d29 148 u16DeviceConfiguredFlag = readEEPROMHalfWord(DEVICE_CONFIGURED_FLAG_POS);
olympux 1:6bdc99dd8e0a 149
olympux 1:6bdc99dd8e0a 150 // if not first run, load network config
olympux 16:700377cd9d29 151 if (u16DeviceConfiguredFlag == DEFAULT_ENABLE_FLAG_VALUE) {
olympux 16:700377cd9d29 152 INFO("User settings");
olympux 1:6bdc99dd8e0a 153
olympux 1:6bdc99dd8e0a 154 // IP address
olympux 16:700377cd9d29 155 u16IpAddr[0] = readEEPROMHalfWord(IP_ADDRESS_POS+2*0);
olympux 16:700377cd9d29 156 u16IpAddr[1] = readEEPROMHalfWord(IP_ADDRESS_POS+2*1);
olympux 16:700377cd9d29 157 u16IpAddr[2] = readEEPROMHalfWord(IP_ADDRESS_POS+2*2);
olympux 16:700377cd9d29 158 u16IpAddr[3] = readEEPROMHalfWord(IP_ADDRESS_POS+2*3);
olympux 16:700377cd9d29 159 u8IpAddr[0] = (uint8_t)(u16IpAddr[0] & 0x00FF);
olympux 16:700377cd9d29 160 u8IpAddr[1] = (uint8_t)(u16IpAddr[1] & 0x00FF);
olympux 16:700377cd9d29 161 u8IpAddr[2] = (uint8_t)(u16IpAddr[2] & 0x00FF);
olympux 16:700377cd9d29 162 u8IpAddr[3] = (uint8_t)(u16IpAddr[3] & 0x00FF);
olympux 1:6bdc99dd8e0a 163
olympux 1:6bdc99dd8e0a 164 // IP subnet
olympux 16:700377cd9d29 165 u16IpSubnet[0] = readEEPROMHalfWord(IP_SUBNET_POS+2*0);
olympux 16:700377cd9d29 166 u16IpSubnet[1] = readEEPROMHalfWord(IP_SUBNET_POS+2*1);
olympux 16:700377cd9d29 167 u16IpSubnet[2] = readEEPROMHalfWord(IP_SUBNET_POS+2*2);
olympux 16:700377cd9d29 168 u16IpSubnet[3] = readEEPROMHalfWord(IP_SUBNET_POS+2*3);
olympux 1:6bdc99dd8e0a 169
olympux 1:6bdc99dd8e0a 170 // IP gateway
olympux 16:700377cd9d29 171 u16IpGateway[0] = readEEPROMHalfWord(IP_GATEWAY_POS+2*0);
olympux 16:700377cd9d29 172 u16IpGateway[1] = readEEPROMHalfWord(IP_GATEWAY_POS+2*1);
olympux 16:700377cd9d29 173 u16IpGateway[2] = readEEPROMHalfWord(IP_GATEWAY_POS+2*2);
olympux 16:700377cd9d29 174 u16IpGateway[3] = readEEPROMHalfWord(IP_GATEWAY_POS+2*3);
olympux 1:6bdc99dd8e0a 175
olympux 1:6bdc99dd8e0a 176 // MAC address
olympux 16:700377cd9d29 177 u16MacAddr[0] = readEEPROMHalfWord(MAC_ADDRESS_POS+2*0);
olympux 16:700377cd9d29 178 u16MacAddr[1] = readEEPROMHalfWord(MAC_ADDRESS_POS+2*1);
olympux 16:700377cd9d29 179 u16MacAddr[2] = readEEPROMHalfWord(MAC_ADDRESS_POS+2*2);
olympux 16:700377cd9d29 180 u8MacAddr[0] = DEFAULT_MAC0; u8MacAddr[1] = DEFAULT_MAC1; u8MacAddr[2] = DEFAULT_MAC2;
olympux 16:700377cd9d29 181 u8MacAddr[3] = (uint8_t)(u16MacAddr[0] & 0x00FF);
olympux 16:700377cd9d29 182 u8MacAddr[4] = (uint8_t)(u16MacAddr[1] & 0x00FF);
olympux 16:700377cd9d29 183 u8MacAddr[5] = (uint8_t)(u16MacAddr[2] & 0x00FF);
olympux 16:700377cd9d29 184
olympux 16:700377cd9d29 185 // Ports
olympux 16:700377cd9d29 186 u16LocalTcpServerPort = readEEPROMHalfWord(LOCAL_TCP_SERVER_PORT_POS);
olympux 18:d88314ae7979 187 u16LocalUdpServerPort = readEEPROMHalfWord(LOCAL_UDP_SERVER_PORT_POS);
olympux 1:6bdc99dd8e0a 188
olympux 16:700377cd9d29 189 // Remote TCP server
olympux 16:700377cd9d29 190 u16RemoteTcpServerIpAddr[0] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*0);
olympux 16:700377cd9d29 191 u16RemoteTcpServerIpAddr[1] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*1);
olympux 16:700377cd9d29 192 u16RemoteTcpServerIpAddr[2] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*2);
olympux 16:700377cd9d29 193 u16RemoteTcpServerIpAddr[3] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*3);
olympux 16:700377cd9d29 194 u8RemoteTcpServerIpAddr[0] = (uint8_t)(u16RemoteTcpServerIpAddr[0] & 0x00FF);
olympux 16:700377cd9d29 195 u8RemoteTcpServerIpAddr[1] = (uint8_t)(u16RemoteTcpServerIpAddr[1] & 0x00FF);
olympux 16:700377cd9d29 196 u8RemoteTcpServerIpAddr[2] = (uint8_t)(u16RemoteTcpServerIpAddr[2] & 0x00FF);
olympux 16:700377cd9d29 197 u8RemoteTcpServerIpAddr[3] = (uint8_t)(u16RemoteTcpServerIpAddr[3] & 0x00FF);
olympux 16:700377cd9d29 198
olympux 18:d88314ae7979 199 // Remote TCP server port
olympux 16:700377cd9d29 200 u16RemoteTcpServerPort = readEEPROMHalfWord(REMOTE_TCP_SERVER_PORT_POS);
olympux 16:700377cd9d29 201
olympux 16:700377cd9d29 202 // Auto transmit
olympux 16:700377cd9d29 203 u16AutoTransmitFlag = readEEPROMHalfWord(AUTO_TRANSMIT_FLAG_POS);
olympux 16:700377cd9d29 204 u16TransmitPeriod = readEEPROMHalfWord(AUTO_TRANSMIT_TIME_PERIOD_POS);
olympux 16:700377cd9d29 205
olympux 18:d88314ae7979 206 // Remote UDP server
olympux 18:d88314ae7979 207 u16RemoteUdpServerIpAddr[0] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*0);
olympux 18:d88314ae7979 208 u16RemoteUdpServerIpAddr[1] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*1);
olympux 18:d88314ae7979 209 u16RemoteUdpServerIpAddr[2] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*2);
olympux 18:d88314ae7979 210 u16RemoteUdpServerIpAddr[3] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*3);
olympux 18:d88314ae7979 211 u8RemoteUdpServerIpAddr[0] = (uint8_t)(u16RemoteUdpServerIpAddr[0] & 0x00FF);
olympux 18:d88314ae7979 212 u8RemoteUdpServerIpAddr[1] = (uint8_t)(u16RemoteUdpServerIpAddr[1] & 0x00FF);
olympux 18:d88314ae7979 213 u8RemoteUdpServerIpAddr[2] = (uint8_t)(u16RemoteUdpServerIpAddr[2] & 0x00FF);
olympux 18:d88314ae7979 214 u8RemoteUdpServerIpAddr[3] = (uint8_t)(u16RemoteUdpServerIpAddr[3] & 0x00FF);
olympux 18:d88314ae7979 215
olympux 18:d88314ae7979 216 // Remote port
olympux 18:d88314ae7979 217 u16RemoteUdpServerPort = readEEPROMHalfWord(REMOTE_UDP_SERVER_PORT_POS);
olympux 18:d88314ae7979 218
olympux 16:700377cd9d29 219 // Enable modes
olympux 16:700377cd9d29 220 u16EnableTcpServer = readEEPROMHalfWord(ENABLE_TCP_SERVER_POS);
olympux 16:700377cd9d29 221 u16EnableTcpClient = readEEPROMHalfWord(ENABLE_TCP_CLIENT_POS);
olympux 18:d88314ae7979 222 u16EnableUdpServer = readEEPROMHalfWord(ENABLE_UDP_SERVER_POS);
olympux 18:d88314ae7979 223 u16EnableUdpClient = readEEPROMHalfWord(ENABLE_UDP_CLIENT_POS);
olympux 16:700377cd9d29 224
olympux 16:700377cd9d29 225 sprintf(strIpAddr, "%d.%d.%d.%d", u8IpAddr[0], u8IpAddr[1], u8IpAddr[2], u8IpAddr[3]);
olympux 16:700377cd9d29 226 sprintf(strIpSubnet, "%d.%d.%d.%d", (uint8_t)u16IpSubnet[0], (uint8_t)u16IpSubnet[1], (uint8_t)u16IpSubnet[2], (uint8_t)u16IpSubnet[3]);
olympux 16:700377cd9d29 227 sprintf(strIpGateway, "%d.%d.%d.%d", (uint8_t)u16IpGateway[0], (uint8_t)u16IpGateway[1], (uint8_t)u16IpGateway[2], (uint8_t)u16IpGateway[3]);
olympux 16:700377cd9d29 228 sprintf(strRemoteTcpServerIpAddr, "%d.%d.%d.%d", u8RemoteTcpServerIpAddr[0], u8RemoteTcpServerIpAddr[1], u8RemoteTcpServerIpAddr[2], u8RemoteTcpServerIpAddr[3]);
olympux 18:d88314ae7979 229 sprintf(strRemoteUdpServerIpAddr, "%d.%d.%d.%d", u8RemoteUdpServerIpAddr[0], u8RemoteUdpServerIpAddr[1], u8RemoteUdpServerIpAddr[2], u8RemoteUdpServerIpAddr[3]);
olympux 17:574f90b11417 230 sprintf(strMacAddr, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", u8MacAddr[0], u8MacAddr[1], u8MacAddr[2], u8MacAddr[3], u8MacAddr[4], u8MacAddr[5]);
olympux 1:6bdc99dd8e0a 231 }
olympux 8:4fc4b1b5509b 232 // if ip is not configured, use default addresses
olympux 1:6bdc99dd8e0a 233 else {
olympux 16:700377cd9d29 234 INFO("No user settings, load defaults");
olympux 16:700377cd9d29 235 u8MacAddr[0] = DEFAULT_MAC0; u8MacAddr[1] = DEFAULT_MAC1; u8MacAddr[2] = DEFAULT_MAC2;
olympux 16:700377cd9d29 236 u8MacAddr[3] = DEFAULT_MAC3; u8MacAddr[4] = DEFAULT_MAC4; u8MacAddr[5] = DEFAULT_MAC5;
olympux 16:700377cd9d29 237 sprintf(strIpAddr, DEFAULT_IP_ADDRESS);
olympux 16:700377cd9d29 238 sprintf(strIpSubnet, DEFAULT_IP_SUBNET);
olympux 16:700377cd9d29 239 sprintf(strIpGateway, DEFAULT_IP_GATEWAY);
olympux 16:700377cd9d29 240 sprintf(strRemoteTcpServerIpAddr, DEFAULT_REMOTE_TCP_SERVER_IP);
olympux 18:d88314ae7979 241 sprintf(strRemoteUdpServerIpAddr, DEFAULT_REMOTE_UDP_SERVER_IP);
olympux 17:574f90b11417 242 sprintf(strMacAddr, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", u8MacAddr[0], u8MacAddr[1], u8MacAddr[2], u8MacAddr[3], u8MacAddr[4], u8MacAddr[5]);
olympux 1:6bdc99dd8e0a 243 }
olympux 1:6bdc99dd8e0a 244
olympux 16:700377cd9d29 245 INFO("Successful");
olympux 16:700377cd9d29 246 INFO("IP: %s", strIpAddr);
olympux 16:700377cd9d29 247 INFO("MASK: %s", strIpSubnet);
olympux 16:700377cd9d29 248 INFO("GW: %s", strIpGateway);
olympux 16:700377cd9d29 249 INFO("TCP server local port: %d", u16LocalTcpServerPort);
olympux 18:d88314ae7979 250 INFO("UDP server local port: %d", u16LocalUdpServerPort);
olympux 18:d88314ae7979 251
olympux 18:d88314ae7979 252 INFO("Remote TCP server: %s", strRemoteTcpServerIpAddr);
olympux 18:d88314ae7979 253 INFO("Remote TCP server port: %d", u16RemoteTcpServerPort);
olympux 18:d88314ae7979 254
olympux 18:d88314ae7979 255 INFO("Remote UDP server: %s", strRemoteUdpServerIpAddr);
olympux 18:d88314ae7979 256 INFO("Remote UDP server port: %d", u16RemoteUdpServerPort);
olympux 18:d88314ae7979 257
olympux 18:d88314ae7979 258 INFO("Auto transmit: %s", (u16AutoTransmitFlag == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
olympux 18:d88314ae7979 259 INFO("Period: %d", u16TransmitPeriod);
olympux 16:700377cd9d29 260
olympux 16:700377cd9d29 261 INFO("TCP server: %s", (u16EnableTcpServer == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
olympux 16:700377cd9d29 262 INFO("TCP client: %s", (u16EnableTcpClient == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
olympux 18:d88314ae7979 263 INFO("UDP server: %s", (u16EnableUdpServer == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
olympux 18:d88314ae7979 264 INFO("UDP client: %s", (u16EnableUdpClient == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable");
olympux 1:6bdc99dd8e0a 265 }
olympux 1:6bdc99dd8e0a 266
olympux 16:700377cd9d29 267 void reset_device_configuration() {
olympux 16:700377cd9d29 268 // erase first_run flag
olympux 16:700377cd9d29 269 enableEEPROMWriting();
olympux 16:700377cd9d29 270 disableEEPROMWriting();
olympux 1:6bdc99dd8e0a 271 }