361 lines
12 KiB
C
Executable File
361 lines
12 KiB
C
Executable File
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#ifndef __IOT_BRM_EVT_H
|
|
#define __IOT_BRM_EVT_H
|
|
|
|
#include "iot_brm_config.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
/* define the maximum threshold data length for events */
|
|
#define IOT_BRM_EVT_THR_DATA_MAX_LEN 32
|
|
|
|
/* define voltage threshold range for under voltage check, unit is 0.1V,
|
|
* see DL/T645-2007-14
|
|
*/
|
|
#define IOT_BRM_EVT_UV_THR_V_MIM 1540 /* 220V * 70% */
|
|
#define IOT_BRM_EVT_UV_THR_V_MAX 1980 /* 220V * 90% */
|
|
/* define check delay time range for under voltage, unit is 1s,
|
|
* see DL/T645-2007-14.
|
|
*/
|
|
#define IOT_BRM_EVT_UV_THR_TIME_MIN 10
|
|
#define IOT_BRM_EVT_UV_THR_TIME_MAX 99
|
|
|
|
/* define voltage threshold range for over voltage check, unit is 0.1V,
|
|
* see DL/T645-2007-14
|
|
*/
|
|
#define IOT_BRM_EVT_OV_THR_V_MIM 2420 /* 220V * 110% */
|
|
#define IOT_BRM_EVT_OV_THR_V_MAX 2860 /* 220V * 130% */
|
|
/* define check delay time range for over voltage, unit is 1s,
|
|
* see DL/T645-2007-14.
|
|
*/
|
|
#define IOT_BRM_EVT_OV_THR_TIME_MIN 10
|
|
#define IOT_BRM_EVT_OV_THR_TIME_MAX 99
|
|
|
|
/* define voltage threshold range for phase failure check, unit is 0.1V,
|
|
* see DL/T645-2007-14
|
|
*/
|
|
#define IOT_BRM_EVT_PF_THR_V_MIM 1200 /* 220V * 50% */
|
|
#define IOT_BRM_EVT_PF_THR_V_MAX 1540 /* 220V * 70% */
|
|
/* define voltage threshold range for phase failure check, unit is 0.0001A,
|
|
* see DL/T645-2007-14
|
|
*/
|
|
#define IOT_BRM_EVT_PF_THR_I_MIM 8000 /* 160A * 0.5% */
|
|
#define IOT_BRM_EVT_PF_THR_I_MAX 32000 /* 160A * 2% */
|
|
/* define check delay time range for phase failure, unit is 1s,
|
|
* see DL/T645-2007-14.
|
|
*/
|
|
#define IOT_BRM_EVT_PF_THR_TIME_MIN 10
|
|
#define IOT_BRM_EVT_PF_THR_TIME_MAX 99
|
|
|
|
/* define current threshold range for over current check, unit is 0.1A,
|
|
* see DL/T645-2007-14
|
|
*/
|
|
#define IOT_BRM_EVT_OI_THR_I_MIN 656 /* 125A * 1.05 * 0.5 */
|
|
#define IOT_BRM_EVT_OI_THR_I_MAX 12600 /* 800A * 1.05 * 1.5 */
|
|
/* define check delay time range for over current, unit is 1s,
|
|
* see DL/T645-2007-14.
|
|
*/
|
|
#define IOT_BRM_EVT_OI_THR_TIME_MIN 10
|
|
#define IOT_BRM_EVT_OI_THR_TIME_MAX 99
|
|
|
|
/* define rate threshold range for voltage unbalance check, unit is 0.01%,
|
|
* see DL/T645-2007-14
|
|
*/
|
|
#define IOT_BRM_EVT_UBV_THR_RATE_MIN 1000 /* 10.00% */
|
|
#define IOT_BRM_EVT_UBV_THR_RATE_MAX 9000 /* 90.00% */
|
|
/* define check delay time range for voltage unbalance, unit is 1s,
|
|
* see DL/T645-2007-14.
|
|
*/
|
|
#define IOT_BRM_EVT_UBV_THR_TIME_MIN 10
|
|
#define IOT_BRM_EVT_UBV_THR_TIME_MAX 99
|
|
|
|
#if (IOT_BRM_ENABLE)
|
|
|
|
/* define event id */
|
|
typedef enum {
|
|
iot_brm_evt_id_switch_trip = 14, /* breaker switching trip */
|
|
iot_brm_evt_id_switch_on = 15, /* breaker switching on */
|
|
iot_brm_evt_id_uv_a = 17, /* A phase under voltage */
|
|
iot_brm_evt_id_ov_a = 18, /* A phase over voltage */
|
|
iot_brm_evt_id_oi_a = 20, /* A phase over current */
|
|
iot_brm_evt_id_pf_a = 23, /* A phase phase failure */
|
|
iot_brm_evt_id_uv_b = 33, /* B phase under voltage */
|
|
iot_brm_evt_id_ov_b = 34, /* B phase over voltage */
|
|
iot_brm_evt_id_oi_b = 36, /* B phase over current */
|
|
iot_brm_evt_id_pf_b = 39, /* B phase phase failure */
|
|
iot_brm_evt_id_uv_c = 49, /* C phase under voltage */
|
|
iot_brm_evt_id_ov_c = 50, /* C phase over voltage */
|
|
iot_brm_evt_id_oi_c = 52, /* C phase over current */
|
|
iot_brm_evt_id_pf_c = 55, /* C phase phase failure */
|
|
iot_brm_evt_id_meter_chge = 62, /* meter add and delete event */
|
|
iot_brm_evt_id_qd = 63, /* qiedian event */
|
|
iot_brm_evt_id_unbalance_v = 66, /* unbalance of voltage */
|
|
iot_brm_evt_id_unbalance_i = 67, /* unbalance of current */
|
|
iot_brm_evt_id_pd = 69, /* power down event */
|
|
iot_brm_evt_adp_id = 76, /* brm_adp status change event */
|
|
iot_brm_evt_id_max = 100,
|
|
} iot_brm_evt_id_t;
|
|
|
|
#pragma pack(push) /* save the pack status */
|
|
#pragma pack(1) /* 1 byte align */
|
|
|
|
/* define event common thresholds */
|
|
typedef struct _iot_brm_evt_common_thr {
|
|
/* The stability threshold is event occurrence */
|
|
uint8_t stable_thr_enter;
|
|
/* stability threshold for event exit */
|
|
uint8_t stable_thr_exit;
|
|
} iot_brm_evt_common_thr_t;
|
|
|
|
/* threshold parameters data */
|
|
typedef struct _iot_brm_evt_thr {
|
|
/* event common threshold structure */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* save event private threshold data */
|
|
uint8_t thr_data[IOT_BRM_EVT_THR_DATA_MAX_LEN];
|
|
} iot_brm_evt_thr_t;
|
|
|
|
/* qiedian event private thresholds */
|
|
typedef struct _iot_brm_evt_qd_pri_thr {
|
|
/* current threshold for qiedian event occurrence, uint is 0.001A */
|
|
int32_t enter_i_thr;
|
|
/* current threshold for qiedian event exit, uint is 0.001A */
|
|
int32_t exit_i_thr;
|
|
} iot_brm_evt_qd_pri_thr_t;
|
|
|
|
/* threshold parameters of qiedian event */
|
|
typedef struct _iot_brm_evt_qd_thr {
|
|
/* common thresholds */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* qiedian event private thresholds */
|
|
iot_brm_evt_qd_pri_thr_t pri_thr;
|
|
} iot_brm_evt_qd_thr_t;
|
|
|
|
/* under voltage event private thresholds */
|
|
typedef struct _iot_brm_evt_under_voltage_pri_thr {
|
|
/* voltage threshold for under voltage event, uint is 0.1V */
|
|
uint16_t v_thr;
|
|
} iot_brm_evt_uv_pri_thr_t;
|
|
|
|
/* threshold parameters of under voltage event */
|
|
typedef struct _iot_brm_evt_under_voltage_thr {
|
|
/* common thresholds */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* under voltage event private thresholds */
|
|
iot_brm_evt_uv_pri_thr_t pri_thr;
|
|
} iot_brm_evt_uv_thr_t;
|
|
|
|
/* over voltage event private thresholds */
|
|
typedef struct _iot_brm_evt_over_voltage_pri_thr {
|
|
/* voltage threshold for over voltage event, uint is 0.1V */
|
|
uint16_t v_thr;
|
|
} iot_brm_evt_ov_pri_thr_t;
|
|
|
|
/* threshold parameters of over voltage event */
|
|
typedef struct _iot_brm_evt_ov_thr {
|
|
/* common thresholds */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* over voltage event private thresholds */
|
|
iot_brm_evt_ov_pri_thr_t pri_thr;
|
|
} iot_brm_evt_ov_thr_t;
|
|
|
|
/* over current event private thresholds */
|
|
typedef struct _iot_brm_evt_over_current_pri_thr {
|
|
/* current threshold for over current event, uint is 0.1A */
|
|
uint16_t i_thr;
|
|
} iot_brm_evt_oi_pri_thr_t;
|
|
|
|
/* threshold parameters of over current event */
|
|
typedef struct _iot_brm_evt_over_current_thr {
|
|
/* common thresholds */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* over current event private thresholds */
|
|
iot_brm_evt_oi_pri_thr_t pri_thr;
|
|
} iot_brm_evt_oi_thr_t;
|
|
|
|
/* phase failure event private thresholds */
|
|
typedef struct _iot_brm_evt_phase_failure_pri_thr {
|
|
/* voltage threshold for phase failure event, uint is 0.1V */
|
|
uint16_t v_thr;
|
|
/* current threshold for phase failure event, uint is 0.0001A */
|
|
int32_t i_thr;
|
|
} iot_brm_evt_pf_pri_thr_t;
|
|
|
|
/* threshold parameters of phase failure event */
|
|
typedef struct _iot_brm_evt_pf_thr {
|
|
/* common thresholds */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* phase failure event private thresholds */
|
|
iot_brm_evt_pf_pri_thr_t pri_thr;
|
|
} iot_brm_evt_pf_thr_t;
|
|
|
|
/* voltage or current unbalance event private thresholds */
|
|
typedef struct _iot_brm_evt_unbalance_pri_thr {
|
|
/* voltage or current unbalance rate threshold for current unbalance event,
|
|
* uint is 0.01%.
|
|
*/
|
|
uint16_t rate_thr;
|
|
} iot_brm_evt_unbalance_pri_thr_t;
|
|
|
|
/* threshold parameters of current unbalance event */
|
|
typedef struct _iot_brm_evt_unbalance_thr {
|
|
/* common thresholds */
|
|
iot_brm_evt_common_thr_t comm_thr;
|
|
/* voltage or current unbalance event private thresholds */
|
|
iot_brm_evt_unbalance_pri_thr_t pri_thr;
|
|
} iot_brm_evt_unbalance_thr_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
/* event information descriptor */
|
|
typedef struct {
|
|
/* flag to mark if the event happens, but it hasn't been handled yet */
|
|
uint8_t pend;
|
|
/* event occurrence count */
|
|
uint32_t cnt;
|
|
/* event add counter */
|
|
uint8_t add_cnt;
|
|
} iot_brm_evt_info_t;
|
|
|
|
/**
|
|
* @brief iot_brm_evt_init() - event initialization
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @param thr: pointer to threshold data, if is NULL, default threshold
|
|
* parameters are used.
|
|
* @param rpt_en: 1 - enable report, 0 - not.
|
|
* @retval ERR_OK -- for success case.
|
|
* @retval othersie -- error code.
|
|
*/
|
|
uint8_t iot_brm_evt_init(iot_brm_evt_id_t id, void *thr, uint8_t rpt_en);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_status_load() - event status load according to the last
|
|
* record
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
*/
|
|
void iot_brm_evt_status_load(iot_brm_evt_id_t id);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_set() - set event to prepare reporting
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
*/
|
|
void iot_brm_evt_set(iot_brm_evt_id_t id);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_timeout() - event periodic hadnling function
|
|
*/
|
|
void iot_brm_evt_timeout(void);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_get_info() - get events info.
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @param info: return events info.
|
|
* @retval ERR_OK -- for success case.
|
|
* @retval othersie -- error code.
|
|
*/
|
|
uint8_t iot_brm_evt_get_info(iot_brm_evt_id_t id, iot_brm_evt_info_t *info);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_set_thr() - setting threshold parameters for events
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @param thr: pointer to threshold data.
|
|
* @retval ERR_OK -- for success case.
|
|
* @retval othersie -- error code.
|
|
*/
|
|
uint8_t iot_brm_evt_set_thr(iot_brm_evt_id_t id, void *thr);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_clear_pend() - clear pending event status if it is set.
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
*/
|
|
void iot_brm_evt_clear_pend(iot_brm_evt_id_t id);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_get_thr() - get threshold data for events
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @param thr: pointer to threshold data.
|
|
* @retval: pointer to threshold data.
|
|
*/
|
|
uint8_t *iot_brm_evt_get_thr(iot_brm_evt_id_t id);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_get_comm_thr() - get comm threshold data for events
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @retval: pointer to event common thresholds.
|
|
*/
|
|
iot_brm_evt_common_thr_t *iot_brm_evt_get_comm_thr(iot_brm_evt_id_t id);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_cmd() - enable or disable event check
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @param en: 1 - enable, 0 - disable.
|
|
*/
|
|
void iot_brm_evt_cmd(iot_brm_evt_id_t id, uint8_t en);
|
|
|
|
/**
|
|
* @brief iot_brm_evt_get_is_en() - judge event enable or disable
|
|
* @param id: event id, see iot_brm_evt_id_t.
|
|
* @retval: 1 - enable, 0 - disable.
|
|
*/
|
|
uint8_t iot_brm_evt_get_is_en(iot_brm_evt_id_t id);
|
|
|
|
/**
|
|
* @brief: iot_brm_evt_qd_check() - check for qiedian event.
|
|
*/
|
|
void iot_brm_evt_qd_check(void);
|
|
|
|
#if IOT_BRM_METER_RUN_EVT_CHECK_EN
|
|
|
|
/**
|
|
* @brief: iot_brm_evt_switch_change_check() - check for switch trip / on event.
|
|
*/
|
|
void iot_brm_evt_switch_change_check(void);
|
|
|
|
/**
|
|
* @brief: iot_brm_evt_meter_run_evt_check() - check for meter run event,
|
|
* please call it once every second .
|
|
*/
|
|
void iot_brm_evt_meter_run_evt_check(void);
|
|
|
|
#else /* IOT_BRM_METER_RUN_EVT_CHECK_EN */
|
|
|
|
#define iot_brm_evt_switch_change_check()
|
|
|
|
#define iot_brm_evt_meter_run_evt_check()
|
|
|
|
#endif /* IOT_BRM_METER_RUN_EVT_CHECK_EN */
|
|
|
|
/**
|
|
* @brief: iot_brm_evt_node_chge_check() - check for meter node change event.
|
|
*/
|
|
void iot_brm_evt_node_chge_check(void);
|
|
|
|
/**
|
|
* @brief: iot_brm_evt_pd_check() - check for power down event.
|
|
* @param is_down: 1 - power down, 0 - power on.
|
|
*/
|
|
void iot_brm_evt_pd_check(uint8_t is_down);
|
|
|
|
#endif /* IOT_BRM_ENABLE */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __IOT_BRM_EVT_H */
|
|
|