mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
[zhoulongyu]: 1. 更改部分函数名, 避免不同的 class里的函数名一样, 造成代码阅读困难; 2. 优化中间件的对外接口; 3. 更改 LedManager 的构造函数的默认参数(闪烁时间改为0)
This commit is contained in:
parent
ca56f16a20
commit
1b11f55fa4
|
@ -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<VLedHalOwner> 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<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)
|
||||
virtual StatusCode GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ StatusCode HalCpp::UnInit(void)
|
|||
LogInfo("HalCpp::UnInit\n");
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode HalCpp::GetLedHal(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||
StatusCode HalCpp::GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||
{
|
||||
ledHals = mLedHals;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
virtual ~HalCpp() = default;
|
||||
StatusCode Init(void) override;
|
||||
StatusCode UnInit(void) override;
|
||||
StatusCode GetLedHal(std::vector<std::shared_ptr<VLedHal>> &ledHals) override;
|
||||
StatusCode GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals) override;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<VLedHal>> mLedHals;
|
||||
|
|
|
@ -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<std::shared_ptr<VLedManager>> &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
|
|
@ -19,16 +19,17 @@
|
|||
const StatusCode DeviceManager::Init(void)
|
||||
{
|
||||
std::vector<std::shared_ptr<VLedHal>> ledHals;
|
||||
IHalCpp::GetInstance()->GetLedHal(ledHals);
|
||||
IHalCpp::GetInstance()->GetLedHals(ledHals);
|
||||
|
||||
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::make_shared<LedManager>(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<LedManager> ledOut = *it;
|
||||
if (ledOut->GetLedHal()->GetLedName() == ledName) {
|
||||
ledOut->SetLedState(CurrentState, KeepAliveTime, BlinkPeriod);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
|
|
|
@ -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<std::shared_ptr<VLedManager>> &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<std::shared_ptr<VLedManager>> mLedManagers;
|
||||
std::vector<std::shared_ptr<LedManager>> mLedManagers;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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<VLedHal> &LedHal, const LedState &CurrentState,
|
||||
const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod)
|
||||
{
|
||||
|
@ -34,13 +35,17 @@ LedManager::LedManager(std::shared_ptr<VLedHal> &LedHal, const LedState &Current
|
|||
mStateAliveTime = 0;
|
||||
}
|
||||
|
||||
StatusCode LedManager::SetLedState(std::string ledName, LedState &CurrentState, const unsigned int &KeepAliveTime,
|
||||
std::shared_ptr<VLedHal> 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;
|
||||
|
|
|
@ -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<VLedHal> &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<VLedHal> 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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user