QT嵌入式程序 运行10分钟就卡死 界面不动
疯而不觉 2017-07-13 10:33:22
[/code]
#include "conHttp.h"
#include <QMessageBox>
#include <QtDebug>
#include <QThread>
#include <QObject>
#include "Widget.h"
#include "static_public.h"
#include<QMessageBox>
#include <QCoreApplication>
#include <QtDebug>
conHttp::conHttp(Widget *parent)
{
myCom3 = new Posix_QextSerialPort("/dev/ttySAC2",QextSerialBase::Polling);
myCom3 -> open(QIODevice::ReadWrite);
myCom3 -> setBaudRate(BAUD9600);
myCom3 -> setDataBits(DATA_8);
myCom3 -> setParity(PAR_NONE);
myCom3 -> setStopBits(STOP_1);
myCom3 -> setFlowControl(FLOW_OFF);
myCom3 -> setTimeout(10);
httpOnFlag = false;
threadWidget = parent;
sendResultCount = 0;
// timerResult = new QTimer(this);
// connect(timerResult,SIGNAL(timeout()),this,SLOT(HttpSendResult()));
//timerResult->moveToThread(this);
threadStop = false;
sendCIPSHUT = "AT+CIPSHUT\r\n";//关闭网络
sendCIPSEND1 = "AT+CIPSEND=1\r\n";
sendCIPSEND2 = "AT+CIPSEND=2\r\n";
sendCIPSTATUS = "AT+CIPSTATUS\r\n";//判断连接状态
}
conHttp::~conHttp()
{
}
void conHttp::run(){
qDebug()<<" thread run:" <<QThread::currentThreadId();
// while(!threadStop){
if(choose == "start"){
choose = "NULL";
qDebug()<<" start";
HttpOn();
if(httpOnFlag){
emit stringChanged("connect");
httpFlag = true;
}
else{
emit stringChanged("notConnect");
}
}
else if(choose == "stop"){
choose = "NULL";
qDebug()<<" stop";
HttpOff();
httpFlag = false;
}
else if(choose == "send"){
choose = "NULL";
qDebug()<<" send";
qDebug() << "5";
HttpSendData();
}
qDebug() << "end!!!!!!!!!!!";
}
void conHttp::httpConnect(){
//qDebug()<<" thread start:" <<QThread::currentThreadId();
choose = "start";
}
void conHttp::httpBreak(){
//qDebug()<<" thread break:" <<QThread::currentThreadId();
choose = "stop";
}
void conHttp::httpSend(QString str){
//qDebug()<<" thread send:" <<QThread::currentThreadId();
qDebug() << "4";
sendHTTPPARA = str;
choose = "send";
}
//连接指令
void conHttp::HttpOn(){
QString temp;
QStringList str;
QString sendStr[6] = {"AT+CIPMUX=1\r\n",
"AT+CSTT\r\n",
"AT+CIICR\r\n",
"AT+CIFSR\r\n",
"AT+CIPSTART=1,\"TCP\",\"" + static_public::IP1 + "\",\"" + static_public::Port1 + "\"\r\n"
"AT+CIPSTART=2,\"TCP\",\"" + static_public::IP2 + "\",\"" + static_public::Port2 + "\"\r\n"};
for(int i= 0;i < 6; i++){
myCom3->readAll();
myCom3->write(sendStr[i].toLatin1());
sleep(1);
}
sleep(5);
temp = myCom3->readAll();
qDebug() << "sendstr" << ":" << temp;
str = temp.split("\r\n",QString::SkipEmptyParts);
qDebug() <<"str"<<str;
qDebug() << "str.count:" << str.count();
if(!str.empty()){
if(str.at(0).endsWith("K") && str.at(1).endsWith("K")){
qDebug() << "test ok";
httpOnFlag = true;//con << "7";nect ok
}
else{
httpOnFlag = false;//connect error
qDebug() << "no ok";
HttpOff();
return;
}
}
}
//断开指令
void conHttp::HttpOff(){
qDebug() << "HttpOff";
myCom3->write(sendCIPSHUT.toLatin1());
sleep(1);
}
//发送数据
void conHttp::HttpSendData(){
qDebug() << "thread HttpSendData:" <<QThread::currentThreadId();
qDebug() << "HttpSendData";
qDebug() << "httpFlag:" << httpFlag;
qDebug() << "httpOnFlag:" << httpOnFlag;
// char send1A[] = {0x1A};
QString StateConnect;
QStringList list;
qDebug() << "6";
QByteArray send1A;
send1A.resize(1);
send1A[0] = 0x1A;
if(!httpFlag){
qDebug()<<"return qian";
return;
}
//判断连接状态
myCom3->write(sendCIPSTATUS.toLatin1());
sleep(2);
StateConnect = myCom3->readAll();
list = StateConnect.split(":",QString::SkipEmptyParts);
for(int h = 0; h < list.count(); h++){
qDebug() << "StateConnect" << list.at(h);
}
/* if(list.count() > 3&& list.at(3).trimmed() != "CONNECTED"){
qDebug() << "disconnect";
int i=0;
HttpOn();
while (!httpOnFlag) {
qDebug() << "httpflagwhile";
HttpOff();
HttpOn();
i++;
if(i >4){
return;
}
}
}*/
if(httpOnFlag){
myCom3->write(sendCIPSEND1.toLatin1());
sleep(2);
myCom3->write(sendHTTPPARA.toLatin1());
sleep(2);
myCom3->write(send1A);
sleep(2);
myCom3->write(sendCIPSEND2.toLatin1());
sleep(2);
myCom3->write(sendHTTPPARA.toLatin1());
sleep(2);
myCom3->write(send1A);
#if 1
sleep(2);
qDebug() << myCom3->readAll();
#endif
}
qDebug() << "7";
}
这是一部分代码,之前没有过这种问题,就是点击开始时候,会用定时器采集数据发送数据