You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
16 KiB
C

/*****************************************************************************
* file include/pd_main.h
* author YuLiang
* version 1.0.0
* date 07-Feb-2023
* brief This file provides all the headers of the partial discharge functions.
******************************************************************************
* Attention
*
* <h2><center>&copy; COPYRIGHT(c) 2021 LandPower</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of LandPower nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef __PD_MAIN_H__
#define __PD_MAIN_H__
#ifdef CFG_DEV_TYPE_LAND_PD
/* Includes ------------------------------------------------------------------*/
#include "cmd.h"
/* Define --------------------------------------------------------------------*/
#define PD_SLOTS_MAX 8 // 主控之下最大槽位数
#define PD_DAU_SUM 1 // 每个采集卡最大采集单元数, 固定为 1
#define PD_DAU_PORT_SUM 8 // 每个采集卡的采集单元最大端口数
#define PD_PORT_SUM 8
#define PD_PORT_PROMPT_LEN 64 // DAU 端口节点前标长度.
#define PD_DEV_NUM_LEN 16
#define PD_DEV_TYPE_LEN 8
#define PD_POWER_FRE_MAX 384
#define PD_PHASE_NUM 256
#define PD_VAULE_NUM 256
#define PD_PRPS_NUM 12800
#define PD_PRPS_NUM_MAX 98304
#define PD_EVENT_POINT_MAX 983040
#define PD_TREND_PHASE_POINT_CNT 256
#define PD_TREND_POINT_MAX 983040
#define PD_TREND_ORIGINAL_NUM 65536
#define PD_PORT_ORIGINAL_NUM 2560000 // 100M采样率, 最大40Hz
#define PD_4G_APN_LEN 64
/* Exported types ------------------------------------------------------------*/
/* 用于命令行模式节点注册配置保存函数 */
typedef int pd_port_cmd_save_config_f(vty_t*, uint8_t, uint8_t);
/* 向服务器发送消息的类型. */
typedef enum
{
PD_DEV_TYPE_HF = 1,
PD_DEV_TYPE_UHF
} PD_DEV_TYPE_E;
/* 向服务器发送消息的类型. */
typedef enum
{
PD_SEND_TYPE_PRPS = 1,
PD_SEND_TYPE_TREND,
PD_SEND_TYPE_EVENT,
PD_SEND_TYPE_POINT,
PD_SEND_TYPE_CMD,
PD_SEND_TYPE_COUNT
} PD_SEND_TYPE_E;
/* 端口类型. */
typedef enum
{
PD_PORT_TYPE_UHF = 1,
PD_PORT_TYPE_AE,
PD_PORT_TYPE_TEV,
PD_PORT_TYPE_HF,
PD_PORT_TYPE_COUNT
} PD_PORT_TYPE_E;
/* 设备配置的主备类型. */
typedef enum
{
PD_DAU_MODE_AUTO = 0,
PD_DAU_MODE_MASTER,
PD_DAU_MODE_SLAVE,
PD_DAU_MODE_COUNT
} PD_DAU_MODE_E;
/* 设备配置的滤波类型. */
typedef enum
{
PD_FILTER_TYPE_HF = 3,
PD_FILTER_TYPE_LF = 6,
PD_FILTER_TYPE_FR = 9,
PD_FILTER_TYPE_FF = 12
} PD_FILTER_TYPE_E;
/* 端口类型. */
typedef enum
{
PD_SEN_TYPE_NONE = 0,
PD_SEN_TYPE_SIG,
PD_SEN_TYPE_NOISE,
PD_SEN_TYPE_SIG_NOISE,
PD_SEN_TYPE_COUNT
} PD_SEN_TYPE_E;
/* 端口类型. */
typedef enum
{
PD_DENOISE_TYPE_NONE = 0,
PD_DENOISE_TYPE_AOTU,
PD_DENOISE_TYPE_MANUAL,
PD_DENOISE_TYPE_VARIANCE,
PD_DENOISE_TYPE_COUNT
} PD_NOISE_TYPE_E;
/* 设备配置的滤波类型. */
typedef enum
{
PD_SYNC_PT = 1,
PD_SYNC_INSIDE,
PD_SYNC_OUTSIDE
} PD_SYNC_MODE_E;
/* 设备配置的 PPS 同步模式. */
typedef enum
{
PD_PPS_AUTO = 0,
PD_PPS_MASTER,
PD_PPS_SLAVE,
} PD_PPS_MODE_E;
/* 协议类型. */
typedef enum
{
PD_PROTOCOL_LAND = 0,
PD_PROTOCOL_CSG = 1
} PD_PROTOCOL_TYPE;
/* 事件类型. */
typedef enum
{
PD_EVENT_TYPE_NONE = 0,
PD_EVENT_TYPE_CNTH, // 计数高
PD_EVENT_TYPE_THRH, // 阈值要
PD_EVENT_TYPE_THRL, // 计数阈值低
PD_EVENT_TYPE_BURST, // 突发
PD_EVENT_TYPE_COUNT
} PD_EVENT_TYPE_E;
/* 端口节点配置优先级 */
typedef enum
{
PD_PORT_CMD_PRI_DAU = 0,
PD_PORT_CMD_PRI_COUNT
} PD_PORT_CMD_PRI_E;
typedef struct {
uint16_t index; // 点位
int16_t data; // 数据
} pd_data_point_t;
/* 1s prps 数据结构体. */
typedef struct {
uint16_t fre_cnt; // 工频周期计数.
uint16_t max; // 通道的最大值.
uint16_t avg_o; // 通道原始信号 (降噪前) 的平均值.
uint16_t avg; // 通道脉冲的平均值.
uint32_t cnt; // 通道脉冲的计数值.
uint32_t phase_sum[PD_PHASE_NUM]; // 通道的周波放电相位累加值.
uint16_t phase_max[PD_PHASE_NUM]; // 通道的周波相位最大值.
uint16_t phase_avg[PD_PHASE_NUM]; // 通道的周波相位平均值.
uint16_t phase_cnt[PD_PHASE_NUM]; // 通道的周波相位计数值
int16_t prps[PD_PRPS_NUM_MAX]; // 1s prps 降噪数据.
pd_data_point_t point[PD_PRPS_NUM_MAX]; // 通道数据.
uint32_t point_cnt; // 通道点数.
uint8_t is_event; // 是否产生事件.
uint8_t is_timing; // 是否产生定时数据.
uint16_t cnt_h; // 高于指定高阈值的脉冲个数.
uint16_t cnt_l; // 高于指定低阈值的脉冲个数.
} pd_prps_data_point_t;
typedef struct {
uint32_t index; // 数据编号.
uint32_t utc; // UTC 时标.
uint32_t ms; // UTC 时标.
pd_prps_data_point_t data[PD_DAU_SUM][PD_DAU_PORT_SUM]; // 16 个通道的数据.
} pd_prps_point_t;
typedef struct {
uint8_t vport; // 通道编号.
uint8_t reserved[3]; // 预留.
uint32_t index; // 数据编号: 0 - (2^32-1) 循环.
uint32_t utc; // UTC 时标.
uint16_t max; // 通道的最大值.
int16_t avg_o; // 通道原始信号 (降噪前) 的平均值.
int16_t avg; // 通道的平均值.
int16_t cnt; // 通道的计数值.
} pd_event_old_t;
typedef struct {
uint32_t power_fre; // 工频周期.
uint8_t data_cnt; // 数据计数
uint8_t event_cnt; // 上次处理的事件计数
uint8_t is_sec_h; // 每秒脉冲高触发.
uint8_t is_sec_l; // 每秒脉冲低触发.
uint8_t is_burst; // 是否产生突变.
uint8_t type; // 事件类型.
uint16_t max; // 通道的最大值.
uint32_t index; // 数据编号: 0 - (2^32-1) 循环.
uint32_t utc; // UTC 时标.
uint32_t cnt; // 通道每秒脉冲计数值.
uint32_t cnt_h; // 高于指定高阈值的脉冲个数.
uint32_t cnt_l; // 高于指定低阈值的脉冲个数.
uint32_t point_cnt; // 数据累计点数.
uint64_t avg_o; // 通道原始信号 (降噪前) 的平均值.
uint64_t avg; // 脉冲平均值.
pd_data_point_t point[PD_EVENT_POINT_MAX]; // 事件累计数据.
} pd_event_port_t;
typedef struct {
pd_event_port_t port[PD_DAU_SUM][PD_DAU_PORT_SUM];
} pd_event_t;
typedef struct {
uint32_t trend_sec; // 上次处理的趋势计数
uint32_t utc; // UTC 时标.
uint16_t data_cnt; // 数据计数.
uint16_t max; // 通道的最大值.
uint64_t avg; // 通道的平均值.
uint32_t cnt; // 通道的计数值.
float phase; // 放电相位 .
float noise; // 趋势数据中的底噪值: 单位 dBm .
uint32_t event_cnt; // 趋势数据中的的事件数量记录.
uint64_t phase_sum[PD_PHASE_NUM]; // 通道的周波放电相位累加值.
uint16_t phase_max[PD_PHASE_NUM]; // 通道的周波相位最大值.
uint16_t phase_avg[PD_PHASE_NUM]; // 通道的周波相位平均值.
uint32_t phase_cnt[PD_PHASE_NUM]; // 通道的周波相位计数值.
} pd_trend_data_t;
typedef struct {
uint32_t index; // 数据编号: 0 - (2^32-1) 循环.
uint32_t utc; // UTC 时标.
pd_trend_data_t data[PD_DAU_SUM][PD_DAU_PORT_SUM]; // 通道 0 - 15 的计算及测量数据.
} pd_trend_col_t;
typedef struct {
uint16_t data[PD_PHASE_NUM][PD_VAULE_NUM];
} pd_trend_prpd_port_t;
typedef struct {
pd_trend_prpd_port_t port[PD_DAU_SUM][PD_DAU_PORT_SUM];
} pd_trend_prpd_t;
typedef struct {
uint32_t point_cnt; // 数据累计点数.
pd_data_point_t point[PD_TREND_POINT_MAX];
} pd_trend_prps_port_t;
typedef struct {
pd_trend_prps_port_t port[PD_DAU_SUM][PD_DAU_PORT_SUM];
} pd_trend_prps_t;
typedef struct {
uint32_t point[PD_PHASE_NUM]; // 最大值出现的位置
int16_t data[PD_PHASE_NUM][PD_TREND_PHASE_POINT_CNT]; // 每个相位中有 256 个点
} pd_trend_original_port_t;
typedef struct {
pd_trend_original_port_t port[PD_DAU_SUM][PD_DAU_PORT_SUM];
} pd_trend_original_t;
typedef struct {
pd_trend_col_t col;
pd_trend_prpd_t *prpd;
pd_trend_prps_t prps;
pd_trend_original_t original;
} pd_trend_t;
typedef struct {
pd_prps_point_t *real; // 实时数据指针
pd_event_t *event; // 事件
pd_trend_col_t trend_col; // 趋势统计数据
pd_trend_prpd_t *trend_prpd; // 趋势 PRPD
pd_trend_t trend; // 趋势完整数据
} pd_data_t;
typedef struct {
uint32_t type;
void *data;
} pd_csg_msg_t;
typedef struct{
uint16_t power_frequency; // 工频频率, 单位: 0.1Hz
uint16_t trend_period; // 趋势数据上送周期, 单位: 秒
uint8_t sync_mode; // 同步方式 1: PT 同步 2: 内同步(默认) 3: 外接信号同步
uint8_t heartbeat_period; // 心跳包周期, 单位: 分钟
uint8_t pps_mode; // pps 主从模式 PD_PPS_XXX
uint8_t protocol_type; // 0:朗德协议 1:南网协议
uint16_t trend_storage; // 趋势存储文件数量阈值
uint16_t event_storage; // 事件存储文件数量阈值
uint8_t is_4G_enable; // 是否使用 4G 模块
char APN[PD_4G_APN_LEN]; // 4G 模块 APN
} pd_config_global_t;
/* 端口配置. */
typedef struct {
uint8_t vport; // 通道编号.
uint8_t port_type; // 采集通道类型 , 1 表示特高频局放 2 表示超声局放 3 表示 TEV 4 表示高频.
uint8_t filter; // 滤波器类型 1: 低频段 2: 全频段 3: 窄频段 4: 高频段
uint8_t sensor_type; // 0: 无配置; 1: UHF信号传感器; 2: UHF噪声传感器 ; 3: UHF信号传感器, 关联噪声降噪.
uint8_t is_auto_noise; // 是否自动调整降噪等级.
uint8_t denoise_type; // 0-无配置 1-自动 2-手动降噪
uint16_t denoise_variance; // 方差降噪系数, 单位: 1%
uint32_t event_counter_h; // 事件次数阀值高.
uint16_t event_sec_h; // 事件每秒次数阀值高.
uint16_t event_thr_h; // 事件值阈值高.
uint32_t event_counter_thr_h; // 事件值阈值高的次数.
uint32_t event_counter_l; // 事件次数阀值低.
uint16_t event_sec_l; // 事件每秒次数阀值低.
uint16_t event_thr_l; // 事件值阈值低.
uint32_t event_counter_thr_l; // 事件值阈值低的次数.
uint8_t burst_time; // 事件突发计算时间
uint8_t reserved0[1];
uint16_t burst_thr; // 事件突发阈值
int16_t denoise_manual; // 手动底噪等级
int16_t denoise_auto; // 自动降噪水平
uint8_t reserved1[2];
uint16_t auto_noise_cnt; // 自动调整降噪等级时脉冲计数阈值.
} pd_config_port_t;
/* 实时波形配置. */
typedef struct {
uint8_t is_concern; // 是否被关注, 在实时波形中使用.
uint8_t filter_cfg; // 端口配置的滤波类型, 在实时波形中使用.
uint8_t denoise_correlation; // 是否启动关联降噪, 在实时波形中使用.
uint8_t denoise_type; // 0-无配置 1-自动 2-手动降噪
uint16_t denoise_manual; // 手动降噪等级
} pd_config_real_t;
typedef struct {
pd_config_global_t config; // 全局配置
pd_config_port_t config_port[PD_DAU_SUM][PD_DAU_PORT_SUM]; // 端口配置
pd_config_real_t config_real[PD_DAU_SUM][PD_DAU_PORT_SUM]; // 实时波形配置
} pd_config_t;
typedef struct
{
uint8_t state;
uint8_t sync;
uint8_t is_4G_connect;
} pd_state_t;
/* Exported macro ------------------------------------------------------------*/
/* Extern global variables ---------------------------------------------------*/
extern pd_data_t pd_data;
extern pd_config_t pd_config;
extern pd_state_t pd_state;
extern cmd_node_t pd_slot_node;
/* Extern functions ----------------------------------------------------------*/
extern int32_t pd_main(void);
extern int32_t pd_main_after(void);
extern int32_t pd_port_cmd_config_register(int32_t pri, pd_port_cmd_save_config_f *func);
extern void pd_sync_state_get(void);
extern void pd_pps_mode_set(void);
extern void pd_prps_show(void);
extern void pd_show(void);
#endif
#endif
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/