| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- /*
- * @Description:
- * @Version: 2.0
- * @Author: Seven
- * @Date: 2022-08-22 17:13:45
- * @LastEditors: Seven
- * @LastEditTime: 2023-04-28 16:58:15
- */
- #ifndef __ENCODER_H__
- #define __ENCODER_H__
- #include "stm32f10x.h"
- #include "tools.h"
- #define EEPROM_ENCODER_TAX1_ADDR 0x80 //编码器总脉冲存储地址(第三页)
- #define EEPROM_ENCODER_TAX2_ADDR 0x100 //编码器总脉冲存储地址(第五页)
- #define EEPROM_ENCODER_TAX1_GUNNUM_ADDR 0x200 //编码器空抬枪次数存储地址(第九页)
- #define EEPROM_ENCODER_TAX2_GUNNUM_ADDR 0x240 //编码器空抬枪次数存储地址(第十页)
- #define ENCODER_TAX_NUM 2 //报税口个数
- #define ENCODER_GUN_NUM 2 //一个报税口下枪的个数
- #define TAX1 0
- #define TAX2 1
- #define GUN1 0
- #define GUN2 1
- #define GUN3 2
- #define GUN4 3
- #define ENCODER_SAVE_GROUP_NUM 16 //脉冲数据存储的最大组数
- #define GUN_GPIO 0 //枪
- #define PULSE_GPIO 1 //脉冲
- #define GUNSIGNAL_IRQ_TIME (100)//(10) //抬枪信号中断消抖延时,单位ms
- #define PULSE_IRQ_TIME (1000)//(500) //脉冲信号中断消抖延时,单位us
- #define GUNUP_NUM_IRQ_TIME (200) //抬枪次数中断消抖,单位ms
- #define GUN_UP 1 //抬枪
- #define GUN_DOWN 0 //挂枪
- #define GUN_SIGNAL_ENABLE 0 //抬枪信号有效
- #define GUN_SIGNAL_DISABLE 1 //抬枪信号无效
- #define PULSE_NOGUN_END_TIME (5*1000) //无抬枪信号是判断脉冲结束的时间间隔
- #define PULSE_GUN_END_TIME (5*60*1000) //有抬枪信号是判断脉冲结束的时间间隔
- #define PULSE_END_MODE_GUN 1 //抬枪信号产生的记录
- #define PULSE_END_MODE_LOGIC 0 //逻辑判断产生的记录
- #define GUN_NUM_TIME (3*1000) //抬枪信号定时时间
- /*接口配置数据结构*/
- typedef struct _GPIO_TypeDef_t
- {
- GPIO_TypeDef* GPIOx;
- uint16_t GPIO_Pin;
- uint32_t EXTI_Line;
- }GPIO_TypeDef_t;
- //枪引脚信息
- typedef struct _gun_gpio_info_t
- {
- GPIO_TypeDef_t pulse;
- GPIO_TypeDef_t gunsignal;
- }gun_gpio_info_t;
- //中断线对应信息
- typedef struct _exti_info_t
- {
- uint8_t tax;
- uint8_t gun;
- uint8_t mode;
- uint32_t timeout;
- }exti_info_t;
- //中断线
- enum {
- EXTI_LINE6 = 0,
- EXTI_LINE12,
- EXTI_LINE7,
- EXTI_LINE13,
- EXTI_LINE10,
- EXTI_LINE14,
- EXTI_LINE9,
- EXTI_LINE15,
- EXTI_LINE_MAX,
- };
- extern exti_info_t exti_info[EXTI_LINE_MAX];
- //脉冲上报信息存储
- typedef struct _pulse_up_info_t
- {
- uint32_t id; //记录id
- uint8_t pulse_mode; //产生记录方式
- uint32_t single_pulse_num; //单次脉冲个数
- uint32_t total_pulse_num; //总脉冲数
- uint32_t time; //时间戳
- }__attribute__((packed)) pulse_up_info_t;
- //编码器中断信息
- typedef struct _encoder_irq_info_t
- {
- uint8_t last_level; //上次有效电平
- uint8_t current_level; //当次有效电平
- uint8_t gun_signal_is_work; //抬枪信号是否有效(0:有效;1:无效)
- uint8_t gun_down_irq; //挂枪中断标记
- timeout_t wave_time; //中断消抖定时
- }encoder_irq_info_t;
- //脉冲计数信息
- typedef struct _encoder_count_info_t
- {
- uint8_t eeprom_write_flag; //写eeprom标记
- uint8_t gun_signal; //枪信号状态
- uint32_t pulse_count; //脉冲计数
- uint8_t write_group; //写入的组号
- uint32_t write_id; //写入的记录id
- uint8_t read_group; //读取的组号
- uint32_t read_id; //读取的记录id
- uint32_t record_id; //记录id
- uint32_t record_time; //记录每次交易产生时间
- uint8_t read_first_valie; //第一次有效读取
- uint32_t gunup_num; //空抬枪次数
- uint8_t eeprom_write_gunup_flag;//空抬枪次数写eeprom标记
- }encoder_count_info_t;
- //空抬枪计时
- typedef struct _gunnum_time
- {
- uint8_t flag;
- uint32_t gunup_time;
- uint32_t gundown_time;
- uint32_t interval_time;
- }gunnum_time_t;
- //枪信息
- typedef struct _encoder_record_info_t
- {
- encoder_count_info_t encoder_count_info; //脉冲计数信息
- encoder_irq_info_t gunsignal_irq; //抬抢信号中断信息
- encoder_irq_info_t pulse_irq; //脉冲信号中断信息
- // encoder_irq_info_t gunup_irq; //抬枪次数信息
- timeout_t pulse_stop_time; //脉冲计数停止定时器
- }encoder_record_info_t;
- //编码器存储信息
- typedef struct _encoder_eeprom_t
- {
- uint32_t id; //记录id
- uint32_t total_pulse; //总脉冲数
- }encoder_eeprom_t;
- //存储空抬枪次数
- typedef struct _encoder_gunnum_ee_t
- {
- uint32_t gunup_num; //抬枪次数
- }encoder_gunnum_ee_t;
- ////////////////////通信协议格式//////////
- //编码器下发数据格式
- typedef struct _encoder_down_data_t
- {
- uint8_t order; //指令
- }__attribute__((packed)) encoder_down_data_t;
- //脉冲上传(指令0和1),以枪为单位
- typedef struct _encoder_up_gun_t
- {
- uint8_t order; //指令
- uint8_t tax1_gunstatus; //报税口1抬枪状态(按位记录,抬枪时置1)
- uint8_t tax2_gunstatus; //报税口2抬枪状态(按位记录,抬枪时置1)
- uint8_t new_recode_status; //是否新交易状态(0:无新交易;1:有新交易)
- uint32_t id; //记录id
- uint8_t id_mode; //产生记录方式(0:逻辑判断产生;1:抬枪信号产生)
- uint32_t single_pulse_num; //单组脉冲数
- uint32_t total_pulse_num; //总脉冲数
- uint32_t time; //时间戳
- }__attribute__((packed)) encoder_up_gun_t;
- //指令2和3,以报税口为单位
- typedef struct _encoder_up_tax_head_t
- {
- uint8_t order; //指令
- uint8_t tax1_gunstatus; //报税口1抬枪状态(按位记录,抬枪时置1)
- uint8_t tax2_gunstatus; //报税口2抬枪状态(按位记录,抬枪时置1)
- uint8_t new_recode_status; //是否新交易状态(0:无新交易;1:有新交易)
- uint8_t id_mode; //产生记录方式(0:逻辑判断产生;1:抬枪信号产生)
- uint8_t gun_num; //最大枪数
- char info[100];
- }__attribute__((packed)) encoder_up_tax_head_t;
- #define ENCODER_UP_HEAD_NUM 6
- //编码器数据
- typedef struct _encoder_up_tax_data_t
- {
- uint32_t id; //记录id
- uint32_t single_pulse_num; //单组脉冲数
- uint32_t total_pulse_num; //总脉冲数
- uint32_t time; //时间戳
- }__attribute__((packed)) encoder_up_tax_data_t;
- void encoder_init(void);
- uint8_t tax_oil_judge_single(uint8_t tax);
- uint8_t tax_oil_judge_all(void);
- uint8_t Gun_Signal_Check(uint8_t tax);
- uint8_t Gun_Signal_Check_all(void);
- void encoder_record_end_handle(void);
- void encoder_irq_handle(uint8_t exti);
- void gunsignal_irq_delay_handle(void);
- void pulse_irq_delay_handle(void);
- //void gunnum_irq_delay_handle(void);
- void encoder_eeprom_write_handle(void);
- uint8_t coll_encoder_return_0_1(uint8_t tax, uint8_t gun, uint8_t order, uint8_t *data);
- uint8_t coll_encoder_return_2_3(uint8_t tax, uint8_t gun, uint8_t order, uint8_t *data);
- uint8_t Reset_encoder_judge(void);
- #endif
|