You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.6 KiB
141 lines
3.6 KiB
#include "gstate_mgr.hpp"
|
|
|
|
#include "app_event_bus.hpp"
|
|
|
|
using namespace std;
|
|
using namespace iflytop;
|
|
#define TAG "GSM"
|
|
#define GSM GStateMgr::ins()
|
|
|
|
void GStateMgr::initialize() { m_mutex.init(); }
|
|
|
|
/***********************************************************************************************************************
|
|
* USER *
|
|
***********************************************************************************************************************/
|
|
void GStateMgr::setLogin(int loginUsrId, const char* usrName, user_role_t role) {
|
|
zlock_guard l(m_mutex);
|
|
m_loginUsrType = role;
|
|
m_isLogin = true;
|
|
strncpy(this->m_loginUsr, usrName, MAX_USR_NAME_SIZE);
|
|
m_loginUsrId = loginUsrId;
|
|
}
|
|
void GStateMgr::setUnLogin() {
|
|
zlock_guard l(m_mutex);
|
|
m_isLogin = false;
|
|
m_loginUsrType = kuser;
|
|
memset(m_loginUsr, 0, sizeof(m_loginUsr));
|
|
}
|
|
|
|
bool GStateMgr::isLogin() {
|
|
zlock_guard l(m_mutex);
|
|
return m_isLogin;
|
|
}
|
|
user_role_t GStateMgr::getLoginUsrType() {
|
|
zlock_guard l(m_mutex);
|
|
return m_loginUsrType;
|
|
}
|
|
const char* GStateMgr::getLoginUsr() {
|
|
zlock_guard l(m_mutex);
|
|
return m_loginUsr;
|
|
}
|
|
|
|
int GStateMgr::getUserId() {
|
|
zlock_guard l(m_mutex);
|
|
return m_loginUsrId;
|
|
}
|
|
|
|
void GStateMgr::setRemoterHeart(int32_t state, uint8_t* heart_data) {
|
|
zlock_guard l(m_mutex);
|
|
AppEvent appevent;
|
|
|
|
m_RemoterS = state;
|
|
appevent.type = kAE_RemoterHeartEvent;
|
|
appevent.setHeartInfo(heart_data);
|
|
AppEventBus::ins()->pushEvent(appevent);
|
|
}
|
|
|
|
//
|
|
|
|
void GStateMgr::setRemoterS(int32_t state, const char* name) {
|
|
zlock_guard l(m_mutex);
|
|
AppEvent appevent;
|
|
|
|
m_RemoterS = state;
|
|
if (state) {
|
|
ZLOGI(TAG, "on ble connect -> client name:%s", name);
|
|
strncpy(m_RemoterName, name, sizeof(m_RemoterName));
|
|
// strncpy(appevent.d.bleName, name, sizeof(appevent.d.bleName));
|
|
appevent.type = kAE_RemoterConnectedEvent;
|
|
|
|
} else {
|
|
ZLOGI(TAG, "on ble disconnect");
|
|
appevent.type = kAE_RemoterDisConnectedEvent;
|
|
}
|
|
AppEventBus::ins()->pushEvent(appevent);
|
|
}
|
|
const char* GStateMgr::getRemoterName() {
|
|
zlock_guard l(m_mutex);
|
|
return m_RemoterName;
|
|
}
|
|
|
|
void GStateMgr::setRunMode(hand_acid_mode_t mode) {
|
|
zlock_guard l(m_mutex);
|
|
if (m_RunMode != mode) {
|
|
m_RunMode = mode;
|
|
AppEventBus::ins()->pushSimpleEvent(kAE_RunModeChangeEvent);
|
|
}
|
|
}
|
|
void GStateMgr::changeToNextRunMode() {
|
|
zlock_guard l(m_mutex);
|
|
|
|
if (m_RunMode == khand_acid_m_jog_mode) {
|
|
setRunMode(khand_acid_m_continuous_mode);
|
|
} else {
|
|
setRunMode(khand_acid_m_jog_mode);
|
|
}
|
|
}
|
|
|
|
int32_t GStateMgr::getRemoterS() {
|
|
zlock_guard l(m_mutex);
|
|
return m_RemoterS;
|
|
}
|
|
hand_acid_mode_t GStateMgr::getRunMode() {
|
|
zlock_guard l(m_mutex);
|
|
return m_RunMode;
|
|
}
|
|
|
|
void GStateMgr::setPumpSelectState(int32_t index, bool state) {
|
|
zlock_guard l(m_mutex);
|
|
m_pumpSelectState[index] = state;
|
|
}
|
|
bool GStateMgr::getPumpSelectState(int32_t index) {
|
|
zlock_guard l(m_mutex);
|
|
return m_pumpSelectState[index];
|
|
}
|
|
float GStateMgr::getAcidRemain(int32_t index) {
|
|
zlock_guard l(m_mutex);
|
|
return acidRemain[index]; // add 0.5 for force change to int
|
|
}
|
|
float GStateMgr::getAcidUsed(int32_t index) {
|
|
zlock_guard l(m_mutex);
|
|
return acidUsed[index]; // add 0.5 for force change to int
|
|
}
|
|
|
|
bool GStateMgr::isHasPumpSelect() {
|
|
zlock_guard l(m_mutex);
|
|
for (int i = 0; i < 4; i++) {
|
|
if (m_pumpSelectState[i]) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void GStateMgr::setAcidRemain(int32_t index, float val) {
|
|
zlock_guard l(m_mutex);
|
|
acidRemain[index] = val;
|
|
}
|
|
void GStateMgr::setAcidUsed(int32_t index, float val) {
|
|
zlock_guard l(m_mutex);
|
|
acidUsed[index] = val;
|
|
}
|