You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
3.6 KiB
C
173 lines
3.6 KiB
C
#ifndef __PD_NET_H__
|
|
#define __PD_NET_H__
|
|
|
|
#ifdef CFG_DEV_TYPE_LAND_PD
|
|
#define NET_CONFIG "CSG PARAM CONFIG"
|
|
#define NET_FIFO_PRPS "NET_FIFO_PRPS"
|
|
#define NET_FIFO_EVENT "NET_FIFO_EVENT"
|
|
#define NET_FIFO_TREND "NET_FIFO_TREND"
|
|
#define PRPS_FIFO_NUM (16)
|
|
#define EVENT_FIFO_NUM (16)
|
|
#define TREND_FIFO_NUM (8)
|
|
|
|
#define NET_PKT_LEN (1300)
|
|
|
|
#define NET_START (0x68)
|
|
#define NET_END (0x16)
|
|
#define NET_FIX_LEN (12)
|
|
#define NET_HEADER_LEN (10)
|
|
#define NET_ADJUST_TIMEOUT (20)
|
|
#define NET_SYNC_HOUR (1)
|
|
#define NET_CONTACT_TIME (60)
|
|
#define NET_ADJUST_TIME (120)
|
|
#define NET_DISCONNECT_TIME (5)
|
|
#define NET_CONNECT_TIME_CNT (60)
|
|
#define NET_SEND_TIMEOUT (2)
|
|
#define NET_SEND_ERR_CNT (3)
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
/* 报文头结构. */
|
|
typedef struct{
|
|
uint8_t start_code;
|
|
uint8_t device_id[6];
|
|
uint8_t cmd;
|
|
uint16_t length;
|
|
} net_pkt_head_t;
|
|
#pragma pack(pop)
|
|
|
|
// 定义命令字常量
|
|
typedef enum {
|
|
CMD_CONTACT = 0x00,
|
|
CMD_TIME_ADJ = 0x01,
|
|
CMD_SET_PW = 0x02,
|
|
CMD_SET_PARMA = 0x03,
|
|
CMD_HEARTBEAT = 0x05,
|
|
CMD_RESET = 0x08,
|
|
CMD_GIS_DATA = 0x46,
|
|
CMD_INVALID
|
|
} command_type;
|
|
|
|
// 定义函数指针类型
|
|
typedef void (*command_handler)(char *data);
|
|
|
|
// 定义命令结构体
|
|
typedef struct {
|
|
command_type cmd; // 命令字
|
|
command_handler handler; // 处理函数
|
|
} command_entry;
|
|
|
|
#pragma pack(push, 1)
|
|
typedef struct {
|
|
uint8_t major;
|
|
uint8_t minor;
|
|
} net_ver_t;
|
|
|
|
typedef struct {
|
|
uint8_t year;
|
|
uint8_t month;
|
|
uint8_t day;
|
|
uint8_t hour;
|
|
uint8_t minute;
|
|
uint8_t second;
|
|
} net_time_t;
|
|
|
|
typedef struct {
|
|
net_time_t time;
|
|
uint8_t signal;
|
|
uint8_t vol;
|
|
} net_heartbeat_t;
|
|
|
|
typedef struct {
|
|
char old[4];
|
|
char new[4];
|
|
} net_passwd_t;
|
|
|
|
typedef struct {
|
|
uint8_t day;
|
|
uint8_t hour;
|
|
uint8_t min;
|
|
} reset_time_t;
|
|
|
|
typedef struct {
|
|
char passwd[4];
|
|
uint8_t heart_interval;
|
|
uint16_t collect_interval;
|
|
uint16_t sleep_time;
|
|
uint16_t online_time;
|
|
reset_time_t reset_time;
|
|
char verify[4];
|
|
} net_param_t;
|
|
|
|
typedef struct {
|
|
uint8_t discharge_type;
|
|
uint16_t capacity;
|
|
uint16_t noise;
|
|
uint16_t avg;
|
|
uint16_t max;
|
|
uint16_t cnt;
|
|
uint16_t relation50;
|
|
uint16_t relation100;
|
|
} net_gis_data_t;
|
|
|
|
typedef struct {
|
|
char verify[4];
|
|
uint8_t index;
|
|
uint8_t pack_num;
|
|
uint8_t unit;
|
|
} net_gis_head_t;
|
|
|
|
typedef struct {
|
|
uint8_t index;
|
|
uint16_t fix;
|
|
} net_gis_reply_t;
|
|
|
|
typedef struct {
|
|
uint8_t mday;
|
|
uint8_t hour;
|
|
uint8_t min;
|
|
} net_reset_time_t;
|
|
|
|
typedef struct {
|
|
char passwd[4];
|
|
uint8_t heartbeat_interval;
|
|
uint16_t collect_interval;
|
|
uint16_t sleep_time;
|
|
uint16_t online_time;
|
|
net_reset_time_t reset_time;
|
|
char verify[4];
|
|
} net_config_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
typedef struct {
|
|
int skfd; // 后台通讯使用的 socket.
|
|
uint8_t is_connect; // 是否连接上服务器.
|
|
int32_t fifo_prps_id; // 实时图谱 fifo
|
|
int32_t fifo_event_id; // 事件 fifo
|
|
int32_t fifo_trend_id; // 趋势 fifo
|
|
char buf_send[1500];
|
|
char buf_recv[1500];
|
|
struct sockaddr_in server;
|
|
int32_t server_ip; // server ip.
|
|
uint16_t server_port; // server port.
|
|
time_t heartbeat_timeout;
|
|
int32_t heartbeat_timeout_cnt;
|
|
uint8_t is_time_adjust;
|
|
uint8_t last_sync_day;
|
|
uint8_t last_sync_mon;
|
|
net_config_t config;
|
|
uint8_t trend_snd_idx;
|
|
sem_t trend_sem;
|
|
} net_t;
|
|
|
|
net_t net;
|
|
|
|
int32_t net_handle_init(void);
|
|
int32_t _net_handle_init_common(void);
|
|
int32_t net_handle_init_after(void);
|
|
#endif
|
|
|
|
#endif
|
|
|