#pragma once #include "uart/ProtocolSender.h" #include "net/NetManager.h" #include "storage/StoragePreferences.h" #include "net/net.h" #include #include "restclient-cpp/restclient.h" #include "curl/curl.h" #include #include "service/BusinessConfig.h" #include "core/sip_config.h" #include "manager/LanguageManager.h" #include "core/utilities.h" #include "base/strings.hpp" #include "base/http_client.h" #include "os/UpgradeMonitor.h" #include "core/jhws.h" #include "core/update_assistant.h" #include "utils/TimeHelper.h" #define ETHERNETMANAGER NETMANAGER->getEthernetManager() /* *此文件由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 + /” 快捷键可以打开智能提示 */ BabySex BabySex; Json::Value babyList; static std::string babySex = BabySex.girl; // 默认是女孩,有可能是男孩boy,也有可能是双胞胎twins,有女娃的就twins_girl,都是男娃的就twins_boy static uint32_t redLightColour = 0xFFF9C5C5; static uint32_t redDeepColour = 0xFFF84D61; static uint32_t buleLightColour = 0xFFD2E2F2; static uint32_t buleDeepColour = 0xFF2F9DF1; static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据 PartSetting partSetting; Json::Value frameRoom; Json::Value frameBed; Json::Value frameInfo; // 缓存房间名字等 Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题 Json::Value painterInfo; Json::Value painterInfoList; Json::Value nurseInfo; static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要 #define HELP_TIMER_HANDLE 3 // 增援的定时器id #define NURSING_TIME_HANDLE 6 // 护理的定时器id #define EVENT_TIME_HANDLE 8 // 事件定时器 #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏 //======================================= udp 请示服务器信息 static net::Conn* udpConn; class UdpThread: public Thread { public: static void getServerInfo(){ string url = getHttpGateway() + "/ncs_url/server_info"; LOGD("请求服务器信息. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ // http StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString()); StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt()); // tcp StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString()); StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt()); // sip StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt()); serverInfo = false; // 只有请求成功了,才不需要重复请求 } } static void getDeviceInfo(){ if (dataInit){ getFrameInfo(); getMainInfo(); //getPartSetting(StoragePreferences::getString(STORE_PARTID, "")); return; } string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + ETHERNETMANAGER->getMacAddr(); LOGD("请求设备信息. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); LOGD("获得设备信息. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ string partName = root["part_display"].asString(); StoragePreferences::putString(STORE_PARTNAME,partName); NavibarSetPartName(partName); //设备 StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt()); StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt()); //SIP存储 // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString()); StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString()); //获取科室设置 string partId = root["part_id"].asString(); StoragePreferences::putString(STORE_PARTID, partId); getPartSetting(partId); getVersion(); setFrameInfo(root); getFrameRoom(root["frame_id"].asInt()); } } // 将空间相关的数据缓存起来 static void setFrameInfo(Json::Value deviceInfo) { frameInfo["frame_id"] = deviceInfo["frame_id"].asInt(); frameInfo["full_name"] = deviceInfo["full_name"].asString(); frameInfo["part_id"] = deviceInfo["part_id"].asInt(); getFrameInfo(); getFrameRoom(deviceInfo["frame_id"].asInt()); } // 读取空间缓存的数据 static void getFrameInfo() { mRoomNamePtr->setText(frameInfo["full_name"].asString()); } static void getFrameRoom(int frame_id) { string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id); LOGD("请求房间信息. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); LOGD("获得房间信息. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ frameRoom = root; frameBed = root["frame_bed_list"][0]; babyList = frameBed["frame_bed_relative_vos"]; if (babyList.size() > 1) { int boysexInt = 0; for (int i = 0; i < 2; i++) { boysexInt += babyList[i]["relative_sex"].asInt(); } if (boysexInt > 1) { babySex = BabySex.twins_boy; LOGD("双胞胎男孩"); } else if (boysexInt == 1) { babySex = BabySex.twins_boy_and_girl; LOGD("龙凤胎"); } else { babySex = BabySex.twins_girl; LOGD("双胞胎女孩"); } } else if (babyList.size() == 1) { if (babyList[0]["relative_sex"].asInt() == 1) { // 如果是女孩 babySex = BabySex.boy; LOGD("单个男孩"); } else { babySex = BabySex.girl; LOGD("单个女孩"); } } getMainInfo(); } int customerId = frameBed["customer_id"].asInt(); if (customerId != 0) { getClerk(frameBed["customer_id"].asInt()); } } static void getClerk(int customerId) { string url = getHttpGateway() + "/deviceRoom/get_clerk_by_customer_id/" + to_string(customerId); LOGD("请求护士信息. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); LOGD("获得护士信息. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ nurseInfo = root; string clerkName = nurseInfo["clerk_name"].asString(); if (clerkName != "") { mNurseNameTextViewPtr->setText(nurseInfo["clerk_name"].asCString()); } } if (babySex == BabySex.girl || babySex == BabySex.twins_girl) { // 护士 mNursePhotoPainterPtr->setBackgroundPic("nurse_red.png"); mNurseNameTextViewPtr->setTextColor(redDeepColour); } else { // 护士 mNursePhotoPainterPtr->setBackgroundPic("nurse_blue.png"); mNurseNameTextViewPtr->setTextColor(buleDeepColour); } } static void getMainInfo() { string customerName = frameBed["customer_name"].asString(); if (customerName == "") { return; } mCustomerNameTextViewPtr->setText(customerName); string descText = frameBed["customer_illness_desc"].asString(); if (descText != "") { mDescTextViewPtr->setText(descText); mDescTextViewPtr->setVisible(true); } string inDateStr = LANGUAGEMANAGER->getValue("InTime"); string inDate = frameBed["customer_in_date"].asString(); if (inDate != "") { time_t timet = stoi(inDate); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); inDate = pDate; } mInDateTextViewPtr->setText(inDateStr + inDate); string outDateStr = LANGUAGEMANAGER->getValue("OutTime"); string outDate = frameBed["customer_out_date"].asString(); if (outDate != "") { time_t timet = stoi(outDate); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); outDate = pDate; } if (outDate == "") { outDate = "0000-00-00"; } mOutDateTextViewPtr->setText(outDateStr + outDate); if (babySex == BabySex.girl || babySex == BabySex.twins_girl) { // 背景 mMainPainterPtr->setBackgroundColor(redLightColour); // 房间 // mPainterInfoPtr->setBackgroundPic("/main/title_red.png"); mPainterInfoPtr->setBackgroundColor(redDeepColour); // 用户 mCustomerNameTextViewPtr->setTextColor(redDeepColour); mDescTextViewPtr->setBackgroundColor(redDeepColour); mInDateTextViewPtr->setTextColor(redDeepColour); mOutDateTextViewPtr->setTextColor(redDeepColour); mMsgPainterPtr->setBackgroundPic("/main/msg_red.png"); // 更多 mMoreButtonPtr->setTextColor(redDeepColour); // 设置科室名称和时间 setPartNameAndDateColor(redDeepColour); // 设置ui3界面的颜色 setUi3BgColor(redDeepColour); if (babyList.size() == 0) { return; } if (babySex == BabySex.girl) { // 只有一个女孩的时候 // 主图 mCustomerInfoPainterPtr->setBackgroundPic("/main/girl.png"); // 婴儿姓名 mBayNameTextViewPtr->setVisible(true); mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString()); mBayNameTextViewPtr->setTextColor(redDeepColour); // 婴儿出生日期 mBabyBirTextViewPtr->setVisible(true); string babyBirStr = LANGUAGEMANAGER->getValue("BirTime"); string babyBir = babyList[0]["relative_birthday"].asString(); babyBir = babyBir.substr(0, 10); if (babyBir != "") { time_t timet = stoi(babyBir); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir = pDate; } babyBirStr += babyBir; mBabyBirTextViewPtr->setText(babyBirStr); mBabySexTextViewPtr->setVisible(true); mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Woman")); mBabySexTextViewPtr->setBackgroundColor(redDeepColour); mBabyNameTextView2Ptr->setVisible(false); mBabyBirTextView2Ptr->setText(""); mBabySexTextView2Ptr->setVisible(false); } else { // 双胞胎女孩 // 主图 mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_girl.png"); // 婴儿姓名 mBayNameTextViewPtr->setVisible(true); mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString()); mBayNameTextViewPtr->setTextColor(redDeepColour); // 婴儿出生日期 mBabyBirTextViewPtr->setVisible(true); string babyBirStr = LANGUAGEMANAGER->getValue("BirTime"); string babyBir = babyList[0]["relative_birthday"].asString(); if (babyBir != "") { babyBir = babyBir.substr(0, 10); time_t timet = stoi(babyBir); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir = pDate; } babyBirStr += babyBir; mBabyBirTextViewPtr->setText(babyBirStr); mBabySexTextViewPtr->setVisible(true); mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Woman")); mBabySexTextViewPtr->setBackgroundColor(redDeepColour); // 婴儿姓名 mBabyNameTextView2Ptr->setVisible(true); mBabyNameTextView2Ptr->setText(babyList[1]["relative_member_name"].asCString()); mBabyNameTextView2Ptr->setTextColor(redDeepColour); // 婴儿出生日期 mBabyBirTextView2Ptr->setVisible(true); string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime"); string babyBir2 = babyList[1]["relative_birthday"].asString(); babyBir2 = babyBir2.substr(0, 10); if (babyBir != "") { time_t timet = stoi(babyBir2); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir2 = pDate; } babyBir2Str += babyBir2; mBabyBirTextView2Ptr->setText(babyBir2Str); mBabySexTextView2Ptr->setVisible(true); mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman")); mBabySexTextView2Ptr->setBackgroundColor(redDeepColour); } } else { // 背景 mMainPainterPtr->setBackgroundColor(buleLightColour); // 房间 // mPainterInfoPtr->setBackgroundPic("/main/title_blue.png"); mPainterInfoPtr->setBackgroundColor(buleDeepColour); // 用户 mCustomerNameTextViewPtr->setTextColor(buleDeepColour); mDescTextViewPtr->setBackgroundColor(buleDeepColour); mInDateTextViewPtr->setTextColor(buleDeepColour); mOutDateTextViewPtr->setTextColor(buleDeepColour); mMsgPainterPtr->setBackgroundPic("/main/msg_blue.png"); // 更多 mMoreButtonPtr->setTextColor(buleDeepColour); // 设置科室名称和时间 setPartNameAndDateColor(buleDeepColour); // 设置ui3界面的颜色 setUi3BgColor(buleDeepColour); if (babyList.size() == 0) { return; } if (babySex == BabySex.boy) { // 只有一个男孩 // 主图 mCustomerInfoPainterPtr->setBackgroundPic("/main/boy.png"); // 婴儿姓名 mBayNameTextViewPtr->setVisible(true); mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString()); mBayNameTextViewPtr->setTextColor(buleDeepColour); // 婴儿出生日期 mBabyBirTextViewPtr->setVisible(true); string babyBirStr = LANGUAGEMANAGER->getValue("BirTime"); string babyBir = babyList[0]["relative_birthday"].asString(); babyBir = babyBir.substr(0, 10); if (babyBir != "") { time_t timet = stoi(babyBir); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir = pDate; } babyBirStr += babyBir; mBabyBirTextViewPtr->setText(babyBirStr); mBabySexTextViewPtr->setVisible(true); mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man")); mBabySexTextViewPtr->setBackgroundColor(buleDeepColour); mBabyNameTextView2Ptr->setVisible(false); mBabyBirTextView2Ptr->setText(""); mBabySexTextView2Ptr->setVisible(false); } else if (babySex == BabySex.twins_boy) { // 双胞胎男孩 // 主图 mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_boy.png"); // 婴儿姓名 mBayNameTextViewPtr->setVisible(true); mBayNameTextViewPtr->setText(babyList[0]["relative_member_name"].asCString()); mBayNameTextViewPtr->setTextColor(buleDeepColour); // 婴儿出生日期 mBabyBirTextViewPtr->setVisible(true); string babyBirStr = LANGUAGEMANAGER->getValue("BirTime"); string babyBir = babyList[0]["relative_birthday"].asString(); if (babyBir != "") { babyBir = babyBir.substr(0, 10); time_t timet = stoi(babyBir); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir = pDate; } babyBirStr += babyBir; mBabyBirTextViewPtr->setText(babyBirStr); mBabySexTextViewPtr->setVisible(true); mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man")); mBabySexTextViewPtr->setBackgroundColor(buleDeepColour); // 婴儿姓名 mBabyNameTextView2Ptr->setVisible(true); mBabyNameTextView2Ptr->setText(babyList[1]["relative_member_name"].asCString()); mBabyNameTextView2Ptr->setTextColor(buleDeepColour); // 婴儿出生日期 mBabyBirTextView2Ptr->setVisible(true); string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime"); string babyBir2 = babyList[1]["relative_birthday"].asString(); babyBir2 = babyBir2.substr(0, 10); if (babyBir != "") { time_t timet = stoi(babyBir2); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir2 = pDate; } babyBir2Str += babyBir2; mBabyBirTextView2Ptr->setText(babyBir2Str); mBabySexTextView2Ptr->setVisible(true); mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Man")); mBabySexTextView2Ptr->setBackgroundColor(buleDeepColour); } else if (babySex == BabySex.twins_boy_and_girl) { // 龙凤胎 // 主图 mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_boy_girl.png"); for (int i = 0; i < babyList.size(); i++) { if (babyList[i]["relative_sex"].asInt() == 1) { // 婴儿姓名 mBayNameTextViewPtr->setVisible(true); mBayNameTextViewPtr->setText(babyList[i]["relative_member_name"].asCString()); mBayNameTextViewPtr->setTextColor(buleDeepColour); // 婴儿出生日期 mBabyBirTextViewPtr->setVisible(true); string babyBirStr = LANGUAGEMANAGER->getValue("BirTime"); string babyBir = babyList[i]["relative_birthday"].asString(); if (babyBir != "") { babyBir = babyBir.substr(0, 10); time_t timet = stoi(babyBir); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir = pDate; } babyBirStr += babyBir; mBabyBirTextViewPtr->setText(babyBirStr); mBabySexTextViewPtr->setVisible(true); mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man")); mBabySexTextViewPtr->setBackgroundColor(buleDeepColour); } else { // 婴儿姓名 mBabyNameTextView2Ptr->setVisible(true); mBabyNameTextView2Ptr->setText(babyList[i]["relative_member_name"].asCString()); mBabyNameTextView2Ptr->setTextColor(redDeepColour); // 婴儿出生日期 mBabyBirTextView2Ptr->setVisible(true); string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime"); string babyBir2 = babyList[i]["relative_birthday"].asString(); babyBir2 = babyBir2.substr(0, 10); if (babyBir2 != "") { time_t timet = stoi(babyBir2); struct tm *t = gmtime(&timet); char pDate[25]; sprintf(pDate,"%d-%02d-%02d", 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday); babyBir2 = pDate; } babyBir2Str += babyBir2; mBabyBirTextView2Ptr->setText(babyBir2Str); mBabySexTextView2Ptr->setVisible(true); mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman")); mBabySexTextView2Ptr->setBackgroundColor(redDeepColour); } } } } } static void getPartSetting(string partId){ string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId; LOGD("请求科室信息. url = %s", url.c_str()); //发起HTTP GET请求 RestClient::Response r = RestClient::get(url); LOGD("获得科室信息. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if (reader.parse(r.body, root, false)){ partSetting.partId = root["part_id"].asInt(); partSetting.dayStart = root["day_start"].asString(); partSetting.dayLight = root["day_light"].asInt(); partSetting.dayVol = root["day_vol"].asInt(); partSetting.dayRingVol = root["day_ring_vol"].asInt(); partSetting.dayRingTimes = root["day_ring_times"].asInt(); partSetting.dayNurseLed = root["day_nurse_led"].asInt(); partSetting.dayDoorVol = root["day_door_vol"].asInt(); partSetting.dayBedVol = root["day_bed_vol"].asInt(); partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt(); partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt(); partSetting.nightStart = root["night_start"].asString(); partSetting.nightLight = root["night_light"].asInt(); partSetting.nightVol = root["night_vol"].asInt(); partSetting.nightRingVol = root["night_ring_vol"].asInt(); partSetting.nightRingTimes = root["night_ring_times"].asInt(); partSetting.nightNurseLed = root["night_nurse_led"].asInt(); partSetting.nightDoorVol = root["night_door_vol"].asInt(); partSetting.nightBedVol = root["night_bed_vol"].asInt(); partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt(); partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt(); partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt(); partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt(); partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt(); partSetting.sipOvertime = root["sip_overtime"].asInt(); partSetting.transferDuration = root["transfer_duration"].asInt(); partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt(); partSetting.communicationModeBed = root["communication_mode_bed"].asInt(); partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt(); partSetting.communicationModeMobile = root["communication_model_mobile"].asInt(); partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt(); partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt(); partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt(); partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt(); partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt(); partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt(); partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString(); partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt(); partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString(); partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt(); partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString(); partSetting.doctorTitle = root["doctor_title"].asString(); partSetting.doctorValid = root["doctor_valid"].asInt(); partSetting.nurseTitle = root["nurse_title"].asString(); partSetting.nurseValid = root["nurse_valid"].asInt(); partSetting.doorNurseTitle = root["door_nurse_title"].asString(); partSetting.doorNurseValid = root["door_nurse_valid"].asInt(); partSetting.doorNursingTitle = root["door_nursing_title"].asString(); partSetting.doorNursingValid = root["door_nursing_valid"].asInt(); partSetting.upSeconds = root["up_seconds"].asInt(); partSetting.autoAccept = root["auto_accept"].asInt(); partSetting.eventForward = root["event_forward"].asInt(); partSetting.nursingColorRgb = root["nursing_color_rgb"].asString(); partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt(); partSetting.qrUrl = root["qr_url"].asString(); partSetting.screenLight = root["screen_light"].asInt(); StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart); StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight); StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol); StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes); StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart); StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight); StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol); StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes); StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor); StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle); StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1); StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle); StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1); StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb); StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1); StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight); dataInit = true; } } static void getVersion() { std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, ""); std::string content_type = std::string("application/json"); LOGD("请求版本信息. url = %s", url.c_str()); //发起HTTP POST请求 RestClient::Response r = RestClient::post(url, content_type, ""); if (r.code != 200) { LOGD("请求版本信息-> 错误代码: %d", r.code); return; } LOGD("获得版本信息. result = %s", r.body.c_str()); //解析json Json::Reader reader; Json::Value root; if(reader.parse(r.body, root, false)) { int currentVersionNo = getVersionNo(); int responseVersionNo = root["version_no"].asInt(); std::string responseVersion = root["version_code"].asString(); LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo); if (currentVersionNo < responseVersionNo) { Intent* intent = new Intent(); intent->putExtra(appUpdate, "true"); EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent); } } } /** * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作 * return true 继续线程 * false 退出线程 */ virtual bool readyToRun() { LOGD("Thread 已经创建完成"); return true; } /** * 线程循环函数 * * return true 继续线程循环 * false 推出线程 */ virtual bool threadLoop() { LOGD("线程循环函数"); //检查是否有退出线程的请求,如果有,则返回false,立即退出线程 if (exitPending()) { return false; } udpConn = net::Dial("udp", "192.168.1.255:10010"); if (udpConn) { byte buf[1024] = {0}; const char* req = "search_server"; //发送 udpConn->Write((byte*)req, strlen(req)); while (true && !exitPending()) { //读取,超时10*1000毫秒 int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000); if (n > 0) { buf[n] = 0; char serverStr[1024]; sprintf(serverStr,"%s",buf); LOGD("读取 %d字节: %s", n, serverStr); //解析json Json::Reader reader; Json::Value root; if (reader.parse(serverStr, root, false)){ if (root.isMember("success") && root["success"].asBool()){ serverIP = root["data"]["third_server"].asString(); serverHttpPort = root["data"]["third_server_port"].asInt(); StoragePreferences::putString(STORE_GATEWAY, serverIP); StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort); //先获取服务器信息 //getServerInfo(); //就当在获取服务器信息完成后获取用户信息,这里测试用 //getCustomerInfo(); //退出UDP线程 pthread_exit(NULL); break; } } } else if (n == 0) { LOGD("连接正常断开"); break; } else if (n == net::E_TIMEOUT) { udpConn->Write((byte*)req, strlen(req)); LOGD("读取超时"); } else { LOGD("出错"); break; } } //关闭连接 udpConn->Close(); //释放内存 delete udpConn; udpConn = NULL; } //返回真,继续下次线程循环 return true; } }; static UdpThread udp_thread; int getNowTime() { struct tm *t = TimeHelper::getDateTime(); char timeStr[50]; string formatStr = "%02d:%02d:%02d"; sprintf(timeStr, formatStr.c_str(), t->tm_hour,t->tm_min,t->tm_sec); int hour, minute, second;// 定义时间的各个int临时变量。 sscanf(timeStr, "%d:%d:%d", &hour, &minute, &second); int time = hour * 60 * 60 + minute * 60 + second; return time; } Json::Value getPainterInfoList() { return painterInfoList; } void addPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, int endTime) { // 将设备id,颜色,展示的信息,时间存放起来 painterInfo["deviceId"] = deviceId; // painterInfo["bgColor"] = bgColor + ""; painterInfo["bgColor"] = bgColor; painterInfo["msg"] = msg; painterInfo["type"] = type; painterInfo["endTime"] = getNowTime() + endTime; painterInfoList.append(painterInfo); } bool removePainterInfo(int deviceId, const std::string type) { // 获取painterInfoList的长度 int size = painterInfoList.size(); if (size == 0) { // 如果为空了,那就代表painterInfoList没有值,直接返回 return false; } // 如果painterInfoList里有对应的deviceId,那就需要先删除原本的,然后再从头添加新的 int removeIndex = -1; for (int i = 0; i < painterInfoList.size(); i++) { LOGD("deviceId == %d", deviceId); LOGD("painterInfoList.deviceId == %d", painterInfoList[i]["deviceId"].asInt()); LOGD("type == %s", type.c_str()); LOGD("painterInfoList.type == %s", painterInfoList[i]["type"].asCString()); if (painterInfoList[i]["deviceId"].asInt() == deviceId && painterInfoList[i]["type"].asString() == type) { removeIndex = i; } } if (removeIndex != -1) { painterInfoList.removeIndex(removeIndex, &painterInfo); } return true; } // 收到tcp的时候,刷新数据 void dataRefresh() { LOGD("DATA-REFRESH, 数据刷新"); if (serverInfo) { udp_thread.getServerInfo(); } dataInit = false; udp_thread.getDeviceInfo(); } void getPartSetting() { udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, "")); } /** * 注册定时器 * 填充数组用于注册定时器 * 注意:id不能重复 */ static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = { //{0, 6000}, //定时器id=0, 时间间隔6秒 //{1, 1000}, }; /** * 当界面构造时触发 */ static void onUI_init(){ //udp_thread.run("this is thread name"); //测试用 LOGD("进入mainLogic页面, 触发 onUI_init"); if(serverInfo) { // 如果是false,就是不需要 udp_thread.getServerInfo(); } udp_thread.getDeviceInfo(); } /** * 当切换到该界面时触发 */ static void onUI_intent(const Intent *intentPtr) { if (intentPtr != NULL) { } } /* * 当界面显示时触发 */ static void onUI_show() { } /* * 当界面隐藏时触发 */ static void onUI_hide() { } /* * 当界面完全退出时触发 */ static void onUI_quit() { //pthread_exit(NULL); } /** * 串口数据回调接口 */ 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 onmainActivityTouchEvent(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_MoreButton(ZKButton *pButton) { LOGD(" ButtonClick MoreButton !!!\n"); EASYUICONTEXT->openActivity("ui3Activity"); return false; }