void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, boolean _repeaterMode, uint8_t _parentNodeId, rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) { Serial.begin(BAUD_RATE); isGateway = false; repeaterMode = _repeaterMode; msgCallback = _msgCallback; if (repeaterMode) { setupRepeaterMode(); } setupRadio(paLevel, channel, dataRate); // Read settings from EEPROM eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig)); // Read latest received controller configuration from EEPROM eeprom_read_block((void*)&cc, (void*)EEPROM_LOCAL_CONFIG_ADDRESS, sizeof(ControllerConfig)); if (cc.isMetric == 0xff) { // Eeprom empty, set default to metric cc.isMetric = 0x01; } if (_parentNodeId != AUTO) { nc.parentNodeId = _parentNodeId; autoFindParent = false; } else { autoFindParent = true; } if (_nodeId != AUTO) { // Set static id nc.nodeId = _nodeId; } // If no parent was found in eeprom. Try to find one. if (autoFindParent && nc.parentNodeId == 0xff) { findParentNode(); } // Try to fetch node-id from gateway if (nc.nodeId == AUTO) { requestNodeId(); } debug(PSTR("%s started, id %d\n"), repeaterMode?"repeater":"sensor", nc.nodeId); // Open reading pipe for messages directed to this node (set write pipe to same) RF24::openReadingPipe(WRITE_PIPE, TO_ADDR(nc.nodeId)); RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId)); // Send presentation for this radio node (attach present(NODE_SENSOR_ID, repeaterMode? S_ARDUINO_REPEATER_NODE : S_ARDUINO_NODE); // Send a configuration exchange request to controller // Node sends parent node. Controller answers with latest node configuration // which is picked up in process() sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CONFIG, false).set(nc.parentNodeId)); // Wait configuration reply. waitForReply(); }
wxDataViewItem GraphTreeModel::findParentIter(const scene::INodePtr& node) const { // Find the parent's GraphTreeNode const GraphTreeNodePtr& nodePtr = findParentNode(node); // Return an empty iterator if not found return (nodePtr != NULL) ? nodePtr->getIter() : wxDataViewItem(); }
boolean MySensor::sendRoute(MyMessage &message) { // Make sure to process any incoming messages before sending (could this end up in recursive loop?) // process(); bool isInternal = mGetCommand(message) == C_INTERNAL; // If we still don't have any node id, re-request and skip this message. if (nc.nodeId == AUTO && !(isInternal && message.type == I_ID_REQUEST)) { requestNodeId(); return false; } if (repeaterMode) { uint8_t dest = message.destination; uint8_t route = getChildRoute(dest); if (route>GATEWAY_ADDRESS && route<BROADCAST_ADDRESS && dest != GATEWAY_ADDRESS) { // --- debug(PSTR("route %d.\n"), route); // Message destination is not gateway and is in routing table for this node. // Send it downstream return sendWrite(route, message); } else if (isInternal && message.type == I_ID_RESPONSE && dest==BROADCAST_ADDRESS) { // Node has not yet received any id. We need to send it // by doing a broadcast sending, return sendWrite(BROADCAST_ADDRESS, message, true); } } if (!isGateway) { // --- debug(PSTR("route parent\n")); // Should be routed back to gateway. bool ok = sendWrite(nc.parentNodeId, message); if (!ok) { // Failure when sending to parent node. The parent node might be down and we // need to find another route to gateway. if (autoFindParent && failedTransmissions > SEARCH_FAILURES) { findParentNode(); } failedTransmissions++; } else { failedTransmissions = 0; } return ok; } return false; }
int DicomImageSet::insertFileItem(IXMLDOMDocument *pDom, IXMLDOMNode * pRoot, const QString &folderName, const QString &fileName) { DicomImage * dicomImage = new DicomImage (); if (!dicomImage->readHeader((QDir(folderName).absoluteFilePath(fileName)).toStdString().c_str())) { //fail to resolve header information return 0; } int nElement; char * patientsName = dicomImage->getCharTag(DicomImage::TAG_PATIENTS_NAME, nElement); char * patientsId = dicomImage->getCharTag(DicomImage::TAG_PATIENT_ID, nElement); char * protocolName = dicomImage->getCharTag(DicomImage::TAG_PROTOCOL_NAME, nElement); double * pInstanceNumber = dicomImage->getNumericTag(DicomImage::TAG_INSTANCE_NUMBER, nElement); double * pAcquisitionNumber = dicomImage->getNumericTag(DicomImage::TAG_ACQUISITION_NUMBER, nElement); double * pAcquisitionDate = dicomImage->getNumericTag(DicomImage::TAG_ACQUISITION_DATE, nElement); int instanceNumber = pInstanceNumber?(int)pInstanceNumber[0]:-1; int acquisitionNumber = pAcquisitionNumber?(int)pAcquisitionNumber[0]:-1; int acquisitionDate = pAcquisitionDate?(int)pAcquisitionDate[0]:0; IXMLDOMNode * pParent = findParentNode(pDom, pRoot, patientsName, patientsId, acquisitionDate, protocolName, acquisitionNumber); if (!pParent) { return 0; } HRESULT hr = S_OK; IXMLDOMElement *pNode = NULL; CHK_HR(CreateElement(pDom, L"File", &pNode)); CHK_HR(CreateAndAddAttributeNode(pDom, L"path", fileName.toStdWString().c_str(), pNode)); CHK_HR(CreateAndAddAttributeNode(pDom, L"instance_number", QString::number(instanceNumber).toStdWString().c_str(), pNode)); IXMLDOMNode * pSibling = NULL; CHK_HR(pParent->get_firstChild(&pSibling)); int sibInstanceNumber = -1; VARIANT varInstanceNumber; DOMNodeType nodeType; while (pSibling && instanceNumber >= sibInstanceNumber) { CHK_HR(pSibling->get_nodeType(&nodeType)); if(nodeType == NODE_ELEMENT) { CHK_HR(GetAttributeFromNode(pSibling, L"instance_number", &varInstanceNumber)); sibInstanceNumber = QString::fromWCharArray(_bstr_t(varInstanceNumber)).toInt(); if (instanceNumber < sibInstanceNumber) { break; } } IXMLDOMNode * tmpNode = NULL; CHK_HR(pSibling->get_nextSibling(&tmpNode)); SAFE_RELEASE(pSibling); pSibling = tmpNode; } if (pSibling) { IXMLDOMNode * tmpNode = NULL; CHK_HR(pSibling->get_previousSibling(&tmpNode)); SAFE_RELEASE(pSibling); pSibling = tmpNode; } CHK_HR(CreateAndAddTextNodeBefore(pDom, L"\n", pParent, pSibling)); CHK_HR(InsertChildToParent(pNode, pSibling, pParent)); CleanUp: SAFE_RELEASE(pNode); return 1; }
void BPTree::insertNonleaf(Node node,Value key,PtrType pointer) { if (node.getNodePtr() == root) { Node newNode(dbName,indexName,tableInstance,n); vector<Value> keyList; Value temp1(_TYPE_INT,node.getNodePtr()); Value temp2(_TYPE_INT,pointer); keyList.push_back(temp1); keyList.push_back(key); keyList.push_back(temp2); newNode.set(keyList); root = newNode.getNodePtr(); //把根节点的更改写入磁盘 int firstBlock = bfm->getIndexBlocks(indexName)[0];//获取开始的块 Node rootNode(dbName,firstBlock,indexName,tableInstance,n); Value temp3(_TYPE_INT,root); vector<Value> temp4; temp4.push_back(temp3); rootNode.set(temp4); } else { Node parentNode(dbName,findParentNode(node.getNodePtr()),indexName,tableInstance,n); if (parentNode.getCount() < n) { vector<Value> keyList = parentNode.getInfo();//只读键值对 if (isLess(key,keyList[0])) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin()+1,tempPtr); keyList.insert(keyList.begin()+1,key); } else { for (int i = (keyList.size() - 1 - 1); i >= 0; i-=2) { if (isLessEqual(keyList.at(i),key)) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin() + i+2,tempPtr);//TODO:最后一个会怎么样? keyList.insert(keyList.begin() + i+2,key); break; } } } parentNode.set(keyList); } else//分裂ParentNode { //排序 vector<Value> keyList = parentNode.getInfo();//只读键值对 if (isLess(key,keyList[0])) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin()+1,tempPtr); keyList.insert(keyList.begin()+1,key); } else { for (int i = (keyList.size() - 1 - 1); i >= 0; i-=2) { if (isLessEqual(keyList.at(i),key)) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin() + i+2,tempPtr);//TODO:最后一个会怎么样? keyList.insert(keyList.begin() + i+2,key); break; } } } //赋值元素到该到的地方 int breakPoint = 0; if (n % 2 == 0) breakPoint = (n /2); else breakPoint = ((n / 2) + 1); vector<Value> temp; temp.push_back(keyList[0]); int j = 1; for (int i = 1; i < breakPoint; i++) { temp.push_back(keyList[j]); temp.push_back(keyList[++j]); } parentNode.set(temp); Value newK = keyList[++j]; vector<Value> temp2; for (int i = j + 1; i < keyList.size(); i++) { temp2.push_back(keyList[i]); } Node newNode(dbName,indexName,tableInstance,n); newNode.set(temp2); insertNonleaf(parentNode,newK,newNode.getNodePtr()); } } }