mainLogic.cc 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  229. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  230. setRightTitle(root);
  231. dataInit = true;
  232. }
  233. }
  234. // 将医生和护士别称缓存起来
  235. static void setRightTitle(Json::Value partSetting) {
  236. rightTitleInfo["doctor_title"] = partSetting["doctor_title"].asString();
  237. rightTitleInfo["doctor_valid"] = partSetting["doctor_valid"].asInt();
  238. rightTitleInfo["nurse_title"] = partSetting["nurse_title"].asString();
  239. rightTitleInfo["nurse_valid"] = partSetting["nurse_valid"].asInt();
  240. }
  241. static void getVersion() {
  242. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  243. std::string content_type = std::string("application/json");
  244. LOGD("请求版本信息. url = %s", url.c_str());
  245. //发起HTTP POST请求
  246. RestClient::Response r = RestClient::post(url, content_type, "");
  247. if (r.code != 200) {
  248. LOGD("请求版本信息-> 错误代码: %d", r.code);
  249. return;
  250. }
  251. LOGD("获得版本信息. result = %s", r.body.c_str());
  252. //解析json
  253. Json::Reader reader;
  254. Json::Value root;
  255. if(reader.parse(r.body, root, false)) {
  256. int currentVersionNo = getVersionNo();
  257. int responseVersionNo = root["version_no"].asInt();
  258. std::string responseVersion = root["version_code"].asString();
  259. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  260. if (currentVersionNo < responseVersionNo) {
  261. Intent* intent = new Intent();
  262. intent->putExtra(appUpdate, "true");
  263. EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent);
  264. }
  265. }
  266. }
  267. // 判断是否处于增援状态,处于增援状态,就要显示蓝色
  268. static void reinforceDispaly() {
  269. if (reinforce) {
  270. SetPainterInfo(0xFF2F9DF1, "增援已发出");
  271. setHelpButton("/button/button_help3.png" ,false);
  272. }
  273. }
  274. /**
  275. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  276. * return true 继续线程
  277. * false 退出线程
  278. */
  279. virtual bool readyToRun() {
  280. LOGD("Thread 已经创建完成");
  281. return true;
  282. }
  283. /**
  284. * 线程循环函数
  285. *
  286. * return true 继续线程循环
  287. * false 推出线程
  288. */
  289. virtual bool threadLoop() {
  290. LOGD("线程循环函数");
  291. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  292. if (exitPending()) {
  293. return false;
  294. }
  295. udpConn = net::Dial("udp", "192.168.1.255:10010");
  296. if (udpConn) {
  297. byte buf[1024] = {0};
  298. const char* req = "search_server";
  299. //发送
  300. udpConn->Write((byte*)req, strlen(req));
  301. while (true && !exitPending()) {
  302. //读取,超时10*1000毫秒
  303. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  304. if (n > 0) {
  305. buf[n] = 0;
  306. char serverStr[1024];
  307. sprintf(serverStr,"%s",buf);
  308. LOGD("读取 %d字节: %s", n, serverStr);
  309. //解析json
  310. Json::Reader reader;
  311. Json::Value root;
  312. if (reader.parse(serverStr, root, false)){
  313. if (root.isMember("success") && root["success"].asBool()){
  314. serverIP = root["data"]["third_server"].asString();
  315. serverHttpPort = root["data"]["third_server_port"].asInt();
  316. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  317. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  318. //先获取服务器信息
  319. //getServerInfo();
  320. //就当在获取服务器信息完成后获取用户信息,这里测试用
  321. //getCustomerInfo();
  322. //退出UDP线程
  323. pthread_exit(NULL);
  324. break;
  325. }
  326. }
  327. } else if (n == 0) {
  328. LOGD("连接正常断开");
  329. break;
  330. } else if (n == net::E_TIMEOUT) {
  331. udpConn->Write((byte*)req, strlen(req));
  332. LOGD("读取超时");
  333. } else {
  334. LOGD("出错");
  335. break;
  336. }
  337. }
  338. //关闭连接
  339. udpConn->Close();
  340. //释放内存
  341. delete udpConn;
  342. udpConn = NULL;
  343. }
  344. //返回真,继续下次线程循环
  345. return true;
  346. }
  347. };
  348. static UdpThread udp_thread;
  349. void setReinforce(bool result) {
  350. reinforce = result;
  351. }
  352. void cancelAutoBtnHelpTimer(){
  353. if (isHelpTimerRegistered) {
  354. mActivityPtr->unregisterUserTimer(HELP_TIMER_HANDLE);
  355. isHelpTimerRegistered = false;
  356. }
  357. }
  358. //标识方法
  359. void SetPainterInfo(uint32_t bgColor, const std::string& msg){
  360. mPainterInfoPtr->setBackgroundColor(bgColor);
  361. mTextInfoPtr->setText(msg);
  362. if (bgColor == 0xFFFFFFFF){
  363. mRoomNamePtr->setTextColor(0x00AAF4);
  364. } else {
  365. mRoomNamePtr->setTextColor(0xFFFFFF);
  366. }
  367. }
  368. // 收到tcp的时候,刷新数据
  369. void dataRefresh() {
  370. LOGD("DATA-REFRESH, 数据刷新");
  371. dataInit = false;
  372. udp_thread.getDeviceInfo();
  373. }
  374. void getPartSetting() {
  375. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  376. }
  377. // 处理护理的tcpModel
  378. void setNursingTcpModel(TcpModel tcpModel) {
  379. LOGD("缓存Nursing的tcpModel !!!");
  380. nursingTcpModel = tcpModel;
  381. }
  382. void setHelpButton(const char *pPicPath, bool isTouchable){
  383. mHelpButtonPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, pPicPath);
  384. mHelpButtonPtr->setTouchable(isTouchable);
  385. }
  386. /**
  387. * 注册定时器
  388. * 填充数组用于注册定时器
  389. * 注意:id不能重复
  390. */
  391. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  392. //{0, 6000}, //定时器id=0, 时间间隔6秒
  393. //{1, 1000},
  394. };
  395. /**
  396. * 当界面构造时触发
  397. */
  398. static void onUI_init(){
  399. //udp_thread.run("this is thread name");
  400. //测试用
  401. LOGD("进入mainLogic页面, 触发 onUI_init");
  402. if(serverInfo) { // 如果是false,就是不需要
  403. udp_thread.getServerInfo();
  404. }
  405. udp_thread.getDeviceInfo();
  406. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) { // 如果处于护理状态
  407. mFunctionWinPtr->showWnd();
  408. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  409. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  410. mFunctionBackPtr->setVisible(false);
  411. } else {
  412. mFunctionWinPtr->hideWnd();
  413. }
  414. }
  415. /**
  416. * 当切换到该界面时触发
  417. */
  418. static void onUI_intent(const Intent *intentPtr) {
  419. if (intentPtr != NULL) {
  420. }
  421. }
  422. /*
  423. * 当界面显示时触发
  424. */
  425. static void onUI_show() {
  426. }
  427. /*
  428. * 当界面隐藏时触发
  429. */
  430. static void onUI_hide() {
  431. }
  432. /*
  433. * 当界面完全退出时触发
  434. */
  435. static void onUI_quit() {
  436. //pthread_exit(NULL);
  437. }
  438. /**
  439. * 串口数据回调接口
  440. */
  441. static void onProtocolDataUpdate(const SProtocolData &data) {
  442. }
  443. /**
  444. * 定时器触发函数
  445. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  446. * 参数: id
  447. * 当前所触发定时器的id,与注册时的id相同
  448. * 返回值: true
  449. * 继续运行当前定时器
  450. * false
  451. * 停止运行当前定时器
  452. */
  453. static bool onUI_Timer(int id){
  454. switch (id) {
  455. case HELP_TIMER_HANDLE: // 不能在线程里面关掉线程
  456. {
  457. SetPainterInfo(0xFFFFFFFF, "");
  458. setReinforce(false);
  459. setHelpButton("/button/button_help2.png", true);
  460. return false;
  461. }
  462. break;
  463. default:
  464. break;
  465. }
  466. return true;
  467. }
  468. /**
  469. * 有新的触摸事件时触发
  470. * 参数:ev
  471. * 新的触摸事件
  472. * 返回值:true
  473. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  474. * false
  475. * 触摸事件将继续传递到控件上
  476. */
  477. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  478. switch (ev.mActionStatus) {
  479. case MotionEvent::E_ACTION_DOWN://触摸按下
  480. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  481. break;
  482. case MotionEvent::E_ACTION_MOVE://触摸滑动
  483. break;
  484. case MotionEvent::E_ACTION_UP: //触摸抬起
  485. break;
  486. default:
  487. break;
  488. }
  489. return false;
  490. }
  491. static int getListItemCount_BedListView(const ZKListView *pListView) {
  492. //LOGD("getListItemCount_BedListView !\n");
  493. if (frameBedList.size() > 3) {
  494. return frameBedList.size();
  495. }
  496. return 3;
  497. }
  498. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  499. //LOGD(" obtainListItemData_ BedListView !!!\n");
  500. if (frameBedList.size() > 0) {
  501. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  502. // 用户相关
  503. string customerName = frameBedList[index]["customer_name"].asString();
  504. pListItem->findSubItemByID(ID_MAIN_CustomerName)->setText(customerName);
  505. pListItem->findSubItemByID(ID_MAIN_CustomerAge)->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  506. string customerSex = frameBedList[index]["customer_sex"].asString();
  507. if (customerSex == "0") { // 如果性别为女性,则替换成女性头像,和女性的图标
  508. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_female.png");
  509. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_female.png");
  510. }
  511. else if (customerSex == "1") {
  512. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_male.png");
  513. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("ic_gender_male.png");
  514. }
  515. else {
  516. pListItem->findSubItemByID(ID_MAIN_CustomerPortrait)->setBackgroundPic("ic_custom_empty.png");
  517. pListItem->findSubItemByID(ID_MAIN_CustomerSex)->setBackgroundPic("");
  518. }
  519. // 医生护士相关
  520. if (rightTitleInfo["doctor_valid"] != 1){
  521. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setVisible(false);
  522. } else {
  523. pListItem->findSubItemByID(ID_MAIN_DoctorText)->setText(rightTitleInfo["doctor_title"].asString());
  524. }
  525. if (rightTitleInfo["nurse_valid"] != 1){
  526. pListItem->findSubItemByID(ID_MAIN_NurseText)->setVisible(false);
  527. } else {
  528. pListItem->findSubItemByID(ID_MAIN_NurseText)->setText(rightTitleInfo["nurse_title"].asString());
  529. }
  530. pListItem->findSubItemByID(ID_MAIN_DoctorName)->setText(frameBedList[index]["doctor_name"].asString());
  531. pListItem->findSubItemByID(ID_MAIN_NurseName)->setText(frameBedList[index]["nurse_name"].asString());
  532. // 护理项相关
  533. Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  534. if (nurseConfigList.size() > 0) {
  535. for (int i = 0; i < 5; i++) {
  536. int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  537. int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  538. int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  539. if (nurseConfigList.size() >= i) {
  540. //颜色
  541. string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  542. uint32_t bgColor = 0xFFC0C0C0;
  543. if (nurseConfigColot != "") {
  544. string rgbStr = "FF" + nurseConfigColot;
  545. transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  546. bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  547. }
  548. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  549. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  550. string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  551. if (nurseOptionName == "") {
  552. nurseOptionName = LANGUAGEMANAGER->getValue("None");
  553. }
  554. pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  555. } else {
  556. //颜色
  557. pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  558. pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  559. pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  560. }
  561. }
  562. }
  563. else {
  564. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  565. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  566. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  567. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  568. pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  569. pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  570. pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  571. pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  572. pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  573. pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  574. pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  575. pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  576. pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  577. pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  578. pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  579. }
  580. }
  581. }
  582. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  583. //LOGD(" onListItemClick_ BedListView !!!\n");
  584. }
  585. static bool onButtonClick_CallBedButton(ZKButton *pButton) {
  586. LOGD(" ButtonClick CallBedButton !!!\n");
  587. if (frameBedList.size() > 0) {
  588. mCallBebWinPtr->showWnd();
  589. } else {
  590. Intent* intent = new Intent();
  591. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedList"));
  592. EASYUICONTEXT->openActivity("warnActivity", intent);
  593. }
  594. return false;
  595. }
  596. static bool onButtonClick_CallNurseButton(ZKButton *pButton) {
  597. LOGD(" ButtonClick CallNurseButton !!!\n");
  598. if (SIGNAL_TYPE=="SIP"){
  599. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  600. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  601. std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  602. std::string od_number_uri = URI(od_number, domain, port);
  603. LOGD("od_number_uri: %s", od_number_uri.c_str());
  604. GetTelephone()->MakeCall(od_number_uri);
  605. } else {
  606. Intent* intent = new Intent();
  607. intent->putExtra(isOutgoing, "true");
  608. intent->putExtra(audioOnly, "true");
  609. EASYUICONTEXT->openActivity("callActivity", intent);
  610. }
  611. return false;
  612. }
  613. static bool onButtonClick_HelpButton(ZKButton *pButton) {
  614. LOGD(" ButtonClick HelpButton !!!\n");
  615. TcpModel tcpModel;
  616. tcpModel.type = TcpType::REINFORCE;
  617. tcpModel.action = ReinforceAction::CALL;
  618. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  619. tcpModel.to_id = 0;
  620. std::string req = getTcpModelString(tcpModel);
  621. LOGD("REINFORCE CALL : %s",req.c_str());
  622. // TcpClient::instance()->sendMsg(req.c_str());
  623. //回调注册
  624. TcpCallback callback;
  625. callback.tid = tcpModel.tid;
  626. callback.jsonStr = req;
  627. callback.onSuccess = [](Json::Value json){
  628. LOGD("callback success");
  629. return 0;
  630. };
  631. callback.onFalied = [](Json::Value json){
  632. LOGD("callback failed");
  633. return 0;
  634. };
  635. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  636. setHelpButton("/button/button_help3.png" ,false);
  637. SetPainterInfo(0xFF2F9DF1, "增援已发出");
  638. setReinforce(true); // 设置增援状态为true
  639. //1分钟后无响应还原颜色
  640. if (!isHelpTimerRegistered){
  641. mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 60000);
  642. }
  643. return false;
  644. }
  645. static bool onButtonClick_CallCencelButton(ZKButton *pButton) {
  646. LOGD(" ButtonClick CallCencelButton !!!\n");
  647. // 发送tcp, tcp_type = VOICE, tcp_action = CANCEL_BY_DOOR
  648. TcpModel tcpModel;
  649. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  650. tcpModel.type = TcpType::VOICE;
  651. tcpModel.action = VoiceAction::CANCEL_BY_DOOR;
  652. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  653. tcpModel.to_id = NULL;
  654. std::string req = getTcpModelString(tcpModel);
  655. LOGD("TCP VOICE : %s",req.c_str());
  656. //回调注册
  657. TcpCallback callback;
  658. callback.tid = tcpModel.tid;
  659. callback.jsonStr = req;
  660. callback.onSuccess = [](Json::Value json){
  661. LOGD("side callback success");
  662. return 0;
  663. };
  664. callback.onFalied = [](Json::Value json){
  665. LOGD("side callback failed");
  666. return 0;
  667. };
  668. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  669. return false;
  670. }
  671. static bool onButtonClick_NursingButton(ZKButton *pButton) {
  672. LOGD(" ButtonClick NursingButton !!!\n");
  673. LOGD("onButtonClick_Nursing 触发护理按钮!!!");
  674. std::string color = partSetting.nursingColorRgb;
  675. std::string heartStr;
  676. if (color != "" && color.size() == 3) {
  677. heartStr = "DOORLED," + color + "F";
  678. } else {
  679. heartStr = "DOORLED,010F";
  680. }
  681. const char* sendMsg = heartStr.c_str();
  682. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  683. mFunctionWinPtr->showWnd();
  684. mFunctionTextViewPtr->setText(LANGUAGEMANAGER->getValue("InNursing"));
  685. mFunctionButtonPtr->setText(LANGUAGEMANAGER->getValue("NursingEnd"));
  686. mFunctionBackPtr->setVisible(false);
  687. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING
  688. TcpModel tcpModel;
  689. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  690. tcpModel.type = TcpType::SIDE;
  691. tcpModel.action = SideAction::NURSING;
  692. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  693. tcpModel.to_id = NULL;
  694. std::string req = getTcpModelString(tcpModel);
  695. LOGD("TCP SIDE : %s",req.c_str());
  696. //回调注册
  697. TcpCallback callback;
  698. callback.tid = tcpModel.tid;
  699. callback.jsonStr = req;
  700. callback.onSuccess = [](Json::Value json){
  701. LOGD("side callback success");
  702. return 0;
  703. };
  704. callback.onFalied = [](Json::Value json){
  705. LOGD("side callback failed");
  706. return 0;
  707. };
  708. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  709. // 把护理状态缓存起来
  710. StoragePreferences::putBool(STORE_NURSING_TYPE, true);
  711. return false;
  712. }
  713. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  714. LOGD(" ButtonClick MoreButton !!!\n");
  715. EASYUICONTEXT->openActivity("ui3Activity");
  716. return false;
  717. }
  718. static bool onButtonClick_FunctionButton(ZKButton *pButton) {
  719. LOGD(" ButtonClick FunctionButton !!!\n");
  720. mFunctionWinPtr->hideWnd();
  721. std::string heartStr = "DOORLED,000F";
  722. const char* sendMsg = heartStr.c_str();
  723. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  724. if (nursingTcpModel.json.size() != 0) { // 对比一下,json里面不为空的时候
  725. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  726. // 发送tcp, tcp_type = SIDE, tcp_action = NURSING_END
  727. TcpModel tcpModel;
  728. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  729. tcpModel.type = TcpType::SIDE;
  730. tcpModel.action = SideAction::NURSING_END;
  731. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  732. tcpModel.data = nursingTcpModel.json["id"].asString(); // 获取nursingTcpModel里,id字段的数据
  733. std::string req = getTcpModelString(tcpModel);
  734. LOGD("TCP NURSING_END : %s",req.c_str());
  735. //回调注册
  736. TcpCallback callback;
  737. callback.tid = tcpModel.tid;
  738. callback.jsonStr = req;
  739. callback.onSuccess = [](Json::Value json){
  740. LOGD("event callback success");
  741. return 0;
  742. };
  743. callback.onFalied = [](Json::Value json){
  744. LOGD("event callback failed");
  745. return 0;
  746. };
  747. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  748. TcpModel newTcpModel;
  749. nursingTcpModel = newTcpModel; // 清空nursingTcpModel
  750. }
  751. return false;
  752. }
  753. static bool onButtonClick_FunctionBack(ZKButton *pButton) {
  754. LOGD(" ButtonClick FunctionBack !!!\n");
  755. return false;
  756. }
  757. static int getListItemCount_CallBedListView(const ZKListView *pListView) {
  758. //LOGD("getListItemCount_CallBedListView !\n");
  759. return frameBedList.size();
  760. }
  761. static void obtainListItemData_CallBedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  762. //LOGD(" obtainListItemData_ CallBedListView !!!\n");
  763. pListItem->setText(frameBedList[index]["frame_bed"]["full_name"].asString());
  764. pListItem->findSubItemByID(ID_MAIN_CallBedName)->setText(frameBedList[index]["customer_name"].asString());
  765. }
  766. static void onListItemClick_CallBedListView(ZKListView *pListView, int index, int id) {
  767. // LOGD(" onListItemClick_ CallBedListView !!!\n");
  768. string customerName = frameBedList[index]["customer_name"].asString();
  769. string toId = frameBedList[index]["bed_device_id"].asString();
  770. if (customerName == "") {
  771. Intent* intent = new Intent();
  772. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoCustomer"));
  773. EASYUICONTEXT->openActivity("warnActivity", intent);
  774. }
  775. else if (toId == "") {
  776. Intent* intent = new Intent();
  777. intent->putExtra(warnText, LANGUAGEMANAGER->getValue("NoBedDevice"));
  778. EASYUICONTEXT->openActivity("warnActivity", intent);
  779. }
  780. else {
  781. mCallBebWinPtr->hideWnd();
  782. Intent* intent = new Intent();
  783. intent->putExtra(isOutgoing, "true");
  784. intent->putExtra(audioOnly, "true");
  785. intent->putExtra(toIdStr, toId);
  786. intent->putExtra(callName, frameBedList[index]["frame_bed"]["full_name"].asString() + " " + customerName);
  787. EASYUICONTEXT->openActivity("callActivity", intent);
  788. }
  789. }
  790. static bool onButtonClick_CallBedCancel(ZKButton *pButton) {
  791. LOGD(" ButtonClick CallBedCancel !!!\n");
  792. mCallBebWinPtr->hideWnd();
  793. return false;
  794. }