181 lines
5.3 KiB
C
181 lines
5.3 KiB
C
/*****************************************************************************
|
||
* @copyright 1997-2050, H3C. POWER SUPPLY CO., LTD.
|
||
* @file app_task_regedit.c
|
||
* @brief xx功能
|
||
* @author H3C_GQ
|
||
* @date 2024-09-05
|
||
* @remark
|
||
*****************************************************************************/
|
||
#define _XOPEN_SOURCE 700
|
||
#include <errno.h>
|
||
#include "kit_db.h"
|
||
#include "drv_4g.h"
|
||
#include "drv_wifi.h"
|
||
#include "app_task_regedit.h"
|
||
|
||
|
||
/*********************************************************************
|
||
* @brief 初始化系统时间将rtc时钟同步到linux系统
|
||
* @param[in] void
|
||
* @return 0-成功 1-失败
|
||
*********************************************************************/
|
||
int initEmsConfig(void)
|
||
{
|
||
UT_array *emsDevConfigs = {0};
|
||
int ret = 0;
|
||
if (0 != kit_get_config_db_data(&emsDevConfigs))
|
||
{
|
||
return 1;
|
||
}
|
||
utarray_foreach(emsDevConfigs, ems_dev_config_t *, p_emsDevConfig)
|
||
{
|
||
switch (p_emsDevConfig->type)
|
||
{
|
||
case kEms_Config_Uart:
|
||
// 系统串口不需要初始化
|
||
break;
|
||
case kEms_Config_Net:
|
||
// 初始化系统的IP、MAC地址、网关等配置
|
||
ret = netInitHandble(p_emsDevConfig);
|
||
break;
|
||
case kEms_Config_DI:
|
||
break;
|
||
case kEms_Config_DO:
|
||
break;
|
||
case kEms_Config_Rtc:
|
||
// 初始化系统时间将rtc时钟同步到linux系统
|
||
ret = systimeInitHandle(p_emsDevConfig);
|
||
break;
|
||
case kEms_Config_Wifi:
|
||
ret = sysWifiInitHandle(p_emsDevConfig);
|
||
break;
|
||
case kEms_Config_4G:
|
||
ret = sys4GInitHandle(p_emsDevConfig);
|
||
break;
|
||
default:
|
||
printf("Unknown EMS device config type: %d\n", p_emsDevConfig->type);
|
||
ret = 1;
|
||
break;
|
||
}
|
||
if (ret != 0)
|
||
{
|
||
// 初始化失败,释放资源并返回错误
|
||
utarray_free(emsDevConfigs);
|
||
return 1;
|
||
}
|
||
}
|
||
// 释放数组内存
|
||
utarray_free(emsDevConfigs);
|
||
|
||
// gpio口初始化
|
||
ret = drvGpioOpen();
|
||
if (ret != 0)
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
|
||
|
||
/*********************************************************************
|
||
* @brief 整个系统初始化
|
||
* @param[in] arg:相关配置
|
||
* @return 0-成功 1-失败
|
||
*********************************************************************/
|
||
uint8_t initSystem(void *arg)
|
||
{
|
||
int ret = 0;
|
||
|
||
ret = initSqliteDb();
|
||
if (ret != 0)
|
||
{
|
||
KITPTF(LOG_APP_EN, ERROR_EN, "数据库初始化失败!");
|
||
KITLOG(LOG_APP_EN, ERROR_EN, "数据库初始化失败!");
|
||
return ret;
|
||
}
|
||
|
||
ret = initEmsConfig();
|
||
if (ret != 0)
|
||
{
|
||
KITPTF(LOG_APP_EN, ERROR_EN, "EMS盒子初始化失败!");
|
||
KITLOG(LOG_APP_EN, ERROR_EN, "EMS盒子初始化失败!");
|
||
//return ret;
|
||
}
|
||
|
||
ret = initDevInfo();
|
||
if (ret != 0)
|
||
{
|
||
KITPTF(LOG_APP_EN, ERROR_EN, "读取设备配置、电位配置信息失败!");
|
||
KITLOG(LOG_APP_EN, ERROR_EN, "读取设备配置、电位配置信息失败!");
|
||
return ret;
|
||
}
|
||
|
||
ret = initNorthInfo();
|
||
if (ret != 0)
|
||
{
|
||
KITPTF(LOG_APP_EN, ERROR_EN, "读取北向配置失败!");
|
||
KITLOG(LOG_APP_EN, ERROR_EN, "读取北向配置失败!");
|
||
return ret;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
|
||
/*********************************************************************
|
||
* @brief EMS业务初始化
|
||
* @param[in] arg:相关配置
|
||
* @return 0:sucessful;1:fault
|
||
*********************************************************************/
|
||
uint8_t initEmsStart(void *arg)
|
||
{
|
||
if (initRtdb(rtdbType, NULL, kEE_SHM_CREAT) != 0)
|
||
{
|
||
KITLOG(LOG_APP_EN, ERROR_EN, "RTDB初始化失败!");
|
||
KITPTF(LOG_APP_EN, ERROR_EN, "RTDB初始化失败!");
|
||
return E_STATUS_ERROR;
|
||
}
|
||
if (initWebSign(kSign_ShMem, kEE_SHM_CREAT) != 0)
|
||
{
|
||
KITLOG(LOG_APP_EN, ERROR_EN, "websign初始化失败!");
|
||
KITPTF(LOG_APP_EN, ERROR_EN, "websign初始化失败!");
|
||
return E_STATUS_ERROR;
|
||
}
|
||
if (logic_initTask() != 0)
|
||
{
|
||
KITLOG(LOG_LOGIC_EN, ERROR_EN, "任务初始化失败!");
|
||
KITPTF(LOG_LOGIC_EN, ERROR_EN, "任务初始化失败!");
|
||
//return E_STATUS_ERROR;
|
||
}
|
||
|
||
return E_STATUS_OK;
|
||
}
|
||
|
||
|
||
|
||
/*********************************************************************
|
||
* @brief 创建任务的总入口
|
||
* @param[in] arg:相关配置
|
||
* @return void
|
||
*********************************************************************/
|
||
void regeditThreadEntry(void *map_t) // 创建线程入口
|
||
{
|
||
// 创建各种采集任务
|
||
|
||
creatModbusRtuMasterTask(void* item);
|
||
creatMobusTcpMasterTask(void* item);
|
||
|
||
// 创建各种转发任务
|
||
creatModbusRtuSlaveTask(item)
|
||
creatModbusTcpSlaveTask(item)
|
||
creatMqttTask(item)
|
||
|
||
// 创建定时落库任务
|
||
creatCycleTimeToDBTask(item);
|
||
|
||
//创建DIDO策略任务
|
||
creatDIDICtrlTask(10); //
|
||
|
||
//创建业务控制算法
|
||
creatAlgorithmTask(10); //
|
||
} |