/*
 * @Author: ghzhang gogosanmao@126.com
 * @Date: 2023-06-18 14:58:37
 * @LastEditors: ybzhou yibo.zhou@lnxall.com
 * @LastEditTime: 2025-10-14 10:07:35
 * @FilePath: \lnxall_package\proto_forward\src\main.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __UTILS_H__
#define __UTILS_H__

#include <syslog.h>
#include "mqtt_session.h"
#include "lnxall_list.h"
#include "dy_utils/dy_common.h"
#include "dy_utils/dy_ipc.h"
#include "dy_utils/hash_intptr.h"
#include "dy_utils/modbus_utils.h"
#include "dy_utils/period_service.h"
#include "dy_utils/bitmap.h"
#include "sys/param.h"
#include "assert.h"
#include "pthread.h"
#include <sys/epoll.h>
#include "define.h"
#include "collector-api.h"
#include "deviceLayer.h"
#include "pub_fun.h"

#define EMS_UPGRADE_FILE "/tmp/ems.update"
#define WEB_UPGRADE_FILE "/tmp/web.update"

// 当前时间段关键信息，有功、无功、SOC上限、SOC下限、索引（时间段角标）
typedef struct
{
    int power;
    int repower;
    int socup;
    int soclower;
    int last_index;
    int index;
} key_info_t;

void sig_init(void);
bool check_float_equal(float a,float b);
void system_upgrade_ck(void);
void ems_base_variant_free();
int ems_base_variant_get(ems_base_variant_t ***val,int *size);
int ems_base_variant_sing_add(ems_base_variant_t *val);
int ems_base_variant_multi_add(const ems_base_variant_t *val,size_t size);
double update_plan_cfg(pcs_ctrl_var_t *var);
int getIccid(char *iccid,int size);
int getInternalIccid(char *iccid,int size);
int getExternalIccid(char *iccid,int size);
void get_cpu_usage(double *cpu_used);
void get_net_usage(int *net_status);
void get_mem_usage(double *mem_used);
void open_sysinfo(void);
bool is_dir(const char* path);
long long get_dir_size(const char*pathname,char*first_file) ;
int check_workstate_by_time(int time,float powernow);

cJSON* append_json_file(cJSON* test_json, const char* json_file_path, const char *prefix); 
cJSON* add_prefix_to_name(cJSON *json, const char *prefix);
bool automatic_cfg_merged(const char* object_file_path);
int logic_dod_protect(key_info_t *key_info, int *chadischapro, double value);
int sync_check_ems_sys_status(void);
#endif
