qt/LedOK/wDevicesManager/wdevicesitem.cpp
2022-01-07 18:22:58 +08:00

1191 lines
48 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "wdevicesitem.h"
#include "loapptools.h"
#include "LoUIClass/x_uimsgboxok.h"
#include <QMessageBox>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <wDevicesManager/inputpassworddialog.h>
//#include <LoQClass/qexcel.h>
#include <globaldefine.h>
#include <QSettings>
#include <loappconfig.h>
#include <QHttpMultiPart>
#include <QUuid>
#include "LoUIClass/updaterdialog.h"
#include <QBuffer>
#include <QJsonDocument>
#include "LoUIClass/pixbmpshowdialog.h"
#include <QThread>
#include <QtXlsx/QtXlsx>
#include <QMessageBox>
#include <QTcpSocket>
#include <QHostAddress>
static const QString DEFS_FIRMWARE_URL = "https://www.ledok.cn/download/definitions/player.json";
static const QString strCurInstallApkVersion="10.9.9-8";
static const QString strCurInstallApkFileName="xixunplayer10.9.9-8.apk";
wDevicesItem::wDevicesItem(LedCard *pLedCard, LoQTreeWidget *parent,QWidget *pWnd) :
QObject(parent),
QTreeWidgetItem(UserType),
m_parent(parent)
{
qDebug() <<"wDevicesItem::wDevicesItem()";
m_pWnd=pWnd;
m_pLedCard=pLedCard;
pHpptClient = new HpptClient(this);
init();
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)));
}
wDevicesItem::~wDevicesItem()
{
if(m_HeartbeatTimer!=nullptr)
{
if(m_HeartbeatTimer->isActive())
m_HeartbeatTimer->stop();
m_HeartbeatTimer->deleteLater();
}
if(pHpptClient!=nullptr)
{
qDebug() <<"delete pHpptClient in ~wDevicesItem";
delete pHpptClient;
pHpptClient=nullptr;
}
// if(m_bnCardDetailInfo!=nullptr)
// {
// m_bnCardDetailInfo->deleteLater();
// m_bnCardDetailInfo=nullptr;
// }
// if(m_bnLock!=nullptr)
// m_bnLock->deleteLater();
// if(m_ImageOnline!=nullptr)
// m_ImageOnline->deleteLater();
}
void wDevicesItem::init()
{
qDebug() <<"wDevicesItem::init()";
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(0, Qt::Unchecked);
m_parent->addTopLevelItem(this);
m_bnLock = new QPushButton();
m_bnCardDetailInfo = new QPushButton();
m_bnReadbackPic = new QPushButton();
m_ImageOnline = new QLabel();
m_pLedCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png"));
ChangeHttpGetResponsePro(m_pLedCard);
SetDetailInfoItem(m_pLedCard);
SetPasswordItem(m_pLedCard);
for(int i=1; i<ENUM_DEVICEHEADE_PIC_READBACK; i++) {
setTextAlignment(i, Qt::AlignCenter);
}
//启动心跳监测设备在线和下线3次超时表示下线
DeviceItemHttpPost();
m_HeartbeatTimer = new QTimer(this);
connect(m_HeartbeatTimer,SIGNAL(timeout()),this,SLOT(onSendHeartbeat()));
m_HeartbeatTimer->start(200000);
connect(m_bnCardDetailInfo, SIGNAL(clicked()), this, SLOT(onGetCardDetailInfo()));
connect(m_bnReadbackPic, SIGNAL(clicked()), this, SLOT(onReadbackPic()));
connect(m_bnLock, SIGNAL(clicked()), this, SLOT(onVerifyLockPassword()));
}
void wDevicesItem::SetMainTabWidgetIndex(int index)
{
qDebug() <<"wDevicesItem::SetMainTabWidgetIndex()";
m_intIndexFlagOfInfoOrControl=index;
DeviceItemHttpPost();
}
//针对这个ITEM通过POST获取控制卡的信息两种情况下会调用创建该Item初始化后二、手动刷新
void wDevicesItem::DeviceItemHttpPost()
{
if(m_intIndexFlagOfInfoOrControl!=ENUM_MAIN_TOOL_DEVICESMANAGER)
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 wDevicesItem::onSendHeartbeat(){
m_HeartbeatCount++;
// qDebug()<< "m_HeartbeatCount="<<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"));
// qDebug()<< "offline m_HeartbeatCount="<<m_HeartbeatCount;
}
else
{
//在线
m_pLedCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png"));
// qDebug()<< "online m_HeartbeatCount="<<m_HeartbeatCount;
}
}
void wDevicesItem::OnControlTcpSend(int iProgramIndex)
{
SendAnycastCmd(m_pLedCard->m_strCardIp,iProgramIndex);
}
void wDevicesItem::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 wDevicesItem::HttpGetLedCardWidthHeight()
{
qDebug() <<"wDevicesItem::HttpGetLedCardWidthHeight()";
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetScreenSize");
HttpPostByTypeJsonObject(json);
}
void wDevicesItem::HttpGetLedCardRemarkName()
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetCardAlias");
HttpPostByTypeJsonObject(json);
}
void wDevicesItem::refreshLable()
{
qDebug() <<"wDevicesItem::refreshLable()";
if(m_pLedCard->m_bPowerStatus)
{
this->setTextColor(ENUM_DEVICEHEADE_POWER,Qt::green);
setData(ENUM_DEVICEHEADE_POWER, 0, tr("on"));
}
else
{
this->setTextColor(ENUM_DEVICEHEADE_POWER,Qt::red);
setData(ENUM_DEVICEHEADE_POWER, 0, tr("off"));
}
m_bnReadbackPic->setToolTip(tr("ReadbackPic"));
m_bnCardDetailInfo->setToolTip(tr("GetScreenDetailInfo"));
}
void wDevicesItem::onAttrChanged()
{
}
void wDevicesItem::onVerifyLockPassword()
{
InputPasswordDialog *pDlg=new InputPasswordDialog(m_parent,0);
connect(pDlg, SIGNAL(sigAcceptData(QString)), this, SLOT(onInputPasswordPro(QString)));
pDlg->setWindowModality(Qt::WindowModal);
pDlg->exec();
}
void wDevicesItem::onInputPasswordPro(QString strPassword)
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "VerifyPassword");
json.insert("pwd", strPassword);
HttpPostByTypeJsonObject(json);
}
bool wDevicesItem::compare (const QString& x, const QString& y)
{
qDebug() <<"wDevicesItem::compare()";
QStringList versionsX = x.split (".");
QStringList versionsY = y.split (".");
int count = qMin (versionsX.count(), versionsY.count());
for (int i = 0; i < count; ++i) {
int a = QString (versionsX.at (i)).toInt();
int b = QString (versionsY.at (i)).toInt();
if (a > b)
return true;
else if (b > a)
return false;
}
return versionsY.count() < versionsX.count();
}
void wDevicesItem::onReadbackPic()
{
qDebug() <<"wDevicesItem::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 wDevicesItem::onGetCardDetailInfo()
{
qDebug() <<"wDevicesItem::onGetCardDetailInfo()";
QString strTip="";
strTip.append(tr("cur brightness:")+QString::number(m_pLedCard->brightness)+"\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:")+m_pLedCard->androidVersion+"\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:")+m_pLedCard->strIMEI+"\r\n");
strTip.append(tr("HardWard Version:")+m_pLedCard->HardVersion+"\r\n");
strTip.append(tr("MAX Brightness level:")+QString::number(m_pLedCard->BrightnessLevel)+"\r\n");
strTip.append(tr("Android OS Resolution:")+m_pLedCard->ScreenResolution+"\r\n");
strTip.append(tr("Firmware Version:")+m_pLedCard->FirmwareVersion+"\r\n");
if(!m_pLedCard->strXixunplayerVersion.isEmpty())
{
strTip.append(tr("Player Version:")+m_pLedCard->strXixunplayerVersion+"\r\n");
LoAppConfig *cfg = LoAppConfig::getInstance();
QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
QString strCurApkVersion=settings->value(DEFS_FIRMWARE_URL).toString();
if(strCurApkVersion.isEmpty())
{
strCurApkVersion=strCurInstallApkVersion;
}
else {
if(compare(strCurApkVersion,strCurInstallApkVersion))
{
}
else
{
strCurApkVersion=strCurInstallApkVersion;
}
}
// settings->setValue("xixunplayer","G:/Dev/QT/LedOK-master/build-LedOK-Desktop_Qt_5_12_3_MinGW_32_bit-Debug/debug/Downloads/xixunplayer1042.apk");
QString strfilepath = settings->value("xixunplayer").toString();
if(strCurApkVersion!=m_pLedCard->strXixunplayerVersion && !strfilepath.isEmpty())
{
strTip.append("\r\n"+tr("you can click sync firmware button to lastest version")+":"+strCurApkVersion+"\r\n");
X_UIMsgBoxOk *mb = new X_UIMsgBoxOk(tr("Detail Info"),strTip, m_pWnd,2);
connect(mb, SIGNAL(signSyncFirmware()), this, SLOT(OnSyncFirmware()));
mb->exec();
}
else
{
if(!strfilepath.isEmpty())
{
strTip.append("\r\n"+tr("you can click sync firmware button to lastest version")+":"+strCurApkVersion+"\r\n");
X_UIMsgBoxOk *mb = new X_UIMsgBoxOk(tr("Detail Info"),strTip, m_pWnd,2);
connect(mb, SIGNAL(signSyncFirmware()), this, SLOT(OnSyncFirmware()));
mb->exec();
}
else {
X_UIMsgBoxOk *mb = new X_UIMsgBoxOk(tr("Detail Info"),strTip, m_pWnd,0);
mb->exec();
}
}
}
else {
strTip.append(tr("No install xixunplay apk firmware!"));
X_UIMsgBoxOk *mb = new X_UIMsgBoxOk(tr("Detail Info"),strTip, m_pWnd,3);
connect(mb, SIGNAL(signSyncFirmware()), this, SLOT(OnSyncFirmware()));
mb->exec();
}
// QMessageBox::information(NULL, "Title", strTip, QMessageBox::Yes , QMessageBox::Yes);
}
QString wDevicesItem::GetLedCardId()
{
return m_pLedCard->m_strCardId;
}
void wDevicesItem::OnStopAllItemPostHeartBeat(bool b)
{
qDebug() <<"wDevicesItem::OnStopAllItemPostHeartBeat()";
if(b)
{
m_HeartbeatTimer->start(5000);
}
else {
m_HeartbeatTimer->stop();
}
}
void wDevicesItem::onClearHeartbeatFlagByUdp()
{
// qDebug() <<"wDevicesItem::onClearHeartbeatFlagByUdp()";
m_HeartbeatCount=0;
if(m_ImageOnline!=nullptr)
{
m_pLedCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/DeviceManager/O_Online.png"));
}
}
//参数变化更新item控件内容
void wDevicesItem::ChangeHttpGetResponsePro(LedCard *p)
{
qDebug() <<"wDevicesItem::ChangeHttpGetResponsePro()";
// qDebug()<<"ChangeHttpGetResponsePro:m_HeartbeatCount="<<m_HeartbeatCount;
setData(ENUM_DEVICEHEADE_SCREEN_ID, 0, p->m_strCardId);
setData(ENUM_DEVICEHEADE_SCREEN_IP, 0, p->m_strCardIp);
setData(ENUM_DEVICEHEADE_SCREEN_SIZE, 0, QString("%1 x %2").arg(p->m_iWidth).arg(p->m_iHeight));
//setData(ENUM_DEVICEHEADE_REMARK_NAME, 0, p->m_strCardRemarkName);
}
void wDevicesItem::SetPasswordItem(LedCard *p)
{
qDebug()<<"p->bPassword:"<<p->bPassword;
qDebug()<<"p->m_bLockStatus:"<<p->m_bLockStatus;
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, ENUM_DEVICEHEADE_PASSWORD, m_bnLock);
}
else {
//显示空白
m_bnLock->setIcon(QIcon(":/res/DeviceManager/Transparent.png"));
}
}
void wDevicesItem::SetDetailInfoItem(LedCard *p)
{
qDebug() <<"wDevicesItem::SetDetailInfoItem()";
Q_UNUSED(p)
m_bnCardDetailInfo->setProperty("ssType", "deviceItemTool");
m_bnCardDetailInfo->setProperty("ssName", "deviceDetail");
m_bnCardDetailInfo->setCursor(QCursor(Qt::PointingHandCursor));
m_bnCardDetailInfo->setToolTip(tr("GetScreenDetailInfo"));
m_bnReadbackPic->setProperty("ssType", "deviceItemTool");
m_bnReadbackPic->setProperty("ssName", "deviceReadbackPic");
m_bnReadbackPic->setCursor(QCursor(Qt::PointingHandCursor));
m_bnReadbackPic->setToolTip(tr("ReadbackPic"));
m_parent->setItemWidget(this, ENUM_DEVICEHEADE_MORE_INFO, m_bnCardDetailInfo);
m_parent->setItemWidget(this, ENUM_DEVICEHEADE_PIC_READBACK, m_bnReadbackPic);
m_parent->setItemWidget(this, ENUM_DEVICEHEADE_ONLINE, m_ImageOnline);
m_ImageOnline->setAlignment(Qt::AlignCenter);
}
struct flyData
{
int iSensor[255];
};
Q_DECLARE_METATYPE(flyData);//重点
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
QString wDevicesItem::b64ToQs(QString b64qs1){//ok
QByteArray ba;
std::string stdStr = b64qs1.toStdString();//std::string
ba=QByteArray(stdStr.c_str() ); //QByteArray
ba=ba.fromBase64(ba); //unBase64
QString qs1=QString::fromUtf8(ba); //QString
return qs1;
}
void wDevicesItem::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()<<tr("wDevicesItem 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(ENUM_DEVICEHEADE_SCREEN_SIZE, 0, QString("%1 x %2").arg(m_pLedCard->m_iWidth).arg(m_pLedCard->m_iHeight));
}
else if(strType=="GetCardAlias" )
{
m_pLedCard->m_strCardRemarkName=b64ToQs(jsonObject["alias"].toString()); //QString
setData(ENUM_DEVICEHEADE_REMARK_NAME,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"));
//qDebug()<< "GetScreenSize online m_HeartbeatCount="<<m_HeartbeatCount;
}
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->setTextColor(ENUM_DEVICEHEADE_POWER,Qt::green);
setData(ENUM_DEVICEHEADE_POWER, 0, tr("on"));
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetScreenStatus")+tr("success")+","+tr("Status")+":"+tr("on"));
}
else
{
this->setTextColor(ENUM_DEVICEHEADE_POWER,Qt::red);
setData(ENUM_DEVICEHEADE_POWER, 0, tr("off"));
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetScreenStatus")+tr("success")+","+tr("Status")+":"+tr("off"));
}
}
}
else if(strType == "GetEthernet")
{
QString strDhcp="";
if(jsonObject["dhcp"].toBool())
{
strDhcp=tr("DHCP IP");
}
else {
strDhcp=tr("STATIC IP");
}
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+strDhcp+","+"IP:"+jsonObject["ipAddr"].toString()+" GateWay:"+jsonObject["gateWay"].toString()+" Mask:"+jsonObject["netMask"].toString()+" Dns:"+jsonObject["dnsAddr"].toString());
}
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")
{
//if(m_pLedCard->brightness!=jsonObject["brightness"].toInt())
{
m_pLedCard->brightness=jsonObject["brightness"].toInt();
setData(ENUM_DEVICEHEADE_BRIGHTNESS, 0, m_pLedCard->brightness);
QString strBrightness=QString::number(m_pLedCard->brightness);
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetBrightness")+tr("success")+","+tr("brightness")+"="+strBrightness);
}
}
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 == "SetScreenSize")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetScreenSize")+":"+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")
{
// ui->lineEditNtpServer->setText(jsonObject["ntpServer"].toString());
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetNtpServer")+":"+jsonObject["ntpServer"].toString());
}
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 == "GetMinBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetMinBrightness")+":"+QString::number(jsonObject["brightness"].toInt()));
}
else if(strType == "GetMaxBrightness")
{
emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetMaxBrightness")+":"+QString::number(jsonObject["brightness"].toInt()));
}
else if(strType == "GetingSyncMethod")
{
double dTime=jsonObject["lastSynchronousTime"].toDouble();
QDateTime tpast = QDateTime::fromMSecsSinceEpoch(dTime);
QString strLastSyncTime=tpast.toString("yyyy-MM-dd HH:mm:ss");
// QDateTime *dt=new QDateTime;
// int day =dTime/1;
// int secs =(dTime-day)*24*60*60/1;
// int msecs =((dTime-day)*24*60*60-secs)*1000;
// dt->setDate(QDate(1899,12,30));
// dt->setTime(QTime(0,0,0,0));
// *dt = dt->addDays(day);
// *dt = dt-> addSecs(secs);
// msecs=dTime*24*60*60*1000;
// *dt = dt->addMSecs(msecs);
// QString strLastSyncTime=dt->toString("yyyy-MM-dd hh:mm:ss");
QString strType=jsonObject["time"].toString();
QString strScreenSwtichBool="";
if(jsonObject["screenSwitch"].toBool())
strScreenSwtichBool=tr("screenSwitch")+":"+tr("YES");
else
strScreenSwtichBool=tr("screenSwitch")+":"+tr("NO");
QString strVolumeBool="";
if(jsonObject["volume"].toBool())
strVolumeBool=tr("volume")+":"+tr("YES");
else
strVolumeBool=tr("volume")+":"+tr("NO");
QString strBrightnessBool="";
if(jsonObject["brightness"].toBool())
strBrightnessBool=tr("brightness")+":"+tr("YES");
else
strBrightnessBool=tr("brightness")+":"+tr("NO");
QString strOtherSyncItem=strScreenSwtichBool+" "+strVolumeBool+" "+strBrightnessBool;
strType=strType.toLower();
if(strType=="serial")
{
strType="Lora";
QString stridentificationCode =jsonObject["identificationCode"].toString();
QString strtempdelaySync=QString::number(jsonObject["delaySync"].toInt());
QString strOut=m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetingSyncMethod")+":"+strType+"\r\n "
+tr("identificationCode")+":"+stridentificationCode+"\r\n "
+tr("delaySync")+":"+strtempdelaySync+tr("msec")+"\r\n "
+tr("OtherSyncItem")+":"+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+":"+strLastSyncTime;
emit sigOutputInfo(strOut);
}
else if(strType=="ntp"){
QString strtempdelaySync=QString::number(jsonObject["checkNtpTime"].toInt());
QString strOut=m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetingSyncMethod")+":"+strType+"\r\n "
+tr("checkNtpTime")+":"+strtempdelaySync+"\r\n "
+tr("OtherSyncItem")+":"+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+":"+strLastSyncTime;
emit sigOutputInfo(strOut);
}
else if(strType=="gps"){
QString strOut=m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetingSyncMethod")+":"+strType+"\r\n "
+tr("OtherSyncItem")+":"+strOtherSyncItem+"\r\n "
+tr("lastSynchronousTime")+":"+strLastSyncTime;
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();
// qDebug() <<"save" ;
// imageresult.save("G:/1.jpg");
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 wDevicesItem::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;
}
LedCard * wDevicesItem::GetLedCardPoint()
{
return m_pLedCard;
}
void wDevicesItem::OnSyncFirmware()
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "UninstallSoftware");
json.insert("packageName", "com.xixun.xixunplayer");
HttpPostByTypeJsonObject(json);
qDebug()<<"OnSyncFirmware";
// QCoreApplication::applicationDirPath() + "/Downloads/"+
QString url="http://"+m_pLedCard->m_strCardIp+":2016/upload?type=software";
LoAppConfig *cfg = LoAppConfig::getInstance();
QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
QString strfilepath = settings->value("xixunplayer").toString();
if(strfilepath.isEmpty())
{
strfilepath=QCoreApplication::applicationDirPath() + "/Downloads/"+strCurInstallApkFileName;
settings->setValue("xixunplayer",strfilepath);
}
QFileInfo file1(strfilepath);
QFile file(strfilepath);
if(file.exists())
{
QMap<QString,QString> params_send; //上传的普通参数 在本程序中 需要上传一个普通参数为"username"
params_send.insert("username","10005");
UpLoadForm(url,params_send,file1.fileName(),&file,file1.fileName(),0);
//UpLoadForm(url,file1.fileName(),&file,file1.fileName());
}
}
void wDevicesItem::slotUploadFinished()
{
// LoAppConfig *cfg = LoAppConfig::getInstance();
// QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
// QString strfilepath = settings->value("xixunplayer").toString();
// QFileInfo file(strfilepath);
// QJsonObject json;
// json.insert("_id", getRandomString(10));
// json.insert("_type", "UpgradeSoftware");
// json.insert("fileName", file.fileName());
// HttpPostByTypeJsonObject(json);
// emit sigSetTipTextContent(tr("install start..."));
// qDebug()<<"slotUploadFinished";
LoAppConfig *cfg = LoAppConfig::getInstance();
QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
QString strfilepath = settings->value("xixunplayer").toString();
if(strfilepath.isEmpty())
{
strfilepath=QCoreApplication::applicationDirPath() + "/Downloads/"+strCurInstallApkFileName;
}
QFileInfo file(strfilepath);
if(file.exists())
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "UpgradeSoftware");
json.insert("fileName", file.fileName());
json.insert("isCustom", true);
HttpPostByTypeJsonObject(json);
emit sigSetTipTextContent(tr("install start..."));
//MACRO_ASKTIME_STOP
//m_pGetAskTimer->start(40000);
qDebug()<<strfilepath;
}
else
{
QMessageBox::information(NULL, "warning", tr("not found xixunplayer.apk in computer")+strfilepath, QMessageBox::Yes , QMessageBox::Yes);
//QMessageBox::warning((this,"warning",tr("not found xixunplayer.apk in computer")));
}
}
//void wDevicesItem::UpLoadForm(QString Path,QMap<QString,QString> params,QString fileFormName,QFile *uploadFile,QString newFileName)
//void wDevicesItem::UpLoadForm(QString Path,QString fileFormName,QFile *uploadFile,QString newFileName)
//{
// qDebug()<<"UpLoadForm";
// QString BOUNDARY=QUuid::createUuid().toString();
// QByteArray sb=QByteArray();
// //上传文件的头部
// sb.append("--"+BOUNDARY+"\r\n");
// sb.append(QString("Content-Disposition: form-data;name=\"")+fileFormName+QString("\";filename=\"")+newFileName+QString("\"")+QString("\r\n"));
// sb.append("\r\n");
// //上传文件内容
// if(!uploadFile->open(QIODevice::ReadOnly)){
// return;
// }
// sb.append(uploadFile->readAll());
// sb.append("\r\n");
// sb.append("--"+BOUNDARY+"\r\n");
// //编辑HTTP头部
// QNetworkAccessManager *_uploadManager=new QNetworkAccessManager();
// QNetworkRequest request=QNetworkRequest(QUrl(Path));
// request.setRawHeader(QString("Content-Type").toLatin1(),QString("multipart/form-data;boundary="+BOUNDARY).toLatin1());
// request.setRawHeader(QString("Content-Length").toLatin1(),QString::number(sb.length()).toLatin1());
// //执行post请求
// QNetworkReply * m_netReply =_uploadManager->post(request,sb);
// connect(m_netReply, SIGNAL(uploadProgress ( qint64 ,qint64 )), this, SLOT( slotUploadProgress(qint64 ,qint64)));
// connect(m_netReply, SIGNAL(finished()), this, SLOT(slotUploadFinished()));
// 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("UpgradeSoftware"),tr("Success"),tr("UpgradeSoftware")+tr("failed"));
// m_pGetAskTimer->start(15000);
// connect(this, SIGNAL(sigSetTipTextContent ( QString)), m_PostingDlg, SLOT( SetTipTextContent(QString)));
// m_PostingDlg->exec();
// }
//}
void wDevicesItem::UpLoadForm(QString Path,QMap<QString,QString> params,QString fileFormName,QFile *uploadFile,QString newFileName,int iType)
{
QString BOUNDARY=QUuid::createUuid().toString();
QByteArray sb=QByteArray();
//先上传普通的表单数据
// for(QMap<QString,QString>::Iteratort=params.begin();t!=params.end();t++)
for(QMap<QString,QString>::iterator t=params.begin();t!=params.end();t++)
{
sb.append("--"+BOUNDARY+"\r\n");
sb.append(QString("Content-Disposition: form-data;name=\"")+t.key()+QString("\"")+QString("\r\n"));
sb.append("\r\n");
sb.append(t.value()+"\r\n");
}
//上传文件的头部
sb.append("--"+BOUNDARY+"\r\n");
sb.append(QString("Content-Disposition: form-data;name=\"")+fileFormName+QString("\";filename=\"")+newFileName+QString("\"")+QString("\r\n"));
sb.append("\r\n");
//上传文件内容
if(!uploadFile->open(QIODevice::ReadOnly)){
return;
}
sb.append(uploadFile->readAll());
sb.append("\r\n");
sb.append("--"+BOUNDARY+"\r\n");
//编辑HTTP头部
QNetworkAccessManager *_uploadManager=new QNetworkAccessManager();
QNetworkRequest request=QNetworkRequest(QUrl(Path));
request.setRawHeader(QString("Content-Type").toLatin1(),QString("multipart/form-data;boundary="+BOUNDARY).toLatin1());
request.setRawHeader(QString("Content-Length").toLatin1(),QString::number(sb.length()).toLatin1());
//执行post请求
if(m_PostingDlg==nullptr)
{
m_PostingDlg = new LoEmptyDialog();
connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg()));
connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock()));
m_PostingDlg->lock(tr("UpgradeSoftware"),tr("Success"),tr("UpgradeSoftware")+tr("failed"));
m_pGetAskTimer->start(60000);
QNetworkReply * m_netReply =_uploadManager->post(request,sb);
connect(m_netReply, SIGNAL(uploadProgress ( qint64 ,qint64 )), this, SLOT( slotUploadProgress(qint64 ,qint64)));
connect(this, SIGNAL(sigSetTipTextContent ( QString )), m_PostingDlg, SLOT( SetTipTextContent(QString)));
connect(m_netReply, SIGNAL(finished()), this, SLOT(slotUploadFinished()));
m_PostingDlg->exec();
}
}
void wDevicesItem::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 wDevicesItem::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}
void wDevicesItem::SendAnycastCmd(QString strIp,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(strIp),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()<<strIp<<"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))
{
QByteArray readBuf=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;
}