コード例 #1
0
void ClientMessenger::connect(string serverIP) {
	tcpSocket = new TCPSocket(serverIP, MSNGR_PORT);
	cout << readDataFromServer() << endl;
	cin >> username;
	sendDataToServer(username);
	cout << readDataFromServer() << endl;
	cin >> password;
	sendDataToServer(password);
	if ((readCommandFromServer()) == SESSION_ESTABLISHED_WITH_SERVER) {
		srand(time(NULL));
		myUDPport = rand() % 10500 + 10000;
		cout << "My UDP port is: " << myUDPport << endl;
		ostringstream convert;
		convert << myUDPport;
		cout << convert.str() << endl;
		sendDataToServer(convert.str());
		cout << "My UDP port is: " << myUDPport << endl;
		dispatcher = new ServerCommandDispatcher(this);
		dispatcher->start();
		connected = true;
		cout << "The server has approved your login" << endl;
	} else {
		perror("Error at login into the server");
		cout << "pls try again" << endl;
	}
}
コード例 #2
0
void ClientBackgroundManager::logout() {
    MessageEnvelop sendData(SEND_LOGOUT_REQUEST);
    emit sendDataToServer(sendData);

//    myClient2ServerThread.disconnect();
//    submitButton->setEnabled(true);
}
コード例 #3
0
void ClientBackgroundManager::callClient() {
    QObject* sendedFrom = sender();
    qDebug() << "Called callClient" << sendedFrom->objectName();
    //send message to server
    MessageEnvelop call(REQUEST_CALL_TO_CLIENT_FROM_SERVER);
    call.setName(sendedFrom->objectName());
    emit sendDataToServer(call);
    //myClient2ServerThread.sendMessageToServer(call);
    //GUI

}
コード例 #4
0
ファイル: ChatWidget.cpp プロジェクト: UgoM/info
/** \brief process and send input data
  */
void ChatWidget::returnPressed()
{
    QString text = textInput->text();
    if (text.isEmpty())
        return;

    QSettings settings;
    QString nick = settings.value("global/username").toString();
    emit sendDataToServer(nick + " : " + text);
    textInput->clear();
    qDebug() << "ChatWidget::returnPressed()" << text;
}
コード例 #5
0
void DeviceAcquisitionManager::onNewFrame(vector<Rect>* objects)
{
    //qDebug() << "onNewFrame";

    DeviceMessage deviceMessage;
    deviceMessage.id = mMessageId;

    for (int i = 0; i < objects->size(); ++i) {
        DeviceMessageObject deviceObject;
        Rect objectBounds = objects->at(i);

        deviceObject.x = objectBounds.x;
        deviceObject.y = objectBounds.y;
        deviceObject.width = objectBounds.width;
        deviceObject.height = objectBounds.height;

        deviceMessage.objects.append(deviceObject);
    }


    //qDebug() << deviceMessage.serializeToJson();
    sendDataToServer(deviceMessage.serializeToJson());
}
コード例 #6
0
ファイル: gsmModule.c プロジェクト: qermit/aprs-firmware
/**
 * Function establish connection with server
 * via GPRS service and send data
 */
uint8_t GSM_GPRSConnection(void)
{
	//=============DISCONNECT ALL
	GSM_SendCommand("AT+CGATT=0\r");
	GSM_SendCommand("AT+QICLOSE\r");
	delay_ms(5000);

	//============GPRS CONNECTION
	GSM_SendCommand("AT+CGDCONT=1,\"IP\",\"internet\",,0,0\r");
	if(GPRS_connectionReports()!=0x01)
		{return 1;}
	delay_ms(500);

	GSM_SendCommand("AT+CGATT=1\r");
	if(GPRS_connectionReports()!=0x01)
		{return 1;}
	delay_ms(500);
	//===========================

	//===========TCP/UDP connection
	recentServerResponseFlag = 0;
	GSM_SendCommand(GSM_ServerConf);
	if(GPRS_connectionReports()!=0x01)
		{return 1;}
	while ( !recentServerResponseFlag );
	if(recentServerResponseFlag == 0x01)
		{return 2;}
	//==============================

	//============SEND DEV_ID
	promptReceived = 0;
	GSM_SendCommand("AT+QISEND\r");
	while (!promptReceived);

	recentServerResponseFlag=0;
	GSM_SerialSendString("6382846480147182");
	GSM_TerminateDataSending();
	while(!recentServerResponseFlag);
	if(recentServerResponseFlag == 0x01)
		{return 2;}

	//===========SEND DATA
	promptReceived=0;
	GSM_SendCommand("AT+QISEND\r");
	while(!promptReceived);
	promptReceived=0;

	bytes = sendDataToServer();

	recentServerResponseFlag = 0;
	GSM_TerminateDataSending();
	while(!recentServerResponseFlag);
	if(recentServerResponseFlag == 0x01)
		{return 2;}

	//===========CLOSE CONNECTION
	GSM_SendCommand("AT+QICLOSE\r");
	GSM_SendCommand("AT+CGATT=0\r");

	return 0;
}
コード例 #7
0
ファイル: mainwindow.cpp プロジェクト: emi1988/gpsCar
void MainWindow::serialDataReceived()
{

    QString currentReceivedData = QString(m_serialPort->readAll());

    //add the buffered data from the last receive run
    currentReceivedData.prepend(m_receiveBuffer);

    //search for the start-character "$"
    QStringList currentGPSsentences = currentReceivedData.split("$");
    //save the last incomplete part in the buffer
    m_receiveBuffer.clear();
    m_receiveBuffer.append(currentGPSsentences.last());
    //remove the last incomplete sentence from the buffer
    currentGPSsentences.removeLast();

    //go through all sentences

    foreach (QString currentSentence, currentGPSsentences)
    {
        QStringList singleSentenceData = currentSentence.split(",");

        //just use the GPGGA-Information and check if it's already received completely
        if((singleSentenceData.at(0).compare("GPGGA")== 0) & (singleSentenceData.count() == 15))
        {

            //just save/send the gps-data if the m_msecondsBetweenWebSend is over
            quint64 currentTime = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000;

            if(currentTime > (m_lastSendetTime + m_secondsBetweenWebSend) )
            {
                m_lastSendetTime = currentTime;

                QStringList singleSentenceData = currentSentence.split(",");
                qDebug() << "GPGGA-Data: " << singleSentenceData;
                ui->textEditOutput->append("GPGGA-Data: " );

                foreach (QString sentenceData, singleSentenceData)
                {
                //     ui->textEditOutput->append(sentenceData);
                }

                qDebug() << "RapiTimestamp: " << currentTime;
                ui->textEditOutput->append("RapiTimestamp: " + QString::number(currentTime));

                //GPGGA-Data:  ("GPGGA", "213225.936", "", "", "", "", "0", "00", "", "", "M", "0.0", "M", "", "0000*5F ")
                //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45    //sum =15

                //check if received data is empty because of no gps-signal
                QString testData = singleSentenceData.at(2);
                if(testData.compare("") == 0)
                {
                    qDebug() << "gps-data is empty";
                    ui->textEditOutput->append("gps-data is empty");
                }
                else
                {
                    //gps-data is not empty -> process it

                    //save the current GPS-data
                    m_currentGPSdata.timeStampGPS = singleSentenceData.at(1);
                    m_currentGPSdata.latitude = singleSentenceData.at(2);
                    m_currentGPSdata.latitudeAlignment = singleSentenceData.at(3);
                    m_currentGPSdata.longitude = singleSentenceData.at(4);
                    m_currentGPSdata.longitudeAlignment = singleSentenceData.at(5);
                    m_currentGPSdata.satelliteAmount= singleSentenceData.at(7);
                    m_currentGPSdata.horizontalPrecision = singleSentenceData.at(8);
                    m_currentGPSdata.altitude = singleSentenceData.at(9);

                    m_currentGPSdata.timeStampRapi = QString::number(currentTime);

                    //convert position to decimal-degree
                    convertToDecimalCoordinates(m_currentGPSdata.latitude, m_currentGPSdata.latitudeAlignment, m_currentGPSdata.latitudeDecimal);
                    convertToDecimalCoordinates(m_currentGPSdata.longitude, m_currentGPSdata.longitudeAlignment, m_currentGPSdata.longitudeDecimal);

                    //send data to server
                    sendDataToServer(m_currentGPSdata, true);
                }
            }
コード例 #8
0
void ClientBackgroundManager::incommingCall(const QString name,
                                            const QHostAddress IP) {

    //info about incomming call
    qDebug() << "Called incommingCall " << name << " IP " << IP;
    //QStringList list = from.split(" ");

    //generating keys for threads
    std::ifstream rand("/dev/urandom",std::ios::binary);
    char *keyCharArray = new char[256];
    rand.read(keyCharArray, 256);
    rand.close();
    QString keyString(keyCharArray);
    delete[] keyCharArray;
    QString firstHalf = keyString.mid(0, 128);
    QString secondHalf = keyString.mid(128, 128);


    MessageEnvelop sendData(SEND_SUCCESS_RESPONSE_TO_COMMUNICATION);
    sendData.setPassword(keyString);
    emit sendDataToServer(sendData);

    //listen thread
    /*test*/myClient2ClientListenThread = new C2CListenThread();
    /*test*/myClient2ClientListenThread->startListener(IP, firstHalf);

    sleep(1); //wait for startListener init all right
    //write thread
    qDebug() << "write start";
    /*test*/myClient2ClientWriteThread = new C2CWriteThread();
    /*test*/myClient2ClientWriteThread->startOutput(IP, secondHalf);

    //GUI
    /*QMessageBox::StandardButton reply;
    reply = QMessageBox::question(this, "Hovor s " + name,
                                      "Chcete navazat hovor s hovor " + name + " Answer?",
                                      QMessageBox::Yes|QMessageBox::No);
    if(reply) { //answer
        MessageEnvelop sendData(SEND_SUCCESS_RESPONSE_TO_COMMUNICATION);
        emit sendDataToServer(sendData);

        myClient2ClientListenThread = new C2CListenThread();
        myClient2ClientListenThread->startListener(IP);

        QMessageBox::StandardButton really;
        really = QMessageBox::question(this, "Zapnete si mikrofon",
                                      "Zapli jste mikrofon?",
                                      QMessageBox::Yes|QMessageBox::No);
        if(really) {
            myClient2ClientWriteThread = new C2CWriteThread();
            myClient2ClientWriteThread->startOutput(IP, port);
            QMessageBox msgBox;
            msgBox.setText("You are speaking to" + name);
            msgBox.setStandardButtons(QMessageBox::Cancel);
            msgBox.exec();
            if(QMessageBox::Save) {
                MessageEnvelop sendData(END_OF_CALL_FROM_CLIENT);
                emit sendDataToServer(sendData);
            }
        }

    }
    else {//deny
        MessageEnvelop sendData(SEND_DENIED_RESPONSE_TO_COMMUNICATION);
        emit sendDataToServer(sendData);
        //myClient2ServerThread.sendMessageToServer(sendData);
    }*/
}
コード例 #9
0
void ClientBackgroundManager::call2() {
    MessageEnvelop call(REQUEST_CALL_TO_CLIENT_FROM_SERVER);
    call.setName("client2");
    emit sendDataToServer(call);
}
コード例 #10
0
ファイル: energycam.c プロジェクト: gedankennebel/ecpi
int main(int argc, char *argv[])
{

	//Projektwerkstatt
	if(argc != 4) {
		ErrorAndExit("Illegal number of Parameters");
	}
	//Projektwerkstatt

	int key=0;
	int  Reading;
	char OCR[20];
	char Version[20];

	int iReadRequest=0;

	int ReadingPeriod=10;
	int ReadingTimer=ReadingPeriod+1;

	uint16_t Data = 0;
	uint32_t Build = 0;
	uint32_t OCRData = 0;

	int iRetry = 3;
	int iTimeout = 0;

	int sock;
	int connected;

	Intro(ReadingPeriod);

	if (wiringPiSetup () == -1) {
		fprintf (stderr, "Not running on raspberry pi - now ending\n") ;
		exit(0);
	}

	EnergyCamOpen(0);  //open serial port

	//get Status & wakeup
	iRetry = 3;
	do {
	if(iRetry-- < 0 ) break;
	}while(MODBUSERROR == EnergyCam_GetManufacturerIdentification(&Data));

	if(Data == SAIDENTIFIER) {
		Colour(PRINTF_GREEN,false);
		printf("EnergyCAM Sensor connected ");
		Colour(0,true);
	} else {
		ErrorAndExit("EnergyCAM not found ");
	}

	//Read Buildnumber
	if (MODBUSOK == EnergyCam_GetAppFirmwareBuildNumber(&Build)) {
	  printf("Build %d \n",Build);
	}

	//Check Buildnumber, GetResultOCRInt requires Build 8374
	if (Build < 8374) {
	  ErrorAndExit("This App requires a Firmwareversion >= 8374. ");
	}

	//Is EnergyCam installed
	Data = DisplayInstallationStatus();

	//try to install the device if not installed
	if((Data == INSTALLATION_NODIGITS) || (Data == INSTALLATION_NOTDONE)){
		EnergyCam_TriggerInstallation();
		usleep(2000*1000);   //sleep 2000ms - wait for Installation
		printf("Installing ");
		iTimeout = 20;
		do {
			usleep(500*1000);   //sleep 500ms
			printf(".");
			if (MODBUSERROR == EnergyCam_GetResultOCRInstallation(&Data)) {
				Data = 0xFFFD; //retry if MODBUS returns with an Error
			}
		}
		while((iTimeout-->0) && (Data == 0xFFFD));
		printf("\n");

		//Is EnergyCam installed
		Data = DisplayInstallationStatus();
	}

	if((Data == INSTALLATION_NODIGITS) || (Data == INSTALLATION_NOTDONE) || (Data == INSTALLATION_FAILED) || (Data == INSTALLATION_ONGOING)){
		ErrorAndExit("EnergyCAM not installed ");
	}




	//get last Reading
	EnergyCam_TriggerReading();
	sleep(4);
	iRetry = 3;
	do{
		if(iRetry-- < 0) break;
	}while(MODBUSERROR == EnergyCam_GetStatusReading(&Data));
	if (MODBUSOK == EnergyCam_GetResultOCRInt(&OCRData,&Data)) {
	  time_t t = time(NULL);
	  struct tm tm = *localtime(&t);
	  printf("(%02d:%02d:%02d) Reading %04d.%d \n",tm.tm_hour,tm.tm_min,tm.tm_sec,OCRData,Data);
	  //Projektwerkstatt
	  sendDataToServer(argv[1],argv[2],argv[3],OCRData,Data);
	  //Projektwerkstatt
	  EnergyCam_Log2CSVFile("/var/www/ecpi/data/ecpi.csv",OCRData,Data);
	}

	IsNewMinute();
	ReadingTimer=ReadingPeriod+1;

	while (!((key == 0x1B) || (key == 'q')))
	{
		usleep(500*1000);   //sleep 500ms

		key = getkey();

		/*if(key == 'r')   {
		  iReadRequest++; //Read now
		}
		if(key == 'R')   {
			ReadingTimer=1;  //read in 1 minute

		  //get Status & wakeup
			iRetry = 3;
			do {
				if(iRetry-- < 0 ) break;
			}while(MODBUSERROR == EnergyCam_GetStatusReading(&Data));
			printf("GetStatusReading %04X \n",Data);

			//trigger new reading
			EnergyCam_TriggerReading();
		}*/


		if(IsNewMinute()){
		  if(--ReadingTimer<=1)iReadRequest++;
		  printf("%02d ",ReadingTimer);
		  fflush(stdout);
		  iRetry = 3;
                  do {
                      if(iRetry-- < 0 ) break;
                  }while(MODBUSERROR == EnergyCam_GetStatusReading(&Data));

                  //trigger new reading
		  EnergyCam_TriggerReading();
		}

		if(iReadRequest > 0) {
		  iReadRequest=0;
		  printf("%02d \n",ReadingTimer);
		  ReadingTimer=ReadingPeriod+1;

		  //get Status & wakeup
	  	  iRetry = 3;
		  do {
		    if(iRetry-- < 0 ) break;
		  }while(MODBUSERROR == EnergyCam_GetStatusReading(&Data));
		    //printf("GetStatusReading %04X \n",Data);
		    EnergyCam_GetOCRPicDone(&Data);
		    //printf("Pictures %04d \n",Data);
		    if (MODBUSOK == EnergyCam_GetResultOCRInt(&OCRData,&Data)) {
		    time_t t = time(NULL);
		    struct tm tm = *localtime(&t);
	    	    printf("(%02d:%02d:%02d) Reading %04d.%d \n",tm.tm_hour,tm.tm_min,tm.tm_sec,OCRData,Data);
		    //Projektwerkstatt
		    sendDataToServer(argv[1],argv[2],argv[3],OCRData,Data);
		    //Projektwerkstatt
		    EnergyCam_Log2CSVFile("/var/www/ecpi/data/ecpi.csv",OCRData,Data);
		  }
		}

	} // end while

	EnergyCamClose();

	return 0;
}