startLogic.cc 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  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. logoutMedicalCare();
  442. const char* currentAppName = EASYUICONTEXT->currentAppName();
  443. string _currentAppName = currentAppName;
  444. if (_currentAppName == "medicalCareActivity") {
  445. goHome();
  446. }
  447. }
  448. }
  449. }
  450. else if (tcpModel.type == TcpType::BLUE_CODE) {
  451. if (tcpModel.action == BlueCodeAction::SUCCESS) {
  452. int id = tcpModel.json["id"].asInt();
  453. LOGD("blue code id ===> %d", id);
  454. setBlueCodeId(id, tcpModel.tid);
  455. }
  456. }
  457. }
  458. bool getSleepTimerRegistered() {
  459. return isSleepTimerRegistered;
  460. }
  461. // 触发定时任务
  462. void setSleepTimerRegistered(bool result) {
  463. LOGD("isSleepTimerRegistered = %d", isSleepTimerRegistered);
  464. LOGD("result = %d", result);
  465. if (mActivityPtr == NULL) {
  466. return;
  467. }
  468. if (result != isSleepTimerRegistered) { // 与定时任务不同时,才进行处理
  469. if (isSleepTimerRegistered) { // 与定时任务开关进行判断,如果定时任务开启,那就要关闭
  470. isSleepTimerRegistered = result;
  471. mActivityPtr->unregisterUserTimer(SLEEP_STRAT_TIME_HANDLE); // 关闭定时器
  472. if (isSleep) {
  473. isSleep = false;
  474. BRIGHTNESSHELPER->screenOn();
  475. }
  476. LOGD("关闭息屏");
  477. } else { // 如果定时任务关着,那就要打开
  478. isSleepTimerRegistered = result;
  479. int sleepTime = StoragePreferences::getInt(STORE_SLEEP_TIME, 3);
  480. if (sleepTime > 0) {
  481. mActivityPtr->registerUserTimer(SLEEP_STRAT_TIME_HANDLE, sleepTime * 60 * 1000);
  482. LOGD("开启息屏");
  483. }
  484. }
  485. }
  486. }
  487. void scrrenOn() {
  488. isSleep = false;
  489. BRIGHTNESSHELPER->screenOn();
  490. }
  491. void setCallTid(std::string tid) {
  492. callTid = tid;
  493. }
  494. //================================= IO 口操作
  495. //紧急按钮灯,明/灭
  496. void setSOS_A5(bool light){
  497. int result = -1;
  498. int slight = light?0:1;
  499. result = GpioHelper::output("A5", slight);
  500. if (result==0){
  501. LOGD("set A5 SOS light %d. success",light);
  502. } else {
  503. LOGD("set A5 SOS light %d. failed",light);
  504. }
  505. }
  506. //A6,A7,A8 RGB灯控制
  507. void setRGB_A678(bool R, bool G, bool B){
  508. int rR = -1, rG = -1, rB = -1;
  509. int sR = R?0:1, sG = G?0:1, sB = B?0:1;
  510. rR = GpioHelper::output("A6", sR);
  511. rG = GpioHelper::output("A7", sG);
  512. rB = GpioHelper::output("A8", sB);
  513. const char *strLog = "set %s light %d. %d";
  514. LOGD(strLog,"A6 R",R, rR);
  515. LOGD(strLog,"A7 G",G, rG);
  516. LOGD(strLog,"A8 B",B, rB);
  517. }
  518. //手柄按钮
  519. class A1GpioListener : public IGpioListener{
  520. public:
  521. bool onGpioEdge(const char *pPin) override {
  522. int state = GpioHelper::input("A1");
  523. LOGD("IGpioListener GPIO IS A1=%d", state);
  524. if (state==0){
  525. voip::CallInfo info = GetTelephone()->GetCallInfo();
  526. //拨打 或 挂断
  527. if (CallingStatus::instance()->busy()){
  528. callActivityFinish(CallFinishType::A1CLICK);
  529. } else {
  530. Intent* intent = new Intent();
  531. intent->putExtra(isOutgoing, "true");
  532. intent->putExtra(audioOnly, "true");
  533. EASYUICONTEXT->openActivity("callActivity", intent);
  534. }
  535. }
  536. return true;
  537. }
  538. void onGpioError(const char *pPin, int error) override {
  539. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  540. }
  541. };
  542. //7寸面板,呼出
  543. class A2GpioListener : public IGpioListener{
  544. public:
  545. bool onGpioEdge(const char *pPin) override {
  546. int state = GpioHelper::input("A2");
  547. LOGD("IGpioListener GPIO IS A2=%d", state);
  548. if (state==0){
  549. //拨打 或 接听
  550. }
  551. return true;
  552. }
  553. void onGpioError(const char *pPin, int error) override {
  554. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  555. }
  556. };
  557. //7寸面板,挂断
  558. class A3GpioListener : public IGpioListener{
  559. public:
  560. bool onGpioEdge(const char *pPin) override {
  561. int state = GpioHelper::input("A3");
  562. LOGD("IGpioListener GPIO IS A3=%d", state);
  563. if (state==0){
  564. //挂断
  565. }
  566. return true;
  567. }
  568. void onGpioError(const char *pPin, int error) override {
  569. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  570. }
  571. };
  572. //紧急按钮
  573. class A4GpioListener : public IGpioListener{
  574. public:
  575. bool onGpioEdge(const char *pPin) override {
  576. int state = GpioHelper::input("A4");
  577. LOGD("IGpioListener GPIO IS A4=%d", state);
  578. if (state==0){
  579. //发出
  580. setSOS_A5(true);
  581. }
  582. return true;
  583. }
  584. void onGpioError(const char *pPin, int error) override {
  585. LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
  586. }
  587. };
  588. /**
  589. * 注册定时器
  590. * 填充数组用于注册定时器
  591. * 注意:id不能重复
  592. */
  593. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  594. {1, 5000},
  595. {2, 30*1000}
  596. };
  597. /**
  598. * 当界面构造时触发
  599. */
  600. static void onUI_init(){
  601. //IO监测
  602. IGpioListener *iGpioListenerA1 = new A1GpioListener();
  603. GpioHelper::registerGpioListener("A1", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  604. IGpioListener *iGpioListenerA2 = new A2GpioListener();
  605. GpioHelper::registerGpioListener("A2", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  606. IGpioListener *iGpioListenerA3 = new A3GpioListener();
  607. GpioHelper::registerGpioListener("A3", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  608. IGpioListener *iGpioListenerA4 = new A4GpioListener();
  609. GpioHelper::registerGpioListener("A4", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
  610. //TCP启动
  611. TcpClient::instance()->startTcp();
  612. //监听SIP信令
  613. GetTelephone()->AddCallStateListener(OnCallStateChanged);
  614. //开启网页
  615. httpServer.RunAsync(HTTP_SERVER_PORT);
  616. // 启动的时候更改为tcp模式
  617. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  618. if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
  619. LOGD("===============> 关闭护理状态");
  620. StoragePreferences::putBool(STORE_NURSING_TYPE, false);
  621. isNursing = true;
  622. }
  623. //请求版本号
  624. // if(UartContext::Uart3IsOpen()) {
  625. // string heartStr = "ASK,VNF-0";
  626. // const char* sendMsg = heartStr.c_str();
  627. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  628. // }
  629. #if 0
  630. std::thread backend([](){
  631. while (true) {
  632. if (feed_dogs > 0) {
  633. --feed_dogs;
  634. LOGD("feed");
  635. int ret = GpioHelper::output("GPIO_2", 1); //拉高
  636. if (ret != 0) {
  637. LOGE("GPIO操作失败");
  638. }
  639. usleep(1000 * 20);
  640. ret = GpioHelper::output("GPIO_2", 0); //拉低
  641. if (ret != 0) {
  642. LOGE("GPIO操作失败");
  643. }
  644. }
  645. usleep(1000 * 1000);
  646. }
  647. });
  648. backend.detach();
  649. #endif
  650. }
  651. /**
  652. * 当切换到该界面时触发
  653. */
  654. static void onUI_intent(const Intent *intentPtr) {
  655. if (intentPtr != NULL) {
  656. //TODO
  657. }
  658. }
  659. /*
  660. * 当界面显示时触发
  661. */
  662. static void onUI_show() {
  663. StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
  664. //进入主界面
  665. EASYUICONTEXT->openActivity("mainActivity");
  666. }
  667. /*
  668. * 当界面隐藏时触发
  669. */
  670. static void onUI_hide() {
  671. }
  672. /*
  673. * 当界面完全退出时触发
  674. */
  675. static void onUI_quit() {
  676. }
  677. /**
  678. * 串口数据回调接口
  679. */
  680. static void onProtocolDataUpdate(const SProtocolData &data) {
  681. LOGD("cmd = %s", data.cmd.c_str());
  682. if (data.state!=""){
  683. LOGD("state = %s",data.state.c_str());
  684. }
  685. // if (data.msg != ""){
  686. // LOGD("msg = %s", data.msg.c_str());
  687. // }
  688. if(UartContext::Uart3IsOpen()) { // 如果是true,表示串口打开了
  689. string heartStr;
  690. // 面板拨号
  691. if (data.cmd == "KEY5") {
  692. if (data.state == "0") {
  693. if (isSleep) {
  694. scrrenOn();
  695. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  696. return;
  697. }
  698. }
  699. const char* currentAppName = EASYUICONTEXT->currentAppName();
  700. string _currentAppName = currentAppName;
  701. if (_currentAppName == "sipTestActivity") {
  702. setCheckbox("KEY5");
  703. return;
  704. }
  705. else {
  706. voip::CallInfo info = GetTelephone()->GetCallInfo();
  707. //拨打 或 挂断
  708. if (CallingStatus::instance()->busy()){
  709. callActivityFinish(CallFinishType::A1CLICK);
  710. } else {
  711. Intent* intent = new Intent();
  712. intent->putExtra(isOutgoing, "true");
  713. intent->putExtra(audioOnly, "true");
  714. EASYUICONTEXT->openActivity("callActivity", intent);
  715. }
  716. }
  717. }
  718. }
  719. else if (data.cmd == "KEY6") {
  720. if (data.state == "0") {
  721. if (isSleep) {
  722. scrrenOn();
  723. if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  724. return;
  725. }
  726. }
  727. const char* currentAppName = EASYUICONTEXT->currentAppName();
  728. string _currentAppName = currentAppName;
  729. if (_currentAppName == "sipTestActivity") {
  730. setCheckbox("KEY6");
  731. return;
  732. }
  733. isTriggerHandle = true;
  734. mActivityPtr->registerUserTimer(HANDLE_TRIGGER_TIME_HANDLE, 5 * 1000);
  735. }
  736. else if (data.state == "1") {
  737. if (isTriggerHandle) {
  738. isTriggerHandle = false;
  739. voip::CallInfo info = GetTelephone()->GetCallInfo();
  740. //拨打 或 挂断
  741. if (CallingStatus::instance()->busy()){
  742. callActivityFinish(CallFinishType::KEY6_CLICK);
  743. } else {
  744. Intent* intent = new Intent();
  745. intent->putExtra(isOutgoing, "true");
  746. intent->putExtra(audioOnly, "true");
  747. EASYUICONTEXT->openActivity("callActivity", intent);
  748. }
  749. }
  750. }
  751. else if (data.state == "3") {
  752. isConnectHandle = true;
  753. }
  754. else if (data.state == "4") {
  755. if (!isConnectHandle) {
  756. return;
  757. }
  758. if (sosTimerRegistered) {
  759. LOGD("TCP -> SOS_CALL");
  760. Json::Value data;
  761. data["title"] = "手柄断连";
  762. TcpModel tcpModel;
  763. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  764. tcpModel.type = TcpType::SOS;
  765. tcpModel.action = SosAction::CALL;
  766. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  767. tcpModel.json = data;
  768. std::string req = getTcpModelString(tcpModel);
  769. LOGD("TCP SOS_CALL : %s",req.c_str());
  770. TcpClient::instance()->sendMsg(req.c_str());
  771. // SOS亮红灯
  772. lightControl("ULED", "1F");
  773. // 门灯亮红灯
  774. lightControl("DOORLED", "200F");
  775. lightControl("CALLLED", "100F");
  776. sosTimerRegistered = false;
  777. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  778. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  779. }
  780. }
  781. }
  782. else if (data.cmd == "KEY7") {
  783. if (data.state == "0") {
  784. scrrenOn();
  785. const char* currentAppName = EASYUICONTEXT->currentAppName();
  786. string _currentAppName = currentAppName;
  787. if (_currentAppName == "sipTestActivity") {
  788. setCheckbox("KEY7");
  789. return;
  790. }
  791. else {
  792. if (sosTimerRegistered) {
  793. isTriggerSos = true;
  794. mActivityPtr->registerUserTimer(SOS_TRIGGER_TIME_HANDLE, 5 * 1000);
  795. }
  796. }
  797. }
  798. else if (data.state == "1") {
  799. if (isTriggerSos) {
  800. LOGD("TCP -> SOS_CALL");
  801. TcpModel tcpModel;
  802. tcpModel.type = TcpType::SOS;
  803. tcpModel.action = SosAction::CALL;
  804. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  805. tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  806. std::string req = getTcpModelString(tcpModel);
  807. LOGD("TCP SOS_CALL : %s",req.c_str());
  808. TcpClient::instance()->sendMsg(req.c_str());
  809. // SOS亮红灯
  810. lightControl("ULED", "1F");
  811. // 门灯亮红灯
  812. lightControl("DOORLED", "200F");
  813. lightControl("CALLLED", "100F");
  814. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  815. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  816. }
  817. }
  818. else if (data.state == "3") {
  819. isConnectSos = true;
  820. }
  821. else if (data.state == "4") {
  822. if (!isConnectSos) {
  823. return;
  824. }
  825. if (sosTimerRegistered) {
  826. LOGD("TCP -> SOS_CALL");
  827. Json::Value data;
  828. data["title"] = "紧急按钮断连";
  829. TcpModel tcpModel;
  830. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  831. tcpModel.type = TcpType::SOS;
  832. tcpModel.action = SosAction::CALL;
  833. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  834. tcpModel.json = data;
  835. std::string req = getTcpModelString(tcpModel);
  836. LOGD("TCP SOS_CALL : %s",req.c_str());
  837. TcpClient::instance()->sendMsg(req.c_str());
  838. // SOS亮红灯
  839. lightControl("ULED", "1F");
  840. // 门灯亮红灯
  841. lightControl("DOORLED", "200F");
  842. lightControl("CALLLED", "100F");
  843. sosTimerRegistered = false;
  844. mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  845. mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  846. }
  847. }
  848. }
  849. else if (data.cmd == "KEY<") {
  850. if (isSleep) {
  851. scrrenOn();
  852. }
  853. // lightControl("DOORLED", "100F");
  854. }
  855. else if (data.cmd == "KEY>") { // key>是面板挂断按钮
  856. if (data.state == "0") {
  857. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  858. setCheckbox("KEY>");
  859. return;
  860. }
  861. if (isSleep) {
  862. scrrenOn();
  863. }
  864. else {
  865. voip::CallInfo info = GetTelephone()->GetCallInfo();
  866. //拨打 或 挂断
  867. if (CallingStatus::instance()->busy()){
  868. callActivityFinish(CallFinishType::A1CLICK);
  869. lightControl("DOORLED", "000F");
  870. }
  871. }
  872. }
  873. }
  874. else if (data.cmd == "KEY;") {
  875. if (isSleep) {
  876. scrrenOn();
  877. }
  878. // lightControl("DOORLED", "111F");
  879. }
  880. else {
  881. if (isSleep) {
  882. scrrenOn();
  883. }
  884. lightControl("DOORLED", "000F");
  885. }
  886. // //按下
  887. // if (data.state=="0"){ // 0表示正被按下,1表示短按松开,2表示长按松开。
  888. // if (data.cmd == "KEY5") { // key5是面板拨号按钮
  889. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  890. // setCheckbox("KEY5");
  891. // return;
  892. // }
  893. //
  894. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  895. // if (isSleep) {
  896. // scrrenOn();
  897. // }
  898. // else {
  899. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  900. // //拨打 或 挂断
  901. // if (CallingStatus::instance()->busy()){
  902. // callActivityFinish(CallFinishType::A1CLICK);
  903. // } else {
  904. // Intent* intent = new Intent();
  905. // intent->putExtra(isOutgoing, "true");
  906. // intent->putExtra(audioOnly, "true");
  907. // EASYUICONTEXT->openActivity("callActivity", intent);
  908. // }
  909. // }
  910. // }
  911. // else {
  912. // scrrenOn();
  913. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  914. // //拨打 或 挂断
  915. // if (CallingStatus::instance()->busy()){
  916. // callActivityFinish(CallFinishType::A1CLICK);
  917. // } else {
  918. // Intent* intent = new Intent();
  919. // intent->putExtra(isOutgoing, "true");
  920. // intent->putExtra(audioOnly, "true");
  921. // EASYUICONTEXT->openActivity("callActivity", intent);
  922. // }
  923. // }
  924. // }
  925. //
  926. // else if (data.cmd == "KEY6"){ // key6是手柄触发,手柄只有呼叫和挂断功能,没有取消功能,防止用户不停地按
  927. //
  928. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  929. // if (isSleep) {
  930. // scrrenOn();
  931. // }
  932. // else {
  933. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  934. // //拨打 或 挂断
  935. // if (CallingStatus::instance()->busy()){
  936. // callActivityFinish(CallFinishType::KEY6_CLICK);
  937. // } else {
  938. // Intent* intent = new Intent();
  939. // intent->putExtra(isOutgoing, "true");
  940. // intent->putExtra(audioOnly, "true");
  941. // EASYUICONTEXT->openActivity("callActivity", intent);
  942. // }
  943. // }
  944. // }
  945. // else {
  946. // scrrenOn();
  947. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  948. // //拨打 或 挂断
  949. // if (CallingStatus::instance()->busy()){
  950. // callActivityFinish(CallFinishType::KEY6_CLICK);
  951. // } else {
  952. // Intent* intent = new Intent();
  953. // intent->putExtra(isOutgoing, "true");
  954. // intent->putExtra(audioOnly, "true");
  955. // EASYUICONTEXT->openActivity("callActivity", intent);
  956. // }
  957. // }
  958. //
  959. // }
  960. // else if (data.cmd == "KEY7"){ // key7是紧急按钮
  961. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  962. // setCheckbox("KEY7");
  963. // return;
  964. // }
  965. // if (isSleep) {
  966. // scrrenOn();
  967. // }
  968. // if (sosTimerRegistered) {
  969. // LOGD("TCP -> SOS_CALL");
  970. // TcpModel tcpModel;
  971. // tcpModel.type = TcpType::SOS;
  972. // tcpModel.action = SosAction::CALL;
  973. // tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
  974. // tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
  975. // std::string req = getTcpModelString(tcpModel);
  976. // LOGD("TCP SOS_CALL : %s",req.c_str());
  977. // TcpClient::instance()->sendMsg(req.c_str());
  978. //
  979. // // SOS亮红灯
  980. // lightControl("ULED", "1F");
  981. // // 门灯亮红灯
  982. // lightControl("DOORLED", "200F");
  983. //
  984. // lightControl("CALLLED", "100F");
  985. //
  986. // mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
  987. // mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
  988. // }
  989. // }
  990. // else if (data.cmd == "KEY<") { //下左3,红
  991. // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
  992. // setCheckbox("KEY<");
  993. // return;
  994. // }
  995. //
  996. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  997. // if (isSleep) {
  998. // scrrenOn();
  999. // }
  1000. // else {
  1001. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1002. // //拨打 或 挂断
  1003. // if (CallingStatus::instance()->busy()){
  1004. // callActivityFinish(CallFinishType::A1CLICK);
  1005. // } else {
  1006. // Intent* intent = new Intent();
  1007. // intent->putExtra(isOutgoing, "true");
  1008. // intent->putExtra(audioOnly, "true");
  1009. // EASYUICONTEXT->openActivity("callActivity", intent);
  1010. // }
  1011. // }
  1012. // }
  1013. // else {
  1014. // scrrenOn();
  1015. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1016. // //拨打 或 挂断
  1017. // if (CallingStatus::instance()->busy()){
  1018. // callActivityFinish(CallFinishType::A1CLICK);
  1019. // } else {
  1020. // Intent* intent = new Intent();
  1021. // intent->putExtra(isOutgoing, "true");
  1022. // intent->putExtra(audioOnly, "true");
  1023. // EASYUICONTEXT->openActivity("callActivity", intent);
  1024. // }
  1025. // }
  1026. // }
  1027. // else if (data.cmd == "KEY>") { // key>是面板挂断按钮
  1028. // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
  1029. // if (isSleep) {
  1030. // scrrenOn();
  1031. // }
  1032. // else {
  1033. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1034. // //拨打 或 挂断
  1035. // if (CallingStatus::instance()->busy()){
  1036. // callActivityFinish(CallFinishType::A1CLICK);
  1037. //
  1038. // lightControl("DOORLED", "000F");
  1039. // }
  1040. // }
  1041. // }
  1042. // else {
  1043. // scrrenOn();
  1044. // voip::CallInfo info = GetTelephone()->GetCallInfo();
  1045. // //拨打 或 挂断
  1046. // if (CallingStatus::instance()->busy()){
  1047. // callActivityFinish(CallFinishType::A1CLICK);
  1048. //
  1049. // lightControl("DOORLED", "000F");
  1050. // }
  1051. // }
  1052. // }
  1053. // else if (data.cmd == "KEY;"){ //下左4,白
  1054. // if (isSleep) {
  1055. // scrrenOn();
  1056. // }
  1057. // lightControl("DOORLED", "111F");
  1058. // }
  1059. // else {
  1060. // if (isSleep) {
  1061. // scrrenOn();
  1062. // }
  1063. //// lightControl("DOORLED", "000F");
  1064. // }
  1065. // }
  1066. }
  1067. }
  1068. /**
  1069. * 定时器触发函数
  1070. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  1071. * 参数: id
  1072. * 当前所触发定时器的id,与注册时的id相同
  1073. * 返回值: true
  1074. * 继续运行当前定时器
  1075. * false
  1076. * 停止运行当前定时器
  1077. */
  1078. static bool onUI_Timer(int id){
  1079. switch (id) {
  1080. case 1:
  1081. {
  1082. //定时器跑在UI线程,这里将喂狗标记加1
  1083. //++feed_dogs;
  1084. //不用心跳
  1085. // if(UartContext::Uart3IsOpen()) {
  1086. // string heartStr = "HEART,1E";
  1087. // const char* sendMsg = heartStr.c_str();
  1088. // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
  1089. // }
  1090. }
  1091. break;
  1092. case 2: //TCP心跳
  1093. {
  1094. const char* req = "0";
  1095. TcpClient::instance()->sendMsg(req);
  1096. }
  1097. break;
  1098. case SOS_CLICK_TIME_HANDLE: {
  1099. sosTimerRegistered = true;
  1100. return false;
  1101. }
  1102. break;
  1103. case SOS_LAMP_TIME_HANDLE: {
  1104. // SOS还原成无灯光的状态
  1105. lightControl("ULED", "0F");
  1106. // 进行门灯还原
  1107. lightControl("DOORLED", "000F");
  1108. statusLight();
  1109. return false;
  1110. }
  1111. break;
  1112. case SLEEP_STRAT_TIME_HANDLE: { // 息屏
  1113. if (isSleepTimerRegistered) {
  1114. isSleep = true;
  1115. BRIGHTNESSHELPER->screenOff();
  1116. } else { // 如果是false的话,就需要关闭定时器
  1117. isSleep = false;
  1118. BRIGHTNESSHELPER->screenOn();
  1119. }
  1120. }
  1121. break;
  1122. case SYS_RESTART_TIME_HANDLE:
  1123. netresetInt += 1;
  1124. lightControl("NETRESET", "1F");
  1125. if (netresetInt == 5) {
  1126. LOGD("网卡重启无效,程序内部重启");
  1127. //重启
  1128. sync();
  1129. reboot(RB_AUTOBOOT);
  1130. }
  1131. break;
  1132. case HANDLE_TRIGGER_TIME_HANDLE: {
  1133. isTriggerHandle = false;
  1134. return false;
  1135. }
  1136. break;
  1137. case SOS_TRIGGER_TIME_HANDLE: {
  1138. isTriggerSos = false;
  1139. return false;
  1140. }
  1141. break;
  1142. default:
  1143. break;
  1144. }
  1145. return true;
  1146. }
  1147. /**
  1148. * 有新的触摸事件时触发
  1149. * 参数:ev
  1150. * 新的触摸事件
  1151. * 返回值:true
  1152. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  1153. * false
  1154. * 触摸事件将继续传递到控件上
  1155. */
  1156. static bool onstartActivityTouchEvent(const MotionEvent &ev) {
  1157. switch (ev.mActionStatus) {
  1158. case MotionEvent::E_ACTION_DOWN://触摸按下
  1159. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  1160. break;
  1161. case MotionEvent::E_ACTION_MOVE://触摸滑动
  1162. break;
  1163. case MotionEvent::E_ACTION_UP: //触摸抬起
  1164. break;
  1165. default:
  1166. break;
  1167. }
  1168. return false;
  1169. }