Files
kunlun/app/iot_sunsolar_app/inc/proto_645_sunsolar.h
2024-09-28 14:24:04 +08:00

225 lines
8.0 KiB
C

/****************************************************************************
Copyright(c) 2024 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_645_SUNSOLAR_H
#define PROTO_645_SUNSOLAR_H
/* os shim includes */
#include "os_types_api.h"
/* ------------------------ dlt645 DI for solar ---------------------------- */
/* DI: read sunsolar module SN */
#define PROTO_645_2007_EXT_SOLR_DI_READ_PVSN (0x04001516u)
/* DI: set sunsolar module SN */
#define PROTO_645_2007_EXT_SOLR_DI_SET_PVSN (0x04001517u)
/* DI: reboot sunsolar module */
#define PROTO_645_2007_EXT_SOLR_DI_DEV_REBOOT (0x04001518u)
/* DI: set rsd status */
#define PROTO_645_2007_EXT_SOLR_DI_SET_RSD (0x04001525u)
/* DI: read rsd current status */
#define PROTO_645_2007_EXT_SOLR_DI_READ_RSD (0x04001526u)
/* DI: heartbeat from CCTT */
#define PROTO_645_2007_EXT_SOLR_DI_CCTT_HEARTBEAT (0x04001537u)
/* DI: set heartbeat enable or disable */
#define PROTO_645_2007_EXT_SOLR_DI_SET_HEARTBEAT (0x04001538u)
/* DI: read hearbeat status */
#define PROTO_645_2007_EXT_SOLR_DI_READ_HEARTBEAT (0x04001539u)
/* DI: read sunsolar module datas, voltage ... */
#define PROTO_645_2007_EXT_SOLR_DI_READ_SOLAR_DATA (0xFFB00001u)
/* DI: read sunsolar collector current data */
#define PROTO_645_2007_EXT_SOLR_DI_READ_CUR_DATA (0xFFB00002u)
/* DI: upgrade data buffer */
#define PROTO_645_2007_EXT_SOLR_DI_TRANS_UPGRADE_DATA (0xFFB00003u)
/* DI: query upgrade data bitmap */
#define PROTO_645_2007_EXT_SOLR_DI_QUERY_UPGRADE_BM (0xFFB00004u)
/* DI: after device recv done datas, execute device upgrade */
#define PROTO_645_2007_EXT_SOLR_DI_EXECUTE_UPGRADE (0xFFB00005u)
/* DI: read solar sta frozen data */
#define PROTO_645_2007_EXT_SOLR_DI_READ_FROZEN_DATA (0xFFB0000Du)
/* sunsolar tlv data type */
#define PROTO_645_SUNSOLAR_TLV_LINKSTATE 1
#define PROTO_645_SUNSOLAR_TLV_VOLTAGE 2
#define PROTO_645_SUNSOLAR_TLV_CURRENT 3
#define PROTO_645_SUNSOLAR_TLV_TEMPERATURE 4
#define PROTO_645_SUNSOLAR_TLV_PLC_LINKSTATISTICS 5
#define PROTO_645_SUNSOLAR_TLV_PV_SN_STR 6
#define PROTO_645_SUNSOLAR_TLV_VERSION 7
#define PROTO_645_SUNSOLAR_TLV_RSD_STATUS 9
#define PROTO_645_SUNSOLAR_TLV_PERIOD_ENERGY 10
#define PROTO_645_SUNSOLAR_TLV_HIS_TOTAL_ENERGY 11
#define PROTO_645_SUNSOLAR_TLV_REBOOT_CNT 12
/* define sunsolar max tlv data type count */
#define PROTO_645_SUNSOLAR_TLV_TYPE_MAX 16
#define PROTO_645_SUNSOLAR_TLV_TYPE_ALL (0x0FFF)
#define PROTO_645_SUNSOLAR_REBOOT_TYPE_NORMAL 0
#define PROTO_645_SUNSOLAR_REBOOT_TYPE_ASSERT 1
#define PROTO_645_SUNSOLAR_REBOOT_TYPE_W_ZERO_ADDR 2
#define PROTO_645_SUNSOLAR_REBOOT_TYPE_MAX 2
/* proto 645 cmd magic */
#define PROTO_645_SUNSOLAR_CMD_EN_MAGIC (0XAA)
#define PROTO_645_SUNSOLAR_CMD_DIS_MAGIC (0X55)
/* local rsd status change to magic */
#define RSD_STATUS_2_MAGIC(rsd_status) \
(rsd_status) ? \
(PROTO_645_SUNSOLAR_CMD_EN_MAGIC & 0xF) : \
(PROTO_645_SUNSOLAR_CMD_DIS_MAGIC & 0xF)
/* start code for load curve record */
#define PROTO_645_SOLR_LOAD_CURVE_START_CODE 0xA0
/* finish code for load curve record */
#define PROTO_645_SOLR_LOAD_CURVE_END_CODE 0xE5
/* data structure version for freeze data: version0 */
#define PROTO_645_SOLR_FROZEN_DATA_VER_0 (0)
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* sunsolar tlv data type request */
typedef struct _proto_645_tlv_type_req {
/* each bit represents a type */
uint16_t value;
} proto_645_tlv_type_req_t;
/* report data information use tag, length, value module */
typedef struct _proto_645_sunsolar_tlv_data {
/* data type: see PROTO_645_SUNSOLAR_TLV_XX */
uint8_t type :7,
/* if is last type data set to 1 */
flg :1;
/* include data length */
uint8_t len;
/* data */
uint8_t data[0];
} proto_645_sunsolar_tlv_data_t;
/* link status */
typedef struct _proto_645_sunsolar_link_state {
/* link type, online/offline status */
uint8_t is_online;
} proto_645_sunsolar_link_state_t;
/* voltage */
typedef struct _proto_645_sunsolar_voltage {
/* voltage unit:0.1V */
uint16_t vol;
} proto_645_sunsolar_voltage_t;
/* current */
typedef struct _proto_645_sunsolar_current {
/* current unit:0.001A */
uint16_t cur;
} proto_645_sunsolar_current_t;
/* temperature */
typedef struct _proto_645_sunsolar_temperature {
/* temperature unit:0.1degrees */
int16_t temp;
} proto_645_sunsolar_temperature_t;
/* plc link statistics */
typedef struct _proto_645_sunsolar_plc_link_stat {
/* the last pkt rssi */
uint8_t rssi;
/* the last pkt snr */
int8_t snr;
} proto_645_sunsolar_plc_link_stat_t;
/* period power output */
typedef struct _proto_645_sunsolar_period_energy {
/* period power output, unit: mWh */
uint32_t period_total_energy;
} proto_645_sunsolar_period_energy_t;
/* history power output */
typedef struct _proto_645_sunsolar_total_his_energy {
/* history total energy output, unit: Wh */
uint64_t his_total_energy;
} proto_645_sunsolar_total_his_energy_t;
/* reboot count struct */
typedef struct _proto_645_sunsolar_reboot_cnt {
/* reboot count */
uint16_t reboot_cnt;
} proto_645_sunsolar_reboot_cnt_t;
/* reboot type struct */
typedef struct _proto_645_sunsolar_dev_reboot {
/* reboot_type, see PROTO_645_SUNSOLAR_REBOOT_TYPE_XX. */
uint8_t reboot_type;
} proto_645_sunsolar_dev_reboot_t;
/* heartbeat function config command layout */
typedef struct _proto_645_sunsolar_heartbeat_set {
/* heartbeat function control cmd magic,
* see PROTO_645_SUNSOLAR_CMD_XX_MAGCI.
*/
uint8_t cmd_magic;
} proto_645_sunsolar_heartbeat_set_t;
/* read rsd cfg status and real status*/
typedef struct _proto_645_sunsolar_read_rsd {
/* config rsd status: 0xA, open; 0x5, close; */
uint8_t last_cmd :4,
/* real time rsd status: 0xA, open; 0x5, close; */
real_status :4;
/* rsd voltage unit:0.1v*/
uint16_t real_volt;
} proto_645_sunsolar_read_rsd_t;
/* rsd config status */
typedef struct _proto_645_sunsolar_set_rsd {
/* master device set rsd time */
uint32_t tm;
/* rsd direct control command magic,
* see PROTO_645_SUNSOLAR_CMD_XX_MAGCI.
*/
uint8_t cmd_magic;
} proto_645_sunsolar_set_rsd_t;
/* sunsolar module Version */
typedef struct _proto_645_sunsolar_mod_ver {
uint32_t sw_ver;
uint32_t hw_ver;
} proto_645_sunsolar_mod_ver_t;
/* collect upgrade data */
typedef struct _proto_645_sunsolar_col_upgrade_data {
/* upgrade total frame count */
uint16_t total_cnt;
/* current frame index */
uint16_t cur_index;
/* current frame data */
uint8_t data[0];
} proto_645_sunsolar_col_upgrade_data_t;
typedef struct _proto_645_sunsolar_upgrade_lost_data {
/* total frame count */
uint16_t total_cnt;
/* lost frame count, one time max 64 */
uint16_t cur_lost_cnt;
/* lost index list */
uint16_t lost_index[0];
} proto_645_sunsolar_upgrade_lost_data_t;
#pragma pack(pop)
#endif /* PROTO_645_SUNSOLAR_H */