Skip to content

Commit

Permalink
Progress #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvord committed May 22, 2021
1 parent d6a3d9a commit d22e885
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
29 changes: 13 additions & 16 deletions src/main/java/hzg/wpn/tango/DataFormatServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public String getNxPath() throws Exception {
@Attribute
public void setNxPath(String nxPath) throws Exception {
String clientId = getClientId();
//TODO aroundInvoke?
if(NexusWriterHelper.hasMapping("external:" + nxPath)) {
nxPath = NexusWriterHelper.toNxPath("external:" + nxPath);
}
Expand Down Expand Up @@ -396,13 +397,12 @@ public void delete() throws Exception {
}
}

private class DoubleWriter implements NexusWriter {
private class DoubleWriter extends NexusWriter {
private double v;
private String nxPath;

private DoubleWriter(double v, String nxPath) {
super(nxPath);
this.v = v;
this.nxPath = nxPath;
}

@Override
Expand All @@ -415,13 +415,12 @@ public void write(NxFile file) throws IOException {
}
}

private class FloatWriter implements NexusWriter {
private class FloatWriter extends NexusWriter {
private float v;
private String nxPath;

private FloatWriter(float v, String nxPath) {
super(nxPath);
this.v = v;
this.nxPath = nxPath;
}

@Override
Expand All @@ -434,13 +433,12 @@ public void write(NxFile file) throws IOException {
}
}

private class IntegerWriter implements NexusWriter {
private class IntegerWriter extends NexusWriter {
private int v;
private String nxPath;

private IntegerWriter(int v, String nxPath) {
super(nxPath);
this.v = v;
this.nxPath = nxPath;
}

@Override
Expand All @@ -453,14 +451,13 @@ public void write(NxFile file) throws IOException {
}
}

private class LongWriter implements NexusWriter {
private long v;
private String nxPath;
private class LongWriter extends NexusWriter {
long v;


private LongWriter(long v, String nxPath) {
super(nxPath);
this.v = v;
this.nxPath = nxPath;
}

@Override
Expand All @@ -473,13 +470,12 @@ public void write(NxFile file) throws IOException {
}
}

private class StringWriter implements NexusWriter {
private class StringWriter extends NexusWriter {
private String v;
private String nxPath;

private StringWriter(String v, String nxPath) {
super(nxPath);
this.v = v;
this.nxPath = nxPath;
}

@Override
Expand Down Expand Up @@ -509,6 +505,7 @@ public void run() {
} catch (IOException | LibpniioException e) {
DataFormatServer.this.logger.error(e.getMessage(), e);
deviceManager.pushStateChangeEvent(DeviceState.ALARM);
deviceManager.pushStatusChangeEvent(String.format("Failed to write a value into %s in %s due to %s", writer.nxPath ,nxFile.getFileName(), e.getMessage()));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/hzg/wpn/tango/GenericBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
* @author Igor Khokhriakov <[email protected]>
* @since 11.07.2015
*/
public class GenericBlob implements NexusWriter {
public class GenericBlob extends NexusWriter {
private final Logger logger = LoggerFactory.getLogger(GenericBlob.class);

public final List<Element> elements = new ArrayList<>();
private final boolean append;


public GenericBlob(boolean append) {
super(null);
this.append = append;
}

public GenericBlob(PipeBlob blob) throws DevFailed {
super(null);
this.append = blob.get(0).extractBooleanArray()[0];


Expand Down
10 changes: 8 additions & 2 deletions src/main/java/hzg/wpn/tango/NexusWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
* @author Igor Khokhriakov <[email protected]>
* @since 13.07.2015
*/
public interface NexusWriter {
void write(NxFile file) throws IOException;
public abstract class NexusWriter {
final String nxPath;

public NexusWriter(String nxPath) {
this.nxPath = nxPath;
}

abstract void write(NxFile file) throws IOException;
}
3 changes: 2 additions & 1 deletion src/main/java/hzg/wpn/tango/StatusServerBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* @author Igor Khokhriakov <[email protected]>
* @since 11.07.2015
*/
public class StatusServerBlob implements NexusWriter {
public class StatusServerBlob extends NexusWriter {
private final Logger logger = LoggerFactory.getLogger(GenericBlob.class);

public GenericBlob values = new GenericBlob(true);
public GenericBlob times = new GenericBlob(true);

public StatusServerBlob(PipeBlob blob) throws DevFailed {
super(null);
for (PipeDataElement dataElement : blob) {
PipeBlob innerBlob = dataElement.extractPipeBlob();
String name = innerBlob.getName();
Expand Down

0 comments on commit d22e885

Please sign in to comment.