| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /*
- * @Description:
- * @Version: 2.0
- * @Author: Seven
- * @Date: 2023-09-08 09:08:43
- * @LastEditors: Seven
- * @LastEditTime: 2024-04-07 15:24:46
- */
- #ifndef TAX_H__
- #define TAX_H__
- #include "stm32f10x.h"
- #include "tools.h"
- #define SINGLE_DATA 0 //当次交易
- #define CUMULATIVE_DATA 1 //总累计
- ////////////////////////////////////明文///////////////////////////////////////////////////
- //协议头
- typedef struct _tTaxCommFrame
- {
- //前导码+长度码 千帧号+命令码 +参数 +校验码
- uint8_t fhead; //帧头(1Byte)
- uint8_t flen; //帧长度(1Byte)
- uint8_t findex; //帧序号(1Byte)
- uint8_t fcmd; //命令码(1Byte)
- // uint16_t fcrc; //CRC校验(2Byte)
- }tTaxCommFrame_t;
- //////////////////////////////////////密文/////////////////////////////////////////////////
- #define YTSF_0XA2_0X00 0xA2
- #define YTSF_0XA1_0X11 0xA1
- #define YTSF_0XA1_0X14 0xA4
- //协议头
- typedef struct _tYTSFCommFrame
- {
- uint8_t fhead; //帧头(1Byte)
- uint8_t flen; //帧长度(1Byte)
- uint8_t findex; //帧序号(1Byte)
- uint8_t fport; //税控口编号(1Byte),0税控口1,1税控口2
- uint8_t fcmd; //命令码(1Byte)
- // uint16_t fcrc; //CRC校验(2Byte)
- }tYTSFCommFrame_t;
- typedef struct _gun_info {
- uint8_t fail_count;
- uint8_t quality; //油品
- uint8_t id; //编号
- uint8_t status; //工作状态
- uint64_t total_price; //总累计金额
- uint64_t total_oil_volume; //总体积
- uint32_t last_unit_price; //最后一次加油的单价
- uint32_t last_oil_volume; //最后一次加油的油量
- uint32_t last_price; //最后一次加油的油价
- uint8_t gun_type; //加油枪的数据类型:0当次数据;1 累计数据
- uint32_t gun_msgid; //加油枪序列号
- uint8_t time_day;
- uint8_t time_hour;
- uint8_t time_minute;
- }__attribute__((packed)) gun_info_t;
- typedef struct _tax_info {
- uint8_t monitor_serino[16];
- uint8_t coder_serino[20];
- uint8_t dispaly_serino[16];
- uint8_t gun_num;
- uint8_t factory; /* 1: 英泰赛福 2: 拓盛 */
- uint8_t fail_count;
- uint8_t status;
- uint8_t gun_valid;
- uint8_t taxpayer_reg_no[20];
- gun_info_t gun[8];
- uint8_t cmd_73_data[4];
- uint8_t tax_serino[10];
- uint8_t bmq_serino[10];
- uint8_t data73len; // 73指令的长度
- //for debug
- uint32_t tx_pkts;
- uint32_t rx_pkts;
- uint32_t rx_errs;
- }__attribute__((packed)) tax_info_t ;
- extern tax_info_t tax_info;
- ///////////////////////////////////////////////////////////////////////////////
- typedef enum{
- TAX_GUN_LP_STATE_IDLE=0, //空闲状态
- TAX_GUN_LP_STATE_83, //读取83指令,读取的是采集器有关的信息,上电读取一次就可以
- TAX_GUN_LP_STATE_89, //总金额和总油量
- TAX_GUN_LP_STATE_86, //单价 当次金额和当次油量
- TAX_GUN_LP_STATE_CH, //切换采集器 枪 或是报税口
- TAX_GUN_LP_STATE_FINISH, //完成
- TAX_GUN_LP_STATE_UNKNOWN
- }tTaxGunLpState_t;
- #define TAX_MAX_NUM 2
- #define GUN_MAX_NUM 8
- //枪数据
- typedef struct _gun_conf
- {
- uint8_t gunid; //加油枪编号
- uint16_t unit_price; //单价
- uint32_t price; //金额
- uint32_t volume; //油量
- uint64_t totle_price; //总金额
- uint64_t totle_volume; //总油量
- timeout_t tt_ts; //拓盛密文定时
- }__attribute__((packed)) gun_conf_t;
- //报税口数据
- typedef struct _tax_conf
- {
- uint8_t tax_id; //报税口编号
- uint8_t gun_num; //加油枪数量
- uint8_t alrd_sn; //是否查询过加油机的信息
- uint8_t factory; //厂家 1:英泰 2:拓盛
- uint8_t status; //报税口的状态,是否连接
- uint8_t encrypt; //报税口的加密状态,由服务器下发,暂没有用到
- uint8_t monitor_serino[16]; //税控序列号
- gun_conf_t gun_conf[GUN_MAX_NUM]; //枪信息
- }__attribute__((packed)) tax_conf_t;
- //采集器数据
- typedef struct _coll_tax_conf
- {
- uint8_t tax_num; //报税口数量
- uint8_t tax_type; //报税口类型,明文或密文
- uint8_t cmd_83; //是否需要读83
- tax_conf_t tax_conf[TAX_MAX_NUM]; //报税口信息
- }__attribute__((packed)) coll_tax_conf_t;
- extern coll_tax_conf_t coll_tax_conf;
- typedef struct _tax_read_info_t
- {
- uint8_t tax_no; //当前查询的报税口编号
- uint8_t cmd_no; //当前查询的命令编号
- uint8_t read_flag; //是否开始查询
- uint8_t uart_flag; //串口定时是否结束
- uint8_t cmd_flag; //命令间隔是否结束
- timeout_t tt_cmd_time; //命令查询间隔
- timeout_t tt_uart; //命令返回超时
- }__attribute__((packed)) tax_read_info_t;
- typedef struct _tax_send_info
- {
- uint8_t start;
- uint8_t step;
- uint8_t send;
- uint8_t cmd;
- uint8_t gun;
- uint8_t uartid;
- uint8_t startcmd;
- //timeout_t tt_rcv;
- uint8_t dalen;
- uint8_t data[32];
- }tax_send_info_t;
- extern tax_send_info_t tax_send_info;
- enum {
- CMD_72=0,
- CMD_73,
- CMD_70,
- CMD_8C,
- CMD_86,
- };
- extern void tax_send_start(uint8_t startCmd);
- extern void tax_send_end(void);
- uint16_t tax_send_cmd(uint8_t cmd, uint8_t gun, void *purse);
- extern uint16_t tax_send_cmd_ciphertext(uint8_t cmd, uint8_t *data, uint8_t len, void *purse);
- extern int tax_rcv_analyze(uint8_t *data, void *puser, uint16_t len);
- void tax_test(void);
- #endif // !
|