#pragma once #include "uart/ProtocolSender.h" #include "net/NetManager.h" #include #include #include #include "utils/TimeHelper.h" #include "core/utilities.h" #include "core/sip_config.h" #include "base/strings.hpp" #include "base/base.hpp" #include "storage/StoragePreferences.h" #include "service/BusinessConfig.h" #include "core/jhws.h" #include "manager/LanguageManager.h" #define ETHERNETMANAGER NETMANAGER->getEthernetManager() #define WIFIMANAGER NETMANAGER->getWifiManager() /* *此文件由GUI工具生成 *文件功能:用于处理用户的逻辑相应代码 *功能说明: *========================onButtonClick_XXXX 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称, 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK. *========================onSlideWindowItemClick_XXXX(int index) 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称, 如slideWindow1;index 代表按下图标的偏移值 *========================onSeekBarChange_XXXX(int progress) 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称, 如SeekBar1;progress 代表当前的进度值 *========================ogetListItemCount_XXXX() 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称, 如List1;返回值为当前列表的总条数 *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index) 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称, 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明 *========================常用接口=============== *LOGD(...) 打印调试信息的接口 *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字**** *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色 *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12 *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用 *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度 * * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示 */ static std::string passwordType = ""; using namespace std; struct NetworkConfiguration { std::string ip; std::string sub_network_mask; std::string gateway; }; NetworkConfiguration GetNetworkConfiguration() { char ip[64] = {0}; char mask[64] = {0}; char gateway[64] = {0}; char dns1[64] = {0}; char dns2[64] = {0}; ENetChannel channel = NETMANAGER->getConnChannel(); switch (channel) { case E_NET_CHANNEL_ETHERNET: if (ETHERNETMANAGER->isAutoMode()) { ETHERNETMANAGER->getConfigureInfo(ip, mask, gateway, dns1, dns2); } else { ETHERNETMANAGER->getStaticConfigureInfo(ip, mask, gateway, dns1, dns2); } break; case E_NET_CHANNEL_WIFI: WIFIMANAGER->getConfigureInfo(ip, mask, gateway, dns1, dns2); break; } return NetworkConfiguration{ip, mask, gateway}; } //地址总长 #define ADDRLEN 15 //定义字符串数组保存IP地址、掩码地址、网关地址、首选DNS服务器地址以及备选DNS服务器地址 static string addr[5]; /** * 字符长度是否正确 * */ const bool isLengthCorrect(const string addr) { return addr.size() <= ADDRLEN; } /** * 检查是不是最多只有3个.字符 * */ const bool noMoreThan3charactor(const string addr) { //.字符个数 int count = 0; for(unsigned int level1 = 0; level1 < addr.size(); ++level1) { if('.' == addr[level1]) { ++count; } } return 3 >= count; } /* * 判断所有字符是不是由0~9和.组成 * */ const bool allCharacterIsLegal(const string addr) { for(unsigned int level1 = 0; level1 < addr.size(); ++level1) { if(false == (('0' <= addr[level1] && addr[level1] <= '9') || '.' == addr[level1])) { return false; } } return true; } /** * 判断开头是否是1`9 * */ const bool headIsCorrect(string addr, unsigned int pos = 0) { //查找到达末尾,直接返回true if(addr.size() == pos) { return true; } //查找.字符 if(string::npos == addr.find('.', pos)) { if('0' < addr[pos] && addr[pos] <= '9') { return true; } //如果开头为字符'0'且其后没有字符,那么返回true else if(addr.size()-1 == pos) { return true; } return false; } else { //开头为0~9 if('0' > addr[pos] || addr[pos] > '9') { return false; } //开头为0,后面没有字符返回false if('0' == addr[pos] && addr.size()-1 <= pos) { return false; } //跳过.字符继续查找 return headIsCorrect(addr, addr.find('.', pos)+1); } return true; //默认返回true } /** * 检查地址每一小段的长度,最长为3个字符 * */ const bool partCheractorCorrect(const string addr, unsigned int pos = 0) { //查找到达末尾,直接返回true if(addr.size() == pos) { return true; } //查找.字符 if(string::npos == addr.find('.', pos)) { if(3 >= addr.size()-pos) { return true; } return false; } else { //由于跳过了.字符进行查找,因此判断条件应该是>3 if(3 < addr.find('.', pos) - pos) { return false; } //跳过.字符继续查找 return partCheractorCorrect(addr, addr.find('.', pos)+1); } return true; //默认返回true } /** * 检测地址是否有误 * */ const bool checkAddr(string addr) { return (true == headIsCorrect(addr))? //地址每小段开头是否为0~9 (true == partCheractorCorrect(addr))? //每小段字符串最大长度是否为3 (true == noMoreThan3charactor(addr))? //最多是否只有3个.字符 (true == isLengthCorrect(addr))? //地址最大长度是否为15 (true == allCharacterIsLegal(addr))? //所有的字符是否都由0~9和.组成 true: false: false: false: false: false; // bool ret = true; // // ret = headIsCorrect(addr); //地址每小段开头是否为0~9 // if(false == ret){LOGD("---%d---", __LINE__); return ret;} // // ret = partCheractorCorrect(addr); //每小段字符串最大长度是否为3 // if(false == ret){LOGD("---%d---", __LINE__); return ret;} // // ret = noMoreThan3charactor(addr); //最多是否只有3个.字符 // if(false == ret){LOGD("---%d---", __LINE__); return ret;} // // ret = isLengthCorrect(addr); //地址最大长度是否为15 // if(false == ret){LOGD("---%d---", __LINE__); return ret;} // // ret = allCharacterIsLegal(addr); //所有的字符是否都由0~9和.组成 // if(false == ret){LOGD("---%d---", __LINE__); return ret;} // // return true; } static void passwordWindowShow() { mPasswordEditTextPtr->setText(""); mErrorTextViewPtr->setText(""); mPasswordWindowPtr->showWnd(); } static uint32_t color = 0xFFF84D61; static uint32_t redLightColour = 0xFFF9C5C5; static uint32_t redDeepColour = 0xFFF84D61; static uint32_t buleLightColour = 0xFFD2E2F2; static uint32_t buleDeepColour = 0xFF2F9DF1; void setUi3BgColor(uint32_t _color) { color = _color; } /** * 注册定时器 * 填充数组用于注册定时器 * 注意:id不能重复 */ static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = { //{0, 6000}, //定时器id=0, 时间间隔6秒 //{1, 1000}, }; /** * 当界面构造时触发 */ static void onUI_init(){ //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123"); string qrStr = "http://m.wdklian.com/care/apk/care.user?type=NCS_DEVICE&code=&mac=" + std::string(ETHERNETMANAGER->getMacAddr()) + "&model=&hard_ver=HV1.0&soft_ver=SW1.0&device_type=3&device_name=门口机"; mQRCode1Ptr->loadQRCode(qrStr.c_str()); mDeviceIdPtr->setText(StoragePreferences::getInt(STORE_DEVICE_ID, 0)); mDeviceCodePtr->setText(GetDeviceUid()); mDeviceMacPtr->setText(ETHERNETMANAGER->getMacAddr()); ENetChannel channel = NETMANAGER->getConnChannel(); switch (channel) { case E_NET_CHANNEL_ETHERNET: mDeviceIpPtr->setText(ETHERNETMANAGER->getIp()); break; case E_NET_CHANNEL_WIFI: mDeviceIpPtr->setText(WIFIMANAGER->getIp()); break; } mNetMaskPtr->setText(GetNetworkConfiguration().sub_network_mask); mGatewayPtr->setText(GetNetworkConfiguration().gateway); //sip //StoragePreferences::putString(SIP_REG_ACCOUNT, SIP_REG_ACCOUNT_DEFAULT); string voiceId = StoragePreferences::getString(SIP_REG_ACCOUNT, SIP_REG_ACCOUNT_DEFAULT); mVoiceIdPtr->setText(voiceId); string voicePwd = StoragePreferences::getString(SIP_REG_PASSWORD, SIP_REG_PASSWORD_DEFAULT); mVoiceDomainPtr->setText(StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT)); mVersionPtr->setText(version); //server ip string sIP = StoragePreferences::getString(STORE_GATEWAY, serverIP); mServerIPPtr->setText(sIP); if (color == redDeepColour) { mUi3PainterPtr->setBackgroundColor(redLightColour); mWindowServerIPPtr->setBackgroundColor(0xFFFF8080); mPasswordWindowPtr->setBackgroundColor(0xFFFF8080); mRebootWindowPtr->setBackgroundColor(0xFFFF8080); } else { mUi3PainterPtr->setBackgroundColor(buleLightColour); mWindowServerIPPtr->setBackgroundColor(0xFF92C5EB); mPasswordWindowPtr->setBackgroundColor(0xFF92C5EB); mRebootWindowPtr->setBackgroundColor(0xFF92C5EB); } // 界面上 mBtnRestartPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mSettingPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mBtnNetSettingPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mBtnSoftVerPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mTestButtonPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); msys_backPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); // 窗口上 mBtnServerIPConfirmPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mConfirmButtonPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); // 重启窗口上 mRebootDeviceButtonPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mRebootPowerButtonPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); mRebootLineButtonPtr->setBgStatusColor(ZK_CONTROL_STATUS_NORMAL, color); } /** * 当切换到该界面时触发 */ static void onUI_intent(const Intent *intentPtr) { if (intentPtr != NULL) { //TODO } } /* * 当界面显示时触发 */ static void onUI_show() { } /* * 当界面隐藏时触发 */ static void onUI_hide() { } /* * 当界面完全退出时触发 */ static void onUI_quit() { } /** * 串口数据回调接口 */ static void onProtocolDataUpdate(const SProtocolData &data) { } /** * 定时器触发函数 * 不建议在此函数中写耗时操作,否则将影响UI刷新 * 参数: id * 当前所触发定时器的id,与注册时的id相同 * 返回值: true * 继续运行当前定时器 * false * 停止运行当前定时器 */ static bool onUI_Timer(int id){ switch (id) { default: break; } return true; } /** * 有新的触摸事件时触发 * 参数:ev * 新的触摸事件 * 返回值:true * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上 * false * 触摸事件将继续传递到控件上 */ static bool onui3ActivityTouchEvent(const MotionEvent &ev) { switch (ev.mActionStatus) { case MotionEvent::E_ACTION_DOWN://触摸按下 //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY); break; case MotionEvent::E_ACTION_MOVE://触摸滑动 break; case MotionEvent::E_ACTION_UP: //触摸抬起 break; default: break; } return false; } static bool onButtonClick_Setting(ZKButton *pButton) { LOGD(" ButtonClick Setting !!!\n"); passwordType = "serverIp"; passwordWindowShow(); return false; } static void onEditTextChanged_EditTextServerIP(const std::string &text) { //LOGD(" onEditTextChanged_ EditTextServerIP %s !!!\n", text.c_str()); } static void onEditTextChanged_EditTextServerPort(const std::string &text) { //LOGD(" onEditTextChanged_ EditTextServerPort %s !!!\n", text.c_str()); } // 设置服务器ip static bool onButtonClick_BtnServerIPConfirm(ZKButton *pButton) { LOGD("设置服务器ip !!!\n"); LOGD("服务器ip set to %s",mEditTextServerIPPtr->getText().c_str()); if(false == checkAddr(mEditTextServerIPPtr->getText())){ mServerIPMsgPtr->setTextTr("ServerIPWrong"); return false; } StoragePreferences::putString(STORE_GATEWAY, mEditTextServerIPPtr->getText().c_str()); StoragePreferences::putInt(STORE_HTTP_PORT, std::atoi(mEditTextServerPortPtr->getText().c_str())); //mWindowServerIPPtr->hideWnd(); const char* req = "-1"; TcpClient::instance()->sendMsg(req); lightControl("CALLLED", "000F"); //重启 sync(); reboot(RB_AUTOBOOT); return false; } static bool onButtonClick_BtnRestart(ZKButton *pButton) { LOGD(" ButtonClick BtnRestart !!!\n"); passwordType = "reboot"; passwordWindowShow(); // const char* req = "-1"; // TcpClient::instance()->sendMsg(req); // //重启 // sync(); // reboot(RB_AUTOBOOT); return false; } static bool onButtonClick_BtnNetSetting(ZKButton *pButton) { LOGD(" ButtonClick BtnNetSetting !!!\n"); //EASYUICONTEXT->openActivity("EthernetSettingActivity"); EASYUICONTEXT->openActivity("NetSettingActivity"); return false; } static bool onButtonClick_BtnSoftVer(ZKButton *pButton) { LOGD(" ButtonClick BtnSoftVer !!!\n"); EASYUICONTEXT->openActivity("DeviceUpdateActivity"); return false; } static bool onButtonClick_BackButton(ZKButton *pButton) { LOGD(" ButtonClick BackButton !!!\n"); return false; } static bool onButtonClick_sys_back(ZKButton *pButton) { LOGD(" ButtonClick sys_back !!!\n"); return false; } static bool onButtonClick_TestButton(ZKButton *pButton) { LOGD(" ButtonClick TestButton !!!\n"); passwordType = "sipTest"; passwordWindowShow(); return false; } static void onEditTextChanged_PasswordEditText(const std::string &text) { //LOGD(" onEditTextChanged_ PasswordEditText %s !!!\n", text.c_str()); } static bool onButtonClick_ConfirmButton(ZKButton *pButton) { LOGD(" ButtonClick ConfirmButton !!!\n"); string pwd = mPasswordEditTextPtr->getText(); if (passwordType == "serverIp") { string cpwd = "666"; if (pwd == cpwd){ mPasswordWindowPtr->hideWnd(); mWindowServerIPPtr->showWnd(); string serverIp = StoragePreferences::getString(STORE_GATEWAY, "172.28.100.100"); int serverPort = StoragePreferences::getInt(STORE_HTTP_PORT, 8006); mEditTextServerIPPtr->setText(serverIp); mEditTextServerPortPtr->setText(to_string(serverPort)); return false; } else { mErrorTextViewPtr->setTextTr("PasswordWrong"); } } else if (passwordType == "sipTest") { // 密码为888 string cpwd = "888"; if (pwd == cpwd){ // 关闭密码输入界面 mPasswordWindowPtr->hideWnd(); EASYUICONTEXT->openActivity("sipTestActivity"); return false; } else { mErrorTextViewPtr->setTextTr("PasswordWrong"); } } else if (passwordType == "reboot") { // 密码为888 string cpwd = "888"; if (pwd == cpwd){ // 关闭密码输入界面 mPasswordWindowPtr->hideWnd(); mRebootWindowPtr->showWnd(); return false; } else { mErrorTextViewPtr->setTextTr("PasswordWrong"); } } return false; } static bool onButtonClick_RebootDeviceButton(ZKButton *pButton) { LOGD(" ButtonClick RebootDeviceButton !!!\n"); const char* req = "-1"; TcpClient::instance()->sendMsg(req); lightControl("CALLLED", "000F"); //重启 sync(); reboot(RB_AUTOBOOT); return false; } static bool onButtonClick_RebootPowerButton(ZKButton *pButton) { LOGD(" ButtonClick RebootPowerButton !!!\n"); systemRestart(); return false; } static bool onButtonClick_RebootLineButton(ZKButton *pButton) { LOGD(" ButtonClick RebootLineButton !!!\n"); TcpModel tcpModel; tcpModel.type = TcpType::DEVICE; tcpModel.action = DeviceAction::POWER_RESET; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = NULL; std::string req = getTcpModelString(tcpModel); LOGD("TCP DEVICE : %s",req.c_str()); TcpClient::instance()->sendMsg(req.c_str()); return false; }