1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819 |
- #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 "net/udp_client.h"
- #include "net/tcp_client5084.h"
- #include "net/tcp_client5089.h"
- #include "net/NetManager.h"
- #include "server/http_server.h"
- #include "base/strings.hpp"
- #include "utils/GpioHelper.h"
- #include "utils/TimeHelper.h"
- #include "utils/CrcCheckUtil.h"
- #include "utils/BrightnessHelper.h"
- #include <manager/LanguageManager.h>
- #include <time.h>
- #include <thread>
- #include <string>
- #include <unistd.h>
- #include <sys/reboot.h>
- #include "service/BusinessConfig.h"
- #include <utils/TimeUtil.h>
- static bool isHelpTimerRegistered = false; //增援定时任务
- static bool sosTimerRegistered = true; //sos定时任务
- static string sosTid = "";
- static bool isSleepTimerRegistered = false; // 是否开启息屏定时任务
- static bool isSleep = false; // 是否在息屏
- static bool isNursing = false; // 用于启动时判断是否处于护理状态
- static bool isNetreset = false;
- static bool loraEnable = false;
- static bool loraSosTimeRegistered = false;
- static int netresetInt = 0;
- static string voiceCallTid = "";
- Json::Value sosInteraction;
- struct DeviceButtonFunctionTypeAndValue {
- string type;
- string value;
- };
- static std::unordered_map<string, DeviceButtonFunctionTypeAndValue> deviceButtonFunction;
- static bool isConnectHandle = false;
- static bool isConnectSos = 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 isTriggerKey13 = false;
- static bool isUdpClientWait = false;
- static int isUdpClientWaitCount = 0;
- static int timeDifference = 8;
- #define FUNCTION_TIMER_HANDLE 3 // 增援的定时器id
- #define SOS_CLICK_TIME_HANDLE 4 // sos的定时器id
- #define SOS_LAMP_TIME_HANDLE 5 // sos的门灯定时器id
- #define PART_LANGUAGE_TIME_HANDLE 7 // 暂时弃用
- #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 SOS_TID_TIME_HANDLE 14
- #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 KEY13_TRIGGER_TIME_HANDLE 23
- #define COUNTDOWN1_TIME_HANDLE 51
- #define COUNTDOWN2_TIME_HANDLE 52
- #define COUNTDOWN3_TIME_HANDLE 53
- #define UDP_CLIENT_TIME_HANDLE 83
- #define UPDATE_LIGHT_TIME_HANDLE 84
- #define REBOOT_TIME_HANDLE 99
- #define WIFI_TIME_HANDLE 100
- #define HTTP_SERVER_PORT 80
- #define goback 200
- #define SIP_RECONNECT_TIME_HANDLE 201
- static bool isMulitFunction = false;
- #define MULTI_FUNCTION 5089
- srv::HttpServer httpServer;
- static bool isWifiSupported = false;
- #define ETHERNETMANAGER NETMANAGER->getEthernetManager()
- #define WIFIMANAGER NETMANAGER->getWifiManager()
- 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("当前呼叫状态 ===> %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.call_direction == %d", info.call_direction);
- LOGD("info.remote_uri == %s", info.remote_uri.c_str());
- LOGD("info.remote_contact == %s", info.remote_contact.c_str());
- LOGD("info.duration == %d", info.duration);
- 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"){
- LOGD("=================> 类型是SIP,进入呼叫界面");
- Intent* intent = new Intent();
- intent->putExtra(callActivityType, "toCall");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- else {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName == "callActivity") {
- if (sipId == "0000000000" && getCallActivityType() == "wait") {
- telephone->Hangup();
- LOGD("=================> 在通话界面,但已经在通话中,不接受广播");
- return;
- }
- }
- else if (_currentAppName == "functionActivity") {
- EASYUICONTEXT->closeActivity("functionActivity");
- }
- else {
- if (sipId != "0000000000") {
- telephone->Hangup();
- LOGD("=================> 不在通话界面,直接挂断!");
- return;
- }
- }
- LOGD("=================> 通话建立");
- }
- 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) {
- if (telephone->GetCallCount() > 1) {
- LOGD("call count > 1, return");
- return;
- }
- if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
- EASYUICONTEXT->goBack();
- }
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- LOGD("通话结束的状态码 ===> %d", info.last_state);
- if (info.last_state == 404) {
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::NOT_FOUND);
- }
- mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
- }
- else if (info.last_state == 408) {
- 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("删除失败");
- // }
- // }
- // 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 (getIsDay()){
- BRIGHTNESSHELPER->setBrightness(dayLight);
- } else {
- BRIGHTNESSHELPER->setBrightness(nightLight);
- }
- }
- void addSipCallStateListener() {
- GetTelephone()->AddCallStateListener(OnCallStateChanged);
- }
- void removeSipCallStateListener() {
- GetTelephone()->RemoveCallStateListener(OnCallStateChanged);
- }
- }
- void systemRestart() {
- if (!isNetreset) {
- isNetreset = true;
- statusLight("000F");
- mActivityPtr->registerUserTimer(SYS_RESTART_TIME_HANDLE, 1000);
- }
- }
- void setTimeDifference() {
- std::string _timeZone = StoragePreferences::getString(STORE_PART_TIME_ZONE, defaultPartTimeZone);
- if (_timeZone == "Africa/Lome") {
- timeDifference = 0;
- }
- else if (_timeZone == "Africa/Luanda") {
- timeDifference = 1;
- }
- else if (_timeZone == "Africa/Kigali") {
- timeDifference = 2;
- }
- else if (_timeZone == "Europe/Moscow") {
- timeDifference = 3;
- }
- else if (_timeZone == "Europe/Astrakhan") {
- timeDifference = 4;
- }
- else if (_timeZone == "Asia/Karachi") {
- timeDifference = 5;
- }
- else if (_timeZone == "Asia/Dhaka") {
- timeDifference = 6;
- }
- else if (_timeZone == "Asia/Ho_Chi_Minh") {
- timeDifference = 7;
- }
- else if (_timeZone == "Asia/Seoul") {
- timeDifference = 9;
- }
- else if (_timeZone == "Asia/Ust-Nera") {
- timeDifference = 10;
- }
- else if (_timeZone == "Asia/Magadan") {
- timeDifference = 11;
- }
- else if (_timeZone == "Asia/Anadyr") {
- timeDifference = 12;
- }
- else if (_timeZone == "Pacific/Apia") {
- timeDifference = 13;
- }
- else if (_timeZone == "Pacific/Kiritimati") {
- timeDifference = 14;
- }
- else if (_timeZone == "Atlantic/Cape_Verde") {
- timeDifference = -1;
- }
- else if (_timeZone == "America/Noronha") {
- timeDifference = -2;
- }
- else if (_timeZone == "America/Sao_Paulo") {
- timeDifference = -3;
- }
- else if (_timeZone == "America/Montserrat") {
- timeDifference = -4;
- }
- else if (_timeZone == "America/Bogota") {
- timeDifference = -5;
- }
- else if (_timeZone == "America/Merida") {
- timeDifference = -6;
- }
- else if (_timeZone == "America/Creston") {
- timeDifference = -7;
- }
- else if (_timeZone == "Pacific/Pitcairn") {
- timeDifference = -8;
- }
- else if (_timeZone == "Pacific/Gambier") {
- timeDifference = -9;
- }
- else if (_timeZone == "Pacific/Honolulu") {
- timeDifference = -10;
- }
- else if (_timeZone == "Pacific/Midway") {
- timeDifference = -11;
- }
- }
- int getTimeDifference() {
- return timeDifference;
- }
- // 门灯还原
- 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;
- }
- heartStr = "$" + heartStr + "#";
- LOGD("=====> the heartStr == %s", heartStr.c_str());
- sendSimleBySerialType(heartStr, SerialType::PANEL_BUTTON);
- }
- void loraStart() {
- if (!loraEnable) {
- loraEnable = true;
- string startMsg1 = "AT+FREQ=483200000,483200000,483200000,483200000\r\n";
- string statrMsg2 = "AT+RATE=6,6\r\n";
- string statrMsg3 = "AT+TXP=15\r\n";
- string statrMsg4 = "AT+WORKMODE=82\r\n";
- string statrMsg5 = "AT+WORKMODE=81\r\n";
- sendLoraTo(statrMsg4);
- sendLoraTo(startMsg1);
- sendLoraTo(statrMsg2);
- sendLoraTo(statrMsg3);
- sendLoraTo(statrMsg5);
- LOGD("启动LoRa模块");
- }
- }
- void loraStart(bool enable) {
- loraEnable = enable;
- loraStart();
- }
- void udpHandleMsg(byte* inBytes) {
- LOGD("UDP received: %s", inBytes);
- Json::Reader reader(Json::Features::strictMode());
- Json::Value root;
- const char* cstr = reinterpret_cast<const char*>(inBytes);
- if (reader.parse(cstr, root, false)){
- string serverIp = root["data"]["third_server"].asString();
- int serverPort = root["data"]["third_server_port"].asInt();
- StoragePreferences::putString(STORE_GATEWAY, serverIp.c_str());
- StoragePreferences::putInt(STORE_HTTP_PORT, serverPort);
- StoragePreferences::putBool(STORE_SET_SERVER_IP, true);
- deviceReboot();
- }
- }
- // 接收tcp消息
- void handleMsg(byte* inBytes){
- 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);
- TimeUtil::setDataTimeByTimeDifference(serverTime, timeDifference);
- 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) { // 重启设备
- deviceReboot();
- }
- else if (tcpModel.action == DeviceAction::REBOOT) { // 重启设备
- deviceReboot();
- }
- 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());
- deviceReboot();
- }
- }
- else if (tcpModel.type == TcpType::DATA){
- if (tcpModel.action == DataAction::REFRESH){ // 刷新数据
- dataRefresh();
- }
- }
- else if (tcpModel.type == TcpType::VOICE){
- if (tcpModel.action == VoiceAction::FAILED){
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::FAILED);
- }
- }
- else if (tcpModel.action == VoiceAction::SUCCESS){
- CallingStatus::instance()->setTcpModel(tcpModel); // 只有呼叫成功才闪红灯
- lightControl("DOORLED", "200F");
- }
- 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 (getCallActivityType() == "broadcast") {
- callActivityFinish(CallFinishType::BROADCAST);
- sleep(1);
- }
- // 如果是自己呼叫自己,则直接跳过
- if (tcpModel.from_id == StoragePreferences::getInt(STORE_DEVICE_ID, 0)) {
- return;
- }
- //我方忙线判断
- if (CallingStatus::instance()->busy()){
- sendVoiceTcp(VoiceAction::CALLING, tcpModel, tcpModel.from_id);
- } else {
- 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::CANCEL_BY_DOOR) {
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::CANCEL_BY_DOOR);
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- }
- }
- else if (tcpModel.action == VoiceAction::VOICE_OFF) {
- if (CallingStatus::instance()->busy()) {
- callActivityFinish(CallFinishType::VOICE_OFF);
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- }
- }
- else if (tcpModel.action == VoiceAction::SIP_RECONNECT) {
- mActivityPtr->registerUserTimer(SIP_RECONNECT_TIME_HANDLE, 1 * 1000);
- }
- }
- else if (tcpModel.type == TcpType::SOS) {
- if (tcpModel.action == SosAction::CANCEL) {
- // SOS还原成无灯光的状态
- lightControl("ULED", "0F");
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- statusLight("000F", StatusLightType::INIT);
- mActivityPtr->unregisterUserTimer(SOS_LAMP_TIME_HANDLE);
- }
- }
- else if (tcpModel.type == TcpType::EVENT) {
- if (tcpModel.action == EventAction::RESPONSE) {
- string data = tcpModel.json["data"].asString();
- string toMemberName = tcpModel.json["toMemberName"].asString();
- if (toMemberName != "") {
- string toRoleName = tcpModel.json["toRoleName"].asString();
- data = toMemberName + toRoleName + LANGUAGEMANAGER->getValue("EventResponse") + data;
- }
- else {
- data = LANGUAGEMANAGER->getValue("HostDevice") + LANGUAGEMANAGER->getValue("EventResponse") + data;
- }
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName != "functionActivity") {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "eventResponse");
- intent->putExtra(functionText, data);
- EASYUICONTEXT->openActivity("functionActivity", intent);
- } else {
- toFunctionActivity(data);
- }
- }
- }
- else if (tcpModel.type == TcpType::SIDE) {
- if (tcpModel.action == SideAction::NURSING) {
- // 将护理的interactionId存起来,用于取消护理的时候使用
- 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");
- }
- else if (tcpModel.action == SideAction::CANCEL) {
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- }
- else if (tcpModel.action == SideAction::SOS_CALL) {
- // 收到SOS_CALL,需要亮红灯
- // 门灯亮红灯
- lightControl("DOORLED", "200F");
- statusLight("100F", StatusLightType::NO_COMMON);
- sosTimerRegistered = false;
- mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
- mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
- if (tcpModel.json["fromEthMac"].asString() == StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0")) {
- sosInteraction = tcpModel.json;
- }
- }
- else if (tcpModel.action == SideAction::SOS_CANCEL) {
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- }
- else if (tcpModel.action == SideAction::SIMULATE) {
- TcpModel simulate;
- simulate.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
- simulate.type = tcpModel.json["type"].asCString();
- simulate.action = tcpModel.json["action"].asCString();
- simulate.tid = tcpModel.json["tid"].asCString();
- simulate.json = tcpModel.json["data"];
- if (simulate.type == TcpType::VOICE) {
- if (simulate.action == VoiceAction::CALL) {
- Intent* intent = new Intent();
- intent->putExtra(callTid, simulate.tid);
- intent->putExtra(callRoleType, simulate.json["roleType"].asString());
- intent->putExtra(callActivityType, "fromCall");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- }
- else if (tcpModel.type == TcpType::BROADCAST) {
- string _callActivityType = getCallActivityType();
- if (tcpModel.action == BroadcastAction::START) {
- if (_callActivityType == "wait") {
- LOGD("=================> 收到BROADCAST_START,目前处于空闲状态,进入广播");
- Intent* intent = new Intent();
- intent->putExtra(callActivityType, "broadcast");
- intent->putExtra(broadcastRoomNo, tcpModel.data);
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- else {
- LOGD("=================> 收到BROADCAST_START,目前并不处于空闲状态,无法进入广播");
- }
- }
- else if (tcpModel.action == BroadcastAction::STOP) {
- if (_callActivityType == "broadcast") {
- LOGD("=================> 收到BROADCAST_STOP,目前处于广播状态,退出广播");
- callActivityFinish(CallFinishType::BROADCAST);
- }
- else {
- LOGD("=================> 收到BROADCAST_STOP,目前不处于广播状态,无须退出广播");
- }
- }
- }
- else if (tcpModel.type == TcpType::COUNTDOWN) {
- if (tcpModel.action == CountdownAction::START) {
- if (tcpModel.json.isMember("id") && tcpModel.json.isMember("operationData")) {
- LOGD("operation_data == %s", tcpModel.json["operationData"].asCString());
- Json::Reader Reader;
- Json::Value operationData;
- Reader.parse(tcpModel.json["operationData"].asString(), operationData);
- LOGD("id == %d", tcpModel.json["id"].asInt());
- setCountdownItId(tcpModel.json["id"].asInt(), operationData["number"].asInt());
- }
- }
- }
- 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) {
- if (tcpModel.tid == "") {
- return;
- }
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onSuccess(tcpModel.json);
- }
- if (tcpModel.tid == sosTid && loraSosTimeRegistered) {
- mActivityPtr->unregisterUserTimer(SOS_TID_TIME_HANDLE);
- }
- }
- else if (tcpModel.action == CallbackAction::FAILED) {
- if (tcpModel.tid == "") {
- return;
- }
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onFalied(tcpModel.json);
- }
- if (tcpModel.tid == voiceCallTid){
- callActivityFinish(CallFinishType::FAILED);
- }
- else if (tcpModel.tid == sosTid && loraSosTimeRegistered) {
- mActivityPtr->unregisterUserTimer(SOS_TID_TIME_HANDLE);
- }
- }
- }
- }
- void deviceReboot() {
- LOGD("正在重启");
- const char* req = "-1";
- TcpClient::instance()->sendMsg(req);
- statusLight("000F");
- sync();
- reboot(RB_AUTOBOOT);
- }
- void loraDataSet(std::string loraDataStr, int uartNumber) {
- Json::Reader reader(Json::Features::strictMode());
- Json::Value json;
- if (reader.parse(loraDataStr.c_str(), json, false)) {
- if (json.size() > 0 && json.isMember("server")) {
- StoragePreferences::putString(STORE_GATEWAY, json["server"].asString());
- StoragePreferences::putInt(STORE_HTTP_PORT, json["port"].asInt());
- StoragePreferences::putString(STORE_WIFI_SSID, json["wifi"].asString());
- StoragePreferences::putString(STORE_WIFI_PW, json["wifi_pw"].asString());
- // std::string success = "$ "+ StoragePreferences::getString(STORE_MAC_ADDR, GetDeviceUid()) +"SUCCESS#"; // 暂定
- // const BYTE *pData = reinterpret_cast<const BYTE *>(success.c_str());
- // std::uint32_t len = success.size();
- // UartContext::sendTo(uartNumber, pData, len);
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "loraDataSet");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- }
- }
- void startTcpClient5089() {
- if (!isMulitFunction) {
- isMulitFunction = true;
- mActivityPtr->registerUserTimer(MULTI_FUNCTION, 30 * 1000);
- }
- }
- void stopTcpClient5089() {
- isMulitFunction = false;
- }
- void setLangeuage() {
- std::string deviceLanguage = StoragePreferences::getString(STORE_LANG, defaultLang);
- std::string partLanguage = StoragePreferences::getString(STORE_PART_LANG, defaultPartLang);
- if (deviceLanguage != defaultLang) {
- LOGD("设备自身拥有语言:%s", deviceLanguage.c_str());
- EASYUICONTEXT->updateLocalesCode(deviceLanguage.c_str());
- }
- else {
- LOGD("科室语言:%s", partLanguage.c_str());
- if (partLanguage == "en") {
- EASYUICONTEXT->updateLocalesCode("en_US");
- }
- else if (partLanguage == "es") {
- EASYUICONTEXT->updateLocalesCode("es_ES");
- }
- else if (partLanguage == "ru") {
- EASYUICONTEXT->updateLocalesCode("ru_RU");
- }
- else {
- EASYUICONTEXT->updateLocalesCode("zh_CN");
- }
- }
- }
- bool getSleepTimerRegistered() {
- return isSleepTimerRegistered;
- }
- void screenOn() {
- isSleep = false;
- BRIGHTNESSHELPER->screenOn();
- }
- // 触发定时任务
- 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;
- //默认3分钟
- int sleepTime = StoragePreferences::getInt(STORE_SLEEP_TIME, 3);
- if (sleepTime > 0) {
- mActivityPtr->registerUserTimer(SLEEP_STRAT_TIME_HANDLE, sleepTime * 60 * 1000);
- LOGD("开启息屏");
- }
- }
- }
- }
- void setCallTid(std::string tid) {
- voiceCallTid = tid;
- }
- void sendSosToLora() {
- string sosMsg = "$" + StoragePreferences::getString(STORE_MAC_ADDR, GetDeviceUid()) + "LORA7,1F#\r\n";
- sendLoraTo(sosMsg, 5);
- }
- void sosCall(string sosMsg, bool isConnectServer) {
- if (sosTimerRegistered) {
- if (isConnectServer) {
- LOGD("TCP -> SOS_CALL");
- sosTid = sendSosCall(sosMsg);
- loraSosTimeRegistered = true;
- mActivityPtr->registerUserTimer(SOS_TID_TIME_HANDLE, 5* 1000);
- }
- else {
- LOGD("LORA -> SOS_CALL");
- sendSosToLora();
- }
- // SOS亮红灯
- lightControl("ULED", "1F");
- // 门灯亮红灯
- lightControl("DOORLED", "200F");
- statusLight("100F", StatusLightType::NO_COMMON);
- sosTimerRegistered = false;
- mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
- mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
- if (getCallActivityType() == "wait") {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "sosCall");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- }
- }
- 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 (isSleep) {
- screenOn();
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- return;
- }
- }
- if (roleType == "CANCEL") {
- if (getCallActivityType() == "broadcast") {
- callActivityFinish(CallFinishType::BROADCAST);
- return;
- }
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- lightControl("DOORLED", "000F");
- callActivityFinish(CallFinishType::A1CLICK);
- }
- }
- else {
- if (getCallActivityType() == "broadcast") {
- return;
- }
- else {
- if (StoragePreferences::getString(STORE_CUSTOMER_ID, "") != "" || StoragePreferences::getInt(STORE_EMPTY_BED_CALL, 0) == 1) {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- lightControl("DOORLED", "000F");
- callActivityFinish(CallFinishType::A1CLICK);
- } else {
- lightControl("DOORLED", "200F");
- Intent* intent = new Intent();
- intent->putExtra(callRoleType, roleType);
- intent->putExtra(callActivityType, "fromCall");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- }
- }
- void handleSosCancel(string key) {
- LOGD("Trigger sos cancel");
- if (sosInteraction > 0 && sosInteraction.isMember("id")) {
- sendSosCancel(sosInteraction["id"].asString());
- sosInteraction = Json::Value();
- }
- }
- void handleSos(string value) {
- screenOn();
- if (value == "SOS_CANCEL") {
- handleSosCancel("");
- }
- else {
- sosCall("", isConnectServer());
- }
- }
- void handleEvent(string key, string id) {
- if (isSleep) {
- screenOn();
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- return;
- }
- }
- 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);
- if (getCallActivityType() == "wait") {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "eventCall");
- intent->putExtra(functionText, getEventMap(id));
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- }
- }
- void handleReinforce(string key) {
- if (isSleep) {
- screenOn();
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- return;
- }
- }
- sendReinforceCall();
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "help");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- void handleNursing(string key, string time) {
- if (isSleep) {
- screenOn();
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- return;
- }
- }
- if (!StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "nursing2");
- intent->putExtra(nursingTime, time);
- // intent->putExtra(nursingTime, "1");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- else {
- setNursingTime(false);
- }
- }
- void handleBlueCode() {
- if (isSleep) {
- screenOn();
- }
- }
- void getDeviceButtonFunction(string key) {
- const char* currentAppName = EASYUICONTEXT->currentAppName();
- string _currentAppName = currentAppName;
- if (_currentAppName == "sipTestActivity") {
- if (isSleep) {
- screenOn();
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- return;
- }
- }
- setCheckbox(key);
- return;
- }
- if (!isConnectServer()) {
- sendSosToLora();
- sosCall("", false);
- 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(typeAndValue.value);
- }
- 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 == "KEY@") {
- handleSosCancel(key);
- }
- }
- }
- #define WIFIMANAGER NETMANAGER->getWifiManager()
- void wifiConnect() {
- if (WIFIMANAGER->isSupported()) {
- LOGD("检测支持wifi");
- if (!WIFIMANAGER->isWifiEnable()) {
- LOGD("判断wifi未开启");
- WIFIMANAGER->enableWifi(true);
- LOGD("启动wifi");
- }
- sleep(3);
- if (!WIFIMANAGER->isConnected()) {
- LOGD("判断wifi未连接");
- WIFIMANAGER->startScan();
- LOGD("扫描wifi");
- sleep(3);
- string ssid = "COMFAST_F371_2G";
- string pw = "12345678";
- WIFIMANAGER->connect(ssid, pw);
- LOGD("进行wifi连接");
- }
- if (WIFIMANAGER->isConnected()) {
- LOGD("wifi连接后");
- WifiInfo* info = WIFIMANAGER->getConnectionInfo();
- LOGD("info.ssid =====> %s", info->getSsid().c_str());
- LOGD("info.Bssid =====> %s", info->getBssid().c_str());
- LOGD("info.pwd =====> %s", info->getPasswd().c_str());
- LOGD("info.Encryption =====> %s", info->getEncryption().c_str());
- LOGD("info.Statement =====> %s", info->getStatement().c_str());
- LOGD("info.Freq =====> %d", info->getFreq());
- LOGD("info.Level =====> %d", info->getLevel());
- LOGD("info.Rssi =====> %d", info->getRssi());
- }
- }
- }
- //================================= 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");
- 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(){
- setTimeDifference();
- setLangeuage();
- //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();
- // if (!StoragePreferences::getBool(STORE_SET_SERVER_IP, false)) {
- // // UDP启动
- // UdpClient::instance()->startUdp();
- // }
- //监听SIP信令
- addSipCallStateListener();
- //开启网页
- httpServer.RunAsync(HTTP_SERVER_PORT);
- if (StoragePreferences::getBool(STORE_NURSING_TYPE, false)) {
- LOGD("===============> 关闭护理状态");
- StoragePreferences::putBool(STORE_NURSING_TYPE, false);
- isNursing = true;
- }
- isWifiSupported = WIFIMANAGER->isSupported();
- //请求版本号
- // if(UartContext::Uart3IsOpen()) {
- // string heartStr = "ASK,VNF-0";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS3, (byte*)(sendMsg), strlen(sendMsg));
- // }
- // wifiConnect();
- #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;
- // getDeviceButtonFunction(data.cmd);
- if (data.state == "0" || data.state == "1") {
- if (data.cmd == "KEY5") {
- if (isTriggerKey5) {
- isTriggerKey5 = false;
- getDeviceButtonFunction(data.cmd);
- }
- else {
- isTriggerKey5 = true;
- mActivityPtr->registerUserTimer(KEY5_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- if (isUdpClientWait) {
- if (isUdpClientWaitCount < 5) {
- LOGD("关闭udp等待定时器");
- isUdpClientWait = false;
- isUdpClientWaitCount = 0;
- mActivityPtr->unregisterUserTimer(UDP_CLIENT_TIME_HANDLE);
- statusLight("000F", StatusLightType::UNLOCK);
- }
- else {
- LOGD("触发udp广播");
- UdpClient::instance()->startUdp();
- if (isWifiSupported) {
- startSoft();
- }
- }
- }
- else {
- isUdpClientWait = true;
- mActivityPtr->registerUserTimer(UDP_CLIENT_TIME_HANDLE, 1 * 1000);
- }
- }
- else if (data.cmd == "KEY6") {
- if (isTriggerKey6) {
- isTriggerKey6 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey6 = true;
- mActivityPtr->registerUserTimer(KEY6_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY7") {
- if (isTriggerKey7) {
- isTriggerKey7 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey7 = true;
- mActivityPtr->registerUserTimer(KEY7_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY>") {
- if (isTriggerKey8) {
- isTriggerKey8 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey8 = true;
- mActivityPtr->registerUserTimer(KEY8_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY<") {
- if (isTriggerKey9) {
- isTriggerKey9 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey9 = true;
- mActivityPtr->registerUserTimer(KEY9_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY;") {
- if (isTriggerKey10) {
- isTriggerKey10 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey10 = true;
- mActivityPtr->registerUserTimer(KEY10_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY?") {
- if (isTriggerKey11) {
- isTriggerKey11 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey11 = true;
- mActivityPtr->registerUserTimer(KEY11_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY=") {
- if (isTriggerKey12) {
- isTriggerKey12 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey12 = true;
- mActivityPtr->registerUserTimer(KEY12_TRIGGER_TIME_HANDLE, 3 * 1000);
- }
- else if (data.cmd == "KEY@") {
- if (isTriggerKey13) {
- isTriggerKey13 = false;
- getDeviceButtonFunction(data.cmd);
- return;
- }
- isTriggerKey13 = true;
- mActivityPtr->registerUserTimer(KEY13_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 == "KEY@" && isTriggerKey13)
- // ) {
- // getDeviceButtonFunction(data.cmd);
- // }
- // }
- else if (data.state == "3") {
- if (data.cmd == "KEY6") {
- isConnectHandle = true;
- }
- else if (data.cmd == "KEY7") {
- isConnectSos = true;
- }
- }
- else if (data.state == "4") {
- if (data.cmd == "KEY6" && isConnectHandle) {
- sendDataRemindOhter(StoragePreferences::getString(STORE_FRAME_FULL_NAME, "") + " " + LANGUAGEMANAGER->getValue("HandleDisconnected"));
- }
- else if (data.cmd == "KEY7" && isConnectSos) {
- sendDataRemindOhter(StoragePreferences::getString(STORE_FRAME_FULL_NAME, "") + " " + LANGUAGEMANAGER->getValue("SosDisconnected"));
- }
- }
- }
- /**
- * 定时器触发函数
- * 不建议在此函数中写耗时操作,否则将影响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 MULTI_FUNCTION: {
- const char* req = "0";
- TcpClient5089::instance()->sendMsg(req);
- return isMulitFunction;
- }
- break;
- case SOS_CLICK_TIME_HANDLE: {
- sosTimerRegistered = true;
- return false;
- }
- break;
- case SOS_LAMP_TIME_HANDLE: {
- // SOS还原成无灯光的状态
- lightControl("ULED", "0F");
- // 进行门灯还原
- lightControl("DOORLED", "000F");
- statusLight("000F", StatusLightType::INIT);
- return false;
- }
- break;
- case SOS_TID_TIME_HANDLE: {
- loraSosTimeRegistered = false;
- sendSosToLora();
- return false;
- }
- 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("网卡重启无效,程序内部重启");
- deviceReboot();
- }
- }
- 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 KEY13_TRIGGER_TIME_HANDLE: {
- isTriggerKey13 = false;
- return false;
- }
- break;
- case UDP_CLIENT_TIME_HANDLE: {
- isUdpClientWaitCount += 1;
- LOGD("isUdpClientWaitCount ===> %d", isUdpClientWaitCount);
- if (isWifiSupported) {
- if (isUdpClientWaitCount >= 2 && isUdpClientWaitCount < 5) {
- statusLight("000F", StatusLightType::NO_LOCK);
- }
- else if (isUdpClientWaitCount >= 5 && isUdpClientWaitCount < 120) {
- statusLight("110F", StatusLightType::LOCK);
- }
- else if (isUdpClientWaitCount >= 120) {
- isUdpClientWaitCount = 0;
- isUdpClientWait = false;
- statusLight("000F", StatusLightType::UNLOCK);
- stopSoft();
- return false;
- }
- }
- else {
- if (isUdpClientWaitCount >= 2 && isUdpClientWaitCount < 5) {
- statusLight("000F", StatusLightType::NO_LOCK);
- }
- else if (isUdpClientWaitCount >= 5 && isUdpClientWaitCount < 15) {
- statusLight("110F", StatusLightType::LOCK);
- }
- else if (isUdpClientWaitCount >= 15) {
- isUdpClientWaitCount = 0;
- isUdpClientWait = false;
- statusLight("000F", StatusLightType::UNLOCK);
- // stopSoft();
- 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;
- }
|