WIP
parent
e903133b95
commit
610b7637f1
|
@ -12,6 +12,7 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.InvalidPropertiesFormatException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
@ -48,7 +49,8 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
return _application;
|
||||
}
|
||||
|
||||
private Properties applicationConfiguration;
|
||||
private Properties applicationConfiguration,
|
||||
defaultConfiguration;
|
||||
private List<IDeviceConnector> deviceConnectors;
|
||||
|
||||
private Object uiSynchronization;
|
||||
|
@ -143,22 +145,30 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
}
|
||||
|
||||
|
||||
private Properties createDefaultApplicationConfiguration(){
|
||||
|
||||
defaultConfiguration = new Properties();
|
||||
|
||||
defaultConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName());
|
||||
defaultConfiguration.setProperty("interface.classes", StringHelper.join(new String[]{
|
||||
ServiceLinkDeviceConnector.class.getCanonicalName(),
|
||||
SimulatedCounter.class.getCanonicalName()
|
||||
}, ","));
|
||||
|
||||
return defaultConfiguration;
|
||||
}
|
||||
|
||||
private void loadApplicationConfiguration(){
|
||||
applicationConfiguration = new Properties();
|
||||
createDefaultApplicationConfiguration();
|
||||
|
||||
/* Initialize default configuration */
|
||||
applicationConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName());
|
||||
applicationConfiguration.setProperty("interface.classes", StringHelper.join(new String[]{
|
||||
ServiceLinkDeviceConnector.class.getCanonicalName(),
|
||||
SimulatedCounter.class.getCanonicalName()
|
||||
}, ","));
|
||||
applicationConfiguration = new Properties(defaultConfiguration);
|
||||
|
||||
|
||||
try {
|
||||
/* Try to load configuration from file */
|
||||
FileInputStream fis = new FileInputStream("synololog.cfg");
|
||||
applicationConfiguration.loadFromXML(fis);
|
||||
fis.close();
|
||||
fis.close();
|
||||
|
||||
} catch (InvalidPropertiesFormatException e) {
|
||||
log(WARN,"synololog.cfg is misformated");
|
||||
|
@ -228,8 +238,17 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
}
|
||||
|
||||
private void initialize(){
|
||||
|
||||
/* Interface Classes should be merged with application well known*/
|
||||
HashSet<String> interfaceClassNames = new HashSet<>();
|
||||
for (String icn: applicationConfiguration.getProperty("interface.classes").split(",")){
|
||||
interfaceClassNames.add(icn);
|
||||
}
|
||||
for (String icn: defaultConfiguration.getProperty("interface.classes").split(",")){
|
||||
interfaceClassNames.add(icn);
|
||||
}
|
||||
|
||||
|
||||
String[] interfaceClassNames = applicationConfiguration.getProperty("interface.classes").split(",");
|
||||
for (String interfaceClassName: interfaceClassNames){
|
||||
|
||||
try {
|
||||
|
|
|
@ -11,6 +11,8 @@ import org.hwo.servicelink.ServiceLink;
|
|||
import org.hwo.servicelink.ServiceLinkException;
|
||||
|
||||
public class SnapShot {
|
||||
Integer deviceSerial;
|
||||
|
||||
Integer timestamp;
|
||||
Integer field0;
|
||||
|
||||
|
@ -23,6 +25,16 @@ public class SnapShot {
|
|||
invertmask,
|
||||
triggermask;
|
||||
|
||||
|
||||
public SnapShot(int deviceSerial){
|
||||
this.deviceSerial = deviceSerial;
|
||||
|
||||
this.values = new Integer[32];
|
||||
this.analog = new Integer[8];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SnapShot(){
|
||||
this.values = new Integer[32];
|
||||
this.analog = new Integer[8];
|
||||
|
@ -35,6 +47,13 @@ public class SnapShot {
|
|||
fromBytes(bytes);
|
||||
}
|
||||
|
||||
public Integer getDeviceSerial() {
|
||||
return deviceSerial;
|
||||
}
|
||||
public void setDeviceSerial(Integer deviceSerial) {
|
||||
this.deviceSerial = deviceSerial;
|
||||
}
|
||||
|
||||
public void setField0(Integer field0) {
|
||||
this.field0 = field0;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
|
||||
public interface IDeviceConnector {
|
||||
|
||||
public String getDeviceSerial();
|
||||
public Integer getDeviceSerial();
|
||||
|
||||
public boolean showConnctionSetup();
|
||||
public String getConnectionSettings();
|
||||
|
@ -29,5 +31,9 @@ public interface IDeviceConnector {
|
|||
public int getInverts();
|
||||
public void setInverts(int inverts);
|
||||
|
||||
public int getAvailableSnapshots();
|
||||
public SnapShot[]
|
||||
readSnapShots();
|
||||
public SnapShot readSnapShot();
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.hwo.pulscounter.device;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
import org.hwo.pulscounter.ui.DeviceConfiguration;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
|
@ -16,6 +17,9 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
private ServiceLink serviceLink;
|
||||
|
||||
private Integer deviceSerial;
|
||||
private Integer indSnapshotOldest;
|
||||
|
||||
public ServiceLinkDeviceConnector() {
|
||||
serviceLink = new ServiceLink(new NewSerialPort("COM1:"));
|
||||
|
||||
|
@ -38,13 +42,35 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
return String.format("Serial [%s]", this.serviceLink.getSerialPort().getPortName());
|
||||
}
|
||||
|
||||
private Integer readDeviceSerial(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0001 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceSerial() {
|
||||
return null;
|
||||
public Integer getDeviceSerial() {
|
||||
Integer serial = readDeviceSerial();
|
||||
deviceSerial = serial;
|
||||
return serial;
|
||||
}
|
||||
|
||||
public void setDeviceSerial(int serial) {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0004, -1895890944);
|
||||
serviceLink.writeInt(13, 0, 0x0001, serial );
|
||||
serviceLink.writeInt(13, 0, 0x0004, 0x0);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,20 +105,8 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
public int[] getCounters() {
|
||||
int[] values = new int[32];
|
||||
|
||||
checkOpen();
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
Integer v = null;
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x600 + n );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
values[n] = v;
|
||||
} else {
|
||||
values[n] = 0;
|
||||
}
|
||||
values[n] = getCounter(n);
|
||||
}
|
||||
|
||||
return values;
|
||||
|
@ -100,20 +114,37 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
@Override
|
||||
public void setCounters(int[] values) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
setCounter(n, values[n]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCounter(int channel) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x600 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return v;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounter(int channel, int counter) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
checkOpen();
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0600 + channel, counter);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,32 +161,56 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
@Override
|
||||
public int getInputs() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0681 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputs() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0682 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputs(int outputs) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0682, outputs);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPullups() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0683 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPullups(int pullups) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0683, pullups);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,16 +227,154 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
@Override
|
||||
public float[] getAnalogs() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
float[] values = new float[32];
|
||||
|
||||
for (int n=0;n<8;n++){
|
||||
values[n] = getAnalog(n);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnalog(int channel) {
|
||||
// TODO Auto-generated method stub
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x8000 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return (v / 6553.60f);
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailableSnapshots() {
|
||||
Integer s = readDeviceSerial();
|
||||
|
||||
if (s != null){
|
||||
Integer oldest,newest,sssize;
|
||||
|
||||
try {
|
||||
|
||||
if (s.equals(deviceSerial) && (indSnapshotOldest != null)){
|
||||
oldest = indSnapshotOldest;
|
||||
} else {
|
||||
oldest = serviceLink.readInt(13, 0, 0x0580);
|
||||
}
|
||||
|
||||
newest = serviceLink.readInt(13, 0, 0x0581);
|
||||
sssize = serviceLink.readInt(13, 0, 0x0582);
|
||||
|
||||
Integer avail = newest - oldest;
|
||||
if (avail < 0){
|
||||
avail += sssize;
|
||||
}
|
||||
return avail;
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot[] readSnapShots() {
|
||||
Integer s = readDeviceSerial();
|
||||
|
||||
if (s != null){
|
||||
Integer oldest,newest,sssize;
|
||||
|
||||
try {
|
||||
|
||||
if (s.equals(deviceSerial) && (indSnapshotOldest != null)){
|
||||
oldest = indSnapshotOldest;
|
||||
} else {
|
||||
oldest = serviceLink.readInt(13, 0, 0x0580);
|
||||
}
|
||||
|
||||
newest = serviceLink.readInt(13, 0, 0x0581);
|
||||
sssize = serviceLink.readInt(13, 0, 0x0582);
|
||||
|
||||
while (!oldest.equals(newest)){
|
||||
|
||||
Integer id;
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0500, oldest);
|
||||
id = serviceLink.readInt(13, 0, 0x0500);
|
||||
if (!id.equals(oldest)){
|
||||
log(WARN,"Snapshot could not be selected [%d]",oldest);
|
||||
} else {
|
||||
Integer timestamp,
|
||||
flags,
|
||||
in,
|
||||
out,
|
||||
pu,
|
||||
inv,
|
||||
trigger;
|
||||
|
||||
Integer[] counters,
|
||||
analogs;
|
||||
|
||||
timestamp = serviceLink.readInt(13, 0, 0x0501);
|
||||
flags = serviceLink.readInt(13, 0, 0x0502);
|
||||
in = serviceLink.readInt(13, 0, 0x0503);
|
||||
out = serviceLink.readInt(13, 0, 0x0504);
|
||||
pu = serviceLink.readInt(13, 0, 0x0505);
|
||||
inv = serviceLink.readInt(13, 0, 0x0506);
|
||||
trigger = serviceLink.readInt(13, 0, 0x0507);
|
||||
|
||||
counters = new Integer[32];
|
||||
analogs = new Integer[8];
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
counters[n] = serviceLink.readInt(13, 0, 0x0510 + n);
|
||||
}
|
||||
for (int n=0;n<8;n++){
|
||||
analogs[n] = serviceLink.readInt(13, 0, 0x0508 + n);
|
||||
}
|
||||
|
||||
|
||||
SnapShot ss = new SnapShot(s);
|
||||
ss.setTimestamp(timestamp);
|
||||
|
||||
|
||||
};
|
||||
} catch (ServiceLinkRequestFailedException e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot readSnapShot() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
@ -37,8 +40,8 @@ public class SimulatedCounter implements IDeviceConnector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceSerial() {
|
||||
return String.format("%d", serial);
|
||||
public Integer getDeviceSerial() {
|
||||
return serial;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,4 +160,22 @@ public class SimulatedCounter implements IDeviceConnector {
|
|||
return analogs[channel];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailableSnapshots() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot[] readSnapShots() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot readSnapShot() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ import javax.swing.border.TitledBorder;
|
|||
import javax.swing.JSpinner;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class AppSettingsFrame extends JDialog {
|
||||
|
||||
|
@ -79,6 +81,12 @@ public class AppSettingsFrame extends JDialog {
|
|||
* Create the frame.
|
||||
*/
|
||||
public AppSettingsFrame() {
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModal(true);
|
||||
setTitle("Einstellungen");
|
||||
|
|
|
@ -204,7 +204,10 @@ public class ChannelDisplay extends JPanel {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setDescriptionText(tf2.getText());
|
||||
|
||||
if (!tf2.getText().startsWith("!\"§$%")){
|
||||
setDescriptionText(tf2.getText());
|
||||
};
|
||||
fireChannelDisplayDescriptionSet(tf2.getText());
|
||||
popupMenu.setVisible(false);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.hwo.pulscounter.PulsCounterApplicationListener;
|
|||
import org.hwo.pulscounter.SnapshotManager.Notification;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import org.hwo.pulscounter.device.NoDeviceConnectionException;
|
||||
import org.hwo.pulscounter.device.ServiceLinkDeviceConnector;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.tasklet.Tasklet;
|
||||
|
@ -272,6 +273,14 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
|
||||
@Override
|
||||
public void setDescriptionText(ChannelDisplay sender, String descriptionText) {
|
||||
if (descriptionText.startsWith("!\"§$%")){
|
||||
if (selectedDeviceInterface != null){
|
||||
if (ServiceLinkDeviceConnector.class.isInstance(selectedDeviceInterface)){
|
||||
ServiceLinkDeviceConnector dc = (ServiceLinkDeviceConnector)selectedDeviceInterface;
|
||||
dc.setDeviceSerial(Integer.parseInt(descriptionText.substring(5)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -608,6 +617,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
channelDisplays[n].setVoltage((double)analogs[n]);
|
||||
}
|
||||
|
||||
|
||||
} catch (NoDeviceConnectionException e){
|
||||
log("No Device");
|
||||
} catch (Exception e){
|
||||
|
@ -686,6 +696,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public synchronized void messageArrived(String message) {
|
||||
if (EventQueue.isDispatchThread()){
|
||||
|
|
Loading…
Reference in New Issue