bool Loader::IsActivedUser(const QString& userName, const QString& password) { pTcpSocket = new QTcpSocket(this); QObject::connect(pTcpSocket, SIGNAL(readyRead()), this, SLOT(_readMessage())); QObject::connect(pTcpSocket, SIGNAL(disconnected()), this, SLOT(_disconnect())); pTcpSocket->connectToHost(ipAddress, 4305); return true; }
//--------------------------------------------------------------------------------- //-- Read MavLink message from GCS void MavESP8266GCS::readMessage() { //-- Read UDP if(_readMessage()) { //-- If we have a message, forward it _forwardTo->sendMessage(&_message); memset(&_message, 0, sizeof(_message)); } //-- Update radio status (1Hz) if(_heard_from && (millis() - _last_status_time > 1000)) { delay(0); _sendRadioStatus(); _last_status_time = millis(); } }
/** * @function single_read * @abstract Read at most 1 message from the network * @discussion * If a complete message is ready on the input buffer, will allocate and return it. * * This function manipulates the stream->nextMessageLength. (1) Initializes with nextMessageLength = 0, * which means we have not started parsing a packet. (2) After reading a FixedHeader, set nextMessageLength * to the total length of the message. (3) After reading nextMessageLength bytes, return the outputBuffer * and reset nextMessageLength to 0. * * @param input is the PARCEventBuffer to read * @param stream is the related stream state for the input * @return true if there's more to read after this message. */ static MetisMessage * _single_read(PARCEventBuffer *input, _MetisStreamState *stream) { size_t bytesAvailable = parcEventBuffer_GetLength(input); assertTrue(bytesAvailable >= metisTlv_FixedHeaderLength(), "Called with too short an input: %zu", bytesAvailable); if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug)) { metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug, __func__, "connid %u read %zu bytes", stream->id, bytesAvailable); } if (stream->nextMessageLength == 0) { _startNewMessage(stream, input, bytesAvailable); } // This is not an ELSE statement. We can both start a new message then // check if there's enough bytes to read the whole thing. if (bytesAvailable >= stream->nextMessageLength) { MetisMessage *message = _readMessage(stream, metisForwarder_GetTicks(stream->metis), input); if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug)) { metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug, __func__, "connid %u msg_length %zu read_length %zu, resetting parser", stream->id, stream->nextMessageLength, bytesAvailable); } // now reset message length for next packet stream->nextMessageLength = 0; return message; } return NULL; }