这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
public class PlugwiseBinding extends AbstractActiveBinding<PlugwiseBindingProvider> implements ManagedService {

private static final Logger logger = LoggerFactory.getLogger(PlugwiseBinding.class);
private static final Pattern EXTRACT_PLUGWISE_CONFIG_PATTERN = Pattern.compile("^(.*?)\\.(mac|port)$");
private static final Pattern EXTRACT_PLUGWISE_CONFIG_PATTERN = Pattern.compile("^(.*?)\\.(mac|port|interval)$");

/** the refresh interval which is used to check for changes in the binding configurations */
private static long refreshInterval = 5000;

Expand All @@ -62,6 +62,8 @@ public class PlugwiseBinding extends AbstractActiveBinding<PlugwiseBindingProvid
@Override
public void updated(Dictionary config) throws ConfigurationException {

int interval = 150;

if (config != null) {

// First of all make sure the Stick gets set up
Expand All @@ -80,7 +82,7 @@ public void updated(Dictionary config) throws ConfigurationException {
if (!matcher.matches()) {
logger.error("given plugwise-config-key '"
+ key
+ "' does not follow the expected pattern '<PlugwiseId>.<mac|port>'");
+ "' does not follow the expected pattern '<PlugwiseId>.<mac|port|interval>'");
continue;
}

Expand All @@ -98,21 +100,8 @@ public void updated(Dictionary config) throws ConfigurationException {
if ("port".equals(configKey)) {
stick = new Stick(value,this);
logger.info("Plugwise added Stick connected to serial port {}",value);
}
else {
throw new ConfigurationException(configKey,
"the given configKey '" + configKey + "' is unknown");
}
}

if (stick != null) {

String configKey = matcher.group(2);
String value = (String) config.get(key);

if ("interval".equals(configKey)) {
stick.setInterval(Integer.valueOf(value));
logger.info("Plugwise set the interval to send ZigBee PDUs to {} ms",value);
} else if ("interval".equals(configKey)) {
// do nothing for now. we will set in the second run
}
else {
throw new ConfigurationException(configKey,
Expand Down Expand Up @@ -150,6 +139,24 @@ public void updated(Dictionary config) throws ConfigurationException {

String plugwiseID = matcher.group(1);

if(plugwiseID.equals("stick")) {

String configKey = matcher.group(2);
String value = (String) config.get(key);

if ("interval".equals(configKey)) {
stick.setInterval(Integer.valueOf(value));
logger.info("Plugwise set the interval to send ZigBee PDUs to {} ms",value);
} else if ("port".equals(configKey)) {
//ignore
}
else {
throw new ConfigurationException(configKey,
"the given configKey '" + configKey + "' is unknown");
}

}

PlugwiseDevice device = stick.getDeviceByName(plugwiseID);
if (device == null && !plugwiseID.equals("stick")) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class Stick extends PlugwiseDevice implements SerialPortEventListener{

/** Number of attempts we make at sending a message */
private final static int MAX_ATTEMPTS = 10;

/** counter to track Quartz Jobs */
private static int counter=0;

// Serial communication fields
private String port;
Expand Down Expand Up @@ -244,12 +247,12 @@ private void initialize() throws PlugwiseInitializationException {
map.put("Stick", this);

JobDetail job = newJob(SendJob.class)
.withIdentity("Send", "Plugwise")
.withIdentity("Send-0", "Plugwise")
.usingJobData(map)
.build();

Trigger trigger = newTrigger()
.withIdentity("Send", "Plugwise")
.withIdentity("Send-0", "Plugwise")
.startNow()
.build();

Expand Down Expand Up @@ -782,14 +785,16 @@ public void jobWasExecuted(JobExecutionContext context,

JobDataMap map = new JobDataMap();
map.put("Stick", theStick);

Stick.counter++;

JobDetail job = newJob(SendJob.class)
.withIdentity("Send", "Plugwise")
.withIdentity("Send-"+Stick.counter, "Plugwise")
.usingJobData(map)
.build();

Trigger trigger = newTrigger()
.withIdentity("Send", "Plugwise")
.withIdentity("Send-"+Stick.counter, "Plugwise")
.startNow()
.build();

Expand All @@ -802,7 +807,7 @@ public void jobWasExecuted(JobExecutionContext context,
try {
sched.scheduleJob(job, trigger);
} catch (SchedulerException e) {
logger.error("Error scheduling a job with the Quartz Scheduler");
logger.error("Error scheduling a job with the Quartz Scheduler : {}",e.getMessage());
}

}
Expand Down