mainLogic.cc 31 KB

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