Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of my_eeprom_funcs by
device_configuration.cpp@20:858384cac44a, 2016-08-29 (annotated)
- Committer:
- olympux
- Date:
- Mon Aug 29 21:29:38 2016 +0000
- Revision:
- 20:858384cac44a
- Parent:
- 19:5671f3c25342
- Child:
- 21:23ae23754f0b
Add 2 more EEPROM variables
Who changed what in which revision?
| User | Revision | Line number | New 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 | 19:5671f3c25342 | 45 | 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) |
| olympux | 19:5671f3c25342 | 46 | uint16_t u16EnableUdpServer = DEFAULT_DISABLE_FLAG_VALUE, u16EnableUdpClient = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 20:858384cac44a | 47 | // time period between UART data package before sending through Ethernet interface |
| olympux | 20:858384cac44a | 48 | uint16_t u16InterDataPeriod; |
| olympux | 20:858384cac44a | 49 | // special character to signal sending data |
| olympux | 20:858384cac44a | 50 | uint16_t u16SpecialChar; |
| olympux | 20:858384cac44a | 51 | |
| olympux | 20:858384cac44a | 52 | // extra, not actually in EEPROM |
| olympux | 16:700377cd9d29 | 53 | uint8_t u8IpAddr[4]; // keep device ip address in 8-bits |
| olympux | 16:700377cd9d29 | 54 | uint8_t u8MacAddr[6]; // keep mac in 8-bits |
| olympux | 16:700377cd9d29 | 55 | uint8_t u8RemoteTcpServerIpAddr[4]; // remote TCP server ip address in 8-bits |
| olympux | 18:d88314ae7979 | 56 | uint8_t u8RemoteUdpServerIpAddr[4]; // remote UDP server ip address in 8-bits |
| olympux | 4:944a4646b825 | 57 | |
| olympux | 19:5671f3c25342 | 58 | |
| olympux | 19:5671f3c25342 | 59 | // erase page |
| olympux | 19:5671f3c25342 | 60 | void erase_device_configuration() { |
| olympux | 19:5671f3c25342 | 61 | // erase first_run flag |
| olympux | 19:5671f3c25342 | 62 | enableEEPROMWriting(); |
| olympux | 19:5671f3c25342 | 63 | disableEEPROMWriting(); |
| olympux | 19:5671f3c25342 | 64 | } |
| olympux | 19:5671f3c25342 | 65 | |
| olympux | 19:5671f3c25342 | 66 | |
| olympux | 12:613ab276bf37 | 67 | /*! |
| olympux | 12:613ab276bf37 | 68 | * Function to write module network configuration |
| olympux | 12:613ab276bf37 | 69 | * @param <char *buf> configuration buffer |
| olympux | 16:700377cd9d29 | 70 | * @note 4x16-bit IP address |
| olympux | 16:700377cd9d29 | 71 | * @note 4x16-bit subnet |
| olympux | 16:700377cd9d29 | 72 | * @note 4x16-bit gateway |
| olympux | 16:700377cd9d29 | 73 | * @note 3x16-bit MAC |
| olympux | 16:700377cd9d29 | 74 | * @note 16-bit TCP local port |
| olympux | 16:700377cd9d29 | 75 | * @note 16-bit UDP local port |
| olympux | 12:613ab276bf37 | 76 | */ |
| olympux | 18:d88314ae7979 | 77 | void write_device_configuration(uint16_t* ip, uint16_t* subnet, uint16_t* gateway, uint16_t* mac, |
| olympux | 18:d88314ae7979 | 78 | uint16_t tcp_port, uint16_t udp_port, |
| olympux | 18:d88314ae7979 | 79 | uint16_t* remote_tcp_ip, uint16_t remote_tcp_port, uint16_t auto_transmit, uint16_t transmit_period, |
| olympux | 18:d88314ae7979 | 80 | uint16_t* remote_udp_ip, uint16_t remote_udp_port, |
| olympux | 20:858384cac44a | 81 | uint16_t enable_tcp_server, uint16_t enable_tcp_client, uint16_t enable_udp_server, uint16_t enable_udp_client, |
| olympux | 20:858384cac44a | 82 | uint16_t inter_data_period, uint16_t special_char) { |
| olympux | 1:6bdc99dd8e0a | 83 | // Write network configuration |
| olympux | 1:6bdc99dd8e0a | 84 | // 4-byte IP address + 4-byte subnet + 4-byte gateway + 3-byte MAC |
| olympux | 16:700377cd9d29 | 85 | // + local TCP server port + local UDP port |
| olympux | 1:6bdc99dd8e0a | 86 | |
| olympux | 16:700377cd9d29 | 87 | INFO("Saving network configuration for this device..."); |
| olympux | 16:700377cd9d29 | 88 | |
| olympux | 16:700377cd9d29 | 89 | enableEEPROMWriting(); |
| olympux | 6:241d1539914a | 90 | |
| olympux | 6:241d1539914a | 91 | // erase first_run flag |
| olympux | 16:700377cd9d29 | 92 | writeEEPROMHalfWord(DEVICE_CONFIGURED_FLAG_POS, DEFAULT_ENABLE_FLAG_VALUE); |
| olympux | 6:241d1539914a | 93 | |
| olympux | 1:6bdc99dd8e0a | 94 | // IP address |
| olympux | 16:700377cd9d29 | 95 | writeEEPROMHalfWord(IP_ADDRESS_POS+2*0, ip[0]); |
| olympux | 16:700377cd9d29 | 96 | writeEEPROMHalfWord(IP_ADDRESS_POS+2*1, ip[1]); |
| olympux | 16:700377cd9d29 | 97 | writeEEPROMHalfWord(IP_ADDRESS_POS+2*2, ip[2]); |
| olympux | 16:700377cd9d29 | 98 | writeEEPROMHalfWord(IP_ADDRESS_POS+2*3, ip[3]); |
| olympux | 1:6bdc99dd8e0a | 99 | |
| olympux | 1:6bdc99dd8e0a | 100 | // IP subnet |
| olympux | 16:700377cd9d29 | 101 | writeEEPROMHalfWord(IP_SUBNET_POS+2*0, subnet[0]); |
| olympux | 16:700377cd9d29 | 102 | writeEEPROMHalfWord(IP_SUBNET_POS+2*1, subnet[1]); |
| olympux | 16:700377cd9d29 | 103 | writeEEPROMHalfWord(IP_SUBNET_POS+2*2, subnet[2]); |
| olympux | 16:700377cd9d29 | 104 | writeEEPROMHalfWord(IP_SUBNET_POS+2*3, subnet[3]); |
| olympux | 1:6bdc99dd8e0a | 105 | |
| olympux | 1:6bdc99dd8e0a | 106 | // IP gateway |
| olympux | 16:700377cd9d29 | 107 | writeEEPROMHalfWord(IP_GATEWAY_POS+2*0, gateway[0]); |
| olympux | 16:700377cd9d29 | 108 | writeEEPROMHalfWord(IP_GATEWAY_POS+2*1, gateway[1]); |
| olympux | 16:700377cd9d29 | 109 | writeEEPROMHalfWord(IP_GATEWAY_POS+2*2, gateway[2]); |
| olympux | 16:700377cd9d29 | 110 | writeEEPROMHalfWord(IP_GATEWAY_POS+2*3, gateway[3]); |
| olympux | 1:6bdc99dd8e0a | 111 | |
| olympux | 1:6bdc99dd8e0a | 112 | // MAC address |
| olympux | 16:700377cd9d29 | 113 | writeEEPROMHalfWord(MAC_ADDRESS_POS+2*0, mac[0]); |
| olympux | 16:700377cd9d29 | 114 | writeEEPROMHalfWord(MAC_ADDRESS_POS+2*1, mac[1]); |
| olympux | 16:700377cd9d29 | 115 | writeEEPROMHalfWord(MAC_ADDRESS_POS+2*2, mac[2]); |
| olympux | 16:700377cd9d29 | 116 | |
| olympux | 16:700377cd9d29 | 117 | // Ports |
| olympux | 16:700377cd9d29 | 118 | writeEEPROMHalfWord(LOCAL_TCP_SERVER_PORT_POS, tcp_port); |
| olympux | 18:d88314ae7979 | 119 | writeEEPROMHalfWord(LOCAL_UDP_SERVER_PORT_POS, udp_port); |
| olympux | 16:700377cd9d29 | 120 | |
| olympux | 16:700377cd9d29 | 121 | // Remote TCP server |
| olympux | 18:d88314ae7979 | 122 | writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*0, remote_tcp_ip[0]); |
| olympux | 18:d88314ae7979 | 123 | writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*1, remote_tcp_ip[1]); |
| olympux | 18:d88314ae7979 | 124 | writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*2, remote_tcp_ip[2]); |
| olympux | 18:d88314ae7979 | 125 | writeEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*3, remote_tcp_ip[3]); |
| olympux | 1:6bdc99dd8e0a | 126 | |
| olympux | 18:d88314ae7979 | 127 | // Remote TCP server port |
| olympux | 18:d88314ae7979 | 128 | writeEEPROMHalfWord(REMOTE_TCP_SERVER_PORT_POS, remote_tcp_port); |
| olympux | 16:700377cd9d29 | 129 | |
| olympux | 16:700377cd9d29 | 130 | // Auto transmit |
| olympux | 16:700377cd9d29 | 131 | writeEEPROMHalfWord(AUTO_TRANSMIT_FLAG_POS, auto_transmit); |
| olympux | 16:700377cd9d29 | 132 | writeEEPROMHalfWord(AUTO_TRANSMIT_TIME_PERIOD_POS, transmit_period); |
| olympux | 16:700377cd9d29 | 133 | |
| olympux | 18:d88314ae7979 | 134 | // Remote UDP server |
| olympux | 18:d88314ae7979 | 135 | writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*0, remote_udp_ip[0]); |
| olympux | 18:d88314ae7979 | 136 | writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*1, remote_udp_ip[1]); |
| olympux | 18:d88314ae7979 | 137 | writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*2, remote_udp_ip[2]); |
| olympux | 18:d88314ae7979 | 138 | writeEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*3, remote_udp_ip[3]); |
| olympux | 18:d88314ae7979 | 139 | |
| olympux | 18:d88314ae7979 | 140 | // Remote UDP server port |
| olympux | 18:d88314ae7979 | 141 | writeEEPROMHalfWord(REMOTE_UDP_SERVER_PORT_POS, remote_udp_port); |
| olympux | 18:d88314ae7979 | 142 | |
| olympux | 16:700377cd9d29 | 143 | // Enable modes |
| olympux | 16:700377cd9d29 | 144 | writeEEPROMHalfWord(ENABLE_TCP_SERVER_POS, enable_tcp_server); |
| olympux | 16:700377cd9d29 | 145 | writeEEPROMHalfWord(ENABLE_TCP_CLIENT_POS, enable_tcp_client); |
| olympux | 18:d88314ae7979 | 146 | writeEEPROMHalfWord(ENABLE_UDP_SERVER_POS, enable_udp_server); |
| olympux | 18:d88314ae7979 | 147 | writeEEPROMHalfWord(ENABLE_UDP_CLIENT_POS, enable_udp_client); |
| olympux | 16:700377cd9d29 | 148 | |
| olympux | 20:858384cac44a | 149 | // Serial inter-data period |
| olympux | 20:858384cac44a | 150 | writeEEPROMHalfWord(INTER_DATA_PERIOD_POS, inter_data_period); |
| olympux | 20:858384cac44a | 151 | |
| olympux | 20:858384cac44a | 152 | // Special char |
| olympux | 20:858384cac44a | 153 | writeEEPROMHalfWord(SPECIAL_CHAR_POS, special_char); |
| olympux | 20:858384cac44a | 154 | |
| olympux | 16:700377cd9d29 | 155 | disableEEPROMWriting(); |
| olympux | 16:700377cd9d29 | 156 | |
| olympux | 16:700377cd9d29 | 157 | INFO("Successful"); |
| olympux | 1:6bdc99dd8e0a | 158 | } |
| olympux | 1:6bdc99dd8e0a | 159 | |
| olympux | 10:f37acffddef9 | 160 | /*! |
| olympux | 10:f37acffddef9 | 161 | * Function to load module network configuration |
| olympux | 10:f37acffddef9 | 162 | */ |
| olympux | 16:700377cd9d29 | 163 | void read_device_configuration(void) { |
| olympux | 16:700377cd9d29 | 164 | mbed_mac_address((char *)u8MacAddr); |
| olympux | 1:6bdc99dd8e0a | 165 | |
| olympux | 16:700377cd9d29 | 166 | INFO("Loading network configuration..."); |
| olympux | 1:6bdc99dd8e0a | 167 | |
| olympux | 16:700377cd9d29 | 168 | // check if configured |
| olympux | 16:700377cd9d29 | 169 | u16DeviceConfiguredFlag = readEEPROMHalfWord(DEVICE_CONFIGURED_FLAG_POS); |
| olympux | 1:6bdc99dd8e0a | 170 | |
| olympux | 1:6bdc99dd8e0a | 171 | // if not first run, load network config |
| olympux | 16:700377cd9d29 | 172 | if (u16DeviceConfiguredFlag == DEFAULT_ENABLE_FLAG_VALUE) { |
| olympux | 16:700377cd9d29 | 173 | INFO("User settings"); |
| olympux | 1:6bdc99dd8e0a | 174 | |
| olympux | 1:6bdc99dd8e0a | 175 | // IP address |
| olympux | 16:700377cd9d29 | 176 | u16IpAddr[0] = readEEPROMHalfWord(IP_ADDRESS_POS+2*0); |
| olympux | 16:700377cd9d29 | 177 | u16IpAddr[1] = readEEPROMHalfWord(IP_ADDRESS_POS+2*1); |
| olympux | 16:700377cd9d29 | 178 | u16IpAddr[2] = readEEPROMHalfWord(IP_ADDRESS_POS+2*2); |
| olympux | 16:700377cd9d29 | 179 | u16IpAddr[3] = readEEPROMHalfWord(IP_ADDRESS_POS+2*3); |
| olympux | 16:700377cd9d29 | 180 | u8IpAddr[0] = (uint8_t)(u16IpAddr[0] & 0x00FF); |
| olympux | 16:700377cd9d29 | 181 | u8IpAddr[1] = (uint8_t)(u16IpAddr[1] & 0x00FF); |
| olympux | 16:700377cd9d29 | 182 | u8IpAddr[2] = (uint8_t)(u16IpAddr[2] & 0x00FF); |
| olympux | 16:700377cd9d29 | 183 | u8IpAddr[3] = (uint8_t)(u16IpAddr[3] & 0x00FF); |
| olympux | 1:6bdc99dd8e0a | 184 | |
| olympux | 1:6bdc99dd8e0a | 185 | // IP subnet |
| olympux | 16:700377cd9d29 | 186 | u16IpSubnet[0] = readEEPROMHalfWord(IP_SUBNET_POS+2*0); |
| olympux | 16:700377cd9d29 | 187 | u16IpSubnet[1] = readEEPROMHalfWord(IP_SUBNET_POS+2*1); |
| olympux | 16:700377cd9d29 | 188 | u16IpSubnet[2] = readEEPROMHalfWord(IP_SUBNET_POS+2*2); |
| olympux | 16:700377cd9d29 | 189 | u16IpSubnet[3] = readEEPROMHalfWord(IP_SUBNET_POS+2*3); |
| olympux | 1:6bdc99dd8e0a | 190 | |
| olympux | 1:6bdc99dd8e0a | 191 | // IP gateway |
| olympux | 16:700377cd9d29 | 192 | u16IpGateway[0] = readEEPROMHalfWord(IP_GATEWAY_POS+2*0); |
| olympux | 16:700377cd9d29 | 193 | u16IpGateway[1] = readEEPROMHalfWord(IP_GATEWAY_POS+2*1); |
| olympux | 16:700377cd9d29 | 194 | u16IpGateway[2] = readEEPROMHalfWord(IP_GATEWAY_POS+2*2); |
| olympux | 16:700377cd9d29 | 195 | u16IpGateway[3] = readEEPROMHalfWord(IP_GATEWAY_POS+2*3); |
| olympux | 1:6bdc99dd8e0a | 196 | |
| olympux | 1:6bdc99dd8e0a | 197 | // MAC address |
| olympux | 16:700377cd9d29 | 198 | u16MacAddr[0] = readEEPROMHalfWord(MAC_ADDRESS_POS+2*0); |
| olympux | 16:700377cd9d29 | 199 | u16MacAddr[1] = readEEPROMHalfWord(MAC_ADDRESS_POS+2*1); |
| olympux | 16:700377cd9d29 | 200 | u16MacAddr[2] = readEEPROMHalfWord(MAC_ADDRESS_POS+2*2); |
| olympux | 16:700377cd9d29 | 201 | u8MacAddr[0] = DEFAULT_MAC0; u8MacAddr[1] = DEFAULT_MAC1; u8MacAddr[2] = DEFAULT_MAC2; |
| olympux | 16:700377cd9d29 | 202 | u8MacAddr[3] = (uint8_t)(u16MacAddr[0] & 0x00FF); |
| olympux | 16:700377cd9d29 | 203 | u8MacAddr[4] = (uint8_t)(u16MacAddr[1] & 0x00FF); |
| olympux | 16:700377cd9d29 | 204 | u8MacAddr[5] = (uint8_t)(u16MacAddr[2] & 0x00FF); |
| olympux | 16:700377cd9d29 | 205 | |
| olympux | 16:700377cd9d29 | 206 | // Ports |
| olympux | 16:700377cd9d29 | 207 | u16LocalTcpServerPort = readEEPROMHalfWord(LOCAL_TCP_SERVER_PORT_POS); |
| olympux | 18:d88314ae7979 | 208 | u16LocalUdpServerPort = readEEPROMHalfWord(LOCAL_UDP_SERVER_PORT_POS); |
| olympux | 1:6bdc99dd8e0a | 209 | |
| olympux | 16:700377cd9d29 | 210 | // Remote TCP server |
| olympux | 16:700377cd9d29 | 211 | u16RemoteTcpServerIpAddr[0] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*0); |
| olympux | 16:700377cd9d29 | 212 | u16RemoteTcpServerIpAddr[1] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*1); |
| olympux | 16:700377cd9d29 | 213 | u16RemoteTcpServerIpAddr[2] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*2); |
| olympux | 16:700377cd9d29 | 214 | u16RemoteTcpServerIpAddr[3] = readEEPROMHalfWord(REMOTE_TCP_SERVER_IP_ADDR_POS+2*3); |
| olympux | 16:700377cd9d29 | 215 | u8RemoteTcpServerIpAddr[0] = (uint8_t)(u16RemoteTcpServerIpAddr[0] & 0x00FF); |
| olympux | 16:700377cd9d29 | 216 | u8RemoteTcpServerIpAddr[1] = (uint8_t)(u16RemoteTcpServerIpAddr[1] & 0x00FF); |
| olympux | 16:700377cd9d29 | 217 | u8RemoteTcpServerIpAddr[2] = (uint8_t)(u16RemoteTcpServerIpAddr[2] & 0x00FF); |
| olympux | 16:700377cd9d29 | 218 | u8RemoteTcpServerIpAddr[3] = (uint8_t)(u16RemoteTcpServerIpAddr[3] & 0x00FF); |
| olympux | 16:700377cd9d29 | 219 | |
| olympux | 18:d88314ae7979 | 220 | // Remote TCP server port |
| olympux | 16:700377cd9d29 | 221 | u16RemoteTcpServerPort = readEEPROMHalfWord(REMOTE_TCP_SERVER_PORT_POS); |
| olympux | 16:700377cd9d29 | 222 | |
| olympux | 16:700377cd9d29 | 223 | // Auto transmit |
| olympux | 16:700377cd9d29 | 224 | u16AutoTransmitFlag = readEEPROMHalfWord(AUTO_TRANSMIT_FLAG_POS); |
| olympux | 16:700377cd9d29 | 225 | u16TransmitPeriod = readEEPROMHalfWord(AUTO_TRANSMIT_TIME_PERIOD_POS); |
| olympux | 16:700377cd9d29 | 226 | |
| olympux | 18:d88314ae7979 | 227 | // Remote UDP server |
| olympux | 18:d88314ae7979 | 228 | u16RemoteUdpServerIpAddr[0] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*0); |
| olympux | 18:d88314ae7979 | 229 | u16RemoteUdpServerIpAddr[1] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*1); |
| olympux | 18:d88314ae7979 | 230 | u16RemoteUdpServerIpAddr[2] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*2); |
| olympux | 18:d88314ae7979 | 231 | u16RemoteUdpServerIpAddr[3] = readEEPROMHalfWord(REMOTE_UDP_SERVER_IP_ADDR_POS+2*3); |
| olympux | 18:d88314ae7979 | 232 | u8RemoteUdpServerIpAddr[0] = (uint8_t)(u16RemoteUdpServerIpAddr[0] & 0x00FF); |
| olympux | 18:d88314ae7979 | 233 | u8RemoteUdpServerIpAddr[1] = (uint8_t)(u16RemoteUdpServerIpAddr[1] & 0x00FF); |
| olympux | 18:d88314ae7979 | 234 | u8RemoteUdpServerIpAddr[2] = (uint8_t)(u16RemoteUdpServerIpAddr[2] & 0x00FF); |
| olympux | 18:d88314ae7979 | 235 | u8RemoteUdpServerIpAddr[3] = (uint8_t)(u16RemoteUdpServerIpAddr[3] & 0x00FF); |
| olympux | 18:d88314ae7979 | 236 | |
| olympux | 19:5671f3c25342 | 237 | // Remote UDP server port |
| olympux | 18:d88314ae7979 | 238 | u16RemoteUdpServerPort = readEEPROMHalfWord(REMOTE_UDP_SERVER_PORT_POS); |
| olympux | 18:d88314ae7979 | 239 | |
| olympux | 16:700377cd9d29 | 240 | // Enable modes |
| olympux | 16:700377cd9d29 | 241 | u16EnableTcpServer = readEEPROMHalfWord(ENABLE_TCP_SERVER_POS); |
| olympux | 16:700377cd9d29 | 242 | u16EnableTcpClient = readEEPROMHalfWord(ENABLE_TCP_CLIENT_POS); |
| olympux | 18:d88314ae7979 | 243 | u16EnableUdpServer = readEEPROMHalfWord(ENABLE_UDP_SERVER_POS); |
| olympux | 18:d88314ae7979 | 244 | u16EnableUdpClient = readEEPROMHalfWord(ENABLE_UDP_CLIENT_POS); |
| olympux | 16:700377cd9d29 | 245 | |
| olympux | 20:858384cac44a | 246 | // Serial inter-data period |
| olympux | 20:858384cac44a | 247 | u16InterDataPeriod = readEEPROMHalfWord(INTER_DATA_PERIOD_POS); |
| olympux | 20:858384cac44a | 248 | // Special character |
| olympux | 20:858384cac44a | 249 | u16SpecialChar = readEEPROMHalfWord(SPECIAL_CHAR_POS); |
| olympux | 20:858384cac44a | 250 | |
| olympux | 16:700377cd9d29 | 251 | sprintf(strIpAddr, "%d.%d.%d.%d", u8IpAddr[0], u8IpAddr[1], u8IpAddr[2], u8IpAddr[3]); |
| olympux | 16:700377cd9d29 | 252 | 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 | 253 | 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 | 254 | sprintf(strRemoteTcpServerIpAddr, "%d.%d.%d.%d", u8RemoteTcpServerIpAddr[0], u8RemoteTcpServerIpAddr[1], u8RemoteTcpServerIpAddr[2], u8RemoteTcpServerIpAddr[3]); |
| olympux | 18:d88314ae7979 | 255 | sprintf(strRemoteUdpServerIpAddr, "%d.%d.%d.%d", u8RemoteUdpServerIpAddr[0], u8RemoteUdpServerIpAddr[1], u8RemoteUdpServerIpAddr[2], u8RemoteUdpServerIpAddr[3]); |
| olympux | 17:574f90b11417 | 256 | sprintf(strMacAddr, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", u8MacAddr[0], u8MacAddr[1], u8MacAddr[2], u8MacAddr[3], u8MacAddr[4], u8MacAddr[5]); |
| olympux | 1:6bdc99dd8e0a | 257 | } |
| olympux | 8:4fc4b1b5509b | 258 | // if ip is not configured, use default addresses |
| olympux | 1:6bdc99dd8e0a | 259 | else { |
| olympux | 16:700377cd9d29 | 260 | INFO("No user settings, load defaults"); |
| olympux | 16:700377cd9d29 | 261 | u8MacAddr[0] = DEFAULT_MAC0; u8MacAddr[1] = DEFAULT_MAC1; u8MacAddr[2] = DEFAULT_MAC2; |
| olympux | 16:700377cd9d29 | 262 | u8MacAddr[3] = DEFAULT_MAC3; u8MacAddr[4] = DEFAULT_MAC4; u8MacAddr[5] = DEFAULT_MAC5; |
| olympux | 16:700377cd9d29 | 263 | sprintf(strIpAddr, DEFAULT_IP_ADDRESS); |
| olympux | 16:700377cd9d29 | 264 | sprintf(strIpSubnet, DEFAULT_IP_SUBNET); |
| olympux | 16:700377cd9d29 | 265 | sprintf(strIpGateway, DEFAULT_IP_GATEWAY); |
| olympux | 19:5671f3c25342 | 266 | sprintf(strMacAddr, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", u8MacAddr[0], u8MacAddr[1], u8MacAddr[2], u8MacAddr[3], u8MacAddr[4], u8MacAddr[5]); |
| olympux | 19:5671f3c25342 | 267 | |
| olympux | 19:5671f3c25342 | 268 | u16LocalTcpServerPort = DEFAULT_LOCAL_TCP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 269 | u16LocalUdpServerPort = DEFAULT_LOCAL_UDP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 270 | |
| olympux | 16:700377cd9d29 | 271 | sprintf(strRemoteTcpServerIpAddr, DEFAULT_REMOTE_TCP_SERVER_IP); |
| olympux | 19:5671f3c25342 | 272 | u16RemoteTcpServerPort = DEFAULT_REMOTE_TCP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 273 | |
| olympux | 18:d88314ae7979 | 274 | sprintf(strRemoteUdpServerIpAddr, DEFAULT_REMOTE_UDP_SERVER_IP); |
| olympux | 19:5671f3c25342 | 275 | u16RemoteUdpServerPort = DEFAULT_REMOTE_UDP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 276 | |
| olympux | 19:5671f3c25342 | 277 | u16AutoTransmitFlag = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 278 | u16TransmitPeriod = DEFAULT_TRANSMIT_PERIOD; |
| olympux | 19:5671f3c25342 | 279 | |
| olympux | 19:5671f3c25342 | 280 | u16EnableTcpServer = DEFAULT_ENABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 281 | u16EnableTcpClient = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 282 | u16EnableUdpServer = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 283 | u16EnableUdpClient = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 284 | |
| olympux | 20:858384cac44a | 285 | u16InterDataPeriod = DEFAULT_INTER_DATA_PERIOD; |
| olympux | 20:858384cac44a | 286 | u16SpecialChar = DEFAULT_SPECIAL_CHARACTER; |
| olympux | 20:858384cac44a | 287 | |
| olympux | 1:6bdc99dd8e0a | 288 | } |
| olympux | 1:6bdc99dd8e0a | 289 | |
| olympux | 16:700377cd9d29 | 290 | INFO("Successful"); |
| olympux | 16:700377cd9d29 | 291 | INFO("IP: %s", strIpAddr); |
| olympux | 16:700377cd9d29 | 292 | INFO("MASK: %s", strIpSubnet); |
| olympux | 16:700377cd9d29 | 293 | INFO("GW: %s", strIpGateway); |
| olympux | 16:700377cd9d29 | 294 | INFO("TCP server local port: %d", u16LocalTcpServerPort); |
| olympux | 18:d88314ae7979 | 295 | INFO("UDP server local port: %d", u16LocalUdpServerPort); |
| olympux | 18:d88314ae7979 | 296 | |
| olympux | 18:d88314ae7979 | 297 | INFO("Remote TCP server: %s", strRemoteTcpServerIpAddr); |
| olympux | 18:d88314ae7979 | 298 | INFO("Remote TCP server port: %d", u16RemoteTcpServerPort); |
| olympux | 18:d88314ae7979 | 299 | |
| olympux | 18:d88314ae7979 | 300 | INFO("Remote UDP server: %s", strRemoteUdpServerIpAddr); |
| olympux | 18:d88314ae7979 | 301 | INFO("Remote UDP server port: %d", u16RemoteUdpServerPort); |
| olympux | 18:d88314ae7979 | 302 | |
| olympux | 18:d88314ae7979 | 303 | INFO("Auto transmit: %s", (u16AutoTransmitFlag == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable"); |
| olympux | 18:d88314ae7979 | 304 | INFO("Period: %d", u16TransmitPeriod); |
| olympux | 16:700377cd9d29 | 305 | |
| olympux | 16:700377cd9d29 | 306 | INFO("TCP server: %s", (u16EnableTcpServer == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable"); |
| olympux | 16:700377cd9d29 | 307 | INFO("TCP client: %s", (u16EnableTcpClient == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable"); |
| olympux | 18:d88314ae7979 | 308 | INFO("UDP server: %s", (u16EnableUdpServer == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable"); |
| olympux | 18:d88314ae7979 | 309 | INFO("UDP client: %s", (u16EnableUdpClient == DEFAULT_ENABLE_FLAG_VALUE) ? "enabled" : "disable"); |
| olympux | 20:858384cac44a | 310 | |
| olympux | 20:858384cac44a | 311 | INFO("Serial inter-data period: %d", u16InterDataPeriod); |
| olympux | 20:858384cac44a | 312 | INFO("Special character: %.2x", u16SpecialChar); |
| olympux | 1:6bdc99dd8e0a | 313 | } |
| olympux | 1:6bdc99dd8e0a | 314 | |
| olympux | 19:5671f3c25342 | 315 | void reset_default_device_configuration() { |
| olympux | 19:5671f3c25342 | 316 | uint16_t ip[4] = {192,168,0,120}; |
| olympux | 19:5671f3c25342 | 317 | uint16_t subnet[4] = {255,255,255,0}; |
| olympux | 19:5671f3c25342 | 318 | uint16_t gateway[4] = {192,168,0,1}; |
| olympux | 19:5671f3c25342 | 319 | uint16_t mac[3] = {u8MacAddr[3],u8MacAddr[4],u8MacAddr[5]}; |
| olympux | 19:5671f3c25342 | 320 | |
| olympux | 19:5671f3c25342 | 321 | uint16_t tcp_port = DEFAULT_LOCAL_TCP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 322 | uint16_t udp_port = DEFAULT_LOCAL_UDP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 323 | |
| olympux | 19:5671f3c25342 | 324 | uint16_t remote_tcp_ip[4] = {192,168,0,2}; |
| olympux | 19:5671f3c25342 | 325 | uint16_t remote_tcp_port = DEFAULT_REMOTE_TCP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 326 | |
| olympux | 19:5671f3c25342 | 327 | uint16_t remote_udp_ip[4] = {192,168,0,2}; |
| olympux | 19:5671f3c25342 | 328 | uint16_t remote_udp_port = DEFAULT_REMOTE_UDP_SERVER_PORT; |
| olympux | 19:5671f3c25342 | 329 | |
| olympux | 19:5671f3c25342 | 330 | uint16_t auto_transmit = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 331 | uint16_t transmit_period = DEFAULT_TRANSMIT_PERIOD; |
| olympux | 19:5671f3c25342 | 332 | |
| olympux | 19:5671f3c25342 | 333 | uint16_t enable_tcp_server = DEFAULT_ENABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 334 | uint16_t enable_tcp_client = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 335 | uint16_t enable_udp_server = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 336 | uint16_t enable_udp_client = DEFAULT_DISABLE_FLAG_VALUE; |
| olympux | 19:5671f3c25342 | 337 | |
| olympux | 20:858384cac44a | 338 | uint16_t inter_data_period = DEFAULT_INTER_DATA_PERIOD; |
| olympux | 20:858384cac44a | 339 | uint16_t special_char = DEFAULT_SPECIAL_CHARACTER; |
| olympux | 20:858384cac44a | 340 | |
| olympux | 19:5671f3c25342 | 341 | // erase the device configured flag |
| olympux | 19:5671f3c25342 | 342 | erase_device_configuration(); |
| olympux | 19:5671f3c25342 | 343 | |
| olympux | 19:5671f3c25342 | 344 | // write new one |
| olympux | 19:5671f3c25342 | 345 | write_device_configuration(ip, subnet, gateway, mac, |
| olympux | 19:5671f3c25342 | 346 | tcp_port, udp_port, |
| olympux | 19:5671f3c25342 | 347 | remote_tcp_ip, remote_tcp_port, auto_transmit, transmit_period, |
| olympux | 19:5671f3c25342 | 348 | remote_udp_ip, remote_udp_port, |
| olympux | 20:858384cac44a | 349 | enable_tcp_server, enable_tcp_client, enable_udp_server, enable_udp_client, |
| olympux | 20:858384cac44a | 350 | inter_data_period, special_char); |
| olympux | 1:6bdc99dd8e0a | 351 | } |
