#ifndef __NET_CTRL_H__
#define __NET_CTRL_H__

#include "stm32f10x.h"
#include "../gateway_collect/gateway_collect.h"

enum {
    SEND_DATA_NORMAL = 0x01, //正常数据
    SEND_DATA_LOG    = 0x02, //异常数据
};

#define COLLECT_PARA_NUM 6
#define TAX_PARA_NUM     53

#define SINGLE_DATA      0
#define CUMULATIVE_DATA  1

#define COLLECT_COM   94

extern uint8_t net_send_buf[256],net_send_len;
extern uint8_t net_seng_state;
extern uint8_t net_rcv_data[512];
extern uint16_t net_rcv_len;
extern uint8_t net_rcv_state;

typedef struct _guns_info
{
	uint8_t gun_number;
	uint8_t gun_status;
	uint8_t gun_type;
	uint32_t gun_msgid;
	uint32_t total_price;
	uint32_t total_oil_volume;
	uint32_t last_unit_price;
	uint32_t last_oil_volume;
	uint32_t last_price;
}__attribute__((packed)) guns_info_t;


typedef struct _tax_control_info
{
	uint8_t monitor_serino[16];
	uint8_t coder_serino[20];
	uint8_t dispaly_serino[16];
	uint8_t gun_count;
	guns_info_t guns_info;
}__attribute__((packed)) tax_control_info_t;

typedef struct _tax_comm_info
{
	uint32_t device_type;
	uint32_t device_id;
	uint8_t device_status;
	uint8_t tax_control_count;
	tax_control_info_t tax_control_info;
	uint32_t collect_time;
}__attribute__((packed)) tax_comm_info_t;

//采集器参数
typedef struct _collect_para
{
	uint32_t device_id;
	uint8_t device_status;
	uint8_t tax_control_count;
}__attribute__((packed)) collect_para_t;


//税控口参数
typedef struct _tax_para
{
	uint8_t tax_serino[16];
	uint8_t coder_serino[20];
	uint8_t dispaly_serino[16];
	uint8_t gun_count;
}__attribute__((packed)) tax_para_t;

extern int tax_net_send(uint8_t *tx_data, uint8_t len, uint8_t typeFirst, uint16_t typeSecd);
extern int tax_net_send_0x01_0x1052(uint8_t *tx_data, uint8_t len);

extern void gw_net_comm_test(void);
extern int air_mqtt_pub(char *topic, char *data, uint8_t len);
extern void gw_net_send(char *data, uint32_t len);
extern void gw_net_send_logDa(char *data, uint32_t len);

extern uint16_t crc16_get(uint8_t *data, uint8_t size);
extern unsigned char HexToChar(unsigned char bChar);

extern void net_msg_recv1(void);
extern int net_rcvdata_ch(char *data, uint8_t *out_data, int len);
extern int net_data_copy(char *data, uint8_t *out_data);
extern int tax_net_send_log(uint8_t *tx_data, uint8_t len);

extern int tax_net_data_analyze(void *puser,uint8_t collect, uint8_t tax, uint8_t *outdata, uint8_t *len);
extern void serino_init(void);

extern void gateway_update_status_rcv(gateway_collect_com_t *data, uint32_t len);

#endif

