Move to ReflectiveListen

This commit is contained in:
2016-07-03 16:16:04 +01:00
parent 46b377bf9a
commit 381befaa41
5 changed files with 50 additions and 44 deletions

View File

@@ -1,6 +1,5 @@
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'protobuf'
task wrapper(type: Wrapper) { task wrapper(type: Wrapper) {
gradleVersion = '2.2' gradleVersion = '2.2'
@@ -24,6 +23,8 @@ repositories {
} }
dependencies { dependencies {
compile 'org.slf4j:slf4j-log4j12:1.7.7'
compile 'org.picocontainer:picocontainer:2.15'
compile 'org.msgpack:msgpack:0.6.11' compile 'org.msgpack:msgpack:0.6.11'
compile 'com.sparetimelabs:purejavacomm:0.0.22' compile 'com.sparetimelabs:purejavacomm:0.0.22'
} }

View File

@@ -1,36 +1,41 @@
package com.github.boukefalos.arduino; package com.github.boukefalos.arduino;
import java.util.ArrayList; import java.util.ArrayList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import base.work.Listen; import base.work.Listen;
import base.worker.Worker; import base.work.ReflectiveListen;
import base.worker.Worker;
public abstract class AbstractArduino extends Listen<Object> implements Arduino {
public static final int BUFFER_SIZE = 1024; public abstract class AbstractArduino extends ReflectiveListen implements Arduino {
protected Logger logger = LoggerFactory.getLogger(getClass()); public static final int BUFFER_SIZE = 1024;
protected ArrayList<Listen<Object>> listenList; protected Logger logger = LoggerFactory.getLogger(getClass());
protected ArrayList<Listen<Object>> listenList;
public AbstractArduino() {
super(Worker.Type.DIRECT); public AbstractArduino() {
listenList = new ArrayList<Listen<Object>>(); super(Worker.Type.DIRECT);
} listenList = new ArrayList<Listen<Object>>();
}
public void register(Listen<Object> listen) {
listenList.add(listen); public void register(ReflectiveListen listen) {
} listenList.add(listen);
}
public void remove(Listen<Object> listen) {
listenList.remove(listen); public void remove(ReflectiveListen listen) {
} listenList.remove(listen);
}
public void start() {}
public void start() {}
public void stop() {}
public void stop() {}
public void exit() {
stop(); public void exit() {
} stop();
} }
public void input(byte[] buffer) {
logger.error("Input was not parsed in port!");
}
}

View File

@@ -1,13 +1,13 @@
package com.github.boukefalos.arduino; package com.github.boukefalos.arduino;
import base.Control; import base.Control;
import base.work.Listen; import base.work.ReflectiveListen;
import com.github.boukefalos.arduino.exception.ArduinoException; import com.github.boukefalos.arduino.exception.ArduinoException;
public interface Arduino extends Control { public interface Arduino extends Control {
public void register(Listen<Object> listen); public void register(ReflectiveListen listen);
public void remove(Listen<Object> listen); public void remove(ReflectiveListen listen);
public void send(byte[] buffer) throws ArduinoException; public void send(byte[] buffer) throws ArduinoException;
} }

View File

@@ -7,11 +7,11 @@ import base.Duplex;
import base.Receiver; import base.Receiver;
import base.exception.worker.ActivateException; import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException; import base.exception.worker.DeactivateException;
import base.work.Listen; import base.work.ReflectiveListen;
import com.github.boukefalos.arduino.exception.ArduinoException; import com.github.boukefalos.arduino.exception.ArduinoException;
public class Server extends Listen<Object> implements Control, Receiver { public class Server extends ReflectiveListen implements Control, Receiver {
protected static final boolean DIRECT = false; protected static final boolean DIRECT = false;
protected Arduino arduino; protected Arduino arduino;

View File

@@ -28,7 +28,7 @@ public class Port implements SerialPortEventListener {
"usbdev", // Linux "usbdev", // Linux
"tty", // Linux "tty", // Linux
"serial", // Linux "serial", // Linux
"COM3", // Windows "COM", // Windows
}; };
protected static Logger logger = LoggerFactory.getLogger(Port.class); protected static Logger logger = LoggerFactory.getLogger(Port.class);
@@ -71,7 +71,7 @@ public class Port implements SerialPortEventListener {
portid = (CommPortIdentifier) portEnum.nextElement(); portid = (CommPortIdentifier) portEnum.nextElement();
if (portid != null) { if (portid != null) {
System.out.println("Trying: " + portid.getName()); System.out.println("Trying: " + portid.getName());
for ( String portName: PORT_NAMES) { for (String portName : PORT_NAMES) {
if (portid.getName().equals(portName) || portid.getName().contains(portName)) { if (portid.getName().equals(portName) || portid.getName().contains(portName)) {
try { try {
serialPort = (SerialPort) portid.open("", TIME_OUT); serialPort = (SerialPort) portid.open("", TIME_OUT);