94 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (c) 2023 Fancy Code.
 | 
						|
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
 * you may not use this file except in compliance with the License.
 | 
						|
 * You may obtain a copy of the License at
 | 
						|
 *
 | 
						|
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
 *
 | 
						|
 * Unless required by applicable law or agreed to in writing, software
 | 
						|
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
 * See the License for the specific language governing permissions and
 | 
						|
 * limitations under the License.
 | 
						|
 */
 | 
						|
#ifndef MCU_PROTOCOL_TEST_TOOL_H
 | 
						|
#define MCU_PROTOCOL_TEST_TOOL_H
 | 
						|
#include "LinuxApiMock.h"
 | 
						|
#include "UartDeviceTestTool.h"
 | 
						|
#include <list>
 | 
						|
#include <mutex>
 | 
						|
#include <thread>
 | 
						|
constexpr int READ_PRINT = 0;
 | 
						|
constexpr int WRITE_PRINT = 1;
 | 
						|
constexpr bool PROTOCOL_HANDLED = true;
 | 
						|
constexpr bool PROTOCOL_NOT_HANDLED = false;
 | 
						|
using ProtocolHandleFunc = std::function<bool(std::shared_ptr<LinuxTest> &, const int &, const void *, size_t)>;
 | 
						|
class McuProtocolTestTool : virtual public UartDeviceTestTool
 | 
						|
{
 | 
						|
public:
 | 
						|
    McuProtocolTestTool();
 | 
						|
    virtual ~McuProtocolTestTool() = default;
 | 
						|
    void Init(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
 | 
						|
    void UnInit(void);
 | 
						|
    void OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
 | 
						|
 | 
						|
private:
 | 
						|
    void CheckSerialNumber(const void *buf, const size_t &count);
 | 
						|
    void ChecCRC16Code(const void *buf, const size_t &count);
 | 
						|
    void ResetCheckCode(const void *buf, const size_t &count);
 | 
						|
    void ReplySelectSucceed(std::shared_ptr<LinuxTest> &mock, const int &uartFd);
 | 
						|
    bool MonitorProtocolPacket(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    bool IpcMissionProtocolHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    void IpcMissionProtocolInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    bool CutOffPowerSupplyProtocolHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
 | 
						|
                                         size_t count);
 | 
						|
    bool FeedWatchDogProtocolHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    bool FeedingCycleProtocolHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    void FeedingCycleProtocolInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    bool SetDataTimeProtocolHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    void SetDataTimeProtocolInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    bool SetPirSensitivityProtocolHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
 | 
						|
                                         size_t count);
 | 
						|
    void SetPirSensitivityProtocolInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
 | 
						|
                                       size_t count);
 | 
						|
    bool ContorlInfraredLightHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    void ContorlInfraredLightInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf, size_t count);
 | 
						|
    bool GetPhotosensitivityValueHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
 | 
						|
                                        size_t count);
 | 
						|
    void GetPhotosensitivityValueInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd, const void *buf,
 | 
						|
                                      size_t count);
 | 
						|
    void LockProtocolHandle(void);
 | 
						|
    void UnlockProtocolHandle(void);
 | 
						|
    void UnlockThread(void);
 | 
						|
    void PipeSelectTimeoutForProtocolHandleImmediately(void);
 | 
						|
 | 
						|
private:
 | 
						|
    void OtherSideAskIpcMissionHandle(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
 | 
						|
                                      const unsigned int &serialNumber);
 | 
						|
    void OtherSideAskIpcMissionInit(std::shared_ptr<LinuxTest> &mock, const int &uartFd,
 | 
						|
                                    const unsigned int &serialNumber);
 | 
						|
 | 
						|
private:
 | 
						|
    static void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log);
 | 
						|
 | 
						|
private:
 | 
						|
    // virtual void MonitorWriteProtocolData(const short &head, const unsigned int
 | 
						|
    // &serialNumber, const short &command,
 | 
						|
    //                                       const void *data, const short
 | 
						|
    //                                       &packetLength)
 | 
						|
    // {
 | 
						|
    // }
 | 
						|
 | 
						|
private:
 | 
						|
    std::mutex mMutex;
 | 
						|
    bool mThreadRuning;
 | 
						|
    std::thread mLockThread;
 | 
						|
    std::thread mUnLockThread;
 | 
						|
    std::list<unsigned int> mSerialNumberList;
 | 
						|
    bool mPipeFdMockSelectInit;
 | 
						|
    int mPipeFdMockSelect[2];
 | 
						|
    std::list<ProtocolHandleFunc> mProtocolHandle;
 | 
						|
    int mUartFd;
 | 
						|
};
 | 
						|
#endif |