|
|
/******************************************************************************
|
|
|
* file include/pd_csg.h
|
|
|
* author YuLiang
|
|
|
* version 1.0.0
|
|
|
* date 21-Feb-2023
|
|
|
* brief This file provides all the headers of the csg server functions.
|
|
|
******************************************************************************
|
|
|
* Attention
|
|
|
*
|
|
|
* <h2><center>© 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_CSG_H_
|
|
|
#define _PD_CSG_H_
|
|
|
|
|
|
#ifdef CFG_DEV_TYPE_LAND_PD
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
#include "pd_main.h"
|
|
|
|
|
|
/* Define --------------------------------------------------------------------*/
|
|
|
#define CSG_DATA_FIFO "CSG_DATA_FIFO"
|
|
|
#define CSG_HEAD_LEN (22)
|
|
|
#define CSG_TAIL_LEN (4)
|
|
|
#define CSG_TOTLE_LEN (26)
|
|
|
#define CSG_PKT_LEN (1536)
|
|
|
|
|
|
#define CSG_SHIQUCHA (28800) // 8 * 3600.
|
|
|
|
|
|
#define CSG_CONNECT_REQ (0xA000) // 开机联络信息.
|
|
|
#define CSG_CONNECT_ACK (0xC000) // 开机联络信息应答.
|
|
|
#define CSG_HEARTBEAT_REQ (0xA001) // 心跳信息.
|
|
|
#define CSG_HEARTBEAT_ACK (0xC001) // 心跳信息应答.
|
|
|
#define CSG_ACITVE_CONNECT_REQ (0xC002) // 主站主动连接设备 .
|
|
|
#define CSG_REBOOT_REQ (0xC015) // 装置重启.
|
|
|
|
|
|
#define CSG_FACTORY_SET_ACK (0xA010) // 生产初始化信息配置应答.
|
|
|
#define CSG_FACTORY_SET_REQ (0xC010) // 生产初始化信息配置.
|
|
|
#define CSG_FACTORY_GET_ACK (0xA020) // 生产初始化信息查询应答.
|
|
|
#define CSG_FACTORY_GET_REQ (0xC020) // 生产初始化信息查询.
|
|
|
#define CSG_CONFIG_SET_ACK (0xA013) // 下发参数配置应答.
|
|
|
#define CSG_CONFIG_SET_REQ (0xC013) // 下发参数配置.
|
|
|
#define CSG_CONFIG_GET_ACK (0xA023) // 查询参数配置应答.
|
|
|
#define CSG_CONFIG_GET_REQ (0xC023) // 查询参数配置.
|
|
|
|
|
|
#define CSG_PORT_CONFIG_SET_REQ (0xC111) // 端口参数配置.
|
|
|
#define CSG_PORT_CONFIG_SET_ACK (0xA111) // 端口参数配置应答.
|
|
|
#define CSG_PORT_CONFIG_GET_REQ (0xC121) // 端口参数查询.
|
|
|
#define CSG_PORT_CONFIG_GET_ACK (0xA121) // 端口参数查询应答.
|
|
|
|
|
|
#define CSG_EVENT_REQ (0xA130) // 事件主动上传.
|
|
|
#define CSG_EVENT_ACK (0xC136) // 事件回复确认.
|
|
|
#define CSG_TREND_REQ (0xC132) // 趋势数据查询.
|
|
|
#define CSG_TREND_ACK (0xA132) // 趋势数据主动上传.
|
|
|
#define CSG_REAL_IMAGE_REQ (0xC135) // 实时图谱数据平台召唤.
|
|
|
#define CSG_REAL_IMAGE_ACK (0xA135) // 实时图谱数据上传.
|
|
|
|
|
|
|
|
|
/* Exported types ------------------------------------------------------------*/
|
|
|
/* 设备配置的滤波类型. */
|
|
|
typedef enum
|
|
|
{
|
|
|
CSG_FILTER_TYPE_FF = 1,
|
|
|
CSG_FILTER_TYPE_FR,
|
|
|
CSG_FILTER_TYPE_LF,
|
|
|
CSG_FILTER_TYPE_HF
|
|
|
} CSG_FILTER_TYPE_E;
|
|
|
|
|
|
/* . */
|
|
|
typedef struct
|
|
|
{
|
|
|
int fd; // 后台通讯使用的 socket.
|
|
|
uint32_t pkt_index; // 报文索引.
|
|
|
int32_t data_fifo_id; // 数据处理线程发向后台发送线程的 fifo.
|
|
|
char buf_send[CSG_PKT_LEN];
|
|
|
char buf_reply[CSG_PKT_LEN];
|
|
|
char buf_recv[CSG_PKT_LEN];
|
|
|
struct sockaddr_in server;
|
|
|
int32_t server_ip; // server ip.
|
|
|
uint16_t server_port; // server port.
|
|
|
uint8_t is_connect; // 是否连接上服务器.
|
|
|
uint8_t heartbeat; // 心跳发送后没有收到回复的次数.
|
|
|
int32_t communication_time; // 最后通讯时间.
|
|
|
pthread_mutex_t mutex;
|
|
|
} csg_t;
|
|
|
|
|
|
/* 报文头结构. */
|
|
|
typedef struct{
|
|
|
uint16_t head;
|
|
|
uint16_t cmd;
|
|
|
uint8_t dev_num[PD_DEV_NUM_LEN];
|
|
|
uint16_t len;
|
|
|
} csg_pkt_head_t;
|
|
|
|
|
|
/* 报文尾结构.*/
|
|
|
typedef struct{
|
|
|
uint16_t checksum;
|
|
|
uint16_t tail;
|
|
|
} csg_pkt_tail_t;
|
|
|
|
|
|
/* 心跳报文. */
|
|
|
typedef struct{
|
|
|
uint8_t port_alarm[PD_PORT_SUM]; // 通道报警状态 0: 没有报警 1: 报警.
|
|
|
uint32_t event_num[PD_PORT_SUM]; // 通道的最新事件编号.
|
|
|
uint32_t fault_num[PD_PORT_SUM]; // 通道的最新原始数据编号.
|
|
|
uint32_t utc;
|
|
|
float freq; // 实测同步源工频频率.
|
|
|
uint8_t dau_state[4]; // 采集模块的状态.
|
|
|
uint8_t out_sync; // 外接调频同步 1: 有效 0: 无效.
|
|
|
uint8_t pt_sync; // PT同步 1: 有效 0: 无效.
|
|
|
uint8_t in_sync; // 内同步 1: 有效 0: 无效.
|
|
|
uint8_t reserved1; // 预留 字节对齐.
|
|
|
uint8_t port_link_alarm[PD_PORT_SUM]; // 通道传感器连接状态 断线告警.
|
|
|
float voltage; // 设备电压, 预留.
|
|
|
float temperature; // 设备温度, 预留.
|
|
|
uint8_t heartbeat; // 心跳发送后没有收到回复的次数.
|
|
|
uint8_t bat; // 电池电量 预留, 单位 %.
|
|
|
uint8_t reserved2[18];
|
|
|
} csg_pkt_heartbeat_t;
|
|
|
|
|
|
typedef struct
|
|
|
{
|
|
|
uint8_t vport; // 通道编号 1 ~ 16.
|
|
|
uint8_t is_concern; // 关注 1: 关注 0: 取消关注.
|
|
|
uint8_t r_noise_reduction; // 关联降噪 1: 关联噪声去噪.
|
|
|
uint8_t auto_noise_reduction; // 自适应降噪 自适应降噪.
|
|
|
uint8_t manual_noise_reduction; // 手动降噪 0 ~ 80 手动降噪.
|
|
|
uint8_t filter; // 滤波器类型.
|
|
|
uint8_t reserved[2]; //保留.
|
|
|
} csg_real_image_get_t;
|
|
|
|
|
|
/* 实时图谱报文头 36Byte. */
|
|
|
typedef struct{
|
|
|
uint16_t index; // 每10包传完之后自动自加,用于区分当前包结束.
|
|
|
uint8_t pkt_sum; // 总包数 10.
|
|
|
uint8_t pkt_index; // 当前包数 0 ~ 9.
|
|
|
uint8_t vport; // 通道编号.
|
|
|
uint8_t reserved1[3];
|
|
|
int16_t max;
|
|
|
int16_t avg;
|
|
|
uint32_t cnt;
|
|
|
uint32_t utc;
|
|
|
uint32_t is_sub; // 0: 定时数据主动上传 , 1: 定时数据 UTC 召唤.
|
|
|
uint32_t interval; // 上传间隔, 单位分钟.
|
|
|
uint8_t reserved2[8];
|
|
|
} csg_real_image_t;
|
|
|
|
|
|
typedef struct{
|
|
|
uint32_t is_valid; // 1 有效 0 无效.
|
|
|
int16_t max;
|
|
|
int16_t avg;
|
|
|
uint32_t cnt;
|
|
|
float phase; // 放电相位.
|
|
|
uint32_t event_cnt; // 趋势数据中的的事件数量记录.
|
|
|
float noise; // 底噪平均值.
|
|
|
uint8_t reserved[16];
|
|
|
} csg_trend_t;
|
|
|
|
|
|
typedef struct{
|
|
|
uint32_t idx; // 数据编号.
|
|
|
uint32_t utc;
|
|
|
uint32_t is_sub; // 是否是补包.
|
|
|
uint32_t interval; // 上传间隔 单位分钟.
|
|
|
csg_trend_t data[PD_PORT_SUM];
|
|
|
uint8_t reserved[144];
|
|
|
} csg_trend_head_t;
|
|
|
|
|
|
typedef struct{
|
|
|
uint16_t idx; // 每 10 包传完之后自动++, 用于区分当前包结束.
|
|
|
uint8_t pkt_sum; // 总包数 10.
|
|
|
uint8_t pkt_idx; // 当前包数 0 ~ 9.
|
|
|
uint8_t vport; // 通道编号.
|
|
|
uint8_t type; // 事件类型.
|
|
|
int16_t max; // 事件幅值最大值.
|
|
|
uint32_t level; // 事件等级.
|
|
|
uint32_t pd_Type; // 放电类型.
|
|
|
float type_per[8]; // 放电概率.
|
|
|
float PositionDistance; // 距离本传感器的距离.
|
|
|
uint32_t utc; // utc.
|
|
|
uint32_t event_idx; // 事件编号.
|
|
|
uint32_t cnt; // 脉冲频次计数值.
|
|
|
} csg_event_head_t;
|
|
|
|
|
|
/* Exported macro ------------------------------------------------------------*/
|
|
|
|
|
|
/* Extern global variables ---------------------------------------------------*/
|
|
|
extern csg_t csg;
|
|
|
|
|
|
/* Extern functions ----------------------------------------------------------*/
|
|
|
extern int32_t csg_handle_init(void);
|
|
|
#endif
|
|
|
#endif
|
|
|
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/
|