#ifndef __APP_H__ #define __APP_H__ #include "lib/inc/lib.h" #include "agreement/agreement.h" #include "agreement/agreement_slave.h" #define PID_IP 0 // IP PID开关 #define UART_RXSIZE (300u) #define UART_DATA_ANALYSIS_PORT DATA_1 #define PROJECT_NAME "epm" #define VERSION "1.0" #define LEFT_VALVE 0 #define RIGHT_VALVE 1 #define FLASH_USER_AREA 0x08010000UL // 用户区域的起始地址 #define FLASH_PROCESS_CONFIG FLASH_USER_AREA + (FLASH_PAGE_SIZE * 0) // 配置流程存储的地址 #define FLASH_DEVICE_ADDRESS FLASH_USER_AREA + (FLASH_PAGE_SIZE * 14) // 设备地址存储的地址 #define FLASH_IP_OUT_MODE_ADDRESS FLASH_USER_AREA + (FLASH_PAGE_SIZE * 15) // IP输出模式存储的地址 #define FLASH_IP_OUT_PWM_FREQUENCY_ADDRESS FLASH_USER_AREA + (FLASH_PAGE_SIZE * 16) // IP输出PWM频率存储的地址 // 比例阀参数定义 #define PROPORTIONAL_VALVE_MAX 900 // 单位kpa #define PROPORTIONAL_VALVE_MIN 0 // 单位kpa // 压力传感器参数定义 #define PRESURE_SENSOR_MAX 1000 // 单位kpa #define PRESURE_SENSOR_MIN -100 // 单位kpa typedef union { uint16_t data; struct { uint8_t r1 : 1, // 两通阀1 r2 : 1, // 两通阀2 r3 : 1, // 两通阀3 r4 : 1, // 三通阀4 r5 : 1, // 三通阀5 r6 : 1, // 两通阀6 r7 : 1, // 两通阀7 r8 : 1, // 三通阀8 r9 : 1, // 三通阀9 r10 : 1, // r11 : 1, // r12 : 1; // } bits; } relay_t; // 继电器状态 1-12 typedef struct { bool is_open; uint32_t calibration_value; uint32_t original_value; } calibration_sensor_data_t; typedef struct { calibration_sensor_data_t proportional_valve_in1; // 比例阀 calibration_sensor_data_t ip_in6; calibration_sensor_data_t ntc_in12; calibration_sensor_data_t minor_loop_in13; // 小回路 calibration_sensor_data_t laser_in0; // 没有处理 calibration_sensor_data_t presure_in7; calibration_sensor_data_t presure_in8; calibration_sensor_data_t presure_in9; calibration_sensor_data_t presure_in10; calibration_sensor_data_t presure_in11; calibration_sensor_data_t presure_in12; } adc_t; typedef struct { uint8_t process_index; // 当前执行的流程编号 uint8_t plan_index; // 当前执行的方案编号 uint8_t action_index; // 当前执行的动作编号 } process_state_t; typedef struct { relay_t relay; // 继电器状态 adc_t adc; // 采集的传感器数据 run_state_e task_run_state; // 任务运行状态 process_state_t process_state; // 流程状态 uint32_t device_address; // 设备地址 uint32_t ip_out_mode; // IP输出模式 uint32_t ip_out_pwm_frequency; // IP输出PWM频率 bool master_active; // 主机是否活跃,在任务中设置不活跃,收到串口数据改成活跃 } app_t; typedef void (*agreement_req_cb_t)(uint8_t *data, uint16_t len); extern volatile app_t app; // APP全局变量 extern uint16_t ip_dac_value; extern float32 ip_pwm_duty; extern uint16_t proportional_valve_dac_value; extern bool app_init(void); extern void flash_load(void); extern void flow_init(void); extern void flow_start(void); extern bool uart_init(agreement_req_cb_t cb); extern void uart_recv_data(uint8_t *data, uint16_t len); extern void register_request_done(void); extern bool need_reset(void); extern uint32_t get_ip_dac_out(void); extern uint32_t get_proportional_valve_dac_out(void); extern float32_t get_proportional_valve_adc_in(uint32_t adc_val); extern float32_t get_ip_adc_in(uint32_t adc_val); extern void dac_init_flag_reset(void); extern run_state_e get_task_run_state(void); extern float32_t get_pressure_sensor_adc_in(int32_t adc_val); extern void set_valve_status(unit_e unit, uint8_t index, uint8_t status); extern void laser_zero_flag_reset(void); #endif // __APP_H__