QTcpSocket* socket;
socket = new QTcpSocket(this)
socket -> connectToHost("192.168.0.50", 3000);
while(!socket->waitForConnected(1000))
{
qDebug("waitForConnected!\n"); usleep(10000);
}
//send cmd
socket->write((char*)sdata, 3);
while(!socket->waitForBytesWritten(1000))
{
qDebug("waitForBytesWritten!\n"); usleep(10000);
}
if(sdata[2] == 5)
{
target_pos.x = 0.0;
target_pos.y = 0.0;
target_pos.ang = 0.0;
target_pos.state = 0;
target_pos.waite_time = 0;
memcpy(sdata+3, &target_pos, sizeof(struct Target_pos));
socket->write((char*)(sdata+3), sizeof(struct Target_pos));
while(!socket->waitForBytesWritten(1000))
{
qDebug("waitForBytesWritten!\n"); usleep(10000);
}
}
else if(sdata[2] == 6)
{
target_pos.x = info.pos_x;
target_pos.y = info.pos_y;
target_pos.ang = info.pos_ang;
target_pos.state = 0;
target_pos.waite_time = 0;
memcpy(sdata+3, &target_pos, sizeof(struct Target_pos));
socket->write((char*)(sdata+3), sizeof(struct Target_pos));
while(!socket->waitForBytesWritten(1000))
{
qDebug("waitForBytesWritten!\n"); usleep(10000);
}
}
//recv info data
socket->read((char*)rdata, 2+sizeof(struct Info));
while(socket->bytesAvailable() < 2+sizeof(struct Info))
{
if(!socket->waitForReadyRead(1000))
{
qDebug("waitForReadyRead failed!\n");
break;
}
}