some fixes and tests
This commit is contained in:
parent
9f205dcd07
commit
d3e1feda5b
@ -1,10 +1,7 @@
|
||||
plugins{
|
||||
id "org.jetbrains.kotlin.jvm" version '1.1.2'
|
||||
id "application"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
id 'com.github.johnrengelman.shadow' version '2.0.0'
|
||||
}
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
@ -30,6 +27,8 @@ dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2"
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
shadowJar{
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ import hep.dataforge.context.Context
|
||||
import hep.dataforge.exceptions.StorageException
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.server.ServerManager
|
||||
import hep.dataforge.server.storage.StorageServeUtils
|
||||
import hep.dataforge.storage.commons.StorageFactory
|
||||
import inr.numass.client.ClientUtils
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
@ -77,7 +78,7 @@ class ServerView() : View("Numass server controller") {
|
||||
}
|
||||
|
||||
}
|
||||
serverManager.addStorage("numass", storage);
|
||||
StorageServeUtils.addStorage(serverManager,storage,"numass-storage")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import hep.dataforge.exceptions.ControlException;
|
||||
import hep.dataforge.meta.Meta;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -24,6 +25,7 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
@ValueDef(name = "address", type = "NUMBER", def = "1", info = "A modbus address")
|
||||
public class MeradatVacDevice extends PortSensor<Double> {
|
||||
private static final String REQUEST = "0300000002";
|
||||
|
||||
public MeradatVacDevice() {
|
||||
}
|
||||
@ -42,7 +44,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
|
||||
@Override
|
||||
protected Measurement<Double> createMeasurement() {
|
||||
return new MeradatMeasurement(meta().getInt("address", 1));
|
||||
return new MeradatMeasurement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,6 +52,24 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
return meta().getString("type", "Vit vacuumeter");
|
||||
}
|
||||
|
||||
public static String calculateLRC(String inputString) {
|
||||
/*
|
||||
* String is Hex String, need to convert in ASCII.
|
||||
*/
|
||||
byte[] bytes = new BigInteger(inputString, 16).toByteArray();
|
||||
int checksum = 0;
|
||||
for (byte aByte : bytes) {
|
||||
checksum += aByte;
|
||||
}
|
||||
String val = Integer.toHexString(-checksum);
|
||||
val = val.substring(val.length()-2).toUpperCase();
|
||||
if (val.length() < 2) {
|
||||
val = "0" + val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
private class MeradatMeasurement extends SimpleMeasurement<Double> {
|
||||
|
||||
@ -57,9 +77,10 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
private final Pattern response;
|
||||
private final String base;
|
||||
|
||||
public MeradatMeasurement(int address) {
|
||||
base = String.format(":%02d", address);
|
||||
query = base + "0300000002FA\r\n";
|
||||
public MeradatMeasurement() {
|
||||
base = String.format(":%02d", meta().getInt("address", 1));
|
||||
String dataStr = base.substring(1) + REQUEST;
|
||||
query = base + REQUEST + calculateLRC(dataStr) + "\r\n";
|
||||
response = Pattern.compile(base + "0304(\\w{4})(\\w{4})..\r\n");
|
||||
}
|
||||
|
||||
@ -86,8 +107,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
this.progressUpdate("OK");
|
||||
updateState(CONNECTED_STATE, true);
|
||||
return res.doubleValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.progressUpdate("Wrong answer: " + answer);
|
||||
updateState(CONNECTED_STATE, false);
|
||||
return null;
|
||||
|
@ -7,6 +7,6 @@
|
||||
<sensor name="P3" color="green" port="tcp::192.168.111.32:4003" sensorType="CM32"/>
|
||||
<sensor name="Px" color="black" port="tcp::192.168.111.33:4003" sensorType="meradat" address="1"/>
|
||||
<sensor name="Baratron" color="cyan" port="tcp::192.168.111.33:4004" sensorType="baratron"/>
|
||||
<sensor name="Collector" color="magenta" port="tcp::192.168.111.33:4003" sensorType="meradat" address="5"/>
|
||||
<sensor name="Collector" color="magenta" port="tcp::192.168.111.33:4003" sensorType="meradat" address="2"/>
|
||||
</device>
|
||||
</config>
|
||||
|
@ -0,0 +1,17 @@
|
||||
package inr.numass.readvac
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
/**
|
||||
* Created by darksnake on 22-May-17.
|
||||
*/
|
||||
class MeradatVacTest extends Specification {
|
||||
def "CalculateLRC"() {
|
||||
given:
|
||||
def str = "020300000002";
|
||||
when:
|
||||
def lrc = MeradatVacDevice.calculateLRC(str).toUpperCase();
|
||||
then:
|
||||
lrc == "F9"
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@ import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static hep.dataforge.server.storage.StorageRenderer.renderStorage;
|
||||
import static inr.numass.server.HandlerUtils.renderStates;
|
||||
|
||||
/**
|
||||
@ -68,7 +67,7 @@ public class NumassRootHandler implements Handler {
|
||||
StringBuilder b = new StringBuilder();
|
||||
Storage rootStorage = server.getRun().getStorage();
|
||||
rootStorage.refresh();
|
||||
renderStorage(b,manager.resolveObject(rootStorage), rootStorage);
|
||||
//renderStorage(b, manager.resolveObject(rootStorage), rootStorage);
|
||||
data.put("storageContent", b.toString());
|
||||
} catch (Exception ex) {
|
||||
data.put("storageContent", ex.toString());
|
||||
|
@ -8,6 +8,7 @@ package inr.numass.server;
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.context.Global;
|
||||
import hep.dataforge.server.ServerManager;
|
||||
import hep.dataforge.server.storage.StorageServeUtils;
|
||||
import hep.dataforge.storage.commons.StorageManager;
|
||||
import hep.dataforge.storage.filestorage.FileStorageFactory;
|
||||
import inr.numass.storage.NumassStorage;
|
||||
@ -35,7 +36,7 @@ public class TestServer {
|
||||
context.getLogger().info("Starting test numass storage servlet in '{}'", path);
|
||||
|
||||
NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
|
||||
serverManager.bind("numass", storage, NumassStorageHandler::new);
|
||||
StorageServeUtils.addStorage(serverManager,storage,"numass-storage");
|
||||
|
||||
serverManager.startServer();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user