startLogic.cc 35 KB

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