154 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			154 lines
		
	
	
		
			5.6 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_BRM_MR_H
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MR_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if (IOT_BRM_ENABLE && PLC_SUPPORT_STA_ROLE)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define the maximum number of customers supported */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MR_CUSTOMER_INVALID         0xFF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* meter read canmmand prio defining */
							 | 
						||
| 
								 | 
							
								typedef enum {
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_cmd_prio_0,
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_cmd_prio_1,
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_cmd_prio_max,
							 | 
						||
| 
								 | 
							
								} iot_brm_mr_cmd_prio_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* meter read canmmand type defining */
							 | 
						||
| 
								 | 
							
								typedef enum {
							 | 
						||
| 
								 | 
							
								    /* normal connectionless meter read from sg app */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_normal,
							 | 
						||
| 
								 | 
							
								    /* connectionless meter read for assembly check */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_ass_chk,
							 | 
						||
| 
								 | 
							
								    /* connectionless transmit forward frame witch from sg app */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_fwd_sg,
							 | 
						||
| 
								 | 
							
								    /* connectionless transmit forward frame from rs485 */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_fwd_rs485,
							 | 
						||
| 
								 | 
							
								    /* connectionless transmit frame witch from rs485 */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_nor_rs485,
							 | 
						||
| 
								 | 
							
								    /* connectionless transmit forward frame from multifunction rs485 */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_fwd_mf_rs485,
							 | 
						||
| 
								 | 
							
								    /* connectionless transmit frame witch from multifunction rs485 */
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_type_nor_mf_rs485,
							 | 
						||
| 
								 | 
							
								} iot_brm_mr_type_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief - callback function to transfer data to customers after read done
							 | 
						||
| 
								 | 
							
								 * @param arg: meter reading buffer handle
							 | 
						||
| 
								 | 
							
								 * @param ext_sn: meter reading buffer handle
							 | 
						||
| 
								 | 
							
								 * @param addr: meter reading buffer handle
							 | 
						||
| 
								 | 
							
								 * @param rsp_bm:  eter read respose status bitmap. each bit reflect respose
							 | 
						||
| 
								 | 
							
								 *        status for a frame. the lowest bit corresponding to the first frame
							 | 
						||
| 
								 | 
							
								 *        in the read request.
							 | 
						||
| 
								 | 
							
								 * @param pkt: iot_pkt with mr response, the ownership will be transferred
							 | 
						||
| 
								 | 
							
								 *             to callback. if it's NULL, meter reading timeout.
							 | 
						||
| 
								 | 
							
								 * @param type: meter read canmmand type, see iot_brm_mr_type_t.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								typedef void (*iot_brm_mr_done_func_t)(void *arg, uint16_t ext_sn,
							 | 
						||
| 
								 | 
							
								    uint8_t *addr, iot_pkt_t *pkt, uint16_t rsp_bm, iot_brm_mr_type_t type);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_refresh() - meter reading buffer refresh
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_mr_buf_refresh(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_cmd_match() - matching Meter Reading Response Packet
							 | 
						||
| 
								 | 
							
								 * @param sn:     seq num of meter reading response.
							 | 
						||
| 
								 | 
							
								 * @param pkt:    iot_pkt with meter reading response. this pkt will be
							 | 
						||
| 
								 | 
							
								 *                consumed
							 | 
						||
| 
								 | 
							
								 * @param rsp_bm:  eter read respose status bitmap. each bit reflect respose
							 | 
						||
| 
								 | 
							
								 *        status for a frame. the lowest bit corresponding to the first frame
							 | 
						||
| 
								 | 
							
								 *        in the read request.
							 | 
						||
| 
								 | 
							
								 * @retval 1      -- match success.
							 | 
						||
| 
								 | 
							
								 * @retval 0      -- match fail.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_mr_buf_cmd_match(uint16_t sn, iot_pkt_t *pkt,
							 | 
						||
| 
								 | 
							
								    uint16_t rsp_bm);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_cmd_add() - add a meter reading command to mr buff
							 | 
						||
| 
								 | 
							
								 * @param customer_num: customer num.
							 | 
						||
| 
								 | 
							
								 * @param dest_addr:    destination node address, little endian.
							 | 
						||
| 
								 | 
							
								 * @param ext_sn:       customer-initiated meter reading seq number
							 | 
						||
| 
								 | 
							
								 * @param proto_type:   dest node proto type, not currently used. see
							 | 
						||
| 
								 | 
							
								 *                      IOT_BRM_PROTO_TYPE_XXXX.
							 | 
						||
| 
								 | 
							
								 * @param pkt:          meter reading packet. this pkt will be consumed.
							 | 
						||
| 
								 | 
							
								 * @param timeout:      command timeout, uint is ms.
							 | 
						||
| 
								 | 
							
								 * @param prio:         command prio.
							 | 
						||
| 
								 | 
							
								 * @param type:         meter read canmmand type, see iot_brm_mr_type_t.
							 | 
						||
| 
								 | 
							
								 * @param ppm_fix:      current transmission PPM fix value.
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK      -- for success case.
							 | 
						||
| 
								 | 
							
								 * @retval othersie    -- error code.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_mr_buf_cmd_add(uint8_t customer_num,
							 | 
						||
| 
								 | 
							
								    uint8_t *dest_addr, uint16_t ext_sn, uint8_t proto_type, iot_pkt_t *pkt,
							 | 
						||
| 
								 | 
							
								    uint32_t timeout, iot_brm_mr_cmd_prio_t prio, iot_brm_mr_type_t type,
							 | 
						||
| 
								 | 
							
								    int8_t ppm_fix);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_cmd_clean() - clean the read command in Mr buf
							 | 
						||
| 
								 | 
							
								 * @param cus_id:  specified customer id.
							 | 
						||
| 
								 | 
							
								 * @param addr:    specified destination address
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_mr_buf_cmd_clean(uint8_t cus_id, uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_customer_register() - register a customer in meter
							 | 
						||
| 
								 | 
							
								 *        reading buffer.
							 | 
						||
| 
								 | 
							
								 * @param func:   callback function for customer receiving mr response.
							 | 
						||
| 
								 | 
							
								 * @param arg:    callback function arg.
							 | 
						||
| 
								 | 
							
								 * @retval: customer id, if equal to IOT_BRM_MR_CUSTOMER_INVALID, regist fail.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_mr_buf_customer_register(
							 | 
						||
| 
								 | 
							
								    iot_brm_mr_done_func_t func, void *arg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_customer_deregister() - deegister a customer in meter
							 | 
						||
| 
								 | 
							
								 *        reading buffer.
							 | 
						||
| 
								 | 
							
								 * @param cus_id:   specified customer id;
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_mr_buf_customer_deregister(uint8_t cus_id);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_init() - initialize a meter reading buffer
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK      -- for success case.
							 | 
						||
| 
								 | 
							
								 * @retval othersie    -- error code.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_mr_buf_init(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_mr_buf_init() - deinit a meter reading buffer
							 | 
						||
| 
								 | 
							
								 * @param handle: meter reading buffer handle
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_mr_buf_deinit(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* IOT_BRM_ENABLE && PLC_SUPPORT_STA_ROLE */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif  /* IOT_BRM_MR_H */
							 |