mainLogic.cc 39 KB

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