60 lines
2.1 KiB
C++
60 lines
2.1 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_DEVICE_H
|
|
#define MCU_DEVICE_H
|
|
#include "IMcuManager.h"
|
|
#include "McuProtocol.h"
|
|
#include "UartDevice.h"
|
|
#include <list>
|
|
#include <mutex>
|
|
#include <thread>
|
|
class McuDevice : public IMcuManager, virtual public VProtocolBase, public VProtocolRecv
|
|
{
|
|
public:
|
|
McuDevice();
|
|
virtual ~McuDevice();
|
|
const StatusCode Init(void) override;
|
|
const StatusCode UnInit(void) override;
|
|
|
|
public:
|
|
ssize_t WriteData(const void *buff, const size_t buffLength, std::shared_ptr<VProtocolContext> &context,
|
|
const unsigned int &serialNumber) override;
|
|
|
|
public:
|
|
void GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission) override;
|
|
void OnlyResultReply(const unsigned int &serialNumber, const ReplyResult &result) override;
|
|
|
|
public:
|
|
void DeviceRecvThread(void);
|
|
void McuAskHandleThread(void);
|
|
|
|
protected:
|
|
void DeviceRecvData(const char *keyHead, const size_t headLength);
|
|
void AddMcuAsk(std::shared_ptr<VMcuAsk> &ask);
|
|
bool SearchMcuAsk(const unsigned int &serialNumber, std::shared_ptr<VMcuAsk> &ask);
|
|
void DeleteMcuAsk(std::shared_ptr<VMcuAsk> &ask);
|
|
void DeleteAllAsk(void);
|
|
void TraverseCheckAllAsk(void);
|
|
void PrintHexadecimalData(const void *buf, const size_t &bufLength, const char *log);
|
|
|
|
protected:
|
|
std::mutex mMutex;
|
|
void *mUartDevice;
|
|
std::thread mUartRecvThread;
|
|
std::thread mMcuAskHandleThread;
|
|
bool mThreadRuning;
|
|
std::list<std::shared_ptr<VMcuAsk>> mAllAsk;
|
|
};
|
|
#endif |