Merge branch 'master-develop' of gitee.com:shenzhen-jiuyilian/ipc into master-develop

This commit is contained in:
fancy 2024-01-24 08:21:10 -08:00
commit 9b12014f76
8 changed files with 303 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "StatusCode.h"
#include <iostream>
#include <memory>
#include <vector>
constexpr int INVALID_PERIOD = -1;
constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100;
constexpr int IMEI_LEN = 15;
@ -44,6 +45,54 @@ public:
virtual void SetKeyHalOwner(std::shared_ptr<VKeyHalOwner> owner) {}
virtual const std::string GetKeyName(void) { return "undefine"; }
};
enum HalLedState
{
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 SetHalLedState(const HalLedState &state)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
virtual std::string GetLedName(void) { return "undefine"; }
};
#if 0
class WifiLed : public VLedHalOwner, public VLedHal
{
public:
WifiLed() = default;
~WifiLed() = default;
// StatusCode SetLedHalOwner(std::shared_ptr<VLedHalOwner> owner) override;
StatusCode SetHalLedState(const HalLedState &state) override;
std::string GetLedName(void) 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 +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 GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
};
void CreateHalCppModule(void);
#endif

View File

@ -24,3 +24,8 @@ StatusCode HalCpp::UnInit(void)
LogInfo("HalCpp::UnInit\n");
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode HalCpp::GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals)
{
ledHals = mLedHals;
return CreateStatusCode(STATUS_CODE_OK);
}

View File

@ -22,5 +22,9 @@ public:
virtual ~HalCpp() = default;
StatusCode Init(void) override;
StatusCode UnInit(void) override;
StatusCode GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals) override;
private:
std::vector<std::shared_ptr<VLedHal>> mLedHals;
};
#endif

View File

@ -15,7 +15,9 @@
#ifndef IDEVICEMANAGER_H
#define IDEVICEMANAGER_H
#include "StatusCode.h"
#include <iostream>
#include <memory>
#include <vector>
enum class IpcMission
{
TEST = 0,
@ -29,6 +31,23 @@ enum class KeyAction
HOLD_UP,
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 IDeviceManager
{
public:
@ -38,6 +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 ISetLedState(std::string ledName, LedState &CurrentState,
const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod)
{
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
};
bool CreateDeviceManagerModule(void);
#endif

View File

@ -0,0 +1,55 @@
/*
* 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"
#include <vector>
const StatusCode DeviceManager::Init(void)
{
std::vector<std::shared_ptr<VLedHal>> 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, LED_NOT_BLINK);
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::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);
}

View File

@ -0,0 +1,37 @@
/*
* 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 "IDeviceManager.h"
#include "LedManager.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 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<LedManager>> mLedManagers;
};
#endif

View File

@ -0,0 +1,65 @@
/*
* 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 = 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)
{
mLedHal = LedHal;
mCurrentState = CurrentState;
mKeepAliveTime = KeepAliveTime;
mBlinkPeriod = BlinkPeriod;
mStateAliveTime = 0;
}
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;
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);
}

View File

@ -0,0 +1,58 @@
/*
* 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 "IHalCpp.h"
#include <functional>
#include <mutex>
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:
LedManager();
LedManager(std::shared_ptr<VLedHal> &LedHal, const LedState &CurrentState,
const unsigned int &KeepAliveTime = DEFAULT_KEEP_ALIVE_TIME,
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); }
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);
private:
std::shared_ptr<VLedHal> mLedHal;
LedState mCurrentState; // 当前状态
unsigned int mBlinkPeriod; // 闪烁频率
unsigned int mKeepAliveTime; // 保持存活时间
unsigned int mStateAliveTime; // 状态保持时间
};
#endif