mainLogic.cc 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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 (ETHERNETMANAGER->isConnected()) {
  515. if(serverInfo) { // 如果是false,就是不需要
  516. udp_thread.getServerInfo();
  517. }
  518. udp_thread.getDeviceInfo();
  519. }
  520. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) { // 如果处于护理状态
  521. mFunctionWinPtr->showWnd();
  522. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  523. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  524. mFunctionBackPtr->setVisible(false);
  525. } else {
  526. mFunctionWinPtr->hideWnd();
  527. }
  528. }
  529. /**
  530. * 当切换到该界面时触发
  531. */
  532. static void onUI_intent(const Intent *intentPtr) {
  533. if (intentPtr != NULL) {
  534. }
  535. }
  536. /*
  537. * 当界面显示时触发
  538. */
  539. static void onUI_show() {
  540. }
  541. /*
  542. * 当界面隐藏时触发
  543. */
  544. static void onUI_hide() {
  545. }
  546. /*
  547. * 当界面完全退出时触发
  548. */
  549. static void onUI_quit() {
  550. //pthread_exit(NULL);
  551. }
  552. /**
  553. * 串口数据回调接口
  554. */
  555. static void onProtocolDataUpdate(const SProtocolData &data) {
  556. }
  557. /**
  558. * 定时器触发函数
  559. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  560. * 参数: id
  561. * 当前所触发定时器的id,与注册时的id相同
  562. * 返回值: true
  563. * 继续运行当前定时器
  564. * false
  565. * 停止运行当前定时器
  566. */
  567. static bool onUI_Timer(int id){
  568. switch (id) {
  569. case HELP_TIMER_HANDLE: // 不能在线程里面关掉线程
  570. {
  571. // SetPainterInfo(0xFFFFFFFF, "");
  572. // setReinforce(false);
  573. // setHelpButton("/button/button_help2.png", true);
  574. // return false;
  575. if (painterInfoList.size() > 0) { // painterInfoList代表里面存在内容
  576. // 取出排列最后的一项,判断列表是否超时,没有超时就将内容填充到里面
  577. Json::Value _painterInfo;
  578. _painterInfo = painterInfoList.get(painterInfoList.size() - 1, &painterInfo);
  579. int nowTime = getNowTime();
  580. if (nowTime >= _painterInfo["endTime"].asInt()) {
  581. if (_painterInfo["type"] == "REINFORCE") {
  582. setReinforce(false);
  583. setHelpButton("/button/button_help2.png", true);
  584. }
  585. painterInfoList.removeIndex(painterInfoList.size() - 1, &painterInfo);
  586. } else {
  587. mPainterInfoPtr->setBackgroundColor( _painterInfo["bgColor"].asUInt());
  588. mTextInfoPtr->setText(_painterInfo["msg"].asCString());
  589. if (_painterInfo["bgColor"] == 0xFFFFFFFF){
  590. mRoomNamePtr->setTextColor(0x00AAF4);
  591. } else {
  592. mRoomNamePtr->setTextColor(0xFFFFFF);
  593. }
  594. }
  595. } else {
  596. mPainterInfoPtr->setBackgroundColor(0xFFFFFFFF);
  597. mTextInfoPtr->setText("");
  598. mRoomNamePtr->setTextColor(0x00AAF4);
  599. setReinforce(false);
  600. setHelpButton("/button/button_help2.png", true);
  601. return false;
  602. }
  603. }
  604. break;
  605. default:
  606. break;
  607. }
  608. return true;
  609. }
  610. /**
  611. * 有新的触摸事件时触发
  612. * 参数:ev
  613. * 新的触摸事件
  614. * 返回值:true
  615. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  616. * false
  617. * 触摸事件将继续传递到控件上
  618. */
  619. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  620. switch (ev.mActionStatus) {
  621. case MotionEvent::E_ACTION_DOWN://触摸按下
  622. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  623. break;
  624. case MotionEvent::E_ACTION_MOVE://触摸滑动
  625. break;
  626. case MotionEvent::E_ACTION_UP: //触摸抬起
  627. break;
  628. default:
  629. break;
  630. }
  631. return false;
  632. }
  633. static int getListItemCount_BedListView(const ZKListView *pListView) {
  634. //LOGD("getListItemCount_BedListView !\n");
  635. if (frameBedList.size() > 3) {
  636. return frameBedList.size();
  637. }
  638. return 3;
  639. }
  640. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  641. //LOGD(" obtainListItemData_ BedListView !!!\n");
  642. if (frameBedList.size() > 0) {
  643. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  644. // 用户相关
  645. string customerName = frameBedList[index]["customer_name"].asString();
  646. pListItem->findSubItemByID(ID_MAIN_CustomerName)->setText(customerName);
  647. pListItem->findSubItemByID(ID_MAIN_CustomerAge)->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  648. string customerSex = frameBedList[index]["customer_sex"].asString();
  649. if (customerSex == "0") { // 如果性别为女性,则替换成女性头像,和女性的图标
  650. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_female.png");
  651. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_female.png");
  652. }
  653. else if (customerSex == "1") {
  654. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_male.png");
  655. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_male.png");
  656. }
  657. else {
  658. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_empty.png");
  659. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("");
  660. }
  661. // 医生护士相关
  662. if (rightTitleInfo["doctor_valid"] != 1){
  663. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setVisible(false);
  664. } else {
  665. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setText(rightTitleInfo["doctor_title"].asString());
  666. }
  667. if (rightTitleInfo["nurse_valid"] != 1){
  668. pListItem->findSubItemByID(ID_MAIN_NurseText)->setVisible(false);
  669. } else {
  670. pListItem->findSubItemByID(ID_MAIN_NurseText)->setText(rightTitleInfo["nurse_title"].asString());
  671. }
  672. pListItem->findSubItemByID(ID_MAIN_DoctorName)->setText(frameBedList[index]["doctor_name"].asString());
  673. pListItem->findSubItemByID(ID_MAIN_NurseName)->setText(frameBedList[index]["nurse_name"].asString());
  674. // 护理项相关
  675. Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  676. if (nurseConfigList.size() > 0) {
  677. for (int i = 0; i < 5; i++) {
  678. int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  679. int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  680. int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  681. if (nurseConfigList.size() >= i) {
  682. //颜色
  683. string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  684. uint32_t bgColor = 0xFFC0C0C0;
  685. if (nurseConfigColot != "") {
  686. string rgbStr = "FF" + nurseConfigColot;
  687. transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  688. bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  689. }
  690. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  691. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  692. string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  693. if (nurseOptionName == "") {
  694. nurseOptionName = LANGUAGEMANAGER->getValue("None");
  695. }
  696. pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  697. } else {
  698. //颜色
  699. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  700. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  701. pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  702. }
  703. }
  704. }
  705. else {
  706. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  707. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  708. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  709. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  710. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  711. pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  712. pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  713. pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  714. pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  715. pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  716. pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  717. pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  718. pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  719. pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  720. pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  721. }
  722. }
  723. }
  724. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  725. //LOGD(" onListItemClick_ BedListView !!!\n");
  726. }
  727. static bool onButtonClick_CallBedButton(ZKButton *pButton) {
  728. LOGD(" ButtonClick CallBedButton !!!\n");
  729. if (frameBedList.size() > 0) {
  730. mCallBebWinPtr->showWnd();
  731. } else {
  732. Intent* intent = new Intent();
  733. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedList"));
  734. EASYUICONTEXT->openActivity("warnActivity", intent);
  735. }
  736. return false;
  737. }
  738. static bool onButtonClick_CallNurseButton(ZKButton *pButton) {
  739. LOGD(" ButtonClick CallNurseButton !!!\n");
  740. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  741. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  742. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  743. std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  744. std::string od_number_uri = URI(od_number, domain, port);
  745. LOGD("od_number_uri: %s", od_number_uri.c_str());
  746. GetTelephone()->MakeCall(od_number_uri);
  747. } else {
  748. Intent* intent = new Intent();
  749. intent->putExtra(isOutgoing, "true");
  750. intent->putExtra(audioOnly, "true");
  751. EASYUICONTEXT->openActivity("callActivity", intent);
  752. }
  753. return false;
  754. }
  755. static bool onButtonClick_HelpButton(ZKButton *pButton) {
  756. LOGD(" ButtonClick HelpButton !!!\n");
  757. TcpModel tcpModel;
  758. tcpModel.type = TcpType::REINFORCE;
  759. tcpModel.action = ReinforceAction::CALL;
  760. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  761. tcpModel.to_id = 0;
  762. std::string req = getTcpModelString(tcpModel);
  763. LOGD("REINFORCE CALL : %s",req.c_str());
  764. // TcpClient::instance()->sendMsg(req.c_str());
  765. //回调注册
  766. TcpCallback callback;
  767. callback.tid = tcpModel.tid;
  768. callback.jsonStr = req;
  769. callback.onSuccess = [](Json::Value json){
  770. LOGD("callback success");
  771. return 0;
  772. };
  773. callback.onFalied = [](Json::Value json){
  774. LOGD("callback failed");
  775. return 0;
  776. };
  777. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  778. // setHelpButton("/button/button_help3.png" ,false);
  779. // SetPainterInfo(0xFF2F9DF1, "增援已发出");
  780. // setReinforce(true); // 设置增援状态为true
  781. // //1分钟后无响应还原颜色
  782. // if (!isHelpTimerRegistered){
  783. // mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 60000);
  784. // }
  785. setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF2F9DF1, LANGUAGEMANAGER->getValue("HelpInfo"), "REINFORCE", "ADD", 60);
  786. return false;
  787. }
  788. static bool onButtonClick_CallCencelButton(ZKButton *pButton) {
  789. LOGD(" ButtonClick CallCencelButton !!!\n");
  790. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  791. TcpModel tcpModel;
  792. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  793. tcpModel.type = TcpType::VOICE;
  794. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  795. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  796. tcpModel.to_id = NULL;
  797. std::string req = getTcpModelString(tcpModel);
  798. LOGD("TCP VOICE : %s",req.c_str());
  799. cencalByDoorTid = tcpModel.tid;
  800. //回调注册
  801. TcpCallback callback;
  802. callback.tid = tcpModel.tid;
  803. callback.jsonStr = req;
  804. callback.onSuccess = [](Json::Value json){
  805. LOGD("side callback success");
  806. return 0;
  807. };
  808. callback.onFalied = [](Json::Value json){
  809. LOGD("side callback failed");
  810. return 0;
  811. };
  812. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  813. return false;
  814. }
  815. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  816. LOGD(" ButtonClick NursingButton !!!\n");
  817. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  818. std::string heartStr;
  819. if (color != "" && color.size() == 3) {
  820. heartStr = "DOORLED," + color + "F";
  821. } else {
  822. heartStr = "DOORLED,010F";
  823. }
  824. const char* sendMsg = heartStr.c_str();
  825. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  826. mFunctionWinPtr->showWnd();
  827. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  828. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  829. mFunctionBackPtr->setVisible(false);
  830. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  831. TcpModel tcpModel;
  832. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  833. tcpModel.type = TcpType::SIDE;
  834. tcpModel.action = SideAction::NURSING;
  835. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  836. tcpModel.to_id = NULL;
  837. std::string req = getTcpModelString(tcpModel);
  838. LOGD("TCP SIDE : %s",req.c_str());
  839. //回调注册
  840. TcpCallback callback;
  841. callback.tid = tcpModel.tid;
  842. callback.jsonStr = req;
  843. callback.onSuccess = [](Json::Value json){
  844. LOGD("side callback success");
  845. return 0;
  846. };
  847. callback.onFalied = [](Json::Value json){
  848. LOGD("side callback failed");
  849. return 0;
  850. };
  851. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  852. // 把护理状态缓存起来
  853. StoragePreferences::putBool(STORE_NURSING_TYPE, true);
  854. return false;
  855. }
  856. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  857. LOGD(" ButtonClick MoreButton !!!\n");
  858. EASYUICONTEXT->openActivity("ui3Activity");
  859. return false;
  860. }
  861. static bool onButtonClick_FunctionButton(ZKButton *pButton) {
  862. LOGD(" ButtonClick FunctionButton !!!\n");
  863. mFunctionWinPtr->hideWnd();
  864. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  865. std::string heartStr = "DOORLED,000F";
  866. const char* sendMsg = heartStr.c_str();
  867. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  868. if (nursingTcpModel.json.size() != 0) { // 对比一下,json里面不为空的时候
  869. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING_END
  870. TcpModel tcpModel;
  871. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  872. tcpModel.type = TcpType::SIDE;
  873. tcpModel.action = SideAction::NURSING_END;
  874. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  875. tcpModel.data = nursingTcpModel.json["id"].asString(); // 获取nursingTcpModel里,id字段的数据
  876. std::string req = getTcpModelString(tcpModel);
  877. LOGD("TCP NURSING_END : %s",req.c_str());
  878. //回调注册
  879. TcpCallback callback;
  880. callback.tid = tcpModel.tid;
  881. callback.jsonStr = req;
  882. callback.onSuccess = [](Json::Value json){
  883. LOGD("event callback success");
  884. return 0;
  885. };
  886. callback.onFalied = [](Json::Value json){
  887. LOGD("event callback failed");
  888. return 0;
  889. };
  890. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  891. TcpModel newTcpModel;
  892. nursingTcpModel = newTcpModel; // 清空nursingTcpModel
  893. }
  894. return false;
  895. }
  896. static bool onButtonClick_FunctionBack(ZKButton *pButton) {
  897. LOGD(" ButtonClick FunctionBack !!!\n");
  898. return false;
  899. }
  900. static int getListItemCount_CallBedListView(const ZKListView *pListView) {
  901. //LOGD("getListItemCount_CallBedListView !\n");
  902. return frameBedList.size();
  903. }
  904. static void obtainListItemData_CallBedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  905. //LOGD(" obtainListItemData_ CallBedListView !!!\n");
  906. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  907. pListItem->findSubItemByID(ID_MAIN_CallBedName)->setText(frameBedList[index]["customer_name"].asString());
  908. }
  909. static void onListItemClick_CallBedListView(ZKListView *pListView, int index, int id) {
  910. // LOGD(" onListItemClick_ CallBedListView !!!\n");
  911. string customerName = frameBedList[index]["customer_name"].asString();
  912. string toId = frameBedList[index]["bed_device_id"].asString();
  913. if (customerName == "") {
  914. Intent* intent = new Intent();
  915. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoCustomer"));
  916. EASYUICONTEXT->openActivity("warnActivity", intent);
  917. }
  918. else if (toId == "") {
  919. Intent* intent = new Intent();
  920. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedDevice"));
  921. EASYUICONTEXT->openActivity("warnActivity", intent);
  922. }
  923. else {
  924. mCallBebWinPtr->hideWnd();
  925. Intent* intent = new Intent();
  926. intent->putExtra(isOutgoing, "true");
  927. intent->putExtra(audioOnly, "true");
  928. intent->putExtra(toIdStr, toId);
  929. intent->putExtra(callName, frameBedList[index]["frame_bed"]["full_name"].asString() + " " + customerName);
  930. EASYUICONTEXT->openActivity("callActivity", intent);
  931. }
  932. }
  933. static bool onButtonClick_CallBedCancel(ZKButton *pButton) {
  934. LOGD(" ButtonClick CallBedCancel !!!\n");
  935. mCallBebWinPtr->hideWnd();
  936. return false;
  937. }