mainLogic.cc 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "net/NetManager.h"
  4. #include "storage/StoragePreferences.h"
  5. #include "net/net.h"
  6. #include <system/Thread.h>
  7. #include "restclient-cpp/restclient.h"
  8. #include "curl/curl.h"
  9. #include <algorithm>
  10. #include "service/BusinessConfig.h"
  11. #include "core/sip_config.h"
  12. #include "manager/LanguageManager.h"
  13. #include "core/utilities.h"
  14. #include <string>
  15. #include "zkaudio.h"
  16. #include "base/strings.hpp"
  17. #include "base/http_client.h"
  18. #include "os/UpgradeMonitor.h"
  19. #include "core/jhws.h"
  20. #include "core/update_assistant.h"
  21. #include "utils/TimeHelper.h"
  22. #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
  23. #define WIFIMANAGER NETMANAGER->getWifiManager()
  24. /*
  25. *此文件由GUI工具生成
  26. *文件功能:用于处理用户的逻辑相应代码
  27. *功能说明:
  28. *========================onButtonClick_XXXX
  29. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  30. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  31. *========================onSlideWindowItemClick_XXXX(int index)
  32. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  33. 如slideWindow1;index 代表按下图标的偏移值
  34. *========================onSeekBarChange_XXXX(int progress)
  35. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  36. 如SeekBar1;progress 代表当前的进度值
  37. *========================ogetListItemCount_XXXX()
  38. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  39. 如List1;返回值为当前列表的总条数
  40. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  41. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  42. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  43. *========================常用接口===============
  44. *LOGD(...) 打印调试信息的接口
  45. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  46. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  47. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  48. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  49. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  50. *
  51. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  52. */
  53. TcpModel nursingTcpModel;
  54. static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据
  55. PartSetting partSetting;
  56. Json::Value frameRoom;
  57. Json::Value frameBedList;
  58. Json::Value frameInfo; // 缓存房间名字等
  59. Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题
  60. Json::Value painterInfo;
  61. Json::Value painterInfoList;
  62. static bool reinforce = false; // 判断设备是否处于增援状态
  63. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  64. static bool isHelpTimerRegistered = false;
  65. static std::string cencalByDoorTid = "";
  66. #define HELP_TIMER_HANDLE 3 // 增援的定时器id
  67. #define EVENT_TIME_HANDLE 8 // 事件定时器
  68. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  69. //======================================= udp 请示服务器信息
  70. static net::Conn* udpConn;
  71. class UdpThread: public Thread {
  72. public:
  73. static void getServerInfo(){
  74. string url = getHttpGateway() + "/ncs_url/server_info";
  75. LOGD("请求服务器信息. url = %s", url.c_str());
  76. //发起HTTP GET请求
  77. RestClient::Response r = RestClient::get(url);
  78. //解析json
  79. Json::Reader reader;
  80. Json::Value root;
  81. if (reader.parse(r.body, root, false)){
  82. // http
  83. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  84. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  85. // tcp
  86. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  87. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  88. // sip
  89. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  90. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  91. serverInfo = false; // 只有请求成功了,才不需要重复请求
  92. }
  93. }
  94. static void getDeviceInfo(){
  95. if (dataInit){
  96. getFrameInfo();
  97. //getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  98. reinforceDispaly();
  99. return;
  100. }
  101. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0");
  102. LOGD("请求设备信息. url = %s", url.c_str());
  103. //发起HTTP GET请求
  104. RestClient::Response r = RestClient::get(url);
  105. LOGD("获得设备信息. result = %s", r.body.c_str());
  106. //解析json
  107. Json::Reader reader;
  108. Json::Value root;
  109. if (reader.parse(r.body, root, false)){
  110. string partName = root["part_display"].asString();
  111. StoragePreferences::putString(STORE_PARTNAME,partName);
  112. NavibarSetPartName(partName);
  113. //设备
  114. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  115. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  116. //SIP存储
  117. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  118. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  119. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  120. frameInfo["frame_id"] = root["frame_id"].asInt();
  121. frameInfo["full_name"] = root["full_name"].asString();
  122. frameInfo["part_id"] = root["part_id"].asInt();
  123. getFrameInfo();
  124. //获取科室设置
  125. string partId = root["part_id"].asString();
  126. StoragePreferences::putString(STORE_PARTID, partId);
  127. getPartSetting(partId);
  128. getVersion();
  129. }
  130. }
  131. // 读取空间缓存的数据
  132. static void getFrameInfo() {
  133. mRoomNamePtr->setText(frameInfo["full_name"].asString());
  134. }
  135. static void getFrameRoom(int frame_id) {
  136. string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id);
  137. LOGD("请求房间信息. url = %s", url.c_str());
  138. //发起HTTP GET请求
  139. RestClient::Response r = RestClient::get(url);
  140. LOGD("获得房间信息. result = %s", r.body.c_str());
  141. //解析json
  142. Json::Reader reader;
  143. Json::Value root;
  144. if (reader.parse(r.body, root, false)){
  145. frameRoom = root;
  146. frameBedList = root["frame_bed_list"];
  147. if (mBedListViewPtr != NULL) {
  148. mBedListViewPtr->refreshListView();
  149. }
  150. }
  151. }
  152. static void getPartSetting(string partId){
  153. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  154. LOGD("请求科室信息. url = %s", url.c_str());
  155. //发起HTTP GET请求
  156. RestClient::Response r = RestClient::get(url);
  157. LOGD("获得科室信息. result = %s", r.body.c_str());
  158. //解析json
  159. Json::Reader reader;
  160. Json::Value root;
  161. if (reader.parse(r.body, root, false)){
  162. partSetting.partId = root["part_id"].asInt();
  163. partSetting.dayStart = root["day_start"].asString();
  164. partSetting.dayLight = root["day_light"].asInt();
  165. partSetting.dayVol = root["day_vol"].asInt();
  166. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  167. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  168. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  169. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  170. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  171. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  172. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  173. partSetting.nightStart = root["night_start"].asString();
  174. partSetting.nightLight = root["night_light"].asInt();
  175. partSetting.nightVol = root["night_vol"].asInt();
  176. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  177. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  178. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  179. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  180. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  181. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  182. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  183. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  184. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  185. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  186. partSetting.sipOvertime = root["sip_overtime"].asInt();
  187. partSetting.transferDuration = root["transfer_duration"].asInt();
  188. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  189. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  190. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  191. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  192. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  193. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  194. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  195. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  196. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  197. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  198. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  199. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  200. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  201. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  202. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  203. partSetting.doctorTitle = root["doctor_title"].asString();
  204. partSetting.doctorValid = root["doctor_valid"].asInt();
  205. partSetting.nurseTitle = root["nurse_title"].asString();
  206. partSetting.nurseValid = root["nurse_valid"].asInt();
  207. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  208. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  209. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  210. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  211. partSetting.upSeconds = root["up_seconds"].asInt();
  212. partSetting.autoAccept = root["auto_accept"].asInt();
  213. partSetting.eventForward = root["event_forward"].asInt();
  214. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  215. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  216. partSetting.qrUrl = root["qr_url"].asString();
  217. partSetting.screenLight = root["screen_light"].asInt();
  218. partSetting.roomCallBed = root["room_call_bed"].asInt();
  219. if (root["linux_door_volume_native"].size() != 0) {
  220. partSetting.linuxDoorVolumeNative = root["linux_door_volume_native"].asInt();
  221. partSetting.linuxDoorGainSize = root["linux_door_gain_size"].asInt();
  222. zk_audio_input_set_volume_native(0, 0);
  223. zk_audio_input_set_volume_native(1, partSetting.linuxDoorVolumeNative);
  224. GetTelephone()->SetInputPcmGainSize(partSetting.linuxDoorGainSize);
  225. StoragePreferences::putInt(STORE_VOLUME_NATIVE, partSetting.linuxDoorVolumeNative);
  226. StoragePreferences::putInt(STORE_GAIN_SIZE, partSetting.linuxDoorGainSize);
  227. }
  228. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  229. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  230. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  231. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  232. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  233. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  234. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  235. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  236. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  237. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  238. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  239. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  240. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  241. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  242. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  243. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  244. StoragePreferences::putInt(STORE_ROOM_CALL_BED, partSetting.roomCallBed);
  245. setRightTitle(root);
  246. callBedButtonSetVisible();
  247. getFrameRoom(frameInfo["frame_id"].asInt());
  248. dataInit = true;
  249. }
  250. }
  251. static void callBedButtonSetVisible() {
  252. int roomCallBed = StoragePreferences::getInt(STORE_ROOM_CALL_BED, 1);
  253. if (!roomCallBed) {
  254. // 如果roomCallBed是0的话,那就隐藏
  255. mCallBedButtonPtr->setVisible(roomCallBed);
  256. mCallNurseButtonPtr->setPosition(LayoutPosition(869, 190, 140, 55));
  257. mCallCencelButtonPtr->setPosition(LayoutPosition(869, 280, 140, 55));
  258. mHelpButtonPtr->setPosition(LayoutPosition(869, 370, 140, 55));
  259. // mNursingButtonPtr->setPosition(LayoutPosition(869, 404, 140, 55));
  260. mMoreButtonPtr->setPosition(LayoutPosition(869, 460, 140, 55));
  261. }
  262. else {
  263. // 如果roomCallBed是1的话,那就显示
  264. mCallBedButtonPtr->setVisible(roomCallBed);
  265. mCallNurseButtonPtr->setPosition(LayoutPosition(869, 255, 140, 55));
  266. mCallCencelButtonPtr->setPosition(LayoutPosition(869, 330, 140, 55));
  267. mHelpButtonPtr->setPosition(LayoutPosition(869, 405, 140, 55));
  268. // mNursingButtonPtr->setPosition(LayoutPosition(869, 420, 140, 55));
  269. mMoreButtonPtr->setPosition(LayoutPosition(869, 480, 140, 55));
  270. }
  271. }
  272. // 将医生和护士别称缓存起来
  273. static void setRightTitle(Json::Value partSetting) {
  274. rightTitleInfo["doctor_title"] = partSetting["doctor_title"].asString();
  275. rightTitleInfo["doctor_valid"] = partSetting["doctor_valid"].asInt();
  276. rightTitleInfo["nurse_title"] = partSetting["nurse_title"].asString();
  277. rightTitleInfo["nurse_valid"] = partSetting["nurse_valid"].asInt();
  278. }
  279. static void getVersion() {
  280. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  281. std::string content_type = std::string("application/json");
  282. LOGD("请求版本信息. url = %s", url.c_str());
  283. //发起HTTP POST请求
  284. RestClient::Response r = RestClient::post(url, content_type, "");
  285. if (r.code != 200) {
  286. LOGD("请求版本信息-> 错误代码: %d", r.code);
  287. return;
  288. }
  289. LOGD("获得版本信息. result = %s", r.body.c_str());
  290. //解析json
  291. Json::Reader reader;
  292. Json::Value root;
  293. if(reader.parse(r.body, root, false)) {
  294. int currentVersionNo = getVersionNo();
  295. int responseVersionNo = root["version_no"].asInt();
  296. std::string responseVersion = root["version_code"].asString();
  297. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  298. if (currentVersionNo < responseVersionNo) {
  299. Intent* intent = new Intent();
  300. intent->putExtra(appUpdate, "true");
  301. EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent);
  302. }
  303. }
  304. }
  305. // 判断是否处于增援状态,处于增援状态,就要显示蓝色
  306. static void reinforceDispaly() {
  307. if (reinforce) {
  308. // SetPainterInfo(0xFF2F9DF1, "增援已发出");
  309. // setHelpButton("/button/button_help3.png" ,false);
  310. setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF2F9DF1, LANGUAGEMANAGER->getValue("HelpInfo"), "REINFORCE", "ADD", 60);
  311. }
  312. }
  313. /**
  314. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  315. * return true 继续线程
  316. * false 退出线程
  317. */
  318. virtual bool readyToRun() {
  319. LOGD("Thread 已经创建完成");
  320. return true;
  321. }
  322. /**
  323. * 线程循环函数
  324. *
  325. * return true 继续线程循环
  326. * false 推出线程
  327. */
  328. virtual bool threadLoop() {
  329. LOGD("线程循环函数");
  330. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  331. if (exitPending()) {
  332. return false;
  333. }
  334. udpConn = net::Dial("udp", "192.168.1.255:10010");
  335. if (udpConn) {
  336. byte buf[1024] = {0};
  337. const char* req = "search_server";
  338. //发送
  339. udpConn->Write((byte*)req, strlen(req));
  340. while (true && !exitPending()) {
  341. //读取,超时10*1000毫秒
  342. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  343. if (n > 0) {
  344. buf[n] = 0;
  345. char serverStr[1024];
  346. sprintf(serverStr,"%s",buf);
  347. LOGD("读取 %d字节: %s", n, serverStr);
  348. //解析json
  349. Json::Reader reader;
  350. Json::Value root;
  351. if (reader.parse(serverStr, root, false)){
  352. if (root.isMember("success") && root["success"].asBool()){
  353. serverIP = root["data"]["third_server"].asString();
  354. serverHttpPort = root["data"]["third_server_port"].asInt();
  355. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  356. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  357. //先获取服务器信息
  358. //getServerInfo();
  359. //就当在获取服务器信息完成后获取用户信息,这里测试用
  360. //getCustomerInfo();
  361. //退出UDP线程
  362. pthread_exit(NULL);
  363. break;
  364. }
  365. }
  366. } else if (n == 0) {
  367. LOGD("连接正常断开");
  368. break;
  369. } else if (n == net::E_TIMEOUT) {
  370. udpConn->Write((byte*)req, strlen(req));
  371. LOGD("读取超时");
  372. } else {
  373. LOGD("出错");
  374. break;
  375. }
  376. }
  377. //关闭连接
  378. udpConn->Close();
  379. //释放内存
  380. delete udpConn;
  381. udpConn = NULL;
  382. }
  383. //返回真,继续下次线程循环
  384. return true;
  385. }
  386. };
  387. static UdpThread udp_thread;
  388. void setReinforce(bool result) {
  389. reinforce = result;
  390. }
  391. void setHelpButton(const char *pPicPath, bool isTouchable){
  392. mHelpButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, pPicPath);
  393. mHelpButtonPtr->setTouchable(isTouchable);
  394. }
  395. void cancelAutoBtnHelpTimer(){
  396. if (isHelpTimerRegistered) {
  397. mActivityPtr->unregisterUserTimer(HELP_TIMER_HANDLE);
  398. isHelpTimerRegistered = false;
  399. }
  400. }
  401. std::string getCencalByDoorTid() {
  402. return cencalByDoorTid;
  403. }
  404. int getNowTime() {
  405. struct tm *t = TimeHelper::getDateTime();
  406. char timeStr[50];
  407. string formatStr = "%02d:%02d:%02d";
  408. sprintf(timeStr, formatStr.c_str(), t->tm_hour,t->tm_min,t->tm_sec);
  409. int hour, minute, second;// 定义时间的各个int临时变量。
  410. sscanf(timeStr, "%d:%d:%d", &hour, &minute, &second);
  411. int time = hour * 60 * 60 + minute * 60 + second;
  412. return time;
  413. }
  414. Json::Value getPainterInfoList() {
  415. return painterInfoList;
  416. }
  417. void addPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, int endTime) {
  418. // 将设备id,颜色,展示的信息,时间存放起来
  419. painterInfo["deviceId"] = deviceId;
  420. // painterInfo["bgColor"] = bgColor + "";
  421. painterInfo["bgColor"] = bgColor;
  422. painterInfo["msg"] = msg;
  423. painterInfo["type"] = type;
  424. painterInfo["endTime"] = getNowTime() + endTime;
  425. painterInfoList.append(painterInfo);
  426. }
  427. bool removePainterInfo(int deviceId, const std::string type) {
  428. // 获取painterInfoList的长度
  429. int size = painterInfoList.size();
  430. if (size == 0) { // 如果为空了,那就代表painterInfoList没有值,直接返回
  431. return false;
  432. }
  433. // 如果painterInfoList里有对应的deviceId,那就需要先删除原本的,然后再从头添加新的
  434. int removeIndex = -1;
  435. for (int i = 0; i < painterInfoList.size(); i++) {
  436. LOGD("deviceId == %d", deviceId);
  437. LOGD("painterInfoList.deviceId == %d", painterInfoList[i]["deviceId"].asInt());
  438. LOGD("type == %s", type.c_str());
  439. LOGD("painterInfoList.type == %s", painterInfoList[i]["type"].asCString());
  440. if (painterInfoList[i]["deviceId"].asInt() == deviceId && painterInfoList[i]["type"].asString() == type) {
  441. removeIndex = i;
  442. }
  443. }
  444. if (removeIndex != -1) {
  445. painterInfoList.removeIndex(removeIndex, &painterInfo);
  446. }
  447. return true;
  448. }
  449. //标识方法
  450. void setPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, const std::string handle, int endTime) {
  451. if (handle == "ADD") { // 进行添加,如果painterInfoList为空时,添加需要启动定时器
  452. int size = painterInfoList.size();
  453. removePainterInfo(deviceId, type);
  454. addPainterInfo(deviceId, bgColor, msg, type, endTime);
  455. if (size == 0) {
  456. mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 1000); // 每秒检测一次
  457. }
  458. if (type == "REINFORCE") { // 增援添加的时候,需要禁用增援按钮
  459. setReinforce(true); // 设置增援状态为true
  460. setHelpButton("/button/button_help3.png", false);
  461. }
  462. }
  463. else if (handle == "UPDATE") { // 进行修改时,需要把原本的删除掉,再进行添加
  464. bool result = removePainterInfo(deviceId, type);
  465. addPainterInfo(deviceId, bgColor, msg, type, endTime);
  466. if (!result) {
  467. mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 1000); // 每秒检测一次
  468. }
  469. }
  470. else if (handle == "DELETE") { // 进行删除
  471. removePainterInfo(deviceId, type);
  472. if (type == "REINFORCE") { // 增援删除的时候,需要还原增援按钮的图片
  473. setReinforce(false);
  474. setHelpButton("/button/button_help2.png", true);
  475. }
  476. }
  477. LOGD("painterInfoList.size() == %d", painterInfoList.size());
  478. mPainterInfoPtr->setBackgroundColor(bgColor);
  479. mTextInfoPtr->setText(msg);
  480. if (bgColor == 0xFFFFFFFF){
  481. mRoomNamePtr->setTextColor(0x00AAF4);
  482. } else {
  483. mRoomNamePtr->setTextColor(0xFFFFFF);
  484. }
  485. }
  486. // 收到tcp的时候,刷新数据
  487. void dataRefresh() {
  488. LOGD("DATA-REFRESH, 数据刷新");
  489. if (mActivityPtr == NULL) {
  490. return;
  491. }
  492. if (serverInfo) {
  493. udp_thread.getServerInfo();
  494. }
  495. dataInit = false;
  496. udp_thread.getDeviceInfo();
  497. mBedListViewPtr->refreshListView();
  498. }
  499. void getPartSetting() {
  500. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  501. }
  502. // 处理护理的tcpModel
  503. void setNursingTcpModel(TcpModel tcpModel) {
  504. LOGD("缓存Nursing的tcpModel !!!");
  505. nursingTcpModel = tcpModel;
  506. }
  507. void sendNursingEnd() {
  508. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  509. // std::string heartStr = "DOORLED,000F";
  510. // const char* sendMsg = heartStr.c_str();
  511. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  512. lightControl("DOORLED", "000F");
  513. if (StoragePreferences::getString(STORE_NURSING_INTERACTION_ID, "") != "") { // 对比一下,json里面不为空的时候
  514. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING_END
  515. TcpModel tcpModel;
  516. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  517. tcpModel.type = TcpType::SIDE;
  518. tcpModel.action = SideAction::NURSING_END;
  519. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  520. tcpModel.data = StoragePreferences::getString(STORE_NURSING_INTERACTION_ID, ""); // 获取nursingTcpModel里,id字段的数据
  521. std::string req = getTcpModelString(tcpModel);
  522. LOGD("TCP NURSING_END : %s",req.c_str());
  523. // TcpClient::instance()->sendMsg(req.c_str());
  524. //回调注册
  525. TcpCallback callback;
  526. callback.tid = tcpModel.tid;
  527. callback.jsonStr = req;
  528. callback.onSuccess = [](Json::Value json){
  529. LOGD("event callback success");
  530. return 0;
  531. };
  532. callback.onFalied = [](Json::Value json){
  533. LOGD("event callback failed");
  534. return 0;
  535. };
  536. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  537. TcpModel newTcpModel;
  538. // 需要把护理的interactionId清空
  539. StoragePreferences::putString(STORE_NURSING_INTERACTION_ID, "");
  540. }
  541. }
  542. /**
  543. * 注册定时器
  544. * 填充数组用于注册定时器
  545. * 注意:id不能重复
  546. */
  547. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  548. //{0, 6000}, //定时器id=0, 时间间隔6秒
  549. //{1, 1000},
  550. };
  551. /**
  552. * 当界面构造时触发
  553. */
  554. static void onUI_init(){
  555. //udp_thread.run("this is thread name");
  556. //测试用
  557. LOGD("进入mainLogic页面, 触发 onUI_init");
  558. if (ETHERNETMANAGER->isConnected() || WIFIMANAGER->isConnected()) {
  559. if(serverInfo) { // 如果是false,就是不需要
  560. udp_thread.getServerInfo();
  561. }
  562. udp_thread.getDeviceInfo();
  563. }
  564. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) { // 如果处于护理状态
  565. mFunctionWinPtr->showWnd();
  566. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  567. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  568. mFunctionBackPtr->setVisible(false);
  569. } else {
  570. mFunctionWinPtr->hideWnd();
  571. }
  572. }
  573. /**
  574. * 当切换到该界面时触发
  575. */
  576. static void onUI_intent(const Intent *intentPtr) {
  577. if (intentPtr != NULL) {
  578. }
  579. }
  580. /*
  581. * 当界面显示时触发
  582. */
  583. static void onUI_show() {
  584. }
  585. /*
  586. * 当界面隐藏时触发
  587. */
  588. static void onUI_hide() {
  589. }
  590. /*
  591. * 当界面完全退出时触发
  592. */
  593. static void onUI_quit() {
  594. //pthread_exit(NULL);
  595. }
  596. /**
  597. * 串口数据回调接口
  598. */
  599. static void onProtocolDataUpdate(const SProtocolData &data) {
  600. }
  601. /**
  602. * 定时器触发函数
  603. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  604. * 参数: id
  605. * 当前所触发定时器的id,与注册时的id相同
  606. * 返回值: true
  607. * 继续运行当前定时器
  608. * false
  609. * 停止运行当前定时器
  610. */
  611. static bool onUI_Timer(int id){
  612. switch (id) {
  613. case HELP_TIMER_HANDLE: // 不能在线程里面关掉线程
  614. {
  615. // SetPainterInfo(0xFFFFFFFF, "");
  616. // setReinforce(false);
  617. // setHelpButton("/button/button_help2.png", true);
  618. // return false;
  619. if (painterInfoList.size() > 0) { // painterInfoList代表里面存在内容
  620. // 取出排列最后的一项,判断列表是否超时,没有超时就将内容填充到里面
  621. Json::Value _painterInfo;
  622. _painterInfo = painterInfoList.get(painterInfoList.size() - 1, &painterInfo);
  623. int nowTime = getNowTime();
  624. if (nowTime >= _painterInfo["endTime"].asInt()) {
  625. if (_painterInfo["type"] == "REINFORCE") {
  626. setReinforce(false);
  627. setHelpButton("/button/button_help2.png", true);
  628. }
  629. painterInfoList.removeIndex(painterInfoList.size() - 1, &painterInfo);
  630. } else {
  631. mPainterInfoPtr->setBackgroundColor( _painterInfo["bgColor"].asUInt());
  632. mTextInfoPtr->setText(_painterInfo["msg"].asCString());
  633. if (_painterInfo["bgColor"] == 0xFFFFFFFF){
  634. mRoomNamePtr->setTextColor(0x00AAF4);
  635. } else {
  636. mRoomNamePtr->setTextColor(0xFFFFFF);
  637. }
  638. }
  639. } else {
  640. mPainterInfoPtr->setBackgroundColor(0xFFFFFFFF);
  641. mTextInfoPtr->setText("");
  642. mRoomNamePtr->setTextColor(0x00AAF4);
  643. setReinforce(false);
  644. setHelpButton("/button/button_help2.png", true);
  645. return false;
  646. }
  647. }
  648. break;
  649. default:
  650. break;
  651. }
  652. return true;
  653. }
  654. /**
  655. * 有新的触摸事件时触发
  656. * 参数:ev
  657. * 新的触摸事件
  658. * 返回值:true
  659. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  660. * false
  661. * 触摸事件将继续传递到控件上
  662. */
  663. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  664. switch (ev.mActionStatus) {
  665. case MotionEvent::E_ACTION_DOWN://触摸按下
  666. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  667. break;
  668. case MotionEvent::E_ACTION_MOVE://触摸滑动
  669. break;
  670. case MotionEvent::E_ACTION_UP: //触摸抬起
  671. break;
  672. default:
  673. break;
  674. }
  675. return false;
  676. }
  677. static int getListItemCount_BedListView(const ZKListView *pListView) {
  678. //LOGD("getListItemCount_BedListView !\n");
  679. if (frameBedList.size() > 3) {
  680. return frameBedList.size();
  681. }
  682. return 3;
  683. }
  684. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  685. //LOGD(" obtainListItemData_ BedListView !!!\n");
  686. if (frameBedList.size() > 0) {
  687. string frameBedName = frameBedList[index]["frame_bed"]["full_name"].asString();
  688. if (frameBedName == "") {
  689. pListItem->findSubItemByID(ID_MAIN_BedFrameTextView)->setText(LANGUAGEMANAGER->getValue("EmptyBed"));
  690. } else {
  691. int nPos = frameBedName.find("-");
  692. if (nPos != -1) {
  693. frameBedName = frameBedName.substr(nPos + 1, frameBedName.length());
  694. }
  695. pListItem->findSubItemByID(ID_MAIN_BedFrameTextView)->setText(frameBedName);
  696. }
  697. // 用户相关
  698. string customerName = frameBedList[index]["customer_name"].asString();
  699. if (customerName == "") {
  700. pListItem->findSubItemByID(ID_MAIN_CustomerName)->setText(LANGUAGEMANAGER->getValue("EmptyCustomer"));
  701. } else {
  702. pListItem->findSubItemByID(ID_MAIN_CustomerName)->setText(customerName);
  703. }
  704. pListItem->findSubItemByID(ID_MAIN_CustomerAge)->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  705. string customerSex = frameBedList[index]["customer_sex"].asString();
  706. if (customerSex == "0") { // 如果性别为女性,则替换成女性头像,和女性的图标
  707. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_female.png");
  708. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_female.png");
  709. }
  710. else if (customerSex == "1") {
  711. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_male.png");
  712. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_male.png");
  713. }
  714. else {
  715. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_empty.png");
  716. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("");
  717. }
  718. // 医生护士相关
  719. if (rightTitleInfo["doctor_valid"] != 1){
  720. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setVisible(false);
  721. } else {
  722. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setText(rightTitleInfo["doctor_title"].asString());
  723. }
  724. if (rightTitleInfo["nurse_valid"] != 1){
  725. pListItem->findSubItemByID(ID_MAIN_NurseText)->setVisible(false);
  726. } else {
  727. pListItem->findSubItemByID(ID_MAIN_NurseText)->setText(rightTitleInfo["nurse_title"].asString());
  728. }
  729. pListItem->findSubItemByID(ID_MAIN_DoctorName)->setText(frameBedList[index]["doctor_name"].asString());
  730. pListItem->findSubItemByID(ID_MAIN_NurseName)->setText(frameBedList[index]["nurse_name"].asString());
  731. // // 护理项相关
  732. // Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  733. // if (nurseConfigList.size() > 0) {
  734. // for (int i = 0; i < 5; i++) {
  735. // int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  736. // int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  737. // int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  738. // if (nurseConfigList.size() >= i) {
  739. // //颜色
  740. // string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  741. // uint32_t bgColor = 0xFFC0C0C0;
  742. // if (nurseConfigColot != "") {
  743. // string rgbStr = "FF" + nurseConfigColot;
  744. // transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  745. // bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  746. // }
  747. // pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  748. // pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  749. // string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  750. // if (nurseOptionName == "") {
  751. // nurseOptionName = LANGUAGEMANAGER->getValue("None");
  752. // }
  753. // pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  754. //
  755. // } else {
  756. // //颜色
  757. // pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  758. // pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  759. // pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  760. // }
  761. // }
  762. // }
  763. // else {
  764. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  765. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  766. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  767. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  768. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  769. // pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  770. // pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  771. // pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  772. // pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  773. // pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  774. // pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  775. // pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  776. // pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  777. // pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  778. // pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  779. // }
  780. }
  781. }
  782. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  783. //LOGD(" onListItemClick_ BedListView !!!\n");
  784. }
  785. static bool onButtonClick_CallBedButton(ZKButton *pButton) {
  786. LOGD(" ButtonClick CallBedButton !!!\n");
  787. if (frameBedList.size() > 0) {
  788. mCallBebWinPtr->showWnd();
  789. } else {
  790. Intent* intent = new Intent();
  791. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedList"));
  792. EASYUICONTEXT->openActivity("warnActivity", intent);
  793. }
  794. return false;
  795. }
  796. static bool onButtonClick_CallNurseButton(ZKButton *pButton) {
  797. LOGD(" ButtonClick CallNurseButton !!!\n");
  798. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  799. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  800. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  801. std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  802. std::string od_number_uri = URI(od_number, domain, port);
  803. LOGD("od_number_uri: %s", od_number_uri.c_str());
  804. GetTelephone()->MakeCall(od_number_uri);
  805. } else {
  806. Intent* intent = new Intent();
  807. intent->putExtra(isOutgoing, "true");
  808. intent->putExtra(audioOnly, "true");
  809. EASYUICONTEXT->openActivity("callActivity", intent);
  810. }
  811. return false;
  812. }
  813. static bool onButtonClick_HelpButton(ZKButton *pButton) {
  814. LOGD(" ButtonClick HelpButton !!!\n");
  815. TcpModel tcpModel;
  816. tcpModel.type = TcpType::REINFORCE;
  817. tcpModel.action = ReinforceAction::CALL;
  818. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  819. tcpModel.to_id = 0;
  820. std::string req = getTcpModelString(tcpModel);
  821. LOGD("REINFORCE CALL : %s",req.c_str());
  822. // TcpClient::instance()->sendMsg(req.c_str());
  823. //回调注册
  824. TcpCallback callback;
  825. callback.tid = tcpModel.tid;
  826. callback.jsonStr = req;
  827. callback.onSuccess = [](Json::Value json){
  828. LOGD("callback success");
  829. return 0;
  830. };
  831. callback.onFalied = [](Json::Value json){
  832. LOGD("callback failed");
  833. return 0;
  834. };
  835. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  836. // setHelpButton("/button/button_help3.png" ,false);
  837. // SetPainterInfo(0xFF2F9DF1, "增援已发出");
  838. // setReinforce(true); // 设置增援状态为true
  839. // //1分钟后无响应还原颜色
  840. // if (!isHelpTimerRegistered){
  841. // mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 60000);
  842. // }
  843. setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF2F9DF1, LANGUAGEMANAGER->getValue("HelpInfo"), "REINFORCE", "ADD", 60);
  844. return false;
  845. }
  846. static bool onButtonClick_CallCencelButton(ZKButton *pButton) {
  847. LOGD(" ButtonClick CallCencelButton !!!\n");
  848. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  849. TcpModel tcpModel;
  850. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  851. tcpModel.type = TcpType::VOICE;
  852. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  853. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  854. tcpModel.to_id = NULL;
  855. std::string req = getTcpModelString(tcpModel);
  856. LOGD("TCP VOICE : %s",req.c_str());
  857. cencalByDoorTid = tcpModel.tid;
  858. //回调注册
  859. TcpCallback callback;
  860. callback.tid = tcpModel.tid;
  861. callback.jsonStr = req;
  862. callback.onSuccess = [](Json::Value json){
  863. LOGD("side callback success");
  864. return 0;
  865. };
  866. callback.onFalied = [](Json::Value json){
  867. LOGD("side callback failed");
  868. return 0;
  869. };
  870. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  871. return false;
  872. }
  873. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  874. LOGD(" ButtonClick NursingButton !!!\n");
  875. // std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  876. // std::string heartStr;
  877. // if (color != "" && color.size() == 3) {
  878. // heartStr = "DOORLED," + color + "F";
  879. // } else {
  880. // heartStr = "DOORLED,010F";
  881. // }
  882. // const char* sendMsg = heartStr.c_str();
  883. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  884. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  885. if (color != "" && color.size() == 3) {
  886. color = color + "F";
  887. } else {
  888. color = "010F";
  889. }
  890. lightControl("DOORLED", color);
  891. mFunctionWinPtr->showWnd();
  892. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  893. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  894. mFunctionBackPtr->setVisible(false);
  895. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  896. TcpModel tcpModel;
  897. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  898. tcpModel.type = TcpType::SIDE;
  899. tcpModel.action = SideAction::NURSING;
  900. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  901. tcpModel.to_id = NULL;
  902. std::string req = getTcpModelString(tcpModel);
  903. LOGD("TCP SIDE : %s",req.c_str());
  904. //回调注册
  905. TcpCallback callback;
  906. callback.tid = tcpModel.tid;
  907. callback.jsonStr = req;
  908. callback.onSuccess = [](Json::Value json){
  909. LOGD("side callback success");
  910. return 0;
  911. };
  912. callback.onFalied = [](Json::Value json){
  913. LOGD("side callback failed");
  914. return 0;
  915. };
  916. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  917. // 把护理状态缓存起来
  918. StoragePreferences::putBool(STORE_NURSING_TYPE, true);
  919. return false;
  920. }
  921. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  922. LOGD(" ButtonClick MoreButton !!!\n");
  923. EASYUICONTEXT->openActivity("ui3Activity");
  924. return false;
  925. }
  926. static bool onButtonClick_FunctionButton(ZKButton *pButton) {
  927. LOGD(" ButtonClick FunctionButton !!!\n");
  928. mFunctionWinPtr->hideWnd();
  929. sendNursingEnd();
  930. return false;
  931. }
  932. static bool onButtonClick_FunctionBack(ZKButton *pButton) {
  933. LOGD(" ButtonClick FunctionBack !!!\n");
  934. return false;
  935. }
  936. static int getListItemCount_CallBedListView(const ZKListView *pListView) {
  937. //LOGD("getListItemCount_CallBedListView !\n");
  938. return frameBedList.size();
  939. }
  940. static void obtainListItemData_CallBedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  941. //LOGD(" obtainListItemData_ CallBedListView !!!\n");
  942. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  943. pListItem->findSubItemByID(ID_MAIN_CallBedName)->setText(frameBedList[index]["customer_name"].asString());
  944. }
  945. static void onListItemClick_CallBedListView(ZKListView *pListView, int index, int id) {
  946. // LOGD(" onListItemClick_ CallBedListView !!!\n");
  947. string customerName = frameBedList[index]["customer_name"].asString();
  948. string toId = frameBedList[index]["bed_device_id"].asString();
  949. if (customerName == "") {
  950. Intent* intent = new Intent();
  951. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoCustomer"));
  952. EASYUICONTEXT->openActivity("warnActivity", intent);
  953. }
  954. else if (toId == "") {
  955. Intent* intent = new Intent();
  956. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedDevice"));
  957. EASYUICONTEXT->openActivity("warnActivity", intent);
  958. }
  959. else {
  960. mCallBebWinPtr->hideWnd();
  961. Intent* intent = new Intent();
  962. intent->putExtra(isOutgoing, "true");
  963. intent->putExtra(audioOnly, "true");
  964. intent->putExtra(toIdStr, toId);
  965. intent->putExtra(callName, frameBedList[index]["frame_bed"]["full_name"].asString() + " " + customerName);
  966. EASYUICONTEXT->openActivity("callActivity", intent);
  967. }
  968. }
  969. static bool onButtonClick_CallBedCancel(ZKButton *pButton) {
  970. LOGD(" ButtonClick CallBedCancel !!!\n");
  971. mCallBebWinPtr->hideWnd();
  972. return false;
  973. }