startLogic.cc 53 KB

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