2024-05-09 12:49:18 +08:00

246 lines
5.6 KiB
C++

#include "BaseCtrl.h"
vector<string> BaseCtrl::m_InitErrorInfos;
CRITICAL_SECTION BaseCtrl::m_CS;
bool BaseCtrl::m_IsStart = false;
bool BaseCtrl::m_IsPause = false;
bool BaseCtrl::m_IsStop = false;
bool BaseCtrl::m_IsStandBy = false;
bool BaseCtrl::m_IsFinish = false;
bool BaseCtrl::m_IsPrePrint = false;
bool BaseCtrl::m_IsPauseStanBy = false;
bool BaseCtrl::m_IsHeatingScanner = false;
int BaseCtrl::m_State = 0;
int BaseCtrl::m_PreState = 0;
int BaseCtrl::m_PauseState = 0;
void BaseCtrl::SInit()
{
InitializeCriticalSection(&m_CS);
}
void BaseCtrl::SUninit()
{
DeleteCriticalSection(&m_CS);
}
BaseCtrlState BaseCtrl::GetState() {
BaseCtrlState bcState;
EnterCriticalSection(&m_CS);
bcState.IsStart = m_IsStart;
bcState.IsPause = m_IsPause;
bcState.IsStop = m_IsStop;
bcState.IsStandBy = m_IsStandBy;
bcState.IsFinish = m_IsFinish;
bcState.IsPrePrint = m_IsPrePrint;
bcState.IsPauseStanBy = m_IsPauseStanBy;
bcState.IsHeatingScanner = m_IsHeatingScanner;
bcState.State = m_State;
bcState.PreState = m_PreState;
bcState.PauseState = m_PauseState;
LeaveCriticalSection(&m_CS);
return bcState;
}
void BaseCtrl::UpdateState(const ReadData& rd) {
EnterCriticalSection(&BaseCtrl::m_CS);
if (rd.dataType == SCANCTRLSTATE) {
auto it = rd.its.begin();
while (it != rd.its.end()) {
if (it->nameKey == "IsStart") {
m_IsStart = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsPause") {
m_IsPause = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsStop") {
m_IsStop = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsStandBy") {
m_IsStandBy = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsFinish") {
m_IsFinish = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsPrePrint") {
m_IsPrePrint = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsPauseStanBy") {
m_IsPauseStanBy = (bool)stoi(it->strValue);
}
else if (it->nameKey == "IsHeatingScanner") {
m_IsHeatingScanner = (bool)stoi(it->strValue);
}
else if (it->nameKey == "State") {
m_State = stoi(it->strValue);
}
else if (it->nameKey == "PreState") {
m_PreState = stoi(it->strValue);
}
else if (it->nameKey == "PauseState") {
m_PauseState = stoi(it->strValue);
}
else {
printf("error, key %s do not find...", it->nameKey.c_str());
}
++it;
}
}
LeaveCriticalSection(&BaseCtrl::m_CS);
}
//
//bool BaseCtrl::IsStart()
//{
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == PRINTING) {
// rel = true;
// }
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//bool BaseCtrl::IsStandBy()
//{
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == STANDBY || m_print_state == STANDBY_PAUSE || m_print_state == STANDBY_STOP) {
// rel = true;
// }
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//bool BaseCtrl::IsPauseStanBy() {
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == STANDBY_PAUSE)rel = true;
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//
//bool BaseCtrl::IsPause() {
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == PAUSE) {
// rel = true;
// }
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//bool BaseCtrl::IsStop() {
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == STOP)
// {
// rel = true;
// }
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//bool BaseCtrl::IsPrePrint() {
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == PREPRINT) {
// rel = true;
// }
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//bool BaseCtrl::IsFinish() {
// bool rel = false;
// EnterCriticalSection(&BaseCtrl::m_CS);
// if (m_print_state == FINISH) {
// rel = true;
// }
// else rel = false;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return rel;
//}
//
//void BaseCtrl::SetFinish() {
// EnterCriticalSection(&BaseCtrl::m_CS);
// m_print_state = FINISH;
// LeaveCriticalSection(&BaseCtrl::m_CS);
//}
//
//
//void BaseCtrl::SetStandBy()
//{
// EnterCriticalSection(&BaseCtrl::m_CS);
// m_print_state = STANDBY;
// LeaveCriticalSection(&BaseCtrl::m_CS);
//}
//
//void BaseCtrl::SetPauseState(BaseCtrl::PauseState ps)
//{
// EnterCriticalSection(&BaseCtrl::m_CS);
// m_PauseState = ps;
// LeaveCriticalSection(&BaseCtrl::m_CS);
//}
//
//void BaseCtrl::SetState(PrintState ps)
//{
// EnterCriticalSection(&BaseCtrl::m_CS);
// m_print_state = ps;
// LeaveCriticalSection(&BaseCtrl::m_CS);
//}
//
//void BaseCtrl::SetPreState(BaseCtrl::PreRunState rs)
//{
// EnterCriticalSection(&BaseCtrl::m_CS);
// m_PreRunState = rs;
// LeaveCriticalSection(&BaseCtrl::m_CS);
//}
//
//BaseCtrl::PrintState BaseCtrl::GetState()
//{
// PrintState ps;
// EnterCriticalSection(&BaseCtrl::m_CS);
// ps = m_print_state;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return ps;
//}
//
//BaseCtrl::PreRunState BaseCtrl::GetPreState()
//{
// PreRunState ps;
// EnterCriticalSection(&BaseCtrl::m_CS);
// ps = m_PreRunState;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return ps;
//}
//
//BaseCtrl::PauseState BaseCtrl::GetPauseState()
//{
// PauseState ps;
// EnterCriticalSection(&BaseCtrl::m_CS);
// ps = m_PauseState;
// LeaveCriticalSection(&BaseCtrl::m_CS);
// return ps;
//}
//bool BaseCtrl::IsHeatingScanner()
//{
// if (m_print_state == PREPRINT && m_PreRunState == AutoHeatingScanner) {
// return true;
// }
// else return false;
//}