Chau Vo / device_configuration

Dependents:   F103-Web-Server

Fork of my_eeprom_funcs by Chau Vo

my_eeprom_funcs.h

Committer:
olympux
Date:
2015-01-10
Revision:
11:250b05a5266d
Parent:
10:f37acffddef9
Child:
12:613ab276bf37

File content as of revision 11:250b05a5266d:

#ifndef __MY_EEPROM_FUNCS_H
#define __MY_EEPROM_FUNCS_H

#include "eeprom.h"


/*
* Default device network configuration
*/
#define DEFAULT_IP_ADDRESS      "192.168.0.249"
#define DEFAULT_IP_SUBNET       "255.255.255.0"
#define DEFAULT_IP_GATEWAY      "192.168.0.1"
#define DEFAULT_MAC0            0x00
#define DEFAULT_MAC1            0x08
#define DEFAULT_MAC2            0xDC
#define DEFAULT_MAC3            0x00
#define DEFAULT_MAC4            0x00
#define DEFAULT_MAC5            0x01

#define DEFAULT_ENABLE_FLAG_VALUE   0xA5A5
#define DEFAULT_DISABLE_FLAG_VALUE  0xAAAA

/*
* Positions of variables in EEPROM array
*/
#define IP_ADDRESS_POS         0
#define IP_SUBNET_POS          4
#define IP_GATEWAY_POS         8
#define TCP_SERVER_LOCAL_PORT_POS   12
#define UDP_SERVER_LOCAL_PORT_POS   13
#define CONFIGURED_IP_FLAG_POS      14
#define MAC_ADDRESS_POS        15
// EEPROM: for setting TCP server where this device connects to in TCP client mode
#define AUTO_TRANSMIT_FLAG_POS  18
#define AUTO_TRANSMIT_TIME_PERIOD_POS    19
#define TCP_SERVER_IP_ADDR_POS  20
#define TCP_SERVER_PORT_POS     24
#define ENABLE_TCP_SERVER       25
#define ENABLE_TCP_CLIENT       26
#define ENABLE_UDP_SERVER       27


/*
* External variables in main.c
*/
extern uint16_t VirtAddVarTab[];

extern uint8_t u8mac[], u8ip_addr[];// keep mac and ip address in 8-bits
extern uint16_t u16mac_addr[], u16ip_addr[], u16ip_subnet[], u16ip_gateway[]; // 16-bits, directly loaded from eeprom
extern char str_ip_addr[], str_ip_subnet[], str_ip_gateway[]; // for printf, converted from 16-bits u16ip_xxx
extern uint16_t configured_ip;  // first run flag

extern const uint16_t tcp_server_local_port; // fixed
extern const uint16_t udp_server_local_port; // fixed

// this section is for the TCP server that this device connects to in TCP client mode
extern uint16_t auto_transmit_flag, transmit_time_period; // auto transmit status, time period = 1s
extern uint8_t u8server_ip_addr[];
extern uint16_t u16server_ip_addr[]; // directly loaded from eeprom
extern uint16_t u16tcp_server_port; // directly loaded from eeprom
extern char * server_ip_addr;
extern char str_server_ip_addr[];
extern uint16_t u16enable_tcp_client, u16enable_tcp_server;// flags for enabling TCP client or TCP server


/*!
 * Function to write module network configuration
 * @param <char *buf> configuration buffer
 * @note 4-byte IP address
 * @note 4-byte subnet
 * @note 4-byte gateway
 * @note 3-byte MAC
 */
void write_eeprom_network(char* buf);
void load_eeprom_network(void);
void write_eeprom_tcpserver(char* buf);
void load_eeprom_tcpserver(void);

#endif