1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- #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 "utils/GpioHelper.h"
- #include "utils/TimeHelper.h"
- #include "utils/BrightnessHelper.h"
- #include <time.h>
- #include <thread>
- #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 string callTid = "";
- #define HELP_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 10 // 重启
- #define HTTP_SERVER_PORT 80
- srv::HttpServer httpServer;
- 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) {
- if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
- //EASYUICONTEXT->goHome();
- EASYUICONTEXT->openActivity("callActivity");
- CloseUi();
- }
- 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());
- 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->goHome();
- EASYUICONTEXT->goBack();
- }
- //保存通话记录
- 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 (checkIsDay()){
- BRIGHTNESSHELPER->setBrightness(dayLight);
- } else {
- BRIGHTNESSHELPER->setBrightness(nightLight);
- }
- }
- }
- // 门灯还原
- //void doorLampRestoration() {
- 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;
- }
- LOGD("=====> the heartStr == %s", heartStr.c_str());
- const char* sendMsg = heartStr.c_str();
- sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- }
- // 接收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) {
- sendNursingEnd();
- }
- }
- } 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);
- }
- cancelAutoBtnHelpTimer();
- // SetPainterInfo(0xFF37C127, LANGUAGEMANAGER->getValue("HelpResponse"));
- // setHelpButton("/button/button_help3.png", false);
- // setReinforce(false); // 设置增援状态为true
- // //3秒后还原白色
- // if (!isHelpTimerRegistered){
- // mActivityPtr->registerUserTimer(HELP_TIMER_HANDLE, 3000);
- // }
- setPainterInfo(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0xFF37C127, LANGUAGEMANAGER->getValue("HelpResponse"), "REINFORCE", "UPDATE", 3);
- }
- } 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("DeviceUpdateActivity", intent);
- }
- else if (tcpModel.action == DeviceAction::RESTART) { // 重启设备
- const char* req = "-1";
- TcpClient::instance()->sendMsg(req);
- 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);
- //重启
- sync();
- reboot(RB_AUTOBOOT);
- }
- else if (tcpModel.action == DeviceAction::REBOOT) {
- const char* req = "-1";
- TcpClient::instance()->sendMsg(req);
- //重启
- 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){
- string _cencalByDoorTid = getCencalByDoorTid();
- if (tcpModel.tid != _cencalByDoorTid) {
- callActivityFinish(CallFinishType::FAILED);
- }
-
- } else if (tcpModel.action == VoiceAction::SUCCESS){
- CallingStatus::instance()->setTcpModel(tcpModel); // 只有呼叫成功才闪红灯
- // std::string heartStr = "DOORLED,200F"; // 红灯闪烁
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- 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);
- }
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- } else if (tcpModel.action == VoiceAction::REJECT){
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::REJECT);
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- }
- } else if (tcpModel.action == VoiceAction::CANCEL){
- //CallingStatus::instance()->setTcpModel(tcpModel);
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::CANCEL);
- }
- } else if (tcpModel.action == VoiceAction::CALLING){
- //CallingStatus::instance()->setTcpModel(tcpModel);
- //对方忙线
- callActivityFinish(CallFinishType::BUSY);
- } else if (tcpModel.action == VoiceAction::CALL){
- //我方忙线判断
- if (CallingStatus::instance()->busy()){
- sendVoiceTcp(VoiceAction::CALLING, tcpModel, tcpModel.from_id);
- } else {
- CallingStatus::instance()->setTcpModel(tcpModel);
- //来电话了
- Intent* intent = new Intent();
- intent->putExtra(isOutgoing, "false");
- intent->putExtra(audioOnly, "true");
- 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.type == TcpType::SOS) {
- if (tcpModel.action == SosAction::CANCEL) {
- // SOS还原成无灯光的状态
- // std::string heartStr = "ULED,0F";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- lightControl("ULED", "0F");
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- 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");
- // std::string heartStr;
- // if (color != "" && color.size() == 3) {
- // heartStr = "DOORLED," + color + "F";
- // } else {
- // heartStr = "DOORLED,010F";
- // }
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- 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
- // std::string heartStr = "DOORLED,000F";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- lightControl("DOORLED", "000F");
- }
- else if (tcpModel.action == SideAction::CALL) {
- // 收到CALL,需要亮红灯
- // std::string heartStr = "DOORLED,200F"; // 红灯闪烁
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- lightControl("DOORLED", "200F");
- int deviceId = tcpModel.from_id;
- string fromFrameFullName = tcpModel.json["fromFrameFullName"].asString();
- setPainterInfo(deviceId, 0xFF2F9DF1, fromFrameFullName + " " + LANGUAGEMANAGER->getValue("CallInfo"), "VOICE", "ADD", 60);
- }
- else if (tcpModel.action == SideAction::ACCEPT) {
- // 先处理painterInfoList里的数据
- int deviceId = tcpModel.to_id;
- setPainterInfo(deviceId, 0xFFFFFFFF, "", "VOICE", "DELETE", 0);
- // 获取painterInfoList
- Json::Value _painterInfoList = getPainterInfoList();
- if (_painterInfoList.size() > 0) { // 如果painterInfoList.size > 0
- // 如果列表里还有VOICE,就不修改门灯,直接结束
- for (int i = 0; i < _painterInfoList.size(); i++) {
- if (_painterInfoList[i]["type"] == "VOICE") {
- return;
- }
- }
- }
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- }
- else if (tcpModel.action == SideAction::CANCEL) {
- int deviceId = tcpModel.from_id;
- if (tcpModel.json.size() != 0) {
- deviceId = tcpModel.json["fromDeviceId"].asInt();
- }
- setPainterInfo(deviceId, 0xFFFFFFFF, "", "VOICE", "DELETE", 0);
- // 获取painterInfoList
- Json::Value _painterInfoList = getPainterInfoList();
- if (_painterInfoList.size() > 0) { // 如果painterInfoList.size > 0
- // 如果列表里还有VOICE,就不修改门灯,直接结束
- for (int i = 0; i < _painterInfoList.size(); i++) {
- if (_painterInfoList[i]["type"] == "VOICE") {
- return;
- }
- }
- }
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- }
- else if (tcpModel.action == SideAction::SOS_CALL) {
- // 收到SOS_CALL,需要亮红灯
- // SOS亮红灯
- // string heartStr = "ULED,1F";
- // 门灯亮红灯
- // std::string heartStr2 = "DOORLED,200F";
- // const char* sendMsg2 = heartStr2.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg2), strlen(sendMsg2));
- lightControl("DOORLED", "200F");
- sosTimerRegistered = false;
- mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
- mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
- int deviceId = tcpModel.from_id;
- string fromFrameFullName = tcpModel.json["fromFrameFullName"].asString();
- setPainterInfo(deviceId, 0xFFFF0000, fromFrameFullName + " " + LANGUAGEMANAGER->getValue("SOSCallInfo"), "SOS", "ADD", 120);
- }
- else if (tcpModel.action == SideAction::SOS_CANCEL) {
- int deviceId = tcpModel.to_id;
- setPainterInfo(deviceId, 0xFFFFFFFF, "", "SOS", "DELETE", 0);
- // 获取painterInfoList
- Json::Value _painterInfoList = getPainterInfoList();
- if (_painterInfoList.size() > 0) { // 如果painterInfoList.size > 0
- // 如果列表里还有VOICE,就不修改门灯,直接结束
- for (int i = 0; i < _painterInfoList.size(); i++) {
- if (_painterInfoList[i]["type"] == "SOS") {
- return;
- }
- }
- }
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- }
- }
- 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) {
- //回调
- TcpCallback callback = TcpCacheManager::instance()->getFunc(tcpModel.tid);
- if (callback.tid != "0"){
- callback.onFalied(tcpModel.json);
- }
- if (tcpModel.tid == callTid){
- callActivityFinish(CallFinishType::FAILED);
- }
- }
- }
- }
- 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;
- }
- //================================= 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(isOutgoing, "true");
- intent->putExtra(audioOnly, "true");
- 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(){
- //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信令
- GetTelephone()->AddCallStateListener(OnCallStateChanged);
- //开启网页
- httpServer.RunAsync(HTTP_SERVER_PORT);
- // 启动的时候更改为tcp模式
- StoragePreferences::putString(STORE_SIGNAL_TYPE, "TCP");
- //请求版本号
- // 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 (data.state!=""){
- LOGD("state = %s",data.state.c_str());
- }
- // if (data.msg != ""){
- // LOGD("msg = %s", data.msg.c_str());
- // }
- if(UartContext::Uart3IsOpen()) { // 如果是true,表示串口打开了
- string heartStr;
- //按下
- if (data.state=="0"){ // 0表示正被按下,1表示短按松开,2表示长按松开。
- if (data.cmd == "KEY5") { // key5是面板拨号按钮
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- if (isSleep) {
- scrrenOn();
- }
- else {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- } else {
- Intent* intent = new Intent();
- intent->putExtra(isOutgoing, "true");
- intent->putExtra(audioOnly, "true");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- else {
- scrrenOn();
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- } else {
- Intent* intent = new Intent();
- intent->putExtra(isOutgoing, "true");
- intent->putExtra(audioOnly, "true");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- else if (data.cmd == "KEY6"){ // key6是手柄触发,手柄只有呼叫和挂断功能,没有取消功能,防止用户不停地按
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- if (isSleep) {
- scrrenOn();
- }
- else {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::KEY6_CLICK);
- } else {
- Intent* intent = new Intent();
- intent->putExtra(isOutgoing, "true");
- intent->putExtra(audioOnly, "true");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- else {
- scrrenOn();
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::KEY6_CLICK);
- } else {
- Intent* intent = new Intent();
- intent->putExtra(isOutgoing, "true");
- intent->putExtra(audioOnly, "true");
- EASYUICONTEXT->openActivity("callActivity", intent);
- }
- }
- }
- else if (data.cmd == "KEY7"){ // key7是紧急按钮
- if (isSleep) {
- scrrenOn();
- }
- if (sosTimerRegistered) {
- LOGD("TCP -> SOS_CALL");
- TcpModel tcpModel;
- tcpModel.type = TcpType::SOS;
- tcpModel.action = SosAction::CALL;
- tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID, 0);
- tcpModel.tid = base::format("t%d",TimeHelper::getCurrentTime());
- std::string req = getTcpModelString(tcpModel);
- LOGD("TCP SOS_CALL : %s",req.c_str());
- TcpClient::instance()->sendMsg(req.c_str());
- // SOS亮红灯
- // heartStr = "ULED,1F";
- lightControl("ULED", "1F");
- // 门灯亮红灯
- // std::string heartStr2 = "DOORLED,200F";
- // const char* sendMsg2 = heartStr2.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg2), strlen(sendMsg2));
- lightControl("DOORLED", "200F");
- mActivityPtr->registerUserTimer(SOS_CLICK_TIME_HANDLE, 10000); // 10秒后才能触发
- mActivityPtr->registerUserTimer(SOS_LAMP_TIME_HANDLE, 120000); // 2分钟后才能触发
- }
- }
- else if (data.cmd == "KEY<") { //下左3,红
- if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP") {
- setCheckbox("KEY<");
- return;
- }
- if (isSleep) {
- scrrenOn();
- }
- // heartStr = "DOORLED,000F";
- }
- else if (data.cmd == "KEY>") { // key>是面板挂断按钮
- if (!StoragePreferences::getInt(STORE_SCREEN_LIGHT, 0)) {
- if (isSleep) {
- scrrenOn();
- }
- else {
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- // heartStr = "DOORLED,000F";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- lightControl("DOORLED", "000F");
- }
- }
- }
- else {
- scrrenOn();
- voip::CallInfo info = GetTelephone()->GetCallInfo();
- //拨打 或 挂断
- if (CallingStatus::instance()->busy()){
- callActivityFinish(CallFinishType::A1CLICK);
- // heartStr = "DOORLED,000F";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- lightControl("DOORLED", "000F");
- }
- }
- }
- else if (data.cmd == "KEY;"){ //下左4,白
- if (isSleep) {
- scrrenOn();
- }
- // heartStr = "DOORLED,111F";
- lightControl("DOORLED", "111F");
- }
- else {
- if (isSleep) {
- scrrenOn();
- }
- // heartStr = "DOORLED,000F";
- lightControl("DOORLED", "000F");
- }
- // 发送给板子的指令
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- }
- }
- }
- /**
- * 定时器触发函数
- * 不建议在此函数中写耗时操作,否则将影响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 HELP_TIMER_HANDLE:
- // {
- // SetPainterInfo(0xFFFFFFFF,"");
- // setHelpButton("/button/button_help2.png", true);
- // setReinforce(false); // 设置增援状态为false
- //// //取消计时
- //// if (isHelpTimerRegistered) {
- //// mActivityPtr->unregisterUserTimer(HELP_TIMER_HANDLE);
- //// isHelpTimerRegistered = false;
- //// }
- // return false;
- // }
- // break;
- case SOS_CLICK_TIME_HANDLE: {
- sosTimerRegistered = true;
- return false;
- }
- break;
- case SOS_LAMP_TIME_HANDLE: {
- // SOS还原成无灯光的状态
- // std::string heartStr = "ULED,0F";
- // const char* sendMsg = heartStr.c_str();
- // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
- lightControl("ULED", "0F");
- // 进行门灯还原
- // doorLampRestoration();
- lightControl("DOORLED", "000F");
- return false;
- }
- break;
- case SLEEP_STRAT_TIME_HANDLE: { // 息屏
- if (isSleepTimerRegistered) {
- isSleep = true;
- BRIGHTNESSHELPER->screenOff();
- } else { // 如果是false的话,就需要关闭定时器
- isSleep = false;
- BRIGHTNESSHELPER->screenOn();
- }
- }
- 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;
- }
|