Neue PostgreSQL Lib
parent
8cf002e648
commit
cb729441ca
Binary file not shown.
|
@ -1,182 +0,0 @@
|
||||||
package org.hwo.pulscounter;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
/* DeviceControlChannel
|
|
||||||
*
|
|
||||||
* Binary Serial Protocol based on telegrams
|
|
||||||
*
|
|
||||||
* telegram:
|
|
||||||
*
|
|
||||||
* byte length of next telegram
|
|
||||||
* byte request
|
|
||||||
* byte options
|
|
||||||
* byte reserve
|
|
||||||
* int32 parameter1
|
|
||||||
* int32 parameter2
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class DeviceControlChannel {
|
|
||||||
|
|
||||||
public class Telegram
|
|
||||||
{
|
|
||||||
private byte[] buffer;
|
|
||||||
|
|
||||||
private byte request;
|
|
||||||
private byte options;
|
|
||||||
|
|
||||||
private Integer parameter1;
|
|
||||||
private Integer parameter2;
|
|
||||||
|
|
||||||
public Telegram()
|
|
||||||
{
|
|
||||||
buffer = new byte[12];
|
|
||||||
request = 0;
|
|
||||||
options = 0;
|
|
||||||
parameter1 = 0;
|
|
||||||
parameter2 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Telegram(byte request)
|
|
||||||
{
|
|
||||||
this.request = request;
|
|
||||||
options = 0;
|
|
||||||
parameter1 = 0;
|
|
||||||
parameter2 = 0;
|
|
||||||
}
|
|
||||||
public Telegram(byte request,byte options)
|
|
||||||
{
|
|
||||||
this.request = request;
|
|
||||||
this.options = options;
|
|
||||||
parameter1 = 0;
|
|
||||||
parameter2 = 0;
|
|
||||||
}
|
|
||||||
public Telegram(byte request,byte options,int parameter1,int parameter2)
|
|
||||||
{
|
|
||||||
this.request = request;
|
|
||||||
this.options = options;
|
|
||||||
this.parameter1 = parameter1;
|
|
||||||
this.parameter2 = parameter2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getBuffer()
|
|
||||||
{
|
|
||||||
return this.buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void decodeBuffer()
|
|
||||||
{
|
|
||||||
ByteBuffer bb = ByteBuffer.wrap(buffer);
|
|
||||||
bb.get();
|
|
||||||
request = bb.get();
|
|
||||||
options = bb.get();
|
|
||||||
bb.get();
|
|
||||||
parameter1 = bb.getInt();
|
|
||||||
parameter2 = bb.getInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Telegram(byte[] buffer)
|
|
||||||
{
|
|
||||||
this.buffer = buffer;
|
|
||||||
decodeBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] toArray()
|
|
||||||
{
|
|
||||||
return ByteBuffer.allocate(12)
|
|
||||||
.put((byte)11)
|
|
||||||
.put(request)
|
|
||||||
.put(options)
|
|
||||||
.put((byte)0)
|
|
||||||
.putInt(parameter1)
|
|
||||||
.putInt(parameter2)
|
|
||||||
.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRequest() {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRequest(byte request) {
|
|
||||||
this.request = request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getOptions() {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOptions(byte options) {
|
|
||||||
this.options = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getParameter1() {
|
|
||||||
return parameter1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParameter1(Integer parameter1) {
|
|
||||||
this.parameter1 = parameter1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getParameter2() {
|
|
||||||
return parameter2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParameter2(Integer parameter2) {
|
|
||||||
this.parameter2 = parameter2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte NOOP = 0;
|
|
||||||
public static byte READ = 1;
|
|
||||||
public static byte WRITE = 2;
|
|
||||||
public static byte COMMAND = 3;
|
|
||||||
public static byte REPLY = 8;
|
|
||||||
|
|
||||||
private InputStream inputStream;
|
|
||||||
private OutputStream outputStream;
|
|
||||||
|
|
||||||
public DeviceControlChannel(InputStream input,OutputStream output)
|
|
||||||
{
|
|
||||||
this.inputStream = input;
|
|
||||||
this.outputStream = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Telegram sendRequest(Telegram request)
|
|
||||||
{
|
|
||||||
Telegram response = new Telegram();
|
|
||||||
|
|
||||||
try {
|
|
||||||
outputStream.write(request.toArray());
|
|
||||||
inputStream.read(response.getBuffer());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.getRequest() != response.getRequest())
|
|
||||||
System.err.println("DDC Error!");
|
|
||||||
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void noop()
|
|
||||||
{
|
|
||||||
sendRequest(new Telegram());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int readInteger()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,141 +0,0 @@
|
||||||
package org.hwo.pulscounter;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.hwo.io.SerialPort;
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
|
|
||||||
public class PulsCounterDevice {
|
|
||||||
|
|
||||||
private List<CounterChannel> channels; // Aktuelle ZŠhlerstŠnde
|
|
||||||
private List<TimeBarrier> timeBarriers; // TageszeitabhŠngige Wertespeicher
|
|
||||||
|
|
||||||
private Random random;
|
|
||||||
|
|
||||||
private SerialPort serialPort;
|
|
||||||
|
|
||||||
public PulsCounterDevice()
|
|
||||||
{
|
|
||||||
random = new Random();
|
|
||||||
|
|
||||||
channels = new ArrayList<CounterChannel>();
|
|
||||||
timeBarriers = new ArrayList<TimeBarrier>();
|
|
||||||
|
|
||||||
for (int n=0;n<32;n++)
|
|
||||||
{
|
|
||||||
channels.add(new CounterChannel(n + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int n=0;n<10;n++)
|
|
||||||
{
|
|
||||||
timeBarriers.add(new TimeBarrier(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized public void reset(int ch)
|
|
||||||
{
|
|
||||||
if (serialPort == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ServiceLink sl = new ServiceLink(serialPort);
|
|
||||||
|
|
||||||
sl.writeInt((byte)0, (byte)0, (short)(0x1000 + ch), 0);
|
|
||||||
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
System.err.println("Exception: " + e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serialPort.isOpen())
|
|
||||||
serialPort.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized public void reset()
|
|
||||||
{
|
|
||||||
if (serialPort == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ServiceLink sl = new ServiceLink(serialPort);
|
|
||||||
|
|
||||||
for (int i=0;i<32;i++)
|
|
||||||
sl.writeInt((byte)0, (byte)0, (short)(0x1000 + i), 0);
|
|
||||||
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
System.err.println("Exception: " + e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serialPort.isOpen())
|
|
||||||
serialPort.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
synchronized public void update()
|
|
||||||
{
|
|
||||||
if (serialPort == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ServiceLink sl = new ServiceLink(serialPort);
|
|
||||||
|
|
||||||
System.err.println(String.format("BRKVAL: 0x%04x", sl.readInt((byte)0, (byte)0, (short)0x200)));
|
|
||||||
System.err.println(String.format("SPLIM : 0x%04x", sl.readInt((byte)0, (byte)0, (short)0x201)));
|
|
||||||
|
|
||||||
|
|
||||||
for (int i=0;i<32;i++)
|
|
||||||
{
|
|
||||||
channels.get(i).setValue( sl.readInt((byte)0x0D, (byte)0, (short)(0x1000 + i)) );
|
|
||||||
}
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
System.err.println("Exception: " + e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serialPort.isOpen())
|
|
||||||
serialPort.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getDeviceName()
|
|
||||||
{
|
|
||||||
return "PulsCounter Board";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDeviceTime()
|
|
||||||
{
|
|
||||||
return new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CounterChannel> getChannels()
|
|
||||||
{
|
|
||||||
return channels;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TimeBarrier> getTimeBarriers()
|
|
||||||
{
|
|
||||||
return timeBarriers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SerialPort getSerialPort() {
|
|
||||||
return serialPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSerialPort(SerialPort serialPort) {
|
|
||||||
this.serialPort = serialPort;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
package org.hwo.pulscounter;
|
|
||||||
|
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
|
|
||||||
public class PulsCounterInterface {
|
|
||||||
|
|
||||||
|
|
||||||
public PulsCounterInterface(String portName)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> readCounter()
|
|
||||||
{
|
|
||||||
ArrayList<Integer> counter = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (port.open())
|
|
||||||
{
|
|
||||||
port.close();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
for (int i=0;i<32;i++)
|
|
||||||
counter.add( i * i);
|
|
||||||
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue