From a179789b3f8375a8bde87135c644b29085a03bdb Mon Sep 17 00:00:00 2001 From: zhaojingkui <1553836110@qq.com> Date: Tue, 18 Feb 2025 16:57:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86udp=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81,=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=97=B6=E9=97=B4=E8=8E=B7=E5=8F=96=E5=87=BD=E6=95=B0?= =?UTF-8?q?,=E5=AE=8C=E5=96=84=E4=BA=86ccu=E5=8F=91=E9=80=81=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/pPowerManger.moos | 2 +- data/msg/uPower_disSysState_st.json | 2 +- data/msg/uPower_fcsState_st.json | 50 ++++++++++---------- data/msg/uPower_liBatState_st.json | 54 +++++++++++----------- src/pPowerManger/PowerManger.cpp | 71 +++++++++++++++++++++++------ src/pPowerManger/PowerManger.h | 49 ++++++++++++-------- src/pPowerManger/ccuUdpMsg.h | 11 +++-- src/pPowerManger/udpComm.cpp | 41 +++++++++++++++-- src/pPowerManger/udpComm.h | 9 ++-- test/CMakeLists.txt | 18 ++++++++ test/scripts/udpmsg.py | 2 +- test/udpCommTest.cpp | 37 +++++++++++++++ 12 files changed, 247 insertions(+), 99 deletions(-) create mode 100644 test/udpCommTest.cpp diff --git a/bin/pPowerManger.moos b/bin/pPowerManger.moos index 5c7b676..e4e89c1 100644 --- a/bin/pPowerManger.moos +++ b/bin/pPowerManger.moos @@ -3,7 +3,7 @@ ProcessConfig = pPowerManger { - AppTick = 2 + AppTick = 5 CommsTick = 4 } diff --git a/data/msg/uPower_disSysState_st.json b/data/msg/uPower_disSysState_st.json index cc2199c..90bc4ac 100644 --- a/data/msg/uPower_disSysState_st.json +++ b/data/msg/uPower_disSysState_st.json @@ -1,7 +1,7 @@ { "HVolABusBreaker_unit16": 0, "HVolBBusBreaker_unit16": 79, - "HVolBusBreaker_uint16": 32, + "HVolBusBreaker_uint16": 58, "LVolBusBreaker_uint16": 159, "faultCode_array": [ diff --git a/data/msg/uPower_fcsState_st.json b/data/msg/uPower_fcsState_st.json index 25b2bd9..7e58a62 100644 --- a/data/msg/uPower_fcsState_st.json +++ b/data/msg/uPower_fcsState_st.json @@ -1,30 +1,30 @@ { - "backpressure1_fp32": 2.3670901456028489e+36, - "backpressure2_fp32": 4.5630481893809018e-41, - "ch4oConcent1_fp32": 4.2038953929744512e-45, - "ch4oConcent2_fp32": 0.0, + "backpressure1_fp32": 7.0, + "backpressure2_fp32": 0.0, + "ch4oConcent1_fp32": 35.0, + "ch4oConcent2_fp32": 58.0, "ch4o_fp32": 0.0, - "excTemp_fp32": 4.5630481893809018e-41, - "faultCode1_uint16": 20381, - "faultCode2_uint16": 13180, - "faultCode3_uint16": 127, - "fcuCurIns_fp32": 5.7521569093081287e-30, + "excTemp_fp32": 100.0, + "faultCode1_uint16": 0, + "faultCode2_uint16": 0, + "faultCode3_uint16": 0, + "fcuCurIns_fp32": 0.0, "fcuCurPower_fp32": 0.0, - "fcuCur_fp32": -4.4122612457458051e+32, - "fcuFaultLeve_uint8": 124, - "fcuOutIns_fp32": 4.5630481893809018e-41, - "fcuOutPower_fp32": 3.4750156610080462e+36, - "fcuState_uint8": 39, - "fcuVolIns_fp32": 4.3786375736699354e+36, - "fcuVolPower_fp32": 4.5630481893809018e-41, - "fcuVol_fp32": 0.0, - "flameDet_uint8": 88, - "h2Concent1_fp32": -644240900096.0, - "h2Concent2_fp32": 0.0, - "o2Concent1_fp32": 0.0, - "o2Concent2_fp32": 0.0, - "o2Level_fp32": 3.0722067531857289e-41, + "fcuCur_fp32": 81.0, + "fcuFaultLeve_uint8": 0, + "fcuOutIns_fp32": 28.0, + "fcuOutPower_fp32": 753.0, + "fcuState_uint8": 0, + "fcuVolIns_fp32": 0.0, + "fcuVolPower_fp32": 0.0, + "fcuVol_fp32": 341.0, + "flameDet_uint8": 1, + "h2Concent1_fp32": 4.0, + "h2Concent2_fp32": 69.0, + "o2Concent1_fp32": 54.0, + "o2Concent2_fp32": 91.0, + "o2Level_fp32": 0.0, "o2_fp32": 0.0, - "powLimit_fp32": 4.5630481893809018e-41, - "powerGen_fp32": 9.8090892502737195e-45 + "powLimit_fp32": 21.0, + "powerGen_fp32": 757.0 } \ No newline at end of file diff --git a/data/msg/uPower_liBatState_st.json b/data/msg/uPower_liBatState_st.json index 869273d..743c011 100644 --- a/data/msg/uPower_liBatState_st.json +++ b/data/msg/uPower_liBatState_st.json @@ -1,38 +1,38 @@ { "fcuCurToInsLimit1_uint8": 0, "fcuCurToinsLimit2_uint8": 0, - "insBatCurElect_uint16": 127, - "insBatLimit_uint16": 13180, - "insBatSoc_uint8": 0, - "insBatTotalElect_uint16": 20377, - "insChargeState_uint8": 85, + "insBatCurElect_uint16": 0, + "insBatLimit_uint16": 6, + "insBatSoc_uint8": 5, + "insBatTotalElect_uint16": 529, + "insChargeState_uint8": 0, "insCurSocHold1_uint8": 0, "insCurSocHold2_uint8": 0, "insCurSocHold3_uint8": 0, - "insCurrent_uint16": 0, + "insCurrent_uint16": 36, "insLinkVol_uint16": 0, - "insNegRelayState_uint8": 208, - "insNegRes_uint16": 65235, + "insNegRelayState_uint8": 0, + "insNegRes_uint16": 0, "insPackVol_uint16": 0, - "insPosRelayState_uint8": 0, - "insPosRes_uint16": 5632, + "insPosRelayState_uint8": 1, + "insPosRes_uint16": 0, "insfaultCode_uint8": 0, - "powBatCurElect_uint16": 58368, - "powBatSoc_uint8": 208, - "powBatTotalElect_uint16": 13180, - "powChargeState_uint8": 48, - "powCurSocHold1_uint8": 208, - "powCurSocHold2_uint8": 97, - "powCurSocHold3_uint8": 39, - "powCurToInsLimit1_uint8": 124, - "powCurToinsLimit2_uint8": 51, - "powCur_uint16": 20538, - "powLinkVol_uint16": 127, - "powNegRelayState_uint8": 39, - "powNegRes_uint16": 127, - "powPosRelayState_uint8": 97, - "powPosRes_uint16": 13180, - "powerBatLimit_uint16": 127, - "powerPackVol_uint16": 18432, + "powBatCurElect_uint16": 0, + "powBatSoc_uint8": 64, + "powBatTotalElect_uint16": 70, + "powChargeState_uint8": 0, + "powCurSocHold1_uint8": 0, + "powCurSocHold2_uint8": 0, + "powCurSocHold3_uint8": 0, + "powCurToInsLimit1_uint8": 0, + "powCurToinsLimit2_uint8": 0, + "powCur_uint16": 30, + "powLinkVol_uint16": 0, + "powNegRelayState_uint8": 1, + "powNegRes_uint16": 0, + "powPosRelayState_uint8": 1, + "powPosRes_uint16": 0, + "powerBatLimit_uint16": 10, + "powerPackVol_uint16": 0, "powfaultCode_uint8": 0 } \ No newline at end of file diff --git a/src/pPowerManger/PowerManger.cpp b/src/pPowerManger/PowerManger.cpp index 2ce45a3..69c1571 100644 --- a/src/pPowerManger/PowerManger.cpp +++ b/src/pPowerManger/PowerManger.cpp @@ -37,10 +37,19 @@ PowerManger::PowerManger() falutLevel = 0; soc = 0; sustainableTime = 0; - m_connected = false; m_faultNum = 0; + m_ticker = 0; faultCode.push_back(0); + msg_CcuStateFbMsg_Update_time = 0; + // msg_CcuSetParmFbMsg_Update_time = 0; + msg_disHighVolBusFbMsg_Update_time = 0; + msg_disHighAVolBusFbMsg_Update_time = 0; + msg_disHighBVolBusFbMsg_Update_time = 0; + msg_disLowBusFbMsg_Update_time = 0; + + connectState = 0; + //初始化断路器状态 initTargetDisBreakerState(); @@ -115,22 +124,27 @@ bool PowerManger::OnConnectToServer() //--------------------------------------------------------- // Procedure: Iterate() // happens AppTick times per second - +//固定为4Hz bool PowerManger::Iterate() { AppCastingMOOSApp::Iterate(); //1. 更新当前状态 updatePmState(); - updateTime(); + updateConnectState(); //2. 运行状态机 if (FSM_RUN_IS_OK) m_FsmThread.Start(); else m_FsmThread.Stop(); - //进行配电系统操作 - disSysOption(); - //3. 输出报告 - buildPowerSysReport(); + //3. 进行操作 每秒执行一次 + if (m_ticker++ % 5 == 0) + { + //a. 配电系统操作 + disSysOption(); + //b. ccu操作 + //c. 输出报告 + buildPowerSysReport(); + } //4. 打印错误信息 if(!m_udpComm.sError.empty()) { @@ -263,7 +277,6 @@ bool PowerManger::ListenLoopUDP() cout<insertCcuData(m_CcuCurrentState.data); //写入数据库 + msg_CcuStateFbMsg_Update_time = time; } if(!m_udpComm.m_qReceiveDisHighVolBusBuffer.empty()) { @@ -297,6 +336,7 @@ bool PowerManger::updatePmState() m_udpComm.popMsgFormQueue(time,m_disHighVolBusCurrentState); m_pmCurrentState.bus1State = m_disHighVolBusCurrentState.data; m_db->insertDisHighVolBusData(m_disHighVolBusCurrentState.data); //写入数据库 + msg_disHighVolBusFbMsg_Update_time = time; } if(!m_udpComm.m_qReceiveDisHighAVolBusBuffer.empty()) { @@ -304,6 +344,7 @@ bool PowerManger::updatePmState() m_udpComm.popMsgFormQueue(time,m_disHighAVolBusCurrentState); m_pmCurrentState.bus2State = m_disHighAVolBusCurrentState.data; m_db->insertDisHighAVolBusData(m_disHighAVolBusCurrentState.data); //写入数据库 + msg_disHighAVolBusFbMsg_Update_time = time; } if(!m_udpComm.m_qReceiveDisHighBVolBusBuffer.empty()) { @@ -311,6 +352,7 @@ bool PowerManger::updatePmState() m_udpComm.popMsgFormQueue(time,m_disHighBVolBusCurrentState); m_pmCurrentState.bus3State = m_disHighBVolBusCurrentState.data; m_db->insertDisHighBVolBusData(m_disHighBVolBusCurrentState.data); //写入数据库 + msg_disHighBVolBusFbMsg_Update_time = time; } if(!m_udpComm.m_qReceiveDisLowBusBuffer.empty()) { @@ -318,6 +360,7 @@ bool PowerManger::updatePmState() m_udpComm.popMsgFormQueue(time,m_disLowBusState); m_pmCurrentState.bus4State = m_disLowBusState.data; m_db->insertDisLowBusData(m_disLowBusState.data); //写入数据库 + msg_disLowBusFbMsg_Update_time = time; } return true; } @@ -396,6 +439,9 @@ void PowerManger::disSysOption() //a. 高压母线的断路器 disHighVolBusCmd a; a.fuelCellCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker); + a.lithiumBatteryGroupInstrumentCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker); + a.dcDc5ModuleCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker); + a.powerLithiumBatteryCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker); a.propulsionMotorCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker); a.bowHighVoltageDistributionBoxCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker); a.tyzReservedCircuitBreaker = getBreakerOption(m_targetDisBreakerState.bus1Breaker.tyzReservedCircuitBreaker); @@ -485,9 +531,9 @@ void PowerManger::printState(FSM_State st, string desp){ int PowerManger::handleInite_s1(FSM_State &fsm, void* pData) { PowerManger* pm = (PowerManger*)pData; - //1. 检查复合管控器连接 如果10S则进入故障状态 + //1. 检查通信是否正常 如果超时则进入故障状态 double StartTime = pm->GetAppStartTime(); - while (!pm->m_connected) + while (!pm->connectState == 5) { MOOSPause(1000); pm->updateTime(); @@ -495,7 +541,7 @@ int PowerManger::handleInite_s1(FSM_State &fsm, void* pData) if(dft > 10) { pm->m_pmState = pm->m_Fault_s99; - pm->m_faultNum = 1; // 通信超时 + pm->m_faultNum = 1; break; } string desp = "等待复合管控消息 : " + to_string(10-dft); @@ -536,7 +582,6 @@ int PowerManger::handleStandby_s2(FSM_State &fsm, void* pData) } - int PowerManger::handleFault_s99(FSM_State &fsm, void* pData) { // cout << fsm.name << endl; @@ -561,7 +606,7 @@ void PowerManger::initTargetDisBreakerState() m_targetDisBreakerState.bus1Breaker.fuelCellCircuitBreaker = 0; m_targetDisBreakerState.bus1Breaker.powerLithiumBatteryCircuitBreaker = 1; //动力锂电池默认接入 m_targetDisBreakerState.bus1Breaker.propulsionMotorCircuitBreaker = 0; - m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker = 0; //仪表锂电池默认接入 + m_targetDisBreakerState.bus1Breaker.lithiumBatteryGroupInstrumentCircuitBreaker = 1; //仪表锂电池默认接入 m_targetDisBreakerState.bus1Breaker.dcDc5ModuleCircuitBreaker = 1; //DC-DC模块默认接入 m_targetDisBreakerState.bus1Breaker.bowHighVoltageDistributionBoxCircuitBreaker = 1; //艏部高压母线断路器默认接入 m_targetDisBreakerState.bus1Breaker.sternFTDevice45CircuitBreaker = 0; // sternFTDevice45CircuitBreaker默认接入 diff --git a/src/pPowerManger/PowerManger.h b/src/pPowerManger/PowerManger.h index 84b7e9c..69f911c 100644 --- a/src/pPowerManger/PowerManger.h +++ b/src/pPowerManger/PowerManger.h @@ -65,18 +65,30 @@ class PowerManger : public AppCastingMOOSApp bool buildReport(); void registerVariables(); - protected: // app function - // bool _ListenCB(); - bool updatePmState(); + protected: void updateTime(){m_current_time = MOOSTime();} bool IsSkewed(double dfTimeNow, double * pdfSkew = NULL); string getTypeName(const string typeName); + bool inline saveStringToJsonFile(const string &strJson, const string &strFileName); + //数据库 + SQLiteDB* m_db; + bool writeDataToDB(); - //通信相关 + //通信状态变量及操作函数 XPCUdpSocket* setUdpScoket(long lPort); - bool buildPowerSysReport(); + bool updatePmState(); + bool updateConnectState(); - protected: // app variables + int connectState; + double msg_CcuStateFbMsg_Update_time; + // double msg_CcuSetParmFbMsg_Update_time; + double msg_disHighVolBusFbMsg_Update_time; + double msg_disHighAVolBusFbMsg_Update_time; + double msg_disHighBVolBusFbMsg_Update_time; + double msg_disLowBusFbMsg_Update_time; + + + protected: //系统运行状态 unsigned char workCondition; unsigned char currentMod; @@ -85,9 +97,8 @@ class PowerManger : public AppCastingMOOSApp vector faultCode; unsigned int soc; unsigned int sustainableTime; - bool m_connected; pmState m_pmCurrentState; //能源系统的当前状态 - //配电系统状态 + //断路器状态 disSysBreakerList m_currentDisBreakerState; disSysBreakerList m_targetDisBreakerState; @@ -98,11 +109,18 @@ class PowerManger : public AppCastingMOOSApp msg_disHighBVolBusFbMsg m_disHighBVolBusCurrentState; msg_disLowBusFbMsg m_disLowBusState; - //操作函数 + //下位机操作函数 void disSysOption(); char getBreakerOption(char cmd); void initTargetDisBreakerState(); + void ccuOption(); + + + + //上位机操作函数 + bool buildPowerSysReport(); + private: udpComm m_udpComm; XPCUdpSocket *m_pCcuUdpComm; @@ -113,16 +131,12 @@ class PowerManger : public AppCastingMOOSApp unsigned int m_nSendBufferSizeKB; double m_current_time; unsigned int m_faultNum; + unsigned int m_ticker; - //数据库 - SQLiteDB* m_db; - bool writeDataToDB(); + - // CMOOSThread m_SendThread; - private: // - bool inline saveStringToJsonFile(const string &strJson, const string &strFileName); - - public: //状态实现 + public: + //===========================状态机实现============================================== void printState(FSM_State st, string desp); bool FSM_RUN_IS_OK = true; @@ -131,7 +145,6 @@ class PowerManger : public AppCastingMOOSApp string m_pmEvent; FSM m_fsm; - //系统状态定义 //初始化状态 FSM_State m_Inite_s1; static int handleInite_s1(FSM_State &fsm, void* pData); diff --git a/src/pPowerManger/ccuUdpMsg.h b/src/pPowerManger/ccuUdpMsg.h index 4d42fb5..299b7ad 100644 --- a/src/pPowerManger/ccuUdpMsg.h +++ b/src/pPowerManger/ccuUdpMsg.h @@ -40,11 +40,12 @@ typedef struct { typedef struct { unsigned short year; - unsigned short month; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; + unsigned char month; + unsigned char day; + unsigned char hour; + unsigned char minute; + unsigned char second; + unsigned char milliseconds; //每10毫秒 } m_date; // 复合管控器操作指令 typedef struct { diff --git a/src/pPowerManger/udpComm.cpp b/src/pPowerManger/udpComm.cpp index 15edb38..ef9c97e 100644 --- a/src/pPowerManger/udpComm.cpp +++ b/src/pPowerManger/udpComm.cpp @@ -2,7 +2,10 @@ #include #include -udpComm::udpComm() {} +udpComm::udpComm() +{ + +} udpComm::~udpComm() {} @@ -153,7 +156,8 @@ bool udpComm::pushMsgToQueue(unsigned char *m) switch (id) { case CCU_STATE_FB_ID: //CCU_STATE_FB 0x0051 - { msg_CcuStateFbMsg s; + { + msg_CcuStateFbMsg s; if(getMsgFromBuff((char *)Buff,s)) { if(m_qReceiveCcuStateBuffer.size()header.start1 = CCU_UDPMSG_START1; msg->header.start2 = CCU_UDPMSG_START2; msg->header.length = sizeof(ccuColCmd); + getDate(msg->date.year,msg->date.month,msg->date.day,msg->date.hour,msg->date.minute,msg->date.second,msg->date.milliseconds); msg->cmd = cmd; msgBuf = reinterpret_cast(msg); cc = calculateChecksum(msgBuf,sizeof(msg_CcuColCmdMsg)); @@ -517,5 +521,36 @@ bool udpComm::sendCcuSetParmCmd(const ccuSetParmCmd cmd) std::cerr << e.what() << '\n'; } delete msg; + return true; +} + +bool udpComm::getDate(unsigned short &year, unsigned char &month, unsigned char &day, unsigned char &hour, unsigned char &minute, unsigned char &second, unsigned char &milliseconds) { + // 获取当前时间 + std::time_t now = std::time(nullptr); + if (now == -1) { + return false; // 获取时间失败 + } + + // 转换为本地时间 + std::tm *localTime = std::localtime(&now); + if (!localTime) { + return false; // 转换失败 + } + + // 获取年、月、日、时、分、秒 + year = localTime->tm_year + 1900; // tm_year 是从 1900 年开始的 + month = localTime->tm_mon + 1; // tm_mon 是从 0 开始的,0 对应 1 月 + day = localTime->tm_mday; + hour = localTime->tm_hour; + minute = localTime->tm_min; + second = localTime->tm_sec; + + // 获取毫秒,使用 std::chrono + auto now_ms = std::chrono::system_clock::now(); + auto duration = now_ms.time_since_epoch(); + auto ms = std::chrono::duration_cast(duration).count() % 1000; // 取毫秒部分 + ms = ms/10; + milliseconds = static_cast(ms); + return true; } \ No newline at end of file diff --git a/src/pPowerManger/udpComm.h b/src/pPowerManger/udpComm.h index 020c432..51750ad 100644 --- a/src/pPowerManger/udpComm.h +++ b/src/pPowerManger/udpComm.h @@ -9,7 +9,8 @@ #include #include "MOOS/libMOOS/Utils/MOOSUtilityFunctions.h" #include "MOOS/libMOOS/Comms/XPCUdpSocket.h" - +#include +#include #include #include // for std::pair @@ -17,8 +18,6 @@ using namespace std; #define QUENUE_SIZE 100 class udpComm { -private: - /* data */ public: udpComm(); ~udpComm(); @@ -26,7 +25,6 @@ public: string ccuHost; long int ccuPort; - bool pushMsgToQueue(unsigned char *m); bool clearMsgQueue(); @@ -60,8 +58,9 @@ public: Checksum calculateChecksum(const unsigned char* data, int size); Checksum calculateChecksum(const unsigned char* data, int dataSize, int checkSize); + bool getDate(unsigned short &year, unsigned char &month, unsigned char &day, unsigned char &hour, unsigned char &minute, unsigned char &second, unsigned char &milliseconds); + std::vector sError; - std::pair getError(); // std::queue m_qReceiveCcuStateBuffer; std::queue> m_qReceiveCcuStateBuffer; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cb11118..aa73d2f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,6 +17,24 @@ find_package(Catch2 REQUIRED) # 添加测试可执行文件 add_executable(SQLiteDBTest SQLiteDBTest.cpp) + + +# 查找 udpComm 项目库 +find_library(UDPCOMM_LIB NAMES UDPComm PATHS /home/zjk/project/H100/H100PowerManger/lib) +if(NOT UDPCOMM_LIB) + message(FATAL_ERROR "udpComm library not found!") +endif() + +# 添加 udpComm 测试可执行文件 +add_executable(udpCommTest udpCommTest.cpp) + +# 链接库文件(注意顺序:先项目库后系统库) +target_link_libraries(udpCommTest + ${UDPCOMM_LIB} # 项目udpComm库 + ${MOOS_LIBRARIES} + Catch2::Catch2WithMain # 测试框架 +) + # 链接库文件(注意顺序:先项目库后系统库) target_link_libraries(SQLiteDBTest ${SQLiteDB_LIB} # 项目SQLiteDB库 diff --git a/test/scripts/udpmsg.py b/test/scripts/udpmsg.py index 9ff5e6a..95e81ad 100644 --- a/test/scripts/udpmsg.py +++ b/test/scripts/udpmsg.py @@ -4,7 +4,7 @@ class msg_CcuStateFbMsg: def __init__(self): self.start1 = 0x20 self.start2 = 0x20 - self.id = 0x0051 + self.id = 0x0041 self.length = 0x0000 self.currentWorkCondition = 0x00 self.fcuState = 80 diff --git a/test/udpCommTest.cpp b/test/udpCommTest.cpp new file mode 100644 index 0000000..814da4c --- /dev/null +++ b/test/udpCommTest.cpp @@ -0,0 +1,37 @@ +#include "../src/pPowerManger/udpComm.h" +#include "catch2/catch.hpp" +#include + +TEST_CASE("udpComm getDate function test", "[udpComm]") { + udpComm comm; + + unsigned short year; + unsigned char month, day, hour, minute, second, milliseconds; + + bool result = comm.getDate(year, month, day, hour, minute, second, milliseconds); + + // 输出日期和时间信息 + std::cout << "Year: " << year << std::endl; + std::cout << "Month: " << static_cast(month) << std::endl; + std::cout << "Day: " << static_cast(day) << std::endl; + std::cout << "Hour: " << static_cast(hour) << std::endl; + std::cout << "Minute: " << static_cast(minute) << std::endl; + std::cout << "Second: " << static_cast(second) << std::endl; + std::cout << "Milliseconds: " << static_cast(milliseconds) << std::endl; + + REQUIRE(result == true); + REQUIRE(year >= 2023); + REQUIRE(year <= 2030); + REQUIRE(month >= 1); + REQUIRE(month <= 12); + REQUIRE(day >= 1); + REQUIRE(day <= 31); + REQUIRE(hour >= 0); + REQUIRE(hour <= 23); + REQUIRE(minute >= 0); + REQUIRE(minute <= 59); + REQUIRE(second >= 0); + REQUIRE(second <= 59); + REQUIRE(milliseconds >= 0); + REQUIRE(milliseconds <= 999); +}