startLogic.cc 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "uart/UartContext.h"
  4. #include "core/utilities.h"
  5. #include "edge/call_log.h"
  6. #include "net/tcp_client.h"
  7. #include "net/tcp_model.h"
  8. #include "net/udp_client.h"
  9. #include "net/tcp_client5084.h"
  10. #include "net/tcp_client5089.h"
  11. #include "net/NetManager.h"
  12. #include "server/http_server.h"
  13. #include "base/strings.hpp"
  14. #include "utils/GpioHelper.h"
  15. #include "utils/TimeHelper.h"
  16. #include "utils/CrcCheckUtil.h"
  17. #include "utils/BrightnessHelper.h"
  18. #include <manager/LanguageManager.h>
  19. #include <time.h>
  20. #include <thread>
  21. #include <string>
  22. #include <unistd.h>
  23. #include <sys/reboot.h>
  24. #include "service/BusinessConfig.h"
  25. #include <utils/TimeUtil.h>
  26. static bool isHelpTimerRegistered = false; //增援定时任务
  27. static bool sosTimerRegistered = true; //sos定时任务
  28. static string sosTid = "";
  29. static bool isSleepTimerRegistered = false; // 是否开启息屏定时任务
  30. static bool isSleep = false; // 是否在息屏
  31. static bool isNursing = false; // 用于启动时判断是否处于护理状态
  32. static bool isNetreset = false;
  33. static bool loraEnable = false;
  34. static bool loraSosTimeRegistered = false;
  35. static int netresetInt = 0;
  36. static string voiceCallTid = "";
  37. Json::Value sosInteraction;
  38. struct DeviceButtonFunctionTypeAndValue {
  39. string type;
  40. string value;
  41. };
  42. static std::unordered_map<string, DeviceButtonFunctionTypeAndValue> deviceButtonFunction;
  43. static bool isConnectHandle = false;
  44. static bool isConnectSos = false;
  45. static bool isTriggerKey5 = false;
  46. static bool isTriggerKey6 = false;
  47. static bool isTriggerKey7 = false;
  48. static bool isTriggerKey8 = false;
  49. static bool isTriggerKey9 = false;
  50. static bool isTriggerKey10 = false;
  51. static bool isTriggerKey11 = false;
  52. static bool isTriggerKey12 = false;
  53. static bool isTriggerKey13 = false;
  54. static bool isUdpClientWait = false;
  55. static int isUdpClientWaitCount = 0;
  56. static int timeDifference = 8;
  57. #define FUNCTION_TIMER_HANDLE 3 // 增援的定时器id
  58. #define SOS_CLICK_TIME_HANDLE 4 // sos的定时器id
  59. #define SOS_LAMP_TIME_HANDLE 5 // sos的门灯定时器id
  60. #define PART_LANGUAGE_TIME_HANDLE 7 // 暂时弃用
  61. #define EVENT_TIME_HANDLE 8 // 事件定时器
  62. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  63. #define SYS_RESTART_TIME_HANDLE 10 // 重启
  64. #define PROMPT_TIME_HANDLE 11 // 提示语
  65. #define NURSEING_TIME_HANDLE 12 // 护理
  66. #define DOOR_LIGHT_TIME_HANDLE 13 // 门灯
  67. #define SOS_TID_TIME_HANDLE 14
  68. #define KEY5_TRIGGER_TIME_HANDLE 15
  69. #define KEY6_TRIGGER_TIME_HANDLE 16
  70. #define KEY7_TRIGGER_TIME_HANDLE 17
  71. #define KEY8_TRIGGER_TIME_HANDLE 18
  72. #define KEY9_TRIGGER_TIME_HANDLE 19
  73. #define KEY10_TRIGGER_TIME_HANDLE 20
  74. #define KEY11_TRIGGER_TIME_HANDLE 21
  75. #define KEY12_TRIGGER_TIME_HANDLE 22
  76. #define KEY13_TRIGGER_TIME_HANDLE 23
  77. #define COUNTDOWN1_TIME_HANDLE 51
  78. #define COUNTDOWN2_TIME_HANDLE 52
  79. #define COUNTDOWN3_TIME_HANDLE 53
  80. #define UDP_CLIENT_TIME_HANDLE 83
  81. #define UPDATE_LIGHT_TIME_HANDLE 84
  82. #define REBOOT_TIME_HANDLE 99
  83. #define WIFI_TIME_HANDLE 100
  84. #define HTTP_SERVER_PORT 80
  85. #define goback 200
  86. #define SIP_RECONNECT_TIME_HANDLE 201
  87. static bool isMulitFunction = false;
  88. #define MULTI_FUNCTION 5089
  89. srv::HttpServer httpServer;
  90. static bool isWifiSupported = false;
  91. #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
  92. #define WIFIMANAGER NETMANAGER->getWifiManager()
  93. namespace {
  94. std::string uilogic[] = {
  95. "testActivity",
  96. "ui3Activity"
  97. };
  98. void CloseUi();
  99. int feed_dogs = 0;
  100. void PrintCallLog() {
  101. CallLogEntries entries;
  102. int ret = GetCallLog(&entries);
  103. LOGD("GetCallRecord %d", ret);
  104. for (auto r : entries) {
  105. LOGD("id=%d, uri=%s, contact=%s,duration=%d,created_at=%d",
  106. r.id, r.uri.c_str(), r.contact.c_str(), r.duration, r.created_at);
  107. }
  108. }
  109. void OnCallStateChanged(voip::Telephone* telephone, int call_id, voip::State state) {
  110. LOGD("当前呼叫状态 ===> %d", state);
  111. if (state == voip::STATE_CALL_INCOMING
  112. || state == voip::STATE_CALL_CALLING
  113. || state == voip::STATE_CALL_CONFIRMED) {
  114. voip::CallInfo info = GetTelephone()->GetCallInfo();
  115. LOGD("info.id == %d", info.id);
  116. LOGD("info.call_direction == %d", info.call_direction);
  117. LOGD("info.remote_uri == %s", info.remote_uri.c_str());
  118. LOGD("info.remote_contact == %s", info.remote_contact.c_str());
  119. LOGD("info.duration == %d", info.duration);
  120. string sipId = info.remote_uri.substr(info.remote_uri.find(":") + 1, info.remote_uri.find("@") - info.remote_uri.find(":") - 1);
  121. LOGD("sipId == %s", sipId.c_str());
  122. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  123. LOGD("=================> 类型是SIP,进入呼叫界面");
  124. Intent* intent = new Intent();
  125. intent->putExtra(callActivityType, "toCall");
  126. EASYUICONTEXT->openActivity("callActivity", intent);
  127. }
  128. else {
  129. const char* currentAppName = EASYUICONTEXT->currentAppName();
  130. string _currentAppName = currentAppName;
  131. if (_currentAppName == "callActivity") {
  132. if (sipId == "0000000000" && getCallActivityType() == "wait") {
  133. telephone->Hangup();
  134. LOGD("=================> 在通话界面,但已经在通话中,不接受广播");
  135. return;
  136. }
  137. }
  138. else if (_currentAppName == "functionActivity") {
  139. EASYUICONTEXT->closeActivity("functionActivity");
  140. }
  141. else {
  142. if (sipId != "0000000000") {
  143. telephone->Hangup();
  144. LOGD("=================> 不在通话界面,直接挂断!");
  145. return;
  146. }
  147. }
  148. LOGD("=================> 通话建立");
  149. }
  150. if (state == voip::STATE_CALL_INCOMING) {
  151. if (telephone->GetCallCount() > 1) {
  152. LOGD("call count > 1, return");
  153. telephone->Hangup(call_id, voip::SIP_STATUS_CODE_BUSY_HERE);
  154. return;
  155. }
  156. //提前显示视频
  157. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  158. telephone->Answer(call_id, voip::SIP_STATUS_CODE_PROGRESS);
  159. telephone->Answer();
  160. } else {
  161. acceptSIP();
  162. }
  163. }
  164. }
  165. if (state == voip::STATE_CALL_DISCONNECTED) {
  166. if (telephone->GetCallCount() > 1) {
  167. LOGD("call count > 1, return");
  168. return;
  169. }
  170. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  171. EASYUICONTEXT->goBack();
  172. }
  173. voip::CallInfo info = GetTelephone()->GetCallInfo();
  174. LOGD("通话结束的状态码 ===> %d", info.last_state);
  175. if (info.last_state == 404) {
  176. if (CallingStatus::instance()->busy()){
  177. callActivityFinish(CallFinishType::NOT_FOUND);
  178. }
  179. mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
  180. }
  181. else if (info.last_state == 408) {
  182. if (CallingStatus::instance()->busy()){
  183. callActivityFinish(CallFinishType::REQUEST_TIMES);
  184. }
  185. mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
  186. }
  187. else {
  188. if (CallingStatus::instance()->busy()){
  189. callActivityFinish(CallFinishType::END);
  190. }
  191. }
  192. // //保存通话记录
  193. // voip::CallInfo info = telephone->GetCallInfo(call_id);
  194. // CallLogEntry entry;
  195. // entry.uri = info.remote_uri;
  196. // entry.contact = info.remote_contact;
  197. // entry.duration = info.duration/1000;
  198. //
  199. // if (0 != PutCallLog(entry)) {
  200. // LOGE("保存通话记录失败");
  201. // }
  202. //
  203. // int n = GetCallLogCount();
  204. // if (n > CALL_LOG_COUNT_MAX) {
  205. // //超过最大通话记录条数,删除旧记录
  206. // if (0 != DeleteOldCallLog(n - CALL_LOG_COUNT_MAX)) {
  207. // LOGE("删除失败");
  208. // }
  209. // }
  210. // PrintCallLog();
  211. }
  212. }
  213. void CloseUi() {
  214. for(int i = 0; i < 2; i++){
  215. EASYUICONTEXT->closeActivity(uilogic[i].c_str());
  216. }
  217. }
  218. void setBrightness(){
  219. int dayLight = StoragePreferences::getInt(STORE_DAY_LIGHT,100);
  220. int nightLight = StoragePreferences::getInt(STORE_NIGHT_LIGHT,10);
  221. if (getIsDay()){
  222. BRIGHTNESSHELPER->setBrightness(dayLight);
  223. } else {
  224. BRIGHTNESSHELPER->setBrightness(nightLight);
  225. }
  226. }
  227. void addSipCallStateListener() {
  228. GetTelephone()->AddCallStateListener(OnCallStateChanged);
  229. }
  230. void removeSipCallStateListener() {
  231. GetTelephone()->RemoveCallStateListener(OnCallStateChanged);
  232. }
  233. }
  234. void systemRestart() {
  235. if (!isNetreset) {
  236. isNetreset = true;
  237. statusLight("000F");
  238. mActivityPtr->registerUserTimer(SYS_RESTART_TIME_HANDLE, 1000);
  239. }
  240. }
  241. void setTimeDifference() {
  242. std::string _timeZone = StoragePreferences::getString(STORE_PART_TIME_ZONE, defaultPartTimeZone);
  243. if (_timeZone == "Africa/Lome") {
  244. timeDifference = 0;
  245. }
  246. else if (_timeZone == "Africa/Luanda") {
  247. timeDifference = 1;
  248. }
  249. else if (_timeZone == "Africa/Kigali") {
  250. timeDifference = 2;
  251. }
  252. else if (_timeZone == "Europe/Moscow") {
  253. timeDifference = 3;
  254. }
  255. else if (_timeZone == "Europe/Astrakhan") {
  256. timeDifference = 4;
  257. }
  258. else if (_timeZone == "Asia/Karachi") {
  259. timeDifference = 5;
  260. }
  261. else if (_timeZone == "Asia/Dhaka") {
  262. timeDifference = 6;
  263. }
  264. else if (_timeZone == "Asia/Ho_Chi_Minh") {
  265. timeDifference = 7;
  266. }
  267. else if (_timeZone == "Asia/Seoul") {
  268. timeDifference = 9;
  269. }
  270. else if (_timeZone == "Asia/Ust-Nera") {
  271. timeDifference = 10;
  272. }
  273. else if (_timeZone == "Asia/Magadan") {
  274. timeDifference = 11;
  275. }
  276. else if (_timeZone == "Asia/Anadyr") {
  277. timeDifference = 12;
  278. }
  279. else if (_timeZone == "Pacific/Apia") {
  280. timeDifference = 13;
  281. }
  282. else if (_timeZone == "Pacific/Kiritimati") {
  283. timeDifference = 14;
  284. }
  285. else if (_timeZone == "Atlantic/Cape_Verde") {
  286. timeDifference = -1;
  287. }
  288. else if (_timeZone == "America/Noronha") {
  289. timeDifference = -2;
  290. }
  291. else if (_timeZone == "America/Sao_Paulo") {
  292. timeDifference = -3;
  293. }
  294. else if (_timeZone == "America/Montserrat") {
  295. timeDifference = -4;
  296. }
  297. else if (_timeZone == "America/Bogota") {
  298. timeDifference = -5;
  299. }
  300. else if (_timeZone == "America/Merida") {
  301. timeDifference = -6;
  302. }
  303. else if (_timeZone == "America/Creston") {
  304. timeDifference = -7;
  305. }
  306. else if (_timeZone == "Pacific/Pitcairn") {
  307. timeDifference = -8;
  308. }
  309. else if (_timeZone == "Pacific/Gambier") {
  310. timeDifference = -9;
  311. }
  312. else if (_timeZone == "Pacific/Honolulu") {
  313. timeDifference = -10;
  314. }
  315. else if (_timeZone == "Pacific/Midway") {
  316. timeDifference = -11;
  317. }
  318. }
  319. int getTimeDifference() {
  320. return timeDifference;
  321. }
  322. // 门灯还原
  323. void lightControl(std::string typeStr, std::string lightColorStr) {
  324. // 类型是门灯,并且还原成白色灯
  325. std::string heartStr;
  326. if (typeStr == "DOORLED" && lightColorStr == "000F") {
  327. //护理状态,需要还原成护理灯
  328. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  329. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  330. if (color != "" && color.size() == 3) {
  331. heartStr = "DOORLED," + color + "F";
  332. } else {
  333. heartStr = "DOORLED,010F";
  334. }
  335. }
  336. else {
  337. // 还原成无灯光的状态
  338. heartStr = "DOORLED,000F";
  339. }
  340. } else {
  341. heartStr = typeStr + "," + lightColorStr;
  342. }
  343. heartStr = "$" + heartStr + "#";
  344. LOGD("=====> the heartStr == %s", heartStr.c_str());
  345. sendSimleBySerialType(heartStr, SerialType::PANEL_BUTTON);
  346. }
  347. void loraStart() {
  348. if (!loraEnable) {
  349. loraEnable = true;
  350. string startMsg1 = "AT+FREQ=483200000,483200000,483200000,483200000\r\n";
  351. string statrMsg2 = "AT+RATE=6,6\r\n";
  352. string statrMsg3 = "AT+TXP=15\r\n";
  353. string statrMsg4 = "AT+WORKMODE=82\r\n";
  354. string statrMsg5 = "AT+WORKMODE=81\r\n";
  355. sendLoraTo(statrMsg4);
  356. sendLoraTo(startMsg1);
  357. sendLoraTo(statrMsg2);
  358. sendLoraTo(statrMsg3);
  359. sendLoraTo(statrMsg5);
  360. LOGD("启动LoRa模块");
  361. }
  362. }
  363. void loraStart(bool enable) {
  364. loraEnable = enable;
  365. loraStart();
  366. }
  367. void udpHandleMsg(byte* inBytes) {
  368. LOGD("UDP received: %s", inBytes);
  369. Json::Reader reader(Json::Features::strictMode());
  370. Json::Value root;
  371. const char* cstr = reinterpret_cast<const char*>(inBytes);
  372. if (reader.parse(cstr, root, false)){
  373. string serverIp = root["data"]["third_server"].asString();
  374. int serverPort = root["data"]["third_server_port"].asInt();
  375. StoragePreferences::putString(STORE_GATEWAY, serverIp.c_str());
  376. StoragePreferences::putInt(STORE_HTTP_PORT, serverPort);
  377. StoragePreferences::putBool(STORE_SET_SERVER_IP, true);
  378. deviceReboot();
  379. }
  380. }
  381. // 接收tcp消息
  382. void handleMsg(byte* inBytes){
  383. TcpModel tcpModel;
  384. tcpModel = getTcpModel(inBytes);
  385. LOGD("tcp model: %s, %s", tcpModel.type.c_str(), tcpModel.action.c_str());
  386. if (tcpModel.type == TcpType::OTHER) {
  387. LOGD("trans tcp json failed");
  388. }
  389. else if (tcpModel.type == TcpType::TIME) {
  390. if (tcpModel.action == TimeAction::SYNC) {
  391. string serverTime = "";
  392. if (tcpModel.data != ""){
  393. serverTime = tcpModel.data;
  394. } else {
  395. serverTime = tcpModel.json["time"].asString();
  396. }
  397. LOGD("sync time : %s", serverTime.c_str());
  398. // time_t timet = stoi(serverTime);
  399. // struct tm *t = gmtime(&timet);
  400. // char pDate[25];
  401. // sprintf(pDate,"%d-%02d-%02d %02d:%02d:%02d",
  402. // 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday,
  403. // t->tm_hour + 8,t->tm_min,t->tm_sec);
  404. // LOGD("transfered time : %s", pDate);
  405. TimeUtil::setDataTimeByTimeDifference(serverTime, timeDifference);
  406. dataRefresh();
  407. if (isNursing) {
  408. setNursingEnd();
  409. }
  410. }
  411. }
  412. else if (tcpModel.type == TcpType::REINFORCE){
  413. if (tcpModel.action == ReinforceAction::RESPONSED){
  414. //回调
  415. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  416. if (callback.tid != "0"){
  417. callback.onSuccess(tcpModel.json);
  418. }
  419. const char* currentAppName = EASYUICONTEXT->currentAppName();
  420. string _currentAppName = currentAppName;
  421. if (_currentAppName != "functionActivity") {
  422. Intent* intent = new Intent();
  423. intent->putExtra(functionWindows, "helpResonse");
  424. EASYUICONTEXT->openActivity("functionActivity", intent);
  425. } else {
  426. toFunctionActivity("");
  427. }
  428. }
  429. }
  430. else if (tcpModel.type == TcpType::DEVICE){
  431. if (tcpModel.action == DeviceAction::APP_UPDATE){ //软件升级
  432. if (isSleep) {
  433. isSleep = false;
  434. BRIGHTNESSHELPER->screenOn();
  435. }
  436. Intent* intent = new Intent();
  437. intent->putExtra(appUpdate, "true");
  438. EASYUICONTEXT->openActivity("updateActivity", intent);
  439. }
  440. else if (tcpModel.action == DeviceAction::RESTART) { // 重启设备
  441. deviceReboot();
  442. }
  443. else if (tcpModel.action == DeviceAction::REBOOT) { // 重启设备
  444. deviceReboot();
  445. }
  446. else if (tcpModel.action == DeviceAction::DEVICE_REFRESH) { // 设备刷新
  447. dataRefresh();
  448. }
  449. else if (tcpModel.action == DeviceAction::SYSTEM_SETTING) { // 修改科室设置
  450. getPartSetting();
  451. }
  452. else if (tcpModel.action == DeviceAction::SERVER_CHANGE) {
  453. StoragePreferences::putString(STORE_GATEWAY, tcpModel.json["server_ip"].asCString());
  454. StoragePreferences::putString(STORE_HTTP_PORT, tcpModel.json["server_port"].asCString());
  455. deviceReboot();
  456. }
  457. }
  458. else if (tcpModel.type == TcpType::DATA){
  459. if (tcpModel.action == DataAction::REFRESH){ // 刷新数据
  460. dataRefresh();
  461. }
  462. }
  463. else if (tcpModel.type == TcpType::VOICE){
  464. if (tcpModel.action == VoiceAction::FAILED){
  465. if (CallingStatus::instance()->busy()){
  466. callActivityFinish(CallFinishType::FAILED);
  467. }
  468. }
  469. else if (tcpModel.action == VoiceAction::SUCCESS){
  470. CallingStatus::instance()->setTcpModel(tcpModel); // 只有呼叫成功才闪红灯
  471. lightControl("DOORLED", "200F");
  472. }
  473. else if (tcpModel.action == VoiceAction::ACCEPT){
  474. if (CallingStatus::instance()->busy()){
  475. CallingStatus::instance()->setTcpModel(tcpModel);
  476. std::string toSipId = tcpModel.json["toSipId"].asString();
  477. callActivityFinish(CallFinishType::ACCEPT);
  478. //接听
  479. buildSIP(toSipId);
  480. }
  481. // 进行门灯还原
  482. lightControl("DOORLED", "000F");
  483. }
  484. else if (tcpModel.action == VoiceAction::REJECT){
  485. if (CallingStatus::instance()->busy()){
  486. callActivityFinish(CallFinishType::REJECT);
  487. // 进行门灯还原
  488. lightControl("DOORLED", "000F");
  489. }
  490. }
  491. else if (tcpModel.action == VoiceAction::CANCEL){
  492. if (CallingStatus::instance()->busy()){
  493. callActivityFinish(CallFinishType::CANCEL);
  494. }
  495. }
  496. else if (tcpModel.action == VoiceAction::CALLING){
  497. //对方忙线
  498. callActivityFinish(CallFinishType::BUSY);
  499. }
  500. else if (tcpModel.action == VoiceAction::CALL){
  501. if (getCallActivityType() == "broadcast") {
  502. callActivityFinish(CallFinishType::BROADCAST);
  503. sleep(1);
  504. }
  505. // 如果是自己呼叫自己,则直接跳过
  506. if (tcpModel.from_id == StoragePreferences::getInt(STORE_DEVICE_ID, 0)) {
  507. return;
  508. }
  509. //我方忙线判断
  510. if (CallingStatus::instance()->busy()){
  511. sendVoiceTcp(VoiceAction::CALLING, tcpModel, tcpModel.from_id);
  512. } else {
  513. CallingStatus::instance()->setTcpModel(tcpModel);
  514. //来电话了
  515. Intent* intent = new Intent();
  516. intent->putExtra(callActivityType, "toCall");
  517. EASYUICONTEXT->openActivity("callActivity", intent);
  518. }
  519. } else if (tcpModel.action == VoiceAction::HANDOFF){
  520. //判断 是否同一个对话
  521. long iId = CallingStatus::instance()->getInteractionId();
  522. if (iId > 0 && CallingStatus::instance()->busy()){
  523. long inId = tcpModel.json["id"].asInt();
  524. if (iId == inId && CallingStatus::instance()->busy()){
  525. callActivityFinish(CallFinishType::HANDOFF);
  526. }
  527. }
  528. } else if (tcpModel.action == VoiceAction::CANCEL_BY_DOOR) {
  529. if (CallingStatus::instance()->busy()){
  530. callActivityFinish(CallFinishType::CANCEL_BY_DOOR);
  531. // 进行门灯还原
  532. lightControl("DOORLED", "000F");
  533. }
  534. }
  535. else if (tcpModel.action == VoiceAction::VOICE_OFF) {
  536. if (CallingStatus::instance()->busy()) {
  537. callActivityFinish(CallFinishType::VOICE_OFF);
  538. // 进行门灯还原
  539. lightControl("DOORLED", "000F");
  540. }
  541. }
  542. else if (tcpModel.action == VoiceAction::SIP_RECONNECT) {
  543. mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
  544. }
  545. }
  546. else if (tcpModel.type == TcpType::SOS) {
  547. if (tcpModel.action == SosAction::CANCEL) {
  548. // SOS还原成无灯光的状态
  549. lightControl("ULED", "0F");
  550. // 进行门灯还原
  551. lightControl("DOORLED", "000F");
  552. statusLight("000F", StatusLightType::INIT);
  553. mActivityPtr->unregisterUserTimer(SOS_LAMP_TIME_HANDLE);
  554. }
  555. }
  556. else if (tcpModel.type == TcpType::EVENT) {
  557. if (tcpModel.action == EventAction::RESPONSE) {
  558. string data = tcpModel.json["data"].asString();
  559. string toMemberName = tcpModel.json["toMemberName"].asString();
  560. if (toMemberName != "") {
  561. string toRoleName = tcpModel.json["toRoleName"].asString();
  562. data = toMemberName + toRoleName + LANGUAGEMANAGER->getValue("EventResponse") + data;
  563. }
  564. else {
  565. data = LANGUAGEMANAGER->getValue("HostDevice") + LANGUAGEMANAGER->getValue("EventResponse") + data;
  566. }
  567. const char* currentAppName = EASYUICONTEXT->currentAppName();
  568. string _currentAppName = currentAppName;
  569. if (_currentAppName != "functionActivity") {
  570. Intent* intent = new Intent();
  571. intent->putExtra(functionWindows, "eventResponse");
  572. intent->putExtra(functionText, data);
  573. EASYUICONTEXT->openActivity("functionActivity", intent);
  574. } else {
  575. toFunctionActivity(data);
  576. }
  577. }
  578. }
  579. else if (tcpModel.type == TcpType::SIDE) {
  580. if (tcpModel.action == SideAction::NURSING) {
  581. // 将护理的interactionId存起来,用于取消护理的时候使用
  582. StoragePreferences::putString(STORE_NURSING_INTERACTION_ID, tcpModel.json["id"].asString());
  583. // 收到nursing,需要把通话给挂断了
  584. voip::CallInfo info = GetTelephone()->GetCallInfo();
  585. LOGD("info state = %d",info.state);
  586. if (info.state == voip::STATE_CALL_CALLING
  587. || info.state == voip::STATE_CALL_CALLING
  588. || info.state == voip::STATE_CALL_CONFIRMED){
  589. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  590. //只回传iId
  591. storeModel.data = storeModel.json["id"].asString();
  592. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  593. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  594. GetTelephone()->Hangup();
  595. EASYUICONTEXT->goBack();
  596. }
  597. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  598. if (color != "" && color.size() == 3) {
  599. color = color + "F";
  600. } else {
  601. color = "010F";
  602. }
  603. lightControl("DOORLED", color);
  604. }
  605. else if (tcpModel.action == SideAction::NURSING_END) {
  606. // 收到nursing_end
  607. lightControl("DOORLED", "000F");
  608. }
  609. else if (tcpModel.action == SideAction::CALL) {
  610. // 收到呼叫CALL,需要亮红灯
  611. lightControl("DOORLED", "200F");
  612. }
  613. else if (tcpModel.action == SideAction::ACCEPT) {
  614. // 进行门灯还原
  615. lightControl("DOORLED", "000F");
  616. }
  617. else if (tcpModel.action == SideAction::CANCEL) {
  618. // 进行门灯还原
  619. lightControl("DOORLED", "000F");
  620. }
  621. else if (tcpModel.action == SideAction::SOS_CALL) {
  622. // 收到SOS_CALL,需要亮红灯
  623. // 门灯亮红灯
  624. lightControl("DOORLED", "200F");
  625. statusLight("100F", StatusLightType::NO_COMMON);
  626. sosTimerRegistered = false;
  627. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  628. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  629. if (tcpModel.json["fromEthMac"].asString() == StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0")) {
  630. sosInteraction = tcpModel.json;
  631. }
  632. }
  633. else if (tcpModel.action == SideAction::SOS_CANCEL) {
  634. // 进行门灯还原
  635. lightControl("DOORLED", "000F");
  636. }
  637. else if (tcpModel.action == SideAction::SIMULATE) {
  638. TcpModel simulate;
  639. simulate.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  640. simulate.type = tcpModel.json["type"].asCString();
  641. simulate.action = tcpModel.json["action"].asCString();
  642. simulate.tid = tcpModel.json["tid"].asCString();
  643. simulate.json = tcpModel.json["data"];
  644. if (simulate.type == TcpType::VOICE) {
  645. if (simulate.action == VoiceAction::CALL) {
  646. Intent* intent = new Intent();
  647. intent->putExtra(callTid, simulate.tid);
  648. intent->putExtra(callRoleType, simulate.json["roleType"].asString());
  649. intent->putExtra(callActivityType, "fromCall");
  650. EASYUICONTEXT->openActivity("callActivity", intent);
  651. }
  652. }
  653. }
  654. }
  655. else if (tcpModel.type == TcpType::BROADCAST) {
  656. string _callActivityType = getCallActivityType();
  657. if (tcpModel.action == BroadcastAction::START) {
  658. if (_callActivityType == "wait") {
  659. LOGD("=================> 收到BROADCAST_START,目前处于空闲状态,进入广播");
  660. Intent* intent = new Intent();
  661. intent->putExtra(callActivityType, "broadcast");
  662. intent->putExtra(broadcastRoomNo, tcpModel.data);
  663. EASYUICONTEXT->openActivity("callActivity", intent);
  664. }
  665. else {
  666. LOGD("=================> 收到BROADCAST_START,目前并不处于空闲状态,无法进入广播");
  667. }
  668. }
  669. else if (tcpModel.action == BroadcastAction::STOP) {
  670. if (_callActivityType == "broadcast") {
  671. LOGD("=================> 收到BROADCAST_STOP,目前处于广播状态,退出广播");
  672. callActivityFinish(CallFinishType::BROADCAST);
  673. }
  674. else {
  675. LOGD("=================> 收到BROADCAST_STOP,目前不处于广播状态,无须退出广播");
  676. }
  677. }
  678. }
  679. else if (tcpModel.type == TcpType::COUNTDOWN) {
  680. if (tcpModel.action == CountdownAction::START) {
  681. if (tcpModel.json.isMember("id") && tcpModel.json.isMember("operationData")) {
  682. LOGD("operation_data == %s", tcpModel.json["operationData"].asCString());
  683. Json::Reader Reader;
  684. Json::Value operationData;
  685. Reader.parse(tcpModel.json["operationData"].asString(), operationData);
  686. LOGD("id == %d", tcpModel.json["id"].asInt());
  687. setCountdownItId(tcpModel.json["id"].asInt(), operationData["number"].asInt());
  688. }
  689. }
  690. }
  691. else if (tcpModel.type == TcpType::CALLBACK) {
  692. if (tcpModel.action == CallbackAction::ACK) {
  693. LOGD("CALLBACK ACK !!!!");
  694. //回调
  695. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  696. if (callback.tid != "0"){
  697. // callback.onSuccess(tcpModel.json);
  698. }
  699. }
  700. else if (tcpModel.action == CallbackAction::SUCCESS) {
  701. if (tcpModel.tid == "") {
  702. return;
  703. }
  704. //回调
  705. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  706. if (callback.tid != "0"){
  707. callback.onSuccess(tcpModel.json);
  708. }
  709. if (tcpModel.tid == sosTid && loraSosTimeRegistered) {
  710. mActivityPtr->unregisterUserTimer(SOS_TID_TIME_HANDLE);
  711. }
  712. }
  713. else if (tcpModel.action == CallbackAction::FAILED) {
  714. if (tcpModel.tid == "") {
  715. return;
  716. }
  717. //回调
  718. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  719. if (callback.tid != "0"){
  720. callback.onFalied(tcpModel.json);
  721. }
  722. if (tcpModel.tid == voiceCallTid){
  723. callActivityFinish(CallFinishType::FAILED);
  724. }
  725. else if (tcpModel.tid == sosTid && loraSosTimeRegistered) {
  726. mActivityPtr->unregisterUserTimer(SOS_TID_TIME_HANDLE);
  727. }
  728. }
  729. }
  730. }
  731. void deviceReboot() {
  732. LOGD("正在重启");
  733. const char* req = "-1";
  734. TcpClient::instance()->sendMsg(req);
  735. statusLight("000F");
  736. sync();
  737. reboot(RB_AUTOBOOT);
  738. }
  739. void loraDataSet(std::string loraDataStr, int uartNumber) {
  740. Json::Reader reader(Json::Features::strictMode());
  741. Json::Value json;
  742. if (reader.parse(loraDataStr.c_str(), json, false)) {
  743. if (json.size() > 0 && json.isMember("server")) {
  744. StoragePreferences::putString(STORE_GATEWAY, json["server"].asString());
  745. StoragePreferences::putInt(STORE_HTTP_PORT, json["port"].asInt());
  746. StoragePreferences::putString(STORE_WIFI_SSID, json["wifi"].asString());
  747. StoragePreferences::putString(STORE_WIFI_PW, json["wifi_pw"].asString());
  748. // std::string success = "$ "+ StoragePreferences::getString(STORE_MAC_ADDR, GetDeviceUid()) +"SUCCESS#"; // 暂定
  749. // const BYTE *pData = reinterpret_cast<const BYTE *>(success.c_str());
  750. // std::uint32_t len = success.size();
  751. // UartContext::sendTo(uartNumber, pData, len);
  752. Intent* intent = new Intent();
  753. intent->putExtra(functionWindows, "loraDataSet");
  754. EASYUICONTEXT->openActivity("functionActivity", intent);
  755. }
  756. }
  757. }
  758. void startTcpClient5089() {
  759. if (!isMulitFunction) {
  760. isMulitFunction = true;
  761. mActivityPtr->registerUserTimer(MULTI_FUNCTION, 30 * 1000);
  762. }
  763. }
  764. void stopTcpClient5089() {
  765. isMulitFunction = false;
  766. }
  767. void setLangeuage() {
  768. std::string deviceLanguage = StoragePreferences::getString(STORE_LANG, defaultLang);
  769. std::string partLanguage = StoragePreferences::getString(STORE_PART_LANG, defaultPartLang);
  770. if (deviceLanguage != defaultLang) {
  771. LOGD("设备自身拥有语言:%s", deviceLanguage.c_str());
  772. EASYUICONTEXT->updateLocalesCode(deviceLanguage.c_str());
  773. }
  774. else {
  775. LOGD("科室语言:%s", partLanguage.c_str());
  776. if (partLanguage == "en") {
  777. EASYUICONTEXT->updateLocalesCode("en_US");
  778. }
  779. else if (partLanguage == "es") {
  780. EASYUICONTEXT->updateLocalesCode("es_ES");
  781. }
  782. else if (partLanguage == "ru") {
  783. EASYUICONTEXT->updateLocalesCode("ru_RU");
  784. }
  785. else {
  786. EASYUICONTEXT->updateLocalesCode("zh_CN");
  787. }
  788. }
  789. }
  790. bool getSleepTimerRegistered() {
  791. return isSleepTimerRegistered;
  792. }
  793. void screenOn() {
  794. isSleep = false;
  795. BRIGHTNESSHELPER->screenOn();
  796. }
  797. // 触发定时任务
  798. void setSleepTimerRegistered(bool result) {
  799. LOGD("isSleepTimerRegistered = %d", isSleepTimerRegistered);
  800. LOGD("result = %d", result);
  801. if (mActivityPtr == NULL) {
  802. return;
  803. }
  804. if (result != isSleepTimerRegistered) { // 与定时任务不同时,才进行处理
  805. if (isSleepTimerRegistered) { // 与定时任务开关进行判断,如果定时任务开启,那就要关闭
  806. isSleepTimerRegistered = result;
  807. mActivityPtr->unregisterUserTimer(SLEEP_STRAT_TIME_HANDLE); // 关闭定时器
  808. if (isSleep) {
  809. isSleep = false;
  810. BRIGHTNESSHELPER->screenOn();
  811. }
  812. LOGD("关闭息屏");
  813. } else { // 如果定时任务关着,那就要打开
  814. isSleepTimerRegistered = result;
  815. //默认3分钟
  816. int sleepTime = StoragePreferences::getInt(STORE_SLEEP_TIME, 3);
  817. if (sleepTime > 0) {
  818. mActivityPtr->registerUserTimer(SLEEP_STRAT_TIME_HANDLE, sleepTime * 60 * 1000);
  819. LOGD("开启息屏");
  820. }
  821. }
  822. }
  823. }
  824. void setCallTid(std::string tid) {
  825. voiceCallTid = tid;
  826. }
  827. void sendSosToLora() {
  828. string sosMsg = "$" + StoragePreferences::getString(STORE_MAC_ADDR, GetDeviceUid()) + "LORA7,1F#\r\n";
  829. sendLoraTo(sosMsg, 5);
  830. }
  831. void sosCall(string sosMsg, bool isConnectServer) {
  832. if (sosTimerRegistered) {
  833. if (isConnectServer) {
  834. LOGD("TCP -> SOS_CALL");
  835. sosTid = sendSosCall(sosMsg);
  836. loraSosTimeRegistered = true;
  837. mActivityPtr->registerUserTimer(SOS_TID_TIME_HANDLE, 5* 1000);
  838. }
  839. else {
  840. LOGD("LORA -> SOS_CALL");
  841. sendSosToLora();
  842. }
  843. // SOS亮红灯
  844. lightControl("ULED", "1F");
  845. // 门灯亮红灯
  846. lightControl("DOORLED", "200F");
  847. statusLight("100F", StatusLightType::NO_COMMON);
  848. sosTimerRegistered = false;
  849. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  850. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  851. if (getCallActivityType() == "wait") {
  852. Intent* intent = new Intent();
  853. intent->putExtra(functionWindows, "sosCall");
  854. EASYUICONTEXT->openActivity("functionActivity", intent);
  855. }
  856. }
  857. }
  858. void clearDeviceButtonFunction() {
  859. deviceButtonFunction.clear();
  860. }
  861. void setDeviceButtonFunction(std::string deviceButtonFunctionStr) {
  862. LOGD("deviceButtonFunctionStr ==========> %s", deviceButtonFunctionStr.c_str());
  863. Json::Reader reader;
  864. Json::Value deviceButtonFunctionJson;
  865. if (reader.parse(deviceButtonFunctionStr, deviceButtonFunctionJson)) {
  866. for (Json::Value json : deviceButtonFunctionJson) {
  867. const std::string key = json["key"].asString();
  868. const std::string type = json["type"].asString();
  869. DeviceButtonFunctionTypeAndValue typeAndValue;
  870. typeAndValue.type = type;
  871. if (type == "EVENT") {
  872. int value = json["value"].asInt();
  873. std::stringstream valueStr;
  874. valueStr << value;
  875. typeAndValue.value = valueStr.str();
  876. LOGD("key:%s type:%s value:%d ", key.c_str(), type.c_str(), value);
  877. }
  878. else {
  879. string valueStr = json["value"].asString();
  880. typeAndValue.value = valueStr;
  881. LOGD("key:%s type:%s value:%s ", key.c_str(), type.c_str(), valueStr.c_str());
  882. }
  883. deviceButtonFunction[key] = typeAndValue;
  884. }
  885. }
  886. }
  887. void handleCall(string key, string roleType) {
  888. if (isSleep) {
  889. screenOn();
  890. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  891. return;
  892. }
  893. }
  894. if (roleType == "CANCEL") {
  895. if (getCallActivityType() == "broadcast") {
  896. callActivityFinish(CallFinishType::BROADCAST);
  897. return;
  898. }
  899. voip::CallInfo info = GetTelephone()->GetCallInfo();
  900. //拨打 或 挂断
  901. if (CallingStatus::instance()->busy()){
  902. lightControl("DOORLED", "000F");
  903. callActivityFinish(CallFinishType::A1CLICK);
  904. }
  905. }
  906. else {
  907. if (getCallActivityType() == "broadcast") {
  908. return;
  909. }
  910. else {
  911. if (StoragePreferences::getString(STORE_CUSTOMER_ID, "") != "" || StoragePreferences::getInt(STORE_EMPTY_BED_CALL, 0) == 1) {
  912. voip::CallInfo info = GetTelephone()->GetCallInfo();
  913. //拨打 或 挂断
  914. if (CallingStatus::instance()->busy()){
  915. lightControl("DOORLED", "000F");
  916. callActivityFinish(CallFinishType::A1CLICK);
  917. } else {
  918. lightControl("DOORLED", "200F");
  919. Intent* intent = new Intent();
  920. intent->putExtra(callRoleType, roleType);
  921. intent->putExtra(callActivityType, "fromCall");
  922. EASYUICONTEXT->openActivity("callActivity", intent);
  923. }
  924. }
  925. }
  926. }
  927. }
  928. void handleSosCancel(string key) {
  929. LOGD("Trigger sos cancel");
  930. if (sosInteraction > 0 && sosInteraction.isMember("id")) {
  931. sendSosCancel(sosInteraction["id"].asString());
  932. sosInteraction = Json::Value();
  933. }
  934. }
  935. void handleSos(string value) {
  936. screenOn();
  937. if (value == "SOS_CANCEL") {
  938. handleSosCancel("");
  939. }
  940. else {
  941. sosCall("", isConnectServer());
  942. }
  943. }
  944. void handleEvent(string key, string id) {
  945. if (isSleep) {
  946. screenOn();
  947. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  948. return;
  949. }
  950. }
  951. if (StoragePreferences::getString(STORE_CUSTOMER_ID, "") != "" || StoragePreferences::getInt(STORE_EMPTY_BED_CALL, 0) == 1) {
  952. std::stringstream idStr(id);
  953. int _id;
  954. idStr >> _id;
  955. Json::Value json;
  956. json["id"] = _id;
  957. sendEventClick(json);
  958. if (getCallActivityType() == "wait") {
  959. Intent* intent = new Intent();
  960. intent->putExtra(functionWindows, "eventCall");
  961. intent->putExtra(functionText, getEventMap(id));
  962. EASYUICONTEXT->openActivity("functionActivity", intent);
  963. }
  964. }
  965. }
  966. void handleReinforce(string key) {
  967. if (isSleep) {
  968. screenOn();
  969. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  970. return;
  971. }
  972. }
  973. sendReinforceCall();
  974. Intent* intent = new Intent();
  975. intent->putExtra(functionWindows, "help");
  976. EASYUICONTEXT->openActivity("functionActivity", intent);
  977. }
  978. void handleNursing(string key, string time) {
  979. if (isSleep) {
  980. screenOn();
  981. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  982. return;
  983. }
  984. }
  985. if (!StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  986. Intent* intent = new Intent();
  987. intent->putExtra(functionWindows, "nursing2");
  988. intent->putExtra(nursingTime, time);
  989. // intent->putExtra(nursingTime, "1");
  990. EASYUICONTEXT->openActivity("functionActivity", intent);
  991. }
  992. else {
  993. setNursingTime(false);
  994. }
  995. }
  996. void handleBlueCode() {
  997. if (isSleep) {
  998. screenOn();
  999. }
  1000. }
  1001. void getDeviceButtonFunction(string key) {
  1002. const char* currentAppName = EASYUICONTEXT->currentAppName();
  1003. string _currentAppName = currentAppName;
  1004. if (_currentAppName == "sipTestActivity") {
  1005. if (isSleep) {
  1006. screenOn();
  1007. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  1008. return;
  1009. }
  1010. }
  1011. setCheckbox(key);
  1012. return;
  1013. }
  1014. if (!isConnectServer()) {
  1015. sendSosToLora();
  1016. sosCall("", false);
  1017. return;
  1018. }
  1019. if (deviceButtonFunction.find(key) != deviceButtonFunction.end()) {
  1020. DeviceButtonFunctionTypeAndValue typeAndValue = deviceButtonFunction[key];
  1021. LOGD("typeAndValue.type: %s typeAndValue.value: %s", typeAndValue.type.c_str(), typeAndValue.value.c_str());
  1022. if (typeAndValue.type == "SOS") {
  1023. handleSos(typeAndValue.value);
  1024. }
  1025. else if (typeAndValue.type == "VOICE") {
  1026. handleCall(key, typeAndValue.value);
  1027. }
  1028. else if (typeAndValue.type == "EVENT") {
  1029. handleEvent(key, typeAndValue.value);
  1030. }
  1031. else if (typeAndValue.type == "REINFORCE") {
  1032. handleReinforce(key);
  1033. }
  1034. else if (typeAndValue.type == "NURSING") {
  1035. handleNursing(key, typeAndValue.value);
  1036. }
  1037. else if (typeAndValue.type == "BLUE_CODE") {
  1038. handleBlueCode();
  1039. }
  1040. }
  1041. else {
  1042. if (key == "KEY5") {
  1043. handleCall(key, "NURSE");
  1044. }
  1045. else if (key == "KEY6") {
  1046. handleCall(key, "NURSE");
  1047. }
  1048. else if (key == "KEY7" || key == "KEY;") {
  1049. handleSos(key);
  1050. }
  1051. else if (key == "KEY>") {
  1052. handleCall(key, "CANCEL");
  1053. }
  1054. else if (key == "KEY@") {
  1055. handleSosCancel(key);
  1056. }
  1057. }
  1058. }
  1059. #define WIFIMANAGER NETMANAGER->getWifiManager()
  1060. void wifiConnect() {
  1061. if (WIFIMANAGER->isSupported()) {
  1062. LOGD("检测支持wifi");
  1063. if (!WIFIMANAGER->isWifiEnable()) {
  1064. LOGD("判断wifi未开启");
  1065. WIFIMANAGER->enableWifi(true);
  1066. LOGD("启动wifi");
  1067. }
  1068. sleep(3);
  1069. if (!WIFIMANAGER->isConnected()) {
  1070. LOGD("判断wifi未连接");
  1071. WIFIMANAGER->startScan();
  1072. LOGD("扫描wifi");
  1073. sleep(3);
  1074. string ssid = "COMFAST_F371_2G";
  1075. string pw = "12345678";
  1076. WIFIMANAGER->connect(ssid, pw);
  1077. LOGD("进行wifi连接");
  1078. }
  1079. if (WIFIMANAGER->isConnected()) {
  1080. LOGD("wifi连接后");
  1081. WifiInfo* info = WIFIMANAGER->getConnectionInfo();
  1082. LOGD("info.ssid =====> %s", info->getSsid().c_str());
  1083. LOGD("info.Bssid =====> %s", info->getBssid().c_str());
  1084. LOGD("info.pwd =====> %s", info->getPasswd().c_str());
  1085. LOGD("info.Encryption =====> %s", info->getEncryption().c_str());
  1086. LOGD("info.Statement =====> %s", info->getStatement().c_str());
  1087. LOGD("info.Freq =====> %d", info->getFreq());
  1088. LOGD("info.Level =====> %d", info->getLevel());
  1089. LOGD("info.Rssi =====> %d", info->getRssi());
  1090. }
  1091. }
  1092. }
  1093. //================================= IO 口操作
  1094. //紧急按钮灯,明/灭
  1095. void setSOS_A5(bool light){
  1096. int result = -1;
  1097. int slight = light?0:1;
  1098. result = GpioHelper::output("A5", slight);
  1099. if (result==0){
  1100. LOGD("set A5 SOS light %d. success",light);
  1101. } else {
  1102. LOGD("set A5 SOS light %d. failed",light);
  1103. }
  1104. }
  1105. //A6,A7,A8 RGB灯控制
  1106. void setRGB_A678(bool R, bool G, bool B){
  1107. int rR = -1, rG = -1, rB = -1;
  1108. int sR = R?0:1, sG = G?0:1, sB = B?0:1;
  1109. rR = GpioHelper::output("A6", sR);
  1110. rG = GpioHelper::output("A7", sG);
  1111. rB = GpioHelper::output("A8", sB);
  1112. const char *strLog = "set %s light %d. %d";
  1113. LOGD(strLog,"A6 R",R, rR);
  1114. LOGD(strLog,"A7 G",G, rG);
  1115. LOGD(strLog,"A8 B",B, rB);
  1116. }
  1117. //手柄按钮
  1118. class A1GpioListener : public IGpioListener{
  1119. public:
  1120. bool onGpioEdge(const char *pPin) override {
  1121. int state = GpioHelper::input("A1");
  1122. LOGD("IGpioListener GPIO IS A1=%d", state);
  1123. if (state==0){
  1124. voip::CallInfo info = GetTelephone()->GetCallInfo();
  1125. //拨打 或 挂断
  1126. if (CallingStatus::instance()->busy()){
  1127. callActivityFinish(CallFinishType::A1CLICK);
  1128. } else {
  1129. Intent* intent = new Intent();
  1130. intent->putExtra(callActivityType, "fromCall");
  1131. EASYUICONTEXT->openActivity("callActivity", intent);
  1132. }
  1133. }
  1134. return true;
  1135. }
  1136. void onGpioError(const char *pPin, int error) override {
  1137. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1138. }
  1139. };
  1140. //7寸面板,呼出
  1141. class A2GpioListener : public IGpioListener{
  1142. public:
  1143. bool onGpioEdge(const char *pPin) override {
  1144. int state = GpioHelper::input("A2");
  1145. LOGD("IGpioListener GPIO IS A2=%d", state);
  1146. if (state==0){
  1147. //拨打 或 接听
  1148. }
  1149. return true;
  1150. }
  1151. void onGpioError(const char *pPin, int error) override {
  1152. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1153. }
  1154. };
  1155. //7寸面板,挂断
  1156. class A3GpioListener : public IGpioListener{
  1157. public:
  1158. bool onGpioEdge(const char *pPin) override {
  1159. int state = GpioHelper::input("A3");
  1160. LOGD("IGpioListener GPIO IS A3=%d", state);
  1161. if (state==0){
  1162. //挂断
  1163. }
  1164. return true;
  1165. }
  1166. void onGpioError(const char *pPin, int error) override {
  1167. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1168. }
  1169. };
  1170. //紧急按钮
  1171. class A4GpioListener : public IGpioListener{
  1172. public:
  1173. bool onGpioEdge(const char *pPin) override {
  1174. int state = GpioHelper::input("A4");
  1175. LOGD("IGpioListener GPIO IS A4=%d", state);
  1176. if (state==0){
  1177. //发出
  1178. // setSOS_A5(true);
  1179. }
  1180. return true;
  1181. }
  1182. void onGpioError(const char *pPin, int error) override {
  1183. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1184. }
  1185. };
  1186. /**
  1187. * 注册定时器
  1188. * 填充数组用于注册定时器
  1189. * 注意:id不能重复
  1190. */
  1191. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  1192. {1, 5000},
  1193. {2, 30*1000}
  1194. };
  1195. /**
  1196. * 当界面构造时触发
  1197. */
  1198. static void onUI_init(){
  1199. setTimeDifference();
  1200. setLangeuage();
  1201. //IO监测
  1202. // IGpioListener *iGpioListenerA1 = new A1GpioListener();
  1203. // GpioHelper::registerGpioListener("A1", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1204. //
  1205. // IGpioListener *iGpioListenerA2 = new A2GpioListener();
  1206. // GpioHelper::registerGpioListener("A2", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1207. //
  1208. // IGpioListener *iGpioListenerA3 = new A3GpioListener();
  1209. // GpioHelper::registerGpioListener("A3", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1210. //
  1211. // IGpioListener *iGpioListenerA4 = new A4GpioListener();
  1212. // GpioHelper::registerGpioListener("A4", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1213. //TCP启动
  1214. TcpClient::instance()->startTcp();
  1215. // if (!StoragePreferences::getBool(STORE_SET_SERVER_IP, false)) {
  1216. // // UDP启动
  1217. // UdpClient::instance()->startUdp();
  1218. // }
  1219. //监听SIP信令
  1220. addSipCallStateListener();
  1221. //开启网页
  1222. httpServer.RunAsync(HTTP_SERVER_PORT);
  1223. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  1224. LOGD("===============> 关闭护理状态");
  1225. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  1226. isNursing = true;
  1227. }
  1228. isWifiSupported = WIFIMANAGER->isSupported();
  1229. //请求版本号
  1230. // if(UartContext::Uart3IsOpen()) {
  1231. // string heartStr = "ASK,VNF-0";
  1232. // const char* sendMsg = heartStr.c_str();
  1233. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  1234. // }
  1235. // wifiConnect();
  1236. #if 0
  1237. std::thread backend([](){
  1238. while (true) {
  1239. if (feed_dogs > 0) {
  1240. --feed_dogs;
  1241. LOGD("feed");
  1242. int ret = GpioHelper::output("GPIO_2", 1); //拉高
  1243. if (ret != 0) {
  1244. LOGE("GPIO操作失败");
  1245. }
  1246. usleep(1000 * 20);
  1247. ret = GpioHelper::output("GPIO_2", 0); //拉低
  1248. if (ret != 0) {
  1249. LOGE("GPIO操作失败");
  1250. }
  1251. }
  1252. usleep(1000 * 1000);
  1253. }
  1254. });
  1255. backend.detach();
  1256. #endif
  1257. }
  1258. /**
  1259. * 当切换到该界面时触发
  1260. */
  1261. static void onUI_intent(const Intent *intentPtr) {
  1262. if (intentPtr != NULL) {
  1263. //TODO
  1264. }
  1265. }
  1266. /*
  1267. * 当界面显示时触发
  1268. */
  1269. static void onUI_show() {
  1270. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  1271. //进入主界面
  1272. EASYUICONTEXT->openActivity("mainActivity");
  1273. }
  1274. /*
  1275. * 当界面隐藏时触发
  1276. */
  1277. static void onUI_hide() {
  1278. }
  1279. /*
  1280. * 当界面完全退出时触发
  1281. */
  1282. static void onUI_quit() {
  1283. }
  1284. /**
  1285. * 串口数据回调接口
  1286. */
  1287. static void onProtocolDataUpdate(const SProtocolData &data) {
  1288. LOGD("cmd = %s", data.cmd.c_str());
  1289. if (getIsUpdate()) {
  1290. LOGD("处于升级过程中,串口不可使用");
  1291. return;
  1292. }
  1293. if (data.state != ""){
  1294. LOGD("state = %s", data.state.c_str());
  1295. }
  1296. string heartStr;
  1297. // getDeviceButtonFunction(data.cmd);
  1298. if (data.state == "0" || data.state == "1") {
  1299. if (data.cmd == "KEY5") {
  1300. if (isTriggerKey5) {
  1301. isTriggerKey5 = false;
  1302. getDeviceButtonFunction(data.cmd);
  1303. }
  1304. else {
  1305. isTriggerKey5 = true;
  1306. mActivityPtr->registerUserTimer(KEY5_TRIGGER_TIME_HANDLE, 3 * 1000);
  1307. }
  1308. if (isUdpClientWait) {
  1309. if (isUdpClientWaitCount < 5) {
  1310. LOGD("关闭udp等待定时器");
  1311. isUdpClientWait = false;
  1312. isUdpClientWaitCount = 0;
  1313. mActivityPtr->unregisterUserTimer(UDP_CLIENT_TIME_HANDLE);
  1314. statusLight("000F", StatusLightType::UNLOCK);
  1315. }
  1316. else {
  1317. LOGD("触发udp广播");
  1318. UdpClient::instance()->startUdp();
  1319. if (isWifiSupported) {
  1320. startSoft();
  1321. }
  1322. }
  1323. }
  1324. else {
  1325. isUdpClientWait = true;
  1326. mActivityPtr->registerUserTimer(UDP_CLIENT_TIME_HANDLE, 1 * 1000);
  1327. }
  1328. }
  1329. else if (data.cmd == "KEY6") {
  1330. if (isTriggerKey6) {
  1331. isTriggerKey6 = false;
  1332. getDeviceButtonFunction(data.cmd);
  1333. return;
  1334. }
  1335. isTriggerKey6 = true;
  1336. mActivityPtr->registerUserTimer(KEY6_TRIGGER_TIME_HANDLE, 3 * 1000);
  1337. }
  1338. else if (data.cmd == "KEY7") {
  1339. if (isTriggerKey7) {
  1340. isTriggerKey7 = false;
  1341. getDeviceButtonFunction(data.cmd);
  1342. return;
  1343. }
  1344. isTriggerKey7 = true;
  1345. mActivityPtr->registerUserTimer(KEY7_TRIGGER_TIME_HANDLE, 3 * 1000);
  1346. }
  1347. else if (data.cmd == "KEY>") {
  1348. if (isTriggerKey8) {
  1349. isTriggerKey8 = false;
  1350. getDeviceButtonFunction(data.cmd);
  1351. return;
  1352. }
  1353. isTriggerKey8 = true;
  1354. mActivityPtr->registerUserTimer(KEY8_TRIGGER_TIME_HANDLE, 3 * 1000);
  1355. }
  1356. else if (data.cmd == "KEY<") {
  1357. if (isTriggerKey9) {
  1358. isTriggerKey9 = false;
  1359. getDeviceButtonFunction(data.cmd);
  1360. return;
  1361. }
  1362. isTriggerKey9 = true;
  1363. mActivityPtr->registerUserTimer(KEY9_TRIGGER_TIME_HANDLE, 3 * 1000);
  1364. }
  1365. else if (data.cmd == "KEY;") {
  1366. if (isTriggerKey10) {
  1367. isTriggerKey10 = false;
  1368. getDeviceButtonFunction(data.cmd);
  1369. return;
  1370. }
  1371. isTriggerKey10 = true;
  1372. mActivityPtr->registerUserTimer(KEY10_TRIGGER_TIME_HANDLE, 3 * 1000);
  1373. }
  1374. else if (data.cmd == "KEY?") {
  1375. if (isTriggerKey11) {
  1376. isTriggerKey11 = false;
  1377. getDeviceButtonFunction(data.cmd);
  1378. return;
  1379. }
  1380. isTriggerKey11 = true;
  1381. mActivityPtr->registerUserTimer(KEY11_TRIGGER_TIME_HANDLE, 3 * 1000);
  1382. }
  1383. else if (data.cmd == "KEY=") {
  1384. if (isTriggerKey12) {
  1385. isTriggerKey12 = false;
  1386. getDeviceButtonFunction(data.cmd);
  1387. return;
  1388. }
  1389. isTriggerKey12 = true;
  1390. mActivityPtr->registerUserTimer(KEY12_TRIGGER_TIME_HANDLE, 3 * 1000);
  1391. }
  1392. else if (data.cmd == "KEY@") {
  1393. if (isTriggerKey13) {
  1394. isTriggerKey13 = false;
  1395. getDeviceButtonFunction(data.cmd);
  1396. return;
  1397. }
  1398. isTriggerKey13 = true;
  1399. mActivityPtr->registerUserTimer(KEY13_TRIGGER_TIME_HANDLE, 3 * 1000);
  1400. }
  1401. }
  1402. // else if (data.state == "1") {
  1403. // if ((data.cmd == "KEY5" && isTriggerKey5) ||
  1404. // (data.cmd == "KEY6" && isTriggerKey6) ||
  1405. // (data.cmd == "KEY7" && isTriggerKey7) ||
  1406. // (data.cmd == "KEY>" && isTriggerKey8) ||
  1407. // (data.cmd == "KEY<" && isTriggerKey9) ||
  1408. // (data.cmd == "KEY;" && isTriggerKey10) ||
  1409. // (data.cmd == "KEY?" && isTriggerKey11) ||
  1410. // (data.cmd == "KEY=" && isTriggerKey12) ||
  1411. // (data.cmd == "KEY@" && isTriggerKey13)
  1412. // ) {
  1413. // getDeviceButtonFunction(data.cmd);
  1414. // }
  1415. // }
  1416. else if (data.state == "3") {
  1417. if (data.cmd == "KEY6") {
  1418. isConnectHandle = true;
  1419. }
  1420. else if (data.cmd == "KEY7") {
  1421. isConnectSos = true;
  1422. }
  1423. }
  1424. else if (data.state == "4") {
  1425. if (data.cmd == "KEY6" && isConnectHandle) {
  1426. sendDataRemindOhter(StoragePreferences::getString(STORE_FRAME_FULL_NAME, "") + " " + LANGUAGEMANAGER->getValue("HandleDisconnected"));
  1427. }
  1428. else if (data.cmd == "KEY7" && isConnectSos) {
  1429. sendDataRemindOhter(StoragePreferences::getString(STORE_FRAME_FULL_NAME, "") + " " + LANGUAGEMANAGER->getValue("SosDisconnected"));
  1430. }
  1431. }
  1432. }
  1433. /**
  1434. * 定时器触发函数
  1435. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  1436. * 参数: id
  1437. * 当前所触发定时器的id,与注册时的id相同
  1438. * 返回值: true
  1439. * 继续运行当前定时器
  1440. * false
  1441. * 停止运行当前定时器
  1442. */
  1443. static bool onUI_Timer(int id){
  1444. switch (id) {
  1445. case 1:
  1446. {
  1447. //定时器跑在UI线程,这里将喂狗标记加1
  1448. //++feed_dogs;
  1449. //不用心跳
  1450. // if(UartContext::Uart3IsOpen()) {
  1451. // string heartStr = "HEART,1E";
  1452. // const char* sendMsg = heartStr.c_str();
  1453. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  1454. // }
  1455. }
  1456. break;
  1457. case 2: //TCP心跳
  1458. {
  1459. const char* req = "0";
  1460. TcpClient::instance()->sendMsg(req);
  1461. }
  1462. break;
  1463. case MULTI_FUNCTION: {
  1464. const char* req = "0";
  1465. TcpClient5089::instance()->sendMsg(req);
  1466. return isMulitFunction;
  1467. }
  1468. break;
  1469. case SOS_CLICK_TIME_HANDLE: {
  1470. sosTimerRegistered = true;
  1471. return false;
  1472. }
  1473. break;
  1474. case SOS_LAMP_TIME_HANDLE: {
  1475. // SOS还原成无灯光的状态
  1476. lightControl("ULED", "0F");
  1477. // 进行门灯还原
  1478. lightControl("DOORLED", "000F");
  1479. statusLight("000F", StatusLightType::INIT);
  1480. return false;
  1481. }
  1482. break;
  1483. case SOS_TID_TIME_HANDLE: {
  1484. loraSosTimeRegistered = false;
  1485. sendSosToLora();
  1486. return false;
  1487. }
  1488. break;
  1489. case SLEEP_STRAT_TIME_HANDLE: { // 息屏
  1490. if (isSleepTimerRegistered) {
  1491. isSleep = true;
  1492. BRIGHTNESSHELPER->screenOff();
  1493. } else { // 如果是false的话,就需要关闭定时器
  1494. isSleep = false;
  1495. BRIGHTNESSHELPER->screenOn();
  1496. }
  1497. }
  1498. break;
  1499. case SYS_RESTART_TIME_HANDLE: {
  1500. netresetInt += 1;
  1501. lightControl("NETRESET", "1F");
  1502. if (netresetInt == 5) {
  1503. LOGD("网卡重启无效,程序内部重启");
  1504. deviceReboot();
  1505. }
  1506. }
  1507. break;
  1508. case KEY5_TRIGGER_TIME_HANDLE: {
  1509. isTriggerKey5 = false;
  1510. }
  1511. break;
  1512. case KEY6_TRIGGER_TIME_HANDLE: {
  1513. isTriggerKey6 = false;
  1514. return false;
  1515. }
  1516. break;
  1517. case KEY7_TRIGGER_TIME_HANDLE: {
  1518. isTriggerKey7 = false;
  1519. return false;
  1520. }
  1521. break;
  1522. case KEY8_TRIGGER_TIME_HANDLE: {
  1523. isTriggerKey8 = false;
  1524. return false;
  1525. }
  1526. break;
  1527. case KEY9_TRIGGER_TIME_HANDLE: {
  1528. isTriggerKey9 = false;
  1529. return false;
  1530. }
  1531. break;
  1532. case KEY10_TRIGGER_TIME_HANDLE: {
  1533. isTriggerKey10 = false;
  1534. return false;
  1535. }
  1536. break;
  1537. case KEY11_TRIGGER_TIME_HANDLE: {
  1538. isTriggerKey11 = false;
  1539. return false;
  1540. }
  1541. break;
  1542. case KEY12_TRIGGER_TIME_HANDLE: {
  1543. isTriggerKey12 = false;
  1544. return false;
  1545. }
  1546. break;
  1547. case KEY13_TRIGGER_TIME_HANDLE: {
  1548. isTriggerKey13 = false;
  1549. return false;
  1550. }
  1551. break;
  1552. case UDP_CLIENT_TIME_HANDLE: {
  1553. isUdpClientWaitCount += 1;
  1554. LOGD("isUdpClientWaitCount ===> %d", isUdpClientWaitCount);
  1555. if (isWifiSupported) {
  1556. if (isUdpClientWaitCount >= 2 && isUdpClientWaitCount < 5) {
  1557. statusLight("000F", StatusLightType::NO_LOCK);
  1558. }
  1559. else if (isUdpClientWaitCount >= 5 && isUdpClientWaitCount < 120) {
  1560. statusLight("110F", StatusLightType::LOCK);
  1561. }
  1562. else if (isUdpClientWaitCount >= 120) {
  1563. isUdpClientWaitCount = 0;
  1564. isUdpClientWait = false;
  1565. statusLight("000F", StatusLightType::UNLOCK);
  1566. stopSoft();
  1567. return false;
  1568. }
  1569. }
  1570. else {
  1571. if (isUdpClientWaitCount >= 2 && isUdpClientWaitCount < 5) {
  1572. statusLight("000F", StatusLightType::NO_LOCK);
  1573. }
  1574. else if (isUdpClientWaitCount >= 5 && isUdpClientWaitCount < 15) {
  1575. statusLight("110F", StatusLightType::LOCK);
  1576. }
  1577. else if (isUdpClientWaitCount >= 15) {
  1578. isUdpClientWaitCount = 0;
  1579. isUdpClientWait = false;
  1580. statusLight("000F", StatusLightType::UNLOCK);
  1581. // stopSoft();
  1582. return false;
  1583. }
  1584. }
  1585. }
  1586. break;
  1587. case SIP_RECONNECT_TIME_HANDLE: {
  1588. removeSipCallStateListener();
  1589. removeSipRegisterStateListener();
  1590. ReleaseTelephone();
  1591. addSipCallStateListener();
  1592. addSipRegisterStateListener();
  1593. return false;
  1594. }
  1595. break;
  1596. default:
  1597. break;
  1598. }
  1599. return true;
  1600. }
  1601. /**
  1602. * 有新的触摸事件时触发
  1603. * 参数:ev
  1604. * 新的触摸事件
  1605. * 返回值:true
  1606. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  1607. * false
  1608. * 触摸事件将继续传递到控件上
  1609. */
  1610. static bool onstartActivityTouchEvent(const MotionEvent &ev) {
  1611. switch (ev.mActionStatus) {
  1612. case MotionEvent::E_ACTION_DOWN://触摸按下
  1613. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  1614. break;
  1615. case MotionEvent::E_ACTION_MOVE://触摸滑动
  1616. break;
  1617. case MotionEvent::E_ACTION_UP: //触摸抬起
  1618. break;
  1619. default:
  1620. break;
  1621. }
  1622. return false;
  1623. }