mainLogic.cc 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  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. static bool reinforce = false; // 判断设备是否处于增援状态
  58. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  59. static bool isHelpTimerRegistered = false;
  60. #define HELP_TIMER_HANDLE 3
  61. #define NURSING_TIME_HANDLE 6 // 护理的定时器id
  62. #define OXYGEN_TIME_HANDLE 7 // 吸氧倒计时
  63. #define EVENT_TIME_HANDLE 8 // 事件定时器
  64. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  65. //======================================= udp 请示服务器信息
  66. static net::Conn* udpConn;
  67. class UdpThread: public Thread {
  68. public:
  69. static void getServerInfo(){
  70. string url = getHttpGateway() + "/ncs_url/server_info";
  71. LOGD("请求服务器信息. url = %s", url.c_str());
  72. //发起HTTP GET请求
  73. RestClient::Response r = RestClient::get(url);
  74. //解析json
  75. Json::Reader reader;
  76. Json::Value root;
  77. if (reader.parse(r.body, root, false)){
  78. // http
  79. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  80. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  81. // tcp
  82. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  83. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  84. // sip
  85. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  86. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  87. serverInfo = false; // 只有请求成功了,才不需要重复请求
  88. }
  89. }
  90. static void getDeviceInfo(){
  91. if (dataInit){
  92. getFrameInfo();
  93. //getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  94. reinforceDispaly();
  95. return;
  96. }
  97. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + ETHERNETMANAGER->getMacAddr();
  98. LOGD("请求设备信息. url = %s", url.c_str());
  99. //发起HTTP GET请求
  100. RestClient::Response r = RestClient::get(url);
  101. LOGD("获得设备信息. result = %s", r.body.c_str());
  102. //解析json
  103. Json::Reader reader;
  104. Json::Value root;
  105. if (reader.parse(r.body, root, false)){
  106. string partName = root["part_display"].asString();
  107. StoragePreferences::putString(STORE_PARTNAME,partName);
  108. NavibarSetPartName(partName);
  109. //设备
  110. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  111. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  112. //SIP存储
  113. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  114. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  115. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  116. //获取科室设置
  117. string partId = root["part_id"].asString();
  118. StoragePreferences::putString(STORE_PARTID, partId);
  119. getPartSetting(partId);
  120. getVersion();
  121. setFrameInfo(root);
  122. }
  123. }
  124. // 将空间相关的数据缓存起来
  125. static void setFrameInfo(Json::Value deviceInfo) {
  126. frameInfo["frame_id"] = deviceInfo["frame_id"].asInt();
  127. frameInfo["full_name"] = deviceInfo["full_name"].asString();
  128. frameInfo["part_id"] = deviceInfo["part_id"].asInt();
  129. getFrameInfo();
  130. getFrameRoom(deviceInfo["frame_id"].asInt());
  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. }
  149. }
  150. static void getPartSetting(string partId){
  151. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  152. LOGD("请求科室信息. url = %s", url.c_str());
  153. //发起HTTP GET请求
  154. RestClient::Response r = RestClient::get(url);
  155. LOGD("获得科室信息. result = %s", r.body.c_str());
  156. //解析json
  157. Json::Reader reader;
  158. Json::Value root;
  159. if (reader.parse(r.body, root, false)){
  160. partSetting.partId = root["part_id"].asInt();
  161. partSetting.dayStart = root["day_start"].asString();
  162. partSetting.dayLight = root["day_light"].asInt();
  163. partSetting.dayVol = root["day_vol"].asInt();
  164. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  165. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  166. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  167. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  168. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  169. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  170. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  171. partSetting.nightStart = root["night_start"].asString();
  172. partSetting.nightLight = root["night_light"].asInt();
  173. partSetting.nightVol = root["night_vol"].asInt();
  174. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  175. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  176. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  177. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  178. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  179. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  180. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  181. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  182. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  183. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  184. partSetting.sipOvertime = root["sip_overtime"].asInt();
  185. partSetting.transferDuration = root["transfer_duration"].asInt();
  186. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  187. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  188. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  189. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  190. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  191. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  192. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  193. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  194. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  195. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  196. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  197. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  198. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  199. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  200. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  201. partSetting.doctorTitle = root["doctor_title"].asString();
  202. partSetting.doctorValid = root["doctor_valid"].asInt();
  203. partSetting.nurseTitle = root["nurse_title"].asString();
  204. partSetting.nurseValid = root["nurse_valid"].asInt();
  205. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  206. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  207. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  208. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  209. partSetting.upSeconds = root["up_seconds"].asInt();
  210. partSetting.autoAccept = root["auto_accept"].asInt();
  211. partSetting.eventForward = root["event_forward"].asInt();
  212. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  213. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  214. partSetting.qrUrl = root["qr_url"].asString();
  215. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  216. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  217. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  218. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  219. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  220. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  221. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  222. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  223. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsBed);
  224. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  225. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  226. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  227. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  228. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  229. setRightTitle(root);
  230. dataInit = true;
  231. }
  232. }
  233. // 将医生和护士别称缓存起来
  234. static void setRightTitle(Json::Value partSetting) {
  235. rightTitleInfo["doctor_title"] = partSetting["doctor_title"].asString();
  236. rightTitleInfo["doctor_valid"] = partSetting["doctor_valid"].asInt();
  237. rightTitleInfo["nurse_title"] = partSetting["nurse_title"].asString();
  238. rightTitleInfo["nurse_valid"] = partSetting["nurse_valid"].asInt();
  239. }
  240. static void getVersion() {
  241. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  242. std::string content_type = std::string("application/json");
  243. LOGD("请求版本信息. url = %s", url.c_str());
  244. //发起HTTP POST请求
  245. RestClient::Response r = RestClient::post(url, content_type, "");
  246. if (r.code != 200) {
  247. LOGD("请求版本信息-> 错误代码: %d", r.code);
  248. return;
  249. }
  250. LOGD("获得版本信息. result = %s", r.body.c_str());
  251. //解析json
  252. Json::Reader reader;
  253. Json::Value root;
  254. if(reader.parse(r.body, root, false)) {
  255. int currentVersionNo = getVersionNo();
  256. int responseVersionNo = root["version_no"].asInt();
  257. std::string responseVersion = root["version_code"].asString();
  258. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  259. if (currentVersionNo < responseVersionNo) {
  260. Intent* intent = new Intent();
  261. intent->putExtra(appUpdate, "true");
  262. EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent);
  263. }
  264. }
  265. }
  266. // 判断是否处于增援状态,处于增援状态,就要显示蓝色
  267. static void reinforceDispaly() {
  268. if (reinforce) {
  269. SetPainterInfo(0xFF2F9DF1,"增援已发出");
  270. setHelpButton("/button/button_help3.png" ,false);
  271. }
  272. }
  273. /**
  274. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  275. * return true 继续线程
  276. * false 退出线程
  277. */
  278. virtual bool readyToRun() {
  279. LOGD("Thread 已经创建完成");
  280. return true;
  281. }
  282. /**
  283. * 线程循环函数
  284. *
  285. * return true 继续线程循环
  286. * false 推出线程
  287. */
  288. virtual bool threadLoop() {
  289. LOGD("线程循环函数");
  290. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  291. if (exitPending()) {
  292. return false;
  293. }
  294. udpConn = net::Dial("udp", "192.168.1.255:10010");
  295. if (udpConn) {
  296. byte buf[1024] = {0};
  297. const char* req = "search_server";
  298. //发送
  299. udpConn->Write((byte*)req, strlen(req));
  300. while (true && !exitPending()) {
  301. //读取,超时10*1000毫秒
  302. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  303. if (n > 0) {
  304. buf[n] = 0;
  305. char serverStr[1024];
  306. sprintf(serverStr,"%s",buf);
  307. LOGD("读取 %d字节: %s", n, serverStr);
  308. //解析json
  309. Json::Reader reader;
  310. Json::Value root;
  311. if (reader.parse(serverStr, root, false)){
  312. if (root.isMember("success") && root["success"].asBool()){
  313. serverIP = root["data"]["third_server"].asString();
  314. serverHttpPort = root["data"]["third_server_port"].asInt();
  315. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  316. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  317. //先获取服务器信息
  318. //getServerInfo();
  319. //就当在获取服务器信息完成后获取用户信息,这里测试用
  320. //getCustomerInfo();
  321. //退出UDP线程
  322. pthread_exit(NULL);
  323. break;
  324. }
  325. }
  326. } else if (n == 0) {
  327. LOGD("连接正常断开");
  328. break;
  329. } else if (n == net::E_TIMEOUT) {
  330. udpConn->Write((byte*)req, strlen(req));
  331. LOGD("读取超时");
  332. } else {
  333. LOGD("出错");
  334. break;
  335. }
  336. }
  337. //关闭连接
  338. udpConn->Close();
  339. //释放内存
  340. delete udpConn;
  341. udpConn = NULL;
  342. }
  343. //返回真,继续下次线程循环
  344. return true;
  345. }
  346. };
  347. static UdpThread udp_thread;
  348. void setReinforce(bool result) {
  349. reinforce = result;
  350. }
  351. void cancelAutoBtnHelpTimer(){
  352. if (isHelpTimerRegistered) {
  353. mActivityPtr->unregisterUserTimer(HELP_TIMER_HANDLE);
  354. isHelpTimerRegistered = false;
  355. }
  356. }
  357. //标识方法
  358. void SetPainterInfo(uint32_t bgColor, const std::string& msg){
  359. mPainterInfoPtr->setBackgroundColor(bgColor);
  360. mTextInfoPtr->setText(msg);
  361. if (bgColor == 0xFFFFFFFF){
  362. mRoomNamePtr->setTextColor(0x00AAF4);
  363. } else {
  364. mRoomNamePtr->setTextColor(0xFFFFFF);
  365. }
  366. }
  367. // 收到tcp的时候,刷新数据
  368. void dataRefresh() {
  369. LOGD("DATA-REFRESH, 数据刷新");
  370. dataInit = false;
  371. udp_thread.getDeviceInfo();
  372. }
  373. void getPartSetting() {
  374. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  375. }
  376. // 处理护理的tcpModel
  377. void setNursingTcpModel(TcpModel tcpModel) {
  378. LOGD("缓存Nursing的tcpModel !!!");
  379. nursingTcpModel = tcpModel;
  380. }
  381. void setHelpButton(const char *pPicPath, bool isTouchable){
  382. mHelpButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, pPicPath);
  383. mHelpButtonPtr->setTouchable(isTouchable);
  384. }
  385. /**
  386. * 注册定时器
  387. * 填充数组用于注册定时器
  388. * 注意:id不能重复
  389. */
  390. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  391. //{0, 6000}, //定时器id=0, 时间间隔6秒
  392. //{1, 1000},
  393. };
  394. /**
  395. * 当界面构造时触发
  396. */
  397. static void onUI_init(){
  398. //udp_thread.run("this is thread name");
  399. //测试用
  400. LOGD("进入mainLogic页面, 触发 onUI_init");
  401. if(serverInfo) { // 如果是false,就是不需要
  402. udp_thread.getServerInfo();
  403. }
  404. udp_thread.getDeviceInfo();
  405. }
  406. /**
  407. * 当切换到该界面时触发
  408. */
  409. static void onUI_intent(const Intent *intentPtr) {
  410. if (intentPtr != NULL) {
  411. }
  412. }
  413. /*
  414. * 当界面显示时触发
  415. */
  416. static void onUI_show() {
  417. }
  418. /*
  419. * 当界面隐藏时触发
  420. */
  421. static void onUI_hide() {
  422. }
  423. /*
  424. * 当界面完全退出时触发
  425. */
  426. static void onUI_quit() {
  427. //pthread_exit(NULL);
  428. }
  429. /**
  430. * 串口数据回调接口
  431. */
  432. static void onProtocolDataUpdate(const SProtocolData &data) {
  433. }
  434. /**
  435. * 定时器触发函数
  436. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  437. * 参数: id
  438. * 当前所触发定时器的id,与注册时的id相同
  439. * 返回值: true
  440. * 继续运行当前定时器
  441. * false
  442. * 停止运行当前定时器
  443. */
  444. static bool onUI_Timer(int id){
  445. switch (id) {
  446. case HELP_TIMER_HANDLE: // 不能在线程里面关掉线程
  447. {
  448. SetPainterInfo(0xFFFFFFFF,"");
  449. setReinforce(false);
  450. setHelpButton("/button/button_help2.png", true);
  451. return false;
  452. }
  453. break;
  454. default:
  455. break;
  456. }
  457. return true;
  458. }
  459. /**
  460. * 有新的触摸事件时触发
  461. * 参数:ev
  462. * 新的触摸事件
  463. * 返回值:true
  464. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  465. * false
  466. * 触摸事件将继续传递到控件上
  467. */
  468. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  469. switch (ev.mActionStatus) {
  470. case MotionEvent::E_ACTION_DOWN://触摸按下
  471. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  472. break;
  473. case MotionEvent::E_ACTION_MOVE://触摸滑动
  474. break;
  475. case MotionEvent::E_ACTION_UP: //触摸抬起
  476. break;
  477. default:
  478. break;
  479. }
  480. return false;
  481. }
  482. static int getListItemCount_BedListView(const ZKListView *pListView) {
  483. //LOGD("getListItemCount_BedListView !\n");
  484. if (frameBedList.size() > 3) {
  485. return frameBedList.size();
  486. }
  487. return 3;
  488. }
  489. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  490. //LOGD(" obtainListItemData_ BedListView !!!\n");
  491. if (frameBedList.size() > 0) {
  492. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  493. // 用户相关
  494. string customerName = frameBedList[index]["customer_name"].asString();
  495. pListItem->findSubItemByID(ID_MAIN_CustomerName)->setText(customerName);
  496. pListItem->findSubItemByID(ID_MAIN_CustomerAge)->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  497. string customerSex = frameBedList[index]["customer_sex"].asString();
  498. if (customerSex == "0") { // 如果性别为女性,则替换成女性头像,和女性的图标
  499. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_female.png");
  500. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_female.png");
  501. }
  502. else if (customerSex == "1") {
  503. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_male.png");
  504. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_male.png");
  505. }
  506. else {
  507. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_empty.png");
  508. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("");
  509. }
  510. // 医生护士相关
  511. if (rightTitleInfo["doctor_valid"] != 1){
  512. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setVisible(false);
  513. } else {
  514. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setText(rightTitleInfo["doctor_title"].asString());
  515. }
  516. if (rightTitleInfo["nurse_valid"] != 1){
  517. pListItem->findSubItemByID(ID_MAIN_NurseText)->setVisible(false);
  518. } else {
  519. pListItem->findSubItemByID(ID_MAIN_NurseText)->setText(rightTitleInfo["nurse_title"].asString());
  520. }
  521. pListItem->findSubItemByID(ID_MAIN_DoctorName)->setText(frameBedList[index]["doctor_name"].asString());
  522. pListItem->findSubItemByID(ID_MAIN_NurseName)->setText(frameBedList[index]["nurse_name"].asString());
  523. // 护理项相关
  524. Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  525. if (nurseConfigList.size() > 0) {
  526. for (int i = 0; i < 5; i++) {
  527. int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  528. int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  529. int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  530. if (nurseConfigList.size() >= i) {
  531. //颜色
  532. string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  533. uint32_t bgColor = 0xFFC0C0C0;
  534. if (nurseConfigColot != "") {
  535. string rgbStr = "FF" + nurseConfigColot;
  536. transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  537. bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  538. }
  539. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  540. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  541. string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  542. if (nurseOptionName == "") {
  543. nurseOptionName = LANGUAGEMANAGER->getValue("None");
  544. }
  545. pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  546. } else {
  547. //颜色
  548. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  549. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  550. pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  551. }
  552. }
  553. }
  554. else {
  555. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  556. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  557. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  558. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  559. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  560. pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  561. pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  562. pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  563. pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  564. pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  565. pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  566. pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  567. pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  568. pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  569. pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  570. }
  571. }
  572. }
  573. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  574. //LOGD(" onListItemClick_ BedListView !!!\n");
  575. }
  576. static bool onButtonClick_CallBedButton(ZKButton *pButton) {
  577. LOGD(" ButtonClick CallBedButton !!!\n");
  578. if (frameBedList.size() > 0) {
  579. mCallBebWinPtr->showWnd();
  580. } else {
  581. Intent* intent = new Intent();
  582. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedList"));
  583. EASYUICONTEXT->openActivity("warnActivity", intent);
  584. }
  585. return false;
  586. }
  587. static bool onButtonClick_CallNurseButton(ZKButton *pButton) {
  588. LOGD(" ButtonClick CallNurseButton !!!\n");
  589. if (SIGNAL_TYPE=="SIP"){
  590. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  591. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  592. std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  593. std::string od_number_uri = URI(od_number, domain, port);
  594. LOGD("od_number_uri: %s", od_number_uri.c_str());
  595. GetTelephone()->MakeCall(od_number_uri);
  596. } else {
  597. Intent* intent = new Intent();
  598. intent->putExtra(isOutgoing, "true");
  599. intent->putExtra(audioOnly, "true");
  600. EASYUICONTEXT->openActivity("callActivity", intent);
  601. }
  602. return false;
  603. }
  604. static bool onButtonClick_HelpButton(ZKButton *pButton) {
  605. LOGD(" ButtonClick HelpButton !!!\n");
  606. TcpModel tcpModel;
  607. tcpModel.type = TcpType::REINFORCE;
  608. tcpModel.action = ReinforceAction::CALL;
  609. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  610. tcpModel.to_id = 0;
  611. std::string req = getTcpModelString(tcpModel);
  612. LOGD("REINFORCE CALL : %s",req.c_str());
  613. // TcpClient::instance()->sendMsg(req.c_str());
  614. //回调注册
  615. TcpCallback callback;
  616. callback.tid = tcpModel.tid;
  617. callback.jsonStr = req;
  618. callback.onSuccess = [](Json::Value json){
  619. LOGD("callback success");
  620. return 0;
  621. };
  622. callback.onFalied = [](Json::Value json){
  623. LOGD("callback failed");
  624. return 0;
  625. };
  626. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  627. setHelpButton("/button/button_help3.png" ,false);
  628. SetPainterInfo(0xFF2F9DF1,"增援已发出");
  629. setReinforce(true); // 设置增援状态为true
  630. //1分钟后无响应还原颜色
  631. if (!isHelpTimerRegistered){
  632. mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 60000);
  633. }
  634. return false;
  635. }
  636. static bool onButtonClick_CallCencelButton(ZKButton *pButton) {
  637. LOGD(" ButtonClick CallCencelButton !!!\n");
  638. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  639. TcpModel tcpModel;
  640. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  641. tcpModel.type = TcpType::VOICE;
  642. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  643. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  644. tcpModel.to_id = NULL;
  645. std::string req = getTcpModelString(tcpModel);
  646. LOGD("TCP VOICE : %s",req.c_str());
  647. //回调注册
  648. TcpCallback callback;
  649. callback.tid = tcpModel.tid;
  650. callback.jsonStr = req;
  651. callback.onSuccess = [](Json::Value json){
  652. LOGD("side callback success");
  653. return 0;
  654. };
  655. callback.onFalied = [](Json::Value json){
  656. LOGD("side callback failed");
  657. return 0;
  658. };
  659. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  660. return false;
  661. }
  662. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  663. LOGD(" ButtonClick NursingButton !!!\n");
  664. LOGD("onButtonClick_Nursing 触发护理按钮!!!");
  665. std::string color = partSetting.nursingColorRgb;
  666. std::string heartStr;
  667. if (color != "" && color.size() == 3) {
  668. heartStr = "DOORLED," + color + "F";
  669. } else {
  670. heartStr = "DOORLED,010F";
  671. }
  672. const char* sendMsg = heartStr.c_str();
  673. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  674. mFunctionWinPtr->showWnd();
  675. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  676. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  677. mFunctionBackPtr->setVisible(false);
  678. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  679. TcpModel tcpModel;
  680. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  681. tcpModel.type = TcpType::SIDE;
  682. tcpModel.action = SideAction::NURSING;
  683. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  684. tcpModel.to_id = NULL;
  685. std::string req = getTcpModelString(tcpModel);
  686. LOGD("TCP SIDE : %s",req.c_str());
  687. //回调注册
  688. TcpCallback callback;
  689. callback.tid = tcpModel.tid;
  690. callback.jsonStr = req;
  691. callback.onSuccess = [](Json::Value json){
  692. LOGD("side callback success");
  693. return 0;
  694. };
  695. callback.onFalied = [](Json::Value json){
  696. LOGD("side callback failed");
  697. return 0;
  698. };
  699. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  700. return false;
  701. }
  702. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  703. LOGD(" ButtonClick MoreButton !!!\n");
  704. EASYUICONTEXT->openActivity("ui3Activity");
  705. return false;
  706. }
  707. static bool onButtonClick_FunctionButton(ZKButton *pButton) {
  708. LOGD(" ButtonClick FunctionButton !!!\n");
  709. mFunctionWinPtr->hideWnd();
  710. std::string heartStr = "DOORLED,000F";
  711. const char* sendMsg = heartStr.c_str();
  712. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  713. if (nursingTcpModel.json.size() != 0) { // 对比一下,json里面不为空的时候
  714. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING_END
  715. TcpModel tcpModel;
  716. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  717. tcpModel.type = TcpType::SIDE;
  718. tcpModel.action = SideAction::NURSING_END;
  719. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  720. tcpModel.data = nursingTcpModel.json["id"].asString(); // 获取nursingTcpModel里,id字段的数据
  721. std::string req = getTcpModelString(tcpModel);
  722. LOGD("TCP NURSING_END : %s",req.c_str());
  723. //回调注册
  724. TcpCallback callback;
  725. callback.tid = tcpModel.tid;
  726. callback.jsonStr = req;
  727. callback.onSuccess = [](Json::Value json){
  728. LOGD("event callback success");
  729. return 0;
  730. };
  731. callback.onFalied = [](Json::Value json){
  732. LOGD("event callback failed");
  733. return 0;
  734. };
  735. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  736. TcpModel newTcpModel;
  737. nursingTcpModel = newTcpModel; // 清空nursingTcpModel
  738. }
  739. return false;
  740. }
  741. static bool onButtonClick_FunctionBack(ZKButton *pButton) {
  742. LOGD(" ButtonClick FunctionBack !!!\n");
  743. return false;
  744. }
  745. static int getListItemCount_CallBedListView(const ZKListView *pListView) {
  746. //LOGD("getListItemCount_CallBedListView !\n");
  747. return frameBedList.size();
  748. }
  749. static void obtainListItemData_CallBedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  750. //LOGD(" obtainListItemData_ CallBedListView !!!\n");
  751. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  752. pListItem->findSubItemByID(ID_MAIN_CallBedName)->setText(frameBedList[index]["customer_name"].asString());
  753. }
  754. static void onListItemClick_CallBedListView(ZKListView *pListView, int index, int id) {
  755. // LOGD(" onListItemClick_ CallBedListView !!!\n");
  756. string customerName = frameBedList[index]["customer_name"].asString();
  757. string toId = frameBedList[index]["bed_device_id"].asString();
  758. if (customerName == "") {
  759. Intent* intent = new Intent();
  760. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoCustomer"));
  761. EASYUICONTEXT->openActivity("warnActivity", intent);
  762. }
  763. else if (toId == "") {
  764. Intent* intent = new Intent();
  765. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedDevice"));
  766. EASYUICONTEXT->openActivity("warnActivity", intent);
  767. }
  768. else {
  769. mCallBebWinPtr->hideWnd();
  770. Intent* intent = new Intent();
  771. intent->putExtra(isOutgoing, "true");
  772. intent->putExtra(audioOnly, "true");
  773. intent->putExtra(toIdStr, toId);
  774. intent->putExtra(callName, frameBedList[index]["frame_bed"]["full_name"].asString() + " " + customerName);
  775. EASYUICONTEXT->openActivity("callActivity", intent);
  776. }
  777. }
  778. static bool onButtonClick_CallBedCancel(ZKButton *pButton) {
  779. LOGD(" ButtonClick CallBedCancel !!!\n");
  780. mCallBebWinPtr->hideWnd();
  781. return false;
  782. }