mainLogic.cc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "net/NetManager.h"
  4. #include "storage/StoragePreferences.h"
  5. #include "net/net.h"
  6. #include <system/Thread.h>
  7. #include "restclient-cpp/restclient.h"
  8. #include "curl/curl.h"
  9. #include <algorithm>
  10. #include "service/BusinessConfig.h"
  11. #include "core/sip_config.h"
  12. #include "manager/LanguageManager.h"
  13. #include "core/utilities.h"
  14. #include <string>
  15. #include "zkaudio.h"
  16. #include "base/strings.hpp"
  17. #include "base/http_client.h"
  18. #include "os/UpgradeMonitor.h"
  19. #include "core/update_assistant.h"
  20. #include "utils/TimeHelper.h"
  21. #include "voip/media_player.h"
  22. #include "manager/ConfigManager.h"
  23. #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
  24. #define WIFIMANAGER NETMANAGER->getWifiManager()
  25. static base::MediaPlayer mediaPlayer;
  26. /*
  27. *此文件由GUI工具生成
  28. *文件功能:用于处理用户的逻辑相应代码
  29. *功能说明:
  30. *========================onButtonClick_XXXX
  31. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  32. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  33. *========================onSlideWindowItemClick_XXXX(int index)
  34. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  35. 如slideWindow1;index 代表按下图标的偏移值
  36. *========================onSeekBarChange_XXXX(int progress)
  37. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  38. 如SeekBar1;progress 代表当前的进度值
  39. *========================ogetListItemCount_XXXX()
  40. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  41. 如List1;返回值为当前列表的总条数
  42. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  43. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  44. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  45. *========================常用接口===============
  46. *LOGD(...) 打印调试信息的接口
  47. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  48. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  49. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  50. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  51. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  52. *
  53. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  54. */
  55. static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据
  56. PartSetting partSetting;
  57. Json::Value frameRoom;
  58. Json::Value frameBedList;
  59. Json::Value frameInfo; // 缓存房间名字等
  60. Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题
  61. Json::Value painterInfo;
  62. Json::Value painterInfoList;
  63. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  64. static int inBedCount = 0;
  65. static int emptyBedCount = 0;
  66. static bool isMusic = false;
  67. #define HELP_TIMER_HANDLE 3 // 增援的定时器id
  68. #define EVENT_TIME_HANDLE 8 // 事件定时器
  69. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  70. static void getServerInfo(){
  71. string url = getHttpGateway() + "/ncs_url/server_info";
  72. LOGD("请求服务器信息. url = %s", url.c_str());
  73. //发起HTTP GET请求
  74. RestClient::Response r = RestClient::get(url);
  75. //解析json
  76. Json::Reader reader;
  77. Json::Value root;
  78. if (reader.parse(r.body, root, false)){
  79. // http
  80. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  81. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  82. // tcp
  83. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  84. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  85. // sip
  86. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  87. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  88. serverInfo = false; // 只有请求成功了,才不需要重复请求
  89. }
  90. }
  91. // 读取空间缓存的数据
  92. static void getFrameInfo() {
  93. mRoomNameTextViewPtr->setText(frameInfo["full_name"].asString());
  94. }
  95. static void getBedCount() {
  96. if (mActivityPtr == NULL) {
  97. return;
  98. }
  99. mInBedNumTextViewPtr->setText(inBedCount);
  100. mEmptyBedNumTextViewPtr->setText(emptyBedCount);
  101. }
  102. static void getFrameRoom(int frame_id) {
  103. string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id);
  104. LOGD("请求房间信息. url = %s", url.c_str());
  105. //发起HTTP GET请求
  106. RestClient::Response r = RestClient::get(url);
  107. LOGD("获得房间信息. result = %s", r.body.c_str());
  108. //解析json
  109. Json::Reader reader;
  110. Json::Value root;
  111. if (reader.parse(r.body, root, false)){
  112. frameRoom = root;
  113. frameBedList = root["frame_bed_list"];
  114. inBedCount = 0;
  115. emptyBedCount = 0;
  116. if (frameBedList.size() > 0) {
  117. for (int i = 0; i < frameBedList.size(); i++) {
  118. string customerId = frameBedList[i]["customer_id"].asString();
  119. if (customerId != "") {
  120. inBedCount += 1;
  121. }
  122. }
  123. emptyBedCount = frameBedList.size() - inBedCount;
  124. getBedCount();
  125. }
  126. if (mBedListViewPtr != NULL) {
  127. mBedListViewPtr->refreshListView();
  128. }
  129. }
  130. }
  131. // 将医生和护士别称缓存起来
  132. static void setRightTitle(Json::Value partSetting) {
  133. rightTitleInfo["doctor_title"] = partSetting["doctor_title"].asString();
  134. rightTitleInfo["doctor_valid"] = partSetting["doctor_valid"].asInt();
  135. rightTitleInfo["nurse_title"] = partSetting["nurse_title"].asString();
  136. rightTitleInfo["nurse_valid"] = partSetting["nurse_valid"].asInt();
  137. }
  138. static void getPartSetting(string partId){
  139. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  140. LOGD("请求科室信息. url = %s", url.c_str());
  141. //发起HTTP GET请求
  142. RestClient::Response r = RestClient::get(url);
  143. LOGD("获得科室信息. result = %s", r.body.c_str());
  144. //解析json
  145. Json::Reader reader;
  146. Json::Value root;
  147. if (reader.parse(r.body, root, false)){
  148. partSetting.partId = root["part_id"].asInt();
  149. partSetting.dayStart = root["day_start"].asString();
  150. partSetting.dayLight = root["day_light"].asInt();
  151. partSetting.dayVol = root["day_vol"].asInt();
  152. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  153. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  154. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  155. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  156. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  157. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  158. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  159. partSetting.nightStart = root["night_start"].asString();
  160. partSetting.nightLight = root["night_light"].asInt();
  161. partSetting.nightVol = root["night_vol"].asInt();
  162. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  163. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  164. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  165. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  166. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  167. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  168. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  169. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  170. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  171. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  172. partSetting.sipOvertime = root["sip_overtime"].asInt();
  173. partSetting.transferDuration = root["transfer_duration"].asInt();
  174. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  175. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  176. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  177. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  178. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  179. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  180. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  181. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  182. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  183. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  184. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  185. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  186. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  187. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  188. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  189. partSetting.doctorTitle = root["doctor_title"].asString();
  190. partSetting.doctorValid = root["doctor_valid"].asInt();
  191. partSetting.nurseTitle = root["nurse_title"].asString();
  192. partSetting.nurseValid = root["nurse_valid"].asInt();
  193. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  194. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  195. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  196. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  197. partSetting.upSeconds = root["up_seconds"].asInt();
  198. partSetting.autoAccept = root["auto_accept"].asInt();
  199. partSetting.eventForward = root["event_forward"].asInt();
  200. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  201. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  202. partSetting.qrUrl = root["qr_url"].asString();
  203. partSetting.screenLight = root["screen_light"].asInt();
  204. partSetting.roomCallBed = root["room_call_bed"].asInt();
  205. partSetting.autoPosition = root["auto_position"].asInt();
  206. partSetting.customerAgeHiddenOnDoor = root["customer_age_hidden_on_door"].asInt();
  207. if (root.isMember("linux_bed_volume_native")) {
  208. partSetting.linuxDoorVolumeNative = root["linux_door_volume_native"].asInt();
  209. partSetting.linuxDoorGainSize = root["linux_door_gain_size"].asInt();
  210. zk_audio_input_set_volume_native(0, 0);
  211. zk_audio_input_set_volume_native(1, partSetting.linuxDoorVolumeNative);
  212. GetTelephone()->SetInputPcmGainSize(partSetting.linuxDoorGainSize);
  213. StoragePreferences::putInt(STORE_VOLUME_NATIVE, partSetting.linuxDoorVolumeNative);
  214. StoragePreferences::putInt(STORE_GAIN_SIZE, partSetting.linuxDoorGainSize);
  215. }
  216. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  217. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  218. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  219. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  220. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  221. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  222. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  223. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  224. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  225. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  226. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  227. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  228. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  229. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  230. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  231. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  232. StoragePreferences::putInt(STORE_ROOM_CALL_BED, partSetting.roomCallBed);
  233. StoragePreferences::putInt(STORE_AUTO_POSITION, partSetting.autoPosition);
  234. setRightTitle(root);
  235. callBedButtonSetVisible();
  236. getFrameRoom(frameInfo["frame_id"].asInt());
  237. dataInit = true;
  238. }
  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("updateActivity", intent);
  263. }
  264. }
  265. }
  266. static void getNfcInteraction() {
  267. std::string url = getHttpGateway() + "/deviceRoom/get_nfc_interaction_end_time_is_null/" + to_string(StoragePreferences::getInt(STORE_DEVICE_ID,0));
  268. LOGD("请求未完成的nfc记录. url = %s", url.c_str());
  269. //发起HTTP POST请求
  270. RestClient::Response r = RestClient::get(url);
  271. if (r.code != 200) {
  272. LOGD("请求未完成的nfc记录-> 错误代码: %d", r.code);
  273. return;
  274. }
  275. LOGD("获得未完成的nfc记录. result = %s", r.body.c_str());
  276. //解析json
  277. Json::Reader reader;
  278. Json::Value root;
  279. if(reader.parse(r.body, root, false)) {
  280. int clerkId = 0;
  281. for (int i = 0; i < root.size(); i++) {
  282. if (root[i]["components_type"].asCString() == TcpType::AUTH) {
  283. clerkId = root[i]["clerk_id"].asInt();
  284. setClerk(root[i]["clerk_name"].asCString(), root[i]["pass_no"].asCString(), root[i]["id"].asInt());
  285. }
  286. else if (root[i]["components_type"].asString() == "POSITION_COMPONENT") {
  287. setPosistionItId(root[i]["id"].asInt());
  288. setPositionButton(true);
  289. }
  290. else if (root[i]["components_type"].asString() == "ROOMCHECK_COMPONENT") {
  291. setRoomCheckItId(root[i]["id"].asInt());
  292. setRoomPatrolButton(true);
  293. }
  294. else if (root[i]["components_type"].asString() == "SCREEN_TIP_SET_COMPONENT") {
  295. time_t now = TimeHelper::getDateline();
  296. if (now <= 0) {
  297. continue;
  298. }
  299. Json::Reader Reader;
  300. Json::Value operationData;
  301. Reader.parse(root[i]["operation_data"].asString(), operationData);
  302. int seconds = operationData["seconds"].asInt();
  303. if (now - root[i]["start_time"].asInt() < seconds) {
  304. setPromptTimeItId(root[i]["id"].asInt());
  305. Intent* intent = new Intent();
  306. intent->putExtra(promptText2, operationData["tips"].asString());
  307. intent->putExtra(promptTime2, to_string(seconds - (now - root[i]["start_time"].asInt())));
  308. EASYUICONTEXT->openActivity("promptActivity", intent);
  309. }
  310. else {
  311. sendPromptQuit(root[i]["id"].asInt());
  312. }
  313. }
  314. }
  315. if (clerkId != 0) {
  316. goCare();
  317. }
  318. }
  319. }
  320. static void getDeviceInfo(){
  321. if (dataInit){
  322. getFrameInfo();
  323. getBedCount();
  324. return;
  325. }
  326. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0");
  327. LOGD("请求设备信息. url = %s", url.c_str());
  328. //发起HTTP GET请求
  329. RestClient::Response r = RestClient::get(url);
  330. LOGD("获得设备信息. result = %s", r.body.c_str());
  331. //解析json
  332. Json::Reader reader;
  333. Json::Value root;
  334. if (reader.parse(r.body, root, false)){
  335. string partName = root["part_display"].asString();
  336. StoragePreferences::putString(STORE_PARTNAME,partName);
  337. NavibarSetPartName(partName);
  338. //设备
  339. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  340. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  341. //SIP存储
  342. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  343. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  344. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  345. frameInfo["frame_id"] = root["frame_id"].asInt();
  346. frameInfo["full_name"] = root["full_name"].asString();
  347. frameInfo["part_id"] = root["part_id"].asInt();
  348. getFrameInfo();
  349. //获取科室设置
  350. string partId = root["part_id"].asString();
  351. StoragePreferences::putString(STORE_PARTID, partId);
  352. getPartSetting(partId);
  353. getVersion();
  354. getNfcInteraction();
  355. }
  356. }
  357. Json::Value getFrame() {
  358. return frameRoom;
  359. }
  360. // 收到tcp的时候,刷新数据
  361. void dataRefresh() {
  362. LOGD("DATA-REFRESH, 数据刷新");
  363. if (mActivityPtr == NULL) {
  364. return;
  365. }
  366. if (serverInfo) {
  367. getServerInfo();
  368. }
  369. dataInit = false;
  370. getDeviceInfo();
  371. mBedListViewPtr->refreshListView();
  372. }
  373. void getPartSetting() {
  374. getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  375. }
  376. /**
  377. * 注册定时器
  378. * 填充数组用于注册定时器
  379. * 注意:id不能重复
  380. */
  381. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  382. //{0, 6000}, //定时器id=0, 时间间隔6秒
  383. //{1, 1000},
  384. {101, 1000}
  385. };
  386. /**
  387. * 当界面构造时触发
  388. */
  389. static void onUI_init(){
  390. //run("this is thread name");
  391. //测试用
  392. LOGD("进入mainLogic页面, 触发 onUI_init");
  393. if (ETHERNETMANAGER->isConnected() || WIFIMANAGER->isConnected()) {
  394. if(serverInfo) { // 如果是false,就是不需要
  395. getServerInfo();
  396. }
  397. getDeviceInfo();
  398. }
  399. mSeekBarOutputVolumePtr->setProgress(30);
  400. mTextViewOutputVolumePtr->setTouchPass(true);
  401. isMusic = StoragePreferences::getBool(STORE_MUSIC, false);
  402. if (isMusic) {
  403. mediaPlayer.Play(CONFIGMANAGER->getResFilePath("incoming_call.mp3"), "", 1000,
  404. base::MediaPlayer::PlayMode::Loop);
  405. }
  406. }
  407. /**
  408. * 当切换到该界面时触发
  409. */
  410. static void onUI_intent(const Intent *intentPtr) {
  411. if (intentPtr != NULL) {
  412. }
  413. }
  414. /*
  415. * 当界面显示时触发
  416. */
  417. static void onUI_show() {
  418. }
  419. /*
  420. * 当界面隐藏时触发
  421. */
  422. static void onUI_hide() {
  423. }
  424. /*
  425. * 当界面完全退出时触发
  426. */
  427. static void onUI_quit() {
  428. //pthread_exit(NULL);
  429. }
  430. /**
  431. * 串口数据回调接口
  432. */
  433. static void onProtocolDataUpdate(const SProtocolData &data) {
  434. }
  435. int restartTime = 600;
  436. int restartCount = 0;
  437. int commandCount = 0;
  438. /**
  439. * 定时器触发函数
  440. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  441. * 参数: id
  442. * 当前所触发定时器的id,与注册时的id相同
  443. * 返回值: true
  444. * 继续运行当前定时器
  445. * false
  446. * 停止运行当前定时器
  447. */
  448. static bool onUI_Timer(int id){
  449. switch (id) {
  450. case 101: {
  451. if (commandCount == 0) {
  452. restartTime -= 1;
  453. }
  454. std::string restartStr = "重启倒计时:" + to_string(restartTime) + " 循环次数:" + to_string(restartCount);
  455. mTextView1Ptr->setText(restartStr);
  456. if (restartTime == 0) {
  457. lightControl("NETRESET", "1F");
  458. commandCount += 1;
  459. if (commandCount == 10) {
  460. restartTime = 600;
  461. restartCount += 1;
  462. commandCount = 0;
  463. }
  464. }
  465. }
  466. break;
  467. default:
  468. break;
  469. }
  470. return true;
  471. }
  472. /**
  473. * 有新的触摸事件时触发
  474. * 参数:ev
  475. * 新的触摸事件
  476. * 返回值:true
  477. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  478. * false
  479. * 触摸事件将继续传递到控件上
  480. */
  481. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  482. switch (ev.mActionStatus) {
  483. case MotionEvent::E_ACTION_DOWN://触摸按下
  484. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  485. break;
  486. case MotionEvent::E_ACTION_MOVE://触摸滑动
  487. break;
  488. case MotionEvent::E_ACTION_UP: //触摸抬起
  489. break;
  490. default:
  491. break;
  492. }
  493. return false;
  494. }
  495. static int getListItemCount_BedListView(const ZKListView *pListView) {
  496. //LOGD("getListItemCount_BedListView !\n");
  497. return frameBedList.size();
  498. }
  499. static void obtainListItemData_BedListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  500. //LOGD(" obtainListItemData_ BedListView !!!\n");
  501. if (frameBedList.size() > 0) {
  502. ZKListView::ZKListSubItem* bedNum = pListItem->findSubItemByID(ID_MAIN_BedNumSubItem);
  503. ZKListView::ZKListSubItem* name = pListItem->findSubItemByID(ID_MAIN_CustomerNameSubItem);
  504. ZKListView::ZKListSubItem* age = pListItem->findSubItemByID(ID_MAIN_AgeSubItem);
  505. ZKListView::ZKListSubItem* sex = pListItem->findSubItemByID(ID_MAIN_SexSubItem);
  506. ZKListView::ZKListSubItem* doctorTitle = pListItem->findSubItemByID(ID_MAIN_DoctorTitileSubItem);
  507. ZKListView::ZKListSubItem* nurseTitle = pListItem->findSubItemByID(ID_MAIN_NurseTitleSubItem);
  508. ZKListView::ZKListSubItem* doctor = pListItem->findSubItemByID(ID_MAIN_DoctorSubItem);
  509. ZKListView::ZKListSubItem* nurse = pListItem->findSubItemByID(ID_MAIN_NurseSubItem);
  510. string frameBedName = frameBedList[index]["frame_bed"]["full_name"].asString();
  511. if (frameBedName == "") {
  512. bedNum->setText(LANGUAGEMANAGER->getValue("EmptyBed"));
  513. } else {
  514. int nPos = frameBedName.find("-");
  515. if (nPos != -1) {
  516. frameBedName = frameBedName.substr(nPos + 1, frameBedName.length());
  517. }
  518. bedNum->setText(frameBedName);
  519. }
  520. // 用户相关
  521. string customerName = frameBedList[index]["customer_name"].asString();
  522. if (customerName == "") {
  523. name->setText(LANGUAGEMANAGER->getValue("EmptyCustomer"));
  524. } else {
  525. name->setText(customerName);
  526. }
  527. if (partSetting.customerAgeHiddenOnDoor != 0) {
  528. if (frameBedList[index]["customer_age"].asString() == "") {
  529. age->setText("");
  530. } else {
  531. age->setText("*" + frameBedList[index]["customer_age_unit"].asString());
  532. }
  533. }
  534. else {
  535. age->setText(frameBedList[index]["customer_age"].asString() + frameBedList[index]["customer_age_unit"].asString());
  536. }
  537. string customerSex = frameBedList[index]["customer_sex"].asString();
  538. if (customerSex == "0") { // 如果性别为女性,替换成女性,底色为粉色
  539. sex->setText(LANGUAGEMANAGER->getValue("Woman"));
  540. sex->setTextColor(0xFF9F9F);
  541. sex->setBackgroundPic("main/woman.png");
  542. }
  543. else if (customerSex == "1") {
  544. sex->setText(LANGUAGEMANAGER->getValue("Man"));
  545. sex->setTextColor(0x3A78EF);
  546. sex->setBackgroundPic("main/man.png");
  547. }
  548. else {
  549. sex->setText(LANGUAGEMANAGER->getValue("Unknown"));
  550. sex->setTextColor(0x37B643);
  551. sex->setBackgroundPic("main/age.png");
  552. }
  553. // 医生护士相关
  554. if (rightTitleInfo["doctor_valid"] != 1){
  555. doctorTitle->setVisible(false);
  556. } else {
  557. doctorTitle->setText(rightTitleInfo["doctor_title"].asString());
  558. }
  559. if (rightTitleInfo["nurse_valid"] != 1){
  560. nurseTitle->setVisible(false);
  561. } else {
  562. nurseTitle->setText(rightTitleInfo["nurse_title"].asString());
  563. }
  564. doctor->setText(frameBedList[index]["doctor_name"].asString());
  565. nurse->setText(frameBedList[index]["nurse_name"].asString());
  566. // // 护理项相关
  567. // Json::Value nurseConfigList = frameBedList[index]["nurse_config_dtos"];
  568. // if (nurseConfigList.size() > 0) {
  569. // for (int i = 0; i < 5; i++) {
  570. // int nurseConfigColorNumber = ID_MAIN_NurseConfigColor1 + i;
  571. // int nurseConfigNumber = ID_MAIN_NurseConfig1 + i * 2;
  572. // int nurseOptionNumber = ID_MAIN_NurseOption1 + i * 2;
  573. // if (nurseConfigList.size() >= i) {
  574. // //颜色
  575. // string nurseConfigColot = nurseConfigList[i]["nurse_color_rbg"].asString();
  576. // uint32_t bgColor = 0xFFC0C0C0;
  577. // if (nurseConfigColot != "") {
  578. // string rgbStr = "FF" + nurseConfigColot;
  579. // transform(rgbStr.begin(), rgbStr.end(), rgbStr.begin(), ::toupper);
  580. // bgColor = strtoul(("0x" + rgbStr).c_str(), NULL,16);
  581. // }
  582. // pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(bgColor);
  583. // pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  584. // string nurseOptionName = nurseConfigList[i]["nurse_option_name"].asString();
  585. // if (nurseOptionName == "") {
  586. // nurseOptionName = LANGUAGEMANAGER->getValue("None");
  587. // }
  588. // pListItem->findSubItemByID(nurseOptionNumber)->setText(nurseOptionName);
  589. //
  590. // } else {
  591. // //颜色
  592. // pListItem->findSubItemByID(nurseConfigColorNumber)->setBackgroundColor(0xFFC0C0C0);
  593. // pListItem->findSubItemByID(nurseConfigNumber)->setText(nurseConfigList[i]["nurse_config_name"].asString());
  594. // pListItem->findSubItemByID(nurseOptionNumber)->setText(LANGUAGEMANAGER->getValue("None"));
  595. // }
  596. // }
  597. // }
  598. // else {
  599. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor1)->setBackgroundColor(0xFFC0C0C0);
  600. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor2)->setBackgroundColor(0xFFC0C0C0);
  601. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor3)->setBackgroundColor(0xFFC0C0C0);
  602. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor4)->setBackgroundColor(0xFFC0C0C0);
  603. // pListItem->findSubItemByID(ID_MAIN_NurseConfigColor5)->setBackgroundColor(0xFFC0C0C0);
  604. // pListItem->findSubItemByID(ID_MAIN_NurseConfig1)->setText("");
  605. // pListItem->findSubItemByID(ID_MAIN_NurseConfig2)->setText("");
  606. // pListItem->findSubItemByID(ID_MAIN_NurseConfig3)->setText("");
  607. // pListItem->findSubItemByID(ID_MAIN_NurseConfig4)->setText("");
  608. // pListItem->findSubItemByID(ID_MAIN_NurseConfig5)->setText("");
  609. // pListItem->findSubItemByID(ID_MAIN_NurseOption1)->setText(LANGUAGEMANAGER->getValue("None"));
  610. // pListItem->findSubItemByID(ID_MAIN_NurseOption2)->setText(LANGUAGEMANAGER->getValue("None"));
  611. // pListItem->findSubItemByID(ID_MAIN_NurseOption3)->setText(LANGUAGEMANAGER->getValue("None"));
  612. // pListItem->findSubItemByID(ID_MAIN_NurseOption4)->setText(LANGUAGEMANAGER->getValue("None"));
  613. // pListItem->findSubItemByID(ID_MAIN_NurseOption5)->setText(LANGUAGEMANAGER->getValue("None"));
  614. // }
  615. }
  616. }
  617. static void onListItemClick_BedListView(ZKListView *pListView, int index, int id) {
  618. //LOGD(" onListItemClick_ BedListView !!!\n");
  619. }
  620. static bool onButtonClick_Button1(ZKButton *pButton) {
  621. LOGD(" ButtonClick Button1 !!!\n");
  622. lightControl("DOORLED", "200F");
  623. // lightControl("CALLLED", "200F");
  624. return false;
  625. }
  626. static bool onButtonClick_Button2(ZKButton *pButton) {
  627. LOGD(" ButtonClick Button2 !!!\n");
  628. lightControl("DOORLED", "020F");
  629. // lightControl("CALLLED", "020F");
  630. return false;
  631. }
  632. static bool onButtonClick_Button3(ZKButton *pButton) {
  633. LOGD(" ButtonClick Button3 !!!\n");
  634. lightControl("DOORLED", "110F");
  635. // lightControl("CALLLED", "110F");
  636. return false;
  637. }
  638. static bool onButtonClick_Button4(ZKButton *pButton) {
  639. LOGD(" ButtonClick Button4 !!!\n");
  640. mediaPlayer.Stop();
  641. StoragePreferences::putBool(STORE_MUSIC, false);
  642. return false;
  643. }
  644. static bool onButtonClick_Button5(ZKButton *pButton) {
  645. LOGD(" ButtonClick Button5 !!!\n");
  646. mediaPlayer.Play(CONFIGMANAGER->getResFilePath("incoming_call.mp3"), "", 1000,
  647. base::MediaPlayer::PlayMode::Loop);
  648. StoragePreferences::putBool(STORE_MUSIC, true);
  649. return false;
  650. }
  651. static void onProgressChanged_SeekBarOutputVolume(ZKSeekBar *pSeekBar, int progress) {
  652. //LOGD(" ProgressChanged SeekBarOutputVolume %d !!!\n", progress);
  653. zk_audio_output_set_volume_native(progress);
  654. mTextViewOutputVolumePtr->setText(base::format("%d", progress));
  655. }