hlp:桂林国际齿轮泵代码
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,31 @@
|
||||
#ifndef DLGDRAWINIT_H
|
||||
#define DLGDRAWINIT_H
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include "MyInputMethod.h"
|
||||
|
||||
namespace Ui {
|
||||
class dlgDrawInit;
|
||||
}
|
||||
|
||||
class dlgDrawInit : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit dlgDrawInit(QWidget *parent = 0);
|
||||
~dlgDrawInit();
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
int setWidth(int w);
|
||||
int setHeight(int h);
|
||||
public slots:
|
||||
void on_pushButtonOK_pressed();
|
||||
Q_SIGNALS:
|
||||
void dlgDrawOK();
|
||||
private:
|
||||
Ui::dlgDrawInit *ui;
|
||||
};
|
||||
|
||||
#endif // DLGDRAWINIT_H
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef DLGQRCODE_H
|
||||
#define DLGQRCODE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "QtQREnCode/qrencode.h"
|
||||
#include "QGraphicsScene"
|
||||
#include "QGraphicsPixmapItem"
|
||||
#include "SysPara.h"
|
||||
|
||||
namespace Ui {
|
||||
class dlgQrCode;
|
||||
}
|
||||
|
||||
class dlgQrCode : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit dlgQrCode(QWidget *parent = 0);
|
||||
~dlgQrCode();
|
||||
//dlgQrCode(qrOption_t *qrOption);
|
||||
|
||||
int bcWidth,bcHeight;
|
||||
unsigned char flagInsert:1;
|
||||
unsigned char flagCount:1;
|
||||
unsigned char AutoCount11:1;
|
||||
unsigned char barCodeFlag:1; //明码标志
|
||||
unsigned char NNNCC:5;
|
||||
QString pictureName;
|
||||
int QRCntNum;
|
||||
void SetOption(qrOption_t *qrOption);
|
||||
void GetOption(qrOption_t *qrOption);
|
||||
void extSetText(QString text, bool flag = false);
|
||||
QString TextToQRImg(qrOption_t *qrVar);
|
||||
int getDat(SysPara * sysPara,int varNum);
|
||||
unsigned long counter;
|
||||
|
||||
void setCntCheckBoxHide(bool hideEn);
|
||||
QString getCounterText( int counter,int QRCntNum);
|
||||
void MatrixEnCode(unsigned char *intext,int Size);
|
||||
void setSysPara(SysPara * sysPara);
|
||||
|
||||
public slots:
|
||||
void onTextChanged();
|
||||
signals:
|
||||
void onQRCodeCloseNow();
|
||||
|
||||
private slots:
|
||||
void onQRCodeAuto(bool);
|
||||
void on_pushBtnPreView_pressed();
|
||||
void on_pushBtnClose_pressed();
|
||||
void on_pushBtnSave_pressed();
|
||||
void onComboBoxType(int);
|
||||
private:
|
||||
void ShowQRCode(QImage *img);
|
||||
QGraphicsScene *scene;//声明scene
|
||||
QGraphicsPixmapItem *item;//声明item
|
||||
qrOption_t *qrOption;
|
||||
bool AutoRefresh;
|
||||
Ui::dlgQrCode *ui;
|
||||
SysPara * sysPara;
|
||||
};
|
||||
|
||||
#endif // DLGQRCODE_H
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#echo "start up qtui...."
|
||||
export QT_QWS_FONTDIR=/usr/lib/fonts
|
||||
export QWS_MOUSE_PROTO="TSLIB:/dev/input/event1 mouseman:/dev/input/mice"
|
||||
|
||||
cd /dev/ && ln -s am335x_visco_pwm pwm && ln -s am335x_suction_pwm pwm1
|
||||
|
||||
if [ -e /dev/input/touchscreen0 ]; then
|
||||
TSLIB_TSDEVICE=/dev/input/touchscreen0
|
||||
export TSLIB_CALIBFILE=/etc/pointercal
|
||||
export TSLIB_CONFFILE=/usr/local/etc/ts.conf
|
||||
export TSLIB_PLUGINDIR=/usr/lib/ts
|
||||
export TSLIB_TSDEVICE
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -f /etc/pointercal ];then
|
||||
touch /etc/pointercal
|
||||
ts_calibrate
|
||||
fi
|
||||
|
||||
cd /home/plg
|
||||
if [ ! -f /home/plg/runFlag ];then
|
||||
chmod a+x InkJetPrinter
|
||||
./InkJetPrinter -qws
|
||||
fi
|
||||
|
||||
|
||||
#bootup QtUI
|
||||
chmod +x QtUI
|
||||
./QtUI -qws -display VNC:LinuxFb &
|
||||
rm /home/plg/runFlag
|
||||
|
||||
sleep 1
|
||||
#mount mmc and usb disk
|
||||
if [ -f /dev/mmcblk0p1 ];then
|
||||
mount /dev/mmcblk0p1 /mnt/mmc/
|
||||
fi
|
||||
|
||||
ln -sf /mnt/udisk /udisk
|
||||
if [ -f /dev/sda1 ];then
|
||||
mount /dev/sda1 /mnt/udisk/
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
#start quectel-CM
|
||||
./quectel-CM &
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
|
||||
<cconfiguration id="0.212484530">
|
||||
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.212484530" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||
|
||||
<externalSettings/>
|
||||
|
||||
<extensions>
|
||||
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
|
||||
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
|
||||
</extensions>
|
||||
|
||||
</storageModule>
|
||||
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
|
||||
<configuration buildProperties="" description="" id="0.212484530" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
|
||||
|
||||
<folderInfo id="0.212484530." name="/" resourcePath="">
|
||||
|
||||
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1244596468" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
|
||||
|
||||
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1244596468.684704648" name=""/>
|
||||
|
||||
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1410282383" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
|
||||
|
||||
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.392554891" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
||||
|
||||
<tool id="org.eclipse.cdt.build.core.settings.holder.501222950" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||
|
||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.723506115" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||
|
||||
</tool>
|
||||
|
||||
<tool id="org.eclipse.cdt.build.core.settings.holder.242070330" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||
|
||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.928814685" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||
|
||||
</tool>
|
||||
|
||||
<tool id="org.eclipse.cdt.build.core.settings.holder.1354386318" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||
|
||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.2132916160" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||
|
||||
</tool>
|
||||
|
||||
</toolChain>
|
||||
|
||||
</folderInfo>
|
||||
|
||||
</configuration>
|
||||
|
||||
</storageModule>
|
||||
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
|
||||
</cconfiguration>
|
||||
|
||||
</storageModule>
|
||||
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
|
||||
<project id="svn_src.null.1787716003" name="svn_src"/>
|
||||
|
||||
</storageModule>
|
||||
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="0.988500999">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="0.1811839224">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1595335407;cdt.managedbuild.config.gnu.exe.debug.1595335407.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1788775517;cdt.managedbuild.tool.gnu.cpp.compiler.input.1367848852">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="0.1829401466">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="0.1138059952">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="0.2038577112">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="0.212484530">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1595335407;cdt.managedbuild.config.gnu.exe.debug.1595335407.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1296392877;cdt.managedbuild.tool.gnu.c.compiler.input.224723217">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
</storageModule>
|
||||
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
|
||||
</cproject>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,454 @@
|
||||
#include "print_net.h"
|
||||
#include "QDebug"
|
||||
#include <QtNetwork/QSslConfiguration>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
#include "LogInfo.h"
|
||||
|
||||
#define QT_NO_SSL
|
||||
|
||||
|
||||
PrintNet::PrintNet()
|
||||
{
|
||||
m_bShortNet = false;
|
||||
// 创建网络管理器用于GET method
|
||||
this->getManager = new QNetworkAccessManager(this);
|
||||
connect(getManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
|
||||
// 创建网络管理器用于POST method
|
||||
this->postManager = new QNetworkAccessManager(this);
|
||||
connect(postManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(postPrintFinished(QNetworkReply *)));
|
||||
|
||||
m_postmanager = new QNetworkAccessManager(this);
|
||||
connect(m_postmanager, SIGNAL(finished(QNetworkReply *)), this, SLOT(postGetShortUrlFinished(QNetworkReply *)));
|
||||
}
|
||||
|
||||
PrintNet::~PrintNet()
|
||||
{
|
||||
delete this->getManager;
|
||||
delete this->postManager;
|
||||
}
|
||||
|
||||
// 初步实现 喷码机向服务器获取打印数据 以及 上报状态 接口
|
||||
// 未处理 网络条件不具备 / 访问超时 等异常
|
||||
|
||||
// 递归列出JSON所有层内容
|
||||
void PrintNet::traversJson(QJsonObject json_obj)
|
||||
{
|
||||
foreach (const QString& key, json_obj.keys())
|
||||
{
|
||||
QJsonValue value = json_obj.value(key);
|
||||
if (!value.isObject())
|
||||
{
|
||||
// qDebug()<<"[traversJson]key="<<key<<" value="<<value;
|
||||
if(key == "QRCodeContent"){
|
||||
QString t_str;
|
||||
t_str = value.toString();
|
||||
// const char *std_str = t_str.toStdString().data();
|
||||
// strcpy(Json_get_data.QRCodeContent,std_str);
|
||||
strncpy(Json_get_data.QRCodeContent,t_str.toStdString().c_str(),sizeof(Json_get_data.QRCodeContent));
|
||||
Json_get_data.QRCodeContent[sizeof(Json_get_data.QRCodeContent) -1] = '\0';
|
||||
}else
|
||||
if(key == "PrintingContent"){
|
||||
QString t_str;
|
||||
t_str = value.toString();
|
||||
t_str.replace('&',"&").replace('<',"<").replace('>',">").replace('"',""").replace('\'',"'")
|
||||
.replace('¥',"¥").replace('®',"®").replace('°',"°").replace('±',"±").replace('×',"x")
|
||||
.replace('*',"*").replace('÷',"÷").replace('²',"²").replace('³',"³").replace('Ω',"Ω")
|
||||
.replace('Φ',"Φ").replace('¥',"¥").replace('φ',"φ").replace('©',"©").replace('@',"@")
|
||||
.replace('㎡',"㎡").replace('℃',"℃").replace('℉',"℉").replace('\r',' ').replace('\n',' ') ;
|
||||
// const char *std_str = t_str.toStdString().data();
|
||||
// strcpy(Json_get_data.PrintingContent,std_str);
|
||||
strncpy(Json_get_data.PrintingContent,t_str.toStdString().c_str(),sizeof(Json_get_data.PrintingContent));
|
||||
Json_get_data.PrintingContent[sizeof(Json_get_data.PrintingContent) -1] = '\0';
|
||||
}else
|
||||
if(key == "ProductPlanQty"){
|
||||
Json_get_data.ProductPlanQty = value.toDouble();
|
||||
}else
|
||||
if(key == "ProductUniqueCode"){
|
||||
QString t_str;
|
||||
t_str = value.toString();
|
||||
// const char *std_str = t_str.toStdString().data();
|
||||
// strcpy(Json_get_data.ProductUniqueCode,std_str);
|
||||
strncpy(Json_get_data.ProductUniqueCode,t_str.toStdString().c_str(),sizeof(Json_get_data.ProductUniqueCode));
|
||||
Json_get_data.ProductUniqueCode[sizeof(Json_get_data.ProductUniqueCode) -1] = '\0';
|
||||
}else
|
||||
if(key == "ProductionTask"){
|
||||
Json_get_data.ProductionTask = value.toDouble();
|
||||
}else
|
||||
if(key == "StartMetre"){
|
||||
Json_get_data.StartMetre = value.toDouble();
|
||||
}else
|
||||
if(key == "TasdNeedConfirm"){
|
||||
Json_get_data.TasdNeedConfirm = value.toBool();
|
||||
}else
|
||||
if(key == "TaskSwitchingMode"){
|
||||
Json_get_data.TaskSwitchingMode = value.toDouble();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
traversJson(value.toObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PrintNet::postPrintFinished(QNetworkReply *reply)
|
||||
{
|
||||
QNetworkReply::NetworkError error;
|
||||
error = reply->error(); // 应答无错误时为QNetworkReply::NoError(0)
|
||||
if (error)
|
||||
{ // 非0值表示有错误发生
|
||||
switch(error)
|
||||
{
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
save_messege = "远程主机拒绝连接";
|
||||
break;
|
||||
|
||||
case QNetworkReply::RemoteHostClosedError:
|
||||
save_messege = "远程主机关闭连接";
|
||||
break;
|
||||
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
save_messege = "远程主机未找到";
|
||||
break;
|
||||
|
||||
case QNetworkReply::TimeoutError:
|
||||
save_messege = "连接到远程主机超时";
|
||||
break;
|
||||
|
||||
case QNetworkReply::ContentAccessDenied:
|
||||
save_messege = "远程主机拒绝访问";
|
||||
break;
|
||||
|
||||
case QNetworkReply::ContentNotFoundError:
|
||||
save_messege = "内容未找到";
|
||||
break;
|
||||
default:
|
||||
save_messege = "通信失败";
|
||||
}
|
||||
emit json_server_error();
|
||||
return;
|
||||
}
|
||||
|
||||
//未出错时获取响应信息
|
||||
QByteArray rsp_data = reply->readAll();
|
||||
//以下对获取的JSON数据进行解析
|
||||
QJsonDocument json = QJsonDocument::fromJson(rsp_data);
|
||||
|
||||
QJsonObject obj = json.object();
|
||||
|
||||
traversJson(obj); // 递归列出JSON所有层内容
|
||||
// qDebug() << "[postPrintFinished]ResultCode: " << obj["ResultCode"];
|
||||
// qDebug() << "[postPrintFinished]ResultMessage: " << obj["ResultMessage"];
|
||||
// qDebug() << "[postPrintFinished]ResultData: " << obj["ResultData"];
|
||||
|
||||
save_messege = obj["ResultMessage"].toString();
|
||||
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
QString PrintNet::getMessege()
|
||||
{
|
||||
return save_messege;
|
||||
}
|
||||
// 处理HTTP请求的应答
|
||||
void PrintNet::replyFinished(QNetworkReply *reply)
|
||||
{
|
||||
QNetworkReply::NetworkError error;
|
||||
error = reply->error(); // 应答无错误时为QNetworkReply::NoError(0)
|
||||
if (error)
|
||||
{ // 非0值表示有错误发生
|
||||
switch(error)
|
||||
{
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
save_messege = "远程主机拒绝连接";
|
||||
break;
|
||||
|
||||
case QNetworkReply::RemoteHostClosedError:
|
||||
save_messege = "远程主机关闭连接";
|
||||
break;
|
||||
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
save_messege = "远程主机未找到";
|
||||
break;
|
||||
|
||||
case QNetworkReply::TimeoutError:
|
||||
save_messege = "连接到远程主机超时";
|
||||
break;
|
||||
|
||||
case QNetworkReply::ContentAccessDenied:
|
||||
save_messege = "远程主机拒绝访问";
|
||||
break;
|
||||
|
||||
case QNetworkReply::ContentNotFoundError:
|
||||
save_messege = "内容未找到";
|
||||
break;
|
||||
default:
|
||||
save_messege = "通信失败";
|
||||
}
|
||||
|
||||
emit json_server_error();
|
||||
return;
|
||||
}
|
||||
//未出错时获取响应信息
|
||||
QByteArray rsp_data = reply->readAll();
|
||||
//以下对获取的JSON数据进行解析
|
||||
QJsonDocument json = QJsonDocument::fromJson(rsp_data);
|
||||
QJsonObject obj = json.object();
|
||||
traversJson(obj); // 递归列出JSON所有层内容
|
||||
|
||||
// qDebug() << "[replyFinished] ResultCode: " << obj["ResultCode"];
|
||||
// qDebug() << "[replyFinished] ResultMessage: " << obj["ResultMessage"];
|
||||
// qDebug() << "[replyFinished] ResultData: " << obj["ResultData"];
|
||||
|
||||
save_messege = obj["ResultMessage"].toString();
|
||||
|
||||
reply->deleteLater();
|
||||
save_messege = "JSON获取成功!";
|
||||
emit showMessege();
|
||||
if(m_bShortNet)
|
||||
{
|
||||
FromBaiDuGetShortUrl(Json_get_data.QRCodeContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit receiveJSONDatafinish();
|
||||
}
|
||||
}
|
||||
|
||||
// 从服务器获取打印数据
|
||||
// url - 提供打印数据的服务器链接
|
||||
// equip_code - 喷码机编号
|
||||
void PrintNet::PrintNetGetData(QString url, const QString& equip_code)
|
||||
{
|
||||
EquipmentCode = equip_code;
|
||||
//设计本接口实现时,考虑输入的url为问号(?)之前那部分,不同的喷码机equip_code不同
|
||||
//QUrl qrl("http://47.111.170.144:8754/KLAPS/APSServer/ECode/GetProductUniqueCodeTest?EquipmentCode=1");
|
||||
QUrl qrl(url);
|
||||
// 在访问服务器API的链接中添加喷码机编号
|
||||
//qrl.addQueryItem("EquipmentCode", QString::number(equip_code));
|
||||
qrl.addQueryItem("EquipmentCode", equip_code);
|
||||
|
||||
//QUrlQuery query;
|
||||
//query.addQueryItem("EquipmentCode", QString::number(equip_code));
|
||||
//qrl.setQuery(query);
|
||||
|
||||
// 构造请求
|
||||
QNetworkRequest request;
|
||||
request.setUrl(qrl);
|
||||
|
||||
getManager->get(request); // HTTP GET
|
||||
}
|
||||
|
||||
// 向服务器上报打印完成状态
|
||||
// url - 上报打印完成状态的服务器链接
|
||||
void PrintNet::PrintNetPostFinish(QString url)
|
||||
{
|
||||
QUrl qrl(url);
|
||||
|
||||
|
||||
// 构造JSON对象数据
|
||||
QJsonObject json;
|
||||
json.insert("ProductUniqueCode", QString(Json_get_data.ProductUniqueCode));
|
||||
json.insert("ProductionTask", QString::number(Json_get_data.ProductionTask));
|
||||
json.insert("PrintingContent", QString(Json_get_data.PrintingContent));
|
||||
//json.insert("EquipmentUniqueCode", QString::number(EquipmentCode) );
|
||||
json.insert("EquipmentUniqueCode", EquipmentCode );
|
||||
json.insert("StartingMeters", QString::number(Json_get_data.StartMetre));
|
||||
json.insert("ProductNumber", QString::number(Json_get_data.ProductPlanQty));
|
||||
json.insert("Coordinates", QString("北纬N31°51′15.36 东经E117°12′8.77"));
|
||||
// qDebug() << json;
|
||||
|
||||
QJsonDocument jsonDoc(json);
|
||||
// qDebug() << jsonDoc;
|
||||
|
||||
QByteArray jsonData = jsonDoc.toJson();
|
||||
// qDebug() << jsonData;
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(qrl);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
postManager->post(request, jsonData); // HTTP POST
|
||||
}
|
||||
|
||||
// 向服务器上报设备运行状态
|
||||
// url - 上报设备运行状态的服务器链接
|
||||
|
||||
void PrintNet::PrintNetPostState(QString url)
|
||||
{
|
||||
QUrl qrl(url);
|
||||
|
||||
// 构造JSON对象数据
|
||||
QJsonObject json;
|
||||
//json.insert("EquipmentUniqueCode", QString::number(EquipmentCode));
|
||||
json.insert("EquipmentUniqueCode", EquipmentCode );
|
||||
json.insert("CurrentMeter", QString("13.3"));
|
||||
json.insert("CurrentEcode", QString(Json_get_data.ProductUniqueCode));
|
||||
json.insert("CurrentPrintingContent", QString(Json_get_data.PrintingContent));
|
||||
// qDebug() << json;
|
||||
|
||||
QJsonDocument jsonDoc(json);
|
||||
// qDebug() << jsonDoc;
|
||||
|
||||
QByteArray jsonData = jsonDoc.toJson();
|
||||
// qDebug() << jsonData;
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(qrl);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
postManager->post(request, jsonData); // HTTP POST
|
||||
}
|
||||
|
||||
// 向百度云获取转换的短网址
|
||||
//longUrl要转换的长url
|
||||
|
||||
void PrintNet::FromBaiDuGetShortUrl(QString longUrl)
|
||||
{
|
||||
QUrl qrl(QString("https://dwz.cn/api/v3/short-urls"));
|
||||
|
||||
// 构造JSON对象数据
|
||||
QJsonObject json;
|
||||
json.insert("LongUrl", longUrl);
|
||||
json.insert("TermOfValidity", QString("long-term"));
|
||||
//json.insert("CurrentEcode", QString(Json_get_data.ProductUniqueCode));
|
||||
//json.insert("CurrentPrintingContent", QString(Json_get_data.PrintingContent));
|
||||
//qDebug() << json;
|
||||
|
||||
QJsonArray Arrjson;
|
||||
Arrjson.append(json);
|
||||
|
||||
QJsonDocument jsonDoc(Arrjson);
|
||||
//qDebug() << jsonDoc;
|
||||
|
||||
QByteArray jsonData = jsonDoc.toJson();
|
||||
//qDebug() << jsonData;
|
||||
|
||||
|
||||
//LogInfo::setRunStatusText(tr("FromBaiDuGetShortUrl(): setSsl before"));
|
||||
QNetworkRequest request;
|
||||
request.setUrl(qrl);
|
||||
//LogInfo::setRunStatusText(tr("defaultConfiguration new before"));
|
||||
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
|
||||
//LogInfo::setRunStatusText(tr("defaultConfiguration 1"));
|
||||
config.setProtocol(QSsl::TlsV1);
|
||||
//LogInfo::setRunStatusText(tr("defaultConfiguration 2"));
|
||||
config.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
//LogInfo::setRunStatusText(tr("defaultConfiguration 3"));
|
||||
request.setSslConfiguration(config);
|
||||
//LogInfo::setRunStatusText(tr("FromBaiDuGetShortUrl(): setSsl after"));
|
||||
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||
request.setRawHeader("Dwz-Token" ,"708e8736a533df553a8898699280bcf9");
|
||||
|
||||
//LogInfo::setRunStatusText(tr("FromBaiDuGetShortUrl(): <1>"));
|
||||
//QNetworkAccessManager *post_manager = new QNetworkAccessManager(this);
|
||||
//connect(post_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(postGetShortUrlFinished(QNetworkReply *)));
|
||||
m_postmanager->post(request, jsonData); // HTTP POST
|
||||
//LogInfo::setRunStatusText(tr("FromBaiDuGetShortUrl(): <2>"));
|
||||
//connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onNetReplyError(QNetworkReply::NetworkError)));
|
||||
//connect(reply, SIGNAL(sslErrors(QList&)), this, SLOT(onNetReplySshErrors(QList&)));
|
||||
#ifndef QT_NO_SSL
|
||||
connect(post_manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
|
||||
this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
|
||||
#endif
|
||||
|
||||
}
|
||||
#ifndef QT_NO_SSL
|
||||
void PrintNet::sslErrors(QNetworkReply *reply,const QList<QSslError> &)
|
||||
{
|
||||
reply->ignoreSslErrors();
|
||||
}
|
||||
#endif
|
||||
|
||||
void PrintNet::postGetShortUrlFinished(QNetworkReply *reply)
|
||||
{
|
||||
//LogInfo::setRunStatusText(tr("postGetShortUrlFinished(): <3>"));
|
||||
QNetworkReply::NetworkError error;
|
||||
error = reply->error(); // 应答无错误时为QNetworkReply::NoError(0)
|
||||
if (error)
|
||||
{ // 非0值表示有错误发生
|
||||
switch(error)
|
||||
{
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
save_messege = "远程主机拒绝连接";
|
||||
break;
|
||||
|
||||
case QNetworkReply::RemoteHostClosedError:
|
||||
save_messege = "远程主机关闭连接";
|
||||
break;
|
||||
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
save_messege = "远程主机未找到";
|
||||
break;
|
||||
|
||||
case QNetworkReply::TimeoutError:
|
||||
save_messege = "连接到远程主机超时";
|
||||
break;
|
||||
|
||||
case QNetworkReply::ContentAccessDenied:
|
||||
save_messege = "远程主机拒绝访问";
|
||||
break;
|
||||
|
||||
case QNetworkReply::ContentNotFoundError:
|
||||
save_messege = "内容未找到";
|
||||
break;
|
||||
default:
|
||||
save_messege = "通信失败";
|
||||
}
|
||||
//LogInfo::setRunStatusText(tr("postGetShortUrlFinished(): <4>"));
|
||||
emit json_server_error();
|
||||
//emit receiveJSONDatafinish();
|
||||
return;
|
||||
}
|
||||
|
||||
//未出错时获取响应信息
|
||||
QByteArray rsp_data = reply->readAll();
|
||||
//以下对获取的JSON数据进行解析
|
||||
QJsonDocument json = QJsonDocument::fromJson(rsp_data);
|
||||
//qDebug() << json;
|
||||
|
||||
QJsonObject obj = json.object();
|
||||
// qDebug() << obj;
|
||||
|
||||
QString strResultCode;
|
||||
save_messege = strResultCode.number(obj["Code"].toDouble());
|
||||
if(save_messege != "0")
|
||||
{
|
||||
//LogInfo::setRunStatusText(tr("postGetShortUrlFinished(): <5>"));
|
||||
//emit receiveJSONDatafinish();
|
||||
save_messege = "获取短网址出错,错误码:"+ save_messege;
|
||||
return;
|
||||
}
|
||||
QJsonArray JsonArr = obj["ShortUrls"].toArray();
|
||||
QJsonValue value = JsonArr.at(0);
|
||||
QJsonObject jsonObj = value.toObject();
|
||||
#if 1
|
||||
foreach (const QString& key, jsonObj.keys())
|
||||
{
|
||||
QJsonValue value = jsonObj.value(key);
|
||||
if (!value.isObject())
|
||||
{
|
||||
// qDebug()<<"[traversJson]key="<<key<<" value="<<value;
|
||||
if(key == "ShortUrl")
|
||||
{
|
||||
QString t_str;
|
||||
t_str = value.toString();
|
||||
const char *std_str = t_str.toStdString().data();
|
||||
strcpy(Json_get_data.QRCodeContent,std_str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
save_messege = "获取短网址成功";
|
||||
//LogInfo::setRunStatusText(tr("postGetShortUrlFinished(): <6>"));
|
||||
reply->deleteLater();
|
||||
emit receiveJSONDatafinish();
|
||||
}
|
||||
|
||||
|
||||
void PrintNet::getJson_data(JSON_DATA *json_data)
|
||||
{
|
||||
memcpy(json_data, &Json_get_data, sizeof(JSON_DATA));
|
||||
}
|
||||
Reference in New Issue
Block a user