Beispiel #1
0
void QvisController::createTCPThread()
{
    if (ui->getPort() != 3490) {
        ui->setInfoText("Atlas is on port 3940");
        return;
    }
    
    ui->setConnectionStatus(true);

    tcpSocket = new QTcpSocket(this);
    
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readTCP()));
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));

    tcpSocket->connectToHost(ui->getIp(),ui->getPort());
    
    QObject::connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(closeTCP()));
    std::cout << "Connection button set to close" << std::endl;
    tcpSocket->write(getSendData(), 54);
    ui->setConnected();
}
Beispiel #2
0
LHMailBase* LHMail::attachSignature (LHMailSignature &signature)
{
        qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "12346789");

	LHMailPart* mp = new LHMailPart (this);

        if (getPartCount () > 1) {
                QString partsText = getSendData (DataToSign);
                QString newBoundary = LHMime::getBoundaryString ();
                QString oldBoundary = header ().getParameter ("Content-Type", "boundary");
                partsText.replace (oldBoundary, newBoundary);

#               if 1
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
                qDebug()<<partsText;
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
#               endif

                removePart (NULL);
		LHMailPart* mpb = new LHMailPart (this);
		addPart(mpb);

		mpb->header ().setData ("Content-Type", "Multipart/Mixed");
		mpb->header ().setParameter ("Content-Type", "boundary", newBoundary);
                mpb->setBodySendData (partsText);
		mpb->setEncoding (encoding());
                
        }

        /**
         *  Aply this LHMail object to the signature object. The body of mail
         *  is essntial when signing.
         */
         
	if (attachPart (mp))
	{

                // if (getPartCount () == 2 && body.isEmpty ())
                if (getPartCount () != 2) {
                        // qFatal ("*** %s,%d : %s", __FILE__, __LINE__, "!2");
                        return NULL;
                }

                QString body = getPart (0)->getSendData ();
        
                signature.setBody (body);
                signature.load ();

#               if 1
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
                qDebug()<<body;
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
#               endif

		header ().setData ("Content-Type", "multipart/signed");
                header ().setParameter ("Content-Type", "micalg", "sha1");
                header ().setParameter ("Content-Type", "protocol", "application/x-pkcs7-signature");
                
	        mp->setSignature (signature.getData ());
                
		return mp;
	}
	
	//not here if success
	delete mp;
	return 0;
}
Beispiel #3
0
void QvisController::readTCP()
{
    while (tcpSocket->bytesAvailable()>0) {

        if (numbytes==0 && tcpSocket->bytesAvailable()>5) {
            
            data = tcpSocket->read(5);
            qs = data;
            numbytes = qs.mid(0,2).toInt();
            imgChar = qs.mid(3,1).toInt();
            
            if (imgChar==1) {
                recvImg=true;
            }
            else {
                recvImg=false;
            }
        }
        
        if (!recvImg && tcpSocket->bytesAvailable()>=numbytes) {
            
            data = tcpSocket->read(numbytes);
            qs = data;

            pieces = qs.split(" ");
            ui->setDataFields(pieces);
            numbytes = 0;

            // When done reading send back the input data
            tcpSocket->write(getSendData(), 54);
        }
        
        if (recvImg && tcpSocket->bytesAvailable()>=(numbytes+230400)) {
            std::cout << "Reading data and image" << std::endl;

            data = tcpSocket->read(numbytes);
            qs = data;
            pieces = qs.split(" ");
            ui->setDataFields(pieces);
            numbytes = 0;
            
            data = tcpSocket->read(imgSize);
            int ptr=0;
            for (int i = 0;  i < bufFrame.rows; i++) {
                for (int j = 0; j < bufFrame.cols; j++) {
                    bufFrame.at<cv::Vec3b>(i,j) = cv::Vec3b(data[ptr+ 0],data[ptr+1],data[ptr+2]);
                    ptr=ptr+3;
                }
            }
            
            qImageBuffer = (const uchar*)bufFrame.data;
            QImage img(qImageBuffer, bufFrame.cols, bufFrame.rows, bufFrame.step, QImage::Format_RGB888);
            img = img.rgbSwapped();
            if (videoStream) {
                ui->updateImg(img);
            }
            
            // When done reading, send back the input data
            tcpSocket->write(getSendData(), 54);
        }
        
        else {
            return;
        }
    }
}