startLogic.cc 39 KB

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