mainLogic.cc 42 KB

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