bool ZoneHVACComponent_Impl::addToNode(Node & node) { bool result = false; boost::optional<ThermalZone> thermalZone; boost::optional<AirTerminalSingleDuctInletSideMixer> terminal; if( boost::optional<ModelObject> outlet = node.outletModelObject() ) { if( boost::optional<PortList> pl = outlet->optionalCast<PortList>() ) { thermalZone = pl->thermalZone(); } } if( boost::optional<ModelObject> inlet = node.inletModelObject() ) { terminal = inlet->optionalCast<AirTerminalSingleDuctInletSideMixer>(); } if( thermalZone && terminal ) { if( this->thermalZone() ) { removeFromThermalZone(); } thermalZone->setUseIdealAirLoads(false); ZoneHVACComponent thisObject = getObject<ZoneHVACComponent>(); thermalZone->addEquipment(thisObject); thermalZone->setCoolingPriority(thisObject,1); thermalZone->setHeatingPriority(thisObject,1); Model t_model = model(); ModelObject thisModelObject = getObject<model::ZoneHVACComponent>(); unsigned targetPort = node.connectedObjectPort( node.outletPort() ).get(); ModelObject targetModelObject = node.connectedObject( node.outletPort() ).get(); Node newNode( t_model ); t_model.connect( node, node.outletPort(), thisModelObject, inletPort() ); t_model.connect( thisModelObject, outletPort(), newNode, newNode.inletPort() ); t_model.connect( newNode, newNode.outletPort(), targetModelObject, targetPort ); Node exhaustNode(t_model); PortList exhaustPortList = thermalZone->exhaustPortList(); unsigned nextPort = exhaustPortList.nextPort(); t_model.connect(exhaustPortList,nextPort,exhaustNode,exhaustNode.inletPort()); t_model.connect(exhaustNode,exhaustNode.outletPort(),terminal.get(),terminal->secondaryAirInletPort()); result = true; } return result; }
boost::optional<IdfObject> ForwardTranslator::translatePortList( PortList & modelObject ) { OptionalString s; OptionalDouble d; OptionalModelObject temp; // Create a new IddObjectType::NodeList // If you don't want a node list based on the port list, don't use this translator std::vector<ModelObject> modelObjects = modelObject.modelObjects(); if (modelObjects.empty()){ // do not write out this object return boost::none; } IdfObject idfObject(IddObjectType::NodeList); // Name s = modelObject.name(); if(s) { idfObject.setName(*s); } for( std::vector<ModelObject>::iterator it = modelObjects.begin(); it != modelObjects.end(); it++ ) { if( boost::optional<Node> node = it->optionalCast<Node>() ) { IdfExtensibleGroup group = idfObject.pushExtensibleGroup(); group.setString(NodeListExtensibleFields::NodeName,node->name().get()); } } m_idfObjects.push_back(idfObject); return idfObject; }
void Normalize::normalizeMPPortDescReplyV4() { using deprecated::PortV2; // Verify size of port list. size_t portListSize = buf_.size() - sizeof(MultipartReply); if ((portListSize % sizeof(PortV2)) != 0) { markInputInvalid("MultipartReply.PortDesc has invalid size"); return; } // Normalize the port structures from V2 to normal size. size_t portCount = portListSize / sizeof(PortV2); UInt8 *pkt = buf_.mutableData(); const PortV2 *portV2 = reinterpret_cast<const PortV2 *>(pkt + sizeof(MultipartReply)); PortList ports; for (size_t i = 0; i < portCount; ++i) { PortBuilder newPort{*portV2}; ports.add(newPort); ++portV2; } // Copy new port list into packet. buf_.addUninitialized(ports.size() - portListSize); pkt = buf_.mutableData(); assert(buf_.size() == sizeof(MultipartReply) + ports.size()); std::memcpy(pkt + sizeof(MultipartReply), ports.data(), ports.size()); }
bool AirTerminalSingleDuctParallelPIUReheat_Impl::setInducedAirPlenumZone(ThermalZone & plenumZone) { bool result = true; if( ! plenumZone.isPlenum() ) { result = false; } boost::optional<Node> t_secondaryAirInletNode; if( result ) { t_secondaryAirInletNode = secondaryAirInletNode(); if( ! t_secondaryAirInletNode ) { result = false; } } boost::optional<AirLoopHVACReturnPlenum> plenum; if( result ) { plenum = plenumZone.getImpl<detail::ThermalZone_Impl>()->airLoopHVACReturnPlenum(); if( ! plenum ) { result = false; } } if( result ) { Model t_model = model(); PortList pl = plenum->getImpl<detail::AirLoopHVACReturnPlenum_Impl>()->inducedAirOutletPortList(); t_model.connect(pl,pl.nextPort(),t_secondaryAirInletNode.get(),t_secondaryAirInletNode->inletPort()); } return result; }
bool ZoneHVACComponent_Impl::addToThermalZone(ThermalZone & thermalZone) { Model m = this->model(); if( thermalZone.model() != m ) { return false; } if( thermalZone.isPlenum() ) { return false; } removeFromThermalZone(); thermalZone.setUseIdealAirLoads(false); // Connect nodes if this is an air based zone hvac component if( inletPort() != 0u && outletPort() != 0u ) { // Exhaust Node Node exhaustNode(m); PortList exhaustPortList = thermalZone.exhaustPortList(); unsigned nextPort = exhaustPortList.nextPort(); m.connect(exhaustPortList,nextPort,exhaustNode,exhaustNode.inletPort()); ModelObject mo = this->getObject<ModelObject>(); m.connect(exhaustNode,exhaustNode.outletPort(),mo,this->inletPort()); // Air Inlet Node Node airInletNode(m); PortList inletPortList = thermalZone.inletPortList(); unsigned nextInletPort = inletPortList.nextPort(); m.connect(airInletNode,airInletNode.outletPort(),inletPortList,nextInletPort); m.connect(mo,this->outletPort(),airInletNode,airInletNode.inletPort()); } thermalZone.addEquipment(this->getObject<ZoneHVACComponent>()); return true; }
bool FanZoneExhaust_Impl::addToThermalZone(ThermalZone & thermalZone) { Model m = this->model(); if( thermalZone.model() != m ) { return false; } removeFromThermalZone(); thermalZone.setUseIdealAirLoads(false); // Zone Exhaust Node (Exhaust Fan Inlet node) Node exhaustNode(m); PortList exhaustPortList = thermalZone.exhaustPortList(); unsigned nextPort = exhaustPortList.nextPort(); m.connect(exhaustPortList,nextPort,exhaustNode,exhaustNode.inletPort()); ModelObject mo = this->getObject<ModelObject>(); m.connect(exhaustNode,exhaustNode.outletPort(),mo,this->inletPort()); // Node (Exhaust Fan Outlet Node) Node exhaustFanOutletNode(m); m.connect(mo,this->outletPort(),exhaustFanOutletNode,exhaustFanOutletNode.inletPort()); thermalZone.addEquipment(this->getObject<ZoneHVACComponent>()); return true; }
void Normalize::normalizeFeaturesReplyV1() { using deprecated::PortV1; Header *hdr = header(); // Check minimum size requirement. if (hdr->length() < sizeof(FeaturesReply)) { markInputInvalid("FeaturesReply is too short"); return; } // Verify size of port list. size_t portListSize = hdr->length() - sizeof(FeaturesReply); if ((portListSize % sizeof(PortV1)) != 0) { markInputInvalid("FeaturesReply has invalid port list size"); return; } // Normalize the port structures from V1 to normal size. size_t portCount = portListSize / sizeof(PortV1); UInt8 *pkt = buf_.mutableData(); const PortV1 *portV1 = reinterpret_cast<const PortV1 *>(pkt + sizeof(FeaturesReply)); PortList ports; for (size_t i = 0; i < portCount; ++i) { PortBuilder newPort{*portV1}; ports.add(newPort); ++portV1; } if (ports.size() > 65535 - sizeof(FeaturesReply)) { markInputTooBig("FeaturesReply has too many ports"); return; } // Copy new port list into packet. buf_.addUninitialized(ports.size() - portListSize); pkt = buf_.mutableData(); assert(buf_.size() == sizeof(FeaturesReply) + ports.size()); std::memcpy(pkt + sizeof(FeaturesReply), ports.data(), ports.size()); }
static void AddPort(YARPPort *port) { port_list_mutex.Wait(); port_list.push_back(port); port_list_mutex.Post(); }
bool AirTerminalSingleDuctParallelPIUReheat_Impl::addToNode(Node & node) { Model _model = node.model(); if( boost::optional<ModelObject> outlet = node.outletModelObject() ) { boost::optional<ThermalZone> thermalZone; if( boost::optional<PortList> portList = outlet->optionalCast<PortList>() ) { thermalZone = portList->thermalZone(); } if( thermalZone || (outlet->optionalCast<Mixer>() && node.airLoopHVAC()) ) { if( boost::optional<ModelObject> inlet = node.inletModelObject() ) { if( boost::optional<Splitter> splitter = inlet->optionalCast<Splitter>() ) { boost::optional<ModelObject> sourceModelObject = inlet; boost::optional<unsigned> sourcePort = node.connectedObjectPort(node.inletPort()); if( sourcePort && sourceModelObject ) { Node inletNode(_model); ModelObject thisObject = getObject<ModelObject>(); _model.connect( sourceModelObject.get(), sourcePort.get(), inletNode, inletNode.inletPort() ); _model.connect( inletNode, inletNode.outletPort(), thisObject, inletPort() ); _model.connect( thisObject, outletPort(), node, node.inletPort() ); if( thermalZone ) { Node secondaryInletNode(_model); PortList exhaustPortList = thermalZone->exhaustPortList(); _model.connect( exhaustPortList, exhaustPortList.nextPort(), secondaryInletNode, secondaryInletNode.inletPort() ); _model.connect( secondaryInletNode, secondaryInletNode.outletPort(), thisObject, secondaryAirInletPort() ); ModelObject mo = this->getObject<ModelObject>(); thermalZone->addEquipment(mo); } if( auto airLoopHVAC = node.airLoopHVAC() ) { auto schedule = airLoopHVAC->availabilitySchedule(); setFanAvailabilitySchedule(schedule); } return true; } } } } } return false; }
/* Thread that scans for new GPSes, removals etc. */ void Gipsy::scanner_thread() { while (!exit_thread) { // Scan for new ports PortList plist = get_ports(true); vector<unsigned int> changed; vector<unsigned int> removed; PR_Lock(lock); /* Remove non-existent ports */ for (unsigned int i=0; i < gpslist.size(); i++) { if (! gpslist[i] || gpslist[i]->watcher_running) continue; /* Find port */ unsigned int j; for (j=0; j < plist.size(); j++) if (plist[j].device == gpslist[i]->portinfo.device) break; if (j < plist.size()) continue; /* Device does not exist anymore, remove it */ NS_RELEASE(gpslist[i]); gpslist[i] = NULL; removed.push_back(i); } /* Find new ports */ for (unsigned int i=0; i < plist.size(); i++) { int pos; if (find_gps(plist[i].device, pos)) { // Start watcher if not already started // may happen when scanner is stopped and started again if (gpslist[pos]->scan_enabled && !gpslist[pos]->watcher_running) gpslist[pos]->start_watcher(); continue; // Port already in list } /* Add new */ GpsItem *newitem = new GpsItem(); NS_ADDREF(newitem); newitem->portinfo = plist[i]; // Scan_enable according prefs newitem->scan_enabled = prefs_scan_enabled(*newitem); newitem->gpstype = prefs_gpstype(*newitem); newitem->auto_download = newitem->gpstype == GPS_MLR ? false : auto_download; /* Find new slot */ for (pos=0; pos < (int)gpslist.size(); pos++) if (!gpslist[pos]) break; if (pos < (int)gpslist.size()) gpslist[pos] = newitem; else gpslist.push_back(newitem); newitem->pos = pos; changed.push_back(pos); if (newitem->scan_enabled) newitem->start_watcher(); } PR_Unlock(lock); // End of critical section // Send updates to observers for (unsigned int i=0; i < removed.size(); i++) { GpsItem *tmp = new GpsItem(); tmp->pos = removed[i]; NS_ADDREF(tmp); notify(tmp, "gps_removed", true); // - NS_RELEASE will be called in notify } for (unsigned int i=0; i < changed.size(); i++) { int32_t idx = changed[i]; notify(gpslist[idx], "gps_changed"); } sleep(1); } // Abort watchers on scanner exit // TODO: Join them? PR_Lock(lock); for (unsigned int i=0; i < gpslist.size(); i++) if (gpslist[i]) gpslist[i]->exit_thread = true; PR_Unlock(lock); }