mainLogic.cc 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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 <sys/reboot.h>
  8. #include "restclient-cpp/restclient.h"
  9. #include "curl/curl.h"
  10. #include <algorithm>
  11. #include "service/BusinessConfig.h"
  12. #include "core/sip_config.h"
  13. #include "manager/LanguageManager.h"
  14. #include "core/utilities.h"
  15. #include "base/strings.hpp"
  16. #include "base/http_client.h"
  17. #include "os/UpgradeMonitor.h"
  18. #include "core/jhws.h"
  19. #include "core/update_assistant.h"
  20. #include "utils/TimeHelper.h"
  21. #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
  22. /*
  23. *此文件由GUI工具生成
  24. *文件功能:用于处理用户的逻辑相应代码
  25. *功能说明:
  26. *========================onButtonClick_XXXX
  27. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  28. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  29. *========================onSlideWindowItemClick_XXXX(int index)
  30. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  31. 如slideWindow1;index 代表按下图标的偏移值
  32. *========================onSeekBarChange_XXXX(int progress)
  33. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  34. 如SeekBar1;progress 代表当前的进度值
  35. *========================ogetListItemCount_XXXX()
  36. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  37. 如List1;返回值为当前列表的总条数
  38. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  39. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  40. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  41. *========================常用接口===============
  42. *LOGD(...) 打印调试信息的接口
  43. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  44. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  45. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  46. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  47. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  48. *
  49. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  50. */
  51. BabySex BabySex;
  52. Json::Value babyList;
  53. static std::string babySex = BabySex.girl; // 默认是女孩,有可能是男孩boy,也有可能是双胞胎twins,有女娃的就twins_girl,都是男娃的就twins_boy
  54. static int babySize = 0;
  55. static uint32_t redLightColour = 0xFFF9C5C5;
  56. static uint32_t redDeepColour = 0xFFF84D61;
  57. static uint32_t buleLightColour = 0xFFD2E2F2;
  58. static uint32_t buleDeepColour = 0xFF2F9DF1;
  59. static bool dataInit = false; // false表示需要从数据库里获取数据,true表示从缓存里获取数据
  60. PartSetting partSetting;
  61. Json::Value frameRoom;
  62. Json::Value frameBed;
  63. Json::Value frameInfo; // 缓存房间名字等
  64. Json::Value rightTitleInfo; // 缓存分机右边医生和护士标题
  65. Json::Value painterInfo;
  66. Json::Value painterInfoList;
  67. Json::Value nurseInfo;
  68. static bool serverInfo = true; // 判断是否需要从服务器获取服务器信息,第一次要,后续不要
  69. #define HELP_TIMER_HANDLE 3 // 增援的定时器id
  70. #define NURSING_TIME_HANDLE 6 // 护理的定时器id
  71. #define EVENT_TIME_HANDLE 8 // 事件定时器
  72. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  73. //======================================= udp 请示服务器信息
  74. static net::Conn* udpConn;
  75. class UdpThread: public Thread {
  76. public:
  77. static void getServerInfo(){
  78. string url = getHttpGateway() + "/ncs_url/server_info";
  79. LOGD("请求服务器信息. url = %s", url.c_str());
  80. //发起HTTP GET请求
  81. RestClient::Response r = RestClient::get(url);
  82. if (r.code != 200) {
  83. LOGD("请求服务器信息错误. 错误代码 = %d", r.code);
  84. string serverIP = StoragePreferences::getString(STORE_GATEWAY, "172.28.100.100");
  85. int serverPort = StoragePreferences::getInt(STORE_HTTP_PORT, 8006);
  86. LOGD("serverIP ===> %s", serverIP.c_str());
  87. LOGD("serverPort ===> %d", serverPort);
  88. if (!checkAddr(serverIP) || serverPort == 0) {
  89. // http
  90. StoragePreferences::putString(STORE_GATEWAY, "172.28.100.100");
  91. StoragePreferences::putInt(STORE_HTTP_PORT, 8006);
  92. lightControl("CALLLED", "000F");
  93. //重启
  94. sync();
  95. reboot(RB_AUTOBOOT);
  96. }
  97. return;
  98. }
  99. //解析json
  100. Json::Reader reader;
  101. Json::Value root;
  102. if (reader.parse(r.body, root, false)){
  103. // http
  104. StoragePreferences::putString(STORE_GATEWAY, root["http_local_ip"].asString());
  105. StoragePreferences::putInt(STORE_HTTP_PORT, root["http_port"].asInt());
  106. // tcp
  107. StoragePreferences::putString(STORE_TCP_LOCAL_IP, root["tcp_local_ip"].asString());
  108. StoragePreferences::putInt(STORE_TCP_PORT, root["tcp_port"].asInt());
  109. // sip
  110. StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString());
  111. StoragePreferences::putInt(SIP_REG_PORT, root["sip_port"].asInt());
  112. serverInfo = false; // 只有请求成功了,才不需要重复请求
  113. }
  114. }
  115. static void getDeviceInfo(){
  116. if (dataInit){
  117. getFrameInfo();
  118. getMainInfo();
  119. //getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  120. return;
  121. }
  122. string url = getHttpGateway() + "/deviceRoom/get_device_by_eth_mac/" + ETHERNETMANAGER->getMacAddr();
  123. LOGD("请求设备信息. url = %s", url.c_str());
  124. //发起HTTP GET请求
  125. RestClient::Response r = RestClient::get(url);
  126. LOGD("获得设备信息. result = %s", r.body.c_str());
  127. //解析json
  128. Json::Reader reader;
  129. Json::Value root;
  130. if (reader.parse(r.body, root, false)){
  131. string partName = root["part_display"].asString();
  132. StoragePreferences::putString(STORE_PARTNAME,partName);
  133. NavibarSetPartName(partName);
  134. //设备
  135. StoragePreferences::putInt(STORE_DEVICE_ID, root["id"].asInt());
  136. StoragePreferences::putInt(STORE_DEVICE_TYPE, root["device_type"].asInt());
  137. //SIP存储
  138. // StoragePreferences::putString(SIP_REG_DOMAIN, root["sip_ip"].asString()); // 应该去找配置文件里的sip-ip
  139. StoragePreferences::putString(SIP_REG_ACCOUNT,root["sip_id"].asString());
  140. StoragePreferences::putString(SIP_REG_PASSWORD, root["sip_password"].asString());
  141. //获取科室设置
  142. string partId = root["part_id"].asString();
  143. StoragePreferences::putString(STORE_PARTID, partId);
  144. getPartSetting(partId);
  145. getVersion();
  146. setFrameInfo(root);
  147. getFrameRoom(root["frame_id"].asInt());
  148. }
  149. else {
  150. babySex = StoragePreferences::getString(STORE_BABY_SEX, babySex);
  151. getFrameInfo();
  152. getMainInfo();
  153. setClerk("");
  154. }
  155. }
  156. // 将空间相关的数据缓存起来
  157. static void setFrameInfo(Json::Value deviceInfo) {
  158. frameInfo["frame_id"] = deviceInfo["frame_id"].asInt();
  159. frameInfo["full_name"] = deviceInfo["full_name"].asString();
  160. frameInfo["part_id"] = deviceInfo["part_id"].asInt();
  161. getFrameInfo();
  162. getFrameRoom(deviceInfo["frame_id"].asInt());
  163. }
  164. // 读取空间缓存的数据
  165. static void getFrameInfo() {
  166. string farmeName = "";
  167. if (frameInfo.isMember("full_name")) {
  168. farmeName = frameInfo["full_name"].asString();
  169. }
  170. if (farmeName != "") {
  171. StoragePreferences::putString(STORE_FRAME_NAME, farmeName);
  172. }
  173. else {
  174. farmeName = StoragePreferences::getString(STORE_FRAME_NAME, "");
  175. }
  176. mRoomNamePtr->setText(farmeName);
  177. }
  178. static void getFrameRoom(int frame_id) {
  179. string url = getHttpGateway() + "/deviceRoom/get_frame_room/" + to_string(frame_id);
  180. LOGD("请求房间信息. url = %s", url.c_str());
  181. //发起HTTP GET请求
  182. RestClient::Response r = RestClient::get(url);
  183. LOGD("获得房间信息. result = %s", r.body.c_str());
  184. //解析json
  185. Json::Reader reader;
  186. Json::Value root;
  187. if (reader.parse(r.body, root, false)){
  188. frameRoom = root;
  189. frameBed = root["frame_bed_list"][0];
  190. babyList = frameBed["frame_bed_relative_vos"];
  191. babySize = babyList.size();
  192. StoragePreferences::putInt(STORE_BABY_LIST_SIZE, babySize);
  193. if (babySize > 1) {
  194. int boysexInt = 0;
  195. for (int i = 0; i < 2; i++) {
  196. boysexInt += babyList[i]["relative_sex"].asInt();
  197. }
  198. if (boysexInt > 1) {
  199. babySex = BabySex.twins_boy;
  200. LOGD("双胞胎男孩");
  201. }
  202. else if (boysexInt == 1) {
  203. babySex = BabySex.twins_boy_and_girl;
  204. LOGD("龙凤胎");
  205. }
  206. else {
  207. babySex = BabySex.twins_girl;
  208. LOGD("双胞胎女孩");
  209. }
  210. }
  211. else if (babyList.size() == 1) {
  212. if (babyList[0]["relative_sex"].asInt() == 1) { // 如果是女孩
  213. babySex = BabySex.boy;
  214. LOGD("单个男孩");
  215. } else {
  216. babySex = BabySex.girl;
  217. LOGD("单个女孩");
  218. }
  219. }
  220. StoragePreferences::putString(STORE_BABY_SEX, babySex);
  221. getMainInfo();
  222. }
  223. int customerId = frameBed["customer_id"].asInt();
  224. if (customerId != 0) {
  225. getClerk(frameBed["customer_id"].asInt());
  226. }
  227. }
  228. static void setClerk(string clerkName) {
  229. if (clerkName != "") {
  230. StoragePreferences::putString(STORE_NURSE_NAME, clerkName);
  231. }
  232. else {
  233. clerkName = StoragePreferences::getString(STORE_NURSE_NAME, "");
  234. }
  235. mNurseNameTextViewPtr->setText(clerkName);
  236. }
  237. static void getClerk(int customerId) {
  238. string url = getHttpGateway() + "/deviceRoom/get_clerk_by_customer_id/" + to_string(customerId);
  239. LOGD("请求护士信息. url = %s", url.c_str());
  240. //发起HTTP GET请求
  241. RestClient::Response r = RestClient::get(url);
  242. LOGD("获得护士信息. result = %s", r.body.c_str());
  243. //解析json
  244. Json::Reader reader;
  245. Json::Value root;
  246. if (reader.parse(r.body, root, false)){
  247. nurseInfo = root;
  248. string clerkName = nurseInfo["clerk_name"].asString();
  249. setClerk(clerkName);
  250. }
  251. }
  252. static void getMainInfo() {
  253. string customerName = "";
  254. if (frameBed.isMember("customer_name")) {
  255. customerName = frameBed["customer_name"].asString();
  256. }
  257. if (customerName == "") {
  258. customerName = StoragePreferences::getString(STORE_CUSTOMER_NAME, "");
  259. if (customerName == "") {
  260. return;
  261. }
  262. }
  263. else {
  264. StoragePreferences::putString(STORE_CUSTOMER_NAME, customerName);
  265. }
  266. mCustomerNameTextViewPtr->setText(customerName);
  267. string descText = "";
  268. if (frameBed.isMember("customer_illness_desc")) {
  269. descText = frameBed["customer_illness_desc"].asString();
  270. }
  271. if (descText != "") {
  272. StoragePreferences::putString(STORE_CUSTOMER_DESC, descText);
  273. mDescTextViewPtr->setText(descText);
  274. mDescTextViewPtr->setVisible(true);
  275. }
  276. else {
  277. descText = StoragePreferences::getString(STORE_CUSTOMER_DESC, "");
  278. if (descText != "") {
  279. mDescTextViewPtr->setText(descText);
  280. mDescTextViewPtr->setVisible(true);
  281. }
  282. }
  283. string inDateStr = LANGUAGEMANAGER->getValue("InTime");
  284. string inDate = "";
  285. if (frameBed.isMember("customer_in_date")) {
  286. inDate = frameBed["customer_in_date"].asString();
  287. }
  288. if (inDate != "") {
  289. StoragePreferences::putString(STORE_CUSTOMER_IN_DATE, inDate);
  290. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(inDate, 8, "%d-%02d-%02d");
  291. inDate = pDate;
  292. }
  293. else {
  294. inDate = StoragePreferences::getString(STORE_CUSTOMER_IN_DATE, "");
  295. if (inDate != "") {
  296. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(inDate, 8, "%d-%02d-%02d");
  297. inDate = pDate;
  298. }
  299. }
  300. mInDateTextViewPtr->setText(inDateStr + inDate);
  301. string outDateStr = LANGUAGEMANAGER->getValue("OutTime");
  302. string outDate = "";
  303. if (frameBed.isMember("customer_out_date")) {
  304. outDate = frameBed["customer_out_date"].asString();
  305. }
  306. if (outDate != "") {
  307. StoragePreferences::putString(STORE_CUSTOMER_OUT_DATE, outDate);
  308. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(outDate, 8, "%d-%02d-%02d");
  309. outDate = pDate;
  310. }
  311. else {
  312. outDate = StoragePreferences::getString(STORE_CUSTOMER_OUT_DATE, "");
  313. if (outDate != "") {
  314. std::string pDate = TimeHelper::getTimeStrOnTimeDifference(outDate, 8, "%d-%02d-%02d");
  315. outDate = pDate;
  316. }
  317. else {
  318. outDate = "0000-00-00";
  319. }
  320. }
  321. mOutDateTextViewPtr->setText(outDateStr + outDate);
  322. if (babySex == BabySex.girl || babySex == BabySex.twins_girl) {
  323. // 背景
  324. mMainPainterPtr->setBackgroundColor(redLightColour);
  325. // 房间
  326. // mPainterInfoPtr->setBackgroundPic("/main/title_red.png");
  327. mPainterInfoPtr->setBackgroundColor(redDeepColour);
  328. // 用户
  329. mCustomerNameTextViewPtr->setTextColor(redDeepColour);
  330. mDescTextViewPtr->setBackgroundColor(redDeepColour);
  331. mInDateTextViewPtr->setTextColor(redDeepColour);
  332. mOutDateTextViewPtr->setTextColor(redDeepColour);
  333. mMsgPainterPtr->setBackgroundPic("/main/msg_red.png");
  334. // 护士
  335. mNursePhotoPainterPtr->setBackgroundPic("nurse_red.png");
  336. mNurseNameTextViewPtr->setTextColor(redDeepColour);
  337. // 更多
  338. mMoreButtonPtr->setTextColor(redDeepColour);
  339. // 设置科室名称和时间
  340. setPartNameAndDateColor(redDeepColour);
  341. // 设置ui3界面的颜色
  342. setUi3BgColor(redDeepColour);
  343. if (babySize == 0) {
  344. babySize = StoragePreferences::getInt(STORE_BABY_LIST_SIZE, 0);
  345. if (babySize == 0) {
  346. return;
  347. }
  348. }
  349. if (babySex == BabySex.girl) { // 只有一个女孩的时候
  350. // 主图
  351. mCustomerInfoPainterPtr->setBackgroundPic("/main/girl.png");
  352. // 婴儿姓名
  353. string babyName1 = "";
  354. string babyBir = "";
  355. if (babyList.size() > 0) {
  356. babyName1 = babyList[0]["relative_member_name"].asString();
  357. StoragePreferences::putString(STORE_BABY_NAME1, babyName1);
  358. babyBir = babyList[0]["relative_birthday"].asString();
  359. StoragePreferences::putString(STORE_BABY_BIR1, babyBir);
  360. }
  361. else {
  362. babyName1 = StoragePreferences::getString(STORE_BABY_NAME1, "");
  363. babyBir = StoragePreferences::getString(STORE_BABY_BIR1, "");
  364. }
  365. mBayNameTextViewPtr->setVisible(true);
  366. mBayNameTextViewPtr->setText(babyName1);
  367. mBayNameTextViewPtr->setTextColor(redDeepColour);
  368. // 婴儿出生日期
  369. mBabyBirTextViewPtr->setVisible(true);
  370. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  371. if (babyBir != "") {
  372. babyBir = babyBir.substr(0, 10);
  373. time_t timet = stoi(babyBir);
  374. struct tm *t = gmtime(&timet);
  375. char pDate[25];
  376. sprintf(pDate,"%d-%02d-%02d",
  377. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  378. babyBir = pDate;
  379. }
  380. babyBirStr += babyBir;
  381. mBabyBirTextViewPtr->setText(babyBirStr);
  382. mBabySexTextViewPtr->setVisible(true);
  383. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Woman"));
  384. mBabySexTextViewPtr->setBackgroundColor(redDeepColour);
  385. mBabyNameTextView2Ptr->setVisible(false);
  386. mBabyBirTextView2Ptr->setText("");
  387. mBabySexTextView2Ptr->setVisible(false);
  388. }
  389. else { // 双胞胎女孩
  390. // 主图
  391. mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_girl.png");
  392. // 婴儿姓名
  393. string babyName1 = "";
  394. string babyBir = "";
  395. if (babyList.size() > 0) {
  396. babyName1 = babyList[0]["relative_member_name"].asString();
  397. StoragePreferences::putString(STORE_BABY_NAME1, babyName1);
  398. babyBir = babyList[0]["relative_birthday"].asString();
  399. StoragePreferences::putString(STORE_BABY_BIR1, babyBir);
  400. }
  401. else {
  402. babyName1 = StoragePreferences::getString(STORE_BABY_NAME1, "");
  403. babyBir = StoragePreferences::getString(STORE_BABY_BIR1, "");
  404. }
  405. mBayNameTextViewPtr->setVisible(true);
  406. mBayNameTextViewPtr->setText(babyName1);
  407. mBayNameTextViewPtr->setTextColor(redDeepColour);
  408. // 婴儿出生日期
  409. mBabyBirTextViewPtr->setVisible(true);
  410. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  411. if (babyBir != "") {
  412. babyBir = babyBir.substr(0, 10);
  413. time_t timet = stoi(babyBir);
  414. struct tm *t = gmtime(&timet);
  415. char pDate[25];
  416. sprintf(pDate,"%d-%02d-%02d",
  417. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  418. babyBir = pDate;
  419. }
  420. babyBirStr += babyBir;
  421. mBabyBirTextViewPtr->setText(babyBirStr);
  422. mBabySexTextViewPtr->setVisible(true);
  423. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Woman"));
  424. mBabySexTextViewPtr->setBackgroundColor(redDeepColour);
  425. // 婴儿姓名
  426. string babyName2 = "";
  427. string babyBir2 = "";
  428. if (babyList.size() > 0) {
  429. babyName2 = babyList[1]["relative_member_name"].asString();
  430. StoragePreferences::putString(STORE_BABY_NAME2, babyName2);
  431. babyBir2 = babyList[1]["relative_birthday"].asString();
  432. StoragePreferences::putString(STORE_BABY_BIR2, babyBir2);
  433. }
  434. else {
  435. babyName2 = StoragePreferences::getString(STORE_BABY_NAME2, "");
  436. babyBir2 = StoragePreferences::getString(STORE_BABY_BIR2, "");
  437. }
  438. mBabyNameTextView2Ptr->setVisible(true);
  439. mBabyNameTextView2Ptr->setText(babyName2);
  440. mBabyNameTextView2Ptr->setTextColor(redDeepColour);
  441. // 婴儿出生日期
  442. mBabyBirTextView2Ptr->setVisible(true);
  443. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  444. if (babyBir2 != "") {
  445. babyBir2 = babyBir2.substr(0, 10);
  446. time_t timet = stoi(babyBir2);
  447. struct tm *t = gmtime(&timet);
  448. char pDate[25];
  449. sprintf(pDate,"%d-%02d-%02d",
  450. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  451. babyBir2 = pDate;
  452. }
  453. babyBir2Str += babyBir2;
  454. mBabyBirTextView2Ptr->setText(babyBir2Str);
  455. mBabySexTextView2Ptr->setVisible(true);
  456. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman"));
  457. mBabySexTextView2Ptr->setBackgroundColor(redDeepColour);
  458. }
  459. }
  460. else {
  461. // 背景
  462. mMainPainterPtr->setBackgroundColor(buleLightColour);
  463. // 房间
  464. // mPainterInfoPtr->setBackgroundPic("/main/title_blue.png");
  465. mPainterInfoPtr->setBackgroundColor(buleDeepColour);
  466. // 用户
  467. mCustomerNameTextViewPtr->setTextColor(buleDeepColour);
  468. mDescTextViewPtr->setBackgroundColor(buleDeepColour);
  469. mInDateTextViewPtr->setTextColor(buleDeepColour);
  470. mOutDateTextViewPtr->setTextColor(buleDeepColour);
  471. mMsgPainterPtr->setBackgroundPic("/main/msg_blue.png");
  472. // 更多
  473. mMoreButtonPtr->setTextColor(buleDeepColour);
  474. // 护士
  475. mNursePhotoPainterPtr->setBackgroundPic("nurse_blue.png");
  476. mNurseNameTextViewPtr->setTextColor(buleDeepColour);
  477. // 设置科室名称和时间
  478. setPartNameAndDateColor(buleDeepColour);
  479. // 设置ui3界面的颜色
  480. setUi3BgColor(buleDeepColour);
  481. if (babySize == 0) {
  482. babySize = StoragePreferences::getInt(STORE_BABY_LIST_SIZE, 0);
  483. if (babySize == 0) {
  484. return;
  485. }
  486. }
  487. if (babySex == BabySex.boy) { // 只有一个男孩
  488. // 主图
  489. mCustomerInfoPainterPtr->setBackgroundPic("/main/boy.png");
  490. // 婴儿姓名
  491. string babyName1 = "";
  492. string babyBir = "";
  493. if (babyList.size() > 0) {
  494. babyName1 = babyList[0]["relative_member_name"].asString();
  495. StoragePreferences::putString(STORE_BABY_NAME1, babyName1);
  496. babyBir = babyList[0]["relative_birthday"].asString();
  497. StoragePreferences::putString(STORE_BABY_BIR1, babyBir);
  498. }
  499. else {
  500. babyName1 = StoragePreferences::getString(STORE_BABY_NAME1, "");
  501. babyBir = StoragePreferences::getString(STORE_BABY_BIR1, "");
  502. }
  503. mBayNameTextViewPtr->setVisible(true);
  504. mBayNameTextViewPtr->setText(babyName1);
  505. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  506. // 婴儿出生日期
  507. mBabyBirTextViewPtr->setVisible(true);
  508. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  509. if (babyBir != "") {
  510. babyBir = babyBir.substr(0, 10);
  511. time_t timet = stoi(babyBir);
  512. struct tm *t = gmtime(&timet);
  513. char pDate[25];
  514. sprintf(pDate,"%d-%02d-%02d",
  515. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  516. babyBir = pDate;
  517. }
  518. babyBirStr += babyBir;
  519. mBabyBirTextViewPtr->setText(babyBirStr);
  520. mBabySexTextViewPtr->setVisible(true);
  521. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  522. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  523. mBabyNameTextView2Ptr->setVisible(false);
  524. mBabyBirTextView2Ptr->setText("");
  525. mBabySexTextView2Ptr->setVisible(false);
  526. }
  527. else if (babySex == BabySex.twins_boy) { // 双胞胎男孩
  528. // 主图
  529. mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_boy.png");
  530. // 婴儿姓名
  531. string babyName1 = "";
  532. string babyBir = "";
  533. if (babyList.size() > 0) {
  534. babyName1 = babyList[0]["relative_member_name"].asString();
  535. StoragePreferences::putString(STORE_BABY_NAME1, babyName1);
  536. babyBir = babyList[0]["relative_birthday"].asString();
  537. StoragePreferences::putString(STORE_BABY_BIR1, babyBir);
  538. }
  539. else {
  540. babyName1 = StoragePreferences::getString(STORE_BABY_NAME1, "");
  541. babyBir = StoragePreferences::getString(STORE_BABY_BIR1, "");
  542. }
  543. mBayNameTextViewPtr->setVisible(true);
  544. mBayNameTextViewPtr->setText(babyName1);
  545. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  546. // 婴儿出生日期
  547. mBabyBirTextViewPtr->setVisible(true);
  548. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  549. if (babyBir != "") {
  550. babyBir = babyBir.substr(0, 10);
  551. time_t timet = stoi(babyBir);
  552. struct tm *t = gmtime(&timet);
  553. char pDate[25];
  554. sprintf(pDate,"%d-%02d-%02d",
  555. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  556. babyBir = pDate;
  557. }
  558. babyBirStr += babyBir;
  559. mBabyBirTextViewPtr->setText(babyBirStr);
  560. mBabySexTextViewPtr->setVisible(true);
  561. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  562. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  563. // 婴儿姓名
  564. string babyName2 = "";
  565. string babyBir2 = "";
  566. if (babyList.size() > 0) {
  567. babyName2 = babyList[1]["relative_member_name"].asString();
  568. StoragePreferences::putString(STORE_BABY_NAME2, babyName2);
  569. babyBir2 = babyList[1]["relative_birthday"].asString();
  570. StoragePreferences::putString(STORE_BABY_BIR2, babyBir2);
  571. }
  572. else {
  573. babyName2 = StoragePreferences::getString(STORE_BABY_NAME2, "");
  574. babyBir2 = StoragePreferences::getString(STORE_BABY_BIR2, "");
  575. }
  576. mBabyNameTextView2Ptr->setVisible(true);
  577. mBabyNameTextView2Ptr->setText(babyName2);
  578. mBabyNameTextView2Ptr->setTextColor(buleDeepColour);
  579. // 婴儿出生日期
  580. mBabyBirTextView2Ptr->setVisible(true);
  581. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  582. if (babyBir2 != "") {
  583. babyBir2 = babyBir2.substr(0, 10);
  584. time_t timet = stoi(babyBir2);
  585. struct tm *t = gmtime(&timet);
  586. char pDate[25];
  587. sprintf(pDate,"%d-%02d-%02d",
  588. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  589. babyBir2 = pDate;
  590. }
  591. babyBir2Str += babyBir2;
  592. mBabyBirTextView2Ptr->setText(babyBir2Str);
  593. mBabySexTextView2Ptr->setVisible(true);
  594. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Man"));
  595. mBabySexTextView2Ptr->setBackgroundColor(buleDeepColour);
  596. }
  597. else if (babySex == BabySex.twins_boy_and_girl) { // 龙凤胎
  598. // 主图
  599. mCustomerInfoPainterPtr->setBackgroundPic("/main/twins_boy_girl.png");
  600. if (babyList.size() != 0) {
  601. for (int i = 0; i < babyList.size(); i++) {
  602. if (babyList[i]["relative_sex"].asInt() == 1) {
  603. // 婴儿姓名
  604. string babyName1 = babyList[i]["relative_member_name"].asString();
  605. StoragePreferences::putString(STORE_BABY_NAME1, babyName1);
  606. mBayNameTextViewPtr->setVisible(true);
  607. mBayNameTextViewPtr->setText(babyName1);
  608. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  609. // 婴儿出生日期
  610. mBabyBirTextViewPtr->setVisible(true);
  611. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  612. string babyBir = babyList[i]["relative_birthday"].asString();
  613. StoragePreferences::putString(STORE_BABY_BIR1, babyBir);
  614. if (babyBir != "") {
  615. babyBir = babyBir.substr(0, 10);
  616. time_t timet = stoi(babyBir);
  617. struct tm *t = gmtime(&timet);
  618. char pDate[25];
  619. sprintf(pDate,"%d-%02d-%02d",
  620. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  621. babyBir = pDate;
  622. }
  623. babyBirStr += babyBir;
  624. mBabyBirTextViewPtr->setText(babyBirStr);
  625. mBabySexTextViewPtr->setVisible(true);
  626. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  627. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  628. }
  629. else {
  630. // 婴儿姓名
  631. string babyName2 = babyList[i]["relative_member_name"].asString();
  632. StoragePreferences::putString(STORE_BABY_NAME2, babyName2);
  633. mBabyNameTextView2Ptr->setVisible(true);
  634. mBabyNameTextView2Ptr->setText(babyName2);
  635. mBabyNameTextView2Ptr->setTextColor(redDeepColour);
  636. // 婴儿出生日期
  637. mBabyBirTextView2Ptr->setVisible(true);
  638. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  639. string babyBir2 = babyList[i]["relative_birthday"].asString();
  640. StoragePreferences::putString(STORE_BABY_BIR2, babyBir2);
  641. if (babyBir2 != "") {
  642. babyBir2 = babyBir2.substr(0, 10);
  643. time_t timet = stoi(babyBir2);
  644. struct tm *t = gmtime(&timet);
  645. char pDate[25];
  646. sprintf(pDate,"%d-%02d-%02d",
  647. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  648. babyBir2 = pDate;
  649. }
  650. babyBir2Str += babyBir2;
  651. mBabyBirTextView2Ptr->setText(babyBir2Str);
  652. mBabySexTextView2Ptr->setVisible(true);
  653. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman"));
  654. mBabySexTextView2Ptr->setBackgroundColor(redDeepColour);
  655. }
  656. }
  657. }
  658. else {
  659. // 婴儿姓名
  660. string babyName1 = StoragePreferences::getString(STORE_BABY_NAME1, "");
  661. mBayNameTextViewPtr->setVisible(true);
  662. mBayNameTextViewPtr->setText(babyName1);
  663. mBayNameTextViewPtr->setTextColor(buleDeepColour);
  664. // 婴儿出生日期
  665. mBabyBirTextViewPtr->setVisible(true);
  666. string babyBirStr = LANGUAGEMANAGER->getValue("BirTime");
  667. string babyBir = StoragePreferences::getString(STORE_BABY_BIR1, "");
  668. if (babyBir != "") {
  669. babyBir = babyBir.substr(0, 10);
  670. time_t timet = stoi(babyBir);
  671. struct tm *t = gmtime(&timet);
  672. char pDate[25];
  673. sprintf(pDate,"%d-%02d-%02d",
  674. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  675. babyBir = pDate;
  676. }
  677. babyBirStr += babyBir;
  678. mBabyBirTextViewPtr->setText(babyBirStr);
  679. mBabySexTextViewPtr->setVisible(true);
  680. mBabySexTextViewPtr->setText(LANGUAGEMANAGER->getValue("Man"));
  681. mBabySexTextViewPtr->setBackgroundColor(buleDeepColour);
  682. // 婴儿姓名
  683. string babyName2 = StoragePreferences::getString(STORE_BABY_NAME2, "");
  684. mBabyNameTextView2Ptr->setVisible(true);
  685. mBabyNameTextView2Ptr->setText(babyName2);
  686. mBabyNameTextView2Ptr->setTextColor(redDeepColour);
  687. // 婴儿出生日期
  688. mBabyBirTextView2Ptr->setVisible(true);
  689. string babyBir2Str = LANGUAGEMANAGER->getValue("BirTime");
  690. string babyBir2 = StoragePreferences::getString(STORE_BABY_BIR2, "");
  691. if (babyBir2 != "") {
  692. babyBir2 = babyBir2.substr(0, 10);
  693. time_t timet = stoi(babyBir2);
  694. struct tm *t = gmtime(&timet);
  695. char pDate[25];
  696. sprintf(pDate,"%d-%02d-%02d",
  697. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday);
  698. babyBir2 = pDate;
  699. }
  700. babyBir2Str += babyBir2;
  701. mBabyBirTextView2Ptr->setText(babyBir2Str);
  702. mBabySexTextView2Ptr->setVisible(true);
  703. mBabySexTextView2Ptr->setText(LANGUAGEMANAGER->getValue("Woman"));
  704. mBabySexTextView2Ptr->setBackgroundColor(redDeepColour);
  705. }
  706. }
  707. }
  708. }
  709. static void getPartSetting(string partId){
  710. string url = getHttpGateway() + "/deviceBed/getPartSetting/" + partId;
  711. LOGD("请求科室信息. url = %s", url.c_str());
  712. //发起HTTP GET请求
  713. RestClient::Response r = RestClient::get(url);
  714. LOGD("获得科室信息. result = %s", r.body.c_str());
  715. //解析json
  716. Json::Reader reader;
  717. Json::Value root;
  718. if (reader.parse(r.body, root, false)){
  719. partSetting.partId = root["part_id"].asInt();
  720. partSetting.dayStart = root["day_start"].asString();
  721. partSetting.dayLight = root["day_light"].asInt();
  722. partSetting.dayVol = root["day_vol"].asInt();
  723. partSetting.dayRingVol = root["day_ring_vol"].asInt();
  724. partSetting.dayRingTimes = root["day_ring_times"].asInt();
  725. partSetting.dayNurseLed = root["day_nurse_led"].asInt();
  726. partSetting.dayDoorVol = root["day_door_vol"].asInt();
  727. partSetting.dayBedVol = root["day_bed_vol"].asInt();
  728. partSetting.dayTransferBoxVol = root["day_transfer_box_vol"].asInt();
  729. partSetting.dayTransferBoxSystemVol = root["day_transfer_box_system_vol"].asInt();
  730. partSetting.nightStart = root["night_start"].asString();
  731. partSetting.nightLight = root["night_light"].asInt();
  732. partSetting.nightVol = root["night_vol"].asInt();
  733. partSetting.nightRingVol = root["night_ring_vol"].asInt();
  734. partSetting.nightRingTimes = root["night_ring_times"].asInt();
  735. partSetting.nightNurseLed = root["night_nurse_led"].asInt();
  736. partSetting.nightDoorVol = root["night_door_vol"].asInt();
  737. partSetting.nightBedVol = root["night_bed_vol"].asInt();
  738. partSetting.nightTransferBoxVol = root["night_transfer_box_vol"].asInt();
  739. partSetting.nightTransferBoxSystemVol = root["night_transfer_box_system_vol"].asInt();
  740. partSetting.sleepSecondsNurse = root["sleep_seconds_nurse"].asInt();
  741. partSetting.sleepSecondsDoor = root["sleep_seconds_door"].asInt();
  742. partSetting.sleepSecondsBed = root["sleep_seconds_bed"].asInt();
  743. partSetting.sipOvertime = root["sip_overtime"].asInt();
  744. partSetting.transferDuration = root["transfer_duration"].asInt();
  745. partSetting.transferDurationLeader = root["transfer_duration_leader"].asInt();
  746. partSetting.communicationModeBed = root["communication_mode_bed"].asInt();
  747. partSetting.communicationModeNurse = root["communication_mode_nurse"].asInt();
  748. partSetting.communicationModeMobile = root["communication_model_mobile"].asInt();
  749. partSetting.customizeRoleCallFirst = root["customize_role_call_first"].asInt();
  750. partSetting.customizeRoleCallSecond = root["customize_role_call_second"].asInt();
  751. partSetting.customizeRoleCallThird = root["customize_role_call_third"].asInt();
  752. partSetting.customizeRoleCallFourth = root["customize_role_call_fourth"].asInt();
  753. partSetting.customizeRoleCallFifth = root["customize_role_call_fifth"].asInt();
  754. partSetting.customizeHospitalCallFirst = root["customize_hospital_call_first"].asInt();
  755. partSetting.customizeHospitalCallFirstName = root["customize_hospital_call_first_name"].asString();
  756. partSetting.customizeHospitalCallSecond = root["customize_hospital_call_second"].asInt();
  757. partSetting.customizeHospitalCallSecondName = root["customize_hospital_second_name"].asString();
  758. partSetting.customizeHospitalCallThird = root["customize_hospital_call_third"].asInt();
  759. partSetting.customizeHospitalCallThirdName = root["customize_hospital_call_third_name"].asString();
  760. partSetting.doctorTitle = root["doctor_title"].asString();
  761. partSetting.doctorValid = root["doctor_valid"].asInt();
  762. partSetting.nurseTitle = root["nurse_title"].asString();
  763. partSetting.nurseValid = root["nurse_valid"].asInt();
  764. partSetting.doorNurseTitle = root["door_nurse_title"].asString();
  765. partSetting.doorNurseValid = root["door_nurse_valid"].asInt();
  766. partSetting.doorNursingTitle = root["door_nursing_title"].asString();
  767. partSetting.doorNursingValid = root["door_nursing_valid"].asInt();
  768. partSetting.upSeconds = root["up_seconds"].asInt();
  769. partSetting.autoAccept = root["auto_accept"].asInt();
  770. partSetting.eventForward = root["event_forward"].asInt();
  771. partSetting.nursingColorRgb = root["nursing_color_rgb"].asString();
  772. partSetting.twoColorDoorLightValid = root["two_color_door_light_valid"].asInt();
  773. partSetting.qrUrl = root["qr_url"].asString();
  774. partSetting.screenLight = root["screen_light"].asInt();
  775. StoragePreferences::putString(STORE_DAY_START, partSetting.dayStart);
  776. StoragePreferences::putInt(STORE_DAY_LIGHT,partSetting.dayLight);
  777. StoragePreferences::putInt(STORE_DAY_VOL,partSetting.dayBedVol);
  778. StoragePreferences::putInt(STORE_DAY_RING_TIMES,partSetting.dayRingTimes);
  779. StoragePreferences::putString(STORE_NIGHT_START, partSetting.nightStart);
  780. StoragePreferences::putInt(STORE_NIGHT_LIGHT,partSetting.nightLight);
  781. StoragePreferences::putInt(STORE_NIGHT_VOL,partSetting.nightBedVol);
  782. StoragePreferences::putInt(STORE_NIGHT_RING_TIMES,partSetting.nightRingTimes);
  783. StoragePreferences::putInt(STORE_SLEEP_TIME, partSetting.sleepSecondsDoor);
  784. StoragePreferences::putString(STORE_DOCTOR_TITLE, partSetting.doctorTitle);
  785. StoragePreferences::putBool(STORE_DOCTOR_VISIBLE, partSetting.doctorValid==1);
  786. StoragePreferences::putString(STORE_NURSE_TITLE, partSetting.nurseTitle);
  787. StoragePreferences::putBool(STORE_NURSE_VISIBLE, partSetting.nurseValid==1);
  788. StoragePreferences::putString(STORE_NURSING_COLOR_RGB, partSetting.nursingColorRgb);
  789. StoragePreferences::putBool(STORE_AUDO_ANSWER, partSetting.autoAccept==1);
  790. StoragePreferences::putInt(STORE_SCREEN_LIGHT, partSetting.screenLight);
  791. dataInit = true;
  792. }
  793. }
  794. static void getVersion() {
  795. std::string url = getHttpGateway() + "/deviceRoom/get_app_version?device_type=303&part_id=" + StoragePreferences::getString(STORE_PARTID, "");
  796. std::string content_type = std::string("application/json");
  797. LOGD("请求版本信息. url = %s", url.c_str());
  798. //发起HTTP POST请求
  799. RestClient::Response r = RestClient::post(url, content_type, "");
  800. if (r.code != 200) {
  801. LOGD("请求版本信息-> 错误代码: %d", r.code);
  802. return;
  803. }
  804. LOGD("获得版本信息. result = %s", r.body.c_str());
  805. //解析json
  806. Json::Reader reader;
  807. Json::Value root;
  808. if(reader.parse(r.body, root, false)) {
  809. int currentVersionNo = getVersionNo();
  810. int responseVersionNo = root["version_no"].asInt();
  811. std::string responseVersion = root["version_code"].asString();
  812. LOGD("服务器版本 : %s %d, 当前设备版本: %d", responseVersion.c_str(), responseVersionNo, currentVersionNo);
  813. if (currentVersionNo < responseVersionNo) {
  814. Intent* intent = new Intent();
  815. intent->putExtra(appUpdate, "true");
  816. EASYUICONTEXT->openActivity("DeviceUpdateActivity", intent);
  817. }
  818. }
  819. }
  820. /**
  821. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  822. * return true 继续线程
  823. * false 退出线程
  824. */
  825. virtual bool readyToRun() {
  826. LOGD("Thread 已经创建完成");
  827. return true;
  828. }
  829. /**
  830. * 线程循环函数
  831. *
  832. * return true 继续线程循环
  833. * false 推出线程
  834. */
  835. virtual bool threadLoop() {
  836. LOGD("线程循环函数");
  837. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  838. if (exitPending()) {
  839. return false;
  840. }
  841. udpConn = net::Dial("udp", "192.168.1.255:10010");
  842. if (udpConn) {
  843. byte buf[1024] = {0};
  844. const char* req = "search_server";
  845. //发送
  846. udpConn->Write((byte*)req, strlen(req));
  847. while (true && !exitPending()) {
  848. //读取,超时10*1000毫秒
  849. int n = udpConn->Read(buf, sizeof(buf) - 1, 10*1000);
  850. if (n > 0) {
  851. buf[n] = 0;
  852. char serverStr[1024];
  853. sprintf(serverStr,"%s",buf);
  854. LOGD("读取 %d字节: %s", n, serverStr);
  855. //解析json
  856. Json::Reader reader;
  857. Json::Value root;
  858. if (reader.parse(serverStr, root, false)){
  859. if (root.isMember("success") && root["success"].asBool()){
  860. serverIP = root["data"]["third_server"].asString();
  861. serverHttpPort = root["data"]["third_server_port"].asInt();
  862. StoragePreferences::putString(STORE_GATEWAY, serverIP);
  863. StoragePreferences::putInt(STORE_HTTP_PORT, serverHttpPort);
  864. //先获取服务器信息
  865. //getServerInfo();
  866. //就当在获取服务器信息完成后获取用户信息,这里测试用
  867. //getCustomerInfo();
  868. //退出UDP线程
  869. pthread_exit(NULL);
  870. break;
  871. }
  872. }
  873. } else if (n == 0) {
  874. LOGD("连接正常断开");
  875. break;
  876. } else if (n == net::E_TIMEOUT) {
  877. udpConn->Write((byte*)req, strlen(req));
  878. LOGD("读取超时");
  879. } else {
  880. LOGD("出错");
  881. break;
  882. }
  883. }
  884. //关闭连接
  885. udpConn->Close();
  886. //释放内存
  887. delete udpConn;
  888. udpConn = NULL;
  889. }
  890. //返回真,继续下次线程循环
  891. return true;
  892. }
  893. };
  894. static UdpThread udp_thread;
  895. int getNowTime() {
  896. struct tm *t = TimeHelper::getDateTime();
  897. char timeStr[50];
  898. string formatStr = "%02d:%02d:%02d";
  899. sprintf(timeStr, formatStr.c_str(), t->tm_hour,t->tm_min,t->tm_sec);
  900. int hour, minute, second;// 定义时间的各个int临时变量。
  901. sscanf(timeStr, "%d:%d:%d", &hour, &minute, &second);
  902. int time = hour * 60 * 60 + minute * 60 + second;
  903. return time;
  904. }
  905. Json::Value getPainterInfoList() {
  906. return painterInfoList;
  907. }
  908. void addPainterInfo(int deviceId, uint32_t bgColor, const std::string& msg, const std::string type, int endTime) {
  909. // 将设备id,颜色,展示的信息,时间存放起来
  910. painterInfo["deviceId"] = deviceId;
  911. // painterInfo["bgColor"] = bgColor + "";
  912. painterInfo["bgColor"] = bgColor;
  913. painterInfo["msg"] = msg;
  914. painterInfo["type"] = type;
  915. painterInfo["endTime"] = getNowTime() + endTime;
  916. painterInfoList.append(painterInfo);
  917. }
  918. bool removePainterInfo(int deviceId, const std::string type) {
  919. // 获取painterInfoList的长度
  920. int size = painterInfoList.size();
  921. if (size == 0) { // 如果为空了,那就代表painterInfoList没有值,直接返回
  922. return false;
  923. }
  924. // 如果painterInfoList里有对应的deviceId,那就需要先删除原本的,然后再从头添加新的
  925. int removeIndex = -1;
  926. for (int i = 0; i < painterInfoList.size(); i++) {
  927. LOGD("deviceId == %d", deviceId);
  928. LOGD("painterInfoList.deviceId == %d", painterInfoList[i]["deviceId"].asInt());
  929. LOGD("type == %s", type.c_str());
  930. LOGD("painterInfoList.type == %s", painterInfoList[i]["type"].asCString());
  931. if (painterInfoList[i]["deviceId"].asInt() == deviceId && painterInfoList[i]["type"].asString() == type) {
  932. removeIndex = i;
  933. }
  934. }
  935. if (removeIndex != -1) {
  936. painterInfoList.removeIndex(removeIndex, &painterInfo);
  937. }
  938. return true;
  939. }
  940. // 收到tcp的时候,刷新数据
  941. void dataRefresh() {
  942. LOGD("DATA-REFRESH, 数据刷新");
  943. if (mActivityPtr == NULL) {
  944. return;
  945. }
  946. if (serverInfo) {
  947. udp_thread.getServerInfo();
  948. }
  949. dataInit = false;
  950. udp_thread.getDeviceInfo();
  951. }
  952. void getPartSetting() {
  953. udp_thread.getPartSetting(StoragePreferences::getString(STORE_PARTID, ""));
  954. }
  955. /**
  956. * 注册定时器
  957. * 填充数组用于注册定时器
  958. * 注意:id不能重复
  959. */
  960. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  961. //{0, 6000}, //定时器id=0, 时间间隔6秒
  962. //{1, 1000},
  963. };
  964. /**
  965. * 当界面构造时触发
  966. */
  967. static void onUI_init(){
  968. //udp_thread.run("this is thread name");
  969. //测试用
  970. LOGD("进入mainLogic页面, 触发 onUI_init");
  971. if(serverInfo) { // 如果是false,就是不需要
  972. udp_thread.getServerInfo();
  973. }
  974. udp_thread.getDeviceInfo();
  975. }
  976. /**
  977. * 当切换到该界面时触发
  978. */
  979. static void onUI_intent(const Intent *intentPtr) {
  980. if (intentPtr != NULL) {
  981. }
  982. }
  983. /*
  984. * 当界面显示时触发
  985. */
  986. static void onUI_show() {
  987. }
  988. /*
  989. * 当界面隐藏时触发
  990. */
  991. static void onUI_hide() {
  992. }
  993. /*
  994. * 当界面完全退出时触发
  995. */
  996. static void onUI_quit() {
  997. //pthread_exit(NULL);
  998. }
  999. /**
  1000. * 串口数据回调接口
  1001. */
  1002. static void onProtocolDataUpdate(const SProtocolData &data) {
  1003. }
  1004. /**
  1005. * 定时器触发函数
  1006. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  1007. * 参数: id
  1008. * 当前所触发定时器的id,与注册时的id相同
  1009. * 返回值: true
  1010. * 继续运行当前定时器
  1011. * false
  1012. * 停止运行当前定时器
  1013. */
  1014. static bool onUI_Timer(int id){
  1015. switch (id) {
  1016. default:
  1017. break;
  1018. }
  1019. return true;
  1020. }
  1021. /**
  1022. * 有新的触摸事件时触发
  1023. * 参数:ev
  1024. * 新的触摸事件
  1025. * 返回值:true
  1026. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  1027. * false
  1028. * 触摸事件将继续传递到控件上
  1029. */
  1030. static bool onmainActivityTouchEvent(const MotionEvent &ev) {
  1031. switch (ev.mActionStatus) {
  1032. case MotionEvent::E_ACTION_DOWN://触摸按下
  1033. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  1034. break;
  1035. case MotionEvent::E_ACTION_MOVE://触摸滑动
  1036. break;
  1037. case MotionEvent::E_ACTION_UP: //触摸抬起
  1038. break;
  1039. default:
  1040. break;
  1041. }
  1042. return false;
  1043. }
  1044. static bool onButtonClick_MoreButton(ZKButton *pButton) {
  1045. LOGD(" ButtonClick MoreButton !!!\n");
  1046. EASYUICONTEXT->openActivity("ui3Activity");
  1047. return false;
  1048. }