static uavcan_linux::NodePtr initMainNode(const std::vector<std::string>& ifaces, uavcan::NodeID nid,
                                          const std::string& name)
{
    std::cout << "Initializing main node" << std::endl;

    auto node = uavcan_linux::makeNode(ifaces);

    node->setNodeID(nid);
    node->setName(name.c_str());

    node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG);

    const int start_res = node->start();
    ENFORCE(0 == start_res);

    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()));
    }

    node->setStatusOk();
    return node;
}
// show what WOS operator this node will run
void DeleteProjectionNode::showWOS(int* lpNodeID, ofstream* lpOfstream)
{
	// The operator exists
	if (m_bWOSHasShown)
	{
		return;
	}
	
	m_bWOSHasShown = 1;
	
	// Set nodeID to have different variable name for this node
	setNodeID(lpNodeID);
	
	string sOps = "//DELETE WOS FROM PROJECTION: \n";
	
	bool bIsNewDeleteVector = 0;
	if (m_bDeleteOperatorHasShown == 0)
	{
		sOps = sOps + "	// The following 2 lines of code will be replaced by\n";
		sOps = sOps + "	// WOSManager* lpWOSManager = CatalogInstance::getCatalog()->getWOSManager(m_sProjection);\n";
		sOps = sOps + "	string sColumnAny = CatalogInstance::getCatalog()->getPrimaryColumnName(\"" + m_sProjection + "\");\n";
		sOps = sOps + "	WOSManager* lpWOS_WOSManager = CatalogInstance::getCatalog()->getWOSManager(sColumnAny);\n";
		
		sOps = sOps + "	DeleteOperator* lpDeleteOp = new DeleteOperator(lpWOS_WOSManager);\n";
		bIsNewDeleteVector = 1;
		m_bDeleteOperatorHasShown = 1;
	}
	
	// delete all tuples
	if (bIsNewDeleteVector)
	{
		sOps = sOps + "	lpDeleteOp->deleteProjection();\n";
	}
	lpOfstream->write(sOps.c_str(), sOps.length());
}
Exemple #3
0
void TreeNode::updateID(std::string parentID, int count){
  // this is only called after an insert. The tree on which this is called is a sub-tree of someone else.
  // this tree might be a free hanging leaf or a whole tree
  // in any case, the logic is the same: whatever is before the first ":" is replaced by parentID + count. There is no need to treat leaves separately
  // Examples: 
  // a tree with a leaf 0:1:=7 is added to a tree 0:2 at position 3. ---> 0:2:3:1:=7
  // --- a rootleaf 0:=7 is added to the same tree and position. ---> 0:2:3:=7

  std::string newID;
  std::string currentID = getNodeID();
  int index = currentID.find(":");
  std::string tailID;
  if (index == -1) {
    tailID = "";
  } else {
    tailID = currentID.substr(index);
  }
  newID = parentID + ":" + convertIntToStr(count) + tailID;
  //  DEBUG("Setting new ID: " << newID);
  setNodeID(newID);

  for (unsigned int i = 0; i < getNumChildren(); i++) {
    getChild(i)->updateID(parentID, count);
  }
}
Exemple #4
0
void Radio::update() {
  // new traffic?
  if( radio.receiveDone() && radio.DATALEN==sizeof(Message) ) {
    digitalWrite(LED_PIN, HIGH);
    
    // read it
    msg = *(Message*)radio.DATA;  

    // record RSSI
//    recordRSSI(radio.SENDERID-NODESTART, radio.readRSSI());
    recordRSSI(radio.SENDERID-NODESTART, radio.RSSI);
    
    // has someone claimed my nodeID already?
    if( radio.SENDERID == nodeID ) setNodeID(nodeID+1);
    // is the RSSI too high?  cut the power down
//    if( radio.RSSI > RSSI_TARGET ) setPowerLevel(powerLevel-1);
    // someone else could have called for this, too.
//    if( msg.powerLevel != powerLevel ) setPowerLevel(msg.powerLevel);
    
    digitalWrite(LED_PIN, LOW);
  }
  
  // am I next in the round-robin transmission?
  static unsigned long lastSend = millis();

  if( millis()-lastSend > PING_EVERY && radio.readRSSI() > CSMA_LIMIT ) {       
    msg.packetNumber++;
    msg.doTrigger = false;
    Serial << F("sending ping from myNode:") << nodeID; 
    radio.send(BROADCAST, (const void*)(&msg), sizeof(Message));
    lastSend = millis();
    Serial << F(".  done.") << endl;
  }   

}
Exemple #5
0
bool TreeNode::appendChild(shared_ptr<NodeContent> node){
  //  DEBUG("appendChild entry point");
  switch (m_node->getType()){
  case NodeContentType::nil:
     {
       //       DEBUG("nil node");
       setNodeID(initNodeID(node));
       m_node = node;
     }
     break;
  case NodeContentType::leaf:
    {
      //      DEBUG("leaf node");
      throw std::runtime_error("An attempt was made to append a child to a leaf node");
    }
    break;
   case NodeContentType::inner:
     {
       //       DEBUG("Inner node");
       if (m_children.size() == m_node->getArity()) return false;

       shared_ptr<TreeNode> pNode = TreeNode::makeTree(node);
       m_children.push_back(pNode);
       int count = m_children.size()-1;
       
       std::string newId = findIDForNode(m_nodeID, count, node);
       //       DEBUG("New ID: " << newId);
       pNode->setNodeID(newId);
     }
     break;
   }
   return true;
}
Exemple #6
0
// Common fucntions called in showWOS
void UNode::commonShowWOS(int* lpNodeID, string sOperator, ofstream* lpOfstream)
{
	m_bWOSHasShown = 1;
	
	// Set nodeID to have different variable name for this node
	setNodeID(lpNodeID);
	
	if (m_lpChild != NULL)
	{
		m_lpChild->showWOS(lpNodeID, lpOfstream);
	}
}
Exemple #7
0
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 uavcan_linux::SubNodePtr initSubNode(unsigned num_ifaces, uavcan::INode& main_node)
{
    std::cout << "Initializing sub node" << std::endl;

    typedef VirtualCanDriver<QueuePoolSize> Driver;

    std::shared_ptr<Driver> driver(new Driver(num_ifaces));
    auto node = uavcan_linux::makeSubNode(driver);
    node->setNodeID(main_node.getNodeID());

    main_node.getDispatcher().installRxFrameListener(driver.get());

    return node;
}
// Shows what operator this node will run
void UDeleteProjectionNode::showROS(int* lpNodeID, ofstream* lpOfstream)
{
	// The operator exists
	if (m_bROSHasShown)
	{
		return;
	}
	
	m_bROSHasShown = 1;
	
	// Set nodeID to have different variable name for this node
	setNodeID(lpNodeID);
	
	string sOps = "//DELETE ROS FROM PROJECTION: \n";
	
	bool bIsNewDeleteVector = 0;
	if (m_bDeleteOperatorHasShown == 0)
	{
		sOps = sOps + "	// The following 2 lines of code will be replaced by\n";
		sOps = sOps + "	// WOSManager* lpWOSManager = CatalogInstance::getCatalog()->getWOSManager(m_sProjection);\n";
		sOps = sOps + "	string sColumnAny = CatalogInstance::getCatalog()->getPrimaryColumnName(\"" + m_sProjection + "\");\n";
		sOps = sOps + "	WOSManager* lpROS_WOSManager = CatalogInstance::getCatalog()->getWOSManager(sColumnAny);\n";
		
		sOps = sOps + "	DeleteOperator* lpDeleteOp = new DeleteOperator(lpROS_WOSManager);\n";
		bIsNewDeleteVector = 1;
		m_bDeleteOperatorHasShown = 1;
	}


		m_lpChild->showROS(lpNodeID, lpOfstream);
	
		char sChildNode[15];	
		sprintf(sChildNode, "%d", m_lpChild->getNodeID());
		
		if (m_bIsSinglePredicate == 1)
		{
			sOps = sOps + "	lpDeleteOp->deleteTuple(lp_ROS" +  string(sChildNode) + ", true);\n";
		}
		else
		{
			sOps = sOps + "	lpDeleteOp->deleteByPositionList(lp_ROS" +  string(sChildNode) + ", true);\n";
		}
	
	lpOfstream->write(sOps.c_str(), sOps.length());

}
Exemple #10
0
// Common fucntions called in showROS
void BAggNode::commonShowWOS(int* lpNodeID, string sOperator, ofstream* lpOfstream)
{
	m_bWOSHasShown = 1;
	
	// Set nodeID to have different variable name for this node
	setNodeID(lpNodeID);
	
	if (m_lpLeft != NULL)
	{
		m_lpLeft->showWOS(lpNodeID, lpOfstream);
	}
	
	if (m_lpRight != NULL)
	{
		m_lpRight->showWOS(lpNodeID, lpOfstream);
	}
	
	commonShowROSWOS(sOperator, "WOS", lpOfstream);
}
Exemple #11
0
static uavcan_linux::NodePtr initNode(const std::vector<std::string>& ifaces, uavcan::NodeID nid,
                                      const std::string& name)
{
    auto node = uavcan_linux::makeNode(ifaces);
    node->setNodeID(nid);
    node->setName(name.c_str());

    ENFORCE(0 <= node->start());

    uavcan::NetworkCompatibilityCheckResult ncc_result;
    ENFORCE(0 <= node->checkNetworkCompatibility(ncc_result));
    if (!ncc_result.isOk())
    {
        throw std::runtime_error("Network conflict with node " + std::to_string(ncc_result.conflicting_node.get()));
    }

    node->setStatusOk();
    return node;
}
Exemple #12
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;
}
Exemple #13
0
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;
}
Exemple #14
0
void Radio::begin(byte groupID, byte freq) {
  Serial << F("Radio. startup with unknown node number.") << endl;

  radio.initialize(freq, NODESTART, groupID);
  setNodeID(NODESTART);
  radio.setHighPower(); // using RFM69HW board
  radio.promiscuous(true); // so broadcasts are received
  setPowerLevel();
  
  Serial << F("Waiting....") << endl;
  delay( random(0,MAX_NODES)*25UL ); // wait a tick
  
  // clear rssi tracking
  for(int i=0; i<MAX_NODES; i++) {
    relRSSI[i]=1.0;
    averageRSSI[i]=CSMA_LIMIT;
  }
  
  // set up pin
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}
// show what operator this node will run
void MInsertProjectionNode::show(int* lpNodeID, ofstream* lpOfstream)
{
	// The operator exists
	if (m_bROSHasShown)
	{
		return;
	}
	
	m_bROSHasShown = 1;
	
	// Set nodeID to have different variable name for this node
	setNodeID(lpNodeID);
	
	string sOps = "";
	
	// Run all child nodes first
	int numCols = m_children.size();
	
	if (m_listColumns.size() != m_children.size())
	{
		sOps = sOps + "	//ERROR: Number of columns in the insert projection is different from the number of columns in the select query. Insert fails\n";
		lpOfstream->write(sOps.c_str(), sOps.length());
	}
	
	char sTmp[15];	
	sprintf(sTmp, "%d", numCols);
	
	string sSrcs = "	Operator* srcs[" + string(sTmp) + "] = {";
	string sNumCols = "	int numColumns[" + string(sTmp) + "] = {";
	
	int i = 0;
	
	// Run all child nodes first	
	list<EColumn*>::iterator lpColumn = m_listColumns.begin();
	list<Node*>::iterator lpDataSource = m_children.begin();
	while ( (lpColumn != m_listColumns.end()) && (lpDataSource != m_children.end()) )
	{
		// get column index in the projection
		int iColIndex = CatalogInstance::getCatalog()->getColumnIndex(m_lpProjection->toString(), (*lpColumn)->toString());
		 
		// run data source
		if ((*lpDataSource) != NULL)
		{		
			// only insert into WOS
			(*lpDataSource)->showWOS(lpNodeID, lpOfstream);
			
			sprintf(sTmp, "%d", (*lpDataSource)->getNodeID());
			sSrcs = sSrcs + "lp_WOS" + string(sTmp);
			
			sprintf(sTmp, "%d", iColIndex);
			sNumCols = sNumCols + string(sTmp);
				
			//srcs[i] = lpOpWOS;
			//numColumns[i] = iColIndex;
			
			i++;
			
			if (i < numCols) 
			{
				sSrcs = sSrcs + ", ";
				sNumCols = sNumCols + ", ";
			}
		}
		lpColumn++;
		lpDataSource++;
	}
	
	sSrcs = sSrcs + "};\n";
	sNumCols = sNumCols + "};\n";
	
	char sCols[15];	
	sprintf(sCols, "%d", numCols);

	sOps = sOps + sSrcs;
	sOps = sOps + sNumCols;
	
	sOps = sOps + "\n//INSERT\n";
	sOps = sOps + "	// The following 2 lines of code will be replaced by\n";
	sOps = sOps + "	// WOSManager* lpWOSManager = CatalogInstance::getCatalog()->getWOSManager(m_lpProjection->toString());\n";
	sOps = sOps + "	string sColumnAny = CatalogInstance::getCatalog()->getPrimaryColumnName(\"" + m_lpProjection->toString() + "\");\n";
	sOps = sOps + "	WOSManager* lpWOSManager = CatalogInstance::getCatalog()->getWOSManager(sColumnAny);\n\n";
 
	sOps = sOps + "	InsertOperator* lpInsertOp = new InsertOperator(lpWOSManager);\n";
	sOps = sOps + "	lpInsertOp->appendColumns(srcs, " + sCols + ", numColumns);\n"; 

	lpOfstream->write(sOps.c_str(), sOps.length());	
}
Exemple #16
0
// show what operator this node will run
void  BJoinNode::show(int* lpNodeID, ofstream* lpOfstream, bool rosOnly)
{
	// The operator exists
	if (m_bHasShown)
	{
		return;
	}
	
	m_bHasShown = 1;
	
	// Set nodeID to have different variable name for this node
	setNodeID(lpNodeID);

	string sOps = "//JOINS\n";
	if (rosOnly)
	  {
	     // show its children first
	    if (m_lpLeft != NULL)
	      {
		m_lpLeft->showROS(lpNodeID, lpOfstream);
	      }
	
	    if (m_lpRight != NULL)
	      {
		m_lpRight->showROS(lpNodeID, lpOfstream);
	      }	
	
	    char sLeft[15];	
	    sprintf(sLeft, "%d", m_lpLeft->getNodeID());
	    
	    char sRight[15];	
	    sprintf(sRight, "%d", m_lpRight->getNodeID());
	
	    char sNodeID[15];	
	    sprintf(sNodeID, "%d", getNodeID());
	
	    sOps = sOps + "	int colval = 0;\n";
	    sOps =  sOps + "	Operator* lpRosRos = new HashJoin(&lp_ROS" + string(sLeft)  + ", &colval, " +   " &lp_ROS" + string(sRight)  + ", &colval, 1, 1, true);\n";
	  }
	else
	  {  

	    // show its children first
	    if (m_lpLeft != NULL)
	      {
		m_lpLeft->showROS(lpNodeID, lpOfstream);
		m_lpLeft->showWOS(lpNodeID, lpOfstream);
		m_lpLeftReplica->showROS(lpNodeID, lpOfstream);
		m_lpLeftReplica->showWOS(lpNodeID, lpOfstream);
	      }
	
	    if (m_lpRight != NULL)
	      {
		m_lpRight->showROS(lpNodeID, lpOfstream);
		m_lpRight->showWOS(lpNodeID, lpOfstream);
		m_lpRightReplica->showROS(lpNodeID, lpOfstream);
		m_lpRightReplica->showWOS(lpNodeID, lpOfstream);
	      }	
	
	    char sLeft[15];	
	    sprintf(sLeft, "%d", m_lpLeft->getNodeID());
	    
	    char sRight[15];	
	    sprintf(sRight, "%d", m_lpRight->getNodeID());
	
	    char sLeftReplica[15];	
	    sprintf(sLeftReplica, "%d", m_lpLeftReplica->getNodeID());
	
	    char sRightReplica[15];	
	    sprintf(sRightReplica, "%d", m_lpRightReplica->getNodeID());
	
	    char sNodeID[15];	
	    sprintf(sNodeID, "%d", getNodeID());
	
	    
	    sOps =  sOps + "	Operator* lpRosRos = new NLJoin(lp_ROS" + string(sLeft)  + ", 0, " +   " lp_ROS" + string(sRight)  + ", 0);\n";
	    sOps =  sOps + "	Operator* lpRosWos = new NLJoin(lp_ROS" + string(sLeftReplica)  + ", 0, " +   " lp_WOS" + string(sRight)  + ", 0);\n";
	    sOps =  sOps + "	Operator* lpWosRos = new NLJoin(lp_WOS" + string(sLeft)  + ", 0, " +   " lp_ROS" + string(sRightReplica)  + ", 0);\n";
	    sOps =  sOps + "	Operator* lpWosWos = new NLJoin(lp_WOS" + string(sLeftReplica)  + ", 0, " +   " lp_WOS" + string(sRightReplica)  + ", 0);\n";

	  }

	lpOfstream->write(sOps.c_str(), sOps.length());
}