标题:
基于Linux的WiFi智能小车实训
[打印本页]
作者:
帅萌萌小阿嗲
时间:
2018-7-18 10:04
标题:
基于Linux的WiFi智能小车实训
最近实训的.c文件,分享给大家。
0.png
(42.19 KB, 下载次数: 23)
下载附件
2018-7-18 16:23 上传
单片机源程序如下:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
socket = NULL;
timer = NULL;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::net_recv_data()
{
//3.recv piclen of picture from server
char headbuf[20];
int piclen,ret;
char picbuf[60*1024];
switch(flag)
{
case 1:
memset(headbuf,0,sizeof(headbuf));
// socket->waitForReadyRead(300);
ret = socket->read(headbuf, sizeof(headbuf));//piclen len eg:6479len
if(-1 == ret)
{
qDebug()<<"read piclen error";
socket->close();
socket = NULL;
}
qDebug()<<"headbuf:"<<headbuf;
sscanf(headbuf,"%dlen",&piclen);//piclen=6479
qDebug()<<"piclen="<<piclen;
flag = 2;
if(socket->bytesAvailable() >= piclen)
goto STMP_DATA;
break;
STMP_DATA:
case 2:
//4.recv data of picture from server
memset(picbuf, 0,sizeof(picbuf));
// socket->waitForReadyRead(300);
int count = 0;
while(count < piclen)
{
ret = socket->read(picbuf+count, piclen-count);
if(-1 == ret)
{
qDebug()<<"read data error";
socket->close();
socket = NULL;
}
else
count = count + ret;
}
qDebug()<<"ret="<<ret;
//5.display video
QPixmap pixmap;
pixmap.loadFromData((uchar *)picbuf, piclen, "jpg");
ui->label->setPixmap(pixmap);
qDebug()<<"display success";
flag = 0;
break;
}
}
void MainWindow::net_send_cmd()
{
//2.send request cmd to server
char buf[10] = "pic";
if(0 == flag)
{
int ret = socket->write(buf, sizeof(buf));
if(-1 == ret)
{
qDebug()<<"write pic error";
socket->close();
socket = NULL;
}
socket->flush();
flag = 1;
}
}
void MainWindow::net_connectd()
{
qDebug()<<"connect success\n";
timer->start(200);//200ms
}
void MainWindow::on_btnStart_clicked()
{
//1.connect to server
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
car.rar
(5.88 KB, 下载次数: 16)
2018-7-18 10:02 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1