void NodesManager::checkIfNodeDescriptionComplete(unsigned id, const Node& description) { // we will call the virtual function only when we have received all local events and native functions if (description.isComplete() && description.connected) { nodeDescriptionReceived(id); nodeConnected(id); } }
void jarvisNodeTestApp::connectNodeSignals(sJarvisNode* node) { connect(node,SIGNAL(tx()),&m_rxWidget,SLOT(tx())); connect(node,SIGNAL(rx()),&m_rxWidget,SLOT(rx())); connect(node,SIGNAL(rawInput(QByteArray)),this,SLOT(console_log(QByteArray))); connect(node,SIGNAL(writeData(QByteArray)),this,SLOT(console_log(QByteArray))); connect(node,SIGNAL(incomingEvent(QString,jarvisEvents,QStringList)),this,SLOT(eventLog(QString,jarvisEvents,QStringList))); //connect(node,SIGNAL(newComponent(sJarvisNodeComponent*)),this,SLOT(addComponent(sJarvisNodeComponent*))); //connect(&m_sensorsTimer,SIGNAL(timeout()),this,SLOT(timedCmd())); connect(node,SIGNAL(sensorReads(QVector<QString>,QVector<double>)),this,SLOT(sensorRead(QVector<QString>,QVector<double>))); connect(node,SIGNAL(ready()),this,SLOT(nodeConnected())); connect(node,SIGNAL(disconnected()),this,SLOT(nodeDisconnected())); connect(ui->sliderUpdateInterval,SIGNAL(sliderMoved(int)),node,SLOT(setUpdateInterval(int))); connect(ui->btnReset,SIGNAL(clicked()),node,SLOT(resetNode())); }
void NodesManager::processMessage(const Message* message) { // check whether the node is known NodesMap::iterator nodeIt(nodes.find(message->source)); if (nodeIt == nodes.end()) { // node is not known, so ignore excepted if the message type // is node present and it is not a known mismatch protocol, // in that case, request description... if ((message->type == ASEBA_MESSAGE_NODE_PRESENT) && mismatchingNodes.find(message->source) == mismatchingNodes.end()) { GetNodeDescription getNodeDescription(message->source); sendMessage(getNodeDescription); } // or if message type is description, in that case, proceed further if (message->type != ASEBA_MESSAGE_DESCRIPTION) return; } else { // node is known, check if connected... if (!nodeIt->second.connected) { // if not, build complete, set as connected and notify client nodeIt->second.connected = true; if (nodeIt->second.isComplete()) { // only notify connections of completed known nodes nodeConnected(nodeIt->first); } } // update last seen time nodeIt->second.lastSeen = UnifiedTime(); } // if we have a disconnection message { // FIXME: handle disconnected state const Disconnected *disconnected = dynamic_cast<const Disconnected *>(message); if (disconnected) { NodesMap::iterator nodeIt = nodes.find(disconnected->source); assert (nodeIt != nodes.end()); nodes.erase(nodeIt); } } // if we have an initial description { const Description *description = dynamic_cast<const Description *>(message); if (description) { NodesMap::iterator nodeIt = nodes.find(description->source); // We can receive a description twice, for instance if there is another IDE connected if (nodeIt != nodes.end() || (mismatchingNodes.find(description->source) != mismatchingNodes.end())) return; // Call a user function when a node protocol version mismatches if ((description->protocolVersion < ASEBA_MIN_TARGET_PROTOCOL_VERSION) || (description->protocolVersion > ASEBA_PROTOCOL_VERSION)) { nodeProtocolVersionMismatch(description->source, description->name, description->protocolVersion); mismatchingNodes.insert(description->source); return; } // create node and copy description into it nodes[description->source] = Node(*description); checkIfNodeDescriptionComplete(description->source, nodes[description->source]); } } // if we have a named variable description { const NamedVariableDescription *description = dynamic_cast<const NamedVariableDescription *>(message); if (description) { NodesMap::iterator nodeIt = nodes.find(description->source); assert (nodeIt != nodes.end()); // copy description into array if array is empty if (nodeIt->second.namedVariablesReceptionCounter < nodeIt->second.namedVariables.size()) { nodeIt->second.namedVariables[nodeIt->second.namedVariablesReceptionCounter++] = *description; checkIfNodeDescriptionComplete(nodeIt->first, nodeIt->second); } } } // if we have a local event description { const LocalEventDescription *description = dynamic_cast<const LocalEventDescription *>(message); if (description) { NodesMap::iterator nodeIt = nodes.find(description->source); assert (nodeIt != nodes.end()); // copy description into array if array is empty if (nodeIt->second.localEventsReceptionCounter < nodeIt->second.localEvents.size()) { nodeIt->second.localEvents[nodeIt->second.localEventsReceptionCounter++] = *description; checkIfNodeDescriptionComplete(nodeIt->first, nodeIt->second); } } } // if we have a native function description { const NativeFunctionDescription *description = dynamic_cast<const NativeFunctionDescription *>(message); if (description) { NodesMap::iterator nodeIt = nodes.find(description->source); assert (nodeIt != nodes.end()); // copy description into array if (nodeIt->second.nativeFunctionReceptionCounter < nodeIt->second.nativeFunctions.size()) { nodeIt->second.nativeFunctions[nodeIt->second.nativeFunctionReceptionCounter++] = *description; checkIfNodeDescriptionComplete(nodeIt->first, nodeIt->second); } } } }