/**************************************************************************** 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 IOT_SUNSOLAR_REC_H #define IOT_SUNSOLAR_REC_H /* os shim includes */ #include "os_types_api.h" /* iot common header files */ #include "iot_pkt_api.h" #ifdef __cplusplus extern "C" { #endif /* max pv number of this module. */ #define LOCAL_PV_MAX_REC (2) /* every 1 minute freeze curve data unit:minutes */ #define IOT_SOLR_REC_CHECK_CRUVE_FROZEN_TIME (1) /* record frozen data count, one day, every minute */ #define IOT_SOLR_REC_FROZEN_DATA_CNT (24 * 60) #pragma pack(push) /* save the pack status */ #pragma pack(1) /* 1 byte align */ /* frozen data block */ typedef struct _iot_sunsolar_rec_frozen_block { /* frozen voltage uint:0.1v */ uint16_t volt[LOCAL_PV_MAX_REC]; /* current unit:1mA */ uint16_t current; /* temperature 0.1c */ int16_t temp; /* rsd state */ struct { /* config rsd status, 0xA:open, 0x5:close. */ uint8_t last_cmd :4, /* real rsd status, 0xA:open, 0x5:close. */ real_status :4; } rsd_state[LOCAL_PV_MAX_REC]; /* rsd voltage uint:0.1v */ uint16_t rsd_volt[LOCAL_PV_MAX_REC]; /* snr */ int8_t snr; /* rssi */ uint8_t rssi; /* period power out: 0.01Wh */ uint32_t period_energy[LOCAL_PV_MAX_REC]; /* history total power out: 1Wh */ uint32_t total_energy[LOCAL_PV_MAX_REC]; /* reboot count */ uint16_t reboot_cnt; /* online status */ uint8_t plclink_state; } iot_sunsolar_rec_frozen_block_t; /* froezen recording description */ typedef struct { /* content of frozen recording */ iot_sunsolar_rec_frozen_block_t rec; /* flag to mark if frozen recording is valid */ uint8_t valid; } iot_sunsolar_rec_frozen_desc_t; /* record head */ typedef struct _iot_sunsolar_rec_head { /* crc16 from rec_seq to data */ uint16_t crc; /* record sequence n umber */ uint32_t rec_seq; /* time stamp */ uint32_t ts; /* block data */ uint8_t data[0]; } iot_sunsolar_rec_head_t; #pragma pack(pop) /* record region descriptor */ typedef struct iot_sunsolar_rec_region_desc { /* record entry size, contains record headers */ uint32_t entry_size; /* region start position */ uint32_t start; /* max count of entrys current region can save */ uint16_t max_cnt; /* recording depth */ uint32_t rec_depth; /* record serial number will assigned */ uint32_t seq; /* index of the latest record increased one */ uint32_t new_idx; /* index of the oldest record */ uint32_t oldest_idx; /* timestamp of the latest record */ uint32_t last_rec_ts; } iot_sunsolar_rec_region_desc_t; /** * @brief iot_sunsolar_frozen_data_rec() - record frozen data * @param tm: rtc time */ void iot_sunsolar_frozen_data_rec(iot_time_tm_t *tm); /** * @brief iot_sunsolar_frozen_rec_read() - reading frozen record. * @param ts: specify the start time, and return the time of the first point of * successful lookup * @param inteval: time interval, unit is second. * @param n: specifies the number of points to be read, returns the number of * points actually read. * @param pkt: the pointer of pkt containing read result. * @retval: ERR_OK - successfully, otherwise - error code */ uint32_t iot_sunsolar_frozen_rec_read(uint32_t *ts, uint32_t inteval, uint8_t *n, iot_pkt_t **pkt); /** * @brief iot_sunsolar_rec_init() - init sunsolar record specific operation. * @return: 0 - for success case * @return: otherwise - error number */ uint32_t iot_sunsolar_rec_init(); /** * @brief iot_sunsolar_rec_deinit() - deinit sunsolar record specific operation. */ void iot_sunsolar_rec_deinit(); #ifdef __cplusplus } #endif #endif /* IOT_SUNSOLAR_REC_H */