#include "start.h"
#include "TimeSliceOffset.h"
#include "Init.h"
#include "task.h"
#include "pDebug.h"
#include "parameter.h"
#include "FM_TIM.h"
#include "inFlash.h"
#include "SOE.h"

void startInfo(void)
{
    log_info("uniqueDeviceID : 0x%x%x%x%x%x%x%x \n", g_cfgParameter.uniqueDeviceID[0]
                                                    , g_cfgParameter.uniqueDeviceID[1]
                                                    , g_cfgParameter.uniqueDeviceID[2]
                                                    , g_cfgParameter.uniqueDeviceID[3]
                                                    , g_cfgParameter.uniqueDeviceID[4]
                                                    , g_cfgParameter.uniqueDeviceID[5]
                                                    , g_cfgParameter.uniqueDeviceID[6]);
    log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
    log_info("bat485_Baud : %d \n", g_cfgParameter.bat485_Baud);
    log_info("powerBoxType : 0x%x \n", g_cfgParameter.powerBoxType);
    log_info("constantVoltageV : %f \n", g_cfgParameter.constantVoltageV);
    log_info("floatI : %f \n", g_cfgParameter.floatI);
    log_info("startSolarOpenCircuitV : %f \n", g_cfgParameter.startSolarOpenCircuitV);
    log_info("stopSolarOutputCircuitV : %f \n", g_cfgParameter.stopSolarOutputCircuitV);
    log_info("checkCanStartTime : %d \n", g_cfgParameter.checkCanStartTime);
    log_info("shortCircuitJudgmentDelay : %d \n", g_cfgParameter.shortCircuitJudgmentDelay);
    log_info("inputPowerLowJudgmentDelay : %d \n", g_cfgParameter.inputPowerLowJudgmentDelay);
    log_info("inputPowerLowAgainOutputDelay : %d \n", g_cfgParameter.inputPowerLowAgainOutputDelay);
    log_info("firstStageProtectionDelay : %d \n", g_cfgParameter.firstStageProtectionDelay);
    log_info("firstStageProtectionValue : %d \n", g_cfgParameter.firstStageProtectionValue);
    log_info("firstStageProtectionCurr : %f \n", g_cfgParameter.firstStageProtectionCurr);
    log_info("secondStageProtectionDelay : %d \n", g_cfgParameter.secondStageProtectionDelay);
    log_info("secondStageProtectionCurr : %f \n", g_cfgParameter.secondStageProtectionCurr);
    log_info("thirdStageProtectionDelay : %d \n", g_cfgParameter.thirdStageProtectionDelay);
    log_info("thirdStageProtectionCurr : %f \n", g_cfgParameter.thirdStageProtectionCurr);
    log_info("inputPowerLowDetectionDelay : %d \n", g_cfgParameter.inputPowerLowDetectionDelay);
    log_info("inputPowerLowDetectionVolt : %f \n", g_cfgParameter.inputPowerLowDetectionVolt);
    log_info("maxOpenSolarOutputCircuitV : %f \n", g_cfgParameter.maxOpenSolarOutputCircuitV);
    log_info("maxChargCurr : %f \n", g_cfgParameter.maxChargCurr);
    log_info("minCheckLoopImpedanceChargCurr : %f \n", g_cfgParameter.minCheckLoopImpedanceChargCurr);
    log_info("fullPowerOutputTemperature : %f \n", g_cfgParameter.fullPowerOutputTemperature);
    log_info("reducePowerOutputTemperature : %f \n", g_cfgParameter.reducePowerOutputTemperature);
    log_info("stopPowerOutputTemperature : %f \n", g_cfgParameter.stopPowerOutputTemperature);
    log_info("constantVoltageChargeV : %f \n", g_cfgParameter.constantVoltageChargeV);
    log_info("FloatChargeV : %f \n", g_cfgParameter.FloatChargeV);
    log_info("collectOpenCircuitVoltageTime : %d \n", g_cfgParameter.collectOpenCircuitVoltageTime);
    log_info("Access_Node_Type : %x \n", g_cfgParameter.Access_Node_Type);
    log_info("Communication_Methods : %x \n", g_cfgParameter.Communication_Methods);
    log_info("startFlagSL : 0x%x%x \n", g_cfgParameter.startFlagSL[0], g_cfgParameter.startFlagSL[1]);
    log_info("endFlagSL : 0x%x \n", g_cfgParameter.endFlagSL);

    log_info("loopImpedance : %f \n", getLoopImpedance());
}


void start(void)
{
    Init();

    uartCommonInit();

    
    // setDutyRatio(0.0001f);
    // EN_PWMOUT_Eable();

    task_Init();

    startInfo();

    // HAL_Delay(5000);
    // while (1) {
    //     cfgTest();        
    //     HAL_Delay(1000);
    // }
    /* 启动事件 */
    // insertEventsOrderRecord(startEvent);

    TimeSliceOffset_Start();
}