|
@@ -1,6 +1,8 @@
|
|
|
#include "mainwindow.h"
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
+
|
|
|
+
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
: QMainWindow(parent)
|
|
|
, ui(new Ui::MainWindow)
|
|
@@ -16,6 +18,37 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
ui->lineEdit_Lon->setText(QString::number(mfLon,'f',7));
|
|
|
ui->lineEdit_Lat->setText(QString::number(mfLat,'f',7));
|
|
|
|
|
|
+ QStandardItemModel* model = new QStandardItemModel();
|
|
|
+ mmodel = model;
|
|
|
+
|
|
|
+ /* 设置列数 */
|
|
|
+ model->setColumnCount(3);
|
|
|
+ model->setHeaderData(0, Qt::Horizontal, "ip");
|
|
|
+ model->setHeaderData(1, Qt::Horizontal, "port");
|
|
|
+
|
|
|
+ model->setHeaderData(2, Qt::Horizontal, "state");
|
|
|
+
|
|
|
+ /* 设置行数 */
|
|
|
+ model->setRowCount(100);
|
|
|
+
|
|
|
+ ui->tableView->setModel(model);
|
|
|
+
|
|
|
+ ui->tableView->horizontalHeader()->resizeSection(0,360);
|
|
|
+ ui->tableView->horizontalHeader()->resizeSection(1,100);
|
|
|
+ ui->tableView->horizontalHeader()->resizeSection(2,100);
|
|
|
+// /* 设置列宽在可视界面自适应宽度 */
|
|
|
+// ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
|
|
+ /* 行颜色交替显示 */
|
|
|
+ ui->tableView->setAlternatingRowColors(true);
|
|
|
+ /* 不允许在图形界面修改内容 */
|
|
|
+ ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
+
|
|
|
+ /* 在表格内加入内容 */
|
|
|
+
|
|
|
+
|
|
|
+ /* 显示表 */
|
|
|
+ ui->tableView->show();
|
|
|
+
|
|
|
mpntripclient = new ntrip_client(ui->lineEdit_serverip->text().toStdString(),
|
|
|
ui->lineEdit_serverport->text().toStdString(),
|
|
|
ui->lineEdit_servermountpoint->text().toStdString(),
|
|
@@ -30,6 +63,26 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
|
timer->start(100);
|
|
|
|
|
|
+ m_tcpserverNtrip = new QTcpServer(this);
|
|
|
+ m_tcpserverNtrip->listen(QHostAddress::Any,8002);//监听的端口号
|
|
|
+ m_tcpserverNtrip->setMaxPendingConnections(2000);
|
|
|
+ connect(m_tcpserverNtrip,SIGNAL(newConnection()), this,SLOT(newNtripConnect()));
|
|
|
+
|
|
|
+ ui->pushButton_Start->setText("Stop");
|
|
|
+ mbStart = true;
|
|
|
+ mpntripclient->setserverinfo(ui->lineEdit_serverip->text().toStdString(),
|
|
|
+ ui->lineEdit_serverport->text().toStdString(),
|
|
|
+ ui->lineEdit_servermountpoint->text().toStdString(),
|
|
|
+ ui->lineEdit_username->text().toStdString(),
|
|
|
+ ui->lineEdit_password->text().toStdString());
|
|
|
+
|
|
|
+ double flon = ui->lineEdit_Lon->text().toDouble();
|
|
|
+ double flat = ui->lineEdit_Lat->text().toDouble();
|
|
|
+
|
|
|
+
|
|
|
+ mpntripclient->SetLatLon(flon,flat);
|
|
|
+ mpntripclient->StartConnect();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
@@ -92,18 +145,69 @@ void MainWindow::onTimer()
|
|
|
}
|
|
|
setWindowTitle(strtitle);
|
|
|
}
|
|
|
+
|
|
|
+ mMutex.lock();
|
|
|
+ int nNCSize = mvectorNC.size();
|
|
|
+ int i;
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[nNCSize*1000+100]);
|
|
|
+ snprintf(pstr_ptr.get(),1000,"Ntrip Client:\n");
|
|
|
+
|
|
|
+
|
|
|
+ for(i=0;i<std::min(mnModelSize,nNCSize);i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ mmodel->setItem(i,0,new QStandardItem(mvectorNC[i]->mpSocket->peerAddress().toString().toLatin1().data()));
|
|
|
+ mmodel->setItem(i,1,new QStandardItem(QString::number(mvectorNC[i]->mpSocket->peerPort()).toLatin1().data()));
|
|
|
+ mmodel->setItem(i,2,new QStandardItem(QString::number(mvectorNC[i]->mnState).toLatin1().data()));
|
|
|
+ char strout[1000];
|
|
|
+ snprintf(strout,1000,"IP:%s Port:%d State:%d\n",
|
|
|
+ mvectorNC[i]->mpSocket->peerAddress().toString().toLatin1().data(),
|
|
|
+ mvectorNC[i]->mpSocket->peerPort(),
|
|
|
+ mvectorNC[i]->mnState);
|
|
|
+ strncat(pstr_ptr.get(),strout,1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=nNCSize;i<mnModelSize;i++)
|
|
|
+ {
|
|
|
+ mmodel->setItem(i,0,new QStandardItem(""));
|
|
|
+ mmodel->setItem(i,1,new QStandardItem(""));
|
|
|
+ mmodel->setItem(i,2,new QStandardItem(""));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ mMutex.unlock();
|
|
|
+// if(nNCSize > 0)
|
|
|
+// {
|
|
|
+// ui->plainTextEdit_Client->setPlainText(pstr_ptr.get());
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// ui->plainTextEdit_Client->setPlainText("No Connected.");
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
void MainWindow::onupdatentripmsg(QByteArray ba)
|
|
|
{
|
|
|
if(ba.size()<1)return;
|
|
|
+
|
|
|
+ int i;
|
|
|
+ mMutex.lock();
|
|
|
+ int nNCSize = mvectorNC.size();
|
|
|
+ for(i=0;i<nNCSize;i++)
|
|
|
+ {
|
|
|
+ mvectorNC[i]->mpSocket->write(ba);
|
|
|
+ mvectorNC[i]->mpSocket->flush();
|
|
|
+ }
|
|
|
+ mMutex.unlock();
|
|
|
+
|
|
|
+
|
|
|
char * strout = 0;
|
|
|
std::shared_ptr<char> str_ptr = std::shared_ptr<char>(new char[ba.size()*3 + 100]);
|
|
|
strout = str_ptr.get();
|
|
|
- snprintf(strout,3000,"Ntrip msg len is %d info is: ",ba.length());
|
|
|
+ snprintf(strout,3000,"Ntrip msg len is %d \ninfo : ",ba.length());
|
|
|
char strtem[10];
|
|
|
int nlen = ba.length();
|
|
|
- int i;
|
|
|
+
|
|
|
for(i=0;i<nlen;i++)
|
|
|
{
|
|
|
snprintf(strtem,10,"%02X ",(unsigned char )ba.at(i));
|
|
@@ -112,3 +216,135 @@ void MainWindow::onupdatentripmsg(QByteArray ba)
|
|
|
|
|
|
ui->plainTextEdit_NTIPMSG->setPlainText(strout);
|
|
|
}
|
|
|
+
|
|
|
+void MainWindow::newNtripConnect()
|
|
|
+{
|
|
|
+ qDebug("new connect");
|
|
|
+ QTcpSocket * pSocket = m_tcpserverNtrip->nextPendingConnection();
|
|
|
+ if(pSocket != NULL)
|
|
|
+ {
|
|
|
+ pSocket->setSocketOption(QAbstractSocket::LowDelayOption,1);
|
|
|
+ connect(pSocket,SIGNAL(readyRead()),this,SLOT(readNtripMessage()));
|
|
|
+ connect(pSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorNtrip()));
|
|
|
+ connect(pSocket,SIGNAL(disconnected()),this,SLOT(disconnetNtrip()));
|
|
|
+ std::shared_ptr<NtripClient> p = std::shared_ptr<NtripClient>( new NtripClient);
|
|
|
+ p->mnState = 0;
|
|
|
+ p->mpSocket = pSocket;
|
|
|
+
|
|
|
+// p->mLat = 0;
|
|
|
+// p->mLon = 0;
|
|
|
+ mMutex.lock();
|
|
|
+ mvectorNC.push_back(p);
|
|
|
+ mMutex.unlock();
|
|
|
+// mnNCCount++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::readNtripMessage()
|
|
|
+{
|
|
|
+ QTcpSocket * pSocket = static_cast<QTcpSocket *>(this->sender());
|
|
|
+ QByteArray ba = pSocket->readAll();
|
|
|
+ int i;
|
|
|
+ bool bNeedClose = false;
|
|
|
+ mMutex.lock();
|
|
|
+ for(i=0;i<mvectorNC.size();i++)
|
|
|
+ {
|
|
|
+ if(pSocket == mvectorNC.at(i)->mpSocket)
|
|
|
+ {
|
|
|
+ //Send Auth.
|
|
|
+
|
|
|
+ char * str = new char[ba.length() +1];
|
|
|
+ str[ba.length()] = 0;
|
|
|
+ memcpy(str,ba.data(),ba.length());
|
|
|
+// qDebug(str);
|
|
|
+ if(strstr(str,"GET / HTTP") >0)
|
|
|
+ {
|
|
|
+ QDateTime dt = QDateTime::currentDateTime();
|
|
|
+
|
|
|
+ char strSend[1000];
|
|
|
+ char strLine[200];
|
|
|
+ sprintf(strSend,"SOURCETABLE 200 OK\r\n");
|
|
|
+ sprintf(strLine,"Server: NTRIP Trimble NTRIP Caster\r\n");strcat(strSend,strLine);
|
|
|
+ sprintf(strLine,"Content-Type: text/plain");strcat(strSend,strLine);
|
|
|
+ sprintf(strLine,"Content-Length: 111");strcat(strSend,strLine);
|
|
|
+ sprintf(strLine,"Date: %s\r\n",dt.toString(Qt::ISODate).toLatin1().data());strcat(strSend,strLine);
|
|
|
+ qDebug(strLine);
|
|
|
+ // sprintf(strLine,"STR;RTCM23;RTCM23;RTCM 2.3;1(1),3(10),18(1),19(1);2;GPS;SGNET;CHN;31;121;1;1;SGCAN;None;B;N;0;;\r\n");strcat(strSend,strLine);
|
|
|
+ // sprintf(strLine,"STR;RTCM32_GGB;RTCM3X;RTCM 3.X;1004(1),1005/1007(5),PBS(10);2;GPS;SGNET;CHN;31;121;1;1;SGCAN;None;B;N;0;;\r\n");strcat(strSend,strLine);
|
|
|
+ sprintf(strLine,"STR;RTCM32_GGB;RTCM32_GGB;RTCM 3.2;RTCM(1);2;GPS+GLONASS;SGNET;CHN;39.14;117.08;1;1;Trimble BD982;none;B;N;0;\r\n");strcat(strSend,strLine);
|
|
|
+ // sprintf(strLine,"");strcat(strSend,strLine);
|
|
|
+ sprintf(strLine,"ENDSOURCETABLE\r\n");strcat(strSend,strLine);
|
|
|
+ pSocket->write(strSend,strlen(strSend));
|
|
|
+ pSocket->flush();
|
|
|
+ qDebug("send ggb");
|
|
|
+
|
|
|
+ bNeedClose = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(strstr(str,"NTRIP") > 0)
|
|
|
+ {
|
|
|
+ qDebug(str);
|
|
|
+ qDebug("send cors ok");
|
|
|
+ char * strSend = new char[1000];
|
|
|
+ snprintf(strSend,1000,"ICY 200 OK\r\n");
|
|
|
+ pSocket->write(strSend,strlen(strSend));
|
|
|
+ pSocket->flush();
|
|
|
+ delete strSend;
|
|
|
+ mvectorNC.at(i)->mnState = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+ if(strstr(str,"$GPGGA") > 0)
|
|
|
+ {
|
|
|
+ qDebug(str);
|
|
|
+ // SetNCLatLon(str,mListNC.at(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ delete str;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mMutex.unlock();
|
|
|
+ if(bNeedClose )
|
|
|
+ {
|
|
|
+ pSocket->close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::errorNtrip()
|
|
|
+{
|
|
|
+ QTcpSocket * pSocket = static_cast<QTcpSocket *>(this->sender());
|
|
|
+ mMutex.lock();
|
|
|
+ int i;
|
|
|
+ for(i=0;i<mvectorNC.size();i++)
|
|
|
+ {
|
|
|
+ if(pSocket == mvectorNC.at(i)->mpSocket)
|
|
|
+ {
|
|
|
+ mvectorNC.erase(mvectorNC.begin()+i);
|
|
|
+// mnNCCount--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mMutex.unlock();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::disconnetNtrip()
|
|
|
+{
|
|
|
+ qDebug("disconnect");
|
|
|
+ QTcpSocket * pSocket = static_cast<QTcpSocket *>(this->sender());
|
|
|
+ mMutex.lock();
|
|
|
+ int i;
|
|
|
+ for(i=0;i<mvectorNC.size();i++)
|
|
|
+ {
|
|
|
+ if(pSocket == mvectorNC.at(i)->mpSocket)
|
|
|
+ {
|
|
|
+ mvectorNC.erase(mvectorNC.begin()+i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mMutex.unlock();
|
|
|
+}
|
|
|
+
|