startLogic.cc 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  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 "server/http_server.h"
  9. #include "base/strings.hpp"
  10. #include "pjsua/pjsua-lib/pjsua.h"
  11. #include "utils/GpioHelper.h"
  12. #include "utils/TimeHelper.h"
  13. #include "utils/BrightnessHelper.h"
  14. #include <time.h>
  15. #include <thread>
  16. #include <list>
  17. #include <string>
  18. #include <unistd.h>
  19. #include <sys/reboot.h>
  20. #include "service/BusinessConfig.h"
  21. static bool sosTimerRegistered = true;
  22. static bool isSleepTimerRegistered = false; // 是否开启息屏定时任务
  23. static bool isSleep = false; // 是否在息屏
  24. static bool isNursing = false; // 用于启动时判断是否处于护理状态
  25. static bool isNetreset = false;
  26. static int netresetInt = 0;
  27. static string callTid = "";
  28. static int timeDifference = 8;
  29. struct DeviceButtonFunctionTypeAndValue {
  30. string type;
  31. string value;
  32. };
  33. static std::unordered_map<string, DeviceButtonFunctionTypeAndValue> deviceButtonFunction;
  34. static bool isConnectHandle = false;
  35. static bool isConnectSos = false;
  36. static bool isConnectHandle1 = false;
  37. static bool isConnectHandle2 = false;
  38. static bool isConnectHandle3 = false;
  39. static bool isConnectHandle4 = false;
  40. static bool isConnectOutKey1 = false;
  41. static bool isConnectOutKey2 = false;
  42. static bool isConnectOutKey3 = false;
  43. static bool isConnectOutKey4 = false;
  44. static bool isConnectOutKey5 = false;
  45. static bool isConnectOutKey6 = false;
  46. //static bool isTriggerHandle = false;
  47. //static bool isTriggerSos = false;
  48. static bool isTriggerKey5 = false;
  49. static bool isTriggerKey6 = false;
  50. static bool isTriggerKey7 = false;
  51. static bool isTriggerKey8 = false;
  52. static bool isTriggerKey9 = false;
  53. static bool isTriggerKey10 = false;
  54. static bool isTriggerKey11 = false;
  55. static bool isTriggerKey12 = false;
  56. static bool isTriggerKey13 = false;
  57. static bool isTriggerHandle1 = false;
  58. static bool isTriggerHandle2 = false;
  59. static bool isTriggerHandle3 = false;
  60. static bool isTriggerHandle4 = false;
  61. static bool isTriggerOutKey1 = false;
  62. static bool isTriggerOutKey2 = false;
  63. static bool isTriggerOutKey3 = false;
  64. static bool isTriggerOutKey4 = false;
  65. static bool isTriggerOutKey5 = false;
  66. static bool isTriggerOutKey6 = false;
  67. #define FUNCTION_TIMER_HANDLE 3 // 增援的定时器id
  68. #define SOS_CLICK_TIME_HANDLE 4 // sos的定时器id
  69. #define SOS_LAMP_TIME_HANDLE 5 // sos的门灯定时器id
  70. #define EVENT_TIME_HANDLE 8 // 事件定时器
  71. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  72. #define SYS_RESTART_TIME_HANDLE 10 // 重启
  73. #define PROMPT_TIME_HANDLE 11 // 提示语
  74. #define NURSEING_TIME_HANDLE 12 // 护理
  75. #define DOOR_LIGHT_TIME_HANDLE 13 // 门灯
  76. #define KEY5_TRIGGER_TIME_HANDLE 15
  77. #define KEY6_TRIGGER_TIME_HANDLE 16
  78. #define KEY7_TRIGGER_TIME_HANDLE 17
  79. #define KEY8_TRIGGER_TIME_HANDLE 18
  80. #define KEY9_TRIGGER_TIME_HANDLE 19
  81. #define KEY10_TRIGGER_TIME_HANDLE 20
  82. #define KEY11_TRIGGER_TIME_HANDLE 21
  83. #define KEY12_TRIGGER_TIME_HANDLE 22
  84. #define KEY13_TRIGGER_TIME_HANDLE 23
  85. #define HANDLE1_TRIGGER_TIME_HANDLE 24
  86. #define HANDLE2_TRIGGER_TIME_HANDLE 25
  87. #define HANDLE3_TRIGGER_TIME_HANDLE 26
  88. #define HANDLE4_TRIGGER_TIME_HANDLE 27
  89. #define OUTKYE1_TRIGGER_TIME_HANDLE 28
  90. #define OUTKYE2_TRIGGER_TIME_HANDLE 29
  91. #define OUTKYE3_TRIGGER_TIME_HANDLE 30
  92. #define OUTKYE4_TRIGGER_TIME_HANDLE 31
  93. #define OUTKYE5_TRIGGER_TIME_HANDLE 32
  94. #define OUTKYE6_TRIGGER_TIME_HANDLE 33
  95. //#define HANDLE_TRIGGER_TIME_HANDLE 15
  96. //#define SOS_TRIGGER_TIME_HANDLE 16
  97. //#define HANDLE1_TRIGGER_TIME_HANDLE 17
  98. //#define HANDLE2_TRIGGER_TIME_HANDLE 18
  99. //#define HANDLE3_TRIGGER_TIME_HANDLE 19
  100. //#define HANDLE4_TRIGGER_TIME_HANDLE 20
  101. #define HTTP_SERVER_PORT 80
  102. #define goback 200
  103. #define SIP_RECONNECT_TIME_HANDLE 201
  104. srv::HttpServer httpServer;
  105. std::list<string> sosDataList;
  106. namespace {
  107. std::string uilogic[] = {
  108. "testActivity",
  109. "ui3Activity"
  110. };
  111. void CloseUi();
  112. int feed_dogs = 0;
  113. void PrintCallLog() {
  114. CallLogEntries entries;
  115. int ret = GetCallLog(&entries);
  116. LOGD("GetCallRecord %d", ret);
  117. for (auto r : entries) {
  118. LOGD("id=%d, uri=%s, contact=%s,duration=%d,created_at=%d",
  119. r.id, r.uri.c_str(), r.contact.c_str(), r.duration, r.created_at);
  120. }
  121. }
  122. void OnCallStateChanged(voip::Telephone* telephone, int call_id, voip::State state) {
  123. LOGD("call state = %d", state);
  124. if (state == voip::STATE_CALL_INCOMING
  125. || state == voip::STATE_CALL_CALLING
  126. || state == voip::STATE_CALL_CONFIRMED) {
  127. voip::CallInfo info = GetTelephone()->GetCallInfo();
  128. LOGD("info.id == %d", info.id);
  129. LOGD("info.remote_uri == %s", info.remote_uri.c_str());
  130. LOGD("info.remote_contact == %s", info.remote_contact.c_str());
  131. string sipId = info.remote_uri.substr(info.remote_uri.find(":") + 1, info.remote_uri.find("@") - info.remote_uri.find(":") - 1);
  132. LOGD("sipId == %s", sipId.c_str());
  133. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  134. EASYUICONTEXT->openActivity("callActivity");
  135. }
  136. else {
  137. if (sipId != "0000000000") {
  138. const char* currentAppName = EASYUICONTEXT->currentAppName();
  139. string _currentAppName = currentAppName;
  140. if (_currentAppName != "callActivity") {
  141. telephone->Hangup();
  142. LOGD("=================> 不在通话界面,直接挂断!");
  143. return;
  144. }
  145. }
  146. }
  147. if (state == voip::STATE_CALL_INCOMING) {
  148. if (telephone->GetCallCount() > 1) {
  149. LOGD("call count > 1, return");
  150. telephone->Hangup(call_id, voip::SIP_STATUS_CODE_BUSY_HERE);
  151. return;
  152. }
  153. //提前显示视频
  154. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  155. telephone->Answer(call_id, voip::SIP_STATUS_CODE_PROGRESS);
  156. telephone->Answer();
  157. } else {
  158. acceptSIP();
  159. }
  160. }
  161. }
  162. if (state == voip::STATE_CALL_DISCONNECTED) {
  163. LOGD("通话挂断");
  164. if (telephone->GetCallCount() > 1) {
  165. LOGD("call count > 1, return");
  166. return;
  167. }
  168. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  169. //EASYUICONTEXT->goHome();
  170. EASYUICONTEXT->goBack();
  171. }
  172. pjsua_call_info ci;
  173. pjsua_call_get_info(call_id, &ci);
  174. LOGD("通话结束的状态码 ===> %d", ci.last_status);
  175. if (ci.last_status == voip::SIP_NOT_FOUND) {
  176. if (CallingStatus::instance()->busy()){
  177. callActivityFinish(CallFinishType::NOT_FOUND);
  178. }
  179. mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
  180. }
  181. else if (ci.last_status == voip::SIP_REQUEST_TIMES) {
  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. //
  211. // const char* currentAppName = EASYUICONTEXT->currentAppName();
  212. // string _currentAppName = currentAppName;
  213. // if (_currentAppName == "callActivity") {
  214. // callActivityFinish(HANDOFF);
  215. // return;
  216. // }
  217. //PrintCallLog();
  218. }
  219. }
  220. void CloseUi() {
  221. for(int i = 0; i < 2; i++){
  222. EASYUICONTEXT->closeActivity(uilogic[i].c_str());
  223. }
  224. }
  225. void setBrightness(){
  226. int dayLight = StoragePreferences::getInt(STORE_DAY_LIGHT,100);
  227. int nightLight = StoragePreferences::getInt(STORE_NIGHT_LIGHT,10);
  228. if (checkIsDay()){
  229. BRIGHTNESSHELPER->setBrightness(dayLight);
  230. } else {
  231. BRIGHTNESSHELPER->setBrightness(nightLight);
  232. }
  233. }
  234. void addSipCallStateListener() {
  235. GetTelephone()->AddCallStateListener(OnCallStateChanged);
  236. }
  237. void removeSipCallStateListener() {
  238. GetTelephone()->RemoveCallStateListener(OnCallStateChanged);
  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. std::list<string> getSosDataList() {
  323. return sosDataList;
  324. }
  325. void cleanSosDataList() {
  326. sosDataList.clear();
  327. }
  328. void deviceReboot() {
  329. LOGD("Device Reboot!");
  330. const char* req = "-1";
  331. TcpClient::instance()->sendMsg(req);
  332. lightControl("CALLLED", "000F");
  333. sync();
  334. reboot(RB_AUTOBOOT);
  335. }
  336. void systemRestart() {
  337. if (!isNetreset) {
  338. isNetreset = true;
  339. lightControl("CALLLED", "000F");
  340. mActivityPtr->registerUserTimer(SYS_RESTART_TIME_HANDLE, 1000);
  341. }
  342. }
  343. string _typeStr;
  344. string _lightColorStr;
  345. string _actualColorStr;
  346. bool isDoorLightTimeHandle = false;
  347. void lightControl(std::string typeStr, std::string lightColorStr) {
  348. // 类型是门灯,并且还原成白色灯
  349. std::string heartStr;
  350. if (typeStr == "DOORLED" && lightColorStr == "000F") {
  351. //护理状态,需要还原成护理灯
  352. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  353. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  354. if (color != "" && color.size() == 3) {
  355. heartStr = "DOORLED," + color + "F";
  356. } else {
  357. heartStr = "DOORLED,010F";
  358. }
  359. }
  360. else {
  361. // 还原成无灯光的状态
  362. heartStr = "DOORLED,000F";
  363. }
  364. } else {
  365. heartStr = typeStr + "," + lightColorStr;
  366. }
  367. if (typeStr == "DOORLED" && isDoorLightTimeHandle) {
  368. isDoorLightTimeHandle = false;
  369. mActivityPtr->unregisterUserTimer(DOOR_LIGHT_TIME_HANDLE);
  370. }
  371. LOGD("=====> the heartStr == %s", heartStr.c_str());
  372. const char* sendMsg = heartStr.c_str();
  373. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  374. }
  375. void lightControl(std::string typeStr, std::string lightColorStr, int time) {
  376. LOGD("频率闪烁,类型:%s,颜色:%s,频率:%d", typeStr.c_str(), lightColorStr.c_str(), time);
  377. _typeStr = typeStr;
  378. _lightColorStr = lightColorStr;
  379. _actualColorStr = lightColorStr;
  380. // 还原成无灯光的状态
  381. std::string heartStr = typeStr + "," + lightColorStr;
  382. LOGD("=====> the heartStr == %s", heartStr.c_str());
  383. const char* sendMsg = heartStr.c_str();
  384. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  385. isDoorLightTimeHandle = true;
  386. mActivityPtr->registerUserTimer(DOOR_LIGHT_TIME_HANDLE, time);
  387. }
  388. // 接收tcp消息
  389. void handleMsg(byte* inBytes){
  390. TcpModel tcpModel;
  391. tcpModel = getTcpModel(inBytes);
  392. LOGD("tcp model: %s, %s", tcpModel.type.c_str(), tcpModel.action.c_str());
  393. if (tcpModel.type == TcpType::OTHER) {
  394. LOGD("trans tcp json failed");
  395. } else if (tcpModel.type == TcpType::TIME) {
  396. if (tcpModel.action == TimeAction::SYNC) {
  397. string serverTime = "";
  398. if (tcpModel.data != ""){
  399. serverTime = tcpModel.data;
  400. } else {
  401. serverTime = tcpModel.json["time"].asString();
  402. }
  403. LOGD("sync time : %s", serverTime.c_str());
  404. // time_t timet = stoi(serverTime);
  405. // struct tm *t = gmtime(&timet);
  406. // char pDate[25];
  407. // sprintf(pDate,"%d-%02d-%02d %02d:%02d:%02d",
  408. // 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday,
  409. // t->tm_hour + 8,t->tm_min,t->tm_sec);
  410. // LOGD("transfered time : %s", pDate);
  411. // TimeHelper::setDateTime(pDate);
  412. TimeHelper::setDataTimeByTimeDifference(serverTime, timeDifference);
  413. dataRefresh();
  414. if (isNursing) {
  415. setNursingEnd();
  416. }
  417. }
  418. } else if (tcpModel.type == TcpType::REINFORCE){
  419. if (tcpModel.action == ReinforceAction::RESPONSED){
  420. //回调
  421. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  422. if (callback.tid != "0"){
  423. callback.onSuccess(tcpModel.json);
  424. }
  425. const char* currentAppName = EASYUICONTEXT->currentAppName();
  426. string _currentAppName = currentAppName;
  427. if (_currentAppName != "functionActivity") {
  428. Intent* intent = new Intent();
  429. intent->putExtra(functionWindows, "helpResonse");
  430. EASYUICONTEXT->openActivity("functionActivity", intent);
  431. } else {
  432. toFunctionActivity("");
  433. }
  434. }
  435. } else if (tcpModel.type == TcpType::DEVICE){
  436. if (tcpModel.action == DeviceAction::APP_UPDATE){ //软件升级
  437. if (isSleep) {
  438. isSleep = false;
  439. BRIGHTNESSHELPER->screenOn();
  440. }
  441. Intent* intent = new Intent();
  442. intent->putExtra(appUpdate, "true");
  443. EASYUICONTEXT->openActivity("updateActivity", intent);
  444. }
  445. else if (tcpModel.action == DeviceAction::RESTART) { // 重启设备
  446. deviceReboot();
  447. }
  448. else if (tcpModel.action == DeviceAction::REBOOT) {
  449. deviceReboot();
  450. }
  451. else if (tcpModel.action == DeviceAction::DEVICE_REFRESH) { // 设备刷新
  452. dataRefresh();
  453. }
  454. else if (tcpModel.action == DeviceAction::SYSTEM_SETTING) { // 修改科室设置
  455. getPartSetting();
  456. }
  457. else if (tcpModel.action == DeviceAction::SERVER_CHANGE) {
  458. StoragePreferences::putString(STORE_GATEWAY, tcpModel.json["server_ip"].asCString());
  459. StoragePreferences::putString(STORE_HTTP_PORT, tcpModel.json["server_port"].asCString());
  460. deviceReboot();
  461. }
  462. } else if (tcpModel.type == TcpType::DATA){
  463. if (tcpModel.action == DataAction::REFRESH){ // 刷新数据
  464. dataRefresh();
  465. }
  466. } else if (tcpModel.type == TcpType::VOICE){
  467. if (tcpModel.action == VoiceAction::FAILED){
  468. sleep(1);
  469. if (CallingStatus::instance()->busy()){
  470. callActivityFinish(CallFinishType::FAILED);
  471. }
  472. } else if (tcpModel.action == VoiceAction::SUCCESS){
  473. CallingStatus::instance()->setTcpModel(tcpModel); // 只有呼叫成功才闪红灯
  474. lightControl("DOORLED", "100F");
  475. } else if (tcpModel.action == VoiceAction::ACCEPT){
  476. if (CallingStatus::instance()->busy()){
  477. CallingStatus::instance()->setTcpModel(tcpModel);
  478. std::string toSipId = tcpModel.json["toSipId"].asString();
  479. callActivityFinish(CallFinishType::ACCEPT);
  480. //接听
  481. buildSIP(toSipId);
  482. }
  483. // 进行门灯还原
  484. lightControl("DOORLED", "000F");
  485. } else if (tcpModel.action == VoiceAction::REJECT){
  486. if (CallingStatus::instance()->busy()){
  487. callActivityFinish(CallFinishType::REJECT);
  488. // 进行门灯还原
  489. lightControl("DOORLED", "000F");
  490. }
  491. } else if (tcpModel.action == VoiceAction::CANCEL){
  492. if (CallingStatus::instance()->busy()){
  493. callActivityFinish(CallFinishType::CANCEL);
  494. }
  495. } else if (tcpModel.action == VoiceAction::CALLING){
  496. //对方忙线
  497. callActivityFinish(CallFinishType::BUSY);
  498. } else if (tcpModel.action == VoiceAction::CALL){
  499. //我方忙线判断
  500. if (CallingStatus::instance()->busy()){
  501. sendVoiceTcp(VoiceAction::CALLING, tcpModel, tcpModel.from_id);
  502. } else {
  503. lightControl("DOORLED", "200F");
  504. CallingStatus::instance()->setTcpModel(tcpModel);
  505. //来电话了
  506. Intent* intent = new Intent();
  507. intent->putExtra(callActivityType, "toCall");
  508. EASYUICONTEXT->openActivity("callActivity", intent);
  509. }
  510. } else if (tcpModel.action == VoiceAction::HANDOFF){
  511. //判断 是否同一个对话
  512. long iId = CallingStatus::instance()->getInteractionId();
  513. if (iId > 0 && CallingStatus::instance()->busy()){
  514. long inId = tcpModel.json["id"].asInt();
  515. if (iId == inId && CallingStatus::instance()->busy()){
  516. callActivityFinish(CallFinishType::HANDOFF);
  517. }
  518. }
  519. }
  520. else if (tcpModel.action == VoiceAction::SIP_RECONNECT) {
  521. mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
  522. }
  523. else if (tcpModel.action == VoiceAction::GAIN_OK) {
  524. CallingStatus::instance()->setTcpModel(tcpModel);
  525. sleep(1);
  526. callActivityFinish(CallFinishType::GAIN_OK);
  527. }
  528. else if (tcpModel.action == VoiceAction::GAIN_FAIL) {
  529. if (CallingStatus::instance()->busy()){
  530. callActivityFinish(CallFinishType::GAIN_FAIL);
  531. }
  532. }
  533. }
  534. else if (tcpModel.type == TcpType::SOS) {
  535. if (tcpModel.action == SosAction::CANCEL) {
  536. // SOS还原成无灯光的状态
  537. lightControl("ULED", "0F");
  538. // 进行门灯还原
  539. lightControl("DOORLED", "000F");
  540. statusLight();
  541. // mActivityPtr->unregisterUserTimer(SOS_LAMP_TIME_HANDLE);
  542. }
  543. }
  544. else if (tcpModel.type == TcpType::SIDE) {
  545. if (tcpModel.action == SideAction::NURSING) {
  546. StoragePreferences::putString(STORE_NURSING_INTERACTION_ID, tcpModel.json["id"].asString());
  547. // 收到nursing,需要把通话给挂断了
  548. voip::CallInfo info = GetTelephone()->GetCallInfo();
  549. LOGD("info state = %d",info.state);
  550. if (info.state == voip::STATE_CALL_CALLING
  551. || info.state == voip::STATE_CALL_CALLING
  552. || info.state == voip::STATE_CALL_CONFIRMED){
  553. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  554. //只回传iId
  555. storeModel.data = storeModel.json["id"].asString();
  556. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  557. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  558. GetTelephone()->Hangup();
  559. EASYUICONTEXT->goBack();
  560. }
  561. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  562. if (color != "" && color.size() == 3) {
  563. color = color + "F";
  564. } else {
  565. color = "010F";
  566. }
  567. lightControl("DOORLED", color);
  568. }
  569. else if (tcpModel.action == SideAction::NURSING_END) {
  570. // 收到nursing_end
  571. lightControl("DOORLED", "000F");
  572. }
  573. else if (tcpModel.action == SideAction::CALL) {
  574. // 收到CALL,需要亮红灯
  575. lightControl("DOORLED", "200F");
  576. }
  577. else if (tcpModel.action == SideAction::ACCEPT) {
  578. // 进行门灯还原
  579. lightControl("DOORLED", "000F");
  580. if (isHandleId(tcpModel.to_id) && CallingStatus::instance()->busy()) {
  581. CallingStatus::instance()->setTcpModel(tcpModel);
  582. std::string toSipId = tcpModel.json["toSipId"].asString();
  583. callActivityFinish(CallFinishType::ACCEPT);
  584. //接听
  585. buildSIP(toSipId);
  586. }
  587. }
  588. else if (tcpModel.action == SideAction::CANCEL) {
  589. // 进行门灯还原
  590. lightControl("DOORLED", "000F");
  591. if (isHandleId(tcpModel.to_id) && CallingStatus::instance()->busy()) {
  592. callActivityFinish(CallFinishType::CANCEL);
  593. }
  594. }
  595. else if (tcpModel.action == SideAction::SOS_CALL) {
  596. // 收到SOS_CALL,需要亮红灯
  597. // 门灯亮红灯
  598. lightControl("DOORLED", "100F", 1000);
  599. lightControl("CALLLED", "100F");
  600. sosTimerRegistered = false;
  601. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  602. // mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  603. if (tcpModel.json.isMember("id")) {
  604. sosDataList.push_back(tcpModel.json["id"].asString());
  605. }
  606. }
  607. else if (tcpModel.action == SideAction::SOS_CANCEL) {
  608. // 进行门灯还原
  609. lightControl("DOORLED", "000F");
  610. statusLight();
  611. }
  612. else if (tcpModel.action == SideAction::SHOW) {
  613. const char* currentAppName = EASYUICONTEXT->currentAppName();
  614. string _currentAppName = currentAppName;
  615. if (_currentAppName == "callActivity") {
  616. return;
  617. }
  618. Json::Value _it = tcpModel.json;
  619. if (_it["actionType"].asString() != "VOICE") {
  620. return;
  621. }
  622. if (_currentAppName != "functionActivity") {
  623. Intent* intent = new Intent();
  624. intent->putExtra(functionWindows, "gainCall");
  625. EASYUICONTEXT->openActivity("functionActivity", intent);
  626. }
  627. size_t pos = tcpModel.tid.find("_");
  628. if (pos != std::string::npos) {
  629. _it["tid"] = tcpModel.tid.substr(0, pos);
  630. } else {
  631. _it["tid"] = tcpModel.tid;
  632. }
  633. addGainCallData(_it);
  634. }
  635. else if (tcpModel.action == SideAction::CLEAR) {
  636. const char* currentAppName = EASYUICONTEXT->currentAppName();
  637. string _currentAppName = currentAppName;
  638. if (_currentAppName == "functionActivity") {
  639. deleteGainCallData(tcpModel.json["id"].asString());
  640. }
  641. }
  642. }
  643. else if (tcpModel.type == TcpType::CALLBACK) {
  644. if (tcpModel.action == CallbackAction::ACK) {
  645. LOGD("CALLBACK ACK !!!!");
  646. //回调
  647. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  648. if (callback.tid != "0"){
  649. callback.onSuccess(tcpModel.json);
  650. }
  651. }
  652. else if (tcpModel.action == CallbackAction::SUCCESS) {
  653. //回调
  654. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  655. if (callback.tid != "0"){
  656. callback.onSuccess(tcpModel.json);
  657. }
  658. }
  659. else if (tcpModel.action == CallbackAction::FAILED) {
  660. sleep(1);
  661. //回调
  662. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  663. if (callback.tid != "0"){
  664. callback.onFalied(tcpModel.json);
  665. }
  666. if (tcpModel.tid == callTid){
  667. callActivityFinish(CallFinishType::FAILED);
  668. }
  669. }
  670. }
  671. else if (tcpModel.type == TcpType::POSITION) {
  672. if (tcpModel.action == PositionAction::POSITION_START) {
  673. setPosistionItId(tcpModel.json["id"].asInt());
  674. }
  675. }
  676. else if (tcpModel.type == TcpType::ROOMCHECK) {
  677. if (tcpModel.action == RoomCheckAction::START) {
  678. setRoomCheckItId(tcpModel.json["id"].asInt());
  679. }
  680. }
  681. else if (tcpModel.type == TcpType::SCREEN_TIP) {
  682. if (tcpModel.action == ScreenTipAction::START) {
  683. setPromptTimeItId(tcpModel.json["id"].asInt());
  684. }
  685. }
  686. else if (tcpModel.type == TcpType::AUTH) {
  687. if (tcpModel.action == AuthAction::LOGIN) {
  688. // 需要判断fromId跟自己是不是一样的,一样的就代表是自己发送出去,不一样的就代表员工已经登录到其他设备去了
  689. if (tcpModel.from_id == StoragePreferences::getInt(STORE_DEVICE_ID, 0)) {
  690. LOGD("id ===> %d", tcpModel.json["id"].asInt());
  691. setAuthItId(tcpModel.json["id"].asInt());
  692. }
  693. else {
  694. navibarNfcLogout();
  695. // logoutMedicalCare();
  696. // const char* currentAppName = EASYUICONTEXT->currentAppName();
  697. // string _currentAppName = currentAppName;
  698. // if (_currentAppName == "medicalCareActivity") {
  699. // goHome();
  700. // }
  701. }
  702. }
  703. }
  704. else if (tcpModel.type == TcpType::BLUE_CODE) {
  705. if (tcpModel.action == BlueCodeAction::SUCCESS) {
  706. int id = tcpModel.json["id"].asInt();
  707. LOGD("blue code id ===> %d", id);
  708. setBlueCodeId(id, tcpModel.tid);
  709. }
  710. }
  711. }
  712. bool getSleepTimerRegistered() {
  713. return isSleepTimerRegistered;
  714. }
  715. // 触发定时任务
  716. void setSleepTimerRegistered(bool result) {
  717. LOGD("isSleepTimerRegistered = %d", isSleepTimerRegistered);
  718. LOGD("result = %d", result);
  719. if (mActivityPtr == NULL) {
  720. return;
  721. }
  722. if (result != isSleepTimerRegistered) { // 与定时任务不同时,才进行处理
  723. if (isSleepTimerRegistered) { // 与定时任务开关进行判断,如果定时任务开启,那就要关闭
  724. isSleepTimerRegistered = result;
  725. mActivityPtr->unregisterUserTimer(SLEEP_STRAT_TIME_HANDLE); // 关闭定时器
  726. if (isSleep) {
  727. isSleep = false;
  728. BRIGHTNESSHELPER->screenOn();
  729. }
  730. LOGD("关闭息屏");
  731. } else { // 如果定时任务关着,那就要打开
  732. isSleepTimerRegistered = result;
  733. int sleepTime = StoragePreferences::getInt(STORE_SLEEP_TIME, 3);
  734. if (sleepTime > 0) {
  735. mActivityPtr->registerUserTimer(SLEEP_STRAT_TIME_HANDLE, sleepTime * 60 * 1000);
  736. LOGD("开启息屏");
  737. }
  738. }
  739. }
  740. }
  741. void scrrenOn() {
  742. isSleep = false;
  743. BRIGHTNESSHELPER->screenOn();
  744. }
  745. void setLangeuage() {
  746. std::string deviceLanguage = StoragePreferences::getString(STORE_LANG, defaultLang);
  747. std::string partLanguage = StoragePreferences::getString(STORE_PART_LANG, defaultPartLang);
  748. if (deviceLanguage != defaultLang) {
  749. LOGD("设备自身拥有语言:%s", deviceLanguage.c_str());
  750. EASYUICONTEXT->updateLocalesCode(deviceLanguage.c_str());
  751. }
  752. else {
  753. LOGD("科室语言:%s", partLanguage.c_str());
  754. if (partLanguage == "en") {
  755. EASYUICONTEXT->updateLocalesCode("en_US");
  756. }
  757. else if (partLanguage == "es") {
  758. EASYUICONTEXT->updateLocalesCode("es_ES");
  759. }
  760. else if (partLanguage == "ru") {
  761. EASYUICONTEXT->updateLocalesCode("ru_RU");
  762. }
  763. else {
  764. EASYUICONTEXT->updateLocalesCode("zh_CN");
  765. }
  766. }
  767. }
  768. void setCallTid(std::string tid) {
  769. callTid = tid;
  770. }
  771. void handleHCall(int id) {
  772. int handleId = getHandleId(id);
  773. if (handleId != 0) {
  774. const char* currentAppName = EASYUICONTEXT->currentAppName();
  775. string _currentAppName = currentAppName;
  776. if (_currentAppName == "callActivity") {
  777. LOGD("已经在呼叫界面");
  778. return;
  779. }
  780. string handleIdStr = to_string(handleId);
  781. Intent* intent = new Intent();
  782. intent->putExtra(callActivityType, "handleHCall");
  783. intent->putExtra(handleCallId, handleIdStr);
  784. EASYUICONTEXT->openActivity("callActivity", intent);
  785. }
  786. else {
  787. string errorMsg = LANGUAGEMANAGER->getValue("HandleError") +
  788. StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0") + ":h" + to_string(id) + " \n" +
  789. LANGUAGEMANAGER->getValue("NotAdd");
  790. Intent* intent = new Intent();
  791. intent->putExtra(functionWindows, "warn");
  792. intent->putExtra(warnText, errorMsg);
  793. EASYUICONTEXT->openActivity("functionActivity", intent);
  794. }
  795. }
  796. void sosCall(string sosMsg) {
  797. if (sosTimerRegistered) {
  798. LOGD("TCP -> SOS_CALL");
  799. sendSosCall(sosMsg);
  800. // SOS亮红灯
  801. lightControl("ULED", "1F");
  802. // 门灯亮红灯
  803. lightControl("DOORLED", "100F", 1000);
  804. lightControl("CALLLED", "100F");
  805. sosTimerRegistered = false;
  806. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  807. // mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  808. }
  809. }
  810. void clearDeviceButtonFunction() {
  811. deviceButtonFunction.clear();
  812. }
  813. void setDeviceButtonFunction(std::string deviceButtonFunctionStr) {
  814. LOGD("deviceButtonFunctionStr ==========> %s", deviceButtonFunctionStr.c_str());
  815. Json::Reader reader;
  816. Json::Value deviceButtonFunctionJson;
  817. if (reader.parse(deviceButtonFunctionStr, deviceButtonFunctionJson)) {
  818. for (Json::Value json : deviceButtonFunctionJson) {
  819. const std::string key = json["key"].asString();
  820. const std::string type = json["type"].asString();
  821. DeviceButtonFunctionTypeAndValue typeAndValue;
  822. typeAndValue.type = type;
  823. if (type == "EVENT") {
  824. int value = json["value"].asInt();
  825. std::stringstream valueStr;
  826. valueStr << value;
  827. typeAndValue.value = valueStr.str();
  828. LOGD("key:%s type:%s value:%d ", key.c_str(), type.c_str(), value);
  829. }
  830. else {
  831. string valueStr = json["value"].asString();
  832. typeAndValue.value = valueStr;
  833. LOGD("key:%s type:%s value:%s ", key.c_str(), type.c_str(), valueStr.c_str());
  834. }
  835. deviceButtonFunction[key] = typeAndValue;
  836. }
  837. }
  838. }
  839. void handleCall(string key, string roleType) {
  840. if (roleType == "CANCEL") {
  841. voip::CallInfo info = GetTelephone()->GetCallInfo();
  842. //拨打 或 挂断
  843. if (CallingStatus::instance()->busy()){
  844. lightControl("DOORLED", "000F");
  845. callActivityFinish(CallFinishType::A1CLICK);
  846. }
  847. }
  848. else {
  849. voip::CallInfo info = GetTelephone()->GetCallInfo();
  850. //拨打 或 挂断
  851. if (CallingStatus::instance()->busy()){
  852. lightControl("DOORLED", "000F");
  853. callActivityFinish(CallFinishType::A1CLICK);
  854. } else {
  855. lightControl("DOORLED", "200F");
  856. Intent* intent = new Intent();
  857. intent->putExtra(callActivityType, "fromCall");
  858. // intent->putExtra(callRoleType, roleType);
  859. EASYUICONTEXT->openActivity("callActivity", intent);
  860. }
  861. }
  862. }
  863. void handleSos(string value) {
  864. if (value == "SOS_CANCEL") {
  865. std::list<string> _sosData = getSosDataList();
  866. if (_sosData.empty()) {
  867. return;
  868. }
  869. std::list<string>::iterator it = _sosData.begin();
  870. while (it != _sosData.end()) {
  871. string sosDataStr = *it;
  872. sendSosCancel(sosDataStr);
  873. it++;
  874. }
  875. cleanSosDataList();
  876. }
  877. else {
  878. sosCall("");
  879. }
  880. }
  881. void handleEvent(string key, string id) {
  882. // else {
  883. // if (StoragePreferences::getString(STORE_CUSTOMER_ID, "") != "" || StoragePreferences::getInt(STORE_EMPTY_BED_CALL, 0) == 1) {
  884. // std::stringstream idStr(id);
  885. // int _id;
  886. // idStr >> _id;
  887. // Json::Value json;
  888. // json["id"] = _id;
  889. // sendEventClick(json);
  890. //
  891. // Intent* intent = new Intent();
  892. // intent->putExtra(functionWindows, "eventCall");
  893. // intent->putExtra(functionText, getEventMap(id));
  894. // EASYUICONTEXT->openActivity("functionActivity", intent);
  895. // }
  896. // }
  897. }
  898. void handleReinforce(string key) {
  899. sendReinforceCall();
  900. Intent* intent = new Intent();
  901. intent->putExtra(functionWindows, "help");
  902. EASYUICONTEXT->openActivity("functionActivity", intent);
  903. }
  904. void handleNursing(string key, string time) {
  905. if (!StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  906. Intent* intent = new Intent();
  907. intent->putExtra(functionWindows, "nursing3");
  908. EASYUICONTEXT->openActivity("functionActivity", intent);
  909. }
  910. else {
  911. const char* currentAppName = EASYUICONTEXT->currentAppName();
  912. string _currentAppName = currentAppName;
  913. if (_currentAppName != "functionActivity") {
  914. Intent* intent = new Intent();
  915. intent->putExtra(functionWindows, "nursingEnd3");
  916. EASYUICONTEXT->openActivity("functionActivity", intent);
  917. }
  918. else {
  919. nursingEnd3();
  920. }
  921. }
  922. }
  923. void handleBlueCode() {
  924. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  925. setBlueCode(true);
  926. }
  927. }
  928. void getDeviceButtonFunction(string key) {
  929. const char* currentAppName = EASYUICONTEXT->currentAppName();
  930. string _currentAppName = currentAppName;
  931. if (_currentAppName == "sipTestActivity") {
  932. setCheckbox(key);
  933. return;
  934. }
  935. if (deviceButtonFunction.find(key) != deviceButtonFunction.end()) {
  936. DeviceButtonFunctionTypeAndValue typeAndValue = deviceButtonFunction[key];
  937. LOGD("typeAndValue.type: %s typeAndValue.value: %s", typeAndValue.type.c_str(), typeAndValue.value.c_str());
  938. if (typeAndValue.type == "SOS") {
  939. handleSos(typeAndValue.value);
  940. }
  941. else if (typeAndValue.type == "VOICE") {
  942. handleCall(key, typeAndValue.value);
  943. }
  944. else if (typeAndValue.type == "EVENT") {
  945. handleEvent(key, typeAndValue.value);
  946. }
  947. else if (typeAndValue.type == "REINFORCE") {
  948. handleReinforce(key);
  949. }
  950. else if (typeAndValue.type == "NURSING") {
  951. handleNursing(key, typeAndValue.value);
  952. }
  953. else if (typeAndValue.type == "BLUE_CODE") {
  954. handleBlueCode();
  955. }
  956. }
  957. else {
  958. if (key == "KEY5") {
  959. handleCall(key, "NURSE");
  960. }
  961. else if (key == "KEY6") {
  962. handleCall(key, "NURSE");
  963. }
  964. else if (key == "KEY7") {
  965. handleSos("SOS");
  966. }
  967. else if (key == "KEY>") {
  968. handleCall(key, "CANCEL");
  969. }
  970. else if (key == "KEY;") {
  971. handleBlueCode();
  972. }
  973. else if (key == "KEY<") {
  974. handleNursing(key, "");
  975. }
  976. else if (key == "KEY@") {
  977. handleSos("SOS_CANCEL");
  978. }
  979. else if (key == "HANDKEY00" || key == "OUTKEY1") {
  980. handleHCall(1);
  981. }
  982. else if (key == "HANDKEY10" || key == "OUTKEY2") {
  983. handleHCall(2);
  984. }
  985. else if (key == "HANDKEY20" || key == "OUTKEY3") {
  986. handleHCall(3);
  987. }
  988. else if (key == "HANDKEY30" || key == "OUTKEY4") {
  989. handleHCall(4);
  990. }
  991. else if (key == "OUTKEY5") {
  992. handleHCall(5);
  993. }
  994. else if (key == "OUTKEY6") {
  995. handleHCall(6);
  996. }
  997. }
  998. }
  999. //================================= IO 口操作
  1000. //紧急按钮灯,明/灭
  1001. void setSOS_A5(bool light){
  1002. int result = -1;
  1003. int slight = light?0:1;
  1004. result = GpioHelper::output("A5", slight);
  1005. if (result==0){
  1006. LOGD("set A5 SOS light %d. success",light);
  1007. } else {
  1008. LOGD("set A5 SOS light %d. failed",light);
  1009. }
  1010. }
  1011. //A6,A7,A8 RGB灯控制
  1012. void setRGB_A678(bool R, bool G, bool B){
  1013. int rR = -1, rG = -1, rB = -1;
  1014. int sR = R?0:1, sG = G?0:1, sB = B?0:1;
  1015. rR = GpioHelper::output("A6", sR);
  1016. rG = GpioHelper::output("A7", sG);
  1017. rB = GpioHelper::output("A8", sB);
  1018. const char *strLog = "set %s light %d. %d";
  1019. LOGD(strLog,"A6 R",R, rR);
  1020. LOGD(strLog,"A7 G",G, rG);
  1021. LOGD(strLog,"A8 B",B, rB);
  1022. }
  1023. //手柄按钮
  1024. class A1GpioListener : public IGpioListener{
  1025. public:
  1026. bool onGpioEdge(const char *pPin) override {
  1027. int state = GpioHelper::input("A1");
  1028. LOGD("IGpioListener GPIO IS A1=%d", state);
  1029. if (state==0){
  1030. voip::CallInfo info = GetTelephone()->GetCallInfo();
  1031. //拨打 或 挂断
  1032. if (CallingStatus::instance()->busy()){
  1033. callActivityFinish(CallFinishType::A1CLICK);
  1034. } else {
  1035. Intent* intent = new Intent();
  1036. intent->putExtra(callActivityType, "fromCall");
  1037. // intent->putExtra(callRoleType, "NURSE");
  1038. EASYUICONTEXT->openActivity("callActivity", intent);
  1039. }
  1040. }
  1041. return true;
  1042. }
  1043. void onGpioError(const char *pPin, int error) override {
  1044. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1045. }
  1046. };
  1047. //7寸面板,呼出
  1048. class A2GpioListener : public IGpioListener{
  1049. public:
  1050. bool onGpioEdge(const char *pPin) override {
  1051. int state = GpioHelper::input("A2");
  1052. LOGD("IGpioListener GPIO IS A2=%d", state);
  1053. if (state==0){
  1054. //拨打 或 接听
  1055. }
  1056. return true;
  1057. }
  1058. void onGpioError(const char *pPin, int error) override {
  1059. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1060. }
  1061. };
  1062. //7寸面板,挂断
  1063. class A3GpioListener : public IGpioListener{
  1064. public:
  1065. bool onGpioEdge(const char *pPin) override {
  1066. int state = GpioHelper::input("A3");
  1067. LOGD("IGpioListener GPIO IS A3=%d", state);
  1068. if (state==0){
  1069. //挂断
  1070. }
  1071. return true;
  1072. }
  1073. void onGpioError(const char *pPin, int error) override {
  1074. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1075. }
  1076. };
  1077. //紧急按钮
  1078. class A4GpioListener : public IGpioListener{
  1079. public:
  1080. bool onGpioEdge(const char *pPin) override {
  1081. int state = GpioHelper::input("A4");
  1082. LOGD("IGpioListener GPIO IS A4=%d", state);
  1083. if (state==0){
  1084. //发出
  1085. setSOS_A5(true);
  1086. }
  1087. return true;
  1088. }
  1089. void onGpioError(const char *pPin, int error) override {
  1090. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  1091. }
  1092. };
  1093. /**
  1094. * 注册定时器
  1095. * 填充数组用于注册定时器
  1096. * 注意:id不能重复
  1097. */
  1098. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  1099. {1, 5000},
  1100. {2, 30*1000}
  1101. };
  1102. /**
  1103. * 当界面构造时触发
  1104. */
  1105. static void onUI_init(){
  1106. // EASYUICONTEXT->updateLocalesCode(StoragePreferences::getString(STORE_LANG, defaultLang).c_str());
  1107. setTimeDifference();
  1108. setLangeuage();
  1109. //IO监测
  1110. // IGpioListener *iGpioListenerA1 = new A1GpioListener();
  1111. // GpioHelper::registerGpioListener("A1", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1112. //
  1113. // IGpioListener *iGpioListenerA2 = new A2GpioListener();
  1114. // GpioHelper::registerGpioListener("A2", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1115. //
  1116. // IGpioListener *iGpioListenerA3 = new A3GpioListener();
  1117. // GpioHelper::registerGpioListener("A3", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1118. //
  1119. // IGpioListener *iGpioListenerA4 = new A4GpioListener();
  1120. // GpioHelper::registerGpioListener("A4", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  1121. //TCP启动
  1122. TcpClient::instance()->startTcp();
  1123. //监听SIP信令
  1124. addSipCallStateListener();
  1125. //开启网页
  1126. httpServer.RunAsync(HTTP_SERVER_PORT);
  1127. // 启动的时候更改为tcp模式
  1128. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  1129. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  1130. LOGD("===============> 关闭护理状态");
  1131. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  1132. isNursing = true;
  1133. }
  1134. //请求版本号
  1135. // if(UartContext::Uart3IsOpen()) {
  1136. // string heartStr = "ASK,VNF-0";
  1137. // const char* sendMsg = heartStr.c_str();
  1138. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  1139. // }
  1140. #if 0
  1141. std::thread backend([](){
  1142. while (true) {
  1143. if (feed_dogs > 0) {
  1144. --feed_dogs;
  1145. LOGD("feed");
  1146. int ret = GpioHelper::output("GPIO_2", 1); //拉高
  1147. if (ret != 0) {
  1148. LOGE("GPIO操作失败");
  1149. }
  1150. usleep(1000 * 20);
  1151. ret = GpioHelper::output("GPIO_2", 0); //拉低
  1152. if (ret != 0) {
  1153. LOGE("GPIO操作失败");
  1154. }
  1155. }
  1156. usleep(1000 * 1000);
  1157. }
  1158. });
  1159. backend.detach();
  1160. #endif
  1161. }
  1162. /**
  1163. * 当切换到该界面时触发
  1164. */
  1165. static void onUI_intent(const Intent *intentPtr) {
  1166. if (intentPtr != NULL) {
  1167. //TODO
  1168. }
  1169. }
  1170. /*
  1171. * 当界面显示时触发
  1172. */
  1173. static void onUI_show() {
  1174. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  1175. //进入主界面
  1176. EASYUICONTEXT->openActivity("mainActivity");
  1177. }
  1178. /*
  1179. * 当界面隐藏时触发
  1180. */
  1181. static void onUI_hide() {
  1182. }
  1183. /*
  1184. * 当界面完全退出时触发
  1185. */
  1186. static void onUI_quit() {
  1187. }
  1188. /**
  1189. * 串口数据回调接口
  1190. */
  1191. static void onProtocolDataUpdate(const SProtocolData &data) {
  1192. LOGD("cmd = %s", data.cmd.c_str());
  1193. if (getIsUpdate()) {
  1194. LOGD("处于升级过程中,串口不可使用");
  1195. return;
  1196. }
  1197. if (data.state!=""){
  1198. LOGD("state = %s",data.state.c_str());
  1199. }
  1200. string heartStr;
  1201. if (data.state == "0") {
  1202. if (data.cmd == "KEY5") {
  1203. isTriggerKey5 = true;
  1204. mActivityPtr->registerUserTimer(KEY5_TRIGGER_TIME_HANDLE, 3 * 1000);
  1205. }
  1206. else if (data.cmd == "KEY6") {
  1207. isTriggerKey6 = true;
  1208. mActivityPtr->registerUserTimer(KEY6_TRIGGER_TIME_HANDLE, 3 * 1000);
  1209. }
  1210. else if (data.cmd == "KEY7") {
  1211. isTriggerKey7 = true;
  1212. mActivityPtr->registerUserTimer(KEY7_TRIGGER_TIME_HANDLE, 3 * 1000);
  1213. }
  1214. else if (data.cmd == "KEY>") {
  1215. isTriggerKey8 = true;
  1216. mActivityPtr->registerUserTimer(KEY8_TRIGGER_TIME_HANDLE, 3 * 1000);
  1217. }
  1218. else if (data.cmd == "KEY<") {
  1219. isTriggerKey9 = true;
  1220. mActivityPtr->registerUserTimer(KEY9_TRIGGER_TIME_HANDLE, 3 * 1000);
  1221. }
  1222. else if (data.cmd == "KEY;") {
  1223. isTriggerKey10 = true;
  1224. mActivityPtr->registerUserTimer(KEY10_TRIGGER_TIME_HANDLE, 3 * 1000);
  1225. }
  1226. else if (data.cmd == "KEY?") {
  1227. isTriggerKey11 = true;
  1228. mActivityPtr->registerUserTimer(KEY11_TRIGGER_TIME_HANDLE, 3 * 1000);
  1229. }
  1230. else if (data.cmd == "KEY=") {
  1231. isTriggerKey12 = true;
  1232. mActivityPtr->registerUserTimer(KEY12_TRIGGER_TIME_HANDLE, 3 * 1000);
  1233. }
  1234. else if (data.cmd == "KEY@") {
  1235. isTriggerKey13 = true;
  1236. mActivityPtr->registerUserTimer(KEY13_TRIGGER_TIME_HANDLE, 3 * 1000);
  1237. }
  1238. else if (data.cmd == "HANDKEY00") {
  1239. isTriggerHandle1 = true;
  1240. mActivityPtr->registerUserTimer(HANDLE1_TRIGGER_TIME_HANDLE, 3 * 1000);
  1241. }
  1242. else if (data.cmd == "HANDKEY10") {
  1243. isTriggerHandle2 = true;
  1244. mActivityPtr->registerUserTimer(HANDLE2_TRIGGER_TIME_HANDLE, 3 * 1000);
  1245. }
  1246. else if (data.cmd == "HANDKEY20") {
  1247. isTriggerHandle3 = true;
  1248. mActivityPtr->registerUserTimer(HANDLE3_TRIGGER_TIME_HANDLE, 3 * 1000);
  1249. }
  1250. else if (data.cmd == "HANDKEY30") {
  1251. isTriggerHandle4 = true;
  1252. mActivityPtr->registerUserTimer(HANDLE4_TRIGGER_TIME_HANDLE, 3 * 1000);
  1253. }
  1254. else if (data.cmd == "OUTKEY1") {
  1255. isTriggerOutKey1 = true;
  1256. mActivityPtr->registerUserTimer(OUTKYE1_TRIGGER_TIME_HANDLE, 3 * 1000);
  1257. }
  1258. else if (data.cmd == "OUTKEY2") {
  1259. isTriggerOutKey2 = true;
  1260. mActivityPtr->registerUserTimer(OUTKYE2_TRIGGER_TIME_HANDLE, 3 * 1000);
  1261. }
  1262. else if (data.cmd == "OUTKEY3") {
  1263. isTriggerOutKey3 = true;
  1264. mActivityPtr->registerUserTimer(OUTKYE3_TRIGGER_TIME_HANDLE, 3 * 1000);
  1265. }
  1266. else if (data.cmd == "OUTKEY4") {
  1267. isTriggerOutKey4 = true;
  1268. mActivityPtr->registerUserTimer(OUTKYE4_TRIGGER_TIME_HANDLE, 3 * 1000);
  1269. }
  1270. else if (data.cmd == "OUTKEY5") {
  1271. isTriggerOutKey5 = true;
  1272. mActivityPtr->registerUserTimer(OUTKYE5_TRIGGER_TIME_HANDLE, 3 * 1000);
  1273. }
  1274. else if (data.cmd == "OUTKEY6") {
  1275. isTriggerOutKey6 = true;
  1276. mActivityPtr->registerUserTimer(OUTKYE6_TRIGGER_TIME_HANDLE, 3 * 1000);
  1277. }
  1278. }
  1279. else if (data.state == "1") {
  1280. if ((data.cmd == "KEY5" && isTriggerKey5) ||
  1281. (data.cmd == "KEY6" && isTriggerKey6) ||
  1282. (data.cmd == "KEY7" && isTriggerKey7) ||
  1283. (data.cmd == "KEY>" && isTriggerKey8) ||
  1284. (data.cmd == "KEY<" && isTriggerKey9) ||
  1285. (data.cmd == "KEY;" && isTriggerKey10) ||
  1286. (data.cmd == "KEY?" && isTriggerKey11) ||
  1287. (data.cmd == "KEY=" && isTriggerKey12) ||
  1288. (data.cmd == "KEY@" && isTriggerKey13) ||
  1289. (data.cmd == "HANDKEY00" && isTriggerHandle1) ||
  1290. (data.cmd == "HANDKEY10" && isTriggerHandle2) ||
  1291. (data.cmd == "HANDKEY20" && isTriggerHandle3) ||
  1292. (data.cmd == "HANDKEY30" && isTriggerHandle4) ||
  1293. (data.cmd == "OUTKEY1" && isTriggerOutKey1) ||
  1294. (data.cmd == "OUTKEY2" && isTriggerOutKey2) ||
  1295. (data.cmd == "OUTKEY3" && isTriggerOutKey3) ||
  1296. (data.cmd == "OUTKEY4" && isTriggerOutKey4) ||
  1297. (data.cmd == "OUTKEY5" && isTriggerOutKey5) ||
  1298. (data.cmd == "OUTKEY6" && isTriggerOutKey6)) {
  1299. getDeviceButtonFunction(data.cmd);
  1300. }
  1301. }
  1302. else if (data.state == "3") {
  1303. if (data.cmd == "KEY6") {
  1304. isConnectHandle = true;
  1305. }
  1306. else if (data.cmd == "KEY7") {
  1307. isConnectSos = true;
  1308. }
  1309. else if (data.cmd == "HANDKEY00") {
  1310. isConnectHandle1 = true;
  1311. }
  1312. else if (data.cmd == "HANDKEY10") {
  1313. isConnectHandle2 = true;
  1314. }
  1315. else if (data.cmd == "HANDKEY20") {
  1316. isConnectHandle3 = true;
  1317. }
  1318. else if (data.cmd == "HANDKEY30") {
  1319. isConnectHandle4 = true;
  1320. }
  1321. else if (data.cmd == "OUTKEY1") {
  1322. isConnectOutKey1 = true;
  1323. }
  1324. else if (data.cmd == "OUTKEY2") {
  1325. isConnectOutKey2 = true;
  1326. }
  1327. else if (data.cmd == "OUTKEY3") {
  1328. isConnectOutKey3 = true;
  1329. }
  1330. else if (data.cmd == "OUTKEY4") {
  1331. isConnectOutKey4 = true;
  1332. }
  1333. else if (data.cmd == "OUTKEY5") {
  1334. isConnectOutKey5 = true;
  1335. }
  1336. else if (data.cmd == "OUTKEY6") {
  1337. isConnectOutKey6 = true;
  1338. }
  1339. }
  1340. else if (data.state == "4") {
  1341. if (data.cmd == "KEY6" && isConnectHandle) {
  1342. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("HandleDisconnected"));
  1343. }
  1344. else if (data.cmd == "KEY7" && isConnectSos) {
  1345. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("SosDisconnected"));
  1346. }
  1347. else if (data.cmd == "HANDKEY00" && isConnectHandle1) {
  1348. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle1Disconnected"));
  1349. }
  1350. else if (data.cmd == "HANDKEY10" && isConnectHandle2) {
  1351. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle2Disconnected"));
  1352. }
  1353. else if (data.cmd == "HANDKEY20" && isConnectHandle3) {
  1354. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle3Disconnected"));
  1355. }
  1356. else if (data.cmd == "HANDKEY30" && isConnectHandle4) {
  1357. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle4Disconnected"));
  1358. }
  1359. else if (data.cmd == "OUTKEY1" && isConnectOutKey1) {
  1360. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle1Disconnected"));
  1361. }
  1362. else if (data.cmd == "OUTKEY2" && isConnectOutKey2) {
  1363. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle2Disconnected"));
  1364. }
  1365. else if (data.cmd == "OUTKEY3" && isConnectOutKey3) {
  1366. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle3Disconnected"));
  1367. }
  1368. else if (data.cmd == "OUTKEY4" && isConnectOutKey4) {
  1369. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle4Disconnected"));
  1370. }
  1371. else if (data.cmd == "OUTKEY5" && isConnectOutKey5) {
  1372. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle5Disconnected"));
  1373. }
  1374. else if (data.cmd == "OUTKEY6" && isConnectOutKey6) {
  1375. sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle6Disconnected"));
  1376. }
  1377. }
  1378. // if(UartContext::Uart2IsOpen()) { // 如果是true,表示串口打开了
  1379. // string heartStr;
  1380. //
  1381. // // 面板拨号
  1382. // if (data.cmd == "KEY5") {
  1383. // if (data.state == "0") {
  1384. // if (isSleep) {
  1385. // scrrenOn();
  1386. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  1387. // return;
  1388. // }
  1389. // }
  1390. //
  1391. // const char* currentAppName = EASYUICONTEXT->currentAppName();
  1392. // string _currentAppName = currentAppName;
  1393. // if (_currentAppName == "sipTestActivity") {
  1394. // setCheckbox("KEY5");
  1395. // return;
  1396. // }
  1397. // else {
  1398. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1399. // //拨打 或 挂断
  1400. // if (CallingStatus::instance()->busy()){
  1401. // callActivityFinish(CallFinishType::A1CLICK);
  1402. // lightControl("DOORLED", "000F");
  1403. // } else {
  1404. // lightControl("DOORLED", "100F");
  1405. //
  1406. // Intent* intent = new Intent();
  1407. // intent->putExtra(isOutgoing, "true");
  1408. // EASYUICONTEXT->openActivity("callActivity", intent);
  1409. // }
  1410. // }
  1411. // }
  1412. // }
  1413. // else if (data.cmd == "KEY6") {
  1414. // if (data.state == "0") {
  1415. // if (isSleep) {
  1416. // scrrenOn();
  1417. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  1418. // return;
  1419. // }
  1420. // }
  1421. //
  1422. // const char* currentAppName = EASYUICONTEXT->currentAppName();
  1423. // string _currentAppName = currentAppName;
  1424. // if (_currentAppName == "sipTestActivity") {
  1425. // setCheckbox("KEY6");
  1426. // return;
  1427. // }
  1428. //
  1429. // isTriggerHandle = true;
  1430. // mActivityPtr->registerUserTimer(HANDLE_TRIGGER_TIME_HANDLE, 5 * 1000);
  1431. //
  1432. // }
  1433. // else if (data.state == "1") {
  1434. // if (isTriggerHandle) {
  1435. // isTriggerHandle = false;
  1436. // isConnectHandle = true;
  1437. //
  1438. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1439. // //拨打 或 挂断
  1440. // if (CallingStatus::instance()->busy()){
  1441. // callActivityFinish(CallFinishType::KEY6_CLICK);
  1442. // lightControl("DOORLED", "000F");
  1443. // } else {
  1444. // lightControl("DOORLED", "100F");
  1445. //
  1446. // Intent* intent = new Intent();
  1447. // intent->putExtra(isOutgoing, "true");
  1448. // EASYUICONTEXT->openActivity("callActivity", intent);
  1449. // }
  1450. // }
  1451. // }
  1452. // else if (data.state == "3") {
  1453. // LOGD("手柄在线");
  1454. // isConnectHandle = true;
  1455. // }
  1456. // else if (data.state == "4") {
  1457. // if (!isConnectHandle || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
  1458. // return;
  1459. // }
  1460. // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("HandleDisconnected"));
  1461. // }
  1462. //
  1463. // }
  1464. // else if (data.cmd == "KEY7") {
  1465. // if (data.state == "0") {
  1466. // scrrenOn();
  1467. //
  1468. // const char* currentAppName = EASYUICONTEXT->currentAppName();
  1469. // string _currentAppName = currentAppName;
  1470. // if (_currentAppName == "sipTestActivity") {
  1471. // setCheckbox("KEY7");
  1472. // return;
  1473. // }
  1474. // else {
  1475. // if (sosTimerRegistered) {
  1476. // isTriggerSos = true;
  1477. // mActivityPtr->registerUserTimer(SOS_TRIGGER_TIME_HANDLE, 5 * 1000);
  1478. // }
  1479. // }
  1480. // }
  1481. // else if (data.state == "1") {
  1482. // if (isTriggerSos) {
  1483. // isConnectSos = true;
  1484. // sosCall("");
  1485. // }
  1486. // }
  1487. // else if (data.state == "3") {
  1488. // LOGD("SOS按钮在线");
  1489. // isConnectSos = true;
  1490. // }
  1491. // else if (data.state == "4") {
  1492. // if (!isConnectSos || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
  1493. // return;
  1494. // }
  1495. //
  1496. // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("SosDisconnected"));
  1497. // }
  1498. //
  1499. // }
  1500. // else if (data.cmd == "KEY<") {
  1501. // if (isSleep) {
  1502. // scrrenOn();
  1503. // }
  1504. //// lightControl("DOORLED", "100F");
  1505. // }
  1506. // else if (data.cmd == "KEY>") { // key>是面板挂断按钮
  1507. // if (data.state == "0") {
  1508. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  1509. // setCheckbox("KEY>");
  1510. // return;
  1511. // }
  1512. //
  1513. // if (isSleep) {
  1514. // scrrenOn();
  1515. // }
  1516. // else {
  1517. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1518. // //拨打 或 挂断
  1519. // if (CallingStatus::instance()->busy()){
  1520. // callActivityFinish(CallFinishType::A1CLICK);
  1521. // lightControl("DOORLED", "000F");
  1522. // }
  1523. // }
  1524. // }
  1525. //
  1526. // }
  1527. // else if (data.cmd == "KEY;") {
  1528. // if (isSleep) {
  1529. // scrrenOn();
  1530. // }
  1531. //// lightControl("DOORLED", "111F");
  1532. // }
  1533. // else if (data.cmd == "HANDKEY00") {
  1534. // if (data.state == "0") {
  1535. // if (isSleep) {
  1536. // scrrenOn();
  1537. // }
  1538. //
  1539. // isTriggerHandle1 = true;
  1540. // mActivityPtr->registerUserTimer(HANDLE1_TRIGGER_TIME_HANDLE, 5 * 1000);
  1541. // }
  1542. // else if (data.state == "1") {
  1543. // if (isTriggerHandle1) {
  1544. // isTriggerHandle1 = false;
  1545. // isConnectHandle1 = true;
  1546. //
  1547. // handleHCall(1);
  1548. // }
  1549. // }
  1550. // else if (data.state == "3") {
  1551. // LOGD("手柄1在线");
  1552. // isConnectHandle1 = true;
  1553. // }
  1554. // else if (data.state == "4") {
  1555. // if (!isConnectHandle1 || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
  1556. // return;
  1557. // }
  1558. // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle1Disconnected"));
  1559. // }
  1560. // }
  1561. // else if (data.cmd == "HANDKEY10") {
  1562. // if (data.state == "0") {
  1563. // if (isSleep) {
  1564. // scrrenOn();
  1565. // }
  1566. //
  1567. // isTriggerHandle2 = true;
  1568. // mActivityPtr->registerUserTimer(HANDLE2_TRIGGER_TIME_HANDLE, 5 * 1000);
  1569. // }
  1570. // else if (data.state == "1") {
  1571. // if (isTriggerHandle2) {
  1572. // isTriggerHandle2 = false;
  1573. // isConnectHandle2 = true;
  1574. //
  1575. // handleHCall(2);
  1576. // }
  1577. // }
  1578. // else if (data.state == "3") {
  1579. // LOGD("手柄2在线");
  1580. // isConnectHandle2 = true;
  1581. // }
  1582. // else if (data.state == "4" || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
  1583. // if (!isConnectHandle2) {
  1584. // return;
  1585. // }
  1586. // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle2Disconnected"));
  1587. // }
  1588. // }
  1589. // else if (data.cmd == "HANDKEY20") {
  1590. // if (data.state == "0") {
  1591. // if (isSleep) {
  1592. // scrrenOn();
  1593. // }
  1594. //
  1595. // isTriggerHandle3 = true;
  1596. // mActivityPtr->registerUserTimer(HANDLE3_TRIGGER_TIME_HANDLE, 5 * 1000);
  1597. // }
  1598. // else if (data.state == "1") {
  1599. // if (isTriggerHandle3) {
  1600. // isTriggerHandle3 = false;
  1601. // isConnectHandle3 = true;
  1602. //
  1603. // handleHCall(3);
  1604. // }
  1605. // }
  1606. // else if (data.state == "3") {
  1607. // LOGD("手柄3在线");
  1608. // isConnectHandle3 = true;
  1609. // }
  1610. // else if (data.state == "4" || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
  1611. // if (!isConnectHandle3) {
  1612. // return;
  1613. // }
  1614. // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle3Disconnected"));
  1615. // }
  1616. // }
  1617. // else if (data.cmd == "HANDKEY30") {
  1618. // if (data.state == "0") {
  1619. // if (isSleep) {
  1620. // scrrenOn();
  1621. // }
  1622. //
  1623. // isTriggerHandle4 = true;
  1624. // mActivityPtr->registerUserTimer(HANDLE4_TRIGGER_TIME_HANDLE, 5 * 1000);
  1625. // }
  1626. // else if (data.state == "1") {
  1627. // if (isTriggerHandle4) {
  1628. // isTriggerHandle4 = false;
  1629. // isConnectHandle4 = true;
  1630. //
  1631. // handleHCall(4);
  1632. // }
  1633. // }
  1634. // else if (data.state == "3") {
  1635. // LOGD("手柄4在线");
  1636. // isConnectHandle4 = true;
  1637. // }
  1638. // else if (data.state == "4" || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
  1639. // if (!isConnectHandle4) {
  1640. // return;
  1641. // }
  1642. // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle4Disconnected"));
  1643. // }
  1644. // }
  1645. // else {
  1646. // if (isSleep) {
  1647. // scrrenOn();
  1648. // }
  1649. // lightControl("DOORLED", "000F");
  1650. // }
  1651. // }
  1652. }
  1653. /**
  1654. * 定时器触发函数
  1655. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  1656. * 参数: id
  1657. * 当前所触发定时器的id,与注册时的id相同
  1658. * 返回值: true
  1659. * 继续运行当前定时器
  1660. * false
  1661. * 停止运行当前定时器
  1662. */
  1663. static bool onUI_Timer(int id){
  1664. switch (id) {
  1665. case 1:
  1666. {
  1667. //定时器跑在UI线程,这里将喂狗标记加1
  1668. //++feed_dogs;
  1669. //不用心跳
  1670. // if(UartContext::Uart3IsOpen()) {
  1671. // string heartStr = "HEART,1E";
  1672. // const char* sendMsg = heartStr.c_str();
  1673. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  1674. // }
  1675. }
  1676. break;
  1677. case 2: //TCP心跳
  1678. {
  1679. const char* req = "0";
  1680. TcpClient::instance()->sendMsg(req);
  1681. }
  1682. break;
  1683. case SOS_CLICK_TIME_HANDLE: {
  1684. sosTimerRegistered = true;
  1685. return false;
  1686. }
  1687. break;
  1688. case SOS_LAMP_TIME_HANDLE: {
  1689. // SOS还原成无灯光的状态
  1690. lightControl("ULED", "0F");
  1691. // 进行门灯还原
  1692. lightControl("DOORLED", "000F");
  1693. statusLight();
  1694. return false;
  1695. }
  1696. break;
  1697. case DOOR_LIGHT_TIME_HANDLE: {
  1698. if (_lightColorStr == _actualColorStr) {
  1699. _actualColorStr = "000F";
  1700. std::string heartStr = _typeStr + "," + _actualColorStr;
  1701. LOGD("=====> the heartStr == %s", heartStr.c_str());
  1702. const char* sendMsg = heartStr.c_str();
  1703. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  1704. }
  1705. else {
  1706. _actualColorStr = _lightColorStr;
  1707. std::string heartStr = _typeStr + "," + _actualColorStr;
  1708. LOGD("=====> the heartStr == %s", heartStr.c_str());
  1709. const char* sendMsg = heartStr.c_str();
  1710. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  1711. }
  1712. }
  1713. break;
  1714. case SLEEP_STRAT_TIME_HANDLE: { // 息屏
  1715. if (isSleepTimerRegistered) {
  1716. isSleep = true;
  1717. BRIGHTNESSHELPER->screenOff();
  1718. } else { // 如果是false的话,就需要关闭定时器
  1719. isSleep = false;
  1720. BRIGHTNESSHELPER->screenOn();
  1721. }
  1722. }
  1723. break;
  1724. case SYS_RESTART_TIME_HANDLE:
  1725. netresetInt += 1;
  1726. lightControl("NETRESET", "1F");
  1727. if (netresetInt == 5) {
  1728. LOGD("网卡重启无效,程序内部重启");
  1729. //重启
  1730. deviceReboot();
  1731. }
  1732. break;
  1733. case KEY5_TRIGGER_TIME_HANDLE: {
  1734. isTriggerKey5 = false;
  1735. }
  1736. break;
  1737. case KEY6_TRIGGER_TIME_HANDLE: {
  1738. isTriggerKey6 = false;
  1739. return false;
  1740. }
  1741. break;
  1742. case KEY7_TRIGGER_TIME_HANDLE: {
  1743. isTriggerKey7 = false;
  1744. return false;
  1745. }
  1746. break;
  1747. case KEY8_TRIGGER_TIME_HANDLE: {
  1748. isTriggerKey8 = false;
  1749. return false;
  1750. }
  1751. break;
  1752. case KEY9_TRIGGER_TIME_HANDLE: {
  1753. isTriggerKey9 = false;
  1754. return false;
  1755. }
  1756. break;
  1757. case KEY10_TRIGGER_TIME_HANDLE: {
  1758. isTriggerKey10 = false;
  1759. return false;
  1760. }
  1761. break;
  1762. case KEY11_TRIGGER_TIME_HANDLE: {
  1763. isTriggerKey11 = false;
  1764. return false;
  1765. }
  1766. break;
  1767. case KEY12_TRIGGER_TIME_HANDLE: {
  1768. isTriggerKey12 = false;
  1769. return false;
  1770. }
  1771. break;
  1772. case KEY13_TRIGGER_TIME_HANDLE: {
  1773. isTriggerKey13 = false;
  1774. return false;
  1775. }
  1776. break;
  1777. case HANDLE1_TRIGGER_TIME_HANDLE: {
  1778. isTriggerHandle1 = false;
  1779. return false;
  1780. }
  1781. break;
  1782. case HANDLE2_TRIGGER_TIME_HANDLE: {
  1783. isTriggerHandle2 = false;
  1784. return false;
  1785. }
  1786. break;
  1787. case HANDLE3_TRIGGER_TIME_HANDLE: {
  1788. isTriggerHandle3 = false;
  1789. return false;
  1790. }
  1791. break;
  1792. case HANDLE4_TRIGGER_TIME_HANDLE: {
  1793. isTriggerHandle4 = false;
  1794. return false;
  1795. }
  1796. break;
  1797. case OUTKYE1_TRIGGER_TIME_HANDLE: {
  1798. isTriggerOutKey1 = false;
  1799. return false;
  1800. }
  1801. break;
  1802. case OUTKYE2_TRIGGER_TIME_HANDLE: {
  1803. isTriggerOutKey2 = false;
  1804. return false;
  1805. }
  1806. break;
  1807. case OUTKYE3_TRIGGER_TIME_HANDLE: {
  1808. isTriggerOutKey3 = false;
  1809. return false;
  1810. }
  1811. break;
  1812. case OUTKYE4_TRIGGER_TIME_HANDLE: {
  1813. isTriggerOutKey4 = false;
  1814. return false;
  1815. }
  1816. break;
  1817. case OUTKYE5_TRIGGER_TIME_HANDLE: {
  1818. isTriggerOutKey5 = false;
  1819. return false;
  1820. }
  1821. break;
  1822. case OUTKYE6_TRIGGER_TIME_HANDLE: {
  1823. isTriggerOutKey6 = false;
  1824. return false;
  1825. }
  1826. break;
  1827. case SIP_RECONNECT_TIME_HANDLE: {
  1828. removeSipCallStateListener();
  1829. removeSipRegisterStateListener();
  1830. ReleaseTelephone();
  1831. addSipCallStateListener();
  1832. addSipRegisterStateListener();
  1833. return false;
  1834. }
  1835. break;
  1836. default:
  1837. break;
  1838. }
  1839. return true;
  1840. }
  1841. /**
  1842. * 有新的触摸事件时触发
  1843. * 参数:ev
  1844. * 新的触摸事件
  1845. * 返回值:true
  1846. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  1847. * false
  1848. * 触摸事件将继续传递到控件上
  1849. */
  1850. static bool onstartActivityTouchEvent(const MotionEvent &ev) {
  1851. switch (ev.mActionStatus) {
  1852. case MotionEvent::E_ACTION_DOWN://触摸按下
  1853. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  1854. break;
  1855. case MotionEvent::E_ACTION_MOVE://触摸滑动
  1856. break;
  1857. case MotionEvent::E_ACTION_UP: //触摸抬起
  1858. break;
  1859. default:
  1860. break;
  1861. }
  1862. return false;
  1863. }