228 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			228 lines
		
	
	
		
			8.1 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 PROTO_CONN_LESS_H
 | |
| #define PROTO_CONN_LESS_H
 | |
| 
 | |
| /* os shim includes */
 | |
| #include "os_types_api.h"
 | |
| #include "iot_utils_api.h"
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| /* pack for the structures in the whole file */
 | |
| #pragma pack(push) /* save the pack status */
 | |
| #pragma pack(1) /* 1 byte align */
 | |
| 
 | |
| /* connectionless application protocol version */
 | |
| #define CONN_LESS_APP_PROTO_VERSION                 0x01
 | |
| 
 | |
| /* connectionless application protocol id definitions */
 | |
| #define CONN_LESS_APP_ID_METER_R                    (0xFF01)
 | |
| #define CONN_LESS_APP_ID_CONFIG_ACK                 (0xFF02)
 | |
| #define CONN_LESS_APP_ID_DATA_PUSH                  (0xFF03)
 | |
| #define CONN_LESS_APP_ID_CORRECT_TIME               (0xFF04)
 | |
| #define CONN_LESS_APP_ID_TSFM_INFO_RPT              (0xFF05)
 | |
| #define CONN_LESS_APP_ID_SUNSOLAR                   (0xFF06)
 | |
| #define CONN_LESS_APP_ID_CONFIG                     (0xFF07)
 | |
| 
 | |
| /* connectionless application protocol port definitions */
 | |
| #define CONN_LESS_APP_PORT                          (0x11)
 | |
| 
 | |
| /* connectionless frame priority definition */
 | |
| #define CONN_LESS_CFG_PRIO                          3
 | |
| #define CONN_LESS_APP_PRIO_METER_READ               3
 | |
| #define CONN_LESS_APP_PRIO_CORRECT_TIME             3
 | |
| 
 | |
| /* connectionless application data direction: master->master */
 | |
| #define CONN_LESS_APP_DIR_M2M                       2
 | |
| 
 | |
| /* connectionless application data direction: slave->master */
 | |
| #define CONN_LESS_APP_DIR_SLAVE                     1
 | |
| 
 | |
| /* connectionless application data direction: master->slave */
 | |
| #define CONN_LESS_APP_DIR_MASTER                    0
 | |
| 
 | |
| /* connectionless protocol type definition */
 | |
| #define CONN_LESS_PROTO_TYPE_TRANSPARENT            0
 | |
| #define CONN_LESS_PROTO_TYPE_645_1997               1
 | |
| #define CONN_LESS_PROTO_TYPE_645_2007               2
 | |
| #define CONN_LESS_PROTO_TYPE_69845                  3
 | |
| 
 | |
| /* define config target device ID */
 | |
| #define CONN_LESS_CFG_TARGET_ID_CCO                 0
 | |
| #define CONN_LESS_CFG_TARGET_ID_STA                 1
 | |
| 
 | |
| /* connectionless device type definitions */
 | |
| #define CONN_LESS_DEV_TYPE_METER_CONTROLLER         (1)
 | |
| #define CONN_LESS_DEV_TYPE_CONCENTRATOR             (2)
 | |
| #define CONN_LESS_DEV_TYPE_POWER_METER              (3)
 | |
| #define CONN_LESS_DEV_TYPE_REPEAT                   (4)
 | |
| #define CONN_LESS_DEV_TYPE_COLLECTOR_2              (5)
 | |
| #define CONN_LESS_DEV_TYPE_COLLECTOR_1              (6)
 | |
| #define CONN_LESS_DEV_TYPE_THREE_PHASE_METER        (7)
 | |
| 
 | |
| /* connectionless device physical phase line definition */
 | |
| #define CONN_LESS_DEV_PHASE_TYPE_DEFAULT            0
 | |
| #define CONN_LESS_DEV_PHASE_TYPE_A                  1
 | |
| #define CONN_LESS_DEV_PHASE_TYPE_B                  2
 | |
| #define CONN_LESS_DEV_PHASE_TYPE_C                  3
 | |
| 
 | |
| /* define the maximum response message allowed for connectionless meter
 | |
|  * reading.
 | |
|  */
 | |
| #define PROTO_CONN_LESS_MR_RESPONSE_MAX_SIZE        460
 | |
| 
 | |
| /* defining config target device type identifier mask */
 | |
| #define CONN_LESS_CFG_TARGET_ID_MSK_CCO \
 | |
|     (1 << CONN_LESS_CFG_TARGET_ID_CCO)
 | |
| #define CONN_LESS_CFG_TARGET_ID_MSK_STA \
 | |
|     (1 << CONN_LESS_CFG_TARGET_ID_STA)
 | |
| 
 | |
| /* connectionless devive push data type */
 | |
| #define CONN_LESS_DEV_PUSH_DATA_TYPE_FWD            0
 | |
| #define CONN_LESS_DEV_PUSH_DATA_TYPE_EVT            1
 | |
| 
 | |
| /* connectionless application protocol frame header */
 | |
| typedef struct _proto_conn_less_hdr {
 | |
|     uint8_t     port;
 | |
|     uint16_t    id;
 | |
| } proto_conn_less_hdr_t;
 | |
| 
 | |
| /* connectionless application protocol ppm describe */
 | |
| typedef struct _proto_conn_less_ppm_desc {
 | |
|     /* ppm value */
 | |
|     int8_t value;
 | |
|     /* reserve */
 | |
|     uint8_t reserve;
 | |
| } proto_conn_less_ppm_desc_t;
 | |
| 
 | |
| /* connectionless meter reading protocol */
 | |
| typedef struct _proto_conn_less_mr_t {
 | |
|     /* data length */
 | |
|     uint32_t    data_len        :11,
 | |
|     /* flag of source id extension,
 | |
|      * only used link_type is IOT_SG_LINK_TYPE_APP
 | |
|      * flag of add a new request after the req list head,
 | |
|      * only used link_type is IOT_SG_LINK_TYPE_CUS
 | |
|      */
 | |
|                 src_id_ext      :1,
 | |
|     /* meter reading timeout, uint is 100ms */
 | |
|                 mr_timeout      :8,
 | |
|     /* data type. see GW_APP_DATA_TYPE_XXX */
 | |
|                 data_type       :4,
 | |
|     /* direction flag */
 | |
|                 dir             :2,
 | |
|     /* m2m mdoe to switch mode */
 | |
|                 m2m_switch_mode :1,
 | |
|     /* source id, only used link_type is IOT_SG_LINK_TYPE_APP */
 | |
|                 src_id          :3,
 | |
|     /* timeout retry count allowed */
 | |
|                 retry_cnt       :2;
 | |
|     /* packet sequence */
 | |
|     uint16_t    seq;
 | |
|     union {
 | |
|         /* ack bitmap only for up link valid */
 | |
|         uint16_t                   up_ack_bm;
 | |
|         /* conn less ppm describe only for down link valid */
 | |
|         proto_conn_less_ppm_desc_t dl_ppm_desc;
 | |
|     } option;
 | |
|     /* data */
 | |
|     uint8_t     data[0];
 | |
| } proto_conn_less_mr_t;
 | |
| 
 | |
| /* connectionless meter push data */
 | |
| typedef struct _proto_conn_less_push_data_t {
 | |
|     /* data length */
 | |
|     uint32_t    data_len        :12,
 | |
|     /* direction flag */
 | |
|                 dir             :2,
 | |
|     /* data type, see CONN_LESS_DEV_PUSH_DATA_TYPE_XXX */
 | |
|                 data_type       :2,
 | |
|     /* reserve for future */
 | |
|                 rsvd            :16;
 | |
|     /* packet sequence */
 | |
|     uint16_t    seq;
 | |
|     /* options */
 | |
|     uint16_t    option;
 | |
|     /* address of meter, little endian */
 | |
|     uint8_t     addr[IOT_MAC_ADDR_LEN];
 | |
|     /* data */
 | |
|     uint8_t     data[0];
 | |
| } proto_conn_less_push_data_t;
 | |
| 
 | |
| /* configuration acknowledgement message */
 | |
| typedef struct _proto_conn_less_config_ack {
 | |
|     /* current working band ID */
 | |
|     uint8_t band_id;
 | |
| } proto_conn_less_config_ack_t;
 | |
| 
 | |
| /* connectionless correcting time message layout */
 | |
| typedef struct _proto_conn_less_correct_time {
 | |
|     /* len of payload */
 | |
|     uint16_t    len;
 | |
|     /* payload label */
 | |
|     uint8_t     data[0];
 | |
| } proto_conn_less_correct_time_t;
 | |
| 
 | |
| /* target configuration command message layout */
 | |
| typedef struct _proto_conn_less_mode_cfg {
 | |
|     /* band ID to be configured, see PLC_LIB_FREQ_BAND_X */
 | |
|     uint8_t     band_id;
 | |
|     /* configuring effective duration, uint is sec */
 | |
|     uint8_t     dur;
 | |
|     /* the target device ID group that needs to respond to this command.
 | |
|      * see CONN_LESS_CFG_TARGET_ID_MSK_XXX.
 | |
|      */
 | |
|     uint32_t    target_id_mask;
 | |
| } proto_conn_less_mode_cfg_t;
 | |
| 
 | |
| /* connectionless report tsfm info data layout */
 | |
| typedef struct _proto_conn_less_tsfm_info_rpt {
 | |
|     /* protocol version */
 | |
|     uint8_t     ver              :4,
 | |
|     /* reserve for future */
 | |
|                 reserve1         :4;
 | |
|     /* protocol type, see CONN_LESS_PROTO_TYPE_XXX */
 | |
|     uint8_t     pro_type         :4,
 | |
|     /* device type, see CONN_LESS_DEV_TYPE_XXX */
 | |
|                 dev_type         :4;
 | |
|     /* first physical phase line, see CONN_LESS_DEV_PHASE_TYPE_XXX */
 | |
|     uint8_t     phase_1          :2,
 | |
|     /* second physical phase line, see CONN_LESS_DEV_PHASE_TYPE_XXX */
 | |
|                 phase_2          :2,
 | |
|     /* third physical phase line, see CONN_LESS_DEV_PHASE_TYPE_XXX */
 | |
|                 phase_3          :2,
 | |
|     /* reserve for future */
 | |
|                 reserve2         :2;
 | |
|     /* sta mac address, little-endian */
 | |
|     uint8_t     sta_mac[IOT_MAC_ADDR_LEN];
 | |
|     /* cco mac address, little-endian */
 | |
|     uint8_t     cco_mac[IOT_MAC_ADDR_LEN];
 | |
|     /* tsfm address, little-endian */
 | |
|     uint8_t     tsfm_mac[IOT_MAC_ADDR_LEN];
 | |
| } proto_conn_less_tsfm_info_rpt_t;
 | |
| 
 | |
| #pragma pack(pop)/* restore the pack status */
 | |
| 
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* PROTO_CONN_LESS_H */
 |