#include #include #include #include "webrtc/WebRTCVideoChat.h" #include #include #include #include #include "rw_zlog.h" #include "common_utils.h" #include "assert.h" #include "cmd_process.h" #include "db_manage.h" #include "BackStage.h" #include "file_utils.h" #include "rw_protocol.h" #include "detector/detector_tracker.h" #include "decision_actuator/standby.h" #include "dev_version.h" #include "libcJSON.h" #include "ScopeGuard.h" #include "Peripheral.h" #include "cmd_process.h" #include "pe_input/pe_input.h" #include "decision_center/decision_center.h" #include "tracker_lock/tracker_lock.h" #include "camera/camera.h" #include "UiConfig.h" #include "bluetooth.h" #include "View.h" #include "person_manage.h" #include "CardReaderProp.h" #include "decision_actuator/decision_actuator.h" Backstage::Backstage(void* pParaMng, void* pObjs) { m_paramMng = reinterpret_cast(pParaMng); m_objs = reinterpret_cast(pObjs); } Backstage::~Backstage() { } int Backstage::registerPerson(char *name, char *term, int nDataOrigin) { if ((name == nullptr) || (term == nullptr)) { LOGE("param error!name==%p, term===%p", name, term); return -1; } return 0; } int Backstage::startIdentyState(bool setfaceReco, bool setPeInput) { LOGI("startIdentyState"); if(setfaceReco && m_objs){ GDetectorTracker *tracker = (GDetectorTracker*)m_objs->findObject("DetectorTracker"); GStandby *pStandby = (GStandby*)m_objs->findObject("standby"); GTrackerLock *pTrackLock = (GTrackerLock*)m_objs->findObject("trackerLock"); if (tracker && pStandby && pTrackLock){ if(!Singleton::GetInstance()->isHardwareTesting()){ tracker->setRgbFaceDetMode(false); pStandby->setKeepAwake(false); } else{ LOGI("is testing hardware..."); tracker->setRgbFaceDetMode(true); pStandby->setKeepAwake(true); } pTrackLock->lockCtrl(false); } } if(setPeInput){ Singleton::GetInstance()->enableUserInput(Peripheral::enOptorMid, false, true); } return 0; } int Backstage::stopIdentyState(bool setfaceReco, bool setPeInput) { LOGI("stopIdentyState"); if(setfaceReco && m_objs){ GDetectorTracker *tracker = (GDetectorTracker*)m_objs->findObject("DetectorTracker"); GStandby *pStandby = (GStandby*)m_objs->findObject("standby"); GTrackerLock *pTrackLock = (GTrackerLock*)m_objs->findObject("trackerLock"); if (tracker && pStandby && pTrackLock){ tracker->setRgbFaceDetMode(false, true); pStandby->setKeepAwake(true); pTrackLock->lockCtrl(true); } } if(setPeInput){ Singleton::GetInstance()->enableUserInput(Peripheral::enOptorMid, true, false); } return 0; } int Backstage::verifyFactorySettingPwd(const char *pwd) { int ret = -1; if(nullptr == pwd) { LOGE("param pwd is NULL!"); return -1; } if (FileUtils::fileIsExist(PASSWORD_FILE)) { ifstream infile; infile.open(PASSWORD_FILE); if(infile.is_open()){ //std::string s; //while(getline(infile,s)) { //cout<clearParam(); FileUtils::removeFile(AGEING_TIME_FILE); FileUtils::removeFile(DB_PATH"faceGate.db"); FileUtils::removeFile(NETWORK_CFG_FILE); FileUtils::remove_dir(MEETING_DIR); FileUtils::remove_dir(TTS_PERSISTENCE_DIR); //devReboot(); //need black page before reboot return resetNetworkCfg(); } int Backstage::getDeviceId(char *devId, int len)// 获取设备id { int ret = -1; constexpr auto macFile = "/data/.mac"; memset(devId, 0, len); if (FileUtils::fileIsExist(macFile) && FileUtils::getFileSize(macFile) > 0) { const std::string sDevId = getDevId(); LOGD("sDevId=%s", sDevId.c_str()); if (sDevId.length() < (unsigned)len) { strcpy(devId, sDevId.c_str()); ret = 0; } } return ret; } std::string Backstage::getUnderScreenNfcModuleId(){ CardReaderProp prop(CARD_READER_PROP_FILE); return prop.UnderScreenCardReaderModuleId(); } std::string Backstage::getExtendNfcModuleId(){ CardReaderProp prop(CARD_READER_PROP_FILE); return prop.ExtendUsbCardReaderModuleId(); } bool Backstage::isIdModuleInfoUploaded(){ LOGI("isIdModuleInfoUploaded"); return FileUtils::fileIsExist("/tmp/.idModuleInfoUpload2Iot"); } bool Backstage::isDevSettingDisable() { return m_paramMng->getDisableDevSettingSw(); } void Backstage::setAntiDemolitionAvail(bool avail, bool upload) { m_paramMng->setAntiDemolitionAvail(avail); static int outputType = 0; if(avail){ outputType = getAntiDemolitionOutput(); if(1 == outputType){ GDecisionActuator::relayOnCB(2); }else if(2 == outputType){ Singleton::GetInstance()->controlGpioOut(BasePeripheral::enGpio2, false); }else if(3 == outputType){ Singleton::GetInstance()->controlGpioOut(BasePeripheral::enGpio3, false); } if(upload){ RWProtocol::getInstance()->addAlarmEvent(2, utils::getNowTimeS(), ""); } }else if(outputType){ if(1 == outputType){ GDecisionActuator::relayOnCB(3); }else if(2 == outputType){ Singleton::GetInstance()->controlGpioOut(BasePeripheral::enGpio2, true); }else if(3 == outputType){ Singleton::GetInstance()->controlGpioOut(BasePeripheral::enGpio3, true); } } } bool Backstage::getAntiDemolitionSw() { return m_paramMng->getAntiDemolitionSw(); } void Backstage::setAntiDemolitionSw(bool sw) { m_paramMng->setAntiDemolitionSw(sw); } int Backstage::getAntiDemolitionOutput() { return m_paramMng->getAntiDemolitionOutput(); } void Backstage::setAntiDemolitionOutput(int output) { m_paramMng->setAntiDemolitionOutput(output); } int Backstage::getGpio4Cfg() { return m_paramMng->getGpio4Cfg(); } void Backstage::setGpio4Cfg(int cfg) { m_paramMng->setGpio4Cfg(cfg); } int Backstage::getGpio5Cfg() { return m_paramMng->getGpio5Cfg(); } void Backstage::setGpio5Cfg(int cfg) { m_paramMng->setGpio5Cfg(cfg); } int Backstage::getDoorCloseOvertime() { return m_paramMng->getDoorCloseOvertime(); } void Backstage::setDoorCloseOvertime(int overtime) { m_paramMng->setDoorCloseOvertime(overtime); } bool Backstage::getDisableDevSettingSw() { return m_paramMng->getDisableDevSettingSw(); } void Backstage::setDisableDevSettingSw(bool sw) { m_paramMng->setDisableDevSettingSw(sw); } int Backstage::getTicketCheckCountToday() { const std::string curDay = utils::format_time(time(nullptr)).substr(0, 10); const std::string cntDay = RWProtocol::getInstance()->m_paramMng->getTicketCheckDay(); if(curDay != cntDay){ return 0; } return m_paramMng->getTicketCheckCount(); } int Backstage::getTicketModePeopleCountType() { return m_paramMng->getTicketModePeopleCountType(); } int Backstage::getCallDevList() { WebRTCVideoChat::instance()->requestContacts(); return 0; } int Backstage::queryCallDevList(const std::string &text, std::vector &devList) { devList.clear(); auto contacts = WebRTCVideoChat::instance()->contactsSearch(text); for (auto &contact : contacts) { stCallDev info; info.code = contact.code; info.devTag = contact.uniqueTag; info.name = contact.name; info.type = contact.type; info.status = contact.status; devList.push_back(info); } return 0; } int Backstage::callDev(const std::string &devTag, int devType) { WebRTCVideoChat::instance()->callRemote(devType == 2 ? WebRTCVideoChat::Platform : WebRTCVideoChat::Device, devTag); return 0; } int Backstage::callAbort() { WebRTCVideoChat::instance()->setCurrentSessionAction(WebRTCVideoChat::Action::Cancel); return 0; } int Backstage::callHangUp() { WebRTCVideoChat::instance()->setCurrentSessionAction(WebRTCVideoChat::Action::Hangup); return 0; } int Backstage::callReject() { WebRTCVideoChat::instance()->setCurrentSessionAction(WebRTCVideoChat::Action::Reject); return 0; } int Backstage::callAccept() { WebRTCVideoChat::instance()->setCurrentSessionAction(WebRTCVideoChat::Action::Pickup); return 0; } int Backstage::openCallRemoteDoor() { WebRTCVideoChat::instance()->setCurrentSessionAction(WebRTCVideoChat::Action::OpenDoor); return 0; } void Backstage::verifyAbort() { GDecisionActuator *decAor = (GDecisionActuator*)m_objs->findObject("decisionActuator"); if (!decAor){return;} decAor->verifyAbort(); } bool Backstage::getShowIdAndVerSw() { return m_paramMng->getRecoUiShowDevIdAndVerSw(); } int Backstage::setShowIdAndVerSw(bool sw) { m_paramMng->setRecoUiShowDevIdAndVerSw(sw); return 0; } int Backstage::playAudio(enAudioIndex index) { GDecisionActuator *decAor = (GDecisionActuator*)m_objs->findObject("decisionActuator"); if (!decAor){return -1;} const std::vector indexMap{32}; if(index < 0 || index >= indexMap.size()){return -2;} return decAor->_playAudioProc(indexMap.at(index)); } int Backstage::userItemChoose(int index) { GDecisionCenter *decCenter = (GDecisionCenter*)m_objs->findObject("decisionCenter"); if (decCenter){ decCenter->userItemChoose(index); } return 0; } int Backstage::callSetVideoStream(bool enable) { WebRTCVideoChat::instance()->setCurrentSessionAction(enable ? WebRTCVideoChat::Action::EnableVideo : WebRTCVideoChat::Action::DisableVideo); return 0; } int Backstage::getHardwareConfig(char *hardVer, int len)//获取系统版本 { int ret = -1; std::string version; getHardVersion(version); LOGD("version=%s",version.c_str()); if(version.length() < (unsigned)len){ strcpy(hardVer, version.c_str()); ret = 0; } return ret; } int Backstage::getStorSpace(int &total, float &free)//获取存储空间 { int ret = -1; #if 0 char buf[1024] = {0}; FILE *fp = popen("df -h | grep \"/data\"", "r"); if (fp == NULL) { LOGE("popen FAIL!"); return ret; } while(fgets(buf, 1024, fp) != NULL) { LOGD("read buf : %s", buf); if (strstr(buf, "/data") && strstr(buf, "G")) { unsigned iPos = 0; std::string line(buf); for(int i=0; i<2; i++){ iPos = line.find_last_of(" "); if(iPos != std::string::npos){ line = std::string(line.begin(), line.begin() + iPos); line = line.substr(line.find_first_not_of(' '), line.find_last_not_of(' ') + 1); } } iPos = line.find_last_of(" "); if(iPos != std::string::npos) { line = line.substr(iPos + 1); line = line.substr(line.find_first_not_of(' '), line.find_last_not_of(' ') + 1); LOGD("avai space:%s", line.c_str()); line.erase(line.length() - 1); if(line.length() > 0){ free = std::stof(line); ret = 0; } } } } total = 16; if(SERIES_B021 == DevVersion::getInstance()->getDevSeries()) { total = 8; } #else ret = getStoreSpace(free, total); #if 0 total = 16; if(SERIES_B021 == DevVersion::getInstance()->getDevSeries()) { total = 8; } #endif #endif return ret; } int Backstage::getAppVersion(char *appVer, int len)//获取应用版本号 { int ret = -1; std::string version; getSoftVersion(version); if (version.at(version.length() - 1) == '\n') { version.erase(version.length() - 1); } if(version.length() < (unsigned)len){ strcpy(appVer, version.c_str()); ret = 0; } return ret; } int Backstage::getRegisterNum()//获取注册人员数 { int personCount = 0; DBManage::getInstance()->getPersonAllCount(personCount); return personCount; } int Backstage::getAccessRecordQty() { int sum = 0; const string countSql = "select count(*) from access_record"; DBManage::getInstance()->getCountOfTableBySQL(countSql, sum); LOGD("sum==%d", sum); return sum; } int Backstage::getAccessRecordNotUpload()//获取未上传通行记录 { return DBManage::getInstance()->getAccessRecordsNumByUploadSta(dbspace::enRodUpNotYet); } int Backstage::getVolume()//获取音量大小 { assert(nullptr != m_paramMng); return m_paramMng->getVolume(); } int Backstage::setVolume(int vol)//设置音量大小 { assert(nullptr != m_paramMng); m_paramMng->setVolume(vol); int res = blueToothMng::getInstance().setVolume(vol); if (res != 0) { LOGE("bluetooth fail!"); } return 0; } int Backstage::getLcdBrightness()//获取屏幕亮度 { assert(nullptr != m_paramMng); return m_paramMng->getLcdBrightness(); } int Backstage::setLcdBrightness(int brightness)//设置屏幕亮度 { assert(nullptr != m_paramMng); m_paramMng->setLcdBrightness(brightness); return 0; } bool Backstage::getFillLightSw()//获取智能补光开关 { return 0; } int Backstage::setFillLightSw(bool isOpen)//获取智能补光开关 { return 0; } int Backstage::getStandbyTime()//获取待机时间 { assert(nullptr != m_paramMng); return m_paramMng->getStandbyTime(); } int Backstage::setStandbyTime(int time)//设置待机时间 { assert(nullptr != m_paramMng); const bool isMeetingMode = m_paramMng->getMeetingMode() >= 0; const bool isDndMode = m_paramMng->getDndMode() >= 0; if (isMeetingMode) { // 会议模式 m_paramMng->setMeetingScreensaverTimeBackup(time); } else if (isDndMode) { m_paramMng->setDndModeStandbyTime(time); } else { m_paramMng->setStandbyTime(time); } return 0; } int Backstage::getCloseScreenTime()//获取关屏等待时间 { assert(nullptr != m_paramMng); return m_paramMng->getCloseScreenTime(); } int Backstage::setCloseScreenTime(int time)//获取关屏等待时间 { assert(nullptr != m_paramMng); m_paramMng->setCloseScreenTime(time); return 0; } int Backstage::getLanguage()//获取语言 { assert(nullptr != m_paramMng); return m_paramMng->getLanguage(); } int Backstage::setLanguage(int lang)//设置语言 { assert(nullptr != m_paramMng); m_paramMng->setLanguage(lang); return 0; } int Backstage::getIP(char *ip, int len, int& type)//获取IP { std::string maskString; std::string ipString; std::string ifName; if(utils::checkNetRun(std::string("eth0"))) { ifName = "eth0"; type = 0; } else if(utils::checkNetRun(std::string("wlan0"))) { ifName = "wlan0"; type = 1; } else if(utils::checkNetRun(std::string("wwan0"))) { ifName = "wwan0"; type = 2; } else if(utils::checkNetRun(std::string("ppp0"))) { ifName = "ppp0"; type = -1; static int lastType = 6; //满格信号 std::string text; do{ if(0 != utils::read_file("/tmp/.4G_signal_intensity", text)){break;} if(text.find("+CSQ:") == std::string::npos){break;} size_t end = text.find_last_of(","); if(end == std::string::npos){break;} const std::string sigStr = text.substr(6, end - 6); //+CSQ: 24,99 int nSig = -1; try{nSig = std::stoi(sigStr);}catch(...){break;} if(nSig >= 5 && nSig <= 6){type = 2;} //1格 else if(nSig >= 7 && nSig <= 9){type = 3;} //2格 else if(nSig >= 10 && nSig <= 11){type = 4;} //3格 else if(nSig >= 12 && nSig <= 14){type = 5;} //4格 else if(nSig >= 15 && nSig <= 31){type = 6;} //5格 else{type = 7;} //无信号 lastType = type; }while(0); if(type < 0){LOGE("sig text:%s", text.c_str());type = lastType;} } else{ type = -1; } int iRet = 0; if(type >= 0){ iRet = utils::getIpAndMask(ifName, ipString, maskString); snprintf(ip, len, "%s", ipString.c_str()); //LOGD("local ip==%s", ip); } //LOGI("getIP type:%d", type); return iRet; } int Backstage::setIP(char *ip)//设置IP { return 0; } enIpMethod Backstage::getIpMethod()//获取IP方法 { return (enIpMethod)0; } int Backstage::setIpMethod(enIpMethod ipMethod)//设置IP方法 { return 0;//MVC_Ctrler::getInstance()->setIpMethod(ipMethod); } int Backstage::getSubnetMask(char *mask, int len)//获取子网掩码 { return 0;//MVC_Ctrler::getInstance()->getSubnetMask(mask, len); } int Backstage::setSubnetMask(char *mask)//设置子网掩码 { return 0;//MVC_Ctrler::getInstance()->setSubnetMask(mask); } int Backstage::getGateway(char *gateway, int len)//获取默认网关 { return 0;//MVC_Ctrler::getInstance()->getGateway(gateway, len); } int Backstage::setGateway(char *gateway)//设置默认网关 { return 0;//MVC_Ctrler::getInstance()->setGateway(gateway); } int Backstage::getDNS(char *dns, int len)//获取DNS { return 0;//MVC_Ctrler::getInstance()->getDNS(dns, len); } int Backstage::setDNS(char *dns)//设置DNS { return 0;//MVC_Ctrler::getInstance()->setDNS(dns); } int Backstage::getEthMac(char *mac, int len)//获取mac { int ret = -1; const std::string macString = utils::getNetMac("eth0"); LOGD("macString=%s", macString.c_str()); if(macString.length() < (unsigned)len){ strcpy(mac, macString.c_str()); ret = 0; } return ret; } int Backstage::getWifiMac(char *mac, int len)//获取wifi mac { return 0; } int Backstage::getServerAddr(char *addr, int len)//获取服务器ip { assert(nullptr != m_paramMng); int ret = -1; std::string serverinfo = m_paramMng->getServerIP(); if(serverinfo.length() < (unsigned)len){ strcpy(addr, serverinfo.c_str()); ret = 0; } return ret; } int Backstage::setServerAddr(char *addr, bool byQrcode)//设置服务器ip { assert(nullptr != m_paramMng); m_paramMng->setLastModifyServer(1); m_paramMng->setServerIP(addr); if (!byQrcode) { FileUtils::removeFile(QRCODE_CONFIG_FILE);//用户修改平台IP后就删除保存的二维码信息文件,modify by wwb-20220104 } //RWProtocol::getInstance()->modifySrvAddrInfo(1); return 0; } int Backstage::testServerIP(char *addr, float &time)//测试服务器ip { return 0; } int Backstage::getIotServerIP(char *ip, int len)//获取服务器ip { return 0;//MVC_Ctrler::getInstance()->getIotServerIP(ip, len); } int Backstage::setIotServerIP(char *ip)//设置服务器ip { return 0;//MVC_Ctrler::getInstance()->setIotServerIP(ip); } int Backstage::getIotPort()//获取端口号, 成功返回端口号,失败返回-1 { return 0;//MVC_Ctrler::getInstance()->getIotPort(); } int Backstage::setIotPort(int port)//设置端口号 { return 0;//MVC_Ctrler::getInstance()->setIotPort(port); } bool Backstage::getIpShowSw() { assert(nullptr != m_paramMng); return m_paramMng->getIpShowSw(); } int Backstage::setIpShowSw(bool sw) { assert(nullptr != m_paramMng); m_paramMng->setIpShowSw(sw); return 0; } int Backstage::getBtSwitch(bool &isOpen) { assert(nullptr != m_paramMng); isOpen = m_paramMng->getBluetoothSw(); return 0; } int Backstage::getBtName(string &devName) { assert(nullptr != m_paramMng); devName = m_paramMng->getDevName(); return 0; } int Backstage::getBtPairedDev(list &devList) { std::list pairedList; blueToothMng::getInstance().getPairedDevs(pairedList); devList.clear(); for(const auto &iter : pairedList) { BlueToothDevStat_e state = BlueToothDevStat_paired; //连接状态:0搜索到, 1配对中, 2已配对, 3连接中, 4已连接 // if (std::get<0>(iter) == 3) // { // state = BlueToothDevStat_connecting; // } //else if (std::get<0>(iter) == 4) { state = BlueToothDevStat_connected; } LOGD("name:%s, state:%d", std::get<3>(iter).c_str(), std::get<0>(iter)); devList.emplace_back(BluetoothDev_t(std::get<2>(iter), std::get<3>(iter), state)); } return 0; } int Backstage::getBtAvailDev(list &devList) { std::list scanedList; blueToothMng::getInstance().getScanedDevs(scanedList); devList.clear(); for(const auto &iter : scanedList) { //LOGD("name:%s, state:%d", std::get<1>(iter).c_str(), std::get<0>(iter)); devList.emplace_back(BluetoothDev_t(std::get<2>(iter), std::get<3>(iter), BlueToothDevStat_idle)); } return 0; } int Backstage::getBtAllInfo(BluetoothStat_t &bluetoothStat) { assert(nullptr != m_paramMng); bluetoothStat.clear(); bluetoothStat.devName = m_paramMng->getDevName(); bluetoothStat.isEnable = m_paramMng->getBluetoothSw(); getBtPairedDev(bluetoothStat.pairedDev); getBtAvailDev(bluetoothStat.availableDev); return 0; } //blueToothMng模块里有一个线程循环再搜索,所以没有提供主动搜索接口,只提供了获取搜索列表的接口,这里调用getBtAvailDev即可 int Backstage::btScan(list &devList) { #if 0 std::list searchedList; blueToothMng::getInstance().search(searchedList); devList.clear(); for(const auto &iter : searchedList) { LOGD("name:%s, state:%d", std::get<1>(iter).c_str(), std::get<0>(iter)); devList.emplace_back(BluetoothDev_t(std::get<2>(iter), std::get<1>(iter), BlueToothDevStat_idle)); } #endif return 0; } int Backstage::btSetSwitch(bool isOpen) { assert(nullptr != m_paramMng); m_paramMng->setBluetoothSw(isOpen); if (isOpen) { blueToothMng::getInstance().open(); } else { m_paramMng->setBleLockSw(false); blueToothMng::getInstance().close(); } return 0; } int Backstage::btSetName(const string &devName) { if (blueToothMng::getInstance().modifySysName(devName) == 0) { m_paramMng->setDevName(devName); return 0; } return -1; } int Backstage::btPaire(const string &devId) { int res = blueToothMng::getInstance().pair(devId); if (res != 0) { LOGE("bluetooth pairing fail! res:%d", res); } return res; } int Backstage::btDisPaire(const string &devId) { int res = blueToothMng::getInstance().disPair(devId); if (res != 0) { LOGE("bluetooth disPairing fail! res:%d", res); } return res; } int Backstage::btConnect(const string &devId) { int res = blueToothMng::getInstance().connect(devId); if (res != 0) { LOGE("bluetooth connect fail!"); } return res; } int Backstage::btDisConnect(const string &devId) { int res = blueToothMng::getInstance().disConnect(devId); if (res != 0) { LOGE("bluetooth disConnect fail! res:%d", res); } return res; } int Backstage::btRenameDev(const string &devId, const string &devName) { return blueToothMng::getInstance().modifyDevName(devId, devName); } #if 1 //for test bool g_isBluetoothEnable = false; #endif bool Backstage::getParamBluetoothEnable() { return g_isBluetoothEnable; } int Backstage::setParamBluetoothEnable(bool sw) { g_isBluetoothEnable = sw; return 0; } #if 1 //for test string g_bluetoothName = "rw-bluetooth"; #endif string Backstage::getParamBluetoothName() { return g_bluetoothName; } int Backstage::setParamBluetoothName(string name) { g_bluetoothName = name; return 0; } int Backstage::getUnlockTime()//获取开锁时间 { assert(nullptr != m_paramMng); return m_paramMng->getUnlockTime(); } int Backstage::setUnlockTime(int time)//设置开锁时间 { assert(nullptr != m_paramMng); m_paramMng->setUnlockTime(time); return 0; } int Backstage::getUnlockDelay()//获取开锁延时 { assert(nullptr != m_paramMng); return m_paramMng->getUnlockDelay(); } int Backstage::setUnlockDelay(int time)//设置开锁延时 { assert(nullptr != m_paramMng); m_paramMng->setUnlockDelay(time); return 0; } enUnlockSignal Backstage::getUnlockSig()//获取开锁信号 { assert(nullptr != m_paramMng); if(m_paramMng->getUnlockSig() >= UnlockSigButt){ return UnlockSigRelay; } return (enUnlockSignal)m_paramMng->getUnlockSig(); } int Backstage::setUnlockSig(enUnlockSignal value)//设置开锁信号 { assert(nullptr != m_paramMng); m_paramMng->setUnlockSig(value); return 0; } enAssist Backstage::getAssistIn()//获取辅助输入 { return (enAssist)0;//MVC_Ctrler::getInstance()->getAssistIn(); } int Backstage::setAssistIn(enAssist assist)//设置辅助输入 { return 0;//MVC_Ctrler::getInstance()->setAssistIn(assist); } enAssist Backstage::getAssistOut()//获取辅助输出 { return (enAssist)0;//MVC_Ctrler::getInstance()->getAssistOut(); } int Backstage::setAssistOut(enAssist assist)//设置辅助输出 { return 0;//MVC_Ctrler::getInstance()->setAssistOut(assist); } enWiegand Backstage::getWiegandIn()//获取韦根输入 { return (enWiegand)0;//MVC_Ctrler::getInstance()->getWiegandIn(); } int Backstage::setWiegandIn(enWiegand wiegand)//设置韦根输入 { return 0;//MVC_Ctrler::getInstance()->setWiegandIn(wiegand); } enWiegand Backstage::getWiegandOut()//获取韦根输出 { return (enWiegand)0; } int Backstage::setWiegandOut(enWiegand wiegand)//设置韦根输出 { return 0; } enBaudRate Backstage::getBaudRate()//获取波特率 { return (enBaudRate)0; } int Backstage::setBaudRate(enBaudRate baudRate)//设置波特率 { return 0; } int Backstage::getWarningSig()//获取报警信号v { assert(nullptr != m_paramMng); return m_paramMng->getWarningSig(); } int Backstage::setWarningSig(int signal)//设置报警信号 { assert(nullptr != m_paramMng); m_paramMng->setWarningSig(signal); return 0; } enLogo Backstage::getLogo()//获取logo { assert(nullptr != m_paramMng); return (enLogo)m_paramMng->getLogo(); } int Backstage::setLogo(enLogo logo)//设置logo { assert(nullptr != m_paramMng); m_paramMng->setLogo((int)logo); return 0; } int Backstage::getCustomLogo(char *logo, int len)//获取自定义logo { assert(nullptr != m_paramMng); std::string customLogo = m_paramMng->getCustomLogo(); snprintf(logo, len, "%s", customLogo.c_str()); LOGD("customLogo: %s", customLogo.c_str()); return 0; } enLogo Backstage::getLogoTime()//获取logo+time { return (enLogo)0;//MVC_Ctrler::getInstance()->getLogoTime(); } int Backstage::setLogoTime(enLogo logo)//设置logo+time { return 0;//MVC_Ctrler::getInstance()->setLogoTime(logo); } enLogo Backstage::getBackground()//获取背景图 { return (enLogo)0;//MVC_Ctrler::getInstance()->getBackground(); } int Backstage::setBackground(enLogo logo)//设置背景图 { return 0;//MVC_Ctrler::getInstance()->setBackground(logo); } enRecogResult Backstage::getSuccessResult(char *data, int len)//获取成功结果 { int nRet = 0;//MVC_Ctrler::getInstance()->getSuccessResult(data, len); nRet = (nRet < 0) ? RecogResultButt : nRet; return (enRecogResult)nRet; } int Backstage::setSuccessResult(enRecogResult result, char *data)//设置成功结果 { return 0;//MVC_Ctrler::getInstance()->setSuccessResult(result, data); } enRecogResult Backstage::getFailResult(char *data, int len)//获取失败结果 { int nRet = 0;//MVC_Ctrler::getInstance()->getFailResult(data, len); nRet = (nRet < 0) ? RecogResultButt : nRet; return (enRecogResult)nRet; } int Backstage::setFailResult(enRecogResult result, char *data)//设置失败结果 { return 0;//MVC_Ctrler::getInstance()->setFailResult(result, data); } bool Backstage::getPlayAudioSw()//获取语音播报开关 { return 0;//MVC_Ctrler::getInstance()->getPlayAudioSw(); } int Backstage::setPlayAudioSw(bool isOpen)//设置语音播报开关 { return 0;//MVC_Ctrler::getInstance()->setPlayAudioSw(isOpen); } bool Backstage::getIdentificationSw()//获取身份核验开关 { assert(nullptr != m_paramMng); return m_paramMng->getRecoSw(); } int Backstage::setIdentificationSw(bool sw)//设置身份核验开关 { assert(nullptr != m_paramMng); m_paramMng->setRecoSw(sw); return 0; } enSimilarityTh Backstage::getSimilarityTh()//获取相似度阈值 { assert(nullptr != m_paramMng); return (enSimilarityTh)m_paramMng->getSimilarityType(); } int Backstage::setSimilarityTh(enSimilarityTh th)//设置相似度阈值 { assert(nullptr != m_paramMng); m_paramMng->setSimilarityType(th); return 0; } int Backstage::setCustomSimilarity(int sim) //设置自定义识别相似度 { assert(nullptr != m_paramMng); m_paramMng->setSimilarityTh(sim); return 0; } int Backstage::getCustomSimilarity() //获取自定义识别相似度 { assert(nullptr != m_paramMng); return m_paramMng->getSimilarityTh(); } bool Backstage::getLivingBodySw()//获取活体开关 { assert(nullptr != m_paramMng); return m_paramMng->getInfraAntiAttack(); } int Backstage::setLivingBodySw(bool isOpen)//设置活体开关 { assert(nullptr != m_paramMng); m_paramMng->setInfraAntiAttack(isOpen); return 0; } enLivingBodyTh Backstage::getLivingBodyTh()//获取活体检测阈值 { return (enLivingBodyTh)0; } int Backstage::setLivingBodyTh(enLivingBodyTh th)//设置活体检测阈值 { return 0; } bool Backstage::getLivingBodyFailSw()//获取活体失败图片留存开关 { return 0; } int Backstage::setLivingBodyFailSw(bool isOpen)//设置失败图片留存开关 { return 0; } int Backstage::getVerifyInterval()//获取验证间隔时间 { return 0; } int Backstage::setVerifyInterval(int time)//设置验证间隔时间 { return 0; } enRecogDistance Backstage::getRecogDistance()//获取识别距离 { return (enRecogDistance)0;//MVC_Ctrler::getInstance()->getRecogDistance(); } int Backstage::setRecogDistance(enRecogDistance distance)//设置识别距离 { return 0;//MVC_Ctrler::getInstance()->setRecogDistance(distance); } enRecogAngle Backstage::getRecogAngle()//获取识别角度 { return (enRecogAngle)0;//MVC_Ctrler::getInstance()->getRecogAngle(); } int Backstage::setRecogAngle(enRecogAngle angle)//设置识别角度 { return 0;//MVC_Ctrler::getInstance()->setRecogAngle(angle); } int Backstage::getMaxTraceNum()//获取人脸最大跟踪数 { return 0;//MVC_Ctrler::getInstance()->getMaxTraceNum(); } int Backstage::setMaxTraceNum(int num)//设置人脸最大跟踪数 { return 0;//MVC_Ctrler::getInstance()->setMaxTraceNum(num); } enFaceQuality Backstage::getFaceQuality()//获取人脸质量阈值 { return (enFaceQuality)0;//MVC_Ctrler::getInstance()->getFaceQuality(); } int Backstage::setFaceQuality(enFaceQuality quality)//设置人脸质量阈值 { return 0;//MVC_Ctrler::getInstance()->setFaceQuality(quality); } bool Backstage::getDynamicFeatureSw() { return m_paramMng->getDynamicFeatureSw(); } int Backstage::setDynamicFeatureSw(bool sw) { LOGD("setDynamicFeatureSw:%d", sw); m_paramMng->setDynamicFeatureSw(sw); return 0; } bool Backstage::getNtpServerSw()//获取NTP服务开关 { assert(nullptr != m_paramMng); return m_paramMng->getNtpServerSw(); } int Backstage::setNtpServerSw(bool isOpen)//设置NTP服务开关 { assert(nullptr != m_paramMng); m_paramMng->setNtpServerSw(isOpen); return 0; } int Backstage::getNtpServerAddr(char *addr, int len)//获取NTP服务地址 { assert(nullptr != m_paramMng); int ret = -1; std::string serverinfo = m_paramMng->getNtpServerAddr(); if(serverinfo.length() < (unsigned)len){ strcpy(addr, serverinfo.c_str()); ret = 0; } return ret; } int Backstage::setNtpServerAddr(char *addr)//设置NTP服务地址 { assert(nullptr != m_paramMng); m_paramMng->setNtpServerAddr(addr); return 0; } int Backstage::testNtpServer(char *addr, float &time)//测试NTP服务 { return 0;//MVC_Ctrler::getInstance()->testNtpServer(addr, time); } int Backstage::getNtpServerPort()//获取NTP端口,成功返回端口号,失败返回-1 { return m_paramMng->getNtpServerPort(); } int Backstage::setNtpServerPort(int port)//设置NTP服务端口 { m_paramMng->setNtpServerPort(port); return 0; } int Backstage::getNtpCheckInterval() { return m_paramMng->getNtpSyncInterval(); } int Backstage::setNtpCheckInterval(int interval) { m_paramMng->setNtpSyncInterval(interval); return 0; } int Backstage::getNtpTimeZone(char *timeZone, int len) { assert(nullptr != m_paramMng); int ret = -1; std::string zone = m_paramMng->getZone(); if(zone.length() < (unsigned)len){ strcpy(timeZone, zone.c_str()); ret = 0; } return ret; } int Backstage::setNtpTimeZone(char *timeZone) { assert(nullptr != m_paramMng); m_paramMng->setZone(timeZone); return 0; } int Backstage::setVerifyFactorySettingPwd(char *pwd)//设置工程密码 { return 0; } int Backstage::testHardware()//硬件检测 { return 0; } int Backstage::cleanData()//清除数据 { int ret = clearData(); //清空数据会隐藏密码输入显示,需检查是否有本地设置密码 if(m_paramMng->getLocalDevPwd().length()){ View::getInstance()->setPwdButton(true); } return ret; } int Backstage::devReboot()//重启设备 { m_paramMng->setLcdBrightness(0, true); sleep(1); //deviceReboot(); DEV_REBOOT; //system("reboot -f"); return 0; } int Backstage::startCapture() { int nRet = 0; return nRet; } int Backstage::deletePerson(long long personID) { int nRet = 0; return nRet; } int Backstage::queryPersonList(long long* pPersonIDBuff, int nBuffCount, long long startID, int& nRealPerson) { int nRet = 0; return nRet; } unsigned Backstage::queryPerson(const char* searchText) { LOGD("searchText:%s", searchText); const std::string countSql = std::string("select count(*) from person_info where 1=1 and name like '%") + searchText + "%'"; int sum = 0; DBManage::getInstance()->getCountOfTableBySQL(countSql, sum); LOGD("sum:%d", sum); return (unsigned)sum; } unsigned Backstage::queryPerson(const char* searchText, int pageIndex, stQueryPersonInfo personRet[], int personRetSize) { unsigned nRet = 0; const std::string persql = std::string("select * from person_info where 1=1 and name like '%") + searchText + "%' order by reg_time desc limit " + utils::to_string(personRetSize) + " offset " + utils::to_string(pageIndex * personRetSize); std::list personInfoList; DBManage::getInstance()->queryPersonListBySQL(persql, personInfoList); int i = 0; for (auto &personInfo : personInfoList) { if(i < personRetSize){ #if 0 snprintf(personRet[i].name, sizeof(personRet[i].name), personInfo.name.c_str()); snprintf(personRet[i].regTime, sizeof(personRet[i].regTime), utils::format_time(personInfo.regTime).c_str()); snprintf(personRet[i].expTime, sizeof(personRet[i].expTime), personInfo.expTime.c_str()); #endif personRet[i].name = personInfo.name; personRet[i].regTime = utils::format_time(personInfo.regTime).c_str(); personRet[i].expTime = personInfo.expTime; personRet[i].personId = personInfo.personId; personRet[i].idNum = personInfo.idNum; personRet[i].jobNum = personInfo.jobNum; personRet[i].phoneNum = personInfo.phoneNum; personRet[i].icNum = personInfo.cpuCardContent.empty() ? personInfo.icNum : personInfo.cpuCardContent; personRet[i].personType = personInfo.personType; string imgPath = utils::makeRegisterImgPath(personInfo.personId, personInfo.source, 1); if(0 != access(imgPath.c_str(), F_OK))//如果不存在就去数据库中查找图片路径 { LOGE("register img %s not exsit .", imgPath.c_str()); dbspace::rwFeatInfo faceInfo; if (0 == DBManage::getInstance()->queryFaceByPersonId(personInfo.personId, faceInfo)) { imgPath = faceInfo.image; } } #if 0 snprintf(personRet[i].imgPath, sizeof(personRet[i].imgPath), imgPath.c_str()); #endif personRet[i].imgPath = imgPath; i++; nRet = (unsigned)i; } } return nRet; } unsigned Backstage::queryAccessRecord(const char* name, const char* time) { unsigned nRet = 0; std::string countSql("select count(*) from access_record where 1=1"); if(name){ countSql += " and name like '%"; countSql += name; countSql += "%'"; } if(time){ std::string timeBegin(time); timeBegin += " 00:00:00"; std::string timeEnd(time); timeEnd += " 23:59:59"; long long beginTime = utils::format_time(timeBegin.c_str()); long long endTime = utils::format_time(timeEnd.c_str()); LOGD("beginTime:%lld, endTime:%lld", beginTime, endTime); countSql += " and access_time<="; countSql += utils::to_string(endTime*1000); countSql += " and access_time>="; countSql += utils::to_string(beginTime*1000);//通行记录里面保存的是ms } int sum = 0; DBManage::getInstance()->getCountOfTableBySQL(countSql, sum); LOGD("sum:%d", sum); nRet = (unsigned)sum; return nRet; } unsigned Backstage::queryAccessRecord(const char* name, const char* time, int pageIndex, stQueryAccRedInfo recordRet[], int recordRetSize) { unsigned nRet = 0; std::string dataSql("select * from access_record where 1=1"); if(name){ dataSql += " and name like '%"; dataSql += name; dataSql += "%'"; } //时间格式必须为2020-04-05 00:00:00 if(time){ std::string timeBegin(time); timeBegin += " 00:00:00"; std::string timeEnd(time); timeEnd += " 23:59:59"; long long beginTime = utils::format_time(timeBegin.c_str()); long long endTime = utils::format_time(timeEnd.c_str()); LOGD("beginTime:%lld, endTime:%lld", beginTime, endTime); dataSql += " and access_time<="; dataSql += utils::to_string(endTime*1000); dataSql += " and access_time>="; dataSql += utils::to_string(beginTime*1000);//通行记录里面保存的是ms } dataSql += " order by access_time desc"; dataSql += " limit "; dataSql += utils::to_string(recordRetSize); dataSql += " offset "; dataSql += utils::to_string(recordRetSize * pageIndex); std::list accessInfoList; DBManage::getInstance()->queryAccessRecordListBySQL(dataSql, accessInfoList); int i = 0; for (std::list::iterator itr = accessInfoList.begin(); itr != accessInfoList.end(); itr++) { if(i < recordRetSize){ snprintf(recordRet[i].name, sizeof(recordRet[i].name), (*itr).name.length() > 0 ? (*itr).name.c_str() : (m_paramMng->getLanguage() < 2 ? "陌生人" : "stranger")); snprintf(recordRet[i].accessTime, sizeof(recordRet[i].accessTime), utils::format_time((*itr).accessTime/1000).c_str()); snprintf(recordRet[i].imgPath, sizeof(recordRet[i].imgPath), (*itr).imgFile.c_str()); recordRet[i].allowPass = (bool)((*itr).gateStatus); i++; nRet = (unsigned)i; } } return nRet; } int Backstage::clearPeople() { int nRet = 0; return nRet; } int Backstage::getPersonListState(int &sum, unsigned long long &maxPersonID) { int nRet = 0; return nRet; } int Backstage::wakeUpFromScreenSaverOrScreenOff() { return 0; } int Backstage::delPerson(long long personId) { return Singleton::GetInstance()->deletePerson(personId); } int Backstage::modifyPerson(stQueryPersonInfo &personInfo) { dbspace::rwPersonInfo dbPersonInfo; dbPersonInfo.source = 1; dbPersonInfo.personId = personInfo.personId; dbPersonInfo.name = personInfo.name; dbPersonInfo.idNum = personInfo.idNum; dbPersonInfo.jobNum = personInfo.jobNum; dbPersonInfo.phoneNum = personInfo.phoneNum; dbPersonInfo.expTime = personInfo.expTime; dbPersonInfo.icNum = personInfo.icNum; int ret = Singleton::GetInstance()->modifyPerson(dbPersonInfo); return ret; } int Backstage::addPerson(stQueryPersonInfo &personInfo) { int count = 0; DBManage::getInstance()->getPersonAllCount(count); if (count >= REG_PERSON_NUM_MAX) { LOGE("The maximum number(%d) of people!", count); return -99; } dbspace::rwPersonInfo dbPersonInfo; dbPersonInfo.source = 1; //dbPersonInfo.personId = personInfo.personId; dbPersonInfo.name = personInfo.name; dbPersonInfo.idNum = personInfo.idNum; dbPersonInfo.jobNum = personInfo.jobNum; dbPersonInfo.phoneNum = personInfo.phoneNum; dbPersonInfo.expTime = personInfo.expTime; dbPersonInfo.icNum = personInfo.icNum; struct stat st; if ((stat(personInfo.imgPath.c_str(), &st)<0) || (!S_ISREG(st.st_mode))){ LOGE("file:%s is Non-existent!", personInfo.imgPath.c_str()); return -1; } int len = st.st_size; unsigned char *pImg = (unsigned char *)malloc(len); if(pImg == nullptr){ LOGE("malloc size(%d) FAIL!", len); return -1; } ON_SCOPE_EXIT([&]{free(pImg);pImg = NULL;}); int faceImgLen = utils::read_file(personInfo.imgPath.c_str(), pImg, len); if (faceImgLen <= 0) { LOGE("file: %s size is 0!", personInfo.imgPath.c_str()); return -1; } dbspace::rwFaceImg faceImg; faceImg.imgType = dbspace::jpg; faceImg.imgData = pImg; faceImg.imgLen = len; faceImg.faceX = 0; faceImg.faceY = 0; faceImg.faceW = 0; faceImg.faceH = 0; int ret = Singleton::GetInstance()->registerPerson(dbPersonInfo, faceImg); return ret; #if 0 if (ret != 0) { if (ret == -6) { code = CODE_CARD_ALREDDY_EXISTS; } else if (ret == -5) { code = CODE_EXTRACT_FEATURE; } else if (ret == -7) { code = CODE_ID_ALREDDY_EXISTS; } else { code = CODE_REGISTER_PERSON_FAIL; } ret = -1; } #endif } int Backstage::snapFace(std::string &feature, std::string &savePath) { GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); //GCamera* pCamera = (GCamera*)m_objs->findObject("normal"); if(pPeInput){ std::shared_ptr spOriImage; pPeInput->getSpImageFrame(spOriImage); if (spOriImage.get() == nullptr) { LOGE("spOriImage is nullptr"); return -1; } #if 0 //fds::RwImage *pflipImg = spOriImage->getFlipImage(); int width = spOriImage->image.ext.width; int height = spOriImage->image.ext.height; uint8_t* nv21 = (uint8_t*)spOriImage->image.data; uint8_t* size = (uint8_t*)spOriImage->image.ext.size; dbspace::rwFaceImg faceImg = {0, 0, 0, 0, width, height, width, dbspace::nv21, size, nv21, savePath}; #endif fds::RwImage *rwImage = spOriImage->getJpegImage(); #if 0 #ifdef __RV1109__ fds::RwImage* rwImage = spOriImage->getFlipJpegImage(); #else fds::RwImage* rwImage = spOriImage->getJpegImage(); #endif #endif if(rwImage == nullptr) { LOGE("getJpegImage is nullptr"); return -1; } dbspace::rwFaceImg faceImg = {0, 0, 0, 0, rwImage->ext.width, rwImage->ext.height, rwImage->ext.width, dbspace::jpg, rwImage->ext.size, (uint8_t*)rwImage->data, savePath}; std::vector tmp(FEATURE_SIZE); RwFeature feat = {0}; feat.feature_size = FEATURE_SIZE; feat.feature = tmp.data(); int ret = faceImg.getFeature(feat); if (ret != 0) { LOGE("getFeature fail-->ret:%d", ret); return -5; } if (faceImg.imgJpgData == nullptr) { LOGE("jpg is null!"); return -1; } feature.assign((char*)feat.feature, feat.feature_size); LOGD("jpg name:%s, imgdata:%p, imgLen:%d", faceImg.imgName.c_str(), faceImg.imgJpgData.get(), faceImg.imgLen); ret = utils::write_file(faceImg.imgName, (char *)(faceImg.imgJpgData.get()), faceImg.imgLen); return ret; } return -1; } bool Backstage::getMaskCheckSwitch() { assert(nullptr != m_paramMng); return m_paramMng->getMaskSw(); } int Backstage::setMaskCheckSwitch(const bool sw) { assert(nullptr != m_paramMng); m_paramMng->setMaskSw(sw); return 0; } bool Backstage::getNoMaskNoPassSwitch() { assert(nullptr != m_paramMng); return m_paramMng->getNoMaskPassSw(); } int Backstage::setNoMaskNoPassSwitch(const bool sw) { assert(nullptr != m_paramMng); m_paramMng->setNoMaskPassSw(sw); return 0; } bool Backstage::getTemperatureCheckSwitch() { assert(nullptr != m_paramMng); return m_paramMng->getTempSw(); } int Backstage::setTemperatureCheckSwitch(const bool sw) { assert(nullptr != m_paramMng); m_paramMng->setTempSw(sw); return 0; } bool Backstage::getNoTemperatureNoPassSwitch() { return 0;//MVC_Ctrler::getInstance()->getTempAnomalyNoEntrySwitch(); } int Backstage::setNoTemperatureNoPassSwitch(const bool sw) { return 0;//MVC_Ctrler::getInstance()->setTempAnomalyNoEntrySwitch(sw); } float Backstage::getLowTemperature() { return 0;//MVC_Ctrler::getInstance()->getLowTemperature(); } int Backstage::setLowTemperature(const float temp) { return 0;//MVC_Ctrler::getInstance()->setLowTemperature(temp); } float Backstage::getHighTemperature() { return 0;//MVC_Ctrler::getInstance()->getHighTemperature(); } int Backstage::setHighTemperature(const float temp) { return 0;//MVC_Ctrler::getInstance()->setHighTemperature(temp); } bool Backstage::getQRCodeSwitch() { return 0;//MVC_Ctrler::getInstance()->getQRCodeSwitch(); } int Backstage::setQRCodeSwitch(const bool sw) { return 0; } int Backstage::setDateTime(const char *dateTime) { const std::string cmd = std::string("date -s \"") + dateTime + "\" && hwclock -w -u -f /dev/rtc0"; LOGD("setDateTime cmd:%s", cmd.c_str()); return utils::RW_System(cmd.c_str()); } bool Backstage::getDataEncryptSw() { assert(nullptr != m_paramMng); return m_paramMng->getEncryptSw(); } int Backstage::setDataEncryptSw(bool sw) { LOGD("setEncryptSw:%d", sw); m_paramMng->setEncryptSw(sw); return 0; } bool Backstage::getAutoRebootSw() { assert(nullptr != m_paramMng); return m_paramMng->getAutoRebootSw(); } int Backstage::setAutoRebootSw(bool sw) { assert(nullptr != m_paramMng); m_paramMng->setAutoRebootSw(sw); updateRebootTime(sw, m_paramMng->getAutoRebootInterval(), m_paramMng->getAutoRebootTime().c_str()); return 0; } int Backstage::getAutoRebootTime(char* time, int len) { assert(nullptr != m_paramMng); int ret = -1; std::string rebootTime = m_paramMng->getAutoRebootTime(); if(rebootTime.length() < (unsigned)len){ strcpy(time, rebootTime.c_str()); ret = 0; } return ret; } int Backstage::setAutoRebootTime(const char *time) { assert(nullptr != m_paramMng); m_paramMng->setAutoRebootTime(time); updateRebootTime(m_paramMng->getAutoRebootSw(), m_paramMng->getAutoRebootInterval(), time); return 0; } int Backstage::getAutoRebootInterval() { assert(nullptr != m_paramMng); return m_paramMng->getAutoRebootInterval(); } int Backstage::setAutoRebootInterval(int interval) { assert(nullptr != m_paramMng); m_paramMng->setAutoRebootInterval(interval); updateRebootTime(m_paramMng->getAutoRebootSw(), interval, m_paramMng->getAutoRebootTime().c_str()); return 0; } int Backstage::ntpTimeCorrect() { int ret = -1; do{ bool ntpSw = getNtpServerSw(); if(ntpSw){ char ntpaddr[64] = {'\0'}; if(0 != getNtpServerAddr(ntpaddr, sizeof(ntpaddr))){ break; } char timeZone[64] = {'\0'}; if(0 != getNtpTimeZone(timeZone, sizeof(timeZone))){ break; } ret = ntpUpdater::getInstance().setParam(ntpSw, ntpaddr, getNtpCheckInterval(), timeZone); //ret = ntpTimeCorrection(ntpSw, ntpaddr, getNtpCheckInterval(), timeZone); } else{ //ret = ntpTimeCorrection(false, "", 0, ""); ret = ntpUpdater::getInstance().setParam(false, "", 0, ""); } }while(0); return ret; } int Backstage::ntpTimeCorrectForDevTest(const std::string& ntpServerIp) { int ret = 0; //工厂生产时Mes服务器开启NTP校时服务 std::string cmd = utils::to_string(APP_BIN_PATH"ntpdate.sh ") + utils::to_string("/dev/rtc0 ") + ntpServerIp; LOGI("update ntp time for device test, cmd:%s", cmd.c_str()); int nReturn = utils::RW_System(cmd.c_str());//return 1 is int err = WEXITSTATUS(nReturn); if (0 != err) { LOGE("exec [%s] fail,err=%d,nReturn=%d", cmd.c_str(), err, nReturn); ret = -1; } return ret; } int Backstage::getNetWireCfg(stNetWire& wireCfg) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "get_networkSettings"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *obj = cJSON_GetObjectItem(root, "data"); if (NULL == obj){ LOGE("parse data error!"); ret = -3; break; } cJSON *jsTmp = cJSON_GetObjectItem(obj, "type"); if (NULL == jsTmp) { LOGE("parse type error!"); ret = -6; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("type error: %d", jsTmp->valueint); ret = -7; break; } wireCfg.cfg.type = jsTmp->valueint; LOGI("wireCfg.cfg.type:%d", wireCfg.cfg.type); jsTmp = cJSON_GetObjectItem(obj, "status"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -4; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("status error: %d", jsTmp->valueint); ret = -5; break; } wireCfg.cfg.enable = jsTmp->valueint; LOGI("wireCfg.cfg.enable:%d", wireCfg.cfg.enable); if(false == wireCfg.cfg.enable){ ret = 0; break; } if(wireCfg.cfg.type){ //dhcp std::string maskString; std::string ipString; if(0 == utils::getIpAndMask("eth0", ipString, maskString)){ snprintf(wireCfg.cfg.ip, sizeof(wireCfg.cfg.ip), ipString.c_str()); snprintf(wireCfg.cfg.mask, sizeof(wireCfg.cfg.mask), maskString.c_str()); } std::string gw; if(0 == utils::GetDefaultGw(gw)){ snprintf(wireCfg.cfg.gw, sizeof(wireCfg.cfg.gw), gw.c_str()); } snprintf(wireCfg.cfg.dns, sizeof(wireCfg.cfg.dns), utils::getDNS().c_str()); ret = 0; break; } jsTmp = cJSON_GetObjectItem(obj, "ip"); if (NULL == jsTmp){ LOGE("parse ip error!"); ret = -8; break; } snprintf(wireCfg.cfg.ip, sizeof(wireCfg.cfg.ip), jsTmp->valuestring); LOGI("ip:%s", wireCfg.cfg.ip); jsTmp = cJSON_GetObjectItem(obj, "netmask"); if (NULL == jsTmp){ LOGE("parse netmask error!"); ret = -9; break; } snprintf(wireCfg.cfg.mask, sizeof(wireCfg.cfg.mask), jsTmp->valuestring); LOGI("netmask:%s", wireCfg.cfg.mask); jsTmp = cJSON_GetObjectItem(obj, "gateway"); if (NULL == jsTmp){ LOGE("parse gateway error!"); ret = -10; break; } snprintf(wireCfg.cfg.gw, sizeof(wireCfg.cfg.gw), jsTmp->valuestring); LOGI("gateway:%s", wireCfg.cfg.gw); jsTmp = cJSON_GetObjectItem(obj, "dns"); if (NULL == jsTmp){ LOGE("parse dns error!"); ret = -11; break; } snprintf(wireCfg.cfg.dns, sizeof(wireCfg.cfg.dns), jsTmp->valuestring); LOGI("dns:%s", wireCfg.cfg.dns); ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::setNetWireCfg(const stNetWire& wireCfg) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "set_networkSettings"); cJSON_AddNumberToObject(json, "type", wireCfg.cfg.type); if(!wireCfg.cfg.type){ cJSON_AddStringToObject(json, "ip", wireCfg.cfg.ip); cJSON_AddStringToObject(json, "netmask", wireCfg.cfg.mask); if(wireCfg.cfg.gw[0]){ cJSON_AddStringToObject(json, "gateway", wireCfg.cfg.gw); } if(wireCfg.cfg.dns[0]){ cJSON_AddStringToObject(json, "dns", wireCfg.cfg.dns); } } char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::setNetWireEnable(bool enable) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "update_network_status"); cJSON_AddBoolToObject(json, "status", enable); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::getNetWifiCfg(stNetWifi& wifiCfg) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "get_wifiSettings"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *obj = cJSON_GetObjectItem(root, "data"); if (NULL == obj){ LOGE("parse data error!"); ret = -3; break; } cJSON *jsTmp = cJSON_GetObjectItem(obj, "status"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -4; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("status error: %d", jsTmp->valueint); ret = -5; break; } wifiCfg.cfg.enable = jsTmp->valueint; LOGI("wireCfg.cfg.enable:%d", wifiCfg.cfg.enable); if(false == wifiCfg.cfg.enable){ ret = 0; break; } jsTmp = cJSON_GetObjectItem(obj, "enableAp"); if (NULL == jsTmp){ LOGE("parse enableAp error!"); ret = -12; break; } wifiCfg.enableAp = jsTmp->valueint; if(wifiCfg.enableAp){ jsTmp = cJSON_GetObjectItem(obj, "apPwd"); if (NULL == jsTmp){ LOGE("parse apPwd error!"); ret = -12; break; } snprintf(wifiCfg.apPwd, sizeof(wifiCfg.apPwd), jsTmp->valuestring); ret = 0; break; } jsTmp = cJSON_GetObjectItem(obj, "enctype"); if (NULL == jsTmp){ LOGE("parse enctype error!"); ret = -12; break; } snprintf(wifiCfg.encType, sizeof(wifiCfg.encType), jsTmp->valuestring); LOGI("encType:%s", wifiCfg.encType); jsTmp = cJSON_GetObjectItem(obj, "ssid"); if (NULL == jsTmp){ LOGE("parse ssid error!"); ret = -13; break; } snprintf(wifiCfg.ssid, sizeof(wifiCfg.ssid), jsTmp->valuestring); LOGI("ssid:%s", wifiCfg.ssid); jsTmp = cJSON_GetObjectItem(obj, "pwd"); if (NULL == jsTmp){ LOGE("parse pwd error!"); ret = -14; break; } snprintf(wifiCfg.pwd, sizeof(wifiCfg.pwd), jsTmp->valuestring); LOGI("pwd:%s", wifiCfg.pwd); jsTmp = cJSON_GetObjectItem(obj, "connected"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -15; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("connected error: %d", jsTmp->valueint); ret = -16; break; } wifiCfg.isConnected = jsTmp->valueint; LOGI("wireCfg.connected:%d", wifiCfg.isConnected); jsTmp = cJSON_GetObjectItem(obj, "type"); if (NULL == jsTmp) { LOGE("parse type error!"); ret = -6; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("type error: %d", jsTmp->valueint); ret = -7; break; } wifiCfg.cfg.type = jsTmp->valueint; LOGI("wifiCfg.cfg.type:%d", wifiCfg.cfg.type); if(wifiCfg.cfg.type){ //dhcp std::string maskString; std::string ipString; if(0 == utils::getIpAndMask("wlan0", ipString, maskString)){ snprintf(wifiCfg.cfg.ip, sizeof(wifiCfg.cfg.ip), ipString.c_str()); snprintf(wifiCfg.cfg.mask, sizeof(wifiCfg.cfg.mask), maskString.c_str()); } std::string gw; if(0 == utils::GetDefaultGw(gw)){ snprintf(wifiCfg.cfg.gw, sizeof(wifiCfg.cfg.gw), gw.c_str()); } snprintf(wifiCfg.cfg.dns, sizeof(wifiCfg.cfg.dns), utils::getDNS().c_str()); ret = 0; break; } jsTmp = cJSON_GetObjectItem(obj, "ip"); if (NULL == jsTmp){ LOGE("parse ip error!"); ret = -8; break; } snprintf(wifiCfg.cfg.ip, sizeof(wifiCfg.cfg.ip), jsTmp->valuestring); LOGI("ip:%s", wifiCfg.cfg.ip); jsTmp = cJSON_GetObjectItem(obj, "netmask"); if (NULL == jsTmp){ LOGE("parse netmask error!"); ret = -9; break; } snprintf(wifiCfg.cfg.mask, sizeof(wifiCfg.cfg.mask), jsTmp->valuestring); LOGI("netmask:%s", wifiCfg.cfg.mask); jsTmp = cJSON_GetObjectItem(obj, "gateway"); if (NULL == jsTmp){ LOGE("parse gateway error!"); ret = -10; break; } snprintf(wifiCfg.cfg.gw, sizeof(wifiCfg.cfg.gw), jsTmp->valuestring); LOGI("gateway:%s", wifiCfg.cfg.gw); jsTmp = cJSON_GetObjectItem(obj, "dns"); if (NULL == jsTmp){ LOGE("parse dns error!"); ret = -11; break; } snprintf(wifiCfg.cfg.dns, sizeof(wifiCfg.cfg.dns), jsTmp->valuestring); LOGI("ip:%s", wifiCfg.cfg.dns); ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::setNetWifiCfg(const stNetWifi& wifiCfg) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "set_wifiSettings"); cJSON_AddStringToObject(json, "enctype", wifiCfg.encType); cJSON_AddStringToObject(json, "ssid", wifiCfg.ssid); cJSON_AddStringToObject(json, "pwd", wifiCfg.pwd); cJSON_AddNumberToObject(json, "type", wifiCfg.cfg.type); if(!wifiCfg.cfg.type){ cJSON_AddStringToObject(json, "ip", wifiCfg.cfg.ip); cJSON_AddStringToObject(json, "netmask", wifiCfg.cfg.mask); if(wifiCfg.cfg.gw[0]){ cJSON_AddStringToObject(json, "gateway", wifiCfg.cfg.gw); } if(wifiCfg.cfg.dns[0]){ cJSON_AddStringToObject(json, "dns", wifiCfg.cfg.dns); } } cJSON_AddBoolToObject(json, "enableAp", wifiCfg.enableAp); cJSON_AddStringToObject(json, "apPwd", wifiCfg.apPwd); cJSON_AddBoolToObject(json, "isApCfg", wifiCfg.isAPCfg); cJSON_AddBoolToObject(json, "isDevCfg", true); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::setNetWifiEnable(bool enable) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "update_wifi_status"); cJSON_AddBoolToObject(json, "status", enable); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::getSsidList(stAccPoint accPointList[], int accPointListSize) { #if 0 //test int ret = -1; std::vector vSsidList; std::vector vSigLev; std::vector vEncrypt; ret = wifiScan(vSsidList, vSigLev, vEncrypt, targetSsid); if(0 == ret){ int i = 0; for(auto& s : vSsidList){ if(i < accPointListSize){ if("" != s){ snprintf(accPointList[i].ssid, sizeof(accPointList[i].ssid), s.c_str()); accPointList[i].sigLev = vSigLev[i]; accPointList[i].isEncrypt = vEncrypt[i]; if(s == targetSsid){ targetConn = wifiConnect(targetSsid, targetSsidPwd); } i++; } } else{ break; } } ret = i; } return ret; #else int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "get_wifiList"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *obj = cJSON_GetObjectItem(root, "data"); if (NULL == obj){ LOGE("parse data error!"); ret = -3; break; } cJSON *ap_arry = cJSON_GetObjectItem(obj, "wifiList"); if( NULL == ap_arry ){ LOGE("parse wifiList error!"); ret = -4; break; } int i = 0; cJSON *client_list = ap_arry->child; while( client_list != NULL ){ if(i < accPointListSize){ char *ssid = cJSON_GetObjectItem( client_list , "ssid")->valuestring; if(ssid && *ssid){ LOGI("ssid:%s", accPointList[i].ssid); snprintf(accPointList[i].ssid, sizeof(accPointList[i].ssid), ssid); accPointList[i].sigLev = cJSON_GetObjectItem( client_list , "sig")->valueint; accPointList[i].isEncrypt = (bool)cJSON_GetObjectItem( client_list , "ept")->valueint; accPointList[i].isConnected = (bool)cJSON_GetObjectItem( client_list , "conn")->valueint; i++; LOGI("ssid:%s, sigLev:%d, isEncrypt:%d, isConnected:%d", accPointList[i].ssid, accPointList[i].sigLev, accPointList[i].isEncrypt, accPointList[i].isConnected); } } else{ LOGE("space for ssid list not enough"); break; } client_list = client_list->next ; } ret = i; }while(0); } free(jsonBuf); } return ret; #endif } int Backstage::claerNetWifiCfg() { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "clear_wifiSettings"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::getNet4GCfg(stNet4G& n4gCfg) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "get_4g_status"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *obj = cJSON_GetObjectItem(root, "data"); if (NULL == obj){ LOGE("parse data error!"); ret = -3; break; } cJSON *jsTmp = cJSON_GetObjectItem(obj, "hasDevice"); if (NULL == jsTmp){ LOGE("parse available error!"); ret = -4; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("status available: %d", jsTmp->valueint); ret = -5; break; } n4gCfg.available = jsTmp->valueint; LOGI("n4gCfg.available:%d", n4gCfg.available); if(false == n4gCfg.available){ ret = 0; break; } jsTmp = cJSON_GetObjectItem(obj, "status"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -6; break; } if (jsTmp->valueint < 0 || jsTmp->valueint > 1){ LOGE("status error: %d", jsTmp->valueint); ret = -7; break; } n4gCfg.enable = jsTmp->valueint; LOGI("n4gCfg.enable:%d", n4gCfg.enable); if(false == n4gCfg.enable){ ret = 0; break; } jsTmp = cJSON_GetObjectItem(obj, "service_provider_type"); if (NULL == jsTmp){ LOGE("parse provider error!"); ret = -8; break; } n4gCfg.provider = jsTmp->valueint; LOGI("provider:%d", n4gCfg.provider); ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::setNet4GEnable(bool enable) { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "update_4g_status"); cJSON_AddBoolToObject(json, "status", enable); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::reboot4G() { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "reboot_4g"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("netconfig ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::getScreenSaverConfig(stScreensaverCfg& cfg) { cfg.type = m_paramMng->getScreensaverType(); cfg.interval = m_paramMng->getScreensaverInter(); cfg.picQty = 0; std::string screensaverCfg(m_paramMng->getScreensaverPics()); while(screensaverCfg.length()){ unsigned iPos = screensaverCfg.find(";"); if(iPos != std::string::npos){ snprintf(&cfg.pic[cfg.picQty][0], sizeof(cfg.pic[0]), screensaverCfg.substr(0, iPos).c_str()); LOGI("screenasver %d : %s", cfg.picQty, &cfg.pic[cfg.picQty][0]); cfg.picQty++; screensaverCfg = (screensaverCfg.length() > iPos + 1 ? screensaverCfg.substr(iPos + 1) : ""); } else{ return -1; } } return 0; } int Backstage::sendPassword(const char *password) { if(m_objs){ LOGI("sendPassword"); GPeInput *peinput = (GPeInput*)m_objs->findObject("peinput"); if (nullptr != peinput){ peinput->sendPassword(password); } } return 0; } void Backstage::resetDecisionCenterTimer() { if(m_objs){ LOGI("resetDecisionCenterTimer"); GDecisionCenter *decCenter = (GDecisionCenter*)m_objs->findObject("decisionCenter"); if (nullptr != decCenter){ decCenter->timerReset(); } } } int Backstage::pauseDataFlow() { if(m_objs){ LOGI("pause Data Flow"); #if 0 GDecisionCenter *decCenter = (GDecisionCenter*)m_objs->findObject("decisionCenter"); if (nullptr != decCenter){ if(!Singleton::GetInstance()->isHardwareTesting()){ decCenter->pauseDataFlowAfterAllNotRecoResRecvd(); } else{ LOGI("is testing hardware..."); } return 0; } #else GTrackerLock *pTrackLock = (GTrackerLock*)m_objs->findObject("trackerLock"); GStandby *pStandby = (GStandby*)m_objs->findObject("standby"); if (nullptr != pTrackLock && nullptr != pStandby){ if(!Singleton::GetInstance()->isHardwareTesting()){ pTrackLock->lockCtrl(true); } else{ LOGI("is testing hardware..."); } return 0; } #endif } return -1; } int Backstage::resumeDataFlow() { if(m_objs){ LOGI("resume Data Flow"); #if 0 GDecisionCenter *decCenter = (GDecisionCenter*)m_objs->findObject("decisionCenter"); if (nullptr != decCenter){ decCenter->resumeDataFlow(); return 0; } #else GTrackerLock *pTrackLock = (GTrackerLock*)m_objs->findObject("trackerLock"); if (pTrackLock){ pTrackLock->lockCtrl(false); return 0; } #endif } return -1; } int Backstage::candidateChoosedInPopupWindow(int index) { LOGI("candidateChoosedInPopupWindow:%d", (int)index); if(index >= 0){ RWProtocol::getInstance()->sendSelectedItem(index); } else{ if(m_objs){ LOGI("cancle choosed by user"); GDecisionCenter *decCenter = (GDecisionCenter*)m_objs->findObject("decisionCenter"); if (nullptr != decCenter){ decCenter->recheckResult(2);//二次核验未经许可人员 } } } return 0; } int Backstage::resetNetworkCfg() { int ret = -1; cJSON *json = cJSON_CreateObject(); if (!json){ LOGE("cJSON_CreateObject list FAIL!"); return ret; } ON_SCOPE_EXIT([&]{cJSON_Delete(json);}); cJSON_AddStringToObject(json, "cmd", "set_default_setting"); char *jsonBuf = cJSON_PrintUnformatted(json); if(jsonBuf){ LOGI("udp json:%s", jsonBuf); std::string reply; if(0 == udpSend(std::string(jsonBuf), reply)){ do{ cJSON *root = cJSON_Parse(reply.c_str()); if (!root){ LOGE("parse root error. "); ret = -2; break; } ON_SCOPE_EXIT([&]{cJSON_Delete(root);}); cJSON *jsTmp = cJSON_GetObjectItem(root, "ret"); if (NULL == jsTmp){ LOGE("parse status error!"); ret = -3; break; } if (0 != jsTmp->valueint){ LOGE("reset Network Cfg ret: %d", jsTmp->valueint); ret = -4; break; } ret = 0; }while(0); } free(jsonBuf); } return ret; } int Backstage::udpSend(const string &sendData, string &recvData) { int fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { LOGE("create socket fail!"); return -1; } timeval tv = {30, 0}; int ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(timeval)); if (ret) { ::close(fd); return -2; } struct sockaddr_in sin; bzero(&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); sin.sin_port = htons(6788); sendto(fd, sendData.c_str(), sendData.length(), 0, (struct sockaddr *)&sin, sizeof(struct sockaddr)); char buff[1024 * 8] = {0}; #if 0 int len = recvfrom(fd, buff, sizeof(buff) - 1, 0, nullptr, nullptr); #else int len = 0; int tryTime = 3; do{ len = recvfrom(fd, buff, sizeof(buff) - 1, 0, nullptr, nullptr); }while(len < 0 && 4 == errno && tryTime--); #endif if (len < 0) { LOGE("no recv data, ret:%d, errno:%d", len, errno); ::close(fd); return -3; } if (buff[len - 2] == '\n' && buff[len - 1] == '\0') { buff[len - 2] = '\0'; len -= 1; } else { buff[len] = '\0'; len++; } LOGD("recv[%d]:%s", strlen(buff), buff); recvData = buff; ::close(fd); return 0; } bool Backstage::isWiegandIoTestOk() { LOGI("isWiegandIoTestOk"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(pPeInput){ pPeInput->hardwareTest(enWgOut); usleep(300000); return pPeInput->isWiegandLoopTestOk(); } return false; } bool Backstage::isRelayAndGpioTestOk() { LOGI("isRelayAndGpioTestOk"); bool ret = true; for(int i=0; i::GetInstance()->hasGpio((BasePeripheral::enGpio)i)){ LOGI("has no gpio%d", i); continue; } int value = 0; if(Singleton::GetInstance()->getGpioValue((BasePeripheral::enGpio)i, value) < 0){ LOGE("get Gpio%d Value failed!", i); ret = false; } if(value != 1){ LOGE("gpio%d not high before relay on", i); ret = false; } } LOGI("relay on"); Singleton::GetInstance()->controlKZOut(true); usleep(100000); for(int i=0; i::GetInstance()->hasGpio((BasePeripheral::enGpio)i)){ LOGI("has no gpio%d", i); continue; } int value = 0; if(Singleton::GetInstance()->getGpioValue((BasePeripheral::enGpio)i, value) < 0){ LOGE("get Gpio%d Value failed!", i); ret = false; } if(value != 0){ LOGE("gpio%d not low after relay on", i); ret = false; } } LOGI("relay off"); Singleton::GetInstance()->controlKZOut(false); return ret; } bool Backstage::isRs485TestOk() { LOGI("isRs485TestOk"); Singleton::GetInstance()->setTestingFlag(true); ON_SCOPE_EXIT([] { Singleton::GetInstance()->setTestingFlag(false); }); usleep(100000); std::string usbTo485DevNode; do{ std::string cmd = "ls /sys/bus/usb-serial/drivers/ftdi_sio/ | grep tty"; if(utils::read_popen(cmd, usbTo485DevNode) > 0){ LOGI("get ftdi_sio usb to rs485 dev node:%s", usbTo485DevNode.c_str()); break; } cmd = "ls /sys/bus/usb-serial/drivers/ch341-uart/ | grep ttyUSB0"; if(utils::read_popen(cmd, usbTo485DevNode) > 0){ LOGI("get ch341-uart usb to rs485 dev node:%s", usbTo485DevNode.c_str()); break; } LOGE("get usb to rs485 dev node failed!"); return false; }while(0); LOGI("Dev Node:%s", usbTo485DevNode.c_str()); const std::string devNode = "/dev/" + usbTo485DevNode; int usbTo485 = open(devNode.c_str(), O_RDWR | O_NOCTTY); if(usbTo485 < 0){ return false; } setSerialOpt(usbTo485, 9600, 8, 'N', 1); LOGI("rs485 send str 123456"); Singleton::GetInstance()->rs485Send((const unsigned char*)"123456", strlen("123456")); char buffer[32] = {0}; int readBytes = read(usbTo485, buffer, sizeof(buffer) - 1); LOGI("usb2485 recv: %s", buffer); if(readBytes <= 0){ close(usbTo485); return false; } int writeLen = write(usbTo485, buffer, readBytes); LOGI("usb2485 send data:%s, len:%d", buffer, writeLen); usleep(100000); int len = Singleton::GetInstance()->rs485Recv((unsigned char*)buffer, sizeof(buffer)); LOGI("rs485 recv len:%d", len); if(len <= 0){ close(usbTo485); return false; } LOGI("data: %s", (const char*)buffer); close(usbTo485); return (!memcmp("123456", buffer, strlen("123456"))); } bool Backstage::isReaderUnderScreenTestOk() { LOGI("isReaderUnderScreenTestOk"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(!pPeInput){ return false; } pPeInput->hardwareTest(enReadCardUnderScreen); return pPeInput->isReaderUnderScreenTestOk(); } bool Backstage::isWifiTestOk() { LOGI("isWifiTestOk"); #define TEST_SSID "reconova" // "RW-5F" // #define TEST_PWD "12345678" //"RW@sz=B103#" // const int ssidListSize = 64; stAccPoint ssidList[ssidListSize]; int ret = getSsidList(ssidList, ssidListSize); LOGI("ssid list size:%d", ret); if(ret > 0){ for(int i=0; i 45){ return wifiConnect(TEST_SSID, TEST_PWD); } } } return false; } bool Backstage::isRtcTestOk() { LOGI("isRtcTestOk, time:%lld", utils::getNowTimeMS()); //return utils::getNowTimeMS() > 946656000000; //20000101 00:00:00 return FileUtils::fileIsExist("/data/.rtc_test_ok"); } bool Backstage::isWireEthTestOk() { LOGI("isWireEthTestOk");sleep(1);return true; } bool Backstage::is4gTestOk() { LOGI("is4gTestOk");sleep(1);return true; } bool Backstage::isSerial1TestOk() { LOGI("isSerial1TestOk"); system("killall skcaper"); Singleton::GetInstance()->setTestingFlag(true); ON_SCOPE_EXIT([] { Singleton::GetInstance()->setTestingFlag(false); }); usleep(100000); const std::string devNode = "/dev/ttyS3"; LOGI("Dev Node:%s", devNode.c_str()); int fdSerial1 = open(devNode.c_str(), O_RDWR | O_NOCTTY); if(fdSerial1 < 0){ LOGE("open %s failed!", devNode.c_str()); return false; } setSerialOpt(fdSerial1, 9600, 8, 'N', 1); const char* testData = "123456"; int writeLen = write(fdSerial1, testData, strlen(testData)); LOGI("write len:%d", writeLen); usleep(100000); char buffer[32] = {0}; int readBytes = read(fdSerial1, buffer, sizeof(buffer) - 1); LOGI("serial0 read bytes: %d", readBytes); if(readBytes <= 0){ close(fdSerial1); return false; } close(fdSerial1); LOGI("data: %s", (const char*)buffer); return (!memcmp(testData, buffer, strlen(testData))); } void Backstage::screenTest() { LOGI("screenTest"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(pPeInput){ pPeInput->hardwareTest(enLcd); } } void Backstage::speakerTest() { LOGI("speakerTest"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(pPeInput){ pPeInput->hardwareTest(enSpeaker); } } void Backstage::microphoneTest(bool record) { LOGI("microphoneTest"); GPeInput *pPeInput = (GPeInput *)m_objs->findObject("peInput"); if (pPeInput) { pPeInput->hardwareTest(record ? enMicrophoneRecord : enMicrophonePlay); } } void Backstage::audioSwitchTest() { LOGI("Backstage::audioSwitchTest()"); auto pPeInput = reinterpret_cast(m_objs->findObject("peInput")); if (pPeInput != nullptr) { pPeInput->hardwareTest(enAuidoSwitch); } } void Backstage::tpTest() { LOGI("tpTest"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(pPeInput){ //pPeInput->hardwareTest(enTp); } } void Backstage::irCamTest() { LOGI("irCamTest"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(pPeInput){ pPeInput->hardwareTest(enIrCamOn); sleep(3); pPeInput->hardwareTest(enIrCamOff); } } void Backstage::irLedTest() { LOGI("irLedTest"); GPeInput* pPeInput = (GPeInput*)m_objs->findObject("peInput"); if(pPeInput){ pPeInput->hardwareTest(enIrCamOn); for(int i=0; i<3; i++){ Singleton::GetInstance()->setIRledBrightness(0); usleep(500000); Singleton::GetInstance()->setIRledBrightness(255); usleep(500000); } pPeInput->hardwareTest(enIrCamOff); } } void Backstage::ageingTest(unsigned hours) { LOGI("ageingTest"); std::string cmd{"{\"cmd\":\"set_ageing_test\",\"sw\":"}; if(hours){ cmd += "true,\"all_time\":"; cmd += utils::to_string(hours); cmd += "}"; } else{ cmd += "false}"; } udpLoopToSvr(cmd); } int Backstage::getMacFromMes(const char* mesAddrAndProdNo, const char* pcbSeq, std::string& mac) { LOGI("getMacFromMes:%s, %s", mesAddrAndProdNo, pcbSeq); const std::string tmp(mesAddrAndProdNo); unsigned iPos = tmp.find("/"); if(iPos == std::string::npos){ return -1; } std::string mesAddr = tmp.substr(0, iPos); std::string prodNo = tmp.substr(iPos + 1); std::string strPcbSeq = pcbSeq; std::string cmd = "curl -s -K 12 -m 20 -k -X POST \"http://"; cmd += utils::trim(mesAddr); cmd += "/mrs/getProdField?prodNo="; cmd += utils::trim(prodNo); cmd += "&pcbSeq="; cmd += utils::trim(strPcbSeq); cmd += "&fieldName=lanmac\""; LOGI("cmd:%s", cmd.c_str()); if(utils::read_popen(cmd, mac) <= 0){ LOGE("get mac failed!"); return -2; } if(mac.length() != 12){ LOGE("mac invalid, len:%d, mac:%s", mac.length(), mac.c_str()); return -3; } for(int i=5; i>0; i--){ mac.insert(i * 2, 1, ':'); } LOGI("mac:%s", mac.c_str()); cmd = "keydata set mac "; cmd += mac; cmd += " -f"; LOGI("cmd:%s", cmd.c_str()); int nReturn = utils::RW_System(cmd.c_str()); int nResult = WEXITSTATUS(nReturn); if(nResult != 0){ LOGE("str=%s, nReturn=%d, nResult=%d", cmd.c_str(), nReturn, nResult); return -1; } cmd = "echo -n \""; cmd += mac; cmd += " \" > /data/.HWaddr"; LOGI("cmd:%s", cmd.c_str()); nReturn = utils::RW_System(cmd.c_str()); nResult = WEXITSTATUS(nReturn); if(nResult != 0){ LOGE("str=%s, nReturn=%d, nResult=%d", cmd.c_str(), nReturn, nResult); return -1; } return 0; } bool Backstage::isAgeing(std::string& hours) { LOGI("isAgeing"); if(FileUtils::fileIsExist(AGEING_TIME_FILE)){ if(0 == utils::read_file(AGEING_TIME_FILE, hours)){ LOGI("ageing time:%s hours", hours.c_str()); return true; } } return false; } int Backstage::getKeyDataMac(std::string& mac) { LOGI("getKeyDataMac"); return utils::read_popen("keydata get mac", mac); } int Backstage::getRecoUiAdConfig(stScreensaverCfg& cfg) { cfg.type = 1; cfg.interval = m_paramMng->getAdInter(); cfg.picQty = 0; LOGI("reco ui ad config:%s", m_paramMng->getAdPics().c_str()); std::string screensaverCfg(m_paramMng->getAdPics()); while(screensaverCfg.length()){ unsigned iPos = screensaverCfg.find(";"); if(iPos != std::string::npos){ snprintf(&cfg.pic[cfg.picQty][0], sizeof(cfg.pic[0]), screensaverCfg.substr(0, iPos).c_str()); LOGI("ad %d : %s", cfg.picQty, &cfg.pic[cfg.picQty][0]); cfg.picQty++; screensaverCfg = (screensaverCfg.length() > iPos + 1 ? screensaverCfg.substr(iPos + 1) : ""); } else{ return -1; } } return 0; } int Backstage::recoUiTypeSwitch(unsigned x, unsigned y, unsigned w, unsigned h) { GCamera* pcam = (GCamera*)m_objs->findObject("normal"); if (nullptr != pcam){ pcam->voSetDisWin(x, y, w, h); } setLogo(getLogo());//get logo when reci ui switch return 0; } int Backstage::getDevPwd(int& type, std::string& pwd) { int ret = DBManage::getInstance()->getDevicePin(pwd); if(0 == ret && pwd.length()){ type = 2; return 0; } pwd = m_paramMng->getLocalDevPwd(); type = 1; return 0; } int Backstage::setLocalDevPwd(const std::string& pwd) { m_paramMng->setLocalDevPwd(pwd); //该参数配置需要支持清空(取消本地密码操作) //清空时参数对应的更新处理不会关闭识别界面密码按键 //因此需要在这里关闭密码按键显示 if(0 == pwd.length()){ LOGI("hide password button cause pwd deleted by user"); View::getInstance()->setPwdButton(false); } return 0; } int Backstage::getKeyDataHardware(std::string& hardware) { LOGI("getKeyDataHardware"); return utils::read_popen("keydata get hardware", hardware); } int Backstage::setKeyDataHardwareAndUpdataFunction(const std::string& hardware) { LOGI("set hardware:%s", hardware.c_str()); std::string setHwCmd{"keydata set hardware "}; setHwCmd += hardware; setHwCmd += " -f"; system(setHwCmd.c_str()); std::ostringstream oss; oss << "echo " << hardware << " > " WEB_DATA_PATH ".hardversion; sync"; auto command = oss.str(); LOGD("command: %s", command.c_str()); system(command.c_str()); DevVersion::getInstance()->init(); // 工装重新录入型号后,再重新加载 auto manufacturer = DevVersion::getInstance()->getManu(); if (manufacturer == Manu_E::ManuRWRk1109V05) { Singleton::GetInstance()->setAudioOutEnabled(m_paramMng->getAudioOutEnabled()); } const bool hasReaderUnderScreen = ('2' == hardware[strlen("HWA531052") - 1]); Singleton::GetInstance()->functionSwitch(0, hasReaderUnderScreen); const bool hasTp = ('1' == hardware[strlen("HWA5310522C11") - 1]); LOGI("has TP:%d", hasTp); View::getInstance()->showCursorSwitch(!hasTp); return 0; } int Backstage::setSetupAlreadyFlag() { FileUtils::removeFile(SETUP_ALREADY_FILE); return 0; } int Backstage::getParkInfo(std::string& info) { info = m_paramMng->getParkInfo(); return 0; } int Backstage::setParkInfo(const std::string& info) { m_paramMng->setParkInfo(info); return 0; } int Backstage::getDevPosi(std::string& posi) { posi = m_paramMng->getDevicePosition(); return 0; } int Backstage::setDevPosi(const std::string& posi) { m_paramMng->setDevicePosition(posi); return 0; } int Backstage::getRs485Cfg() { if(m_paramMng->getRs485Cfg() == -1){ if(m_paramMng->getAccessController() >= 0){return 1;} //协议1 else if(m_paramMng->getPassCheckByRs485()){return 2;} //协议2 return 0; //禁用 } return m_paramMng->getRs485Cfg(); } int Backstage::setRs485Cfg(int cfg) { #if 0 switch (cfg){ case 0:{m_paramMng->setAccessController(-1);m_paramMng->setPassCheckByRs485(false);}break; case 1:{m_paramMng->setPassCheckByRs485(false);m_paramMng->setAccessController(0);}break;//协议1:门禁控制器 case 2:{m_paramMng->setPassCheckByRs485(true);m_paramMng->setAccessController(-1);}break;//协议2:闸机信号反馈 default:LOGE("rs485 cfg error!");break; } #else m_paramMng->setRs485Cfg(cfg); #endif return 0; } int Backstage::setReverseAccessSw(bool enabled) { int ret = -1; if (m_paramMng != nullptr) { m_paramMng->setReverseAccessSw(enabled); ret = 0; } return ret; } bool Backstage::getReverseAccessSw() const { bool ret = false; if (m_paramMng != nullptr) { ret = m_paramMng->getReverseAccessSw(); } return ret; } int Backstage::getRs485Prot1Addr() { return m_paramMng->getAccessController(); } int Backstage::setRs485Prot1Addr(int addr) { if(addr < 0 || addr > 255){return -1;} m_paramMng->setAccessController(addr);return 0; } int Backstage::getRs485Prot3Cfg(int& handCfg, int& feetCfg) { handCfg = m_paramMng->getStaticHandCfg(); feetCfg = m_paramMng->getStaticFeetCfg(); return 0; } int Backstage::setRs485Prot3Cfg(int handCfg, int feetCfg) { m_paramMng->setStaticHandCfg(handCfg); m_paramMng->setStaticFeetCfg(feetCfg); return 0; } int Backstage::getGPIOCfg() { //return m_paramMng->getGpio4Sw() ? m_paramMng->getGpio4Use() + 1 : 0; return 0; } int Backstage::setGPIOCfg(int cfg) { #if 0 switch (cfg){ case 0:{m_paramMng->setGpio4Sw(false);}break;//禁用 case 1:{m_paramMng->setGpio4Sw(true);m_paramMng->setGpio4Use(0);}break;//开门信号上报(门磁) default:LOGE("gpio cfg error!");break; } #endif return 0; } int Backstage::getIDFaceVerifySw() { return m_paramMng->getFaceIDVerifySw(); } int Backstage::setIDFaceVerifySw(bool sw) { m_paramMng->setFaceIDVerifySw(sw); return 0; } int Backstage::getBtLockCfg(BtDoorLock& cfg) { cfg.isEnable = m_paramMng->getBleLockSw(); int manu[5] = {0}; std::string manuS = m_paramMng->getBleManu(); sscanf(manuS.c_str(), "%d,%d,%d,%d,%d", manu, manu+1, manu+2, manu+3, manu+4); char name[5][128] = {0}; std::string nameS = m_paramMng->getBleName(); sscanf(nameS.c_str(), "%[^,],%[^,],%[^,],%[^,],%s", name[0], name[1], name[2], name[3], name[4]); char mac[5][20] = {0}; std::string macS = m_paramMng->getBleMac(); sscanf(macS.c_str(), "%[^,],%[^,],%[^,],%[^,],%s", mac[0], mac[1], mac[2], mac[3], mac[4]); for(cfg.qty = 0; cfg.qty < 5 && manu[cfg.qty] > 0; cfg.qty++) { LOGD("manu[%d]=%d", cfg.qty, manu[cfg.qty]); cfg.manufacturer.emplace_back(manu[cfg.qty]); LOGD("name[%d]=%s", cfg.qty, name[cfg.qty]); cfg.position.emplace_back(name[cfg.qty]); LOGD("mac[%d]=%s", cfg.qty, mac[cfg.qty]); cfg.mac.emplace_back(mac[cfg.qty]); } return 0; } int Backstage::setBtLockCfg(const BtDoorLock& cfg) { LOGI("setBtLockCfg"); blueToothMng::getInstance().clearBleLock(); std::string bleManu; std::string bleName; std::string bleId; for(int i=0; isetBleManu(bleManu.c_str()); m_paramMng->setBleName(bleName.c_str()); m_paramMng->setBleMac(bleId.c_str()); m_paramMng->setBleLockSw(cfg.isEnable); return 0; } int Backstage::getBtLockRemainingBatPwr(const std::string& mac) { return blueToothMng::getInstance().getElecValue(blueToothMng::enBleLockManu::BYX, mac.c_str()); } bool Backstage::getHealthCodeSw() { return m_paramMng->getHealthCodeSw(); } int Backstage::setHealthCodeSw(bool sw) { m_paramMng->setHealthCodeSw(sw); if(sw){ m_paramMng->setRecoSw(true); m_paramMng->setFaceIDVerifySw(true); } return 0; } bool Backstage::getHealthCodeNoFaceRequired(){ return m_paramMng->getHealthNoFaceRequired(); } int Backstage::setHealthCodeNoFaceRequired(bool sw){ m_paramMng->setHealthNoFaceRequired(sw); return 0; } bool Backstage::getHealthCodeAllowStranger() { return m_paramMng->getHealthCodeAllowStrangerSw(); } int Backstage::setHealthCodeAllowStranger(bool sw) { m_paramMng->setHealthCodeAllowStrangerSw(sw); return 0; } int Backstage::getHealthCodePassCfg(int& codeColorCfg, int& c19tCfg, int& tripCfg, int& abtCfg) { codeColorCfg = m_paramMng->getHealthCodeColorPassCfg(); c19tCfg = m_paramMng->getHealthC19TResPassCfg(); tripCfg = m_paramMng->getHealthTripResPassCfg(); abtCfg = m_paramMng->getHealthAbtResPassCfg(); return 0; } int Backstage::setHealthCodePassCfg(int codeColorCfg, int c19tCfg, int tripCfg, int abtCfg) { m_paramMng->setHealthCodeColorPassCfg(codeColorCfg); m_paramMng->setHealthC19TResPassCfg(c19tCfg); m_paramMng->setHealthTripResPassCfg(tripCfg); m_paramMng->setHealthAbtResPassCfg(abtCfg); return 0; } std::string Backstage::utfRawStrToEncodeStr(const std::string &str) { return utils::utfRawStrToEncodeStr(str); } int Backstage::udpLoopToSvr(const std::string &sendData) { int udpFd = socket(AF_INET, SOCK_DGRAM, 0); if (udpFd < 0){ LOGE("create socket fail!"); } timeval tv = {1, 0}; int ret = setsockopt(udpFd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(timeval)); if (ret){ LOGE("setsockopt failed"); ::close(udpFd); udpFd = -1; } struct sockaddr_in sin; bzero(&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); sin.sin_port = htons(6790); sendto(udpFd, sendData.c_str(), sendData.length(), 0, (struct sockaddr *)&sin, sizeof(struct sockaddr)); LOGI("udp send:%s", sendData.c_str()); ::close(udpFd); return 0; }