static inline void unLockNode(Node *node) { IDnum nodeID = getNodeID(node); if (nodeID < 0) nodeID = -nodeID; omp_unset_lock (nodeLocks + nodeID); }
/** Special entry point if the player is challeged */ void ninjaChallenged(NinjaPacket packet) { //Ignore RF-related popups while they play disablePopups(); bool accept = false; PeerNode peer; NinjaState state; //Find the peer for (uint8_t i = 0; i < PEER_NODES_MAX; i++) { if (peers[i].lastSeen > 0) { if (peers[i].nodeid == packet.src) { peer = peers[i]; char b[50]; sprintf(b, "Accept Ninja\nChallenge from\n%s?", packet.src); accept = yesNoDialog(b); } } } //If the peer is known and the user accepts, ACK if (accept) { packet.type = TYPE_ACK; state.p2nodeid = peer.nodeid; state.p2Level = peer.level; state.p2Name = peer.name; state.lastACK = -1; state.lastNACK = -1; //Unwrap the tiebreaker if ((packet.data & B00000100) > 0) state.tiebreaker[0] = false; else state.tiebreaker[0] = true; if ((packet.data & B00000010) > 0) state.tiebreaker[1] = false; else state.tiebreaker[1] = true; if ((packet.data & B00000001) > 0) state.tiebreaker[2] = false; else state.tiebreaker[2] = true; } else { packet.type = TYPE_NACK; } //Repurpose the packet to send it back packet.dest = packet.src; packet.src = getNodeID(); packet.data = TYPE_INIT; //Send the NACK or ACK three times for (uint8_t i = 0; i < 5; i + 0) { if (ANXRFAvailable()) { ANXRFSend(&packet, NINJA_PACKET_SIZE); i++; } deepSleep(random(100) + 100); tick(); } //Play the game if they ack if (accept) { _doNinja(&state, &packet); } enablePopups(); }
uint8_t RF24Mesh::getNodeId(uint16_t address){ if(!getNodeID()){ //Master Node for(uint8_t i=0; i<addrListTop; i++){ if(addrList[i].address == address){ return addrList[i].nodeID; } } } return 0; }
/** Handle packets, updating game state as appropriate */ static bool _handlePackets(NinjaState *state, NinjaPacket *packet) { //Get a packet if (ninjaPacketAvailable) { //If we received a move packet, do something with it and ACK if (lastNinjaPacket.type == TYPE_MOVE) { //Only accept moves for this round if (lastNinjaPacket.round == state->round) { state->p2Move = lastNinjaPacket.data; //ACK the move packet->type = TYPE_ACK; packet->data = TYPE_MOVE; //ACK the move //Try to send the packet 5 times for (uint8_t i = 0; i < 5; i++) { //Delay a bit deepSleep(random(30) + 40); if (ANXRFSend(packet, NINJA_PACKET_SIZE)) break; } } } //ACK any latent INIT packets (challenger never got our previous ACKs) if (lastNinjaPacket.type == TYPE_INIT && state->state == STATE_SELECT_MOVE && lastNinjaPacket.src == state->p2nodeid) { packet->type = TYPE_ACK; packet->dest = state->p2nodeid; packet->src = getNodeID(); packet->data = TYPE_INIT; //Try to send the packet 5 times for (uint8_t i = 0; i < 5; i++) { //Delay a bit deepSleep(random(30) + 40); if (ANXRFSend(packet, NINJA_PACKET_SIZE)) break; } } //Handle if it's an ACK if (lastNinjaPacket.type == TYPE_ACK) { state->lastACK = lastNinjaPacket.data; } //Handle if it's a NACK if (lastNinjaPacket.type == TYPE_NACK) { state->lastNACK = lastNinjaPacket.data; } //Reset packet buffer ninjaPacketAvailable = false; } }
static void projectFromReadPair(Node * node, ReadOccurence * readOccurence, Coordinate position, Coordinate offset, Coordinate insertLength, double insertVariance) { Coordinate distance = insertLength; Coordinate variance = insertVariance; Node *target = getNodeInGraph(graph, readOccurence->nodeID); if (target == getTwinNode(node) || target == node) return; if (getUniqueness(target) && getNodeID(target) < getNodeID(node)) return; if (position < 0) { variance += getNodeLength(node) * getNodeLength(node) / 16; // distance += 0; } else { // variance += 0; distance += position - offset - getNodeLength(node) / 2; } if (readOccurence->position < 0) { variance += getNodeLength(target) * getNodeLength(target) / 16; //distance += 0; } else { // variance += 0; distance += readOccurence->position - readOccurence->offset - getNodeLength(target) / 2; } if (distance - getNodeLength(node)/2 - getNodeLength(target)/2 < -6 * sqrt(insertVariance)) return; else if (distance < getNodeLength(node)/2 + getNodeLength(target)/2) distance = getNodeLength(node)/2 + getNodeLength(target)/2; createConnection(getNodeID(node), getNodeID(target), 0, 1, distance, variance); }
static void setEmptyMiniConnection(Node * node) { MiniConnection *localConnect = &localScaffold[getNodeID(node) + nodeCount(graph)]; localConnect->distance = 0; localConnect->variance = 1; localConnect->frontReference = NULL; localConnect->backReference = NULL; localConnect->nodeList = recordNode(node); setSingleNodeStatus(node, true); }
void RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate){ //radio.begin(); if(getNodeID()){ //Not master node mesh_address = MESH_DEFAULT_ADDRESS; }else{ #if !defined (RF24_TINY) && !defined(MESH_NOMASTER) addrList = (addrListStruct*)malloc(2 * sizeof(addrListStruct)); loadDHCP(); #endif mesh_address = 0; } radio_channel = channel; radio.setChannel(radio_channel); radio.setDataRate(data_rate); network.begin(mesh_address); network.returnSysMsgs = 1; if(getNodeID()){ //Not master node renewAddress(); } }
const KinematicNode* KinematicTree::getRootNode() const { static const std::string rootName = "root"; static const KinematicNode* ret = nullptr; if (nullptr == ret) { const NodeID rootID = getNodeID(rootName); ret = getNode(rootID); } return ret; }
void Dispatcher::handleLoopbackFrame(const CanRxFrame& can_frame) { RxFrame frame; if (!frame.parse(can_frame)) { UAVCAN_TRACE("Dispatcher", "Invalid loopback CAN frame: %s", can_frame.toString().c_str()); UAVCAN_ASSERT(0); // No way! return; } UAVCAN_ASSERT(frame.getSrcNodeID() == getNodeID()); loopback_listeners_.invokeListeners(frame); }
void FilterIOConfigurationWindow::update() { auto nodeID = getNodeID(); if (auto* graph = getGraph()) if (nodeID != AudioProcessorGraph::NodeID()) graph->disconnectNode (nodeID); if (auto* graphEditor = getGraphEditor()) if (auto* panel = graphEditor->graphPanel.get()) panel->updateComponents(); }
static void projectFromSingleRead(Node * node, ReadOccurence * readOccurence, Coordinate position, Coordinate offset, Coordinate length) { Coordinate distance = 0; Node *target = getNodeInGraph(graph, -readOccurence->nodeID); double variance = 1; if (target == getTwinNode(node) || target == node) return; if (position < 0) { variance += getNodeLength(node) * getNodeLength(node) / 16; // distance += 0; } else { // variance += 0; distance += position - offset - getNodeLength(node) / 2; } if (readOccurence->position < 0) { variance += getNodeLength(target) * getNodeLength(target) / 16; //distance += 0; } else { // variance += 0; distance += -readOccurence->position + readOccurence->offset + getNodeLength(target) / 2; } if (position < 0 || readOccurence->position < 0) { if (offset < readOccurence->offset && distance - getNodeLength(node)/2 - getNodeLength(target)/2 < -10) return; if (offset > readOccurence->offset && distance - getNodeLength(node)/2 - getNodeLength(target)/2 > 10) return; variance += length * length / 16; createConnection(getNodeID(node), getNodeID(target), 1, 0, distance, variance); createConnection(-getNodeID(node), -getNodeID(target), 1, 0, -distance, variance); } else if (distance > 0) { createConnection(getNodeID(node), getNodeID(target), 1, 0, distance, variance); } else { createConnection(-getNodeID(node), -getNodeID(target), 1, 0, -distance, variance); } }
int tree::build_affix_tree_from_file(item_types type) { //out<<QDateTime::currentDateTime().time().toString()<<"\n"; #ifndef LOAD_FROM_FILE return build_affix_tree(type); #else file=NULL; reset(); isAffix=true; this->type=type; QString fileName; if (type==PREFIX) fileName=prefix_tree_path; else if (type==SUFFIX) fileName=suffix_tree_path; reverseIDMap.clear(); QFile file(fileName.toStdString().data()); if (file.open(QIODevice::ReadOnly)) { QDataStream in(&file); // read the data serialized from the file QString version; in >> version; if (version==cache_version()) { int num1,num2; QString letters; long affix_id;long category_id; long resulting_category_id;bool isAccept; #if defined (REDUCE_THRU_DIACRITICS) QString raw_data,inflected_raw_data,descriptionInflectionRule; #elif defined (MEMORY_EXHAUSTIVE) QString raw_data;QString description; #endif while(!in.atEnd()) { in>>letters>>affix_id>>category_id>>resulting_category_id>>isAccept #if defined (REDUCE_THRU_DIACRITICS) >>raw_data>>inflected_raw_data>>descriptionInflectionRule #elif defined (MEMORY_EXHAUSTIVE) >>raw_data>>description #endif >>num1>>num2; node * n=addElement(letters,affix_id,category_id,resulting_category_id,isAccept, #if defined (REDUCE_THRU_DIACRITICS) raw_data,inflected_raw_data,descriptionInflectionRule, #elif defined (MEMORY_EXHAUSTIVE) raw_data,description, #endif getNodeID(num1)); setNodeID(num2,n); } file.close(); return 0; }
static void recenterNode(Node * node, Coordinate oldLength) { IDnum nodeID = getNodeID(node); Connection *connect, *next; Coordinate distance_shift = (getNodeLength(node) - oldLength) / 2; Coordinate min_distance = getNodeLength(node) / 2 - BACKTRACK_CUTOFF; MiniConnection *localConnect; //velvetLog("Recentering node\n"); for (connect = getConnection(node); connect != NULL; connect = next) { next = getNextConnection(connect); incrementConnectionDistance(connect, -distance_shift); if (getConnectionDistance(connect) < min_distance) { //velvetLog("Unrecording %li\n", // -getNodeID(getConnectionDestination(connect))); localConnect = &localScaffold[-getNodeID(getConnectionDestination(connect)) + nodeCount(graph)]; localConnect->frontReference = NULL; unmarkNode(getTwinNode(getConnectionDestination(connect)), localConnect); destroyConnection(connect, nodeID); } else if (getTwinConnection(connect) != NULL) incrementConnectionDistance(getTwinConnection(connect), -distance_shift); } for (connect = getConnection(getTwinNode(node)); connect != NULL; connect = next) { next = getNextConnection(connect); incrementConnectionDistance(connect, distance_shift); if (getTwinConnection(connect) != NULL) incrementConnectionDistance(getTwinConnection(connect), distance_shift); } }
bool MapTargetsMsgEx::processIncoming(struct sockaddr_in* fromAddr, Socket* sock, char* respBuf, size_t bufLen, HighResolutionStats* stats) { LogContext log("MapTargetsMsg incoming"); std::string peer = fromAddr ? Socket::ipaddrToStr(&fromAddr->sin_addr) : sock->getPeername(); LOG_DEBUG_CONTEXT(log, Log_DEBUG, std::string("Received a MapTargetsMsg from: ") + peer); App* app = Program::getApp(); NodeStoreServers* storageNodes = app->getStorageNodes(); TargetMapper* targetMapper = app->getTargetMapper(); uint16_t nodeID = getNodeID(); UInt16List targetIDs; parseTargetIDs(&targetIDs); for(UInt16ListConstIter iter = targetIDs.begin(); iter != targetIDs.end(); iter++) { bool wasNewTarget = targetMapper->mapTarget(*iter, nodeID); if(wasNewTarget) { LOG_DEBUG_CONTEXT(log, Log_WARNING, "Mapping " "target " + StringTk::uintToStr(*iter) + " => " + storageNodes->getNodeIDWithTypeStr(nodeID) ); IGNORE_UNUSED_VARIABLE(storageNodes); } } // send response if(!MsgHelperAck::respondToAckRequest(this, fromAddr, sock, respBuf, bufLen, app->getDatagramListener() ) ) { MapTargetsRespMsg respMsg(FhgfsOpsErr_SUCCESS); respMsg.serialize(respBuf, bufLen); if(fromAddr) { // datagram => sync via dgramLis send method app->getDatagramListener()->sendto(respBuf, respMsg.getMsgLength(), 0, (struct sockaddr*)fromAddr, sizeof(*fromAddr) ); } else sock->sendto(respBuf, respMsg.getMsgLength(), 0, NULL, 0); } return true; }
static IDnum expectedNumberOfConnections(IDnum IDA, Connection * connect, IDnum ** counts, Category cat) { Node *A = getNodeInGraph(graph, IDA); Node *B = connect->destination; IDnum IDB = getNodeID(B); double left, middle, right; Coordinate longLength, shortLength, D; double M, N, O, P; Coordinate mu = getInsertLength(graph, cat); double sigma = sqrt(getInsertLength_var(graph, cat)); double result; double densityA, densityB, minDensity; if (mu <= 0) return 0; if (getNodeLength(A) == 0 || getNodeLength(B) == 0) return 0; if (getNodeLength(A) < getNodeLength(B)) { longLength = getNodeLength(B); shortLength = getNodeLength(A); } else { longLength = getNodeLength(A); shortLength = getNodeLength(B); } densityA = counts[cat][IDA + nodeCount(graph)] / (double) getNodeLength(A); densityB = counts[cat][IDB + nodeCount(graph)] / (double) getNodeLength(B); minDensity = densityA > densityB ? densityB : densityA; D = getConnectionDistance(connect) - (longLength + shortLength) / 2; M = (D - mu) / sigma; N = (D + shortLength - mu) / sigma; O = (D + longLength - mu) / sigma; P = (D + shortLength + longLength - mu) / sigma; left = ((norm(M) - norm(N)) - M * normInt(M, N)) * sigma; middle = shortLength * normInt(N, O); right = ((norm(O) - norm(P)) - P * normInt(O, P)) * (-sigma); result = (minDensity * (left + middle + right)); if (result > 0) return (IDnum) result; else return 0; }
static void computeLocalNodeToNodeMappingsFromConnections(Connection * connect, Connection * connect2) { Node *node1 = getTwinNode(getConnectionDestination(connect)); Node *node2 = getTwinNode(getConnectionDestination(connect2)); IDnum nodeID1 = getNodeID(node1); IDnum nodeID2 = getNodeID(node2); Coordinate distance = getNodeLength(node1)/2 + getNodeLength(node2)/2; Arc *arc; if (getUniqueness(node1) || getUniqueness(node2)) return; if ((arc = getArcBetweenNodes(node1, node2, graph)) && !getConnectionBetweenNodes(node1, getTwinNode(node2))) { createConnection(nodeID1, -nodeID2, getMultiplicity(arc), 0, distance, 1 / (double) getMultiplicity(arc)); incrementConnectionWeight(getConnectionBetweenNodes (node1, getTwinNode(node2)), getMultiplicity(arc)); } if ((arc = getArcBetweenNodes(node2, node1, graph)) && !getConnectionBetweenNodes(node2, getTwinNode(node1))) { createConnection(nodeID2, -nodeID1, getMultiplicity(arc), 0, distance, 1 / (double) getMultiplicity(arc)); incrementConnectionWeight(getConnectionBetweenNodes (node2, getTwinNode(node1)), getMultiplicity(arc)); } }
uint8_t RF24Mesh::update() { uint8_t type = network.update(); if(mesh_address == MESH_DEFAULT_ADDRESS) { return type; } #if !defined (RF24_TINY) && !defined(MESH_NOMASTER) if(type == NETWORK_REQ_ADDRESS) { doDHCP = 1; } if( (type == MESH_ADDR_LOOKUP || type == MESH_ID_LOOKUP) && !getNodeID()) { RF24NetworkHeader& header = *(RF24NetworkHeader*)network.frame_buffer; header.to_node = header.from_node; if(type==MESH_ADDR_LOOKUP) { int16_t returnAddr = getAddress(network.frame_buffer[sizeof(RF24NetworkHeader)]); network.write(header,&returnAddr,sizeof(returnAddr)); } else { int16_t returnAddr = getNodeID(network.frame_buffer[sizeof(RF24NetworkHeader)]); network.write(header,&returnAddr,sizeof(returnAddr)); } //printf("Returning lookup 0%o to 0%o \n",returnAddr,header.to_node); //network.write(header,&returnAddr,sizeof(returnAddr)); } else if(type == MESH_ADDR_RELEASE && !getNodeID() ) { uint16_t *fromAddr = (uint16_t*)network.frame_buffer; for(uint8_t i=0; i<addrListTop; i++) { if(addrList[i].address == *fromAddr) { addrList[i].address = 0; } } } #endif return type; }
static void unmarkInterestingNodes() { Node *node; MiniConnection *localConnect; while ((node = popNodeRecord())) { setSingleNodeStatus(node, false); localConnect = &localScaffold[getNodeID(node) + nodeCount(graph)]; localConnect->frontReference = NULL; localConnect->backReference = NULL; localConnect->nodeList = NULL; } }
void AudioMixer::removeHRTFsForFinishedInjector(const QUuid& streamID) { auto injectorClientData = qobject_cast<AudioMixerClientData*>(sender()); if (injectorClientData) { // enumerate the connected listeners to remove HRTF objects for the disconnected injector auto nodeList = DependencyManager::get<NodeList>(); nodeList->eachNode([injectorClientData, &streamID](const SharedNodePointer& node){ auto listenerClientData = dynamic_cast<AudioMixerClientData*>(node->getLinkedData()); if (listenerClientData) { listenerClientData->removeHRTFForStream(injectorClientData->getNodeID(), streamID); } }); } }
void testcounter() { uint8_t ledcounter; counter = 0; while (1) { lib_sleep_thread(500); buffersum[0] = getNodeID(); lib_get_radio_lock(); lib_radio_set_channel(19); buffersum[1] = counter; lib_radio_send_msg(0xffff, 0xffff, 8, (uint8_t *)buffersum); lib_release_radio_lock(); counter++; if (counter&0x1) lib_red_on(); else lib_red_off(); if (counter&0x2) lib_green_on(); else lib_green_off(); if (counter&0x04) lib_yellow_on(); else lib_yellow_off(); } return; }
static QPair< const void*, raptor_identifier_type > convertNode(QMap< Node*, int >& nodeIDs, Node* node) { QPair< const void*, raptor_identifier_type > pair; if (node->attributes.exists(UtopiaSystem.uri)) { QString encoded = encodeUnicode(node->attributes.get(UtopiaSystem.uri).toString()); pair.first = raptor_new_uri((const unsigned char*) encoded.toAscii().data()); pair.second = RAPTOR_IDENTIFIER_TYPE_RESOURCE; } else { char nodeID[11]; sprintf(nodeID, "ID%08d", getNodeID(nodeIDs, node)); pair.first = (const unsigned char*) strdup(nodeID); pair.second = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; } return pair; }
int Dispatcher::send(const Frame& frame, MonotonicTime tx_deadline, MonotonicTime blocking_deadline, CanTxQueue::Qos qos, CanIOFlags flags, uint8_t iface_mask) { if (frame.getSrcNodeID() != getNodeID()) { UAVCAN_ASSERT(0); return -ErrLogic; } CanFrame can_frame; if (!frame.compile(can_frame)) { UAVCAN_TRACE("Dispatcher", "Unable to send: frame is malformed: %s", frame.toString().c_str()); UAVCAN_ASSERT(0); return -ErrLogic; } return canio_.send(can_frame, tx_deadline, blocking_deadline, iface_mask, qos, flags); }
void CalloutNote::storeText(int pid, int type, int id, bool plain) { int ID = getNodeID(nodeIDs, pid, type, id); vector<int> temp; temp.push_back(pid), temp.push_back(type), temp.push_back(id); if(ID<0) { nodeIDs.push_back(temp); QString sName = m_note->toPlainText(); //QString pName = m_note->toPlainText(); //m_note->toPlainText(); int index= sName.indexOf("\n"); sName = sName.mid(index, sName.size()); if(compare(_preText,sName)) { sName =""; } nodeText.push_back(sName); } else { QString sName = plain? m_note->toPlainText(): m_note->toHtml(); //m_note->toPlainText(); QString pName = m_note->toPlainText(); //m_note->toPlainText(); int index= sName.indexOf("\n"); sName = sName.mid(index, sName.size()); while(sName.lastIndexOf("\n")==sName.size()-1) { index= sName.lastIndexOf("\n"); sName = sName.mid(0, index); if(sName.size()==0) break; } if(compare(_preText,pName)) { //sName =""; } else { nodeText.resize(ID+1); nodeText[ID]=sName; } int size1=pName.size(),size2=_preText.size(); size1=size1; } }
static IDnum expectedNumberOfConnections(IDnum IDA, Connection * connect, IDnum ** counts, Category cat) { Node *A = getNodeInGraph(graph, IDA); Node *B = connect->destination; double left, middle, right; Coordinate longLength, shortLength, D; IDnum longCount; double M, N, O, P; Coordinate mu = getInsertLength(graph, cat); double sigma = sqrt(getInsertLength_var(graph, cat)); double result; if (mu <= 0) return 0; if (getNodeLength(A) < getNodeLength(B)) { longLength = getNodeLength(B); shortLength = getNodeLength(A); longCount = counts[cat][getNodeID(B) + nodeCount(graph)]; } else { longLength = getNodeLength(A); shortLength = getNodeLength(B); longCount = counts[cat][IDA + nodeCount(graph)]; } D = connect->distance - (longLength + shortLength) / 2; M = (D - mu) / sigma; N = (D + shortLength - mu) / sigma; O = (D + longLength - mu) / sigma; P = (D + shortLength + longLength - mu) / sigma; left = ((norm(M) - norm(N)) - M * normInt(M, N)) * sigma; middle = shortLength * normInt(N, O); right = ((norm(O) - norm(P)) - P * normInt(O, P)) * (-sigma); result = (longCount * (left + middle + right)) / longLength; if (result > 0) return (IDnum) result; else return 0; }
bool TreeNode::appendTree(shared_ptr<TreeNode> pTree){ switch (m_node->getType()){ case NodeContentType::nil: m_node = pTree->m_node; m_children = pTree->m_children; setNodeID(initNodeID(m_node)); break; case NodeContentType::leaf: throw std::runtime_error("An attempt was made to append a tree to a leaf node"); break; case NodeContentType::inner: if (m_children.size() == m_node->getArity()) return false; m_children.push_back(pTree); pTree->updateID(getNodeID(), m_children.size()-1); break; } return true; }
static void tourBusArc_local(Node * origin, Arc * arc, Time originTime) { Node *destination = getDestination(arc); Time arcTime, totalTime, destinationTime; IDnum nodeIndex = getNodeID(destination) + nodeCount(graph); Node *oldPrevious = previous[nodeIndex]; //velvetLog("Trying arc from %li -> %li\n", getNodeID(origin), getNodeID(destination)); if (oldPrevious == origin) return; arcTime = ((Time) getNodeLength(origin)) / ((Time) getMultiplicity(arc)); totalTime = originTime + arcTime; destinationTime = times[nodeIndex]; if (destinationTime == -1) { //velvetLog("New destination\n"); setNodeTime(destination, totalTime); dheapNodes[nodeIndex] = insertNodeIntoDHeap(dheap, totalTime, destination); previous[nodeIndex] = origin; return; } else if (destinationTime > totalTime) { //velvetLog("Previously visited from slower node %li\n", getNodeID(getNodePrevious(destination))); if (dheapNodes[nodeIndex] == NULL) { return; } setNodeTime(destination, totalTime); replaceKeyInDHeap(dheap, dheapNodes[nodeIndex], totalTime); previous[nodeIndex] = origin; comparePaths_local(destination, oldPrevious); return; } else { //velvetLog("Previously visited by faster node %li\n", getNodeID(getNodePrevious(destination))); comparePaths_local(destination, origin); } }
void correctGraphLocally(Node * argStart) { IDnum index, nodeIndex; NodeList *nodeList; start = argStart; //velvetLog("Correcting graph from node %li\n", (long int)getNodeID(start)); clipTipsVeryHardLocally(); index = 0; for (nodeList = getMarkedNodeList(); nodeList != NULL; nodeList = nodeList->next) { nodeIndex = getNodeID(nodeList->node) + nodeCount(graph); times[nodeIndex] = -1; dheapNodes[nodeIndex] = NULL; previous[nodeIndex] = NULL; } tourBus_local(start); }
std::string SHAMapTreeNode::getString () const { std::string ret = "NodeID("; ret += lexicalCastThrow <std::string> (getDepth ()); ret += ","; ret += getNodeID ().GetHex (); ret += ")"; if (isInner ()) { for (int i = 0; i < 16; ++i) if (!isEmptyBranch (i)) { ret += "\nb"; ret += lexicalCastThrow <std::string> (i); ret += " = "; ret += mHashes[i].GetHex (); } } if (isLeaf ()) { if (mType == tnTRANSACTION_NM) ret += ",txn\n"; else if (mType == tnTRANSACTION_MD) ret += ",txn+md\n"; else if (mType == tnACCOUNT_STATE) ret += ",as\n"; else ret += ",leaf\n"; ret += " Tag="; ret += getTag ().GetHex (); ret += "\n Hash="; ret += mHash.GetHex (); ret += "/"; ret += lexicalCast <std::string> (mItem->peekSerializer ().getDataLength ()); } return ret; }
static uavcan_linux::NodePtr initNode(const std::vector<std::string>& ifaces, uavcan::NodeID nid, const std::string& name) { auto node = uavcan_linux::makeNode(ifaces); /* * Configuring the node. */ node->setNodeID(nid); node->setName(name.c_str()); node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); /* * Starting the node. */ std::cout << "Starting the node..." << std::endl; const int start_res = node->start(); std::cout << "Start returned: " << start_res << std::endl; ENFORCE(0 == start_res); /* * Checking if our node conflicts with other nodes. This may take a few seconds. */ uavcan::NetworkCompatibilityCheckResult init_result; ENFORCE(0 == node->checkNetworkCompatibility(init_result)); if (!init_result.isOk()) { throw std::runtime_error("Network conflict with node " + std::to_string(init_result.conflicting_node.get())); } std::cout << "Node started successfully" << std::endl; /* * Say Hi to the world. */ node->setStatusOk(); node->logInfo("init", "Hello world! I'm [%*], NID %*", node->getNodeStatusProvider().getName().c_str(), int(node->getNodeID().get())); return node; }
/* * Dispatcher */ void Dispatcher::handleFrame(const CanRxFrame& can_frame) { RxFrame frame; if (!frame.parse(can_frame)) { // This is not counted as a transport error UAVCAN_TRACE("Dispatcher", "Invalid CAN frame received: %s", can_frame.toString().c_str()); return; } if ((frame.getDstNodeID() != NodeID::Broadcast) && (frame.getDstNodeID() != getNodeID())) { return; } switch (frame.getTransferType()) { case TransferTypeMessageBroadcast: case TransferTypeMessageUnicast: { lmsg_.handleFrame(frame); break; } case TransferTypeServiceRequest: { lsrv_req_.handleFrame(frame); break; } case TransferTypeServiceResponse: { lsrv_resp_.handleFrame(frame); break; } default: { UAVCAN_ASSERT(0); break; } } }