mainLogic.cc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. BabySex BabySex;
  51. Json::Value babyList;
  52. static std::string babySex = BabySex.girl; // 默认是女孩,有可能是男孩boy,也有可能是双胞胎twins,有女娃的就twins_girl,都是男娃的就twins_boy
  53. static uint32_t redLightColour = 0xFFF9C5C5;
  54. static uint32_t redDeepColour = 0xFFFEB8BF;
  55. static uint32_t buleLightColour = 0xFFD2E2F2;
  56. static uint32_t buleDeepColour = 0xFF68A5FF;
  57. static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据
  58. PartSetting partSetting;
  59. Json::Value frameRoom;
  60. Json::Value frameBed;
  61. Json::Value frameInfo; // 缓存房间名字等
  62. Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题
  63. Json::Value painterInfo;
  64. Json::Value painterInfoList;
  65. Json::Value nurseInfo;
  66. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  67. #define HELP_TIMER_HANDLE 3 // 增援的定时器id
  68. #define NURSING_TIME_HANDLE 6 // 护理的定时器id
  69. #define EVENT_TIME_HANDLE 8 // 事件定时器
  70. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  71. //======================================= udp 请示服务器信息
  72. static net::Conn* udpConn;
  73. class UdpThread: public Thread {
  74. public:
  75. static void getServerInfo(){
  76. string url = getHttpGateway() + "/ncs_url/server_info";
  77. LOGD("请求服务器信息. url = %s", url.c_str());
  78. //发起HTTP GET请求
  79. RestClient::Response r = RestClient::get(url);
  80. LOGD("请求服务器信息. result = %s", r.body.c_str());
  81. //解析json
  82. Json::Reader reader;
  83. Json::Value root;
  84. if (reader.parse(r.body, root, false)){
  85. if (root.isMember("http_local_ip")) {
  86. // http
  87. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  88. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  89. // tcp
  90. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  91. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  92. // sip
  93. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  94. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  95. serverInfo = false; // 只有请求成功了,才不需要重复请求
  96. }
  97. }
  98. }
  99. static void getDeviceInfo(){
  100. if (dataInit){
  101. getFrameInfo();
  102. getMainInfo();
  103. //getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  104. return;
  105. }
  106. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + ETHERNETMANAGER->getMacAddr();
  107. LOGD("请求设备信息. url = %s", url.c_str());
  108. //发起HTTP GET请求
  109. RestClient::Response r = RestClient::get(url);
  110. LOGD("获得设备信息. result = %s", r.body.c_str());
  111. //解析json
  112. Json::Reader reader;
  113. Json::Value root;
  114. if (reader.parse(r.body, root, false)){
  115. if (root.isMember("id")) {
  116. string partName = root["part_display"].asString();
  117. StoragePreferences::putString(STORE_PARTNAME,partName);
  118. NavibarSetPartName(partName);
  119. //设备
  120. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  121. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  122. //SIP存储
  123. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  124. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  125. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  126. //获取科室设置
  127. string partId = root["part_id"].asString();
  128. StoragePreferences::putString(STORE_PARTID, partId);
  129. getPartSetting(partId);
  130. getVersion();
  131. setFrameInfo(root);
  132. getFrameRoom(root["frame_id"].asInt());
  133. }
  134. }
  135. }
  136. // 将空间相关的数据缓存起来
  137. static void setFrameInfo(Json::Value deviceInfo) {
  138. frameInfo["frame_id"] = deviceInfo["frame_id"].asInt();
  139. frameInfo["full_name"] = deviceInfo["full_name"].asString();
  140. frameInfo["part_id"] = deviceInfo["part_id"].asInt();
  141. getFrameInfo();
  142. getFrameRoom(deviceInfo["frame_id"].asInt());
  143. }
  144. // 读取空间缓存的数据
  145. static void getFrameInfo() {
  146. mRoomNameTextViewPtr->setText(frameInfo["full_name"].asString());
  147. }
  148. static void getFrameRoom(int frame_id) {
  149. string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id);
  150. LOGD("请求房间信息. url = %s", url.c_str());
  151. //发起HTTP GET请求
  152. RestClient::Response r = RestClient::get(url);
  153. LOGD("获得房间信息. result = %s", r.body.c_str());
  154. //解析json
  155. Json::Reader reader;
  156. Json::Value root;
  157. if (reader.parse(r.body, root, false)){
  158. frameRoom = root;
  159. frameBed = root["frame_bed_list"][0];
  160. babyList = frameBed["frame_bed_relative_vos"];
  161. if (babyList.size() > 1) {
  162. int boysexInt = 0;
  163. for (int i = 0; i < 2; i++) {
  164. boysexInt += babyList[i]["relative_sex"].asInt();
  165. }
  166. if (boysexInt > 1) {
  167. babySex = BabySex.twins_boy;
  168. LOGD("双胞胎男孩");
  169. }
  170. else if (boysexInt == 1) {
  171. babySex = BabySex.twins_boy_and_girl;
  172. LOGD("龙凤胎");
  173. }
  174. else {
  175. babySex = BabySex.twins_girl;
  176. LOGD("双胞胎女孩");
  177. }
  178. }
  179. else if (babyList.size() == 1) {
  180. if (babyList[0]["relative_sex"].asInt() == 1) { // 如果是女孩
  181. babySex = BabySex.boy;
  182. LOGD("单个男孩");
  183. } else {
  184. babySex = BabySex.girl;
  185. LOGD("单个女孩");
  186. }
  187. }
  188. getMainInfo();
  189. }
  190. // int customerId = frameBed["customer_id"].asInt();
  191. // if (customerId != 0) {
  192. // getClerk(frameBed["customer_id"].asInt());
  193. // }
  194. }
  195. static void getClerk(int customerId) {
  196. // string url = getHttpGateway() + "/deviceRoom/get_clerk_by_customer_id/" + to_string(customerId);
  197. // LOGD("请求护士信息. url = %s", url.c_str());
  198. // //发起HTTP GET请求
  199. // RestClient::Response r = RestClient::get(url);
  200. // LOGD("获得护士信息. result = %s", r.body.c_str());
  201. // //解析json
  202. // Json::Reader reader;
  203. // Json::Value root;
  204. // if (reader.parse(r.body, root, false)){
  205. // nurseInfo = root;
  206. // string clerkName = nurseInfo["clerk_name"].asString();
  207. // if (clerkName != "") {
  208. // mNurseNameTextViewPtr->setText(nurseInfo["clerk_name"].asCString());
  209. // }
  210. // }
  211. //
  212. // if (babySex == BabySex.girl || babySex == BabySex.twins_girl) {
  213. // // 护士
  214. // mNursePhotoPainterPtr->setBackgroundPic("nurse_red.png");
  215. // mNurseNameTextViewPtr->setTextColor(redDeepColour);
  216. // }
  217. // else {
  218. // // 护士
  219. // mNursePhotoPainterPtr->setBackgroundPic("nurse_blue.png");
  220. // mNurseNameTextViewPtr->setTextColor(buleDeepColour);
  221. //
  222. // }
  223. }
  224. static void getMainInfo() {
  225. string customerName = frameBed["customer_name"].asString();
  226. if (customerName == "") {
  227. return;
  228. }
  229. string customerAge = frameBed["customer_age"].asString();
  230. string customerAgeUnit = frameBed["customer_age_unit"].asString();
  231. string customerAndAge = customerName + " " + customerAge + customerAgeUnit;
  232. mCustomerNameAndAgeTextViewPtr->setText(customerAndAge);
  233. string inDateStr = LANGUAGEMANAGER->getValue("InTime");
  234. string inDate = frameBed["customer_in_date"].asString();
  235. if (inDate != "") {
  236. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(inDate, 8);
  237. inDate = pDate;
  238. }
  239. mInDateTextViewPtr->setText(inDateStr + inDate);
  240. string outDateStr = LANGUAGEMANAGER->getValue("OutTime");
  241. string outDate = frameBed["customer_out_date"].asString();
  242. if (outDate != "") {
  243. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(outDate, 8);
  244. outDate = pDate;
  245. }
  246. if (outDate == "") {
  247. outDate = "0000-00-00";
  248. }
  249. mOutDateTextViewPtr->setText(outDateStr + outDate);
  250. if (babySex == BabySex.girl || babySex == BabySex.twins_girl) {
  251. // 背景
  252. mMainPainterPtr->setBackgroundColor(redDeepColour);
  253. mRoomNameTextViewPtr->setTextColor(redDeepColour);
  254. mCustomerInfoTextViewPtr->setBackgroundPic("main/infoBg_red.png");
  255. mCustomerNameTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_red.png");
  256. mCustomerAgeTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_red.png");
  257. mBabyInfoTextViewPtr->setBackgroundPic("main/infoBg_red.png");
  258. mBabyNameTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_red.png");
  259. mBabySexTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_red.png");
  260. // 设置科室名称和时间
  261. setStatusbarBdColor(redDeepColour);
  262. if (babyList.size() == 0) {
  263. return;
  264. }
  265. if (babySex == BabySex.girl) { // 只有一个女孩的时候
  266. // 主图
  267. mBabyPicRightPainterPtr->setBackgroundPic("/main/nv_right.png");
  268. mBabyPicRightPainterPtr->setVisible(true);
  269. mBabyPicLeftPainterPtr->setVisible(false);
  270. }
  271. else { // 双胞胎女孩
  272. // 主图
  273. mBabyPicRightPainterPtr->setBackgroundPic("/main/nv_right.png");
  274. mBabyPicRightPainterPtr->setVisible(true);
  275. mBabyPicLeftPainterPtr->setBackgroundPic("/main/nv_left.png");
  276. mBabyPicLeftPainterPtr->setVisible(true);
  277. }
  278. }
  279. else {
  280. // 背景
  281. mMainPainterPtr->setBackgroundColor(buleDeepColour);
  282. mRoomNameTextViewPtr->setTextColor(buleDeepColour);
  283. mCustomerInfoTextViewPtr->setBackgroundPic("main/infoBg_blue.png");
  284. mCustomerNameTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_blue.png");
  285. mCustomerAgeTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_blue.png");
  286. mBabyInfoTextViewPtr->setBackgroundPic("main/infoBg_blue.png");
  287. mBabyNameTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_blue.png");
  288. mBabySexTitleTextViewPtr->setBackgroundPic("/main/infoTitleBg_blue.png");
  289. // 设置科室名称和时间
  290. setStatusbarBdColor(buleDeepColour);
  291. if (babyList.size() == 0) {
  292. return;
  293. }
  294. if (babySex == BabySex.boy) { // 只有一个男孩
  295. // 主图
  296. mBabyPicRightPainterPtr->setBackgroundPic("/main/nan_right.png");
  297. mBabyPicRightPainterPtr->setVisible(true);
  298. mBabyPicLeftPainterPtr->setVisible(false);
  299. }
  300. else if (babySex == BabySex.twins_boy) { // 双胞胎男孩
  301. // 主图
  302. mBabyPicRightPainterPtr->setBackgroundPic("/main/nan_right.png");
  303. mBabyPicRightPainterPtr->setVisible(true);
  304. mBabyPicLeftPainterPtr->setBackgroundPic("/main/nan_left.png");
  305. mBabyPicLeftPainterPtr->setVisible(true);
  306. }
  307. else if (babySex == BabySex.twins_boy_and_girl) { // 龙凤胎
  308. // 主图
  309. mBabyPicRightPainterPtr->setBackgroundPic("/main/nv_right.png");
  310. mBabyPicRightPainterPtr->setVisible(true);
  311. mBabyPicLeftPainterPtr->setBackgroundPic("/main/nan_left.png");
  312. mBabyPicLeftPainterPtr->setVisible(true);
  313. }
  314. }
  315. }
  316. static void getPartSetting(string partId){
  317. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  318. LOGD("请求科室信息. url = %s", url.c_str());
  319. //发起HTTP GET请求
  320. RestClient::Response r = RestClient::get(url);
  321. LOGD("获得科室信息. result = %s", r.body.c_str());
  322. //解析json
  323. Json::Reader reader;
  324. Json::Value root;
  325. if (reader.parse(r.body, root, false)){
  326. partSetting.partId = root["part_id"].asInt();
  327. partSetting.dayStart = root["day_start"].asString();
  328. partSetting.dayLight = root["day_light"].asInt();
  329. partSetting.dayVol = root["day_vol"].asInt();
  330. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  331. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  332. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  333. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  334. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  335. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  336. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  337. partSetting.nightStart = root["night_start"].asString();
  338. partSetting.nightLight = root["night_light"].asInt();
  339. partSetting.nightVol = root["night_vol"].asInt();
  340. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  341. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  342. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  343. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  344. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  345. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  346. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  347. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  348. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  349. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  350. partSetting.sipOvertime = root["sip_overtime"].asInt();
  351. partSetting.transferDuration = root["transfer_duration"].asInt();
  352. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  353. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  354. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  355. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  356. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  357. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  358. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  359. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  360. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  361. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  362. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  363. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  364. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  365. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  366. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  367. partSetting.doctorTitle = root["doctor_title"].asString();
  368. partSetting.doctorValid = root["doctor_valid"].asInt();
  369. partSetting.nurseTitle = root["nurse_title"].asString();
  370. partSetting.nurseValid = root["nurse_valid"].asInt();
  371. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  372. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  373. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  374. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  375. partSetting.upSeconds = root["up_seconds"].asInt();
  376. partSetting.autoAccept = root["auto_accept"].asInt();
  377. partSetting.eventForward = root["event_forward"].asInt();
  378. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  379. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  380. partSetting.qrUrl = root["qr_url"].asString();
  381. partSetting.screenLight = root["screen_light"].asInt();
  382. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  383. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  384. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  385. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  386. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  387. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  388. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  389. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  390. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  391. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  392. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  393. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  394. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  395. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  396. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  397. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  398. dataInit = true;
  399. }
  400. }
  401. static void getVersion() {
  402. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  403. std::string content_type = std::string("application/json");
  404. LOGD("请求版本信息. url = %s", url.c_str());
  405. //发起HTTP POST请求
  406. RestClient::Response r = RestClient::post(url, content_type, "");
  407. if (r.code != 200) {
  408. LOGD("请求版本信息-> 错误代码: %d", r.code);
  409. return;
  410. }
  411. LOGD("获得版本信息. result = %s", r.body.c_str());
  412. //解析json
  413. Json::Reader reader;
  414. Json::Value root;
  415. if(reader.parse(r.body, root, false)) {
  416. int currentVersionNo = getVersionNo();
  417. int responseVersionNo = root["version_no"].asInt();
  418. std::string responseVersion = root["version_code"].asString();
  419. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  420. if (currentVersionNo < responseVersionNo) {
  421. Intent* intent = new Intent();
  422. intent->putExtra(appUpdate, "true");
  423. EASYUICONTEXT->openActivity("updateActivity", intent);
  424. }
  425. }
  426. }
  427. /**
  428. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  429. * return true 继续线程
  430. * false 退出线程
  431. */
  432. virtual bool readyToRun() {
  433. LOGD("Thread 已经创建完成");
  434. return true;
  435. }
  436. /**
  437. * 线程循环函数
  438. *
  439. * return true 继续线程循环
  440. * false 推出线程
  441. */
  442. virtual bool threadLoop() {
  443. LOGD("线程循环函数");
  444. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  445. if (exitPending()) {
  446. return false;
  447. }
  448. udpConn = net::Dial("udp", "192.168.1.255:10010");
  449. if (udpConn) {
  450. byte buf[1024] = {0};
  451. const char* req = "search_server";
  452. //发送
  453. udpConn->Write((byte*)req, strlen(req));
  454. while (true && !exitPending()) {
  455. //读取,超时10*1000毫秒
  456. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  457. if (n > 0) {
  458. buf[n] = 0;
  459. char serverStr[1024];
  460. sprintf(serverStr,"%s",buf);
  461. LOGD("读取 %d字节: %s", n, serverStr);
  462. //解析json
  463. Json::Reader reader;
  464. Json::Value root;
  465. if (reader.parse(serverStr, root, false)){
  466. if (root.isMember("success") && root["success"].asBool()){
  467. serverIP = root["data"]["third_server"].asString();
  468. serverHttpPort = root["data"]["third_server_port"].asInt();
  469. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  470. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  471. //先获取服务器信息
  472. //getServerInfo();
  473. //就当在获取服务器信息完成后获取用户信息,这里测试用
  474. //getCustomerInfo();
  475. //退出UDP线程
  476. pthread_exit(NULL);
  477. break;
  478. }
  479. }
  480. } else if (n == 0) {
  481. LOGD("连接正常断开");
  482. break;
  483. } else if (n == net::E_TIMEOUT) {
  484. udpConn->Write((byte*)req, strlen(req));
  485. LOGD("读取超时");
  486. } else {
  487. LOGD("出错");
  488. break;
  489. }
  490. }
  491. //关闭连接
  492. udpConn->Close();
  493. //释放内存
  494. delete udpConn;
  495. udpConn = NULL;
  496. }
  497. //返回真,继续下次线程循环
  498. return true;
  499. }
  500. };
  501. static UdpThread udp_thread;
  502. int getNowTime() {
  503. struct tm *t = TimeHelper::getDateTime();
  504. char timeStr[50];
  505. string formatStr = "%02d:%02d:%02d";
  506. sprintf(timeStr, formatStr.c_str(), t->tm_hour,t->tm_min,t->tm_sec);
  507. int hour, minute, second;// 定义时间的各个int临时变量。
  508. sscanf(timeStr, "%d:%d:%d", &hour, &minute, &second);
  509. int time = hour * 60 * 60 + minute * 60 + second;
  510. return time;
  511. }
  512. Json::Value getPainterInfoList() {
  513. return painterInfoList;
  514. }
  515. void addPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, int endTime) {
  516. // 将设备id,颜色,展示的信息,时间存放起来
  517. painterInfo["deviceId"] = deviceId;
  518. // painterInfo["bgColor"] = bgColor + "";
  519. painterInfo["bgColor"] = bgColor;
  520. painterInfo["msg"] = msg;
  521. painterInfo["type"] = type;
  522. painterInfo["endTime"] = getNowTime() + endTime;
  523. painterInfoList.append(painterInfo);
  524. }
  525. bool removePainterInfo(int deviceId, const std::string type) {
  526. // 获取painterInfoList的长度
  527. int size = painterInfoList.size();
  528. if (size == 0) { // 如果为空了,那就代表painterInfoList没有值,直接返回
  529. return false;
  530. }
  531. // 如果painterInfoList里有对应的deviceId,那就需要先删除原本的,然后再从头添加新的
  532. int removeIndex = -1;
  533. for (int i = 0; i < painterInfoList.size(); i++) {
  534. LOGD("deviceId == %d", deviceId);
  535. LOGD("painterInfoList.deviceId == %d", painterInfoList[i]["deviceId"].asInt());
  536. LOGD("type == %s", type.c_str());
  537. LOGD("painterInfoList.type == %s", painterInfoList[i]["type"].asCString());
  538. if (painterInfoList[i]["deviceId"].asInt() == deviceId && painterInfoList[i]["type"].asString() == type) {
  539. removeIndex = i;
  540. }
  541. }
  542. if (removeIndex != -1) {
  543. painterInfoList.removeIndex(removeIndex, &painterInfo);
  544. }
  545. return true;
  546. }
  547. // 收到tcp的时候,刷新数据
  548. void dataRefresh() {
  549. LOGD("DATA-REFRESH, 数据刷新");
  550. if (mActivityPtr == NULL) {
  551. return;
  552. }
  553. if (serverInfo) {
  554. udp_thread.getServerInfo();
  555. }
  556. dataInit = false;
  557. udp_thread.getDeviceInfo();
  558. }
  559. void getPartSetting() {
  560. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  561. }
  562. /**
  563. * 注册定时器
  564. * 填充数组用于注册定时器
  565. * 注意:id不能重复
  566. */
  567. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  568. //{0, 6000}, //定时器id=0, 时间间隔6秒
  569. //{1, 1000},
  570. };
  571. /**
  572. * 当界面构造时触发
  573. */
  574. static void onUI_init(){
  575. //udp_thread.run("this is thread name");
  576. //测试用
  577. LOGD("进入mainLogic页面, 触发 onUI_init");
  578. if(serverInfo) { // 如果是false,就是不需要
  579. udp_thread.getServerInfo();
  580. }
  581. udp_thread.getDeviceInfo();
  582. }
  583. /**
  584. * 当切换到该界面时触发
  585. */
  586. static void onUI_intent(const Intent *intentPtr) {
  587. if (intentPtr != NULL) {
  588. }
  589. }
  590. /*
  591. * 当界面显示时触发
  592. */
  593. static void onUI_show() {
  594. }
  595. /*
  596. * 当界面隐藏时触发
  597. */
  598. static void onUI_hide() {
  599. }
  600. /*
  601. * 当界面完全退出时触发
  602. */
  603. static void onUI_quit() {
  604. //pthread_exit(NULL);
  605. }
  606. /**
  607. * 串口数据回调接口
  608. */
  609. static void onProtocolDataUpdate(const SProtocolData &data) {
  610. }
  611. /**
  612. * 定时器触发函数
  613. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  614. * 参数: id
  615. * 当前所触发定时器的id,与注册时的id相同
  616. * 返回值: true
  617. * 继续运行当前定时器
  618. * false
  619. * 停止运行当前定时器
  620. */
  621. static bool onUI_Timer(int id){
  622. switch (id) {
  623. default:
  624. break;
  625. }
  626. return true;
  627. }
  628. /**
  629. * 有新的触摸事件时触发
  630. * 参数:ev
  631. * 新的触摸事件
  632. * 返回值:true
  633. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  634. * false
  635. * 触摸事件将继续传递到控件上
  636. */
  637. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  638. switch (ev.mActionStatus) {
  639. case MotionEvent::E_ACTION_DOWN://触摸按下
  640. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  641. break;
  642. case MotionEvent::E_ACTION_MOVE://触摸滑动
  643. break;
  644. case MotionEvent::E_ACTION_UP: //触摸抬起
  645. break;
  646. default:
  647. break;
  648. }
  649. return false;
  650. }
  651. static int getListItemCount_BabyInfoListView(const ZKListView *pListView) {
  652. //LOGD("getListItemCount_BabyInfoListView !\n");
  653. return babyList.size();
  654. }
  655. static void obtainListItemData_BabyInfoListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
  656. //LOGD(" obtainListItemData_ BabyInfoListView !!!\n");
  657. ZKListView::ZKListSubItem* babyName = pListItem->findSubItemByID(ID_MAIN_BabyNameSubItem);
  658. ZKListView::ZKListSubItem* babySex = pListItem->findSubItemByID(ID_MAIN_BabySexSubItem);
  659. babyName->setText(babyList[index]["relative_member_name"].asCString());
  660. int babySexInt = babyList[index]["relative_sex"].asInt();
  661. if (babySexInt == 1) {
  662. babySex->setText(LANGUAGEMANAGER->getValue("Boy"));
  663. }
  664. else if (babySexInt == 0) {
  665. babySex->setText(LANGUAGEMANAGER->getValue("Girl"));
  666. }
  667. }
  668. static void onListItemClick_BabyInfoListView(ZKListView *pListView, int index, int id) {
  669. //LOGD(" onListItemClick_ BabyInfoListView !!!\n");
  670. }