实现赋码仪命令
升级小板程序失败时停止
This commit is contained in:
@@ -46,17 +46,31 @@ static QString get_local_ip()
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
bool CheckNetInfo()
|
||||
{
|
||||
QNetworkInterface net= QNetworkInterface::interfaceFromName("eth0");
|
||||
if(net.flags().testFlag(QNetworkInterface::IsUp)
|
||||
&& net.flags().testFlag(QNetworkInterface::IsRunning)
|
||||
&& !net.flags().testFlag(QNetworkInterface::IsLoopBack)
|
||||
&& (net.name() == "eth0"))
|
||||
{
|
||||
// qDebug() << "eth0 is Connected" << endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// qDebug() << "eth0 is Not Connected";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void command::init_cb()
|
||||
{
|
||||
mycfg *cfg_ = syscfg();
|
||||
if (get_local_ip().isEmpty())
|
||||
{
|
||||
qDebug("modify local ip addr.");
|
||||
QString str = "ifconfig eth0 %1";
|
||||
system(str.arg(cfg_->local_ip).toLocal8Bit().data());
|
||||
str = "route add default gw %1";
|
||||
system(str.arg(cfg_->gateway_ip).toLocal8Bit().data());
|
||||
}
|
||||
if (socket_ == nullptr)
|
||||
{
|
||||
socket_ = new QUdpSocket(this);
|
||||
@@ -65,8 +79,46 @@ void command::init_cb()
|
||||
qInfo() << "udp command start.";
|
||||
qInfo() << "cmd port=" << cfg_->cmd_port;
|
||||
}
|
||||
if(timer_==nullptr)
|
||||
{
|
||||
timer_=new QTimer();
|
||||
connect(timer_,&QTimer::timeout,this,&command::timer_cb);
|
||||
timer_->start(3000);
|
||||
}
|
||||
}
|
||||
|
||||
void command::timer_cb()
|
||||
{
|
||||
mycfg *cfg_ = syscfg();
|
||||
// qDebug("command timer cb.");
|
||||
if(CheckNetInfo()==true){
|
||||
if(networt_state==0){
|
||||
qDebug("network connected.");
|
||||
networt_state=1;
|
||||
}
|
||||
if (get_local_ip().isEmpty())
|
||||
{
|
||||
qDebug()<<"modify local ip addr."<<endl;
|
||||
QString str="ifconfig eth0 %1";
|
||||
str=str.arg(cfg_->local_ip);
|
||||
system(str.toLocal8Bit().data());
|
||||
qDebug()<<str<<endl;
|
||||
str="route add default gw %1";
|
||||
str=str.arg(cfg_->gateway_ip);
|
||||
system(str.toLocal8Bit().data());
|
||||
qDebug()<<str<<endl;
|
||||
}
|
||||
}else{
|
||||
if(networt_state!=0){
|
||||
qDebug("network disconnected.");
|
||||
networt_state=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void command::send(QByteArray data)
|
||||
{
|
||||
if (socket_ == nullptr)
|
||||
|
||||
Reference in New Issue
Block a user