2 Star 2 Fork 4

yangyang/gps resolve

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mytcpserver.cpp 2.82 KB
一键复制 编辑 原始数据 按行查看 历史
yangyang 提交于 2018-10-12 19:00 . register frame complete
#include "mytcpserver.h"
#include "command.h"
#include "cstring"
#include "cstdio"
MyTcpServer::MyTcpServer(QObject *parent) :
QObject(parent)
{
server = new QTcpServer(this);
// whenever a user connects, it will emit signal
connect(server, SIGNAL(newConnection()),this, SLOT(newConnection()));
if(!server->listen(QHostAddress::Any, 38990))
qDebug() << "Server could not start";
else
qDebug() << "Server started!";
count=0;
db.setHostName("23.95.31.58");
db.setDatabaseName("testdb"); //这里输入你的数据库名
db.setUserName("root");
db.setPassword("1");
qDebug()<<db.open();
}
void MyTcpServer::newConnection()
{
// need to grab the socket
qDebug()<<"incoming connection";
QTcpSocket *socket =server->nextPendingConnection();
char* buf=new char[500];
connect(socket, SIGNAL(readyRead()), this, SLOT(readMessage()));
// socket->close();
delete[] buf;
}
void MyTcpServer::readMessage()
{
qDebug()<<"\nread start";
Command command;
QTcpSocket *socket= dynamic_cast<QTcpSocket *> ( this->sender());
//int len=socket->read((char*)(command.rawdata),1024);
QString sql_qurey;
QByteArray b=socket->readAll();
//socket->waitForReadyRead();
// qDebug()<<b;
data_print((UCHAR*)b.data(),b.length());
int len=b.length();
// GPS device raw data 2 array
memcpy(command.rawdata,b.data(),b.length());
qDebug()<<"length="<<len;
// data_print((UCHAR*)b.data(),b.length());
command.resolve_from_rawdata();
int fun_code= command.fun_code;
qDebug()<<"fun code"<<command.fun_code;
qDebug()<<"count"<<command.count;
if(FUN_CODE_REGISTER==fun_code)
{
command.register_sync_time();
}
if(FUN_DEVICE_RETUEN_TIME==fun_code )
{
command.configure(count); //do sth here
}
if(FUN_RETURN_CONFIGURE==fun_code)
{
//if it is return configure
//report 2 database, the confiure is done
command.finish_configure_database();
command.configure(count);
}
//gps data frame from device
if(FUN_DATA_UPLOAD==fun_code)
{
command.return_status();
//write to database
}
// data_print(command.rawdata,command.frame_length);
qDebug()<<"frame length read message"<<command.frame_length;
// data_print(command.rawdata,command.frame_length);
QByteArray write_data((char*)command.rawdata,command.frame_length);
int write_len=socket->write(write_data);
qDebug()<<"write len"<<write_len;
this->count++;
}
//debug function
void MyTcpServer::data_print(UCHAR* p,int length)
{
int i=0;
//QTextStream myout(stdout);
qDebug()<<"print start print length="<<length;
for(i=0;i<length;i++)
{
printf("%02x ",*(p+i));
}
// fflush(stdout);
qDebug()<<"print end";
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/dirausgang/gps-resolve.git
git@gitee.com:dirausgang/gps-resolve.git
dirausgang
gps-resolve
gps resolve
master

搜索帮助