228 lines
7.5 KiB
C
228 lines
7.5 KiB
C
/**
|
||
* @file mode_diagnosis.h
|
||
* @author xushenghao
|
||
* @date 2024-03-01 00:05:33
|
||
* @brief 控制模块诊断:斜坡、阶跃、EPM测试指令
|
||
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
|
||
*/
|
||
#ifndef __MODE_DIAGNOSIS_H
|
||
#define __MODE_DIAGNOSIS_H
|
||
#include "lib.h"
|
||
#include <fal.h>
|
||
#include "mode_def.h"
|
||
#include "hart_frame.h"
|
||
#include "app_hart_user.h"
|
||
|
||
#define DIAGNOSIS_EPM_DBG FALSE // 测试:诊断EPM调试
|
||
|
||
#define MODE_DIAGNOSIS_FILE_SIZE (27994) // 文件大小
|
||
#define FINISHED_BYTE (0x40) // 结束标志
|
||
|
||
#define MODE_DIAGNOSIS_STORAGE_SIZE (4 * 1024) // 诊断存储空间大小
|
||
#if MODE_DIAGNOSIS_STORAGE_SIZE < (HART_PACKED4_LEN * 2)
|
||
#error "MODE_DIAGNOSIS_STORAGE_SIZE must be greater than or equal to HART_PACKED4_LEN*2"
|
||
#endif
|
||
|
||
#define STABILITY_TIME (15) // 稳定时间 秒
|
||
|
||
typedef enum
|
||
{
|
||
MODE_DIAGNOSIS_TYPE_NONE, // 无
|
||
MODE_DIAGNOSIS_TYPE_SLOPE_STEP, // 斜坡 和 阶跃测试
|
||
MODE_DIAGNOSIS_TYPE_EPM, // EPM
|
||
MODE_DIAGNOSIS_TYPE_ONLINE // 在线测试
|
||
} mode_diagnosis_type_e;
|
||
|
||
typedef enum
|
||
{
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_TRAVEL_SET_POINT = BIT1, // DIN_IMPLIED_VALVE_POSITION 9
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_TRAVEL = BIT2, // DIN_TRAVEL 3
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_DRIVE_SIGNAL = BIT3, // DIN_DRIVE_SIGNAL 4
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_PRESSURE_A = BIT4, // DIN_PRESSURE_PORT_A 2
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_PRESSURE_B = BIT5, // DIN_PRESSURE_PORT_B 5
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_SUPPLY_PRESSURE = BIT6, // DIN_SUPPLY_PRESSURE 8
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_RELAY_POSITION = BIT7, // DIN_MINOR_LOOP_NORMAL 79
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_TRAVEL_DEVIATION = BIT8, // ???
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_INPUT_SET_PT = BIT9, // DIN_TRAVEL_SETPOINT 6
|
||
MODE_DIAGNOSIS_OUTPUT_DATA_INPUT_CURRENT = BIT10, // DIN_ANALOG_INPUT 0
|
||
} mode_diagnosis_output_data_e;
|
||
|
||
#pragma pack(1)
|
||
|
||
/**
|
||
*
|
||
总时间 = 测试时间 + 固定值15s
|
||
RampRate = (开始和结束行程设置点差绝对值 / 测试时间 *16.384) ,其中小数部分大于0则加1
|
||
输入值增量 = RampRate /16.384 * 间隔时间 或
|
||
输入值增量 = 开始和结束行程设置点差绝对值 / 斜坡数据点数
|
||
斜坡时间 =开始和结束行程设置点差绝对值 / RampRate*16.384
|
||
*/
|
||
typedef struct
|
||
{
|
||
uint8_t read_or_write; // 读写标志 0:读,1:写
|
||
uint32_t timestamp; // 时间戳 注:手动赋值
|
||
uint8_t variable_code[HART_PACKED4_LEN]; // 设备变量,和HART中的设备变量有关系
|
||
uint8_t sampling_time; // 采样时间
|
||
uint16_t target; // 目标位置
|
||
uint16_t ramp; // 斜率
|
||
uint32_t points; // 总点数
|
||
} mode_diagnosis_slop_file_head_t; // 一共18个字节用于标识文件头
|
||
|
||
/**
|
||
* 文件头
|
||
*/
|
||
typedef struct
|
||
{
|
||
uint8_t read_or_write; // 读写标志 0:读,1:写
|
||
uint8_t variable_code[HART_PACKED4_LEN]; // 设备变量,和HART中的设备变量有关系
|
||
uint8_t sampling_time; // 采样时间
|
||
uint32_t points; // 总点数
|
||
} mode_diagnosis_online_file_head_t; // 一共9个字节用于标识文件头
|
||
|
||
typedef struct
|
||
{
|
||
mode_diagnosis_slop_file_head_t head; // 文件头
|
||
sqqueue_ctrl_t queue;
|
||
} mode_diagnosis_slop_file_storage_t; // 斜坡测试
|
||
|
||
typedef struct
|
||
{
|
||
mode_diagnosis_online_file_head_t head;
|
||
} mode_diagnosis_online_file_storage_t;
|
||
|
||
typedef union
|
||
{
|
||
mode_diagnosis_slop_file_head_t slope; // 斜坡和阶跃测试
|
||
mode_diagnosis_online_file_head_t online; // 在线测试
|
||
} mode_diagnosis_file_head_u;
|
||
|
||
#pragma pack()
|
||
|
||
typedef struct
|
||
{
|
||
float32 v[HART_PACKED4_LEN];
|
||
int32_t decompression_v[HART_PACKED4_LEN];
|
||
} mode_diagnosis_data_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint16_t size;
|
||
uint16_t written; // 已写字节数
|
||
uint16_t remain; // 剩余字节数
|
||
} mode_diagnosis_page_t;
|
||
|
||
typedef struct
|
||
{
|
||
BOOL finshed; // 是否完成
|
||
file_status_e file_status; // 文件状态
|
||
uint16_t file_size_read; // 文件已读大小
|
||
uint16_t file_size_written; // 文件已写入大小
|
||
uint16_t file_size; // 文件大小
|
||
uint8_t head_size; // 文件头大小
|
||
uint8_t *pbuf;
|
||
} mode_diagnosis_storage_t;
|
||
|
||
typedef struct
|
||
{
|
||
BOOL run;
|
||
mode_diagnosis_type_e type; // 诊断类型
|
||
mode_diagnosis_data_t last_data; // 上一次数据
|
||
|
||
struct
|
||
{
|
||
uint8_t actual_variables_num; // 实际变量数量
|
||
uint16_t ticks;
|
||
uint32_t sampling_time; // 采样时间
|
||
float32 output_increment; // 输出增量 百分比
|
||
|
||
// 只用于显示
|
||
int16_t start_target; // 开始目标
|
||
int16_t end_target; // 结束目标
|
||
uint16_t total_points; // 总数据点数
|
||
uint32_t test_time; // 测试时间
|
||
uint32_t stability_time; // 稳定时间
|
||
} params;
|
||
|
||
struct
|
||
{
|
||
uint16_t read_write_offset_time; // 读写偏移时间 秒 计算写入与上位机读取之间的时间差
|
||
uint16_t points; // 斜坡数据点数
|
||
uint32_t run_ticks; // 运行时间,标记执行了多少次中断,当到达ticks时,停止
|
||
uint32_t stability_ticks; // 稳定时间,减到0结束
|
||
|
||
float32 current_target; // 当前目标
|
||
float32 last_target; // 上一次目标
|
||
|
||
hart_device_variable_t *variables[HART_PACKED4_LEN];
|
||
uint16_t variables_cycles_count; // 变量循环计数
|
||
} rt_data;
|
||
|
||
} mode_diagnosis_t;
|
||
|
||
/**
|
||
* @brief Initialize the mode diagnosis module.
|
||
*/
|
||
void mode_diagnosis_init(void);
|
||
|
||
/**
|
||
* @brief Get the mode diagnosis object pointer.
|
||
*
|
||
* This function returns a pointer to the mode diagnosis object. This object is used to store and manage the relevant information of the mode diagnosis.
|
||
*
|
||
* @return The pointer to the mode diagnosis object.
|
||
*/
|
||
mode_diagnosis_t *mode_diagnosis_get(void);
|
||
|
||
/**
|
||
* @brief Get the storage of the mode diagnosis.
|
||
*
|
||
* @return The storage of the mode diagnosis.
|
||
*/
|
||
mode_diagnosis_storage_t *mode_diagnosis_get_storage(void);
|
||
|
||
/**
|
||
* @brief Stop the mode diagnosis.
|
||
*
|
||
* This function stops the mode diagnosis and saves the data to the flash.
|
||
*
|
||
* @return None.
|
||
*/
|
||
void mode_diagnosis_stop(void);
|
||
|
||
/**
|
||
* @brief Start the mode diagnosis.
|
||
*
|
||
* This function starts the mode diagnosis and records the event and data.
|
||
*
|
||
* @param[in] diagnosis_type The type of the mode diagnosis.
|
||
* @param[in] data The data of the mode diagnosis.
|
||
*
|
||
* @return @c true if the mode diagnosis is started successfully, otherwise @c false.
|
||
*/
|
||
BOOL mode_diagnosis_start(mode_diagnosis_type_e diagnosis_type, const mode_diagnosis_file_head_u *const data);
|
||
|
||
/**
|
||
* @brief Write the mode diagnosis file.
|
||
*
|
||
* This function writes the mode diagnosis file to the flash.
|
||
*
|
||
* @param[in] file_offset The offset of the file.
|
||
* @param[in] write_length The length of the data to be written.
|
||
* @param[in] wr_cache The data to be written.
|
||
* @param[in] wf_len The length of the data to be written.
|
||
*
|
||
* @return @c true if the mode diagnosis file is written successfully, otherwise @c false.
|
||
*/
|
||
BOOL mode_diagnosis_file_read(uint16_t file_offset, uint8_t read_length, uint8_t *rd_cache, uint8_t *rd_len);
|
||
|
||
/**
|
||
* @brief Perform an inspection of the mode diagnosis module.
|
||
*/
|
||
void mode_diagnosis_inspection(void);
|
||
|
||
/**
|
||
* @brief Test the mode diagnosis module.
|
||
*/
|
||
INTERNAL_EXTERN void mode_diagnosis_test(mode_diagnosis_type_e event);
|
||
#endif // __MODE_DIAGNOSIS_H
|