コード例 #1
0
ファイル: uart_thread.c プロジェクト: liubins313/k60-rtt1.20
//串口数据处理线程
void uart3_deal_entry(void* parameter)
{
		rt_uint8_t buf[MAXLEN];
		rt_uint8_t len_send;
		rt_sem_take(sem, RT_WAITING_FOREVER);
    while(1)
    {
			rt_sem_take(sem, RT_WAITING_FOREVER);
			rt_kprintf("received a packet\r\n");
			if((recvcnt=dataunpack(uartbuff,uartrecvcnt,buf)) != 0)//对接收的数据进行解包放到buf中,解包后数据长度recvcnt
			{
				rt_uint8_t i;
				
				for(i=0;i<recvcnt;i++)
				{
						rt_kprintf("%02x ",buf[i]); 
				}
				
				len_send =	datapack(buf,2,uartbuff);//将要发送的buf中的2个数据进行打包后放到uartbuff中,打包后数据长度len_send
				rt_device_write(device,0,uartbuff,len_send);
			}
			uartrecvcnt = 0;
			uartbuff = uartcatch;
			curuartptr = uartcatch;
			uartstate = UART_IDLE;
			
    }
}
コード例 #2
0
void MainWindow::connectTheExternalSocket()
{
    //check the certificat
    {
        QDir datapack(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
        datapack.mkpath(datapack.absolutePath());
        QFile certFile;
        certFile.setFileName(datapack.absolutePath()+QStringLiteral("/pub.key"));
        if(certFile.exists())
        {
            if(realSslSocket->mode()==QSslSocket::UnencryptedMode)
            {
                SslCert sslCert(this);
                sslCert.exec();
                if(sslCert.validated())
                    saveCert(certFile.fileName());
                else
                {
                    realSslSocket->disconnectFromHost();
                    return;
                }
            }
            else if(certFile.open(QIODevice::ReadOnly))
            {
                if(realSslSocket->peerCertificate().publicKey().toPem()!=certFile.readAll())
                {
                    SslCert sslCert(this);
                    sslCert.exec();
                    if(sslCert.validated())
                        saveCert(certFile.fileName());
                    else
                    {
                        realSslSocket->disconnectFromHost();
                        return;
                    }
                }
                certFile.close();
            }
        }
        else
        {
            if(realSslSocket->mode()!=QSslSocket::UnencryptedMode)
                saveCert(certFile.fileName());

        }
    }
    //continue the normal procedure
    socket=new CatchChallenger::ConnectedSocket(realSslSocket);
    CatchChallenger::Api_client_real::client=new CatchChallenger::Api_client_real(socket);
    if(!proxy_dns_or_ip.isEmpty())
    {
        QNetworkProxy proxy=realSslSocket->proxy();
        proxy.setType(QNetworkProxy::Socks5Proxy);
        proxy.setHostName(proxy_dns_or_ip);
        proxy.setPort(proxy_port);
        static_cast<CatchChallenger::Api_client_real *>(CatchChallenger::Api_client_real::client)->setProxy(proxy);
    }
    connect(CatchChallenger::Api_client_real::client,               &CatchChallenger::Api_protocol::protocol_is_good,   this,&MainWindow::protocol_is_good,Qt::QueuedConnection);
    connect(CatchChallenger::Api_client_real::client,               &CatchChallenger::Api_protocol::disconnected,       this,&MainWindow::disconnected);
    connect(CatchChallenger::Api_client_real::client,               &CatchChallenger::Api_protocol::message,            this,&MainWindow::message,Qt::QueuedConnection);
    connect(CatchChallenger::Api_client_real::client,               &CatchChallenger::Api_protocol::logged,             this,&MainWindow::logged,Qt::QueuedConnection);
    CatchChallenger::BaseWindow::baseWindow->connectAllSignals();
    CatchChallenger::BaseWindow::baseWindow->setMultiPlayer(true);
    QDir datapack(QStandardPaths::writableLocation(QStandardPaths::DataLocation)+QStringLiteral("/datapack/"));
    if(!datapack.exists())
        if(!datapack.mkpath(datapack.absolutePath()))
        {
            disconnected(tr("Not able to create the folder %1").arg(datapack.absolutePath()));
            return;
        }
    CatchChallenger::Api_client_real::client->setDatapackPath(datapack.absolutePath());
    MapController::mapController->setDatapackPath(CatchChallenger::Api_client_real::client->datapackPath());
    CatchChallenger::BaseWindow::baseWindow->stateChanged(QAbstractSocket::ConnectedState);
    CatchChallenger::Api_client_real::client->sendProtocol();
}