tax.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * @Description:
  3. * @Version: 2.0
  4. * @Author: Seven
  5. * @Date: 2023-09-08 09:08:43
  6. * @LastEditors: Seven
  7. * @LastEditTime: 2024-04-07 15:24:46
  8. */
  9. #ifndef TAX_H__
  10. #define TAX_H__
  11. #include "stm32f10x.h"
  12. #include "tools.h"
  13. #define SINGLE_DATA 0 //当次交易
  14. #define CUMULATIVE_DATA 1 //总累计
  15. ////////////////////////////////////明文///////////////////////////////////////////////////
  16. //协议头
  17. typedef struct _tTaxCommFrame
  18. {
  19. //前导码+长度码 千帧号+命令码 +参数 +校验码
  20. uint8_t fhead; //帧头(1Byte)
  21. uint8_t flen; //帧长度(1Byte)
  22. uint8_t findex; //帧序号(1Byte)
  23. uint8_t fcmd; //命令码(1Byte)
  24. // uint16_t fcrc; //CRC校验(2Byte)
  25. }tTaxCommFrame_t;
  26. //////////////////////////////////////密文/////////////////////////////////////////////////
  27. #define YTSF_0XA2_0X00 0xA2
  28. #define YTSF_0XA1_0X11 0xA1
  29. #define YTSF_0XA1_0X14 0xA4
  30. //协议头
  31. typedef struct _tYTSFCommFrame
  32. {
  33. uint8_t fhead; //帧头(1Byte)
  34. uint8_t flen; //帧长度(1Byte)
  35. uint8_t findex; //帧序号(1Byte)
  36. uint8_t fport; //税控口编号(1Byte),0税控口1,1税控口2
  37. uint8_t fcmd; //命令码(1Byte)
  38. // uint16_t fcrc; //CRC校验(2Byte)
  39. }tYTSFCommFrame_t;
  40. typedef struct _gun_info {
  41. uint8_t fail_count;
  42. uint8_t quality; //油品
  43. uint8_t id; //编号
  44. uint8_t status; //工作状态
  45. uint64_t total_price; //总累计金额
  46. uint64_t total_oil_volume; //总体积
  47. uint32_t last_unit_price; //最后一次加油的单价
  48. uint32_t last_oil_volume; //最后一次加油的油量
  49. uint32_t last_price; //最后一次加油的油价
  50. uint8_t gun_type; //加油枪的数据类型:0当次数据;1 累计数据
  51. uint32_t gun_msgid; //加油枪序列号
  52. uint8_t time_day;
  53. uint8_t time_hour;
  54. uint8_t time_minute;
  55. }__attribute__((packed)) gun_info_t;
  56. typedef struct _tax_info {
  57. uint8_t monitor_serino[16];
  58. uint8_t coder_serino[20];
  59. uint8_t dispaly_serino[16];
  60. uint8_t gun_num;
  61. uint8_t factory; /* 1: 英泰赛福 2: 拓盛 */
  62. uint8_t fail_count;
  63. uint8_t status;
  64. uint8_t gun_valid;
  65. uint8_t taxpayer_reg_no[20];
  66. gun_info_t gun[8];
  67. uint8_t cmd_73_data[4];
  68. uint8_t tax_serino[10];
  69. uint8_t bmq_serino[10];
  70. uint8_t data73len; // 73指令的长度
  71. //for debug
  72. uint32_t tx_pkts;
  73. uint32_t rx_pkts;
  74. uint32_t rx_errs;
  75. }__attribute__((packed)) tax_info_t ;
  76. extern tax_info_t tax_info;
  77. ///////////////////////////////////////////////////////////////////////////////
  78. typedef enum{
  79. TAX_GUN_LP_STATE_IDLE=0, //空闲状态
  80. TAX_GUN_LP_STATE_83, //读取83指令,读取的是采集器有关的信息,上电读取一次就可以
  81. TAX_GUN_LP_STATE_89, //总金额和总油量
  82. TAX_GUN_LP_STATE_86, //单价 当次金额和当次油量
  83. TAX_GUN_LP_STATE_CH, //切换采集器 枪 或是报税口
  84. TAX_GUN_LP_STATE_FINISH, //完成
  85. TAX_GUN_LP_STATE_UNKNOWN
  86. }tTaxGunLpState_t;
  87. #define TAX_MAX_NUM 2
  88. #define GUN_MAX_NUM 8
  89. //枪数据
  90. typedef struct _gun_conf
  91. {
  92. uint8_t gunid; //加油枪编号
  93. uint16_t unit_price; //单价
  94. uint32_t price; //金额
  95. uint32_t volume; //油量
  96. uint64_t totle_price; //总金额
  97. uint64_t totle_volume; //总油量
  98. timeout_t tt_ts; //拓盛密文定时
  99. }__attribute__((packed)) gun_conf_t;
  100. //报税口数据
  101. typedef struct _tax_conf
  102. {
  103. uint8_t tax_id; //报税口编号
  104. uint8_t gun_num; //加油枪数量
  105. uint8_t alrd_sn; //是否查询过加油机的信息
  106. uint8_t factory; //厂家 1:英泰 2:拓盛
  107. uint8_t status; //报税口的状态,是否连接
  108. uint8_t encrypt; //报税口的加密状态,由服务器下发,暂没有用到
  109. uint8_t monitor_serino[16]; //税控序列号
  110. gun_conf_t gun_conf[GUN_MAX_NUM]; //枪信息
  111. }__attribute__((packed)) tax_conf_t;
  112. //采集器数据
  113. typedef struct _coll_tax_conf
  114. {
  115. uint8_t tax_num; //报税口数量
  116. uint8_t tax_type; //报税口类型,明文或密文
  117. uint8_t cmd_83; //是否需要读83
  118. tax_conf_t tax_conf[TAX_MAX_NUM]; //报税口信息
  119. }__attribute__((packed)) coll_tax_conf_t;
  120. extern coll_tax_conf_t coll_tax_conf;
  121. typedef struct _tax_read_info_t
  122. {
  123. uint8_t tax_no; //当前查询的报税口编号
  124. uint8_t cmd_no; //当前查询的命令编号
  125. uint8_t read_flag; //是否开始查询
  126. uint8_t uart_flag; //串口定时是否结束
  127. uint8_t cmd_flag; //命令间隔是否结束
  128. timeout_t tt_cmd_time; //命令查询间隔
  129. timeout_t tt_uart; //命令返回超时
  130. }__attribute__((packed)) tax_read_info_t;
  131. typedef struct _tax_send_info
  132. {
  133. uint8_t start;
  134. uint8_t step;
  135. uint8_t send;
  136. uint8_t cmd;
  137. uint8_t gun;
  138. uint8_t uartid;
  139. uint8_t startcmd;
  140. //timeout_t tt_rcv;
  141. uint8_t dalen;
  142. uint8_t data[32];
  143. }tax_send_info_t;
  144. extern tax_send_info_t tax_send_info;
  145. enum {
  146. CMD_72=0,
  147. CMD_73,
  148. CMD_70,
  149. CMD_8C,
  150. CMD_86,
  151. };
  152. extern void tax_send_start(uint8_t startCmd);
  153. extern void tax_send_end(void);
  154. uint16_t tax_send_cmd(uint8_t cmd, uint8_t gun, void *purse);
  155. extern uint16_t tax_send_cmd_ciphertext(uint8_t cmd, uint8_t *data, uint8_t len, void *purse);
  156. extern int tax_rcv_analyze(uint8_t *data, void *puser, uint16_t len);
  157. void tax_test(void);
  158. #endif // !