WIP161028
parent
8412607d93
commit
bccf82d416
|
@ -61,21 +61,15 @@ public class AsynchronServiceLinkProvider {
|
|||
|
||||
if ((hash & 0x40000000) != 0){
|
||||
Float f = this.cache.getCachedFloat( axFromHash(hash),nodeFromHash(hash),regFromHash(hash));
|
||||
if (f != null){
|
||||
for (ServiceRegisterListener listener: getListeners(hash)){
|
||||
listener.ServiceRegisterValueUpdated(axFromHash(hash),nodeFromHash(hash),regFromHash(hash),f);
|
||||
}
|
||||
}
|
||||
|
||||
for (ServiceRegisterListener listener: getListeners(hash)){
|
||||
listener.ServiceRegisterValueUpdated(axFromHash(hash),nodeFromHash(hash),regFromHash(hash),f);
|
||||
}
|
||||
} else {
|
||||
|
||||
Integer i = this.cache.getCachedInteger( axFromHash(hash),nodeFromHash(hash),regFromHash(hash));
|
||||
if (i != null){
|
||||
for (ServiceRegisterListener listener: getListeners(hash)){
|
||||
listener.ServiceRegisterValueUpdated(axFromHash(hash),nodeFromHash(hash),regFromHash(hash),i);
|
||||
}
|
||||
for (ServiceRegisterListener listener: getListeners(hash)){
|
||||
listener.ServiceRegisterValueUpdated(axFromHash(hash),nodeFromHash(hash),regFromHash(hash),i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,46 @@
|
|||
package org.hwo.servicelink;
|
||||
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream.GetField;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.ChkSum;
|
||||
import org.hwo.Smoother;
|
||||
import org.hwo.bitfields.BitField;
|
||||
import org.hwo.interactiveobjects.InteractiveObject;
|
||||
import org.hwo.io.SerialPort;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPortListener;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream.GetField;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.ChkSum;
|
||||
import org.hwo.Smoother;
|
||||
import org.hwo.bitfields.BitField;
|
||||
import org.hwo.interactiveobjects.InteractiveObject;
|
||||
import org.hwo.io.SerialPort;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPortListener;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream.GetField;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
@ -72,7 +113,7 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
{
|
||||
byte[] txbuffer = new byte[12];
|
||||
ByteBuffer bb = ByteBuffer.wrap(txbuffer).order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
|
||||
bb.put( (byte)SL_MAGIC );
|
||||
bb.put(request);
|
||||
bb.put(achse);
|
||||
|
@ -189,6 +230,8 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
private AsynchronServiceLinkProvider
|
||||
asynchronServiceLinkProvider;
|
||||
|
||||
TxQueue txQueue;
|
||||
|
||||
private List<ServiceLinkListener> serviceLinkListeners;
|
||||
|
||||
public ServiceLink(NewSerialPort serialPort)
|
||||
|
@ -202,6 +245,7 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
this.asynchronServiceLinkProvider = new AsynchronServiceLinkProvider(serviceRegisterCache);
|
||||
this.requestTime = new Smoother();
|
||||
this.requestTime.setTn(16);
|
||||
this.txQueue = null;
|
||||
}
|
||||
|
||||
public void addServiceLinkListener(ServiceLinkListener listener){
|
||||
|
@ -234,14 +278,19 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
{
|
||||
if (serialPort != null){
|
||||
serialPort.open();
|
||||
txQueue = new TxQueue();
|
||||
}
|
||||
throwNotOpen();
|
||||
}
|
||||
|
||||
public synchronized void close()
|
||||
{
|
||||
if (serialPort != null)
|
||||
if (serialPort != null){
|
||||
if (txQueue != null){
|
||||
txQueue.exit();
|
||||
}
|
||||
serialPort.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -254,6 +303,10 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
{
|
||||
return readInt((byte)achse, (byte)knoten, register);
|
||||
}
|
||||
public Float readFloat(int achse,int knoten,int register) throws IOException, ServiceLinkException, ServiceLinkRequestFailedException
|
||||
{
|
||||
return readFloat((byte)achse, (byte)knoten, register);
|
||||
}
|
||||
|
||||
public Integer readInt(byte achse,byte knoten,int register) throws IOException, ServiceLinkException, ServiceLinkRequestFailedException
|
||||
{
|
||||
|
@ -282,7 +335,10 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
|
||||
ServiceTelegram telegram = request((byte)(REQ_WRITE | REQ_INT), achse, knoten, register, v);
|
||||
}
|
||||
|
||||
public void writeFloat(int achse,int knoten,int register,float value) throws IOException, ServiceLinkException, ServiceLinkRequestFailedException{
|
||||
writeFloat((byte)achse,(byte)knoten,register,value);
|
||||
}
|
||||
|
||||
public void writeFloat(byte achse,byte knoten,int register,float value) throws IOException, ServiceLinkException, ServiceLinkRequestFailedException
|
||||
{
|
||||
throwNotOpen();
|
||||
|
@ -312,9 +368,9 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
|
||||
if (value.length == 4)
|
||||
telegram.value = value;
|
||||
|
||||
txQueue.appendRequest(telegram);
|
||||
|
||||
|
||||
telegram.send();
|
||||
rstart = System.currentTimeMillis();
|
||||
for (int n = 0; n<3; n++)
|
||||
{
|
||||
|
@ -367,4 +423,74 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private class TxQueue extends Thread{
|
||||
private LinkedList<ServiceTelegram> queue;
|
||||
private boolean exit;
|
||||
|
||||
public TxQueue(){
|
||||
queue = new LinkedList<>();
|
||||
exit = false;
|
||||
}
|
||||
|
||||
public synchronized void exit(){
|
||||
exit = true;
|
||||
this.notify();
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true){
|
||||
synchronized (this) {
|
||||
|
||||
try {
|
||||
this.wait();
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
if (exit){
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
while (true){
|
||||
ServiceTelegram tx = null;
|
||||
|
||||
synchronized (this) {
|
||||
tx = queue.pollFirst();
|
||||
};
|
||||
|
||||
if (tx != null){
|
||||
tx.send();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
try {
|
||||
if (exit){
|
||||
break;
|
||||
}
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
this.notify();
|
||||
}
|
||||
|
||||
public synchronized void appendRequest(ServiceTelegram request){
|
||||
queue.add(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.hwo.servicelink;
|
||||
|
||||
|
||||
public class ServiceLinkTelegram {
|
||||
static int REQ_READ = 0x01;
|
||||
static int REQ_WRITE = 0x02;
|
||||
static int REQ_EVENT = 0x04;
|
||||
static int REQ_FAIL = 0x08;
|
||||
|
||||
static int REQ_INT = 0x10;
|
||||
static int REQ_FLOAT = 0x20;
|
||||
static int REQ_ACK = 0x40;
|
||||
|
||||
static int SL_MAGIC = 0x66;
|
||||
|
||||
|
||||
int opcode,
|
||||
achse,
|
||||
knoten,
|
||||
register;
|
||||
Object
|
||||
value;
|
||||
|
||||
protected ServiceLinkTelegram(){
|
||||
}
|
||||
|
||||
protected ServiceLinkTelegram(int operation,int achse,int knoten,int register,Object value){
|
||||
this.opcode = operation;
|
||||
this.achse = achse;
|
||||
this.knoten = knoten;
|
||||
this.register = register;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private void checkPlausible(){
|
||||
if ((opcode & REQ_WRITE)!=0){
|
||||
if (value == null){
|
||||
throw new NullPointerException("Need a value to create write-request");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static ServiceLinkTelegram create(int operation,int achse,int knoten,int register,Object value){
|
||||
return new ServiceLinkTelegram(operation,achse,knoten,register,value);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -61,7 +61,7 @@ public class ServiceRegisterCache {
|
|||
public FloatCacheItem(int ax,int node,int register)
|
||||
{
|
||||
super(ax,node,register);
|
||||
floatValue = 0.0f;
|
||||
floatValue = null;
|
||||
}
|
||||
Float floatValue;
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ public abstract class ServiceRegister implements ServiceRegisterListener {
|
|||
}
|
||||
|
||||
|
||||
@TableColumn(label="Bezeichnung",after="Register",width=400)
|
||||
@TableColumn(label="Bezeichnung",width=400,order=5)
|
||||
public String getRegisterName() {
|
||||
return registerName;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public abstract class ServiceRegister implements ServiceRegisterListener {
|
|||
addServiceRegisterListener();
|
||||
}
|
||||
|
||||
@TableColumn(label="Wert",after="Bezeichnung",width=250)
|
||||
@TableColumn(label="Wert",order=10,width=250)
|
||||
abstract public String getTextRepresentation();
|
||||
|
||||
abstract public JComponent getEditorComponent();
|
||||
|
|
Loading…
Reference in New Issue