Files
kunlun/app/smart_grid/inc/internal/iot_sg_sta_ext.h
2024-09-28 14:24:04 +08:00

323 lines
11 KiB
C

/****************************************************************************
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_SG_STA_EXT_H
#define IOT_SG_STA_EXT_H
/* os shim includes */
#include "os_types_api.h"
/* common includes */
#include "iot_pkt_api.h"
#include "iot_errno_api.h"
/* smart grid internal header files */
#include "iot_sg_sta.h"
#include "iot_sg_sta_ext_ai.h"
#include "iot_sg_sta_ext_fj.h"
#include "iot_sg_sta_ext_js.h"
#include "iot_sg_sta_ext_gw.h"
#include "iot_sg_sta_ext_lr.h"
#include "iot_sg_sta_ext_nli.h"
#include "iot_sg_sta_ext_nw.h"
#include "iot_sg_sta_ext_score.h"
#include "iot_sg_sta_ext_tm.h"
#include "iot_sg_sta_ext_x4.h"
#include "iot_sg_sta_ext_ec.h"
#ifdef __cplusplus
extern "C" {
#endif
/* define extend function read data timeout time,
* uint is IOT_SG_STA_EXT_SM_DELAY
*/
#define IOT_SG_STA_EXT_READ_DATA_TIMEOUT (5)
/* define extend function state machine trigger delay time, uint is 1ms */
#define IOT_SG_STA_EXT_SM_DELAY (2 * 1000)
/* define extend function state machine next meter delay time, uint is 1ms */
#define IOT_SG_STA_EXT_SM_METER_DELAY (500)
/* define extend function state machine trigger min delay time, uint is 1ms */
#define IOT_SG_STA_EXT_SM_MIN_DELAY (50)
/* define drv read meter timeout, uint is 100ms */
#define IOT_SG_STA_EXT_DRV_READ_TIMEOUT (20)
/* define extend function collect task interval time, uint is 1s */
#define IOT_SG_STA_EXT_CLCT_PRD_1MIN (1 * 60)
#define IOT_SG_STA_EXT_CLCT_PRD_5MIN (5 * 60)
#define IOT_SG_STA_EXT_CLCT_PRD_15MIN (15 * 60)
#define IOT_SG_STA_EXT_CLCT_PRD_30MIN (30 * 60)
#define IOT_SG_STA_EXT_CLCT_PRD_60MIN (60 * 60)
#define IOT_SG_STA_EXT_CLCT_PRD_1DAY (60 * 60 * 24)
/* define collection period in collection task structure */
#define IOT_SG_EXT_CLCT_TASK_PERIOD_DEFAULT 0
#define IOT_SG_EXT_CLCT_TASK_PERIOD_15MIN 3
#define IOT_SG_EXT_CLCT_TASK_PERIOD_30MIN 4
#define IOT_SG_EXT_CLCT_TASK_PERIOD_60MIN 5
#define IOT_SG_EXT_CLCT_TASK_PERIOD_DAY 6
#define IOT_SG_EXT_CLCT_TASK_PERIOD_15MIN_LR 13
#define IOT_SG_EXT_CLCT_TASK_PERIOD_30MIN_LR 14
#define IOT_SG_EXT_CLCT_TASK_PERIOD_60MIN_LR 15
#define IOT_SG_EXT_CLCT_TASK_PERIOD_SINGLE 16
/* define load curve state */
#define IOT_SG_STA_EXT_LC_STATE_IDLE (0)
#define IOT_SG_STA_EXT_LC_STATE_SEND (1)
#define IOT_SG_STA_EXT_LC_STATE_WAIT (2)
#define IOT_SG_STA_EXT_LC_STATE_END (3)
/* type of record for power event */
#define IOT_SG_STA_POWER_REC_TYPE_UP (0)
#define IOT_SG_STA_POWER_REC_TYPE_DOWN (1)
#define IOT_SG_STA_POWER_REC_TYPE_CLEAR (2)
/* define index of load curve configuration */
#define IOT_SG_STA_EXT_LC_GX_CFG (0)
#define IOT_SG_STA_EXT_LC_XIAN_CFG (1)
#define IOT_SG_STA_EXT_LC_XIAN_3P_CFG (2)
#define IOT_SG_STA_EXT_LC_PEIWANG (3)
/* define extend function read load data interval time, uint is 1s */
#define IOT_SG_STA_EXT_LC_CFG_PRD_1MIN (60)
#define IOT_SG_STA_EXT_LC_CFG_PRD_5MIN (5 * 60)
#define IOT_SG_STA_EXT_LC_CFG_PRD_15MIN (15 * 60)
#define IOT_SG_STA_EXT_LC_CFG_PRD_30MIN (30 * 60)
#define IOT_SG_STA_EXT_LC_CFG_PRD_60MIN (60 * 60)
#if (IOT_SMART_GRID_EXT_FUNC_ENABLE)
/**
* @brief: sta extended function init.
* @retval: ERR_OK -- initialization success
* @retval: otherwise -- other value for failed case, see ERR_XXX.
*/
uint32_t iot_sg_sta_ext_init(void);
/**
* @brief: sta extended function deinit.
*/
void iot_sg_sta_ext_deinit(void);
/**
* @brief: state machine function for sta extension function.
*/
void iot_sg_sta_ext_sm_func(void);
/**
* @brief: add meter expansion function.
* @param node: the pointer to the meter in node list.
* @retval: ERR_OK -- add meter success
* @retval: otherwise -- other value for failed case, see ERR_XXX.
*/
uint32_t iot_sg_sta_ext_meter_add(iot_sg_sta_node_desc_t *node);
/**
* @brief: delete meter expansion function.
* @param node: the pointer to the meter in node list.
* @retval: ERR_OK -- delete meter success
* @retval: otherwise -- other value for failed case, see ERR_XXX.
*/
uint32_t iot_sg_sta_ext_meter_delete(iot_sg_sta_node_desc_t *node);
/**
* @brief handle extend read data response from meter.
* @param seq: sequence of extend read request.
* @param data_type: data type, see IOT_SG_STA_DATA_TYPE_XXX.
* @param resp_data: extend read data of response from meter.
* @param resp_len: response data length.
* @param req_data: request data of extend read function.
* @param req_len: request data length.
*/
void iot_sg_ext_read_data_handle(uint16_t seq,
uint8_t data_type, uint8_t *resp_data, uint16_t resp_len,
uint8_t *req_data, uint16_t req_len);
/**
* @brief: sta extension function to reset next read data time.
*/
void iot_sg_sta_ext_tm_reset(void);
/**
* @brief set integral point time.
* @param tm: start time.
* @param interval: interval time, uint is 1s.
* @param after_flag: 1 - set integral point time after the start time.
* 0 - set integral point time before the start time.
*/
void iot_sg_ext_set_integral_point(iot_time_tm_t *tm,
int64_t interval, uint8_t after_flag);
/*
* @brief: state machine stop for sta extension function.
*/
void iot_sg_sta_ext_sm_stop_action(void);
/*
* @brief: state machine goto next action for sta extension function.
* @param dur: delay time.
*/
void iot_sg_sta_ext_sm_next_action(uint32_t dur);
/**
* @brief: sta extend task 645 meter read nack check.
* @param req_data: request data of extend read function.
* @param req_len: request data length.
* @param resp_data: extend read data of response from meter.
* @param resp_len: response data length.
* @param ext_addr: extend task current meter mac.
* @retval: ERR_OK -- abnormal ack.
* @retval: otherwise -- normal ack.
*/
uint32_t iot_sg_ext_read_645_nack_check(uint8_t *req_data,
uint16_t req_len, uint8_t *resp_data, uint16_t resp_len, uint8_t *ext_addr);
/**
* @brief: sta extend task 69845 meter read apdu sn get.
* @retval: apdu sn.
*/
uint8_t iot_sg_sta_ext_get_69845_apdu_sn(void);
/**
* @brief: sta extend function dl/t645 - 97 meter response data handle.
* @param req_data: request data of extend read function.
* @param req_len: request data length.
* @param resp_data: extend read data of response from meter.
* @param resp_len: response data length.
* @param ext_addr: extend task current meter mac.
* @retval: ERR_OK -- handle success.
* @retval: otherwise -- handle fail, see ERR_XXX.
*/
uint32_t iot_sg_ext_read_645_97_data_handle(uint16_t seq,
uint8_t data_type, uint8_t *resp_data, uint16_t resp_len,
uint8_t *req_data, uint16_t req_len);
/**
* @brief: sta extend function dl/t 645 - 07 meter response data handle.
* @param req_data: request data of extend read function.
* @param req_len: request data length.
* @param resp_data: extend read data of response from meter.
* @param resp_len: response data length.
* @param ext_addr: extend task current meter mac.
* @param is_nack: returns whether the pkt is NACK
* @retval: ERR_OK -- handle success.
* @retval: otherwise -- handle fail, see ERR_XXX.
*/
uint32_t iot_sg_ext_read_645_07_data_handle(uint16_t seq,
uint8_t data_type, uint8_t *resp_data, uint16_t resp_len,
uint8_t *req_data, uint16_t req_len, uint8_t *is_nack);
/**
* @brief: sta extend function dl/t 698.45 meter response data handle.
* @param req_data: request data of extend read function.
* @param req_len: request data length.
* @param resp_data: extend read data of response from meter.
* @param resp_len: response data length.
* @param ext_addr: extend task current meter mac.
* @retval: ERR_OK -- handle success.
* @retval: otherwise -- handle fail, see ERR_XXX.
*/
uint32_t iot_sg_ext_read_698_data_handle(uint16_t seq,
uint8_t data_type, uint8_t *resp_data, uint16_t resp_len,
uint8_t *req_data, uint16_t req_len);
/**
* @brief: sta node time check;
* @param tm: node time.
* @param max_delta: task interval time.
* @retval: ERR_OK -- check success.
* @retval: otherwise -- other value for failed case, see ERR_XXX.
*/
uint32_t iot_sg_sta_ext_node_tm_check(iot_time_tm_t *tm, int64_t max_delta);
/**
* @brief: sta get lr data next collect time.
* @param start_ts: collect start time.
* @param period: collect period.
* @param curr_tm: current time.
* @retval: next collect time.
*/
iot_time_tm_t iot_sg_ext_get_next_lr_ts(iot_time_tm_t start_ts,
uint16_t period, iot_time_tm_t curr_tm);
/**
* @brief: sta extend get min lenght of filled data.
* @param len: length of data.
* @param fill_len: length of data filled.
* @param unit_len: unit length of data.
* @retval: min length of data filled
*/
uint8_t iot_sg_ext_get_min_data_len(uint8_t len,
uint8_t fill_len, uint8_t unit_len);
/**
* @brief: sta extended function disable.
*/
void iot_sg_sta_ext_disable(void);
#else /* IOT_SMART_GRID_EXT_FUNC_ENABLE */
#define iot_sg_sta_ext_init() (ERR_NOSUPP)
#define iot_sg_sta_ext_deinit()
#define iot_sg_sta_ext_sm_func()
#define iot_sg_sta_ext_meter_add(node)
#define iot_sg_sta_ext_meter_delete(node)
#define iot_sg_ext_read_data_handle(seq, data_type, resp_data, resp_len, \
req_data, req_len)
#define iot_sg_sta_ext_tm_reset()
#define iot_sg_ext_set_integral_point(tm, interval, after_flag)
#define iot_sg_sta_ext_sm_stop_action()
#define iot_sg_sta_ext_sm_next_action(dur)
#define iot_sg_ext_read_645_nack_check(req_data, req_len, resp_data, \
resp_len, ext_addr) (ERR_FAIL)
#define iot_sg_sta_ext_get_69845_apdu_sn() (0)
#define iot_sg_ext_read_645_97_data_handle(seq, data_type, resp_data, \
resp_len, req_data, req_len) (ERR_NOSUPP)
#define iot_sg_ext_read_645_07_data_handle(seq, data_type, resp_data, \
resp_len, req_data, req_len, is_nack) (ERR_NOSUPP)
#define iot_sg_ext_read_698_data_handle(seq, data_type, resp_data, \
resp_len, req_data, req_len) (ERR_NOSUPP)
#define iot_sg_sta_ext_node_tm_check(tm, max_delta) (ERR_NOSUPP)
#define iot_sg_ext_get_next_lr_ts(start_ts, period, curr_tm) (0)
#define iot_sg_ext_get_min_data_len(len, fill_len, unit_len) (0)
#define iot_sg_sta_ext_disable()
#endif /* IOT_SMART_GRID_EXT_FUNC_ENABLE */
#ifdef __cplusplus
}
#endif
#endif /* IOT_SG_STA_EXT_H */