mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
53 lines
1.5 KiB
C++
53 lines
1.5 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 MCUASK_BASE_H
|
|
#define MCUASK_BASE_H
|
|
#include "IMcuManager.h"
|
|
#include <semaphore.h>
|
|
constexpr unsigned int ASK_NEVER_TIMEOUT = 0;
|
|
constexpr unsigned int DEFAULT_ASK_TIMEOUT = 5000;
|
|
enum class McuAskBlock
|
|
{
|
|
BLOCK = 0,
|
|
NOT_BLOCK,
|
|
UNRELATED,
|
|
END
|
|
};
|
|
enum class McuAskReply
|
|
{
|
|
NEED_REPLY = 0,
|
|
NEED_NOT_REPLY,
|
|
END
|
|
};
|
|
class McuAskBase : virtual public VMcuAsk
|
|
{
|
|
public:
|
|
McuAskBase(const McuAskBlock isBlock, const McuAskReply needReply,
|
|
const unsigned int timeoutMs = DEFAULT_ASK_TIMEOUT);
|
|
virtual ~McuAskBase() = default;
|
|
ASK_RESULT Blocking(void) override;
|
|
bool NeedReply(void) override;
|
|
void ReplyFinished(const bool result) override;
|
|
bool IfTimeout(const unsigned int &integrationTimeMs) override;
|
|
|
|
protected:
|
|
sem_t mSem;
|
|
McuAskBlock mIsBlock;
|
|
McuAskReply mNeedReply;
|
|
bool mReplyOK;
|
|
unsigned int mTimeout;
|
|
unsigned int mWaitingTimeMs;
|
|
};
|
|
#endif |