mainLogic.cc 27 KB

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