mainLogic.cc 40 KB

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