qt/LedOK/deviceitem.cpp

695 lines
32 KiB
C++
Raw Normal View History

2022-08-25 18:37:24 +08:00
#include "deviceitem.h"
#include "tools.h"
#include "passwordindlg.h"
#include "LoUIClass/x_uimsgboxok.h"
#include <QMessageBox>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <globaldefine.h>
#include <QSettings>
#include <cfg.h>
#include <QHttpMultiPart>
#include <QUuid>
#include "LoUIClass/updaterdialog.h"
#include <QBuffer>
#include "LoUIClass/pixbmpshowdialog.h"
#include <QThread>
#include <QTcpSocket>
#include <QHostAddress>
#include <QInputDialog>
DeviceItem::DeviceItem(LedCard *pLedCard, LoQTreeWidget *parent,QWidget *pWnd) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent){
m_pWnd=pWnd;
m_pLedCard=pLedCard;
pHpptClient = new HpptClient(this);
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(0, Qt::Unchecked);
m_parent->addTopLevelItem(this);
m_bnLock = new QPushButton();
m_bnCardDetailInfo = new QPushButton();
m_bnCardDetailInfo->setToolTip(tr("GetScreenDetailInfo"));
m_bnCardDetailInfo->setCursor(QCursor(Qt::PointingHandCursor));
m_bnCardDetailInfo->setStyleSheet(R"rrr(
QPushButton {
border-radius: 4px;
image: url(:/res/DeviceManager/bnDetail.png);
}
QPushButton:hover{background-color: #cccccc;}
)rrr");
connect(m_bnCardDetailInfo, &QPushButton::clicked, this, [this]{
QString strTip="";
strTip.append(tr("cur brightness:")).append(QString::number(m_pLedCard->brightness)).append("\r\n");
//strTip.append("cardsystem apk version:"+QString::number(m_LedCard.iCardSystemVersion)+"\r\n");
//strTip.append("device apk:"+m_LedCard.starterversionName+"\r\n");
strTip.append(tr("android version:")).append(m_pLedCard->androidVersion).append("\r\n");
//strTip.append(tr("android width:")+QString::number(m_LedCard.androidWidth)+"\r\n");
//strTip.append(tr("android height:")+QString::number(m_LedCard.androidHeight)+"\r\n");
strTip.append(tr("IMEI:")).append(m_pLedCard->strIMEI).append("\r\n");
strTip.append(tr("HardWard Version:")).append(m_pLedCard->HardVersion).append("\r\n");
strTip.append(tr("MAX Brightness level:")).append(QString::number(m_pLedCard->BrightnessLevel)).append("\r\n");
strTip.append(tr("Android OS Resolution:")).append(m_pLedCard->ScreenResolution).append("\r\n");
strTip.append(tr("Firmware Version:")).append(m_pLedCard->FirmwareVersion).append("\r\n");
strTip.append(tr("Player Version:")).append(m_pLedCard->strXixunplayerVersion).append("\r\n");
QMessageBox::information(gMainWin, tr("Detail Info"), strTip);
});
m_bnReadbackPic = new QPushButton();
m_bnReadbackPic->setToolTip(tr("ReadbackPic"));
m_bnReadbackPic->setCursor(QCursor(Qt::PointingHandCursor));
m_bnReadbackPic->setStyleSheet(R"rrr(
QPushButton {
border-radius: 4px;
image: url(:/res/DeviceManager/deviceReadbackPic.png);
}
QPushButton:hover{background-color: #cccccc;}
)rrr");
connect(m_bnReadbackPic, SIGNAL(clicked()), this, SLOT(onReadbackPic()));
m_ImageOnline = new QLabel();
m_pLedCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png"));
setData(DeviceTable_ID, 0, m_pLedCard->m_strCardId);
setData(DeviceTable_IP, 0, m_pLedCard->m_strCardIp);
setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(m_pLedCard->m_iWidth).arg(m_pLedCard->m_iHeight));
m_parent->setItemWidget(this, DeviceTable_Info, m_bnCardDetailInfo);
m_parent->setItemWidget(this, DeviceTable_Screenshot, m_bnReadbackPic);
m_parent->setItemWidget(this, DeviceTable_Online, m_ImageOnline);
m_ImageOnline->setAlignment(Qt::AlignCenter);
SetPasswordItem(m_pLedCard);
for(int i=1; i<DeviceTable_Screenshot; i++) setTextAlignment(i, Qt::AlignCenter);
//启动心跳监测设备在线和下线3次超时表示下线
DeviceItemHttpPost();
connect(&mHeartbeatTimer, &QTimer::timeout, this, [this] {
m_HeartbeatCount++;
QJsonObject json4;
json4.insert("_id", getRandomString(10));
json4.insert("_type", "GetCardName");
HttpPostByTypeJsonObject(json4);
if(m_HeartbeatCount>10) {
//下线
m_pLedCard->m_bOnLine=false;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Offline.png"));
} else {
//在线
m_pLedCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png"));
}
});
mHeartbeatTimer.start(60000);
connect(m_bnLock, SIGNAL(clicked()), this, SLOT(onVerifyLockPassword()));
m_pGetAskTimer=new QTimer(this);
connect(pHpptClient,SIGNAL(httpPostRspReady(QString , QString , QByteArray)),this,SLOT(OnProHttpResponse(QString , QString , QByteArray)));
//连接item的响应信号到信息输出框的显示槽函数
connect(this,SIGNAL(sigOutputInfo(QString)),parent->parent(),SLOT(OnOutputInfo(QString)));
}
DeviceItem::~DeviceItem() {
mHeartbeatTimer.stop();
if(pHpptClient) {
delete pHpptClient;
pHpptClient=nullptr;
}
}
void DeviceItem::SetMainTabWidgetIndex(int index){
m_intIndexFlagOfInfoOrControl=index;
DeviceItemHttpPost();
}
//针对这个ITEM通过POST获取控制卡的信息两种情况下会调用创建该Item初始化后二、手动刷新
void DeviceItem::DeviceItemHttpPost() {
if(m_intIndexFlagOfInfoOrControl!=MainPage_DeviceManager) return;
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetScreenSize");
HttpPostByTypeJsonObject(json);
QJsonObject json1;
json1.insert("_id", getRandomString(10));
json1.insert("_type", "GetBrightness");
HttpPostByTypeJsonObject(json1);
QJsonObject json2;
json2.insert("_id", getRandomString(10));
json2.insert("_type", "IsScreenOn");
HttpPostByTypeJsonObject(json2);
QJsonObject json4;
json4.insert("_id", getRandomString(10));
json4.insert("_type", "GetBuildInformation");
HttpPostByTypeJsonObject(json4);
QJsonObject json5;
json5.insert("_id", getRandomString(10));
json5.insert("_type", "CheckSoftVersions");
HttpPostByTypeJsonObject(json5);
QJsonObject json3;
json3.insert("_id", getRandomString(10));
json3.insert("_type", "HasControllerPassword");
HttpPostByTypeJsonObject(json3);
QJsonObject json8;
json8.insert("_id", getRandomString(10));
json8.insert("_type", "GetCardAlias");
HttpPostByTypeJsonObject(json8);
}
void DeviceItem::OnControlTcpSend(int iProgramIndex) {
QTcpSocket *send = new QTcpSocket();
connect(send, SIGNAL(connected()), this, SLOT(connect_sucessful()));
connect(send, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(show_error(QAbstractSocket::SocketError)));
send->connectToHost(QHostAddress(m_pLedCard->m_strCardIp),31299);
ST_ANSY_PROGRAM_PACKET tempStreadPakcet;
tempStreadPakcet.SyncHead[0]=0x7e;
tempStreadPakcet.SyncHead[1]=0x7e;
tempStreadPakcet.SyncHead[2]=0x55;
tempStreadPakcet.ucCommType=0x97;
tempStreadPakcet.iBaoLiu=0;
tempStreadPakcet.iLength=4;
unsigned char uctemp[4]={0};
uctemp[0]=iProgramIndex;
memcpy(tempStreadPakcet.pDataBuffer,uctemp,4);
tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength]=GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength));
int iLenPacket=3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小;
QByteArray databuf = QByteArray(reinterpret_cast<char*>(&tempStreadPakcet), iLenPacket);
if(!send->waitForConnected(10000)) //等待连接返回
{
qDebug()<<m_pLedCard->m_strCardIp<<"Connect timeout ";
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("Connect")+":"+tr("timeout"));
send->close();
delete send;
return ;
}
send->write(databuf);
if(send->waitForBytesWritten(3000))
{
send->read(send->bytesAvailable());
qDebug()<<"recv anycast success ack";
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("Anycast")+":"+tr("success"));
}
send->close();
delete send;
}
void DeviceItem::HttpPostByTypeJsonObject(QJsonObject json)
{
QJsonDocument doc;
doc.setObject(json);
QByteArray post_loginArray = doc.toJson(QJsonDocument::Compact);
m_strUrl="http://"+m_pLedCard->m_strCardIp+":2016/settings";
if(m_pLedCard->m_strCardId.left(2)!="M8"&&m_pLedCard->m_strCardId.left(2)!="m8")
{
if(json["_type"]=="GetAllScreenSizeM80"||json["_type"]=="SetSpecialResolution"||json["_type"]=="GetSpecialResolution"||json["_type"]=="CleanDisplayScreenSize")
{
// pHpptClient->httpPost(m_strUrl,post_loginArray);
}
else {
pHpptClient->httpPost(m_strUrl,post_loginArray);
}
}
else
{
pHpptClient->httpPost(m_strUrl,post_loginArray);
}
}
void DeviceItem::HttpGetLedCardWidthHeight()
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetScreenSize");
HttpPostByTypeJsonObject(json);
}
void DeviceItem::HttpGetLedCardRemarkName(){
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetCardAlias");
HttpPostByTypeJsonObject(json);
}
void DeviceItem::refreshLable(){
if(m_pLedCard->m_bPowerStatus){
this->setForeground(DeviceTable_Power, Qt::green);
setData(DeviceTable_Power, 0, tr("on"));
} else {
this->setForeground(DeviceTable_Power, Qt::red);
setData(DeviceTable_Power, 0, tr("off"));
}
}
void DeviceItem::onVerifyLockPassword() {
bool ok;
auto pwd = QInputDialog::getText(gMainWin, tr("Input password"), tr("Input password"), QLineEdit::Password, QString(), &ok);
if(ok) {
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "VerifyPassword");
json.insert("pwd", pwd);
HttpPostByTypeJsonObject(json);
}
}
void DeviceItem::onReadbackPic() {
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetScreenshotFull");
HttpPostByTypeJsonObject(json);
if(m_PostingDlg==nullptr)
{
m_PostingDlg = new LoEmptyDialog(m_pWnd);
connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg()));
connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock()));
m_PostingDlg->lock(tr("GetScreenshotFull"),tr("Success"),tr("GetScreenshotFull")+tr("failed"));
m_pGetAskTimer->start(20000);
m_PostingDlg->exec();
}
}
void DeviceItem::SetPasswordItem(LedCard *p){
if(p->bPassword) {//加过密
if(p->m_bLockStatus) m_bnLock->setIcon(QIcon(":/res/DeviceManager/Lock.png")); //如果已经验证通过密码显示绿色图标
else m_bnLock->setIcon(QIcon(":/res/DeviceManager/UnLock.png")); //如果没有验证显示蓝色锁图标
m_parent->setItemWidget(this, DeviceTable_Password, m_bnLock);
} else m_bnLock->setIcon(QIcon(":/res/DeviceManager/Transparent.png")); //显示空白
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void DeviceItem::OnProHttpResponse(QString url, QString postMD5, QByteArray data) {
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
// qDebug()<<"POST";
//qDebug()<<postMD5;
//qDebug()<<data;
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误";
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
//alahover 20200521 qDebug()<<m_pLedCard->m_strCardId +"---------"+ strType;
if(strType=="GetScreenSize" )
{
if(m_pLedCard->m_iWidth!=jsonObject["width"].toInt()||m_pLedCard->m_iHeight!=jsonObject["height"].toInt())
{
m_pLedCard->m_iWidth=jsonObject["width"].toInt();
m_pLedCard->m_iHeight=jsonObject["height"].toInt();
}
setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(m_pLedCard->m_iWidth).arg(m_pLedCard->m_iHeight));
}
else if(strType=="GetCardAlias" )
{
m_pLedCard->m_strCardRemarkName = QString::fromUtf8(QByteArray::fromBase64(jsonObject["alias"].toString().toLatin1()));
setData(DeviceTable_Remark,0,m_pLedCard->m_strCardRemarkName);
}
else if(strType=="GetCardName")
{
m_HeartbeatCount=0;
m_pLedCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png"));
}
else if(strType=="GetBuildInformation" )
{
m_pLedCard->strIMEI=jsonObject["IMEI"].toString();
m_pLedCard->HardVersion=jsonObject["HardVersion"].toString();
m_pLedCard->BrightnessLevel=jsonObject["BrightnessLevel"].toInt();
m_pLedCard->ScreenResolution=jsonObject["ScreenResolution"].toString();
m_pLedCard->FirmwareVersion=jsonObject["FirmwareVersion"].toString();
//if(m_pLedCard->CompareHTTPPostParam()==false)
}
else if(strType=="CheckSoftVersions" )
{
foreach(QJsonValue value, jsonObject["apps"].toArray()) {
QJsonObject oApp = value.toObject();
if(oApp["packageName"].toString().contains("xixunplayer"))
{
m_pLedCard->strXixunplayerVersion=oApp["versionName"].toString();
m_pLedCard->strXixunplayerVersionCode=oApp["versionCode"].toInt();
}
}
}
else if(strType == "HasControllerPassword")
{
//if(m_pLedCard->bPassword!=jsonObject["result"].toBool())
{
m_pLedCard->bPassword=jsonObject["result"].toBool();
SetPasswordItem(m_pLedCard);
}
}
else if(strType == "SetScreenOn")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetScreenOn")+":"+tr("success"));
}
else if(strType == "AliIotSetting")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("AliIotSetting")+":"+tr("success"));
}
else if(strType == "IsScreenOn")
{
//if(m_pLedCard->m_bPowerStatus!=jsonObject["on"].toBool())
{
m_pLedCard->m_bPowerStatus=jsonObject["on"].toBool();
if(m_pLedCard->m_bPowerStatus) {
this->setForeground(DeviceTable_Power, Qt::green);
setData(DeviceTable_Power, 0, tr("on"));
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetScreenStatus")+tr("success")+","+tr("Status")+":"+tr("on"));
} else {
this->setForeground(DeviceTable_Power, Qt::red);
setData(DeviceTable_Power, 0, tr("off"));
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetScreenStatus")+tr("success")+","+tr("Status")+":"+tr("off"));
}
}
}
else if(strType == "VerifyPassword")
{
bool bStatus=jsonObject["result"].toBool();
if(bStatus)//解密成功
{
qDebug()<<"解密成功";
m_pLedCard->m_bLockStatus=false;
}
else
{
qDebug()<<"解密失败";
X_UIMsgBoxOk *mb = new X_UIMsgBoxOk(tr("Tip Info"),tr("password is wrong"), m_pWnd,0);
mb->exec();
m_pLedCard->m_bLockStatus=true;
}
SetPasswordItem(m_pLedCard);
} else if(strType == "GetBrightness") {
m_pLedCard->brightness = jsonObject["brightness"].toInt();
QString bright = QString::number(m_pLedCard->brightness);
setData(DeviceTable_Brightness, 0, QString::number(m_pLedCard->brightness*100/m_pLedCard->BrightnessLevel)+"% ("+bright+")");
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetBrightness")+tr("success")+","+tr("brightness")+"="+bright);
}
else if(strType == "IsMasterSlave")
{
if(jsonObject["result"].toBool())
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("Lora identity")+":"+tr("Master"));
}
else
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("Lora identity")+":"+tr("Slave"));
}
}
else if(strType == "MasterSlaveSwitch")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("MasterSlaveSwitch")+":"+tr("success"));
}
else if(strType == "SetBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetBrightness")+":"+tr("success"));
}
else if(strType == "SetBrightnessSensitivity")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetBrightnessSensitivity")+tr("success"));
}
else if(strType == "SetMinBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetMinBrightness")+":"+tr("success"));
}
else if(strType == "GetBrightnessSensitivity")
{
int iTemp=jsonObject["sensitivity"].toInt();
QString strSensitivity=QString::number(iTemp);
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetBrightnessSensitivity")+tr("success")+","+tr("sensitivity")+"="+strSensitivity);
}
else if(strType == "GetMinBrightness")
{
int iTemp=jsonObject["brightness"].toInt();
QString strMinBrightness=QString::number(iTemp);
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetMinBrightness")+tr("success")+","+tr("brightness")+"="+strMinBrightness);
}
else if(strType == "SensorBrightnessTable")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetSensorBrightnessTable")+":"+tr("success"));
}
else if(strType == "SetSwitchWiFi")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetSwitchWiFi")+":"+tr("success"));
}
else if(strType == "ConfigurationWiFi")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("ConfigurationWiFi")+":"+tr("success"));
}
else if(strType == "ConfigurationHotSpot")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("ConfigurationHotSpot")+":"+tr("success"));
}
else if(strType == "GetSwitchWiFi")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetSwitchWiFi")+":"+tr("success"));
}
else if(strType == "SetAutoBrightnessTask")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetAutoBrightnessTask")+":"+tr("success"));
}
else if(strType == "SetAutoVolumeTask")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetAutoVolumeTask")+":"+tr("success"));
}
else if(strType == "SetVolume")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetVolume")+":"+tr("success"));
}
else if(strType == "GetVolume")
{
int itempVolume=jsonObject["volume"].toInt();
QString strCurVolume=QString::number(itempVolume);
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetVolume")+":"+tr("success")+","+tr("volume")+"="+strCurVolume);
}
else if(strType == "SetTimingScreenTask")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetTimingScreenTask")+":"+tr("success"));
}
else if(strType == "GetControllerDate")
{
QString strDate=jsonObject["date"].toString();
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetControllerDate")+":"+strDate);
}
else if(strType == "SetHighForBusy")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetHighForBusy")+":"+tr("success"));
}
else if(strType == "GetStateForBusy")
{
if(jsonObject["result"].toInt()==0)
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetStateForBusy")+":"+tr("Service:Low Out of service:High"));
else
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetStateForBusy")+":"+tr("Service:High Out of service:Low"));
}
else if(strType =="UpgradeSoftware")
{
qDebug()<<"slotUploadFinished success ack";
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
else if(strType == "IsPortableHotSpot")
{
QString strWifi=jsonObject["wifi"].toString();
if(!strWifi.isEmpty())
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("IsPortableHotSpot")+":"+tr("success")+","+tr("WifiName")+":"+strWifi);
QString strAp=jsonObject["hotSpots"].toString();
if(!strAp.isEmpty())
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("IsPortableHotSpot")+":"+tr("success")+","+tr("ApName")+":"+strAp);
if(strWifi.isEmpty()&&strAp.isEmpty())
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("IsPortableHotSpot")+":"+tr("success"));
}
else if(strType == "TestScreen")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("TestScreen")+":"+tr("success"));
}
else if(strType == "SetOnlineAddr")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetOnlineAddr")+":"+tr("success"));
}
else if(strType == "SetRealtimeServer")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetRealtimeServer")+":"+tr("success"));
}
else if(strType == "GetOnlineAddr")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetOnlineAddr")+":"+jsonObject["server"].toString()+" ID:"+jsonObject["companuID"].toString());
}
else if(strType == "GetRealtimeServer")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetRealtimeServer")+":"+jsonObject["server"].toString());
}
else if(strType == "SetNtpServer") emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetNtpServer")+":"+tr("success"));
else if(strType == "GetNtpServer") emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetNtpServer")+":"+jsonObject["ntpServer"].toString());
else if(strType == "SetLanguage") emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-设置语言: "+tr("success"));
else if(strType == "GetLanguage") emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-获取语言: "+(jsonObject["language"].toInt()==1?"中文":"英文"));
else if(strType == "SyncTime")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SyncTime")+":"+tr("success"));
}
else if(strType == "DelPrograms")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("DelPrograms")+":"+tr("success"));
}
else if(strType == "SetingSyncMethod")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetingSyncMethod")+":"+tr("success"));
}
else if(strType == "GetCurrentSensorBrightness")
{
bool b485=jsonObject["is485"].toBool();
QString strSensorType="RL1";
if(b485)
{
strSensorType="R60";
}
else {
strSensorType= "RL1";
}
int iTempValue=jsonObject["value"].toInt();
QString strSensorValue=QString::number(iTempValue);
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetCurrentSensorBrightness")+":"+strSensorType+","+tr("Cur brightness")+":"+strSensorValue);
}
else if(strType == "SetSpecialResolution")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetSpecialResolution")+":"+tr("success"));
}
else if(strType == "GetSpecialResolution")
{
QString strTotalResolution = jsonObject["totalResolution"].toString();
QString strCurDisplayResolution = jsonObject["displayResolution"].toString();
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetSpecialResolution")+":"+tr("totalResolution")+"["+strTotalResolution+"],"+tr("strCurDisplayResolution")+"["+strCurDisplayResolution+"]");
}
else if(strType == "CleanDisplayScreenSize")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("CleanDisplayScreenSize")+":"+tr("success"));
}
else if(strType == "SetMinBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetMinBrightness")+":"+tr("success"));
}
else if(strType == "SetMaxBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetMaxBrightness")+":"+tr("success"));
}
else if(strType == "GetMaxBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetMaxBrightness")+":"+QString::number(jsonObject["brightness"].toInt()));
}
else if(strType == "GetingSyncMethod") {
QString strOtherSyncItem = tr("screenSwitch") + ":" + (jsonObject["screenSwitch"].toBool() ? tr("YES") : tr("NO"))
+ " " + tr("volume") + ":" + (jsonObject["volume"].toBool() ? tr("YES") : tr("NO"))
+ " " + tr("brightness") + ":" + (jsonObject["brightness"].toBool() ? tr("YES") : tr("NO"));
QString lastSynchronousTime = QDateTime::fromMSecsSinceEpoch(jsonObject["lastSynchronousTime"].toDouble()).toString("yyyy-MM-dd HH:mm:ss");
QString time = jsonObject["time"].toString();
QString lower = time.toLower();
if(lower=="serial") {
QString strOut = m_pLedCard->m_strCardId+": "+tr("receive")+"<-"+tr("GetingSyncMethod")+": Lora\r\n "
+tr("identificationCode")+": "+jsonObject["identificationCode"].toString()+"\r\n "
+tr("delaySync")+": "+QString::number(jsonObject["delaySync"].toInt())+tr("msec")+"\r\n "
+tr("OtherSyncItem")+": "+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+": "+lastSynchronousTime;
emit sigOutputInfo(strOut);
} else if(lower=="ntp") {
QString strOut = m_pLedCard->m_strCardId+": "+tr("receive")+"<-"+tr("GetingSyncMethod")+": "+time+"\r\n "
+tr("checkNtpTime")+": "+QString::number(jsonObject["checkNtpTime"].toInt())+"\r\n "
+tr("OtherSyncItem")+": "+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+": "+lastSynchronousTime;
emit sigOutputInfo(strOut);
} else if(lower=="gps") {
QString strOut=m_pLedCard->m_strCardId+": "+tr("receive")+"<-"+tr("GetingSyncMethod")+": "+time+"\r\n "
+tr("OtherSyncItem")+": "+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+": "+lastSynchronousTime;
emit sigOutputInfo(strOut);
} else if(lower=="lan") {
QString strOut=m_pLedCard->m_strCardId+": "+tr("receive")+"<-"+tr("GetingSyncMethod")+": "+tr("LAN")+"\r\n "
+tr("identificationCode")+": "+jsonObject["identificationCode"].toString()+"\r\n "
+tr("delaySync")+": "+QString::number(jsonObject["delaySync"].toInt())+tr("msec")+"\r\n "
+tr("OtherSyncItem")+": "+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+": "+lastSynchronousTime;
emit sigOutputInfo(strOut);
} else {
QString strOut = m_pLedCard->m_strCardId+": "+tr("receive")+"<-"+tr("GetingSyncMethod")+": "+time+"\r\n "+data;
emit sigOutputInfo(strOut);
}
} else if(strType == "GetScreenshotFull") {
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
qDebug()<<"GetScreenshotFull";
QString iTemp=jsonObject["data"].toString();
QByteArray byte_array =iTemp.toLatin1();
QByteArray Ret_bytearray = QByteArray::fromBase64(byte_array);
//QBuffer buffer(&Ret_bytearray);
//buffer.open(QIODevice::WriteOnly);
//QPixmap imageresult;
//imageresult.loadFromData(Ret_bytearray);
PixbmpShowDialog *dlg=new PixbmpShowDialog(m_pWnd);
dlg->m_PixMap.loadFromData(Ret_bytearray);
dlg->ResizeByPixmap(m_pLedCard->m_iWidth,m_pLedCard->m_iHeight);
dlg->exec();
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetingSyncMethod")+":"+tr("success"));
}
} else {//失败应答,打印失败和错误信息
if(strType == "UpgradeSoftware") {
qDebug()<<"slotUploadFinished failed ack";
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
emit sigOutputInfo(m_pLedCard->m_strCardId+"<-"+strType+":failed,error:"+jsonObject["error"].toString());
}
}
}
QPixmap DeviceItem::Base64_To_Image(QByteArray bytearray,QString SavePath)
{
QByteArray Ret_bytearray;
Ret_bytearray = QByteArray::fromBase64(bytearray);
QBuffer buffer(&Ret_bytearray);
buffer.open(QIODevice::WriteOnly);
QPixmap imageresult;
imageresult.loadFromData(Ret_bytearray);
if(SavePath != "")
{
qDebug() <<"save" ;
imageresult.save(SavePath);
}
return imageresult;
}
void DeviceItem::slotUploadProgress(qint64 A,qint64 B)
{
if(B!=0)
{
QString strbaifenbi=tr("Uploadding")+":"+QString("%1%").arg(A*100/B);
emit sigSetTipTextContent(strbaifenbi);
m_pGetAskTimer->stop();
m_pGetAskTimer->start(50000);
}
}
void DeviceItem::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}