startLogic.cc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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 "utils/GpioHelper.h"
  11. #include "utils/TimeHelper.h"
  12. #include "utils/BrightnessHelper.h"
  13. #include <time.h>
  14. #include <thread>
  15. #include <string>
  16. #include <unistd.h>
  17. #include <sys/reboot.h>
  18. #include "service/BusinessConfig.h"
  19. static bool sosTimerRegistered = true;
  20. static bool isSleepTimerRegistered = false; // 是否开启息屏定时任务
  21. static bool isSleep = false; // 是否在息屏
  22. static bool isNursing = false; // 用于启动时判断是否处于护理状态
  23. static bool isNetreset = false;
  24. static int netresetInt = 0;
  25. static string callTid = "";
  26. static bool isConnectHandle = false;
  27. static bool isConnectSos = false;
  28. static bool isTriggerHandle = false;
  29. static bool isTriggerSos = false;
  30. #define FUNCTION_TIMER_HANDLE 3 // 增援的定时器id
  31. #define SOS_CLICK_TIME_HANDLE 4 // sos的定时器id
  32. #define SOS_LAMP_TIME_HANDLE 5 // sos的门灯定时器id
  33. #define EVENT_TIME_HANDLE 8 // 事件定时器
  34. #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
  35. #define SYS_RESTART_TIME_HANDLE 10 // 重启
  36. #define PROMPT_TIME_HANDLE 11 // 提示语
  37. #define HANDLE_TRIGGER_TIME_HANDLE 15
  38. #define SOS_TRIGGER_TIME_HANDLE 16
  39. #define HTTP_SERVER_PORT 80
  40. srv::HttpServer httpServer;
  41. namespace {
  42. std::string uilogic[] = {
  43. "testActivity",
  44. "ui3Activity"
  45. };
  46. void CloseUi();
  47. int feed_dogs = 0;
  48. void PrintCallLog() {
  49. CallLogEntries entries;
  50. int ret = GetCallLog(&entries);
  51. LOGD("GetCallRecord %d", ret);
  52. for (auto r : entries) {
  53. LOGD("id=%d, uri=%s, contact=%s,duration=%d,created_at=%d",
  54. r.id, r.uri.c_str(), r.contact.c_str(), r.duration, r.created_at);
  55. }
  56. }
  57. void OnCallStateChanged(voip::Telephone* telephone, int call_id, voip::State state) {
  58. LOGD("call state = %d", state);
  59. if (state == voip::STATE_CALL_INCOMING
  60. || state == voip::STATE_CALL_CALLING
  61. || state == voip::STATE_CALL_CONFIRMED) {
  62. voip::CallInfo info = GetTelephone()->GetCallInfo();
  63. LOGD("info.id == %d", info.id);
  64. LOGD("info.remote_uri == %s", info.remote_uri.c_str());
  65. LOGD("info.remote_contact == %s", info.remote_contact.c_str());
  66. string sipId = info.remote_uri.substr(info.remote_uri.find(":") + 1, info.remote_uri.find("@") - info.remote_uri.find(":") - 1);
  67. LOGD("sipId == %s", sipId.c_str());
  68. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  69. EASYUICONTEXT->openActivity("callActivity");
  70. }
  71. else {
  72. if (sipId != "0000000000") {
  73. const char* currentAppName = EASYUICONTEXT->currentAppName();
  74. string _currentAppName = currentAppName;
  75. if (_currentAppName != "callActivity") {
  76. telephone->Hangup();
  77. LOGD("=================> 不在通话界面,直接挂断!");
  78. return;
  79. }
  80. }
  81. }
  82. if (state == voip::STATE_CALL_INCOMING) {
  83. if (telephone->GetCallCount() > 1) {
  84. LOGD("call count > 1, return");
  85. telephone->Hangup(call_id, voip::SIP_STATUS_CODE_BUSY_HERE);
  86. return;
  87. }
  88. //提前显示视频
  89. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  90. telephone->Answer(call_id, voip::SIP_STATUS_CODE_PROGRESS);
  91. telephone->Answer();
  92. } else {
  93. acceptSIP();
  94. }
  95. }
  96. }
  97. if (state == voip::STATE_CALL_DISCONNECTED) {
  98. if (telephone->GetCallCount() > 1) {
  99. LOGD("call count > 1, return");
  100. return;
  101. }
  102. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  103. //EASYUICONTEXT->goHome();
  104. EASYUICONTEXT->goBack();
  105. }
  106. //保存通话记录
  107. voip::CallInfo info = telephone->GetCallInfo(call_id);
  108. CallLogEntry entry;
  109. entry.uri = info.remote_uri;
  110. entry.contact = info.remote_contact;
  111. entry.duration = info.duration/1000;
  112. if (0 != PutCallLog(entry)) {
  113. LOGE("保存通话记录失败");
  114. }
  115. int n = GetCallLogCount();
  116. if (n > CALL_LOG_COUNT_MAX) {
  117. //超过最大通话记录条数,删除旧记录
  118. if (0 != DeleteOldCallLog(n - CALL_LOG_COUNT_MAX)) {
  119. LOGE("删除失败");
  120. }
  121. }
  122. //PrintCallLog();
  123. }
  124. }
  125. void CloseUi() {
  126. for(int i = 0; i < 2; i++){
  127. EASYUICONTEXT->closeActivity(uilogic[i].c_str());
  128. }
  129. }
  130. void setBrightness(){
  131. int dayLight = StoragePreferences::getInt(STORE_DAY_LIGHT,100);
  132. int nightLight = StoragePreferences::getInt(STORE_NIGHT_LIGHT,10);
  133. if (checkIsDay()){
  134. BRIGHTNESSHELPER->setBrightness(dayLight);
  135. } else {
  136. BRIGHTNESSHELPER->setBrightness(nightLight);
  137. }
  138. }
  139. }
  140. void systemRestart() {
  141. if (!isNetreset) {
  142. isNetreset = true;
  143. lightControl("CALLLED", "000F");
  144. mActivityPtr->registerUserTimer(SYS_RESTART_TIME_HANDLE, 1000);
  145. }
  146. }
  147. // 门灯还原
  148. void lightControl(std::string typeStr, std::string lightColorStr) {
  149. // 类型是门灯,并且还原成白色灯
  150. std::string heartStr;
  151. if (typeStr == "DOORLED" && lightColorStr == "000F") {
  152. //护理状态,需要还原成护理灯
  153. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  154. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  155. if (color != "" && color.size() == 3) {
  156. heartStr = "DOORLED," + color + "F";
  157. } else {
  158. heartStr = "DOORLED,010F";
  159. }
  160. }
  161. else {
  162. // 还原成无灯光的状态
  163. heartStr = "DOORLED,000F";
  164. }
  165. } else {
  166. heartStr = typeStr + "," + lightColorStr;
  167. }
  168. LOGD("=====> the heartStr == %s", heartStr.c_str());
  169. const char* sendMsg = heartStr.c_str();
  170. sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  171. }
  172. // 接收tcp消息
  173. void handleMsg(byte* inBytes){
  174. LOGD("TCP received: %s", inBytes);
  175. const char* cstr = reinterpret_cast<const char*>(inBytes);
  176. string str = cstr;
  177. if (str == "1"){
  178. LOGD("get a heart beat");
  179. return;
  180. }
  181. TcpModel tcpModel;
  182. tcpModel = getTcpModel(inBytes);
  183. LOGD("tcp model: %s, %s", tcpModel.type.c_str(), tcpModel.action.c_str());
  184. if (tcpModel.type == TcpType::OTHER) {
  185. LOGD("trans tcp json failed");
  186. } else if (tcpModel.type == TcpType::TIME) {
  187. if (tcpModel.action == TimeAction::SYNC) {
  188. string serverTime = "";
  189. if (tcpModel.data != ""){
  190. serverTime = tcpModel.data;
  191. } else {
  192. serverTime = tcpModel.json["time"].asString();
  193. }
  194. LOGD("sync time : %s", serverTime.c_str());
  195. time_t timet = stoi(serverTime);
  196. struct tm *t = gmtime(&timet);
  197. char pDate[25];
  198. sprintf(pDate,"%d-%02d-%02d %02d:%02d:%02d",
  199. 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday,
  200. t->tm_hour + 8,t->tm_min,t->tm_sec);
  201. LOGD("transfered time : %s", pDate);
  202. TimeHelper::setDateTime(pDate);
  203. dataRefresh();
  204. if (isNursing) {
  205. setNursingEnd();
  206. }
  207. }
  208. } else if (tcpModel.type == TcpType::REINFORCE){
  209. if (tcpModel.action == ReinforceAction::RESPONSED){
  210. //回调
  211. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  212. if (callback.tid != "0"){
  213. callback.onSuccess(tcpModel.json);
  214. }
  215. const char* currentAppName = EASYUICONTEXT->currentAppName();
  216. string _currentAppName = currentAppName;
  217. if (_currentAppName != "functionActivity") {
  218. Intent* intent = new Intent();
  219. intent->putExtra(functionWindows, "helpResonse");
  220. EASYUICONTEXT->openActivity("functionActivity", intent);
  221. } else {
  222. toFunctionActivity("");
  223. }
  224. }
  225. } else if (tcpModel.type == TcpType::DEVICE){
  226. if (tcpModel.action == DeviceAction::APP_UPDATE){ //软件升级
  227. if (isSleep) {
  228. isSleep = false;
  229. BRIGHTNESSHELPER->screenOn();
  230. }
  231. Intent* intent = new Intent();
  232. intent->putExtra(appUpdate, "true");
  233. EASYUICONTEXT->openActivity("updateActivity", intent);
  234. }
  235. else if (tcpModel.action == DeviceAction::RESTART) { // 重启设备
  236. const char* req = "-1";
  237. TcpClient::instance()->sendMsg(req);
  238. lightControl("CALLLED", "000F");
  239. sync();
  240. reboot(RB_AUTOBOOT);
  241. }
  242. else if (tcpModel.action == DeviceAction::REBOOT) {
  243. const char* req = "-1";
  244. TcpClient::instance()->sendMsg(req);
  245. lightControl("CALLLED", "000F");
  246. //重启
  247. sync();
  248. reboot(RB_AUTOBOOT);
  249. }
  250. else if (tcpModel.action == DeviceAction::DEVICE_REFRESH) { // 设备刷新
  251. dataRefresh();
  252. }
  253. else if (tcpModel.action == DeviceAction::SYSTEM_SETTING) { // 修改科室设置
  254. getPartSetting();
  255. }
  256. else if (tcpModel.action == DeviceAction::SERVER_CHANGE) {
  257. StoragePreferences::putString(STORE_GATEWAY, tcpModel.json["server_ip"].asCString());
  258. StoragePreferences::putString(STORE_HTTP_PORT, tcpModel.json["server_port"].asCString());
  259. const char* req = "-1";
  260. TcpClient::instance()->sendMsg(req);
  261. lightControl("CALLLED", "000F");
  262. //重启
  263. sync();
  264. reboot(RB_AUTOBOOT);
  265. }
  266. } else if (tcpModel.type == TcpType::DATA){
  267. if (tcpModel.action == DataAction::REFRESH){ // 刷新数据
  268. dataRefresh();
  269. }
  270. } else if (tcpModel.type == TcpType::VOICE){
  271. if (tcpModel.action == VoiceAction::FAILED){
  272. const char* currentAppName = EASYUICONTEXT->currentAppName();
  273. string _currentAppName = currentAppName;
  274. if (_currentAppName == "callActivity") {
  275. callActivityFinish(CallFinishType::FAILED);
  276. }
  277. } else if (tcpModel.action == VoiceAction::SUCCESS){
  278. CallingStatus::instance()->setTcpModel(tcpModel); // 只有呼叫成功才闪红灯
  279. lightControl("DOORLED", "200F");
  280. } else if (tcpModel.action == VoiceAction::ACCEPT){
  281. if (CallingStatus::instance()->busy()){
  282. CallingStatus::instance()->setTcpModel(tcpModel);
  283. std::string toSipId = tcpModel.json["toSipId"].asString();
  284. callActivityFinish(CallFinishType::ACCEPT);
  285. //接听
  286. buildSIP(toSipId);
  287. }
  288. // 进行门灯还原
  289. lightControl("DOORLED", "000F");
  290. } else if (tcpModel.action == VoiceAction::REJECT){
  291. if (CallingStatus::instance()->busy()){
  292. callActivityFinish(CallFinishType::REJECT);
  293. // 进行门灯还原
  294. lightControl("DOORLED", "000F");
  295. }
  296. } else if (tcpModel.action == VoiceAction::CANCEL){
  297. if (CallingStatus::instance()->busy()){
  298. callActivityFinish(CallFinishType::CANCEL);
  299. }
  300. } else if (tcpModel.action == VoiceAction::CALLING){
  301. //对方忙线
  302. callActivityFinish(CallFinishType::BUSY);
  303. } else if (tcpModel.action == VoiceAction::CALL){
  304. //我方忙线判断
  305. if (CallingStatus::instance()->busy()){
  306. sendVoiceTcp(VoiceAction::CALLING, tcpModel, tcpModel.from_id);
  307. } else {
  308. CallingStatus::instance()->setTcpModel(tcpModel);
  309. //来电话了
  310. Intent* intent = new Intent();
  311. intent->putExtra(isOutgoing, "false");
  312. intent->putExtra(audioOnly, "true");
  313. EASYUICONTEXT->openActivity("callActivity", intent);
  314. }
  315. } else if (tcpModel.action == VoiceAction::HANDOFF){
  316. //判断 是否同一个对话
  317. long iId = CallingStatus::instance()->getInteractionId();
  318. if (iId > 0 && CallingStatus::instance()->busy()){
  319. long inId = tcpModel.json["id"].asInt();
  320. if (iId == inId && CallingStatus::instance()->busy()){
  321. callActivityFinish(CallFinishType::HANDOFF);
  322. }
  323. }
  324. }
  325. }
  326. else if (tcpModel.type == TcpType::SOS) {
  327. if (tcpModel.action == SosAction::CANCEL) {
  328. // SOS还原成无灯光的状态
  329. lightControl("ULED", "0F");
  330. // 进行门灯还原
  331. lightControl("DOORLED", "000F");
  332. mActivityPtr->unregisterUserTimer(SOS_LAMP_TIME_HANDLE);
  333. }
  334. }
  335. else if (tcpModel.type == TcpType::SIDE) {
  336. if (tcpModel.action == SideAction::NURSING) {
  337. StoragePreferences::putString(STORE_NURSING_INTERACTION_ID, tcpModel.json["id"].asString());
  338. // 收到nursing,需要把通话给挂断了
  339. voip::CallInfo info = GetTelephone()->GetCallInfo();
  340. LOGD("info state = %d",info.state);
  341. if (info.state == voip::STATE_CALL_CALLING
  342. || info.state == voip::STATE_CALL_CALLING
  343. || info.state == voip::STATE_CALL_CONFIRMED){
  344. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  345. //只回传iId
  346. storeModel.data = storeModel.json["id"].asString();
  347. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  348. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  349. GetTelephone()->Hangup();
  350. EASYUICONTEXT->goBack();
  351. }
  352. std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
  353. if (color != "" && color.size() == 3) {
  354. color = color + "F";
  355. } else {
  356. color = "010F";
  357. }
  358. lightControl("DOORLED", color);
  359. }
  360. else if (tcpModel.action == SideAction::NURSING_END) {
  361. // 收到nursing_end
  362. lightControl("DOORLED", "000F");
  363. }
  364. else if (tcpModel.action == SideAction::CALL) {
  365. // 收到CALL,需要亮红灯
  366. lightControl("DOORLED", "200F");
  367. }
  368. else if (tcpModel.action == SideAction::ACCEPT) {
  369. // 进行门灯还原
  370. lightControl("DOORLED", "000F");
  371. }
  372. else if (tcpModel.action == SideAction::CANCEL) {
  373. // 进行门灯还原
  374. lightControl("DOORLED", "000F");
  375. }
  376. else if (tcpModel.action == SideAction::SOS_CALL) {
  377. // 收到SOS_CALL,需要亮红灯
  378. // 门灯亮红灯
  379. lightControl("DOORLED", "200F");
  380. lightControl("CALLLED", "100F");
  381. sosTimerRegistered = false;
  382. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  383. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  384. }
  385. else if (tcpModel.action == SideAction::SOS_CANCEL) {
  386. // 进行门灯还原
  387. lightControl("DOORLED", "000F");
  388. statusLight();
  389. }
  390. }
  391. else if (tcpModel.type == TcpType::CALLBACK) {
  392. if (tcpModel.action == CallbackAction::ACK) {
  393. LOGD("CALLBACK ACK !!!!");
  394. //回调
  395. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  396. if (callback.tid != "0"){
  397. callback.onSuccess(tcpModel.json);
  398. }
  399. }
  400. else if (tcpModel.action == CallbackAction::SUCCESS) {
  401. //回调
  402. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  403. if (callback.tid != "0"){
  404. callback.onSuccess(tcpModel.json);
  405. }
  406. }
  407. else if (tcpModel.action == CallbackAction::FAILED) {
  408. //回调
  409. TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
  410. if (callback.tid != "0"){
  411. callback.onFalied(tcpModel.json);
  412. }
  413. if (tcpModel.tid == callTid){
  414. callActivityFinish(CallFinishType::FAILED);
  415. }
  416. }
  417. }
  418. else if (tcpModel.type == TcpType::POSITION) {
  419. if (tcpModel.action == PositionAction::POSITION_START) {
  420. setPosistionItId(tcpModel.json["id"].asInt());
  421. }
  422. }
  423. else if (tcpModel.type == TcpType::ROOMCHECK) {
  424. if (tcpModel.action == RoomCheckAction::START) {
  425. setRoomCheckItId(tcpModel.json["id"].asInt());
  426. }
  427. }
  428. else if (tcpModel.type == TcpType::SCREEN_TIP) {
  429. if (tcpModel.action == ScreenTipAction::START) {
  430. setPromptTimeItId(tcpModel.json["id"].asInt());
  431. }
  432. }
  433. else if (tcpModel.type == TcpType::AUTH) {
  434. if (tcpModel.action == AuthAction::LOGIN) {
  435. // 需要判断fromId跟自己是不是一样的,一样的就代表是自己发送出去,不一样的就代表员工已经登录到其他设备去了
  436. if (tcpModel.from_id == StoragePreferences::getInt(STORE_DEVICE_ID, 0)) {
  437. LOGD("id ===> %d", tcpModel.json["id"].asInt());
  438. setAuthItId(tcpModel.json["id"].asInt());
  439. }
  440. else {
  441. navibarNfcLogout();
  442. // logoutMedicalCare();
  443. // const char* currentAppName = EASYUICONTEXT->currentAppName();
  444. // string _currentAppName = currentAppName;
  445. // if (_currentAppName == "medicalCareActivity") {
  446. // goHome();
  447. // }
  448. }
  449. }
  450. }
  451. else if (tcpModel.type == TcpType::BLUE_CODE) {
  452. if (tcpModel.action == BlueCodeAction::SUCCESS) {
  453. int id = tcpModel.json["id"].asInt();
  454. LOGD("blue code id ===> %d", id);
  455. setBlueCodeId(id, tcpModel.tid);
  456. }
  457. }
  458. }
  459. bool getSleepTimerRegistered() {
  460. return isSleepTimerRegistered;
  461. }
  462. // 触发定时任务
  463. void setSleepTimerRegistered(bool result) {
  464. LOGD("isSleepTimerRegistered = %d", isSleepTimerRegistered);
  465. LOGD("result = %d", result);
  466. if (mActivityPtr == NULL) {
  467. return;
  468. }
  469. if (result != isSleepTimerRegistered) { // 与定时任务不同时,才进行处理
  470. if (isSleepTimerRegistered) { // 与定时任务开关进行判断,如果定时任务开启,那就要关闭
  471. isSleepTimerRegistered = result;
  472. mActivityPtr->unregisterUserTimer(SLEEP_STRAT_TIME_HANDLE); // 关闭定时器
  473. if (isSleep) {
  474. isSleep = false;
  475. BRIGHTNESSHELPER->screenOn();
  476. }
  477. LOGD("关闭息屏");
  478. } else { // 如果定时任务关着,那就要打开
  479. isSleepTimerRegistered = result;
  480. int sleepTime = StoragePreferences::getInt(STORE_SLEEP_TIME, 3);
  481. if (sleepTime > 0) {
  482. mActivityPtr->registerUserTimer(SLEEP_STRAT_TIME_HANDLE, sleepTime * 60 * 1000);
  483. LOGD("开启息屏");
  484. }
  485. }
  486. }
  487. }
  488. void scrrenOn() {
  489. isSleep = false;
  490. BRIGHTNESSHELPER->screenOn();
  491. }
  492. void setCallTid(std::string tid) {
  493. callTid = tid;
  494. }
  495. //================================= IO 口操作
  496. //紧急按钮灯,明/灭
  497. void setSOS_A5(bool light){
  498. int result = -1;
  499. int slight = light?0:1;
  500. result = GpioHelper::output("A5", slight);
  501. if (result==0){
  502. LOGD("set A5 SOS light %d. success",light);
  503. } else {
  504. LOGD("set A5 SOS light %d. failed",light);
  505. }
  506. }
  507. //A6,A7,A8 RGB灯控制
  508. void setRGB_A678(bool R, bool G, bool B){
  509. int rR = -1, rG = -1, rB = -1;
  510. int sR = R?0:1, sG = G?0:1, sB = B?0:1;
  511. rR = GpioHelper::output("A6", sR);
  512. rG = GpioHelper::output("A7", sG);
  513. rB = GpioHelper::output("A8", sB);
  514. const char *strLog = "set %s light %d. %d";
  515. LOGD(strLog,"A6 R",R, rR);
  516. LOGD(strLog,"A7 G",G, rG);
  517. LOGD(strLog,"A8 B",B, rB);
  518. }
  519. //手柄按钮
  520. class A1GpioListener : public IGpioListener{
  521. public:
  522. bool onGpioEdge(const char *pPin) override {
  523. int state = GpioHelper::input("A1");
  524. LOGD("IGpioListener GPIO IS A1=%d", state);
  525. if (state==0){
  526. voip::CallInfo info = GetTelephone()->GetCallInfo();
  527. //拨打 或 挂断
  528. if (CallingStatus::instance()->busy()){
  529. callActivityFinish(CallFinishType::A1CLICK);
  530. } else {
  531. Intent* intent = new Intent();
  532. intent->putExtra(isOutgoing, "true");
  533. intent->putExtra(audioOnly, "true");
  534. EASYUICONTEXT->openActivity("callActivity", intent);
  535. }
  536. }
  537. return true;
  538. }
  539. void onGpioError(const char *pPin, int error) override {
  540. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  541. }
  542. };
  543. //7寸面板,呼出
  544. class A2GpioListener : public IGpioListener{
  545. public:
  546. bool onGpioEdge(const char *pPin) override {
  547. int state = GpioHelper::input("A2");
  548. LOGD("IGpioListener GPIO IS A2=%d", state);
  549. if (state==0){
  550. //拨打 或 接听
  551. }
  552. return true;
  553. }
  554. void onGpioError(const char *pPin, int error) override {
  555. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  556. }
  557. };
  558. //7寸面板,挂断
  559. class A3GpioListener : public IGpioListener{
  560. public:
  561. bool onGpioEdge(const char *pPin) override {
  562. int state = GpioHelper::input("A3");
  563. LOGD("IGpioListener GPIO IS A3=%d", state);
  564. if (state==0){
  565. //挂断
  566. }
  567. return true;
  568. }
  569. void onGpioError(const char *pPin, int error) override {
  570. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  571. }
  572. };
  573. //紧急按钮
  574. class A4GpioListener : public IGpioListener{
  575. public:
  576. bool onGpioEdge(const char *pPin) override {
  577. int state = GpioHelper::input("A4");
  578. LOGD("IGpioListener GPIO IS A4=%d", state);
  579. if (state==0){
  580. //发出
  581. setSOS_A5(true);
  582. }
  583. return true;
  584. }
  585. void onGpioError(const char *pPin, int error) override {
  586. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  587. }
  588. };
  589. /**
  590. * 注册定时器
  591. * 填充数组用于注册定时器
  592. * 注意:id不能重复
  593. */
  594. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  595. {1, 5000},
  596. {2, 30*1000}
  597. };
  598. /**
  599. * 当界面构造时触发
  600. */
  601. static void onUI_init(){
  602. //IO监测
  603. IGpioListener *iGpioListenerA1 = new A1GpioListener();
  604. GpioHelper::registerGpioListener("A1", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  605. IGpioListener *iGpioListenerA2 = new A2GpioListener();
  606. GpioHelper::registerGpioListener("A2", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  607. IGpioListener *iGpioListenerA3 = new A3GpioListener();
  608. GpioHelper::registerGpioListener("A3", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  609. IGpioListener *iGpioListenerA4 = new A4GpioListener();
  610. GpioHelper::registerGpioListener("A4", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  611. //TCP启动
  612. TcpClient::instance()->startTcp();
  613. //监听SIP信令
  614. GetTelephone()->AddCallStateListener(OnCallStateChanged);
  615. //开启网页
  616. httpServer.RunAsync(HTTP_SERVER_PORT);
  617. // 启动的时候更改为tcp模式
  618. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  619. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  620. LOGD("===============> 关闭护理状态");
  621. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  622. isNursing = true;
  623. }
  624. //请求版本号
  625. // if(UartContext::Uart3IsOpen()) {
  626. // string heartStr = "ASK,VNF-0";
  627. // const char* sendMsg = heartStr.c_str();
  628. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  629. // }
  630. #if 0
  631. std::thread backend([](){
  632. while (true) {
  633. if (feed_dogs > 0) {
  634. --feed_dogs;
  635. LOGD("feed");
  636. int ret = GpioHelper::output("GPIO_2", 1); //拉高
  637. if (ret != 0) {
  638. LOGE("GPIO操作失败");
  639. }
  640. usleep(1000 * 20);
  641. ret = GpioHelper::output("GPIO_2", 0); //拉低
  642. if (ret != 0) {
  643. LOGE("GPIO操作失败");
  644. }
  645. }
  646. usleep(1000 * 1000);
  647. }
  648. });
  649. backend.detach();
  650. #endif
  651. }
  652. /**
  653. * 当切换到该界面时触发
  654. */
  655. static void onUI_intent(const Intent *intentPtr) {
  656. if (intentPtr != NULL) {
  657. //TODO
  658. }
  659. }
  660. /*
  661. * 当界面显示时触发
  662. */
  663. static void onUI_show() {
  664. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  665. //进入主界面
  666. EASYUICONTEXT->openActivity("mainActivity");
  667. }
  668. /*
  669. * 当界面隐藏时触发
  670. */
  671. static void onUI_hide() {
  672. }
  673. /*
  674. * 当界面完全退出时触发
  675. */
  676. static void onUI_quit() {
  677. }
  678. /**
  679. * 串口数据回调接口
  680. */
  681. static void onProtocolDataUpdate(const SProtocolData &data) {
  682. LOGD("cmd = %s", data.cmd.c_str());
  683. if (data.state!=""){
  684. LOGD("state = %s",data.state.c_str());
  685. }
  686. // if (data.msg != ""){
  687. // LOGD("msg = %s", data.msg.c_str());
  688. // }
  689. if(UartContext::Uart3IsOpen()) { // 如果是true,表示串口打开了
  690. string heartStr;
  691. // 面板拨号
  692. if (data.cmd == "KEY5") {
  693. if (data.state == "0") {
  694. if (isSleep) {
  695. scrrenOn();
  696. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  697. return;
  698. }
  699. }
  700. const char* currentAppName = EASYUICONTEXT->currentAppName();
  701. string _currentAppName = currentAppName;
  702. if (_currentAppName == "sipTestActivity") {
  703. setCheckbox("KEY5");
  704. return;
  705. }
  706. else {
  707. voip::CallInfo info = GetTelephone()->GetCallInfo();
  708. //拨打 或 挂断
  709. if (CallingStatus::instance()->busy()){
  710. callActivityFinish(CallFinishType::A1CLICK);
  711. } else {
  712. Intent* intent = new Intent();
  713. intent->putExtra(isOutgoing, "true");
  714. intent->putExtra(audioOnly, "true");
  715. EASYUICONTEXT->openActivity("callActivity", intent);
  716. }
  717. }
  718. }
  719. }
  720. else if (data.cmd == "KEY6") {
  721. if (data.state == "0") {
  722. if (isSleep) {
  723. scrrenOn();
  724. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  725. return;
  726. }
  727. }
  728. const char* currentAppName = EASYUICONTEXT->currentAppName();
  729. string _currentAppName = currentAppName;
  730. if (_currentAppName == "sipTestActivity") {
  731. setCheckbox("KEY6");
  732. return;
  733. }
  734. isTriggerHandle = true;
  735. mActivityPtr->registerUserTimer(HANDLE_TRIGGER_TIME_HANDLE, 5 * 1000);
  736. }
  737. else if (data.state == "1") {
  738. if (isTriggerHandle) {
  739. isTriggerHandle = false;
  740. voip::CallInfo info = GetTelephone()->GetCallInfo();
  741. //拨打 或 挂断
  742. if (CallingStatus::instance()->busy()){
  743. callActivityFinish(CallFinishType::KEY6_CLICK);
  744. } else {
  745. Intent* intent = new Intent();
  746. intent->putExtra(isOutgoing, "true");
  747. intent->putExtra(audioOnly, "true");
  748. EASYUICONTEXT->openActivity("callActivity", intent);
  749. }
  750. }
  751. }
  752. else if (data.state == "3") {
  753. isConnectHandle = true;
  754. }
  755. else if (data.state == "4") {
  756. if (!isConnectHandle) {
  757. return;
  758. }
  759. if (sosTimerRegistered) {
  760. LOGD("TCP -> SOS_CALL");
  761. Json::Value data;
  762. data["title"] = "手柄断连";
  763. TcpModel tcpModel;
  764. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  765. tcpModel.type = TcpType::SOS;
  766. tcpModel.action = SosAction::CALL;
  767. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  768. tcpModel.json = data;
  769. std::string req = getTcpModelString(tcpModel);
  770. LOGD("TCP SOS_CALL : %s",req.c_str());
  771. TcpClient::instance()->sendMsg(req.c_str());
  772. // SOS亮红灯
  773. lightControl("ULED", "1F");
  774. // 门灯亮红灯
  775. lightControl("DOORLED", "200F");
  776. lightControl("CALLLED", "100F");
  777. sosTimerRegistered = false;
  778. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  779. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  780. }
  781. }
  782. }
  783. else if (data.cmd == "KEY7") {
  784. if (data.state == "0") {
  785. scrrenOn();
  786. const char* currentAppName = EASYUICONTEXT->currentAppName();
  787. string _currentAppName = currentAppName;
  788. if (_currentAppName == "sipTestActivity") {
  789. setCheckbox("KEY7");
  790. return;
  791. }
  792. else {
  793. if (sosTimerRegistered) {
  794. isTriggerSos = true;
  795. mActivityPtr->registerUserTimer(SOS_TRIGGER_TIME_HANDLE, 5 * 1000);
  796. }
  797. }
  798. }
  799. else if (data.state == "1") {
  800. if (isTriggerSos) {
  801. LOGD("TCP -> SOS_CALL");
  802. TcpModel tcpModel;
  803. tcpModel.type = TcpType::SOS;
  804. tcpModel.action = SosAction::CALL;
  805. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  806. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  807. std::string req = getTcpModelString(tcpModel);
  808. LOGD("TCP SOS_CALL : %s",req.c_str());
  809. TcpClient::instance()->sendMsg(req.c_str());
  810. // SOS亮红灯
  811. lightControl("ULED", "1F");
  812. // 门灯亮红灯
  813. lightControl("DOORLED", "200F");
  814. lightControl("CALLLED", "100F");
  815. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  816. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  817. }
  818. }
  819. else if (data.state == "3") {
  820. isConnectSos = true;
  821. }
  822. else if (data.state == "4") {
  823. if (!isConnectSos) {
  824. return;
  825. }
  826. if (sosTimerRegistered) {
  827. LOGD("TCP -> SOS_CALL");
  828. Json::Value data;
  829. data["title"] = "紧急按钮断连";
  830. TcpModel tcpModel;
  831. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  832. tcpModel.type = TcpType::SOS;
  833. tcpModel.action = SosAction::CALL;
  834. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  835. tcpModel.json = data;
  836. std::string req = getTcpModelString(tcpModel);
  837. LOGD("TCP SOS_CALL : %s",req.c_str());
  838. TcpClient::instance()->sendMsg(req.c_str());
  839. // SOS亮红灯
  840. lightControl("ULED", "1F");
  841. // 门灯亮红灯
  842. lightControl("DOORLED", "200F");
  843. lightControl("CALLLED", "100F");
  844. sosTimerRegistered = false;
  845. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  846. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  847. }
  848. }
  849. }
  850. else if (data.cmd == "KEY<") {
  851. if (isSleep) {
  852. scrrenOn();
  853. }
  854. // lightControl("DOORLED", "100F");
  855. }
  856. else if (data.cmd == "KEY>") { // key>是面板挂断按钮
  857. if (data.state == "0") {
  858. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  859. setCheckbox("KEY>");
  860. return;
  861. }
  862. if (isSleep) {
  863. scrrenOn();
  864. }
  865. else {
  866. voip::CallInfo info = GetTelephone()->GetCallInfo();
  867. //拨打 或 挂断
  868. if (CallingStatus::instance()->busy()){
  869. callActivityFinish(CallFinishType::A1CLICK);
  870. lightControl("DOORLED", "000F");
  871. }
  872. }
  873. }
  874. }
  875. else if (data.cmd == "KEY;") {
  876. if (isSleep) {
  877. scrrenOn();
  878. }
  879. // lightControl("DOORLED", "111F");
  880. }
  881. else {
  882. if (isSleep) {
  883. scrrenOn();
  884. }
  885. lightControl("DOORLED", "000F");
  886. }
  887. // //按下
  888. // if (data.state=="0"){ // 0表示正被按下,1表示短按松开,2表示长按松开。
  889. // if (data.cmd == "KEY5") { // key5是面板拨号按钮
  890. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  891. // setCheckbox("KEY5");
  892. // return;
  893. // }
  894. //
  895. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  896. // if (isSleep) {
  897. // scrrenOn();
  898. // }
  899. // else {
  900. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  901. // //拨打 或 挂断
  902. // if (CallingStatus::instance()->busy()){
  903. // callActivityFinish(CallFinishType::A1CLICK);
  904. // } else {
  905. // Intent* intent = new Intent();
  906. // intent->putExtra(isOutgoing, "true");
  907. // intent->putExtra(audioOnly, "true");
  908. // EASYUICONTEXT->openActivity("callActivity", intent);
  909. // }
  910. // }
  911. // }
  912. // else {
  913. // scrrenOn();
  914. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  915. // //拨打 或 挂断
  916. // if (CallingStatus::instance()->busy()){
  917. // callActivityFinish(CallFinishType::A1CLICK);
  918. // } else {
  919. // Intent* intent = new Intent();
  920. // intent->putExtra(isOutgoing, "true");
  921. // intent->putExtra(audioOnly, "true");
  922. // EASYUICONTEXT->openActivity("callActivity", intent);
  923. // }
  924. // }
  925. // }
  926. //
  927. // else if (data.cmd == "KEY6"){ // key6是手柄触发,手柄只有呼叫和挂断功能,没有取消功能,防止用户不停地按
  928. //
  929. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  930. // if (isSleep) {
  931. // scrrenOn();
  932. // }
  933. // else {
  934. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  935. // //拨打 或 挂断
  936. // if (CallingStatus::instance()->busy()){
  937. // callActivityFinish(CallFinishType::KEY6_CLICK);
  938. // } else {
  939. // Intent* intent = new Intent();
  940. // intent->putExtra(isOutgoing, "true");
  941. // intent->putExtra(audioOnly, "true");
  942. // EASYUICONTEXT->openActivity("callActivity", intent);
  943. // }
  944. // }
  945. // }
  946. // else {
  947. // scrrenOn();
  948. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  949. // //拨打 或 挂断
  950. // if (CallingStatus::instance()->busy()){
  951. // callActivityFinish(CallFinishType::KEY6_CLICK);
  952. // } else {
  953. // Intent* intent = new Intent();
  954. // intent->putExtra(isOutgoing, "true");
  955. // intent->putExtra(audioOnly, "true");
  956. // EASYUICONTEXT->openActivity("callActivity", intent);
  957. // }
  958. // }
  959. //
  960. // }
  961. // else if (data.cmd == "KEY7"){ // key7是紧急按钮
  962. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  963. // setCheckbox("KEY7");
  964. // return;
  965. // }
  966. // if (isSleep) {
  967. // scrrenOn();
  968. // }
  969. // if (sosTimerRegistered) {
  970. // LOGD("TCP -> SOS_CALL");
  971. // TcpModel tcpModel;
  972. // tcpModel.type = TcpType::SOS;
  973. // tcpModel.action = SosAction::CALL;
  974. // tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  975. // tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  976. // std::string req = getTcpModelString(tcpModel);
  977. // LOGD("TCP SOS_CALL : %s",req.c_str());
  978. // TcpClient::instance()->sendMsg(req.c_str());
  979. //
  980. // // SOS亮红灯
  981. // lightControl("ULED", "1F");
  982. // // 门灯亮红灯
  983. // lightControl("DOORLED", "200F");
  984. //
  985. // lightControl("CALLLED", "100F");
  986. //
  987. // mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  988. // mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  989. // }
  990. // }
  991. // else if (data.cmd == "KEY<") { //下左3,红
  992. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  993. // setCheckbox("KEY<");
  994. // return;
  995. // }
  996. //
  997. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  998. // if (isSleep) {
  999. // scrrenOn();
  1000. // }
  1001. // else {
  1002. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1003. // //拨打 或 挂断
  1004. // if (CallingStatus::instance()->busy()){
  1005. // callActivityFinish(CallFinishType::A1CLICK);
  1006. // } else {
  1007. // Intent* intent = new Intent();
  1008. // intent->putExtra(isOutgoing, "true");
  1009. // intent->putExtra(audioOnly, "true");
  1010. // EASYUICONTEXT->openActivity("callActivity", intent);
  1011. // }
  1012. // }
  1013. // }
  1014. // else {
  1015. // scrrenOn();
  1016. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1017. // //拨打 或 挂断
  1018. // if (CallingStatus::instance()->busy()){
  1019. // callActivityFinish(CallFinishType::A1CLICK);
  1020. // } else {
  1021. // Intent* intent = new Intent();
  1022. // intent->putExtra(isOutgoing, "true");
  1023. // intent->putExtra(audioOnly, "true");
  1024. // EASYUICONTEXT->openActivity("callActivity", intent);
  1025. // }
  1026. // }
  1027. // }
  1028. // else if (data.cmd == "KEY>") { // key>是面板挂断按钮
  1029. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  1030. // if (isSleep) {
  1031. // scrrenOn();
  1032. // }
  1033. // else {
  1034. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1035. // //拨打 或 挂断
  1036. // if (CallingStatus::instance()->busy()){
  1037. // callActivityFinish(CallFinishType::A1CLICK);
  1038. //
  1039. // lightControl("DOORLED", "000F");
  1040. // }
  1041. // }
  1042. // }
  1043. // else {
  1044. // scrrenOn();
  1045. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1046. // //拨打 或 挂断
  1047. // if (CallingStatus::instance()->busy()){
  1048. // callActivityFinish(CallFinishType::A1CLICK);
  1049. //
  1050. // lightControl("DOORLED", "000F");
  1051. // }
  1052. // }
  1053. // }
  1054. // else if (data.cmd == "KEY;"){ //下左4,白
  1055. // if (isSleep) {
  1056. // scrrenOn();
  1057. // }
  1058. // lightControl("DOORLED", "111F");
  1059. // }
  1060. // else {
  1061. // if (isSleep) {
  1062. // scrrenOn();
  1063. // }
  1064. //// lightControl("DOORLED", "000F");
  1065. // }
  1066. // }
  1067. }
  1068. }
  1069. /**
  1070. * 定时器触发函数
  1071. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  1072. * 参数: id
  1073. * 当前所触发定时器的id,与注册时的id相同
  1074. * 返回值: true
  1075. * 继续运行当前定时器
  1076. * false
  1077. * 停止运行当前定时器
  1078. */
  1079. static bool onUI_Timer(int id){
  1080. switch (id) {
  1081. case 1:
  1082. {
  1083. //定时器跑在UI线程,这里将喂狗标记加1
  1084. //++feed_dogs;
  1085. //不用心跳
  1086. // if(UartContext::Uart3IsOpen()) {
  1087. // string heartStr = "HEART,1E";
  1088. // const char* sendMsg = heartStr.c_str();
  1089. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  1090. // }
  1091. }
  1092. break;
  1093. case 2: //TCP心跳
  1094. {
  1095. const char* req = "0";
  1096. TcpClient::instance()->sendMsg(req);
  1097. }
  1098. break;
  1099. case SOS_CLICK_TIME_HANDLE: {
  1100. sosTimerRegistered = true;
  1101. return false;
  1102. }
  1103. break;
  1104. case SOS_LAMP_TIME_HANDLE: {
  1105. // SOS还原成无灯光的状态
  1106. lightControl("ULED", "0F");
  1107. // 进行门灯还原
  1108. lightControl("DOORLED", "000F");
  1109. statusLight();
  1110. return false;
  1111. }
  1112. break;
  1113. case SLEEP_STRAT_TIME_HANDLE: { // 息屏
  1114. if (isSleepTimerRegistered) {
  1115. isSleep = true;
  1116. BRIGHTNESSHELPER->screenOff();
  1117. } else { // 如果是false的话,就需要关闭定时器
  1118. isSleep = false;
  1119. BRIGHTNESSHELPER->screenOn();
  1120. }
  1121. }
  1122. break;
  1123. case SYS_RESTART_TIME_HANDLE:
  1124. netresetInt += 1;
  1125. lightControl("NETRESET", "1F");
  1126. if (netresetInt == 5) {
  1127. LOGD("网卡重启无效,程序内部重启");
  1128. //重启
  1129. sync();
  1130. reboot(RB_AUTOBOOT);
  1131. }
  1132. break;
  1133. case HANDLE_TRIGGER_TIME_HANDLE: {
  1134. isTriggerHandle = false;
  1135. return false;
  1136. }
  1137. break;
  1138. case SOS_TRIGGER_TIME_HANDLE: {
  1139. isTriggerSos = false;
  1140. return false;
  1141. }
  1142. break;
  1143. default:
  1144. break;
  1145. }
  1146. return true;
  1147. }
  1148. /**
  1149. * 有新的触摸事件时触发
  1150. * 参数:ev
  1151. * 新的触摸事件
  1152. * 返回值:true
  1153. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  1154. * false
  1155. * 触摸事件将继续传递到控件上
  1156. */
  1157. static bool onstartActivityTouchEvent(const MotionEvent &ev) {
  1158. switch (ev.mActionStatus) {
  1159. case MotionEvent::E_ACTION_DOWN://触摸按下
  1160. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  1161. break;
  1162. case MotionEvent::E_ACTION_MOVE://触摸滑动
  1163. break;
  1164. case MotionEvent::E_ACTION_UP: //触摸抬起
  1165. break;
  1166. default:
  1167. break;
  1168. }
  1169. return false;
  1170. }