Move to ReflectiveListen
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'protobuf'
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2'
|
||||
@@ -24,6 +23,8 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'org.slf4j:slf4j-log4j12:1.7.7'
|
||||
compile 'org.picocontainer:picocontainer:2.15'
|
||||
compile 'org.msgpack:msgpack:0.6.11'
|
||||
compile 'com.sparetimelabs:purejavacomm:0.0.22'
|
||||
}
|
||||
@@ -1,36 +1,41 @@
|
||||
package com.github.boukefalos.arduino;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import base.work.Listen;
|
||||
import base.worker.Worker;
|
||||
|
||||
public abstract class AbstractArduino extends Listen<Object> implements Arduino {
|
||||
public static final int BUFFER_SIZE = 1024;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected ArrayList<Listen<Object>> listenList;
|
||||
|
||||
public AbstractArduino() {
|
||||
super(Worker.Type.DIRECT);
|
||||
listenList = new ArrayList<Listen<Object>>();
|
||||
}
|
||||
|
||||
public void register(Listen<Object> listen) {
|
||||
listenList.add(listen);
|
||||
}
|
||||
|
||||
public void remove(Listen<Object> listen) {
|
||||
listenList.remove(listen);
|
||||
}
|
||||
|
||||
public void start() {}
|
||||
|
||||
public void stop() {}
|
||||
|
||||
public void exit() {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
package com.github.boukefalos.arduino;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import base.work.Listen;
|
||||
import base.work.ReflectiveListen;
|
||||
import base.worker.Worker;
|
||||
|
||||
public abstract class AbstractArduino extends ReflectiveListen implements Arduino {
|
||||
public static final int BUFFER_SIZE = 1024;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected ArrayList<Listen<Object>> listenList;
|
||||
|
||||
public AbstractArduino() {
|
||||
super(Worker.Type.DIRECT);
|
||||
listenList = new ArrayList<Listen<Object>>();
|
||||
}
|
||||
|
||||
public void register(ReflectiveListen listen) {
|
||||
listenList.add(listen);
|
||||
}
|
||||
|
||||
public void remove(ReflectiveListen listen) {
|
||||
listenList.remove(listen);
|
||||
}
|
||||
|
||||
public void start() {}
|
||||
|
||||
public void stop() {}
|
||||
|
||||
public void exit() {
|
||||
stop();
|
||||
}
|
||||
|
||||
public void input(byte[] buffer) {
|
||||
logger.error("Input was not parsed in port!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.github.boukefalos.arduino;
|
||||
|
||||
import base.Control;
|
||||
import base.work.Listen;
|
||||
import base.work.ReflectiveListen;
|
||||
|
||||
import com.github.boukefalos.arduino.exception.ArduinoException;
|
||||
|
||||
public interface Arduino extends Control {
|
||||
public void register(Listen<Object> listen);
|
||||
public void remove(Listen<Object> listen);
|
||||
public void register(ReflectiveListen listen);
|
||||
public void remove(ReflectiveListen listen);
|
||||
|
||||
public void send(byte[] buffer) throws ArduinoException;
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import base.Duplex;
|
||||
import base.Receiver;
|
||||
import base.exception.worker.ActivateException;
|
||||
import base.exception.worker.DeactivateException;
|
||||
import base.work.Listen;
|
||||
import base.work.ReflectiveListen;
|
||||
|
||||
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 Arduino arduino;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Port implements SerialPortEventListener {
|
||||
"usbdev", // Linux
|
||||
"tty", // Linux
|
||||
"serial", // Linux
|
||||
"COM3", // Windows
|
||||
"COM", // Windows
|
||||
};
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(Port.class);
|
||||
@@ -71,7 +71,7 @@ public class Port implements SerialPortEventListener {
|
||||
portid = (CommPortIdentifier) portEnum.nextElement();
|
||||
if (portid != null) {
|
||||
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)) {
|
||||
try {
|
||||
serialPort = (SerialPort) portid.open("", TIME_OUT);
|
||||
|
||||
Reference in New Issue
Block a user