#ifndef __NET_CTRL_H__
#define __NET_CTRL_H__

#include "stm32f10x.h"

#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[1024],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, uint16_t len, uint8_t typeFirst, uint16_t typeSecd);

void gw_net_comm_test(void);
int air_mqtt_pub(char *topic, char *data, uint8_t len);
void gw_net_send(char *data, uint32_t len);
uint16_t crc16_get(uint8_t *data, uint8_t size);

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

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

