startLogic.cc 53 KB

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