📄 coreconfigurationreader.java
字号:
sd.zone = zd; context.put("sensor.temp." + sensorAddress, sd); } } private void renderZoneDamper(Map context, Configuration cf, ZoneDescriptor zd) { String servoPrefix = CF_UNIT + "." + zd.unit.name + ".zone." + zd.name + ".damper.controller"; // VT: NOTE: No defaults or errors will be tolerated. If no data is // available, or it is bad, oh well, they'll have to probe and // select the servos again. try { String controllerClassName = cf.getString(servoPrefix + ".class"); String controllerPort = cf.getString(servoPrefix + ".port"); String servoId = cf.getString(servoPrefix + ".id"); complain(LOG_NOTICE, CH_CCR, "Servo: " + controllerClassName + ", " + controllerPort + ", " + servoId); // Let's see first if we have it in the context ServoController controller = null; for ( Iterator i = getContextValues(context, "servo_controller.").iterator(); i.hasNext(); ) { ServoController haveSc = (ServoController)i.next(); if ( controllerClassName.equals(haveSc.getClass().getName()) ) { complain(LOG_DEBUG, CH_CCR, "Have " + controllerClassName + " class already"); // Let's see if the serial matches if ( controllerPort.equals(haveSc.getPort()) ) { // Yep, that's ours complain(LOG_DEBUG, CH_CCR, "Have serial #" + controllerPort + " already"); controller = haveSc; break; } } } if ( controller == null ) { // Nope, we don't have it yet // Let's try to instantiate the controller try { Class controllerClass = Class.forName(controllerClassName); // So far, so good. We don't have an instance pointing // to the same hardware (we've just checked it above), // so it is safe to instantiate it. Object controllerObject = controllerClass.newInstance(); controller = (ServoController)controllerObject; controller.init(controllerPort); context.put("servo_controller." + controllerPort, controller); // Now that we have just created a new servo controller, // let's create servo descriptors for it. We're // guaranteed not to have clashes since we have *just* // created it. for ( Iterator i = controller.getServos(); i.hasNext(); ) { Servo s = (Servo)i.next(); ServoDescriptor sd = new ServoDescriptor(s); context.put("servo." + sd.getComparable(), sd); } } catch ( Throwable t ) { complain(LOG_ERR, CH_CCR, "Failed to render a servo", t); } } // Now that we have a controller and the servo descriptors, // let's find the one that we need. for ( Iterator i = getContextValues(context, "servo.").iterator(); i.hasNext(); ) { ServoDescriptor sd = (ServoDescriptor)i.next(); if ( servoId.equals(sd.servo.getName()) ) { // This is ours complain(LOG_DEBUG, CH_CCR, "Found a servo descriptor for " + zd); // Let's try to avoid duplication - the GUI doesn't // allow for that yet if ( sd.zone == null ) { zd.servo = sd; sd.zone = zd; } else { complain(LOG_WARNING, CH_CCR, "Duplicate servo assignment for " + sd + ": have " + sd.zone + " already, " + zd + " wants too - ignored"); } break; } } // Let's see if we were able to find a descriptor if ( zd.servo == null ) { complain(LOG_WARNING, CH_CCR, "Unable to resolve servo descriptor for " + zd + " (servo id " + servoId + ")"); } } catch ( NoSuchElementException ex ) { // This most probably means that NullDamper is specified in the // configuration. Oh well. complain(LOG_WARNING, CH_CCR, "Failed to parse zone damper configuration (most probably NullDamper is used): " + ex.getMessage()); } catch ( Throwable t ) { complain(LOG_ERR, CH_CCR, "Failed to parse zone damper configuration", t); } } private void renderZoneSchedule(Map context, Configuration cf, ZoneDescriptor zd) { // VT: FIXME: This reads only existing configuration, with no regard // to heating/cooling try { File scheduleDir = new File(cf.getString("dz.persistent_schedule")); File scheduleFile = new File(scheduleDir, zd.name + ".conf"); URL cfURL = new URL("file", "", scheduleFile.toString()); Configuration scheduleCf = (new ConfigurationFactory()).getConfiguration(cfURL); String prefix = "dz.unit." + zd.unit.name + ".zone." + zd.name + ".schedule.day."; //complain(LOG_INFO, CH_CCR, "Schedule: " + scheduleCf); final String days[] = { "MO", "TU", "WE", "TH", "FR", "SA", "SU" }; for ( int offset = 0; offset < days.length; offset++ ) { String day = days[offset]; String dayPrefix = prefix + day + ".period"; // Get available periods. The key is: // dz.unit.${unit_name}.zone.${zone_name}.schedule.day.${day}.period List periods = scheduleCf.getList(dayPrefix); //complain(LOG_NOTICE, CH_CCR, "Periods for " + dayPrefix + ": " + periods); for ( Iterator i = periods.iterator(); i.hasNext(); ) { String periodName = i.next().toString(); String periodPrefix = dayPrefix + "." + periodName + "."; // Now we're ready to put together a schedule string String startTime = scheduleCf.getString(periodPrefix + "start_time"); String setpoint = scheduleCf.getString(periodPrefix + "setpoint"); String enabled = scheduleCf.getString(periodPrefix + "setpoint.enabled"); String voting = scheduleCf.getString(periodPrefix + "voting"); String dump = scheduleCf.getString(periodPrefix + "dump_priority"); // Now lump it all together String scheduleString = day + ":" + periodName + ":" + startTime + ":" + setpoint + ":" + enabled + ":" + voting + ":" + dump; // VT: FIXME: get separate values for cooling and // heating //complain(LOG_NOTICE, CH_CCR, "Schedule: " + scheduleString); zd.coolingSchedule.add(scheduleString); zd.heatingSchedule.add(scheduleString); } } } catch ( Throwable t ) { complain(LOG_ERR, CH_CCR, "Unable to render schedule for " + zd.name + ":", t); } } private void renderSchedule(Map context, Configuration cf) { String scheduleDir = cf.getString("dz.persistent_schedule"); context.put("schedule.dir", scheduleDir); complain(LOG_NOTICE, CH_CCR, "Schedule dir: " + context.get("schedule.dir")); } // VT: FIXME: This is a copy-and-paste, should be moved into a separate // class. /** * Get the context values associated with the keys starting with a given * prefix. * * @param context Context to search. * * @param prefix A prefix to look up. * * @return An unordered set of values for all the prefixes starting with * the given. */ private Set getContextValues(Map context, String prefix) { Set result = new HashSet(); for ( Iterator i = context.keySet().iterator(); i.hasNext(); ) { String key = i.next().toString(); if ( key.startsWith(prefix) ) { result.add(context.get(key)); } } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -