startLogic.cc 54 KB

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