McuManager one test passed.
This commit is contained in:
		
							parent
							
								
									988d2a03e5
								
							
						
					
					
						commit
						e781fbf37d
					
				|  | @ -605,7 +605,7 @@ unsigned char chCRCLo[] ={ | |||
|  * @param       length 数据长度 | ||||
|  * @return      unsigned short  | ||||
|  */ | ||||
| unsigned short Calculate_Check_Sum(const unsigned char* pData, unsigned short length) | ||||
| unsigned short calculate_check_sum(const unsigned char* pData, unsigned short length) | ||||
| { | ||||
|     unsigned char CRCHi = 0xFF; | ||||
|     unsigned char CRCLo = 0xFF; | ||||
|  |  | |||
|  | @ -37,7 +37,7 @@ public: | |||
|                const unsigned int timeoutMs = DEFAULT_ASK_TIMEOUT); | ||||
|     virtual ~McuAskBase() = default; | ||||
|     ASK_RESULT Blocking(void) override; | ||||
|     void StopBlocking(void) override; | ||||
|     // void StopBlocking(void) override;
 | ||||
|     bool NeedReply(void) override; | ||||
|     void ReplyFinished(const bool result) override; | ||||
|     bool IfTimeout(const unsigned int &integrationTimeMs) override; | ||||
|  |  | |||
|  | @ -33,11 +33,11 @@ ASK_RESULT McuAskBase::Blocking(void) | |||
|     } | ||||
|     return ASK_RESULT::FAILED; | ||||
| } | ||||
| void McuAskBase::StopBlocking(void) | ||||
| { | ||||
|     //
 | ||||
|     sem_post(&mSem); | ||||
| } | ||||
| // void McuAskBase::StopBlocking(void)
 | ||||
| // {
 | ||||
| //     //
 | ||||
| //     sem_post(&mSem);
 | ||||
| // }
 | ||||
| bool McuAskBase::NeedReply(void) | ||||
| { | ||||
|     //
 | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ public: | |||
|     VMcuAsk() { mSerialNumber = 0; } | ||||
|     virtual ~VMcuAsk() = default; | ||||
|     virtual ASK_RESULT Blocking(void) { return ASK_RESULT::END; } | ||||
|     virtual void StopBlocking(void) {} | ||||
|     // virtual void StopBlocking(void) {}
 | ||||
|     virtual bool NeedReply(void) { return false; } | ||||
|     virtual void ReplyFinished(const bool result) {} | ||||
|     virtual bool IfTimeout(const unsigned int &integrationTimeMs) { return false; } | ||||
|  |  | |||
|  | @ -16,6 +16,8 @@ | |||
| #include "ILog.h" | ||||
| #include <string.h> | ||||
| constexpr int SLEEP_TIME_MS = 1000; | ||||
| constexpr bool REMOVE_THE_ASK = true; | ||||
| constexpr bool KEEP_THE_ASK = false; | ||||
| /**
 | ||||
|  * @brief Do not use static decoration on this constant pointer, as external test code needs to reference it. | ||||
|  * | ||||
|  | @ -203,15 +205,19 @@ void McuDevice::SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<V | |||
| } | ||||
| void McuDevice::DeleteMcuAsk(std::shared_ptr<VMcuAsk> &ask) | ||||
| { | ||||
|     //
 | ||||
|     std::lock_guard<std::mutex> locker(mMutex); | ||||
|     auto searchMcuAsk = [&ask](std::shared_ptr<VMcuAsk> &askList) -> bool { | ||||
|         if (ask->mSerialNumber == askList->mSerialNumber) { | ||||
|             return REMOVE_THE_ASK; | ||||
|         } | ||||
|         return KEEP_THE_ASK; | ||||
|     }; | ||||
|     mAllAsk.remove_if(searchMcuAsk); | ||||
| } | ||||
| void McuDevice::TraverseCheckAllAsk(void) | ||||
| { | ||||
|     std::lock_guard<std::mutex> locker(mMutex); | ||||
|     auto ifTimeout = [](std::shared_ptr<VMcuAsk> &ask) -> bool { | ||||
|         constexpr bool REMOVE_THE_ASK = true; | ||||
|         constexpr bool KEEP_THE_ASK = false; | ||||
|         if (!ask) { | ||||
|             return REMOVE_THE_ASK; | ||||
|         } | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ include_directories( | |||
|     ${UTILS_SOURCE_PATH}/StatusCode/include | ||||
|     ${UTILS_SOURCE_PATH}/Log/include | ||||
|     ${UTILS_SOURCE_PATH}/UartDevice/include | ||||
|     ${UTILS_SOURCE_PATH}/ModBusCRC16/include | ||||
|     ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include | ||||
|     ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include | ||||
|     ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ | |||
|  */ | ||||
| #include "McuProtocolTestTool.h" | ||||
| #include "ILog.h" | ||||
| #include "ModBusCRC16.h" | ||||
| #include <netinet/in.h> | ||||
| #include <string.h> | ||||
| #include <thread> | ||||
| constexpr size_t PROTOCOL_DATA_KEY_HEAD_LENGTH = 10; | ||||
|  | @ -30,7 +32,7 @@ void McuProtocolTestTool::IpcMissionProtocolInit(std::shared_ptr<LinuxTest> &moc | |||
| { | ||||
|     const unsigned char ASK_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x0C, 0x3D, 0x68}; | ||||
|     const unsigned char REPLY_IPC_MISSION[] = { | ||||
|         0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0D, 0x01, 0x3D, 0x68}; | ||||
|         0xFA, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0D, 0x01, 0xAA, 0x89}; | ||||
|     static size_t WRITE_COUNT = -1; | ||||
|     auto api_write = [=, &mock](int fd, const void *buf, size_t count) { | ||||
|         McuProtocolTestTool::PrintHexadecimalData(buf, count, WRITE_PRINT); | ||||
|  |  | |||
|  | @ -43,7 +43,8 @@ void LittleEndianHandle::HostByteOrderConversion(ProtocolPacket &packet) | |||
| } | ||||
| bool LittleEndianHandle::CheckoutTheCheckCode(const ProtocolPacket &packet) | ||||
| { | ||||
|     short code = Calculate_Check_Sum(mProtocolData, mProtocolDataLength - sizeof(short)); | ||||
|     short code = calculate_check_sum(mProtocolData, mProtocolDataLength - sizeof(short)); | ||||
|     code = htons(code); | ||||
|     if (code == packet.mCheckCode) { | ||||
|         return true; | ||||
|     } | ||||
|  |  | |||
|  | @ -73,7 +73,7 @@ void ProtocolHandle::MakeAskIpcMissionPacket(const std::shared_ptr<VProtocolPara | |||
|     packet.mHead = PROTOCOL_HEAD; | ||||
|     packet.mCommand = param->mCommand; | ||||
|     packet.mLength = dataLength; | ||||
|     packet.mCheckCode = Calculate_Check_Sum(mProtocolData, dataLength - sizeof(short)); | ||||
|     packet.mCheckCode = calculate_check_sum(mProtocolData, dataLength - sizeof(short)); | ||||
|     packet.mSerialNumber = mSerialNumber; | ||||
|     mProtocolSerialNumber = packet.mSerialNumber; | ||||
|     mSerialNumber++; | ||||
|  | @ -122,7 +122,7 @@ void ProtocolHandle::AnalyzeReplyIpcMissionPacket(const ProtocolPacket &packet) | |||
| } | ||||
| bool ProtocolHandle::CheckoutTheCheckCode(const ProtocolPacket &packet) | ||||
| { | ||||
|     short code = Calculate_Check_Sum(mProtocolData, mProtocolDataLength - sizeof(short)); | ||||
|     short code = calculate_check_sum(mProtocolData, mProtocolDataLength - sizeof(short)); | ||||
|     if (code == packet.mCheckCode) { | ||||
|         return true; | ||||
|     } | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ | |||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| unsigned short Calculate_Check_Sum(const unsigned char *pData, unsigned short length); | ||||
| unsigned short calculate_check_sum(const unsigned char *pData, unsigned short length); | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  |  | |||
|  | @ -53,7 +53,7 @@ unsigned char chCRCLo[] = { | |||
|  * @param       length length of data | ||||
|  * @return      unsigned short | ||||
|  */ | ||||
| unsigned short Calculate_Check_Sum(const unsigned char *pData, unsigned short length) | ||||
| unsigned short calculate_check_sum(const unsigned char *pData, unsigned short length) | ||||
| { | ||||
|     unsigned char CRCHi = 0xFF; | ||||
|     unsigned char CRCLo = 0xFF; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Fancy code
						Fancy code