From 532598fbaa68d71529f24dbd00822e27b3fa60d6 Mon Sep 17 00:00:00 2001 From: jas <1790731762@qq.com> Date: Sun, 7 Jan 2024 21:39:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[zhoulongyu]:=20=E5=AE=8C=E5=96=84Led=20?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=B1=82=E5=92=8C=E4=B8=AD=E9=97=B4=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hal/include/IHalCpp.h | 56 +++++++++++++++- hal/src/HalCpp.cpp | 5 ++ hal/src/HalCpp.h | 5 ++ .../DeviceManager/include/IDeviceManager.h | 12 ++++ .../DeviceManager/src/DeviceManager.cpp | 49 ++++++++++++++ middleware/DeviceManager/src/DeviceManager.h | 39 +++++++++++ middleware/DeviceManager/src/LedManager.cpp | 67 +++++++++++++++++++ middleware/DeviceManager/src/LedManager.h | 57 ++++++++++++++++ 8 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 middleware/DeviceManager/src/DeviceManager.cpp create mode 100644 middleware/DeviceManager/src/DeviceManager.h create mode 100644 middleware/DeviceManager/src/LedManager.cpp create mode 100644 middleware/DeviceManager/src/LedManager.h diff --git a/hal/include/IHalCpp.h b/hal/include/IHalCpp.h index 66a49936..e9c9891e 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -16,6 +16,7 @@ #define IHALCPP_H #include "StatusCode.h" #include +#include #include constexpr int INVALID_PERIOD = -1; constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100; @@ -44,6 +45,55 @@ public: virtual void SetKeyHalOwner(std::shared_ptr owner) {} virtual const std::string GetKeyName(void) { return "undefine"; } }; + + +enum class LedState +{ + LED_STATE_OFF = 0, + LED_STATE_ON, + LED_STATE_GREEN, + LED_STATE_RED, + LED_STATE_YELLOW, + LED_STATE_LEVEL_0, + LED_STATE_LEVEL_1, + LED_STATE_LEVEL_2, + LED_STATE_LEVEL_3, + LED_STATE_LEVEL_4, + LED_STATE_LEVEL_END, + LED_STATE_END +}; + + +class VLedHal +{ +public: + VLedHal() = default; + ~VLedHal() = default; + virtual StatusCode SetLedState(const LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual StatusCode GetLedName(std::string &LedName) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +}; + + +#if 0 +class WifiLed : public VLedHalOwner, public VLedHal +{ +public: + WifiLed() = default; + ~WifiLed() = default; + + // StatusCode SetLedHalOwner(std::shared_ptr owner) override; + StatusCode SetLedState(const LedState &state) override; + StatusCode GetLedName(std::string &LedName) override; + +private: + // VLedHalOwner m_LedHalOwner; + std::string m_LedName; + SF_LED_GPIO_IDX_E mPinRed; + SF_LED_GPIO_IDX_E mPinGreen; +} +#endif + + class IHalCpp { public: @@ -52,6 +102,10 @@ public: static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); virtual StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } virtual StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual StatusCode GetLedHal(std::vector> &ledHals) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } }; void CreateHalCppModule(void); -#endif \ No newline at end of file + + +#endif + diff --git a/hal/src/HalCpp.cpp b/hal/src/HalCpp.cpp index ba77430d..095c22b9 100644 --- a/hal/src/HalCpp.cpp +++ b/hal/src/HalCpp.cpp @@ -24,3 +24,8 @@ StatusCode HalCpp::UnInit(void) LogInfo("HalCpp::UnInit\n"); return CreateStatusCode(STATUS_CODE_OK); } +StatusCode HalCpp::GetLedHal(std::vector> &ledHals) +{ + ledHals = mLedHals; + return CreateStatusCode(STATUS_CODE_OK); +} diff --git a/hal/src/HalCpp.h b/hal/src/HalCpp.h index 1017cc2b..ead32f5b 100644 --- a/hal/src/HalCpp.h +++ b/hal/src/HalCpp.h @@ -22,5 +22,10 @@ public: virtual ~HalCpp() = default; StatusCode Init(void) override; StatusCode UnInit(void) override; + StatusCode GetLedHal(std::vector> &ledHals) override; + +private: + std::vector> mLedHals; + }; #endif \ No newline at end of file diff --git a/middleware/DeviceManager/include/IDeviceManager.h b/middleware/DeviceManager/include/IDeviceManager.h index f83e1e98..74fa4940 100644 --- a/middleware/DeviceManager/include/IDeviceManager.h +++ b/middleware/DeviceManager/include/IDeviceManager.h @@ -16,6 +16,7 @@ #define IDEVICEMANAGER_H #include "StatusCode.h" #include +#include "IHalCpp.h" enum class IpcMission { TEST = 0, @@ -29,6 +30,15 @@ enum class KeyAction HOLD_UP, END }; + +class VLedManager +{ +public: + VLedManager() = default; + ~VLedManager() = default; + virtual StatusCode SetLedState(LedState CurrentState, unsigned int KeepAliveTime) {return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +}; + class IDeviceManager { public: @@ -38,6 +48,8 @@ public: virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const IpcMission GetIpcMissiony(void) { return IpcMission::END; } + virtual const StatusCode GetLedManager(std::vector> &ledManagers) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + }; bool CreateDeviceManagerModule(void); #endif \ No newline at end of file diff --git a/middleware/DeviceManager/src/DeviceManager.cpp b/middleware/DeviceManager/src/DeviceManager.cpp new file mode 100644 index 00000000..7dc23035 --- /dev/null +++ b/middleware/DeviceManager/src/DeviceManager.cpp @@ -0,0 +1,49 @@ +/* + * 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 "DeviceManager.h" + +const StatusCode DeviceManager::Init(void) +{ + std::vector> ledHals; + IHalCpp::GetInstance()->GetLedHal(ledHals); + + for (auto it = ledHals.begin(); it != ledHals.end(); ++it) + { + std::shared_ptr ledHal = *it; + std::shared_ptr ledOut = std::make_shared(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, BLINKING_FAST_MS); + mLedManagers.push_back(ledOut); + } + return CreateStatusCode(STATUS_CODE_OK); +} +const StatusCode DeviceManager::UnInit(void) +{ + if (!mLedManagers.empty()) + { + mLedManagers.clear(); + } + + return CreateStatusCode(STATUS_CODE_OK); +} +const IpcMission DeviceManager::GetIpcMissiony(void) +{ + return IpcMission::TEST; +} +const StatusCode DeviceManager::GetLedManager(std::vector> &ledManagers) +{ + ledManagers = mLedManagers; + return CreateStatusCode(STATUS_CODE_OK); +} + diff --git a/middleware/DeviceManager/src/DeviceManager.h b/middleware/DeviceManager/src/DeviceManager.h new file mode 100644 index 00000000..d431bd5c --- /dev/null +++ b/middleware/DeviceManager/src/DeviceManager.h @@ -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 DEVICEMANAGER_H +#define DEVICEMANAGER_H +#include "LedManager.h" +#include "IDeviceManager.h" + + +class DeviceManager : public IDeviceManager +{ +public: + DeviceManager() = default; + virtual ~DeviceManager() = default; + + const StatusCode Init(void) override; + const StatusCode UnInit(void) override; + const IpcMission GetIpcMissiony(void) override; + const StatusCode GetLedManager(std::vector> &ledManagers) override; +private: + std::vector> mLedManagers; +}; + + + + +#endif + diff --git a/middleware/DeviceManager/src/LedManager.cpp b/middleware/DeviceManager/src/LedManager.cpp new file mode 100644 index 00000000..c32e4442 --- /dev/null +++ b/middleware/DeviceManager/src/LedManager.cpp @@ -0,0 +1,67 @@ +/* + * 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 "LedManager.h" +#include "ILog.h" + + + +LedManager::LedManager() +{ + mLedHal = nullptr; + mCurrentState = NEW_LED_STATE; + mBlinkPeriod = BLINKING_FAST_MS; + mKeepAliveTime = DEFAULT_KEEP_ALIVE_TIME; + mStateAliveTime = 0; +} +LedManager::LedManager(std::shared_ptr &LedHal, const LedState &CurrentState, + const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) + : mLedHal(LedHal), mCurrentState(CurrentState), mKeepAliveTime(KeepAliveTime), mBlinkPeriod(BlinkPeriod) +{ + mStateAliveTime = 0; +} + + +StatusCode LedManager::SetLedState(LedState CurrentState, unsigned int KeepAliveTime) +{ + mCurrentState = CurrentState; + mKeepAliveTime = KeepAliveTime; + return CreateStatusCode(STATUS_CODE_OK); +} + + +StatusCode LedManager::GetLedState(LedState &CurrentState) +{ + CurrentState = mCurrentState; + return CreateStatusCode(STATUS_CODE_OK); +} + +StatusCode LedManager::BlinkOn(LedState CurrentState, unsigned int KeepAliveTime) +{ + mKeepAliveTime = KeepAliveTime; + return CreateStatusCode(STATUS_CODE_OK); +} + +StatusCode LedManager::BlinkOff(void) +{ + mCurrentState = LedState::LED_STATE_OFF; + return CreateStatusCode(STATUS_CODE_OK); +} + + + + + + diff --git a/middleware/DeviceManager/src/LedManager.h b/middleware/DeviceManager/src/LedManager.h new file mode 100644 index 00000000..e258e2da --- /dev/null +++ b/middleware/DeviceManager/src/LedManager.h @@ -0,0 +1,57 @@ +/* + * 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_MANAGER_H +#define LED_MANAGER_H + +#include "IDeviceManager.h" +#include +#include + +constexpr LedState NEW_LED_STATE = LedState::LED_STATE_OFF; +constexpr unsigned int LED_NOT_BLINK = 0; +constexpr unsigned int BLINKING_FAST_MS = 500; +constexpr unsigned int BLINKING_SLOW_MS = 1000; +constexpr long int DEFAULT_KEEP_ALIVE_TIME = 1500; +constexpr unsigned int DELETED_LED_STATE = -1; +constexpr unsigned int DO_NOT_KEEP_ALIVE = -2; + +class LedManager : public VLedManager +{ +public: + LedManager(); + LedManager(std::shared_ptr &LedHal, const LedState &CurrentState, + const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, + const unsigned int &BlinkPeriod = BLINKING_FAST_MS + ); + ~LedManager() = default; + StatusCode Init(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode Unit(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode SetLedState(LedState CurrentState, unsigned int KeepAliveTime) override; + +public: + StatusCode GetLedState(LedState &CurrentState) {return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode BlinkOn(LedState CurrentState, unsigned int KeepAliveTime) {return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode BlinkOff(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); } + +private: + std::shared_ptr mLedHal; + LedState mCurrentState; // 当前状态 + unsigned int mBlinkPeriod; // 闪烁频率 + unsigned int mKeepAliveTime; // 保持存活时间 + unsigned int mStateAliveTime; // 状态保持时间 +}; + +#endif + From ca56f16a2048af628c114f1698ce91d0a283fb69 Mon Sep 17 00:00:00 2001 From: jas <1790731762@qq.com> Date: Tue, 9 Jan 2024 10:44:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[zhoulongyu]:=20=E5=AE=8C=E5=96=84Led?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?(=E6=B2=A1=E6=9C=89LedTimer)=E5=90=8E=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hal/include/IHalCpp.h | 46 +++++++++---------- hal/src/HalCpp.h | 1 - .../DeviceManager/include/IDeviceManager.h | 29 ++++++++++-- .../DeviceManager/src/DeviceManager.cpp | 25 ++++------ middleware/DeviceManager/src/DeviceManager.h | 9 +--- middleware/DeviceManager/src/LedManager.cpp | 21 +++------ middleware/DeviceManager/src/LedManager.h | 27 +++++------ test/utils/SharedData/src/SharedData_Test.cpp | 2 +- 8 files changed, 80 insertions(+), 80 deletions(-) diff --git a/hal/include/IHalCpp.h b/hal/include/IHalCpp.h index e9c9891e..5d8f3b54 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -16,8 +16,8 @@ #define IHALCPP_H #include "StatusCode.h" #include -#include #include +#include constexpr int INVALID_PERIOD = -1; constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100; constexpr int IMEI_LEN = 15; @@ -46,34 +46,34 @@ public: virtual const std::string GetKeyName(void) { return "undefine"; } }; - -enum class LedState +enum HalLedState { - LED_STATE_OFF = 0, - LED_STATE_ON, - LED_STATE_GREEN, - LED_STATE_RED, - LED_STATE_YELLOW, - LED_STATE_LEVEL_0, - LED_STATE_LEVEL_1, - LED_STATE_LEVEL_2, - LED_STATE_LEVEL_3, - LED_STATE_LEVEL_4, - LED_STATE_LEVEL_END, - LED_STATE_END + HAL_LED_STATE_OFF = 0, + HAL_LED_STATE_ON, + HAL_LED_STATE_GREEN, + HAL_LED_STATE_RED, + HAL_LED_STATE_YELLOW, + HAL_LED_STATE_LEVEL_0, + HAL_LED_STATE_LEVEL_1, + HAL_LED_STATE_LEVEL_2, + HAL_LED_STATE_LEVEL_3, + HAL_LED_STATE_LEVEL_4, + HAL_LED_STATE_LEVEL_END, + HAL_LED_STATE_END }; - class VLedHal { public: VLedHal() = default; ~VLedHal() = default; - virtual StatusCode SetLedState(const LedState &state) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual StatusCode SetHalLedState(const HalLedState &state) + { + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + } virtual StatusCode GetLedName(std::string &LedName) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } }; - #if 0 class WifiLed : public VLedHalOwner, public VLedHal { @@ -82,7 +82,7 @@ public: ~WifiLed() = default; // StatusCode SetLedHalOwner(std::shared_ptr owner) override; - StatusCode SetLedState(const LedState &state) override; + StatusCode SetHalLedState(const HalLedState &state) override; StatusCode GetLedName(std::string &LedName) override; private: @@ -93,7 +93,6 @@ private: } #endif - class IHalCpp { public: @@ -102,10 +101,11 @@ public: static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); virtual StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } virtual StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } - virtual StatusCode GetLedHal(std::vector> &ledHals) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual StatusCode GetLedHal(std::vector> &ledHals) + { + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + } }; void CreateHalCppModule(void); - #endif - diff --git a/hal/src/HalCpp.h b/hal/src/HalCpp.h index ead32f5b..09191f7b 100644 --- a/hal/src/HalCpp.h +++ b/hal/src/HalCpp.h @@ -26,6 +26,5 @@ public: private: std::vector> mLedHals; - }; #endif \ No newline at end of file diff --git a/middleware/DeviceManager/include/IDeviceManager.h b/middleware/DeviceManager/include/IDeviceManager.h index 74fa4940..2545fa0d 100644 --- a/middleware/DeviceManager/include/IDeviceManager.h +++ b/middleware/DeviceManager/include/IDeviceManager.h @@ -15,8 +15,9 @@ #ifndef IDEVICEMANAGER_H #define IDEVICEMANAGER_H #include "StatusCode.h" +#include #include -#include "IHalCpp.h" +#include enum class IpcMission { TEST = 0, @@ -31,12 +32,32 @@ enum class KeyAction END }; +enum LedState +{ + LED_STATE_OFF = 0, + LED_STATE_ON, + LED_STATE_GREEN, + LED_STATE_RED, + LED_STATE_YELLOW, + LED_STATE_LEVEL_0, + LED_STATE_LEVEL_1, + LED_STATE_LEVEL_2, + LED_STATE_LEVEL_3, + LED_STATE_LEVEL_4, + LED_STATE_LEVEL_END, + LED_STATE_END +}; + class VLedManager { public: VLedManager() = default; ~VLedManager() = default; - virtual StatusCode SetLedState(LedState CurrentState, unsigned int KeepAliveTime) {return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual StatusCode SetLedState(std::string ledName, LedState &CurrentState, const unsigned int &KeepAliveTime, + const unsigned int &BlinkPeriod) + { + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + } }; class IDeviceManager @@ -48,8 +69,8 @@ public: virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const IpcMission GetIpcMissiony(void) { return IpcMission::END; } - virtual const StatusCode GetLedManager(std::vector> &ledManagers) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } - + // virtual const StatusCode GetLedManager(std::vector> &ledManagers) { return + // CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } }; bool CreateDeviceManagerModule(void); #endif \ No newline at end of file diff --git a/middleware/DeviceManager/src/DeviceManager.cpp b/middleware/DeviceManager/src/DeviceManager.cpp index 7dc23035..7ebd0174 100644 --- a/middleware/DeviceManager/src/DeviceManager.cpp +++ b/middleware/DeviceManager/src/DeviceManager.cpp @@ -14,36 +14,27 @@ */ #include "DeviceManager.h" +#include -const StatusCode DeviceManager::Init(void) +const StatusCode DeviceManager::Init(void) { std::vector> ledHals; IHalCpp::GetInstance()->GetLedHal(ledHals); - for (auto it = ledHals.begin(); it != ledHals.end(); ++it) - { + for (auto it = ledHals.begin(); it != ledHals.end(); ++it) { std::shared_ptr ledHal = *it; - std::shared_ptr ledOut = std::make_shared(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, BLINKING_FAST_MS); + std::shared_ptr ledOut = + std::make_shared(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, BLINKING_FAST_MS); mLedManagers.push_back(ledOut); - } + } return CreateStatusCode(STATUS_CODE_OK); } const StatusCode DeviceManager::UnInit(void) { - if (!mLedManagers.empty()) - { + if (!mLedManagers.empty()) { mLedManagers.clear(); } return CreateStatusCode(STATUS_CODE_OK); } -const IpcMission DeviceManager::GetIpcMissiony(void) -{ - return IpcMission::TEST; -} -const StatusCode DeviceManager::GetLedManager(std::vector> &ledManagers) -{ - ledManagers = mLedManagers; - return CreateStatusCode(STATUS_CODE_OK); -} - +const IpcMission DeviceManager::GetIpcMissiony(void) { return IpcMission::TEST; } diff --git a/middleware/DeviceManager/src/DeviceManager.h b/middleware/DeviceManager/src/DeviceManager.h index d431bd5c..c810df1d 100644 --- a/middleware/DeviceManager/src/DeviceManager.h +++ b/middleware/DeviceManager/src/DeviceManager.h @@ -14,9 +14,8 @@ */ #ifndef DEVICEMANAGER_H #define DEVICEMANAGER_H -#include "LedManager.h" #include "IDeviceManager.h" - +#include "LedManager.h" class DeviceManager : public IDeviceManager { @@ -27,13 +26,9 @@ public: const StatusCode Init(void) override; const StatusCode UnInit(void) override; const IpcMission GetIpcMissiony(void) override; - const StatusCode GetLedManager(std::vector> &ledManagers) override; + // const StatusCode GetLedManager(std::vector> &ledManagers) override; private: std::vector> mLedManagers; }; - - - #endif - diff --git a/middleware/DeviceManager/src/LedManager.cpp b/middleware/DeviceManager/src/LedManager.cpp index c32e4442..b23ac376 100644 --- a/middleware/DeviceManager/src/LedManager.cpp +++ b/middleware/DeviceManager/src/LedManager.cpp @@ -16,8 +16,6 @@ #include "LedManager.h" #include "ILog.h" - - LedManager::LedManager() { mLedHal = nullptr; @@ -27,21 +25,22 @@ LedManager::LedManager() mStateAliveTime = 0; } LedManager::LedManager(std::shared_ptr &LedHal, const LedState &CurrentState, - const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) - : mLedHal(LedHal), mCurrentState(CurrentState), mKeepAliveTime(KeepAliveTime), mBlinkPeriod(BlinkPeriod) + const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) { + mLedHal = LedHal; + mCurrentState = CurrentState; + mKeepAliveTime = KeepAliveTime; + mBlinkPeriod = BlinkPeriod; mStateAliveTime = 0; } - -StatusCode LedManager::SetLedState(LedState CurrentState, unsigned int KeepAliveTime) +StatusCode LedManager::SetLedState(std::string ledName, LedState &CurrentState, const unsigned int &KeepAliveTime, + const unsigned int &BlinkPeriod) { mCurrentState = CurrentState; mKeepAliveTime = KeepAliveTime; return CreateStatusCode(STATUS_CODE_OK); } - - StatusCode LedManager::GetLedState(LedState &CurrentState) { CurrentState = mCurrentState; @@ -59,9 +58,3 @@ StatusCode LedManager::BlinkOff(void) mCurrentState = LedState::LED_STATE_OFF; return CreateStatusCode(STATUS_CODE_OK); } - - - - - - diff --git a/middleware/DeviceManager/src/LedManager.h b/middleware/DeviceManager/src/LedManager.h index e258e2da..57faa811 100644 --- a/middleware/DeviceManager/src/LedManager.h +++ b/middleware/DeviceManager/src/LedManager.h @@ -16,6 +16,7 @@ #define LED_MANAGER_H #include "IDeviceManager.h" +#include "IHalCpp.h" #include #include @@ -33,25 +34,25 @@ public: LedManager(); LedManager(std::shared_ptr &LedHal, const LedState &CurrentState, const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, - const unsigned int &BlinkPeriod = BLINKING_FAST_MS - ); + const unsigned int &BlinkPeriod = BLINKING_FAST_MS); ~LedManager() = default; - StatusCode Init(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); } - StatusCode Unit(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); } - StatusCode SetLedState(LedState CurrentState, unsigned int KeepAliveTime) override; + StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode Unit(void) { return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode SetLedState(std::string ledName, LedState &CurrentState, + const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, + const unsigned int &BlinkPeriod = LED_NOT_BLINK) override; public: - StatusCode GetLedState(LedState &CurrentState) {return CreateStatusCode(STATUS_CODE_NOT_OK); } - StatusCode BlinkOn(LedState CurrentState, unsigned int KeepAliveTime) {return CreateStatusCode(STATUS_CODE_NOT_OK); } - StatusCode BlinkOff(void) {return CreateStatusCode(STATUS_CODE_NOT_OK); } + StatusCode GetLedState(LedState &CurrentState); + StatusCode BlinkOn(LedState CurrentState, unsigned int KeepAliveTime); + StatusCode BlinkOff(void); private: std::shared_ptr mLedHal; - LedState mCurrentState; // 当前状态 - unsigned int mBlinkPeriod; // 闪烁频率 - unsigned int mKeepAliveTime; // 保持存活时间 - unsigned int mStateAliveTime; // 状态保持时间 + LedState mCurrentState; // 当前状态 + unsigned int mBlinkPeriod; // 闪烁频率 + unsigned int mKeepAliveTime; // 保持存活时间 + unsigned int mStateAliveTime; // 状态保持时间 }; #endif - diff --git a/test/utils/SharedData/src/SharedData_Test.cpp b/test/utils/SharedData/src/SharedData_Test.cpp index 6ce7efdc..b419d96e 100644 --- a/test/utils/SharedData/src/SharedData_Test.cpp +++ b/test/utils/SharedData/src/SharedData_Test.cpp @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "SharedData.h" #include "ILog.h" +#include "SharedData.h" #include #include namespace SharedDataTest From 1b11f55fa45167b0a752b897a73600d498b62b0a Mon Sep 17 00:00:00 2001 From: jas <1790731762@qq.com> Date: Wed, 10 Jan 2024 10:21:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[zhoulongyu]:=201.=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=87=BD=E6=95=B0=E5=90=8D,=20=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E4=B8=8D=E5=90=8C=E7=9A=84=20class=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=90=8D=E4=B8=80=E6=A0=B7,=20=E9=80=A0?= =?UTF-8?q?=E6=88=90=E4=BB=A3=E7=A0=81=E9=98=85=E8=AF=BB=E5=9B=B0=E9=9A=BE?= =?UTF-8?q?;=202.=20=E4=BC=98=E5=8C=96=E4=B8=AD=E9=97=B4=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=AF=B9=E5=A4=96=E6=8E=A5=E5=8F=A3;=203.=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=20LedManager=20=E7=9A=84=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0(=E9=97=AA?= =?UTF-8?q?=E7=83=81=E6=97=B6=E9=97=B4=E6=94=B9=E4=B8=BA0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hal/include/IHalCpp.h | 6 +++--- hal/src/HalCpp.cpp | 2 +- hal/src/HalCpp.h | 2 +- .../DeviceManager/include/IDeviceManager.h | 19 +++++-------------- .../DeviceManager/src/DeviceManager.cpp | 19 +++++++++++++++++-- middleware/DeviceManager/src/DeviceManager.h | 7 +++++-- middleware/DeviceManager/src/LedManager.cpp | 9 +++++++-- middleware/DeviceManager/src/LedManager.h | 10 +++++----- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/hal/include/IHalCpp.h b/hal/include/IHalCpp.h index 5d8f3b54..6c4e10ec 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -71,7 +71,7 @@ public: { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } - virtual StatusCode GetLedName(std::string &LedName) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual std::string GetLedName(void) { return "undefine"; } }; #if 0 @@ -83,7 +83,7 @@ public: // StatusCode SetLedHalOwner(std::shared_ptr owner) override; StatusCode SetHalLedState(const HalLedState &state) override; - StatusCode GetLedName(std::string &LedName) override; + std::string GetLedName(void) override; private: // VLedHalOwner m_LedHalOwner; @@ -101,7 +101,7 @@ public: static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); virtual StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } virtual StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } - virtual StatusCode GetLedHal(std::vector> &ledHals) + virtual StatusCode GetLedHals(std::vector> &ledHals) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } diff --git a/hal/src/HalCpp.cpp b/hal/src/HalCpp.cpp index 095c22b9..d6ee8d05 100644 --- a/hal/src/HalCpp.cpp +++ b/hal/src/HalCpp.cpp @@ -24,7 +24,7 @@ StatusCode HalCpp::UnInit(void) LogInfo("HalCpp::UnInit\n"); return CreateStatusCode(STATUS_CODE_OK); } -StatusCode HalCpp::GetLedHal(std::vector> &ledHals) +StatusCode HalCpp::GetLedHals(std::vector> &ledHals) { ledHals = mLedHals; return CreateStatusCode(STATUS_CODE_OK); diff --git a/hal/src/HalCpp.h b/hal/src/HalCpp.h index 09191f7b..4185a94a 100644 --- a/hal/src/HalCpp.h +++ b/hal/src/HalCpp.h @@ -22,7 +22,7 @@ public: virtual ~HalCpp() = default; StatusCode Init(void) override; StatusCode UnInit(void) override; - StatusCode GetLedHal(std::vector> &ledHals) override; + StatusCode GetLedHals(std::vector> &ledHals) override; private: std::vector> mLedHals; diff --git a/middleware/DeviceManager/include/IDeviceManager.h b/middleware/DeviceManager/include/IDeviceManager.h index 2545fa0d..4ba75384 100644 --- a/middleware/DeviceManager/include/IDeviceManager.h +++ b/middleware/DeviceManager/include/IDeviceManager.h @@ -48,18 +48,6 @@ enum LedState LED_STATE_END }; -class VLedManager -{ -public: - VLedManager() = default; - ~VLedManager() = default; - virtual StatusCode SetLedState(std::string ledName, LedState &CurrentState, const unsigned int &KeepAliveTime, - const unsigned int &BlinkPeriod) - { - return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); - } -}; - class IDeviceManager { public: @@ -69,8 +57,11 @@ public: virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const IpcMission GetIpcMissiony(void) { return IpcMission::END; } - // virtual const StatusCode GetLedManager(std::vector> &ledManagers) { return - // CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } + virtual const StatusCode ISetLedState(std::string ledName, LedState &CurrentState, + const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) + { + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + } }; bool CreateDeviceManagerModule(void); #endif \ No newline at end of file diff --git a/middleware/DeviceManager/src/DeviceManager.cpp b/middleware/DeviceManager/src/DeviceManager.cpp index 7ebd0174..ab97471e 100644 --- a/middleware/DeviceManager/src/DeviceManager.cpp +++ b/middleware/DeviceManager/src/DeviceManager.cpp @@ -19,16 +19,17 @@ const StatusCode DeviceManager::Init(void) { std::vector> ledHals; - IHalCpp::GetInstance()->GetLedHal(ledHals); + IHalCpp::GetInstance()->GetLedHals(ledHals); for (auto it = ledHals.begin(); it != ledHals.end(); ++it) { std::shared_ptr ledHal = *it; std::shared_ptr ledOut = - std::make_shared(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, BLINKING_FAST_MS); + std::make_shared(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, LED_NOT_BLINK); mLedManagers.push_back(ledOut); } return CreateStatusCode(STATUS_CODE_OK); } + const StatusCode DeviceManager::UnInit(void) { if (!mLedManagers.empty()) { @@ -37,4 +38,18 @@ const StatusCode DeviceManager::UnInit(void) return CreateStatusCode(STATUS_CODE_OK); } + const IpcMission DeviceManager::GetIpcMissiony(void) { return IpcMission::TEST; } + +const StatusCode DeviceManager::ISetLedState(std::string ledName, LedState &CurrentState, + const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) +{ + for (auto it = mLedManagers.begin(); it != mLedManagers.end(); ++it) { + std::shared_ptr ledOut = *it; + if (ledOut->GetLedHal()->GetLedName() == ledName) { + ledOut->SetLedState(CurrentState, KeepAliveTime, BlinkPeriod); + return CreateStatusCode(STATUS_CODE_OK); + } + } + return CreateStatusCode(STATUS_CODE_NOT_OK); +} diff --git a/middleware/DeviceManager/src/DeviceManager.h b/middleware/DeviceManager/src/DeviceManager.h index c810df1d..0e53ad77 100644 --- a/middleware/DeviceManager/src/DeviceManager.h +++ b/middleware/DeviceManager/src/DeviceManager.h @@ -26,9 +26,12 @@ public: const StatusCode Init(void) override; const StatusCode UnInit(void) override; const IpcMission GetIpcMissiony(void) override; - // const StatusCode GetLedManager(std::vector> &ledManagers) override; + const StatusCode ISetLedState(std::string ledName, LedState &CurrentState, + const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, + const unsigned int &BlinkPeriod = LED_NOT_BLINK) override; + private: - std::vector> mLedManagers; + std::vector> mLedManagers; }; #endif diff --git a/middleware/DeviceManager/src/LedManager.cpp b/middleware/DeviceManager/src/LedManager.cpp index b23ac376..eceb2ccc 100644 --- a/middleware/DeviceManager/src/LedManager.cpp +++ b/middleware/DeviceManager/src/LedManager.cpp @@ -20,10 +20,11 @@ LedManager::LedManager() { mLedHal = nullptr; mCurrentState = NEW_LED_STATE; - mBlinkPeriod = BLINKING_FAST_MS; + mBlinkPeriod = LED_NOT_BLINK; mKeepAliveTime = DEFAULT_KEEP_ALIVE_TIME; mStateAliveTime = 0; } + LedManager::LedManager(std::shared_ptr &LedHal, const LedState &CurrentState, const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) { @@ -34,13 +35,17 @@ LedManager::LedManager(std::shared_ptr &LedHal, const LedState &Current mStateAliveTime = 0; } -StatusCode LedManager::SetLedState(std::string ledName, LedState &CurrentState, const unsigned int &KeepAliveTime, +std::shared_ptr LedManager::GetLedHal(void) { return mLedHal; } + +StatusCode LedManager::SetLedState(LedState &CurrentState, const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod) { mCurrentState = CurrentState; mKeepAliveTime = KeepAliveTime; + mBlinkPeriod = BlinkPeriod; return CreateStatusCode(STATUS_CODE_OK); } + StatusCode LedManager::GetLedState(LedState &CurrentState) { CurrentState = mCurrentState; diff --git a/middleware/DeviceManager/src/LedManager.h b/middleware/DeviceManager/src/LedManager.h index 57faa811..e9caf07a 100644 --- a/middleware/DeviceManager/src/LedManager.h +++ b/middleware/DeviceManager/src/LedManager.h @@ -28,21 +28,21 @@ constexpr long int DEFAULT_KEEP_ALIVE_TIME = 1500; constexpr unsigned int DELETED_LED_STATE = -1; constexpr unsigned int DO_NOT_KEEP_ALIVE = -2; -class LedManager : public VLedManager +class LedManager { public: LedManager(); LedManager(std::shared_ptr &LedHal, const LedState &CurrentState, const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, - const unsigned int &BlinkPeriod = BLINKING_FAST_MS); + const unsigned int &BlinkPeriod = LED_NOT_BLINK); ~LedManager() = default; StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_NOT_OK); } StatusCode Unit(void) { return CreateStatusCode(STATUS_CODE_NOT_OK); } - StatusCode SetLedState(std::string ledName, LedState &CurrentState, - const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, - const unsigned int &BlinkPeriod = LED_NOT_BLINK) override; public: + std::shared_ptr GetLedHal(void); + StatusCode SetLedState(LedState &CurrentState, const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME, + const unsigned int &BlinkPeriod = LED_NOT_BLINK); StatusCode GetLedState(LedState &CurrentState); StatusCode BlinkOn(LedState CurrentState, unsigned int KeepAliveTime); StatusCode BlinkOff(void);