void LogParser::onDataAvailable() { QByteArray data = _serialPort->readAll(); for(int i = 0; i < data.size(); i++) { _receivedDataQueue->enqueue((unsigned char)data.constData()[i]); } parseReceivedData(); }
// Server implementation void ReasonerCommunication::messageReceivedCB(std::shared_ptr<ServerClientMessage> msg, const char * message_data, uint64_t buffer_size){ ReasonerMessageDataType expectedResponse = parseReceivedData(message_data, buffer_size); //cout << "messageReceivedCB: " << (int) expectedResponse << endl; // always send a response ReasonerMessageData rmsd; // TODO check against our role if we can provide the requested data rmsd.containedData = expectedResponse; rmsd.reasonerID = this->reasonerID; switch (expectedResponse){ case (ReasonerMessageDataType::PROCESS) : { shared_ptr<ProcessHealth> payload (new ProcessHealth()); //= cb.getProcessHealth(); FIXME assert(payload); rmsd.messagePayload = &* payload; msg->isendResponse(& rmsd); break; } case (ReasonerMessageDataType::NODE) : { shared_ptr<NodeHealth> payload = cb.getNodeHealth(); assert(payload); rmsd.messagePayload = &* payload; msg->isendResponse(& rmsd); break; } case (ReasonerMessageDataType::SYSTEM) : { shared_ptr<SystemHealth> payload = cb.getSystemHealth(); assert(payload); rmsd.messagePayload = &* payload; msg->isendResponse(& rmsd); break; } default:{ rmsd.messagePayload = nullptr; msg->isendResponse(& rmsd); } } }
void AbstractHost::readCallback(ev::io &watcher, int revents) { int bytesRead = -1; char errorBuffer[128] = {'\0'}; memset(receiveBuffer, 0, 4096); bytesRead = recv(hostSocket, (void*)receiveBuffer, 4096, 0); if(bytesRead < 0 && !(errno == EAGAIN || errno == EWOULDBLOCK)) { // strerror_r(errno,errorBuffer,128); // throw std::runtime_error("Host socket read failed: "+std::string(errorBuffer)); throw std::runtime_error("Host socket read failed: "+std::string(strerror_r(errno,errorBuffer,128))); } else if (bytesRead == 0) { closeSocket(); } parseReceivedData(); }
void JumpropesCommon::HttpClient::done() { parseReceivedData(); stop(); onStatusUpdate.execute( JRHTTPSTATUS_DONE ); }
void LogParser::parseReceivedData() { if(_receivedDataQueue->size() < 3) return; unsigned char start = _receivedDataQueue->dequeue(); while(start != 0xDD && !_receivedDataQueue->isEmpty()) { if(start != 0xFF) // skip bytes received when cable disconnected qDebug() << "skipping unexpected data" << QString().sprintf("0x%02x", start); start = _receivedDataQueue->dequeue(); } /* if(_receivedDataQueue->size() >= 1) { if(_receivedDataQueue->at(0) != LOG_TYPE_STRING && _receivedDataQueue->at(0) !=LOG_TYPE_PHY_RX_RES && _receivedDataQueue->at(0) != LOG_TYPE_DLL_RX_RES) { qWarning(qPrintable(QString().sprintf("Unexpected type: 0x%02x, skipping ...", _receivedDataQueue->at(0)))); return; } } */ if(_receivedDataQueue->size() < 2 || _receivedDataQueue->size() < _receivedDataQueue->at(1) + 2) { // not a full packet, reinsert header and wait for more data ... _receivedDataQueue->insert(0, 0xDD); return; } u8 type = _receivedDataQueue->dequeue(); u8 len = _receivedDataQueue->dequeue(); if(type == LOG_TYPE_STRING) { QString msg; for(int i = 0; i < len; i++) { msg += QString(_receivedDataQueue->dequeue()); } emit logMessageReceived(msg); } if(type == LOG_TYPE_PHY_RX_RES) { QByteArray packetData; unsigned char byte; for(int i = 0; i < len; i++) { byte = _receivedDataQueue->dequeue(); packetData.append(byte); } Packet p; p.parsePhyRx(packetData); _packets.append(p); } if(type == LOG_TYPE_DLL_RX_RES) { QByteArray packetData; unsigned char byte; for(int i = 0; i < len; i++) { byte = _receivedDataQueue->dequeue(); packetData.append(byte); } if(_packets.isEmpty()) { qWarning("Received a DllRx while packets empty, probably the first log message received, skipping ..."); return; } Packet lastPacket = _packets.last(); if(lastPacket.hasDllInformation()) { QString msg = "Out of sync, got DLL data while current packet instance already has parsed DLL data"; qCritical(msg.toLocal8Bit()); qDebug() << msg; } lastPacket.parseDllRx(packetData); emit logMessageReceived(lastPacket.toString()); emit packetParsed(lastPacket); } parseReceivedData(); }
void ReasonerCommunication::messageResponseCB(BareMessage * msg, char * buffer, uint64_t buffer_size){ if ( msg->user_ptr == (size_t) ReasonerMessageDataType::NONE ){ return; } parseReceivedData(buffer, buffer_size); }