12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901 |
- #pragma once
- #include "uart/ProtocolSender.h"
- #include "uart/UartContext.h"
- #include "core/utilities.h"
- #include "edge/call_log.h"
- #include "net/tcp_client.h"
- #include "net/tcp_model.h"
- #include "server/http_server.h"
- #include "base/strings.hpp"
- #include "pjsua/pjsua-lib/pjsua.h"
- #include "utils/GpioHelper.h"
- #include "utils/TimeHelper.h"
- #include "utils/BrightnessHelper.h"
- #include <time.h>
- #include <thread>
- #include <list>
- #include <string>
- #include <unistd.h>
- #include <sys/reboot.h>
- #include "service/BusinessConfig.h"
- static bool sosTimerRegistered = true;
- static bool isSleepTimerRegistered = false; // 是否开启息屏定时任务
- static bool isSleep = false; // 是否在息屏
- static bool isNursing = false; // 用于启动时判断是否处于护理状态
- static bool isNetreset = false;
- static int netresetInt = 0;
- static string callTid = "";
- struct DeviceButtonFunctionTypeAndValue {
- string type;
- string value;
- };
- static std::unordered_map<string, DeviceButtonFunctionTypeAndValue> deviceButtonFunction;
- static bool isConnectHandle = false;
- static bool isConnectSos = false;
- static bool isConnectHandle1 = false;
- static bool isConnectHandle2 = false;
- static bool isConnectHandle3 = false;
- static bool isConnectHandle4 = false;
- static bool isConnectOutKey1 = false;
- static bool isConnectOutKey2 = false;
- static bool isConnectOutKey3 = false;
- static bool isConnectOutKey4 = false;
- static bool isConnectOutKey5 = false;
- static bool isConnectOutKey6 = false;
- //static bool isTriggerHandle = false;
- //static bool isTriggerSos = false;
- static bool isTriggerKey5 = false;
- static bool isTriggerKey6 = false;
- static bool isTriggerKey7 = false;
- static bool isTriggerKey8 = false;
- static bool isTriggerKey9 = false;
- static bool isTriggerKey10 = false;
- static bool isTriggerKey11 = false;
- static bool isTriggerKey12 = false;
- static bool isTriggerHandle1 = false;
- static bool isTriggerHandle2 = false;
- static bool isTriggerHandle3 = false;
- static bool isTriggerHandle4 = false;
- static bool isTriggerOutKey1 = false;
- static bool isTriggerOutKey2 = false;
- static bool isTriggerOutKey3 = false;
- static bool isTriggerOutKey4 = false;
- static bool isTriggerOutKey5 = false;
- static bool isTriggerOutKey6 = false;
- #define FUNCTION_TIMER_HANDLE 3 // 增援的定时器id
- #define SOS_CLICK_TIME_HANDLE 4 // sos的定时器id
- #define SOS_LAMP_TIME_HANDLE 5 // sos的门灯定时器id
- #define EVENT_TIME_HANDLE 8 // 事件定时器
- #define SLEEP_STRAT_TIME_HANDLE 9 // 息屏
- #define SYS_RESTART_TIME_HANDLE 10 // 重启
- #define PROMPT_TIME_HANDLE 11 // 提示语
- #define NURSEING_TIME_HANDLE 12 // 护理
- #define DOOR_LIGHT_TIME_HANDLE 13 // 门灯
- #define KEY5_TRIGGER_TIME_HANDLE 15
- #define KEY6_TRIGGER_TIME_HANDLE 16
- #define KEY7_TRIGGER_TIME_HANDLE 17
- #define KEY8_TRIGGER_TIME_HANDLE 18
- #define KEY9_TRIGGER_TIME_HANDLE 19
- #define KEY10_TRIGGER_TIME_HANDLE 20
- #define KEY11_TRIGGER_TIME_HANDLE 21
- #define KEY12_TRIGGER_TIME_HANDLE 22
- #define HANDLE1_TRIGGER_TIME_HANDLE 23
- #define HANDLE2_TRIGGER_TIME_HANDLE 24
- #define HANDLE3_TRIGGER_TIME_HANDLE 25
- #define HANDLE4_TRIGGER_TIME_HANDLE 26
- #define OUTKYE1_TRIGGER_TIME_HANDLE 27
- #define OUTKYE2_TRIGGER_TIME_HANDLE 28
- #define OUTKYE3_TRIGGER_TIME_HANDLE 29
- #define OUTKYE4_TRIGGER_TIME_HANDLE 30
- #define OUTKYE5_TRIGGER_TIME_HANDLE 31
- #define OUTKYE6_TRIGGER_TIME_HANDLE 32
- //#define HANDLE_TRIGGER_TIME_HANDLE 15
- //#define SOS_TRIGGER_TIME_HANDLE 16
- //#define HANDLE1_TRIGGER_TIME_HANDLE 17
- //#define HANDLE2_TRIGGER_TIME_HANDLE 18
- //#define HANDLE3_TRIGGER_TIME_HANDLE 19
- //#define HANDLE4_TRIGGER_TIME_HANDLE 20
- #define HTTP_SERVER_PORT 80
- #define goback 200
- #define SIP_RECONNECT_TIME_HANDLE 201
- srv::HttpServer httpServer;
- std::list<string> sosDataList;
- namespace {
- std::string uilogic[] = {
- "testActivity",
- "ui3Activity"
- };
- void CloseUi();
- int feed_dogs = 0;
- void PrintCallLog() {
- CallLogEntries entries;
- int ret = GetCallLog(&entries);
- LOGD("GetCallRecord %d", ret);
- for (auto r : entries) {
- LOGD("id=%d, uri=%s, contact=%s,duration=%d,created_at=%d",
- r.id, r.uri.c_str(), r.contact.c_str(), r.duration, r.created_at);
- }
- }
- void OnCallStateChanged(voip::Telephone* telephone, int call_id, voip::State state) {
- LOGD("call state = %d", state);
- if (state == voip::STATE_CALL_INCOMING
- || state == voip::STATE_CALL_CALLING
- || state == voip::STATE_CALL_CONFIRMED) {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- LOGD("info.id == %d", info.id);
- LOGD("info.remote_uri == %s", info.remote_uri.c_str());
- LOGD("info.remote_contact == %s", info.remote_contact.c_str());
- string sipId = info.remote_uri.substr(info.remote_uri.find(":") + 1, info.remote_uri.find("@") - info.remote_uri.find(":") - 1);
- LOGD("sipId == %s", sipId.c_str());
- if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
- EASYUICONTEXT->openActivity("callActivity");
- }
- else {
- if (sipId != "0000000000") {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName != "callActivity") {
- telephone->Hangup();
- LOGD("=================> 不在通话界面,直接挂断!");
- return;
- }
- }
- }
- if (state == voip::STATE_CALL_INCOMING) {
- if (telephone->GetCallCount() > 1) {
- LOGD("call count > 1, return");
- telephone->Hangup(call_id, voip::SIP_STATUS_CODE_BUSY_HERE);
- return;
- }
- //提前显示视频
- if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
- telephone->Answer(call_id, voip::SIP_STATUS_CODE_PROGRESS);
- telephone->Answer();
- } else {
- acceptSIP();
- }
- }
- }
- if (state == voip::STATE_CALL_DISCONNECTED) {
- LOGD("通话挂断");
- if (telephone->GetCallCount() > 1) {
- LOGD("call count > 1, return");
- return;
- }
- if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
- //EASYUICONTEXT->goHome();
- EASYUICONTEXT->goBack();
- }
- pjsua_call_info ci;
- pjsua_call_get_info(call_id, &ci);
- LOGD("通话结束的状态码 ===> %d", ci.last_status);
- if (ci.last_status == voip::SIP_NOT_FOUND) {
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::NOT_FOUND);
- }
- mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
- }
- else if (ci.last_status == voip::SIP_REQUEST_TIMES) {
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::REQUEST_TIMES);
- }
- mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
- }
- else {
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::END);
- }
- }
- // //保存通话记录
- // voip::CallInfo info = telephone->GetCallInfo(call_id);
- // CallLogEntry entry;
- // entry.uri = info.remote_uri;
- // entry.contact = info.remote_contact;
- // entry.duration = info.duration/1000;
- //
- // if (0 != PutCallLog(entry)) {
- // LOGE("保存通话记录失败");
- // }
- //
- // int n = GetCallLogCount();
- // if (n > CALL_LOG_COUNT_MAX) {
- // //超过最大通话记录条数,删除旧记录
- // if (0 != DeleteOldCallLog(n - CALL_LOG_COUNT_MAX)) {
- // LOGE("删除失败");
- // }
- // }
- //
- // const char* currentAppName = EASYUICONTEXT->currentAppName();
- // string _currentAppName = currentAppName;
- // if (_currentAppName == "callActivity") {
- // callActivityFinish(HANDOFF);
- // return;
- // }
- //PrintCallLog();
- }
- }
- void CloseUi() {
- for(int i = 0; i < 2; i++){
- EASYUICONTEXT->closeActivity(uilogic[i].c_str());
- }
- }
- void setBrightness(){
- int dayLight = StoragePreferences::getInt(STORE_DAY_LIGHT,100);
- int nightLight = StoragePreferences::getInt(STORE_NIGHT_LIGHT,10);
- if (checkIsDay()){
- BRIGHTNESSHELPER->setBrightness(dayLight);
- } else {
- BRIGHTNESSHELPER->setBrightness(nightLight);
- }
- }
- void addSipCallStateListener() {
- GetTelephone()->AddCallStateListener(OnCallStateChanged);
- }
- void removeSipCallStateListener() {
- GetTelephone()->RemoveCallStateListener(OnCallStateChanged);
- }
- }
- std::list<string> getSosDataList() {
- return sosDataList;
- }
- void cleanSosDataList() {
- sosDataList.clear();
- }
- void systemRestart() {
- if (!isNetreset) {
- isNetreset = true;
- lightControl("CALLLED", "000F");
- mActivityPtr->registerUserTimer(SYS_RESTART_TIME_HANDLE, 1000);
- }
- }
- string _typeStr;
- string _lightColorStr;
- string _actualColorStr;
- bool isDoorLightTimeHandle = false;
- void lightControl(std::string typeStr, std::string lightColorStr) {
- // 类型是门灯,并且还原成白色灯
- std::string heartStr;
- if (typeStr == "DOORLED" && lightColorStr == "000F") {
- //护理状态,需要还原成护理灯
- if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
- std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
- if (color != "" && color.size() == 3) {
- heartStr = "DOORLED," + color + "F";
- } else {
- heartStr = "DOORLED,010F";
- }
- }
- else {
- // 还原成无灯光的状态
- heartStr = "DOORLED,000F";
- }
- } else {
- heartStr = typeStr + "," + lightColorStr;
- }
- if (typeStr == "DOORLED" && isDoorLightTimeHandle) {
- isDoorLightTimeHandle = false;
- mActivityPtr->unregisterUserTimer(DOOR_LIGHT_TIME_HANDLE);
- }
- LOGD("=====> the heartStr == %s", heartStr.c_str());
- const char* sendMsg = heartStr.c_str();
- sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- }
- void lightControl(std::string typeStr, std::string lightColorStr, int time) {
- LOGD("频率闪烁,类型:%s,颜色:%s,频率:%d", typeStr.c_str(), lightColorStr.c_str(), time);
- _typeStr = typeStr;
- _lightColorStr = lightColorStr;
- _actualColorStr = lightColorStr;
- // 还原成无灯光的状态
- std::string heartStr = typeStr + "," + lightColorStr;
- LOGD("=====> the heartStr == %s", heartStr.c_str());
- const char* sendMsg = heartStr.c_str();
- sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- isDoorLightTimeHandle = true;
- mActivityPtr->registerUserTimer(DOOR_LIGHT_TIME_HANDLE, time);
- }
- // 接收tcp消息
- void handleMsg(byte* inBytes){
- LOGD("TCP received: %s", inBytes);
- const char* cstr = reinterpret_cast<const char*>(inBytes);
- string str = cstr;
- if (str == "1"){
- LOGD("get a heart beat");
- return;
- }
- TcpModel tcpModel;
- tcpModel = getTcpModel(inBytes);
- LOGD("tcp model: %s, %s", tcpModel.type.c_str(), tcpModel.action.c_str());
- if (tcpModel.type == TcpType::OTHER) {
- LOGD("trans tcp json failed");
- } else if (tcpModel.type == TcpType::TIME) {
- if (tcpModel.action == TimeAction::SYNC) {
- string serverTime = "";
- if (tcpModel.data != ""){
- serverTime = tcpModel.data;
- } else {
- serverTime = tcpModel.json["time"].asString();
- }
- LOGD("sync time : %s", serverTime.c_str());
- time_t timet = stoi(serverTime);
- struct tm *t = gmtime(&timet);
- char pDate[25];
- sprintf(pDate,"%d-%02d-%02d %02d:%02d:%02d",
- 1900 + t->tm_year, 1+ t->tm_mon, t->tm_mday,
- t->tm_hour + 8,t->tm_min,t->tm_sec);
- LOGD("transfered time : %s", pDate);
- TimeHelper::setDateTime(pDate);
- dataRefresh();
- if (isNursing) {
- setNursingEnd();
- }
- }
- } else if (tcpModel.type == TcpType::REINFORCE){
- if (tcpModel.action == ReinforceAction::RESPONSED){
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onSuccess(tcpModel.json);
- }
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName != "functionActivity") {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "helpResonse");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- } else {
- toFunctionActivity("");
- }
- }
- } else if (tcpModel.type == TcpType::DEVICE){
- if (tcpModel.action == DeviceAction::APP_UPDATE){ //软件升级
- if (isSleep) {
- isSleep = false;
- BRIGHTNESSHELPER->screenOn();
- }
- Intent* intent = new Intent();
- intent->putExtra(appUpdate, "true");
- EASYUICONTEXT->openActivity("updateActivity", intent);
- }
- else if (tcpModel.action == DeviceAction::RESTART) { // 重启设备
- const char* req = "-1";
- TcpClient::instance()->sendMsg(req);
- lightControl("CALLLED", "000F");
- sync();
- reboot(RB_AUTOBOOT);
- }
- else if (tcpModel.action == DeviceAction::REBOOT) {
- const char* req = "-1";
- TcpClient::instance()->sendMsg(req);
- lightControl("CALLLED", "000F");
- //重启
- sync();
- reboot(RB_AUTOBOOT);
- }
- else if (tcpModel.action == DeviceAction::DEVICE_REFRESH) { // 设备刷新
- dataRefresh();
- }
- else if (tcpModel.action == DeviceAction::SYSTEM_SETTING) { // 修改科室设置
- getPartSetting();
- }
- else if (tcpModel.action == DeviceAction::SERVER_CHANGE) {
- StoragePreferences::putString(STORE_GATEWAY, tcpModel.json["server_ip"].asCString());
- StoragePreferences::putString(STORE_HTTP_PORT, tcpModel.json["server_port"].asCString());
- const char* req = "-1";
- TcpClient::instance()->sendMsg(req);
- lightControl("CALLLED", "000F");
- //重启
- sync();
- reboot(RB_AUTOBOOT);
- }
- } else if (tcpModel.type == TcpType::DATA){
- if (tcpModel.action == DataAction::REFRESH){ // 刷新数据
- dataRefresh();
- }
- } else if (tcpModel.type == TcpType::VOICE){
- if (tcpModel.action == VoiceAction::FAILED){
- sleep(1);
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::FAILED);
- }
- } else if (tcpModel.action == VoiceAction::SUCCESS){
- CallingStatus::instance()->setTcpModel(tcpModel); // 只有呼叫成功才闪红灯
- lightControl("DOORLED", "100F");
- } else if (tcpModel.action == VoiceAction::ACCEPT){
- if (CallingStatus::instance()->busy()){
- CallingStatus::instance()->setTcpModel(tcpModel);
- std::string toSipId = tcpModel.json["toSipId"].asString();
- callActivityFinish(CallFinishType::ACCEPT);
- //接听
- buildSIP(toSipId);
- }
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- } else if (tcpModel.action == VoiceAction::REJECT){
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::REJECT);
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- }
- } else if (tcpModel.action == VoiceAction::CANCEL){
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::CANCEL);
- }
- } else if (tcpModel.action == VoiceAction::CALLING){
- //对方忙线
- callActivityFinish(CallFinishType::BUSY);
- } else if (tcpModel.action == VoiceAction::CALL){
- //我方忙线判断
- if (CallingStatus::instance()->busy()){
- sendVoiceTcp(VoiceAction::CALLING, tcpModel, tcpModel.from_id);
- } else {
- lightControl("DOORLED", "200F");
- CallingStatus::instance()->setTcpModel(tcpModel);
- //来电话了
- Intent* intent = new Intent();
- intent->putExtra(callActivityType, "toCall");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- } else if (tcpModel.action == VoiceAction::HANDOFF){
- //判断 是否同一个对话
- long iId = CallingStatus::instance()->getInteractionId();
- if (iId > 0 && CallingStatus::instance()->busy()){
- long inId = tcpModel.json["id"].asInt();
- if (iId == inId && CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::HANDOFF);
- }
- }
- }
- else if (tcpModel.action == VoiceAction::SIP_RECONNECT) {
- mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
- }
- else if (tcpModel.action == VoiceAction::GAIN_OK) {
- CallingStatus::instance()->setTcpModel(tcpModel);
- sleep(1);
- callActivityFinish(CallFinishType::GAIN_OK);
- }
- else if (tcpModel.action == VoiceAction::GAIN_FAIL) {
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::GAIN_FAIL);
- }
- }
- }
- else if (tcpModel.type == TcpType::SOS) {
- if (tcpModel.action == SosAction::CANCEL) {
- // SOS还原成无灯光的状态
- lightControl("ULED", "0F");
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- statusLight();
- // mActivityPtr->unregisterUserTimer(SOS_LAMP_TIME_HANDLE);
- }
- }
- else if (tcpModel.type == TcpType::SIDE) {
- if (tcpModel.action == SideAction::NURSING) {
- StoragePreferences::putString(STORE_NURSING_INTERACTION_ID, tcpModel.json["id"].asString());
- // 收到nursing,需要把通话给挂断了
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- LOGD("info state = %d",info.state);
- if (info.state == voip::STATE_CALL_CALLING
- || info.state == voip::STATE_CALL_CALLING
- || info.state == voip::STATE_CALL_CONFIRMED){
- TcpModel storeModel = CallingStatus::instance()->getTcpModel();
- //只回传iId
- storeModel.data = storeModel.json["id"].asString();
- sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
- GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
- GetTelephone()->Hangup();
- EASYUICONTEXT->goBack();
- }
- std::string color = StoragePreferences::getString(STORE_NURSING_COLOR_RGB, "010");
- if (color != "" && color.size() == 3) {
- color = color + "F";
- } else {
- color = "010F";
- }
- lightControl("DOORLED", color);
- }
- else if (tcpModel.action == SideAction::NURSING_END) {
- // 收到nursing_end
- lightControl("DOORLED", "000F");
- }
- else if (tcpModel.action == SideAction::CALL) {
- // 收到CALL,需要亮红灯
- // lightControl("DOORLED", "200F");
- }
- else if (tcpModel.action == SideAction::ACCEPT) {
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- if (isHandleId(tcpModel.to_id) && CallingStatus::instance()->busy()) {
- CallingStatus::instance()->setTcpModel(tcpModel);
- std::string toSipId = tcpModel.json["toSipId"].asString();
- callActivityFinish(CallFinishType::ACCEPT);
- //接听
- buildSIP(toSipId);
- }
- }
- else if (tcpModel.action == SideAction::CANCEL) {
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- if (isHandleId(tcpModel.to_id) && CallingStatus::instance()->busy()) {
- callActivityFinish(CallFinishType::CANCEL);
- }
- }
- else if (tcpModel.action == SideAction::SOS_CALL) {
- // 收到SOS_CALL,需要亮红灯
- // 门灯亮红灯
- lightControl("DOORLED", "100F", 1000);
- lightControl("CALLLED", "100F");
- sosTimerRegistered = false;
- mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
- // mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
- if (tcpModel.json.isMember("id")) {
- sosDataList.push_back(tcpModel.json["id"].asString());
- }
- }
- else if (tcpModel.action == SideAction::SOS_CANCEL) {
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- statusLight();
- }
- else if (tcpModel.action == SideAction::SHOW) {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName == "callActivity") {
- return;
- }
- Json::Value _it = tcpModel.json;
- if (_it["actionType"].asString() != "VOICE") {
- return;
- }
- if (_currentAppName != "functionActivity") {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "gainCall");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- size_t pos = tcpModel.tid.find("_");
- if (pos != std::string::npos) {
- _it["tid"] = tcpModel.tid.substr(0, pos);
- } else {
- _it["tid"] = tcpModel.tid;
- }
- addGainCallData(_it);
- }
- else if (tcpModel.action == SideAction::CLEAR) {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName == "functionActivity") {
- deleteGainCallData(tcpModel.json["id"].asString());
- }
- }
- }
- else if (tcpModel.type == TcpType::CALLBACK) {
- if (tcpModel.action == CallbackAction::ACK) {
- LOGD("CALLBACK ACK !!!!");
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onSuccess(tcpModel.json);
- }
- }
- else if (tcpModel.action == CallbackAction::SUCCESS) {
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onSuccess(tcpModel.json);
- }
- }
- else if (tcpModel.action == CallbackAction::FAILED) {
- sleep(1);
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onFalied(tcpModel.json);
- }
- if (tcpModel.tid == callTid){
- callActivityFinish(CallFinishType::FAILED);
- }
- }
- }
- else if (tcpModel.type == TcpType::POSITION) {
- if (tcpModel.action == PositionAction::POSITION_START) {
- setPosistionItId(tcpModel.json["id"].asInt());
- }
- }
- else if (tcpModel.type == TcpType::ROOMCHECK) {
- if (tcpModel.action == RoomCheckAction::START) {
- setRoomCheckItId(tcpModel.json["id"].asInt());
- }
- }
- else if (tcpModel.type == TcpType::SCREEN_TIP) {
- if (tcpModel.action == ScreenTipAction::START) {
- setPromptTimeItId(tcpModel.json["id"].asInt());
- }
- }
- else if (tcpModel.type == TcpType::AUTH) {
- if (tcpModel.action == AuthAction::LOGIN) {
- // 需要判断fromId跟自己是不是一样的,一样的就代表是自己发送出去,不一样的就代表员工已经登录到其他设备去了
- if (tcpModel.from_id == StoragePreferences::getInt(STORE_DEVICE_ID, 0)) {
- LOGD("id ===> %d", tcpModel.json["id"].asInt());
- setAuthItId(tcpModel.json["id"].asInt());
- }
- else {
- navibarNfcLogout();
- // logoutMedicalCare();
- // const char* currentAppName = EASYUICONTEXT->currentAppName();
- // string _currentAppName = currentAppName;
- // if (_currentAppName == "medicalCareActivity") {
- // goHome();
- // }
- }
- }
- }
- else if (tcpModel.type == TcpType::BLUE_CODE) {
- if (tcpModel.action == BlueCodeAction::SUCCESS) {
- int id = tcpModel.json["id"].asInt();
- LOGD("blue code id ===> %d", id);
- setBlueCodeId(id, tcpModel.tid);
- }
- }
- }
- bool getSleepTimerRegistered() {
- return isSleepTimerRegistered;
- }
- // 触发定时任务
- void setSleepTimerRegistered(bool result) {
- LOGD("isSleepTimerRegistered = %d", isSleepTimerRegistered);
- LOGD("result = %d", result);
- if (mActivityPtr == NULL) {
- return;
- }
- if (result != isSleepTimerRegistered) { // 与定时任务不同时,才进行处理
- if (isSleepTimerRegistered) { // 与定时任务开关进行判断,如果定时任务开启,那就要关闭
- isSleepTimerRegistered = result;
- mActivityPtr->unregisterUserTimer(SLEEP_STRAT_TIME_HANDLE); // 关闭定时器
- if (isSleep) {
- isSleep = false;
- BRIGHTNESSHELPER->screenOn();
- }
- LOGD("关闭息屏");
- } else { // 如果定时任务关着,那就要打开
- isSleepTimerRegistered = result;
- int sleepTime = StoragePreferences::getInt(STORE_SLEEP_TIME, 3);
- if (sleepTime > 0) {
- mActivityPtr->registerUserTimer(SLEEP_STRAT_TIME_HANDLE, sleepTime * 60 * 1000);
- LOGD("开启息屏");
- }
- }
- }
- }
- void scrrenOn() {
- isSleep = false;
- BRIGHTNESSHELPER->screenOn();
- }
- void setCallTid(std::string tid) {
- callTid = tid;
- }
- void handleHCall(int id) {
- int handleId = getHandleId(id);
- if (handleId != 0) {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName == "callActivity") {
- LOGD("已经在呼叫界面");
- return;
- }
- string handleIdStr = to_string(handleId);
- Intent* intent = new Intent();
- intent->putExtra(callActivityType, "handleHCall");
- intent->putExtra(handleCallId, handleIdStr);
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- else {
- string errorMsg = LANGUAGEMANAGER->getValue("HandleError") +
- StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0") + ":h" + to_string(id) + " \n" +
- LANGUAGEMANAGER->getValue("NotAdd");
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "warn");
- intent->putExtra(warnText, errorMsg);
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- }
- void sosCall(string sosMsg) {
- if (sosTimerRegistered) {
- LOGD("TCP -> SOS_CALL");
- sendSosCall(sosMsg);
- // SOS亮红灯
- lightControl("ULED", "1F");
- // 门灯亮红灯
- lightControl("DOORLED", "100F", 1000);
- lightControl("CALLLED", "100F");
- sosTimerRegistered = false;
- mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
- // mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
- }
- }
- void clearDeviceButtonFunction() {
- deviceButtonFunction.clear();
- }
- void setDeviceButtonFunction(std::string deviceButtonFunctionStr) {
- LOGD("deviceButtonFunctionStr ==========> %s", deviceButtonFunctionStr.c_str());
- Json::Reader reader;
- Json::Value deviceButtonFunctionJson;
- if (reader.parse(deviceButtonFunctionStr, deviceButtonFunctionJson)) {
- for (Json::Value json : deviceButtonFunctionJson) {
- const std::string key = json["key"].asString();
- const std::string type = json["type"].asString();
- DeviceButtonFunctionTypeAndValue typeAndValue;
- typeAndValue.type = type;
- if (type == "EVENT") {
- int value = json["value"].asInt();
- std::stringstream valueStr;
- valueStr << value;
- typeAndValue.value = valueStr.str();
- LOGD("key:%s type:%s value:%d ", key.c_str(), type.c_str(), value);
- }
- else {
- string valueStr = json["value"].asString();
- typeAndValue.value = valueStr;
- LOGD("key:%s type:%s value:%s ", key.c_str(), type.c_str(), valueStr.c_str());
- }
- deviceButtonFunction[key] = typeAndValue;
- }
- }
- }
- void handleCall(string key, string roleType) {
- if (roleType == "CANCEL") {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- }
- }
- else {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- } else {
- Intent* intent = new Intent();
- intent->putExtra(callActivityType, "fromCall");
- // intent->putExtra(callRoleType, roleType);
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- void handleSos(string key) {
- sosCall("");
- }
- void handleEvent(string key, string id) {
- // else {
- // if (StoragePreferences::getString(STORE_CUSTOMER_ID, "") != "" || StoragePreferences::getInt(STORE_EMPTY_BED_CALL, 0) == 1) {
- // std::stringstream idStr(id);
- // int _id;
- // idStr >> _id;
- // Json::Value json;
- // json["id"] = _id;
- // sendEventClick(json);
- //
- // Intent* intent = new Intent();
- // intent->putExtra(functionWindows, "eventCall");
- // intent->putExtra(functionText, getEventMap(id));
- // EASYUICONTEXT->openActivity("functionActivity", intent);
- // }
- // }
- }
- void handleReinforce(string key) {
- sendReinforceCall();
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "help");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- void handleNursing(string key, string time) {
- if (!StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "nursing3");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- else {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName != "functionActivity") {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "nursingEnd3");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- else {
- nursingEnd3();
- }
- }
- }
- void handleBlueCode() {
- if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
- setBlueCode(true);
- }
- }
- void getDeviceButtonFunction(string key) {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName == "sipTestActivity") {
- setCheckbox(key);
- return;
- }
- if (deviceButtonFunction.find(key) != deviceButtonFunction.end()) {
- DeviceButtonFunctionTypeAndValue typeAndValue = deviceButtonFunction[key];
- LOGD("typeAndValue.type: %s typeAndValue.value: %s", typeAndValue.type.c_str(), typeAndValue.value.c_str());
- if (typeAndValue.type == "SOS") {
- handleSos(key);
- }
- else if (typeAndValue.type == "VOICE") {
- handleCall(key, typeAndValue.value);
- }
- else if (typeAndValue.type == "EVENT") {
- handleEvent(key, typeAndValue.value);
- }
- else if (typeAndValue.type == "REINFORCE") {
- handleReinforce(key);
- }
- else if (typeAndValue.type == "NURSING") {
- handleNursing(key, typeAndValue.value);
- }
- else if (typeAndValue.type == "BLUE_CODE") {
- handleBlueCode();
- }
- }
- else {
- if (key == "KEY5") {
- handleCall(key, "NURSE");
- }
- else if (key == "KEY6") {
- handleCall(key, "NURSE");
- }
- else if (key == "KEY7" || key == "KEY;") {
- handleSos(key);
- }
- else if (key == "KEY>") {
- handleCall(key, "CANCEL");
- }
- else if (key == "HANDKEY00" || key == "OUTKEY1") {
- handleHCall(1);
- }
- else if (key == "HANDKEY10" || key == "OUTKEY2") {
- handleHCall(2);
- }
- else if (key == "HANDKEY20" || key == "OUTKEY3") {
- handleHCall(3);
- }
- else if (key == "HANDKEY30" || key == "OUTKEY4") {
- handleHCall(4);
- }
- else if (key == "OUTKEY5") {
- handleHCall(5);
- }
- else if (key == "OUTKEY6") {
- handleHCall(6);
- }
- }
- }
- //================================= IO 口操作
- //紧急按钮灯,明/灭
- void setSOS_A5(bool light){
- int result = -1;
- int slight = light?0:1;
- result = GpioHelper::output("A5", slight);
- if (result==0){
- LOGD("set A5 SOS light %d. success",light);
- } else {
- LOGD("set A5 SOS light %d. failed",light);
- }
- }
- //A6,A7,A8 RGB灯控制
- void setRGB_A678(bool R, bool G, bool B){
- int rR = -1, rG = -1, rB = -1;
- int sR = R?0:1, sG = G?0:1, sB = B?0:1;
- rR = GpioHelper::output("A6", sR);
- rG = GpioHelper::output("A7", sG);
- rB = GpioHelper::output("A8", sB);
- const char *strLog = "set %s light %d. %d";
- LOGD(strLog,"A6 R",R, rR);
- LOGD(strLog,"A7 G",G, rG);
- LOGD(strLog,"A8 B",B, rB);
- }
- //手柄按钮
- class A1GpioListener : public IGpioListener{
- public:
- bool onGpioEdge(const char *pPin) override {
- int state = GpioHelper::input("A1");
- LOGD("IGpioListener GPIO IS A1=%d", state);
- if (state==0){
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- } else {
- Intent* intent = new Intent();
- intent->putExtra(callActivityType, "fromCall");
- // intent->putExtra(callRoleType, "NURSE");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- return true;
- }
- void onGpioError(const char *pPin, int error) override {
- LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
- }
- };
- //7寸面板,呼出
- class A2GpioListener : public IGpioListener{
- public:
- bool onGpioEdge(const char *pPin) override {
- int state = GpioHelper::input("A2");
- LOGD("IGpioListener GPIO IS A2=%d", state);
- if (state==0){
- //拨打 或 接听
- }
- return true;
- }
- void onGpioError(const char *pPin, int error) override {
- LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
- }
- };
- //7寸面板,挂断
- class A3GpioListener : public IGpioListener{
- public:
- bool onGpioEdge(const char *pPin) override {
- int state = GpioHelper::input("A3");
- LOGD("IGpioListener GPIO IS A3=%d", state);
- if (state==0){
- //挂断
- }
- return true;
- }
- void onGpioError(const char *pPin, int error) override {
- LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
- }
- };
- //紧急按钮
- class A4GpioListener : public IGpioListener{
- public:
- bool onGpioEdge(const char *pPin) override {
- int state = GpioHelper::input("A4");
- LOGD("IGpioListener GPIO IS A4=%d", state);
- if (state==0){
- //发出
- setSOS_A5(true);
- }
- return true;
- }
- void onGpioError(const char *pPin, int error) override {
- LOGD("IGpioListener ERROR GPIO IS %s, %d", pPin, error);
- }
- };
- /**
- * 注册定时器
- * 填充数组用于注册定时器
- * 注意:id不能重复
- */
- static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
- {1, 5000},
- {2, 30*1000}
- };
- /**
- * 当界面构造时触发
- */
- static void onUI_init(){
- EASYUICONTEXT->updateLocalesCode(StoragePreferences::getString(STORE_LANG, defaultLang).c_str());
- //IO监测
- // IGpioListener *iGpioListenerA1 = new A1GpioListener();
- // GpioHelper::registerGpioListener("A1", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
- //
- // IGpioListener *iGpioListenerA2 = new A2GpioListener();
- // GpioHelper::registerGpioListener("A2", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
- //
- // IGpioListener *iGpioListenerA3 = new A3GpioListener();
- // GpioHelper::registerGpioListener("A3", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
- //
- // IGpioListener *iGpioListenerA4 = new A4GpioListener();
- // GpioHelper::registerGpioListener("A4", iGpioListenerA1, E_GPIO_EDGE_TYPE_FALLING);
- //TCP启动
- TcpClient::instance()->startTcp();
- //监听SIP信令
- addSipCallStateListener();
- //开启网页
- httpServer.RunAsync(HTTP_SERVER_PORT);
- // 启动的时候更改为tcp模式
- StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
- if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
- LOGD("===============> 关闭护理状态");
- StoragePreferences::putBool(STORE_NURSING_TYPE, false);
- isNursing = true;
- }
- //请求版本号
- // if(UartContext::Uart3IsOpen()) {
- // string heartStr = "ASK,VNF-0";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
- // }
- #if 0
- std::thread backend([](){
- while (true) {
- if (feed_dogs > 0) {
- --feed_dogs;
- LOGD("feed");
- int ret = GpioHelper::output("GPIO_2", 1); //拉高
- if (ret != 0) {
- LOGE("GPIO操作失败");
- }
- usleep(1000 * 20);
- ret = GpioHelper::output("GPIO_2", 0); //拉低
- if (ret != 0) {
- LOGE("GPIO操作失败");
- }
- }
- usleep(1000 * 1000);
- }
- });
- backend.detach();
- #endif
- }
- /**
- * 当切换到该界面时触发
- */
- static void onUI_intent(const Intent *intentPtr) {
- if (intentPtr != NULL) {
- //TODO
- }
- }
- /*
- * 当界面显示时触发
- */
- static void onUI_show() {
- StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
- //进入主界面
- EASYUICONTEXT->openActivity("mainActivity");
- }
- /*
- * 当界面隐藏时触发
- */
- static void onUI_hide() {
- }
- /*
- * 当界面完全退出时触发
- */
- static void onUI_quit() {
- }
- /**
- * 串口数据回调接口
- */
- static void onProtocolDataUpdate(const SProtocolData &data) {
- LOGD("cmd = %s", data.cmd.c_str());
- if (getIsUpdate()) {
- LOGD("处于升级过程中,串口不可使用");
- return;
- }
- if (data.state!=""){
- LOGD("state = %s",data.state.c_str());
- }
- string heartStr;
- if (data.state == "0") {
- if (data.cmd == "KEY5") {
- isTriggerKey5 = true;
- mActivityPtr->registerUserTimer(KEY5_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY6") {
- isTriggerKey6 = true;
- mActivityPtr->registerUserTimer(KEY6_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY7") {
- isTriggerKey7 = true;
- mActivityPtr->registerUserTimer(KEY7_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY>") {
- isTriggerKey8 = true;
- mActivityPtr->registerUserTimer(KEY8_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY<") {
- isTriggerKey9 = true;
- mActivityPtr->registerUserTimer(KEY9_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY;") {
- isTriggerKey10 = true;
- mActivityPtr->registerUserTimer(KEY10_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY?") {
- isTriggerKey11 = true;
- mActivityPtr->registerUserTimer(KEY11_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY=") {
- isTriggerKey12 = true;
- mActivityPtr->registerUserTimer(KEY12_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "HANDKEY00") {
- isTriggerHandle1 = true;
- mActivityPtr->registerUserTimer(HANDLE1_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "HANDKEY10") {
- isTriggerHandle2 = true;
- mActivityPtr->registerUserTimer(HANDLE2_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "HANDKEY20") {
- isTriggerHandle3 = true;
- mActivityPtr->registerUserTimer(HANDLE3_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "HANDKEY30") {
- isTriggerHandle4 = true;
- mActivityPtr->registerUserTimer(HANDLE4_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "OUTKEY1") {
- isTriggerOutKey1 = true;
- mActivityPtr->registerUserTimer(OUTKYE1_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "OUTKEY2") {
- isTriggerOutKey2 = true;
- mActivityPtr->registerUserTimer(OUTKYE2_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "OUTKEY3") {
- isTriggerOutKey3 = true;
- mActivityPtr->registerUserTimer(OUTKYE3_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "OUTKEY4") {
- isTriggerOutKey4 = true;
- mActivityPtr->registerUserTimer(OUTKYE4_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "OUTKEY5") {
- isTriggerOutKey5 = true;
- mActivityPtr->registerUserTimer(OUTKYE5_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "OUTKEY6") {
- isTriggerOutKey6 = true;
- mActivityPtr->registerUserTimer(OUTKYE6_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- }
- else if (data.state == "1") {
- if ((data.cmd == "KEY5" && isTriggerKey5) ||
- (data.cmd == "KEY6" && isTriggerKey6) ||
- (data.cmd == "KEY7" && isTriggerKey7) ||
- (data.cmd == "KEY>" && isTriggerKey8) ||
- (data.cmd == "KEY<" && isTriggerKey9) ||
- (data.cmd == "KEY;" && isTriggerKey10) ||
- (data.cmd == "KEY?" && isTriggerKey11) ||
- (data.cmd == "KEY=" && isTriggerKey12) ||
- (data.cmd == "HANDKEY00" && isTriggerHandle1) ||
- (data.cmd == "HANDKEY10" && isTriggerHandle2) ||
- (data.cmd == "HANDKEY20" && isTriggerHandle3) ||
- (data.cmd == "HANDKEY30" && isTriggerHandle4) ||
- (data.cmd == "OUTKEY1" && isTriggerOutKey1) ||
- (data.cmd == "OUTKEY2" && isTriggerOutKey2) ||
- (data.cmd == "OUTKEY3" && isTriggerOutKey3) ||
- (data.cmd == "OUTKEY4" && isTriggerOutKey4) ||
- (data.cmd == "OUTKEY5" && isTriggerOutKey5) ||
- (data.cmd == "OUTKEY6" && isTriggerOutKey6)) {
- getDeviceButtonFunction(data.cmd);
- }
- }
- else if (data.state == "3") {
- if (data.cmd == "KEY6") {
- isConnectHandle = true;
- }
- else if (data.cmd == "KEY7") {
- isConnectSos = true;
- }
- else if (data.cmd == "HANDKEY00") {
- isConnectHandle1 = true;
- }
- else if (data.cmd == "HANDKEY10") {
- isConnectHandle2 = true;
- }
- else if (data.cmd == "HANDKEY20") {
- isConnectHandle3 = true;
- }
- else if (data.cmd == "HANDKEY30") {
- isConnectHandle4 = true;
- }
- else if (data.cmd == "OUTKEY1") {
- isConnectOutKey1 = true;
- }
- else if (data.cmd == "OUTKEY2") {
- isConnectOutKey2 = true;
- }
- else if (data.cmd == "OUTKEY3") {
- isConnectOutKey3 = true;
- }
- else if (data.cmd == "OUTKEY4") {
- isConnectOutKey4 = true;
- }
- else if (data.cmd == "OUTKEY5") {
- isConnectOutKey5 = true;
- }
- else if (data.cmd == "OUTKEY6") {
- isConnectOutKey6 = true;
- }
- }
- else if (data.state == "4") {
- if (data.cmd == "KEY6" && isConnectHandle) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("HandleDisconnected"));
- }
- else if (data.cmd == "KEY7" && isConnectSos) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("SosDisconnected"));
- }
- else if (data.cmd == "HANDKEY00" && isConnectHandle1) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle1Disconnected"));
- }
- else if (data.cmd == "HANDKEY10" && isConnectHandle2) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle2Disconnected"));
- }
- else if (data.cmd == "HANDKEY20" && isConnectHandle3) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle3Disconnected"));
- }
- else if (data.cmd == "HANDKEY30" && isConnectHandle4) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle4Disconnected"));
- }
- else if (data.cmd == "OUTKEY1" && isConnectOutKey1) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle1Disconnected"));
- }
- else if (data.cmd == "OUTKEY2" && isConnectOutKey2) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle2Disconnected"));
- }
- else if (data.cmd == "OUTKEY3" && isConnectOutKey3) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle3Disconnected"));
- }
- else if (data.cmd == "OUTKEY4" && isConnectOutKey4) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle4Disconnected"));
- }
- else if (data.cmd == "OUTKEY5" && isConnectOutKey5) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle5Disconnected"));
- }
- else if (data.cmd == "OUTKEY6" && isConnectOutKey6) {
- sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle6Disconnected"));
- }
- }
- // if(UartContext::Uart2IsOpen()) { // 如果是true,表示串口打开了
- // string heartStr;
- //
- // // 面板拨号
- // if (data.cmd == "KEY5") {
- // if (data.state == "0") {
- // if (isSleep) {
- // scrrenOn();
- // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- // return;
- // }
- // }
- //
- // const char* currentAppName = EASYUICONTEXT->currentAppName();
- // string _currentAppName = currentAppName;
- // if (_currentAppName == "sipTestActivity") {
- // setCheckbox("KEY5");
- // return;
- // }
- // else {
- // voip::CallInfo info = GetTelephone()->GetCallInfo();
- // //拨打 或 挂断
- // if (CallingStatus::instance()->busy()){
- // callActivityFinish(CallFinishType::A1CLICK);
- // lightControl("DOORLED", "000F");
- // } else {
- // lightControl("DOORLED", "100F");
- //
- // Intent* intent = new Intent();
- // intent->putExtra(isOutgoing, "true");
- // EASYUICONTEXT->openActivity("callActivity", intent);
- // }
- // }
- // }
- // }
- // else if (data.cmd == "KEY6") {
- // if (data.state == "0") {
- // if (isSleep) {
- // scrrenOn();
- // if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- // return;
- // }
- // }
- //
- // const char* currentAppName = EASYUICONTEXT->currentAppName();
- // string _currentAppName = currentAppName;
- // if (_currentAppName == "sipTestActivity") {
- // setCheckbox("KEY6");
- // return;
- // }
- //
- // isTriggerHandle = true;
- // mActivityPtr->registerUserTimer(HANDLE_TRIGGER_TIME_HANDLE, 5 * 1000);
- //
- // }
- // else if (data.state == "1") {
- // if (isTriggerHandle) {
- // isTriggerHandle = false;
- // isConnectHandle = true;
- //
- // voip::CallInfo info = GetTelephone()->GetCallInfo();
- // //拨打 或 挂断
- // if (CallingStatus::instance()->busy()){
- // callActivityFinish(CallFinishType::KEY6_CLICK);
- // lightControl("DOORLED", "000F");
- // } else {
- // lightControl("DOORLED", "100F");
- //
- // Intent* intent = new Intent();
- // intent->putExtra(isOutgoing, "true");
- // EASYUICONTEXT->openActivity("callActivity", intent);
- // }
- // }
- // }
- // else if (data.state == "3") {
- // LOGD("手柄在线");
- // isConnectHandle = true;
- // }
- // else if (data.state == "4") {
- // if (!isConnectHandle || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
- // return;
- // }
- // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("HandleDisconnected"));
- // }
- //
- // }
- // else if (data.cmd == "KEY7") {
- // if (data.state == "0") {
- // scrrenOn();
- //
- // const char* currentAppName = EASYUICONTEXT->currentAppName();
- // string _currentAppName = currentAppName;
- // if (_currentAppName == "sipTestActivity") {
- // setCheckbox("KEY7");
- // return;
- // }
- // else {
- // if (sosTimerRegistered) {
- // isTriggerSos = true;
- // mActivityPtr->registerUserTimer(SOS_TRIGGER_TIME_HANDLE, 5 * 1000);
- // }
- // }
- // }
- // else if (data.state == "1") {
- // if (isTriggerSos) {
- // isConnectSos = true;
- // sosCall("");
- // }
- // }
- // else if (data.state == "3") {
- // LOGD("SOS按钮在线");
- // isConnectSos = true;
- // }
- // else if (data.state == "4") {
- // if (!isConnectSos || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
- // return;
- // }
- //
- // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("SosDisconnected"));
- // }
- //
- // }
- // else if (data.cmd == "KEY<") {
- // if (isSleep) {
- // scrrenOn();
- // }
- //// lightControl("DOORLED", "100F");
- // }
- // else if (data.cmd == "KEY>") { // key>是面板挂断按钮
- // if (data.state == "0") {
- // if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
- // setCheckbox("KEY>");
- // return;
- // }
- //
- // if (isSleep) {
- // scrrenOn();
- // }
- // else {
- // voip::CallInfo info = GetTelephone()->GetCallInfo();
- // //拨打 或 挂断
- // if (CallingStatus::instance()->busy()){
- // callActivityFinish(CallFinishType::A1CLICK);
- // lightControl("DOORLED", "000F");
- // }
- // }
- // }
- //
- // }
- // else if (data.cmd == "KEY;") {
- // if (isSleep) {
- // scrrenOn();
- // }
- //// lightControl("DOORLED", "111F");
- // }
- // else if (data.cmd == "HANDKEY00") {
- // if (data.state == "0") {
- // if (isSleep) {
- // scrrenOn();
- // }
- //
- // isTriggerHandle1 = true;
- // mActivityPtr->registerUserTimer(HANDLE1_TRIGGER_TIME_HANDLE, 5 * 1000);
- // }
- // else if (data.state == "1") {
- // if (isTriggerHandle1) {
- // isTriggerHandle1 = false;
- // isConnectHandle1 = true;
- //
- // handleHCall(1);
- // }
- // }
- // else if (data.state == "3") {
- // LOGD("手柄1在线");
- // isConnectHandle1 = true;
- // }
- // else if (data.state == "4") {
- // if (!isConnectHandle1 || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
- // return;
- // }
- // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle1Disconnected"));
- // }
- // }
- // else if (data.cmd == "HANDKEY10") {
- // if (data.state == "0") {
- // if (isSleep) {
- // scrrenOn();
- // }
- //
- // isTriggerHandle2 = true;
- // mActivityPtr->registerUserTimer(HANDLE2_TRIGGER_TIME_HANDLE, 5 * 1000);
- // }
- // else if (data.state == "1") {
- // if (isTriggerHandle2) {
- // isTriggerHandle2 = false;
- // isConnectHandle2 = true;
- //
- // handleHCall(2);
- // }
- // }
- // else if (data.state == "3") {
- // LOGD("手柄2在线");
- // isConnectHandle2 = true;
- // }
- // else if (data.state == "4" || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
- // if (!isConnectHandle2) {
- // return;
- // }
- // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle2Disconnected"));
- // }
- // }
- // else if (data.cmd == "HANDKEY20") {
- // if (data.state == "0") {
- // if (isSleep) {
- // scrrenOn();
- // }
- //
- // isTriggerHandle3 = true;
- // mActivityPtr->registerUserTimer(HANDLE3_TRIGGER_TIME_HANDLE, 5 * 1000);
- // }
- // else if (data.state == "1") {
- // if (isTriggerHandle3) {
- // isTriggerHandle3 = false;
- // isConnectHandle3 = true;
- //
- // handleHCall(3);
- // }
- // }
- // else if (data.state == "3") {
- // LOGD("手柄3在线");
- // isConnectHandle3 = true;
- // }
- // else if (data.state == "4" || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
- // if (!isConnectHandle3) {
- // return;
- // }
- // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle3Disconnected"));
- // }
- // }
- // else if (data.cmd == "HANDKEY30") {
- // if (data.state == "0") {
- // if (isSleep) {
- // scrrenOn();
- // }
- //
- // isTriggerHandle4 = true;
- // mActivityPtr->registerUserTimer(HANDLE4_TRIGGER_TIME_HANDLE, 5 * 1000);
- // }
- // else if (data.state == "1") {
- // if (isTriggerHandle4) {
- // isTriggerHandle4 = false;
- // isConnectHandle4 = true;
- //
- // handleHCall(4);
- // }
- // }
- // else if (data.state == "3") {
- // LOGD("手柄4在线");
- // isConnectHandle4 = true;
- // }
- // else if (data.state == "4" || StoragePreferences::getInt(STORE_DEVICE_ID, 0) == 0) {
- // if (!isConnectHandle4) {
- // return;
- // }
- // sendDataRemindOhter(getFrameFullName() + " " + LANGUAGEMANAGER->getValue("Handle4Disconnected"));
- // }
- // }
- // else {
- // if (isSleep) {
- // scrrenOn();
- // }
- // lightControl("DOORLED", "000F");
- // }
- // }
- }
- /**
- * 定时器触发函数
- * 不建议在此函数中写耗时操作,否则将影响UI刷新
- * 参数: id
- * 当前所触发定时器的id,与注册时的id相同
- * 返回值: true
- * 继续运行当前定时器
- * false
- * 停止运行当前定时器
- */
- static bool onUI_Timer(int id){
- switch (id) {
- case 1:
- {
- //定时器跑在UI线程,这里将喂狗标记加1
- //++feed_dogs;
- //不用心跳
- // if(UartContext::Uart3IsOpen()) {
- // string heartStr = "HEART,1E";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
- // }
- }
- break;
- case 2: //TCP心跳
- {
- const char* req = "0";
- TcpClient::instance()->sendMsg(req);
- }
- break;
- case SOS_CLICK_TIME_HANDLE: {
- sosTimerRegistered = true;
- return false;
- }
- break;
- case SOS_LAMP_TIME_HANDLE: {
- // SOS还原成无灯光的状态
- lightControl("ULED", "0F");
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- statusLight();
- return false;
- }
- break;
- case DOOR_LIGHT_TIME_HANDLE: {
- if (_lightColorStr == _actualColorStr) {
- _actualColorStr = "000F";
- std::string heartStr = _typeStr + "," + _actualColorStr;
- LOGD("=====> the heartStr == %s", heartStr.c_str());
- const char* sendMsg = heartStr.c_str();
- sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- }
- else {
- _actualColorStr = _lightColorStr;
- std::string heartStr = _typeStr + "," + _actualColorStr;
- LOGD("=====> the heartStr == %s", heartStr.c_str());
- const char* sendMsg = heartStr.c_str();
- sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- }
- }
- break;
- case SLEEP_STRAT_TIME_HANDLE: { // 息屏
- if (isSleepTimerRegistered) {
- isSleep = true;
- BRIGHTNESSHELPER->screenOff();
- } else { // 如果是false的话,就需要关闭定时器
- isSleep = false;
- BRIGHTNESSHELPER->screenOn();
- }
- }
- break;
- case SYS_RESTART_TIME_HANDLE:
- netresetInt += 1;
- lightControl("NETRESET", "1F");
- if (netresetInt == 5) {
- LOGD("网卡重启无效,程序内部重启");
- //重启
- sync();
- reboot(RB_AUTOBOOT);
- }
- break;
- case KEY5_TRIGGER_TIME_HANDLE: {
- isTriggerKey5 = false;
- }
- break;
- case KEY6_TRIGGER_TIME_HANDLE: {
- isTriggerKey6 = false;
- return false;
- }
- break;
- case KEY7_TRIGGER_TIME_HANDLE: {
- isTriggerKey7 = false;
- return false;
- }
- break;
- case KEY8_TRIGGER_TIME_HANDLE: {
- isTriggerKey8 = false;
- return false;
- }
- break;
- case KEY9_TRIGGER_TIME_HANDLE: {
- isTriggerKey9 = false;
- return false;
- }
- break;
- case KEY10_TRIGGER_TIME_HANDLE: {
- isTriggerKey10 = false;
- return false;
- }
- break;
- case KEY11_TRIGGER_TIME_HANDLE: {
- isTriggerKey11 = false;
- return false;
- }
- break;
- case KEY12_TRIGGER_TIME_HANDLE: {
- isTriggerKey12 = false;
- return false;
- }
- break;
- case HANDLE1_TRIGGER_TIME_HANDLE: {
- isTriggerHandle1 = false;
- return false;
- }
- break;
- case HANDLE2_TRIGGER_TIME_HANDLE: {
- isTriggerHandle2 = false;
- return false;
- }
- break;
- case HANDLE3_TRIGGER_TIME_HANDLE: {
- isTriggerHandle3 = false;
- return false;
- }
- break;
- case HANDLE4_TRIGGER_TIME_HANDLE: {
- isTriggerHandle4 = false;
- return false;
- }
- break;
- case OUTKYE1_TRIGGER_TIME_HANDLE: {
- isTriggerOutKey1 = false;
- return false;
- }
- break;
- case OUTKYE2_TRIGGER_TIME_HANDLE: {
- isTriggerOutKey2 = false;
- return false;
- }
- break;
- case OUTKYE3_TRIGGER_TIME_HANDLE: {
- isTriggerOutKey3 = false;
- return false;
- }
- break;
- case OUTKYE4_TRIGGER_TIME_HANDLE: {
- isTriggerOutKey4 = false;
- return false;
- }
- break;
- case OUTKYE5_TRIGGER_TIME_HANDLE: {
- isTriggerOutKey5 = false;
- return false;
- }
- break;
- case OUTKYE6_TRIGGER_TIME_HANDLE: {
- isTriggerOutKey6 = false;
- return false;
- }
- break;
- case SIP_RECONNECT_TIME_HANDLE: {
- removeSipCallStateListener();
- removeSipRegisterStateListener();
- ReleaseTelephone();
- addSipCallStateListener();
- addSipRegisterStateListener();
- return false;
- }
- break;
- default:
- break;
- }
- return true;
- }
- /**
- * 有新的触摸事件时触发
- * 参数:ev
- * 新的触摸事件
- * 返回值:true
- * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
- * false
- * 触摸事件将继续传递到控件上
- */
- static bool onstartActivityTouchEvent(const MotionEvent &ev) {
- switch (ev.mActionStatus) {
- case MotionEvent::E_ACTION_DOWN://触摸按下
- //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
- break;
- case MotionEvent::E_ACTION_MOVE://触摸滑动
- break;
- case MotionEvent::E_ACTION_UP: //触摸抬起
- break;
- default:
- break;
- }
- return false;
- }
|