mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
[zhoulongyu]: 完善Led组件的部分代码(没有LedTimer)后编译通过
This commit is contained in:
parent
532598fbaa
commit
ca56f16a20
|
@ -16,8 +16,8 @@
|
|||
#define IHALCPP_H
|
||||
#include "StatusCode.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
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<VLedHalOwner> 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<IHalCpp> &GetInstance(std::shared_ptr<IHalCpp> *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<std::shared_ptr<VLedHal>> &ledHals) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
virtual StatusCode GetLedHal(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
};
|
||||
void CreateHalCppModule(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -26,6 +26,5 @@ public:
|
|||
|
||||
private:
|
||||
std::vector<std::shared_ptr<VLedHal>> mLedHals;
|
||||
|
||||
};
|
||||
#endif
|
|
@ -15,8 +15,9 @@
|
|||
#ifndef IDEVICEMANAGER_H
|
||||
#define IDEVICEMANAGER_H
|
||||
#include "StatusCode.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "IHalCpp.h"
|
||||
#include <vector>
|
||||
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<std::shared_ptr<VLedManager>> &ledManagers) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
|
||||
// virtual const StatusCode GetLedManager(std::vector<std::shared_ptr<VLedManager>> &ledManagers) { return
|
||||
// CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); }
|
||||
};
|
||||
bool CreateDeviceManagerModule(void);
|
||||
#endif
|
|
@ -14,36 +14,27 @@
|
|||
*/
|
||||
|
||||
#include "DeviceManager.h"
|
||||
#include <vector>
|
||||
|
||||
const StatusCode DeviceManager::Init(void)
|
||||
const StatusCode DeviceManager::Init(void)
|
||||
{
|
||||
std::vector<std::shared_ptr<VLedHal>> 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<VLedHal> ledHal = *it;
|
||||
std::shared_ptr<LedManager> ledOut = std::make_shared<LedManager>(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, BLINKING_FAST_MS);
|
||||
std::shared_ptr<LedManager> ledOut =
|
||||
std::make_shared<LedManager>(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<std::shared_ptr<VLedManager>> &ledManagers)
|
||||
{
|
||||
ledManagers = mLedManagers;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
|
||||
const IpcMission DeviceManager::GetIpcMissiony(void) { return IpcMission::TEST; }
|
||||
|
|
|
@ -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<std::shared_ptr<VLedManager>> &ledManagers) override;
|
||||
// const StatusCode GetLedManager(std::vector<std::shared_ptr<VLedManager>> &ledManagers) override;
|
||||
private:
|
||||
std::vector<std::shared_ptr<VLedManager>> mLedManagers;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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<VLedHal> &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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define LED_MANAGER_H
|
||||
|
||||
#include "IDeviceManager.h"
|
||||
#include "IHalCpp.h"
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
|
@ -33,25 +34,25 @@ public:
|
|||
LedManager();
|
||||
LedManager(std::shared_ptr<VLedHal> &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<VLedHal> mLedHal;
|
||||
LedState mCurrentState; // 当前状态
|
||||
unsigned int mBlinkPeriod; // 闪烁频率
|
||||
unsigned int mKeepAliveTime; // 保持存活时间
|
||||
unsigned int mStateAliveTime; // 状态保持时间
|
||||
LedState mCurrentState; // 当前状态
|
||||
unsigned int mBlinkPeriod; // 闪烁频率
|
||||
unsigned int mKeepAliveTime; // 保持存活时间
|
||||
unsigned int mStateAliveTime; // 状态保持时间
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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 <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
namespace SharedDataTest
|
||||
|
|
Loading…
Reference in New Issue
Block a user