Add:LedManager code.
This commit is contained in:
parent
d05a8757cf
commit
fdbe733bc7
|
@ -545,6 +545,9 @@ unsigned char REPLY_IPC_MISSION[] = {0xFA, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x01, 0
|
||||||
|
|
||||||
   流水号必须大于等于1,0用于代码初始化值,代码意义上表示无效的流水号。
|
   流水号必须大于等于1,0用于代码初始化值,代码意义上表示无效的流水号。
|
||||||
|
|
||||||
|
**协议收发匹配逻辑**
|
||||||
|
   协议发送时,附带自管理的流水号,对端回复时,根据流水号绑定发送的协议,为了避免对端回复时,流水号错误导致的业务逻辑错乱,本端除了匹配流水号,还需要根据协议匹配回复的命令字,保证回复内容的有效匹配。如果流水号和命令字无法同时匹配,该回复的数据包被丢弃。
|
||||||
|
|
||||||
**校验码算法**
|
**校验码算法**
|
||||||
|
|
||||||
   校验码算法使用ModBus CRC16方法计算。
|
   校验码算法使用ModBus CRC16方法计算。
|
||||||
|
@ -644,7 +647,7 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
|
||||||
| 命令字 | CPU | MCU | 数据段 | 协议解析 | 备注 |
|
| 命令字 | CPU | MCU | 数据段 | 协议解析 | 备注 |
|
||||||
|----|----|----|----|----|----|
|
|----|----|----|----|----|----|
|
||||||
| 0x8101 | ask | - | - | 获取启动模式 | - |
|
| 0x8101 | ask | - | - | 获取启动模式 | - |
|
||||||
| 0x0101 | - | reply/ask | Data[0]:启动模式<br>0x01:PIR启动<br>0x02:TEST启动<br>0x03:连拍启动<br>0x04:PIR延时启动<br>0x05:定时(间隔一定时间)启动 | 回复启动模式 | - |
|
| 0x0101 | - | reply | Data[0]:启动模式<br>0x01:PIR启动<br>0x02:TEST启动<br>0x03:连拍启动<br>0x04:PIR延时启动<br>0x05:定时(间隔一定时间)启动 | 回复启动模式 | - |
|
||||||
| 0x8102 | ask | - | - | 断电关机 | - |
|
| 0x8102 | ask | - | - | 断电关机 | - |
|
||||||
| 0x8103 | ask | - | - | 喂狗 | - |
|
| 0x8103 | ask | - | - | 喂狗 | - |
|
||||||
| 0x8104 | ask | - | Data[0]:Hour<br>0-23<br>Data[1]:Min<br>0-59<br>Data[2]:Sec<br>0-59 | 开启狗/设置喂狗周期 | - |
|
| 0x8104 | ask | - | Data[0]:Hour<br>0-23<br>Data[1]:Min<br>0-59<br>Data[2]:Sec<br>0-59 | 开启狗/设置喂狗周期 | - |
|
||||||
|
|
|
@ -23,15 +23,15 @@ const StatusCode DeviceManager::Init(void)
|
||||||
{
|
{
|
||||||
KeyManager::GetInstance()->Init();
|
KeyManager::GetInstance()->Init();
|
||||||
KeyManager::GetInstance()->StartTimer();
|
KeyManager::GetInstance()->StartTimer();
|
||||||
// LedManager::GetInstance()->Init();
|
LedManager::GetInstance()->Init();
|
||||||
// LedManager::GetInstance()->StartTimer();
|
LedManager::GetInstance()->StartTimer();
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatusCode DeviceManager::UnInit(void)
|
const StatusCode DeviceManager::UnInit(void)
|
||||||
{
|
{
|
||||||
KeyManager::GetInstance()->UnInit();
|
KeyManager::GetInstance()->UnInit();
|
||||||
// LedManager::GetInstance()->UnInit();
|
LedManager::GetInstance()->UnInit();
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor)
|
const StatusCode DeviceManager::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor)
|
||||||
|
|
|
@ -33,7 +33,6 @@ void LedManager::Init(void)
|
||||||
std::map<std::string, std::shared_ptr<VLedHal>> allLeds;
|
std::map<std::string, std::shared_ptr<VLedHal>> allLeds;
|
||||||
IHalCpp::GetInstance()->GetAllLeds(allLeds);
|
IHalCpp::GetInstance()->GetAllLeds(allLeds);
|
||||||
LedConversion(allLeds);
|
LedConversion(allLeds);
|
||||||
StartTimer();
|
|
||||||
}
|
}
|
||||||
void LedManager::UnInit(void)
|
void LedManager::UnInit(void)
|
||||||
{
|
{
|
||||||
|
@ -85,6 +84,7 @@ void LedManager::LedConversion(std::map<std::string, std::shared_ptr<VLedHal>> &
|
||||||
for (iter = ledHal.begin(); iter != ledHal.end(); ++iter) {
|
for (iter = ledHal.begin(); iter != ledHal.end(); ++iter) {
|
||||||
std::shared_ptr<VLedControl> led = std::dynamic_pointer_cast<VLedControl>(iter->second);
|
std::shared_ptr<VLedControl> led = std::dynamic_pointer_cast<VLedControl>(iter->second);
|
||||||
if (led) {
|
if (led) {
|
||||||
|
LogInfo("Get led [%s].\n", iter->first.c_str());
|
||||||
mAllLedHal[iter->first] = led;
|
mAllLedHal[iter->first] = led;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#ifndef HAL_TEST_TOOL_H
|
#ifndef HAL_TEST_TOOL_H
|
||||||
#define HAL_TEST_TOOL_H
|
#define HAL_TEST_TOOL_H
|
||||||
#include "IHalCpp.h"
|
#include "IHalCpp.h"
|
||||||
// #include "KeyControl.h"
|
#include "LedControl.h"
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
|
@ -56,8 +56,10 @@ public:
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
void SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
void SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||||
|
void SetAllLedsResult(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||||
// void SetKeyEvent(const std::string keyName, const KeyHalEvent &event); // TODO: unused function?
|
// void SetKeyEvent(const std::string keyName, const KeyHalEvent &event); // TODO: unused function?
|
||||||
void SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
|
void SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
|
||||||
|
void SetLedStateExpectations(const std::string &ledName, const LedState &state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) {}
|
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) {}
|
||||||
|
@ -72,11 +74,19 @@ private:
|
||||||
void InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
void InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||||
void InitKeysMock(std::shared_ptr<VKeyHal> &vMock);
|
void InitKeysMock(std::shared_ptr<VKeyHal> &vMock);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SetAllLedsResult(std::shared_ptr<IHalCpp> &vMock, std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||||
|
std::shared_ptr<VLedHal> SearchLed(const std::string &ledName);
|
||||||
|
void InitAllLedsMock(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||||
|
void InitLedsMock(std::shared_ptr<VLedHal> &vMock);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<VKeyHal> MakeKeyHalTest(const std::string &keyName);
|
static std::shared_ptr<VKeyHal> MakeKeyHalTest(const std::string &keyName);
|
||||||
|
static std::shared_ptr<VLedHal> MakeLedHalTest(const std::string &ledName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<IHalCpp> mHalMock;
|
std::shared_ptr<IHalCpp> mHalMock;
|
||||||
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeys;
|
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeys;
|
||||||
|
std::map<std::string, std::shared_ptr<VLedHal>> mAllLeds;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -18,6 +18,7 @@
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "KeyControl.h"
|
#include "KeyControl.h"
|
||||||
#include "KeyControlMock.h"
|
#include "KeyControlMock.h"
|
||||||
|
#include "LedControlMock.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
void HalTestTool::Init(void)
|
void HalTestTool::Init(void)
|
||||||
{
|
{
|
||||||
|
@ -30,6 +31,8 @@ void HalTestTool::UnInit(void)
|
||||||
{
|
{
|
||||||
mHalMock.reset();
|
mHalMock.reset();
|
||||||
CancelOverrideHalMakePtrObject();
|
CancelOverrideHalMakePtrObject();
|
||||||
|
mAllKeys.clear();
|
||||||
|
mAllLeds.clear();
|
||||||
}
|
}
|
||||||
void HalTestTool::SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
void HalTestTool::SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +40,12 @@ void HalTestTool::SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal
|
||||||
SetAllKeysResult(halMock, allKeys);
|
SetAllKeysResult(halMock, allKeys);
|
||||||
mAllKeys = allKeys;
|
mAllKeys = allKeys;
|
||||||
}
|
}
|
||||||
|
void HalTestTool::SetAllLedsResult(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||||
|
{
|
||||||
|
std::shared_ptr<IHalCpp> halMock = mHalMock;
|
||||||
|
SetAllLedsResult(halMock, allLeds);
|
||||||
|
mAllLeds = allLeds;
|
||||||
|
}
|
||||||
// void HalTestTool::SetKeyEvent(const std::string keyName, const KeyHalEvent &event)
|
// void HalTestTool::SetKeyEvent(const std::string keyName, const KeyHalEvent &event)
|
||||||
// {
|
// {
|
||||||
// std::shared_ptr<VKeyHal> key = SearchKey(keyName);
|
// std::shared_ptr<VKeyHal> key = SearchKey(keyName);
|
||||||
|
@ -69,6 +78,21 @@ void HalTestTool::SetKeyClick(const std::string &keyName, const unsigned int &pr
|
||||||
LogWarning("Key mock error.\n");
|
LogWarning("Key mock error.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void HalTestTool::SetLedStateExpectations(const std::string &ledName, const LedState &state)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VLedHal> led = SearchLed(ledName);
|
||||||
|
if (!led) {
|
||||||
|
LogError("Can't set led state, led not found.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::shared_ptr<LedControlMock> ledMock = std::dynamic_pointer_cast<LedControlMock>(led);
|
||||||
|
if (ledMock) {
|
||||||
|
LedControlMock::SetLedStateMock(ledMock, state);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("led mock error.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
void HalTestTool::KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs)
|
void HalTestTool::KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs)
|
||||||
{
|
{
|
||||||
std::shared_ptr<KeyControlMock> mock = std::dynamic_pointer_cast<KeyControlMock>(vMock);
|
std::shared_ptr<KeyControlMock> mock = std::dynamic_pointer_cast<KeyControlMock>(vMock);
|
||||||
|
@ -109,13 +133,6 @@ void HalTestTool::InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>
|
||||||
for (iter = allKeys.begin(); iter != allKeys.end(); ++iter) {
|
for (iter = allKeys.begin(); iter != allKeys.end(); ++iter) {
|
||||||
std::shared_ptr<VKeyHal> keyHal = iter->second;
|
std::shared_ptr<VKeyHal> keyHal = iter->second;
|
||||||
InitKeysMock(keyHal);
|
InitKeysMock(keyHal);
|
||||||
// std::shared_ptr<KeyControlMock> mock = std::dynamic_pointer_cast<KeyControlMock>(keyHal);
|
|
||||||
// if (mock) {
|
|
||||||
// InitKeysMock(mock);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// LogWarning("Invalid key mock.\n");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HalTestTool::InitKeysMock(std::shared_ptr<VKeyHal> &vMock)
|
void HalTestTool::InitKeysMock(std::shared_ptr<VKeyHal> &vMock)
|
||||||
|
@ -152,8 +169,67 @@ void HalTestTool::SetAllKeysResult(std::shared_ptr<IHalCpp> &vMock,
|
||||||
.WillRepeatedly(DoAll(SetArgReferee<0>(allKeys), Return(CreateStatusCode(STATUS_CODE_OK))));
|
.WillRepeatedly(DoAll(SetArgReferee<0>(allKeys), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||||
InitAllKeysMock(allKeys);
|
InitAllKeysMock(allKeys);
|
||||||
}
|
}
|
||||||
|
void HalTestTool::SetAllLedsResult(std::shared_ptr<IHalCpp> &vMock,
|
||||||
|
std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||||
|
{
|
||||||
|
std::shared_ptr<HalCppMock> mock = std::dynamic_pointer_cast<HalCppMock>(vMock);
|
||||||
|
if (!mock) {
|
||||||
|
LogError("vMock error.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Note: The SetArgReference function cannot be used here, as it will prevent the smart pointer from being released
|
||||||
|
* within the TEST range, resulting in an error only being reported after all test cases have finished running.
|
||||||
|
* Can't use:
|
||||||
|
* EXPECT_CALL(*mock.get(), GetAllLedsTrace(_))
|
||||||
|
* .WillRepeatedly(DoAll(SetArgReferee<0>(allLeds), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||||
|
*/
|
||||||
|
auto getAllLeds = [=, &allLeds](std::map<std::string, std::shared_ptr<VLedHal>> &setAllLeds) {
|
||||||
|
setAllLeds = allLeds;
|
||||||
|
};
|
||||||
|
EXPECT_CALL(*mock.get(), GetAllLedsTrace(_))
|
||||||
|
.WillRepeatedly(DoAll(WithArgs<0>(Invoke(getAllLeds)), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||||
|
InitAllLedsMock(allLeds);
|
||||||
|
}
|
||||||
|
std::shared_ptr<VLedHal> HalTestTool::SearchLed(const std::string &ledName)
|
||||||
|
{
|
||||||
|
std::shared_ptr<LedControlMock> mock;
|
||||||
|
std::map<std::string, std::shared_ptr<VLedHal>>::iterator iter;
|
||||||
|
iter = mAllLeds.find(ledName);
|
||||||
|
if (iter != mAllLeds.end()) {
|
||||||
|
mock = std::dynamic_pointer_cast<LedControlMock>(mAllLeds[ledName]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("Can't found the led control.\n");
|
||||||
|
}
|
||||||
|
return mock;
|
||||||
|
}
|
||||||
|
void HalTestTool::InitAllLedsMock(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||||
|
{
|
||||||
|
std::map<std::string, std::shared_ptr<VLedHal>>::iterator iter;
|
||||||
|
for (iter = allLeds.begin(); iter != allLeds.end(); ++iter) {
|
||||||
|
std::shared_ptr<VLedHal> ledHal = iter->second;
|
||||||
|
InitLedsMock(ledHal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void HalTestTool::InitLedsMock(std::shared_ptr<VLedHal> &vMock)
|
||||||
|
{
|
||||||
|
std::shared_ptr<LedControlMock> mock = std::dynamic_pointer_cast<LedControlMock>(vMock);
|
||||||
|
if (!mock) {
|
||||||
|
LogError("vMock error.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
constexpr int LED_SHOULD_NOT_BE_CONTROLED_WHEN_NOBODY_CONTROL_IT = 0;
|
||||||
|
EXPECT_CALL(*mock.get(), SetLedStateTrace(_)).Times(LED_SHOULD_NOT_BE_CONTROLED_WHEN_NOBODY_CONTROL_IT);
|
||||||
|
}
|
||||||
std::shared_ptr<VKeyHal> HalTestTool::MakeKeyHalTest(const std::string &keyName)
|
std::shared_ptr<VKeyHal> HalTestTool::MakeKeyHalTest(const std::string &keyName)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VKeyHal> key = std::make_shared<KeyControlMock>(keyName);
|
std::shared_ptr<VKeyHal> key = std::make_shared<KeyControlMock>(keyName);
|
||||||
return key;
|
return key;
|
||||||
|
}
|
||||||
|
std::shared_ptr<VLedHal> HalTestTool::MakeLedHalTest(const std::string &ledName)
|
||||||
|
{
|
||||||
|
std::shared_ptr<VLedHal> led = std::make_shared<LedControlMock>(ledName);
|
||||||
|
return led;
|
||||||
}
|
}
|
|
@ -13,6 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "LedControlMock.h"
|
#include "LedControlMock.h"
|
||||||
|
#include "ILog.h"
|
||||||
LedControlTest::LedControlTest(const std::string &ledName) : mLedName(ledName)
|
LedControlTest::LedControlTest(const std::string &ledName) : mLedName(ledName)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
@ -20,4 +21,28 @@ LedControlTest::LedControlTest(const std::string &ledName) : mLedName(ledName)
|
||||||
LedControlMock::LedControlMock(const std::string &ledName) : LedControlTest(ledName)
|
LedControlMock::LedControlMock(const std::string &ledName) : LedControlTest(ledName)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
}
|
||||||
|
StatusCode LedControlTest::SetLedState(const LedState &state)
|
||||||
|
{
|
||||||
|
LogInfo("SetLedState mLedName = %s, state = %s\n", mLedName.c_str(), PrintLedState(state));
|
||||||
|
StatusCode code = SetLedStateTrace(state);
|
||||||
|
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||||
|
// return SetLedState(state);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
StatusCode LedControlTest::SetLedStateTrace(const LedState &state)
|
||||||
|
{
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
void LedControlMock::SetLedStateMock(std::shared_ptr<LedControlMock> &mock, const LedState &state)
|
||||||
|
{
|
||||||
|
LogInfo("LedControlMock::SetLedState\n");
|
||||||
|
constexpr int SOMEBODY_CONTROL_LED = 1;
|
||||||
|
EXPECT_CALL(*mock.get(), SetLedStateTrace(_))
|
||||||
|
// .Times(SOMEBODY_CONTROL_LED)
|
||||||
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
EXPECT_CALL(*mock.get(), SetLedStateTrace(state))
|
||||||
|
.Times(SOMEBODY_CONTROL_LED)
|
||||||
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#ifndef LED_CONTROL_MOCK_H
|
#ifndef LED_CONTROL_MOCK_H
|
||||||
#define LED_CONTROL_MOCK_H
|
#define LED_CONTROL_MOCK_H
|
||||||
|
#include "HalTestTool.h"
|
||||||
#include "IHalCpp.h"
|
#include "IHalCpp.h"
|
||||||
#include "LedControl.h"
|
#include "LedControl.h"
|
||||||
class LedControlTest : public LedControl, public VLedHal
|
class LedControlTest : public LedControl, public VLedHal
|
||||||
|
@ -21,6 +22,10 @@ class LedControlTest : public LedControl, public VLedHal
|
||||||
public:
|
public:
|
||||||
LedControlTest(const std::string &ledName);
|
LedControlTest(const std::string &ledName);
|
||||||
virtual ~LedControlTest() = default;
|
virtual ~LedControlTest() = default;
|
||||||
|
StatusCode SetLedState(const LedState &state) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual StatusCode SetLedStateTrace(const LedState &state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string mLedName;
|
const std::string mLedName;
|
||||||
|
@ -30,5 +35,9 @@ class LedControlMock : public LedControlTest
|
||||||
public:
|
public:
|
||||||
LedControlMock(const std::string &ledName);
|
LedControlMock(const std::string &ledName);
|
||||||
virtual ~LedControlMock() = default;
|
virtual ~LedControlMock() = default;
|
||||||
|
MOCK_METHOD1(SetLedStateTrace, StatusCode(const LedState &));
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void SetLedStateMock(std::shared_ptr<LedControlMock> &mock, const LedState &state);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -11,6 +11,7 @@ include_directories(
|
||||||
# ${UTILS_SOURCE_PATH}/UartDevice/include
|
# ${UTILS_SOURCE_PATH}/UartDevice/include
|
||||||
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||||
|
${UTILS_SOURCE_PATH}/LedControl/include
|
||||||
${HAL_SOURCE_PATH}/include
|
${HAL_SOURCE_PATH}/include
|
||||||
# ${HAL_SOURCE_PATH}/src
|
# ${HAL_SOURCE_PATH}/src
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
namespace DeviceManagerTest
|
namespace DeviceManagerTest
|
||||||
{
|
{
|
||||||
const char *KEY_TEST = "TEST";
|
const char *KEY_TEST = "KEY_TEST";
|
||||||
|
const char *LED_TEST = "LED_TEST";
|
||||||
class DeviceManagerTest : public testing::Test, virtual public HalTestTool, public DeviceManagerTestTool
|
class DeviceManagerTest : public testing::Test, virtual public HalTestTool, public DeviceManagerTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -55,17 +56,21 @@ private:
|
||||||
{
|
{
|
||||||
std::shared_ptr<VKeyHal> key = HalTestTool::MakeKeyHalTest(KEY_TEST);
|
std::shared_ptr<VKeyHal> key = HalTestTool::MakeKeyHalTest(KEY_TEST);
|
||||||
mAllKeysMock[KEY_TEST] = key;
|
mAllKeysMock[KEY_TEST] = key;
|
||||||
|
std::shared_ptr<VLedHal> led = HalTestTool::MakeLedHalTest(LED_TEST);
|
||||||
|
mAllLedsMock[LED_TEST] = led;
|
||||||
}
|
}
|
||||||
void DestroyAllKeysMock(void)
|
void DestroyAllKeysMock(void)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
mAllKeysMock.clear();
|
mAllKeysMock.clear();
|
||||||
|
mAllLedsMock.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// std::shared_ptr<LinuxTest> mLinuxTest;
|
// std::shared_ptr<LinuxTest> mLinuxTest;
|
||||||
protected:
|
protected:
|
||||||
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeysMock;
|
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeysMock;
|
||||||
|
std::map<std::string, std::shared_ptr<VLedHal>> mAllLedsMock;
|
||||||
};
|
};
|
||||||
// ../output_files/test/bin/DeviceManagerTest
|
// ../output_files/test/bin/DeviceManagerTest
|
||||||
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyShortPress
|
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyShortPress
|
||||||
|
@ -133,11 +138,15 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_SetKeyMonitor)
|
||||||
IDeviceManager::GetInstance()->UnInit();
|
IDeviceManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
// ../output_files/test/bin/DeviceManagerTest
|
// ../output_files/test/bin/DeviceManagerTest
|
||||||
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControLed
|
// --gtest_filter=DeviceManagerTest.INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControlLed
|
||||||
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControLed)
|
TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_ControlLed)
|
||||||
{
|
{
|
||||||
// IDeviceManager::GetInstance()->Init();
|
SetAllLedsResult(mAllLedsMock);
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
IDeviceManager::GetInstance()->Init();
|
||||||
// IDeviceManager::GetInstance()->UnInit();
|
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||||
|
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||||
|
ControlLed(LED_TEST, LedState::ON, KEEP_ALIVE_FOREVER, LED_NOT_BLINK);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
IDeviceManager::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
} // namespace DeviceManagerTest
|
} // namespace DeviceManagerTest
|
|
@ -7,6 +7,7 @@ include_directories(
|
||||||
./include
|
./include
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
|
${UTILS_SOURCE_PATH}/LedControl/include
|
||||||
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
# ${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
|
@ -18,7 +19,7 @@ include_directories(
|
||||||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||||
set(TEST_TOOL_TARGET DeviceManagerTestTool)
|
set(TEST_TOOL_TARGET DeviceManagerTestTool)
|
||||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||||
target_link_libraries(${TEST_TOOL_TARGET} Log)
|
target_link_libraries(${TEST_TOOL_TARGET} LedControl Log)
|
||||||
|
|
||||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define DEVICE_MANAGER_TEST_TOOL_H
|
#define DEVICE_MANAGER_TEST_TOOL_H
|
||||||
#include "DeviceManager.h"
|
#include "DeviceManager.h"
|
||||||
#include "HalTestTool.h"
|
#include "HalTestTool.h"
|
||||||
|
#include "LedControl.h"
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
|
@ -82,6 +83,10 @@ public:
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<VirtualLedControl> ControlLed(const std::string &ledName, const LedState &state,
|
||||||
|
const unsigned int &aliveTimeMs, const unsigned int &blinkTimeMs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) override;
|
void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs) override;
|
||||||
|
|
||||||
|
@ -90,6 +95,7 @@ private:
|
||||||
void KeyMonitorInit(std::shared_ptr<KeyMonitorMock> &mock, const std::string &keyName,
|
void KeyMonitorInit(std::shared_ptr<KeyMonitorMock> &mock, const std::string &keyName,
|
||||||
const unsigned int &pressingTimeMs);
|
const unsigned int &pressingTimeMs);
|
||||||
|
|
||||||
|
public:
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DeviceManagerMock> mDeviceManagerMock;
|
std::shared_ptr<DeviceManagerMock> mDeviceManagerMock;
|
||||||
std::shared_ptr<KeyMonitorMock> mKeyMonitorMock;
|
std::shared_ptr<KeyMonitorMock> mKeyMonitorMock;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "DeviceManagerMakePtrTest.h"
|
#include "DeviceManagerMakePtrTest.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "KeyControl.h"
|
#include "KeyControl.h"
|
||||||
|
#include "SingleControlMock.h"
|
||||||
const StatusCode DeviceManagerTool::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor)
|
const StatusCode DeviceManagerTool::SetAllKeysMonitor(std::shared_ptr<VKeyMonitor> &monitor)
|
||||||
{
|
{
|
||||||
LogInfo("DeviceManagerTool::SetAllKeysMonitor\n");
|
LogInfo("DeviceManagerTool::SetAllKeysMonitor\n");
|
||||||
|
@ -37,6 +38,16 @@ void DeviceManagerTestTool::UnInit(void)
|
||||||
mKeyMonitorMock.reset();
|
mKeyMonitorMock.reset();
|
||||||
CancelOverrideDeviceMakePtrObject();
|
CancelOverrideDeviceMakePtrObject();
|
||||||
}
|
}
|
||||||
|
std::shared_ptr<VirtualLedControl> DeviceManagerTestTool::ControlLed(const std::string &ledName, const LedState &state,
|
||||||
|
const unsigned int &aliveTimeMs,
|
||||||
|
const unsigned int &blinkTimeMs)
|
||||||
|
{
|
||||||
|
HalTestTool::SetLedStateExpectations(ledName, state);
|
||||||
|
std::shared_ptr<VirtualLedControl> ledControl =
|
||||||
|
std::make_shared<SingleControlMock>(state, aliveTimeMs, blinkTimeMs);
|
||||||
|
IDeviceManager::GetInstance()->ControlLed(ledName, ledControl);
|
||||||
|
return ledControl;
|
||||||
|
}
|
||||||
void DeviceManagerTestTool::DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
|
void DeviceManagerTestTool::DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||||
{
|
{
|
||||||
LogInfo("DeviceManagerTestTool::DeviceManagerNotice\n");
|
LogInfo("DeviceManagerTestTool::DeviceManagerNotice\n");
|
||||||
|
|
32
test/middleware/DeviceManager/tool/src/SingleControlMock.cpp
Normal file
32
test/middleware/DeviceManager/tool/src/SingleControlMock.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include "SingleControlMock.h"
|
||||||
|
SingleControlTool::SingleControlTool(const LedState &state, const unsigned int aliveTimeMs,
|
||||||
|
const unsigned int &blinkTimeMs)
|
||||||
|
: mState(state), mAliveTimeMs(aliveTimeMs), mBlinkTimeMs(blinkTimeMs)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
StatusCode SingleControlTool::GetLedState(LedState &state)
|
||||||
|
{
|
||||||
|
state = mState;
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
SingleControlMock::SingleControlMock(const LedState &state, const unsigned int aliveTimeMs,
|
||||||
|
const unsigned int &blinkTimeMs)
|
||||||
|
: SingleControlTool(state, aliveTimeMs, blinkTimeMs)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
39
test/middleware/DeviceManager/tool/src/SingleControlMock.h
Normal file
39
test/middleware/DeviceManager/tool/src/SingleControlMock.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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 LED_CONTROL_MOCK_H
|
||||||
|
#define LED_CONTROL_MOCK_H
|
||||||
|
#include "IDeviceManager.h"
|
||||||
|
#include "LedControl.h"
|
||||||
|
class SingleControlTool : public VSingleControl, public VirtualLedControl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SingleControlTool(const LedState &state, const unsigned int aliveTimeMs, const unsigned int &blinkTimeMs);
|
||||||
|
virtual ~SingleControlTool() = default;
|
||||||
|
virtual StatusCode GetLedState(LedState &state);
|
||||||
|
virtual unsigned int GetKeepAliveTimeMs(void) { return mAliveTimeMs; }
|
||||||
|
virtual unsigned int GetBlinkTimeMs(void) { return mBlinkTimeMs; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const LedState mState;
|
||||||
|
const unsigned int mAliveTimeMs;
|
||||||
|
const unsigned int mBlinkTimeMs;
|
||||||
|
};
|
||||||
|
class SingleControlMock : public SingleControlTool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SingleControlMock(const LedState &state, const unsigned int aliveTimeMs, const unsigned int &blinkTimeMs);
|
||||||
|
virtual ~SingleControlMock() = default;
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -53,7 +53,7 @@ class VLedControl
|
||||||
public:
|
public:
|
||||||
VLedControl() = default;
|
VLedControl() = default;
|
||||||
virtual ~VLedControl() = default;
|
virtual ~VLedControl() = default;
|
||||||
virtual bool SetLedState(const LedState &state) { return false; }
|
virtual StatusCode SetLedState(const LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||||
virtual void AddLedState(std::shared_ptr<VSingleControl> &control) {}
|
virtual void AddLedState(std::shared_ptr<VSingleControl> &control) {}
|
||||||
virtual void CheckState(const unsigned int &period) {}
|
virtual void CheckState(const unsigned int &period) {}
|
||||||
// virtual void SetHalLedState(const VirtualLedState &state) {}
|
// virtual void SetHalLedState(const VirtualLedState &state) {}
|
||||||
|
@ -65,7 +65,7 @@ public:
|
||||||
LedControl() = default;
|
LedControl() = default;
|
||||||
virtual ~LedControl() = default;
|
virtual ~LedControl() = default;
|
||||||
void CheckState(const unsigned int &period) override;
|
void CheckState(const unsigned int &period) override;
|
||||||
void AddLedState(std::shared_ptr<VSingleControl> &state);
|
void AddLedState(std::shared_ptr<VSingleControl> &state) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void NewLedStateStart(void);
|
void NewLedStateStart(void);
|
||||||
|
@ -79,4 +79,5 @@ private:
|
||||||
unsigned int mStateAliveTime;
|
unsigned int mStateAliveTime;
|
||||||
unsigned int mBlinkPeriod;
|
unsigned int mBlinkPeriod;
|
||||||
};
|
};
|
||||||
|
const char *PrintLedState(const LedState &state);
|
||||||
#endif
|
#endif
|
|
@ -97,4 +97,28 @@ void LedControl::BlinkOn(std::shared_ptr<VSingleControl> &state, const LedState
|
||||||
mCurrentState = onState;
|
mCurrentState = onState;
|
||||||
mBlinkPeriod = 0;
|
mBlinkPeriod = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
const char *PrintLedState(const LedState &state)
|
||||||
|
{
|
||||||
|
switch (state) {
|
||||||
|
case LedState::OFF: {
|
||||||
|
return "OFF";
|
||||||
|
}
|
||||||
|
case LedState::ON: {
|
||||||
|
return "ON";
|
||||||
|
}
|
||||||
|
case LedState::GREEN: {
|
||||||
|
return "GREEN";
|
||||||
|
}
|
||||||
|
case LedState::RED: {
|
||||||
|
return "RED";
|
||||||
|
}
|
||||||
|
case LedState::YELLOW: {
|
||||||
|
return "YELLOW";
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
return "Unknown LedState";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user