WIP161201
parent
b27124b8eb
commit
fd83cf147e
|
@ -13,6 +13,8 @@ import org.hwo.Smoother;
|
|||
import org.hwo.StringHelper;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPortListener;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkException;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkRequestFailedException;
|
||||
|
||||
import static org.hwo.servicelink.ServiceLinkTelegram.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
@ -21,9 +23,9 @@ import static org.hwo.logging.LogLevel.*;
|
|||
*
|
||||
* Kommunikation via USB mit RegBus f<EFBFBD>higem System
|
||||
*
|
||||
* <EFBFBD>bertragungssicherheit wird durch USB sichergestellt
|
||||
* Übertragungssicherheit wird durch USB sichergestellt
|
||||
*
|
||||
* <EFBFBD>bertragen werden Telegramme mit folgendem Aufbau:
|
||||
* Übertragen werden Telegramme mit folgendem Aufbau:
|
||||
*
|
||||
* Offset Type Inhalt
|
||||
* 0 Byte RequestTyp ( 0 = NoOP, 1 = Wert lesen, 2 = Wert schreiben, 3 = Ereignis senden )
|
||||
|
@ -60,7 +62,7 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
|
||||
public ServiceLink(NewSerialPort serialPort)
|
||||
{
|
||||
this.requestTimeOut = 50;
|
||||
this.requestTimeOut = 75;
|
||||
|
||||
this.serviceLinkListeners = new LinkedList<ServiceLinkListener>();
|
||||
this.retries = 3;
|
||||
|
@ -182,7 +184,7 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
|
||||
removeRequest(request);
|
||||
|
||||
log(DEBUG,"queuedRequest finished. %s Value: %s",request.getAddress().toString(),request.value);
|
||||
log(DEBUG,"ServiceLink: queuedRequest: %s Value: %s",request.getAddress().toString(),request.value);
|
||||
|
||||
}
|
||||
|
||||
|
@ -299,7 +301,7 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
exit = true;
|
||||
this.notifyAll();
|
||||
try {
|
||||
this.wait(2000);
|
||||
this.wait(getSerialPort().getTimeOut());
|
||||
|
||||
if (this.isAlive()){
|
||||
this.stop();
|
||||
|
@ -323,7 +325,6 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
}
|
||||
rx = ServiceLinkTelegram.read(getSerialPort().getInputStream());
|
||||
if (rx != null){
|
||||
log(DEBUG,"RX: %s", rx.getAddress());
|
||||
received(rx);
|
||||
}
|
||||
}
|
||||
|
@ -372,7 +373,7 @@ public class ServiceLink implements NewSerialPortListener {
|
|||
while (tx != null){
|
||||
byte[] txbytes = tx.toByteArray();
|
||||
try {
|
||||
log(DEBUG,"TX BYTES: %s",ByteArrayHexlifier.byteArrayToString(txbytes));
|
||||
log(DEBUGDETAIL,"TX BYTES: %s",ByteArrayHexlifier.byteArrayToString(txbytes));
|
||||
serialPort.getOutputStream().write(txbytes);
|
||||
} catch (IOException e) {
|
||||
log(e);
|
||||
|
|
|
@ -9,6 +9,8 @@ import java.util.zip.CRC32;
|
|||
|
||||
import org.hwo.ByteArrayHexlifier;
|
||||
import org.hwo.ChkSum;
|
||||
import org.hwo.servicelink.exceptions.CRCFailedException;
|
||||
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
@ -44,8 +46,7 @@ public class ServiceLinkTelegram {
|
|||
if (ch == -1){
|
||||
return null;
|
||||
}
|
||||
|
||||
System.err.println(String.format("PRE-JUNK: 0x%02x",ch));
|
||||
log(DEBUGDETAIL,"readTelegramBytes(): junk byte in the line: %d [ 0x%02x ]",ch,ch);
|
||||
}
|
||||
}
|
||||
sync = (byte)ch;
|
||||
|
@ -59,7 +60,7 @@ public class ServiceLinkTelegram {
|
|||
rxbuffer[1] = (byte)opcode;
|
||||
|
||||
l = in.read(rxbuffer,2,l);
|
||||
log(DEBUG,"RX BYTES: %2d: %s",rxbuffer.length,ByteArrayHexlifier.byteArrayToString(rxbuffer));
|
||||
log(DEBUGDETAIL,"RX BYTES: %2d: %s",rxbuffer.length,ByteArrayHexlifier.byteArrayToString(rxbuffer));
|
||||
|
||||
return rxbuffer;
|
||||
} catch (IOException e) {
|
||||
|
@ -96,19 +97,18 @@ public class ServiceLinkTelegram {
|
|||
this.address = new ServiceLinkAddress(achse, knoten, register);
|
||||
this.value = value;
|
||||
}
|
||||
protected ServiceLinkTelegram(byte[] buffer){
|
||||
protected ServiceLinkTelegram(byte[] buffer) throws CRCFailedException {
|
||||
if ((buffer.length != 12) && (buffer.length != 8) ){
|
||||
throw new ArrayIndexOutOfBoundsException(String.format("ServiceLinkTelegram needs to be constructed from 8 or 12 bytes! But got %d bytes.",buffer.length));
|
||||
}
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN);
|
||||
short chk = ChkSum.chksum(buffer, 1, buffer.length - 3);
|
||||
//log(DEBUG,"CHK: 0x%04x", chk);
|
||||
|
||||
|
||||
if (bb.getShort(buffer.length - 2) != chk) {
|
||||
log(DEBUG,"CRC failed: 0x%04x != 0x%04x",bb.getShort(buffer.length - 2),chk);
|
||||
throw new RuntimeException("CRC Failed");
|
||||
throw new CRCFailedException(buffer, "ServiceLinkTelegram bytes with wrong crc");
|
||||
}
|
||||
|
||||
this.opcode = bb.get(1);
|
||||
|
@ -189,104 +189,3 @@ public class ServiceLinkTelegram {
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* public class ServiceTelegram
|
||||
{
|
||||
private byte request;
|
||||
private byte achse;
|
||||
private byte knoten;
|
||||
private int register;
|
||||
byte[] value;
|
||||
|
||||
public ServiceTelegram()
|
||||
{
|
||||
request = 0;
|
||||
achse = 0;
|
||||
knoten = 0;
|
||||
register = 0;
|
||||
value = new byte[4];
|
||||
ByteBuffer.wrap(value).asIntBuffer().put(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void recv() throws ServiceLinkException
|
||||
{
|
||||
byte[] rxbuffer = new byte[12];
|
||||
ByteBuffer bb = ByteBuffer.wrap(rxbuffer).order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
try {
|
||||
int ch = in.read();
|
||||
|
||||
while ((ch != SL_MAGIC) && (ch >= 0)) {
|
||||
ch = in.read();
|
||||
if (ch != SL_MAGIC)
|
||||
System.err.println(String.format("PRE-JUNK: 0x%02x",ch));
|
||||
}
|
||||
|
||||
in.read(rxbuffer,0,5);
|
||||
|
||||
request = bb.get();
|
||||
achse = bb.get();
|
||||
knoten = bb.get();
|
||||
register = bb.getShort();
|
||||
if (register < 0)
|
||||
register = (register & 0x7FFF) | 0x8000;
|
||||
|
||||
if ((request & (REQ_READ | REQ_ACK)) == (REQ_READ | REQ_ACK))
|
||||
{
|
||||
in.read(rxbuffer,bb.position(),4);
|
||||
bb.get(value);
|
||||
};
|
||||
in.read(rxbuffer,bb.position(),2);
|
||||
short chksum = bb.getShort();
|
||||
|
||||
if (chksum != ChkSum.chksum(rxbuffer, 0, bb.position() - 2))
|
||||
throw new ServiceLinkException();
|
||||
|
||||
//System.err.println(String.format("recv(): %d.%d:%d = 0x%08x",achse,knoten,register,bb.getInt(5)));
|
||||
|
||||
} catch (IOException e) {
|
||||
getSerialPort().close();
|
||||
|
||||
System.err.println(e.toString());
|
||||
throw new ServiceLinkException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public void setRequest(byte request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public byte getAchse() {
|
||||
return achse;
|
||||
}
|
||||
|
||||
public void setAchse(byte achse) {
|
||||
this.achse = achse;
|
||||
}
|
||||
|
||||
public byte getKnoten() {
|
||||
return knoten;
|
||||
}
|
||||
|
||||
public void setKnoten(byte knoten) {
|
||||
this.knoten = knoten;
|
||||
}
|
||||
|
||||
public int getRegister() {
|
||||
return register;
|
||||
}
|
||||
|
||||
public void setRegister(int register) {
|
||||
this.register = register;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -12,9 +12,9 @@ import javax.swing.JComponent;
|
|||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.interactiveobjects.InteractiveObject;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.servicelink.ServiceRegisterListener;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkException;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkRequestFailedException;
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
import org.hwo.ui.servicelink.register.bitfield.BitFieldEditor;
|
||||
import org.w3c.dom.Element;
|
||||
|
|
Loading…
Reference in New Issue