numass cryotemp update

This commit is contained in:
darksnake 2016-10-14 16:31:21 +03:00
parent f3ecec7dfc
commit 4e179d6814
11 changed files with 89 additions and 92 deletions

View File

@ -5,6 +5,8 @@ if (!hasProperty('mainClass')) {
} }
mainClassName = mainClass mainClassName = mainClass
version = "0.1.1";
//mainClassName = "inr.numass.readvac.Main" //mainClassName = "inr.numass.readvac.Main"
dependencies { dependencies {

View File

@ -38,7 +38,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Locale;
/** /**
* @author darksnake * @author darksnake
@ -76,7 +75,7 @@ public class PKT8App extends Application {
@Override @Override
public void start(Stage primaryStage) throws IOException, ControlException, ParseException { public void start(Stage primaryStage) throws IOException, ControlException, ParseException {
Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой // Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.INFO); rootLogger.setLevel(Level.INFO);
new StorageManager().startGlobal(); new StorageManager().startGlobal();

View File

@ -36,9 +36,9 @@ import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.PointListener; import hep.dataforge.tables.PointListener;
import hep.dataforge.tables.TableFormatBuilder; import hep.dataforge.tables.TableFormatBuilder;
import hep.dataforge.utils.DateTimeUtils;
import java.time.Duration; import java.time.Duration;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -261,7 +261,7 @@ public class PKT8Device extends PortSensor<PKT8Result> {
.map(it -> ((StorageConnection) it.getKey()).getStorage()).collect(Collectors.toList()); .map(it -> ((StorageConnection) it.getKey()).getStorage()).collect(Collectors.toList());
storages.forEach(storage -> { storages.forEach(storage -> {
String suffix = Integer.toString((int) Instant.now().toEpochMilli()); String suffix = Integer.toString((int) DateTimeUtils.now().toEpochMilli());
PointLoader pointLoader = null; PointLoader pointLoader = null;
try { try {

View File

@ -18,6 +18,9 @@ package inr.numass.control.magnet;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.control.ports.PortTimeoutException; import hep.dataforge.control.ports.PortTimeoutException;
import hep.dataforge.exceptions.PortException; import hep.dataforge.exceptions.PortException;
import hep.dataforge.utils.DateTimeUtils;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
@ -25,7 +28,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -34,46 +36,28 @@ import org.slf4j.LoggerFactory;
*/ */
public class MagnetController implements PortHandler.PortController { public class MagnetController implements PortHandler.PortController {
private static final DecimalFormat LAMBDAformat = new DecimalFormat("###.##");
public static double CURRENT_PRECISION = 0.05; public static double CURRENT_PRECISION = 0.05;
// public static double CURRENT_STEP = 0.05; // public static double CURRENT_STEP = 0.05;
public static int DEFAULT_DELAY = 1; public static int DEFAULT_DELAY = 1;
public static int DEFAULT_MONITOR_DELAY = 2000; public static int DEFAULT_MONITOR_DELAY = 2000;
public static double MAX_STEP_SIZE = 0.2; public static double MAX_STEP_SIZE = 0.2;
public static double MIN_UP_STEP_SIZE = 0.005; public static double MIN_UP_STEP_SIZE = 0.005;
public static double MIN_DOWN_STEP_SIZE = 0.05; public static double MIN_DOWN_STEP_SIZE = 0.05;
public static double MAX_SPEED = 5d; // 5 A per minute public static double MAX_SPEED = 5d; // 5 A per minute
private static final DecimalFormat LAMBDAformat = new DecimalFormat("###.##");
/**
* Method converts double to LAMBDA string
*
* @param d double that should be converted to string
* @return string
*/
private static String d2s(double d) {
return LAMBDAformat.format(d);
}
private final String name; private final String name;
private final PortHandler port; private final PortHandler port;
private final int address; private final int address;
private final ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
protected MagnetStateListener listener;
private volatile double current = 0; private volatile double current = 0;
private int timeout = 200; private int timeout = 200;
private Future monitorTask; private Future monitorTask;
private Future updateTask; private Future updateTask;
protected MagnetStateListener listener;
private Instant lastUpdate = null; private Instant lastUpdate = null;
private double speed = MAX_SPEED; private double speed = MAX_SPEED;
private final ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
/** /**
* This method creates an element of class MegnetController with exact * This method creates an element of class MegnetController with exact
* parameters. If you have two parameters for your method - the next * parameters. If you have two parameters for your method - the next
@ -104,6 +88,16 @@ public class MagnetController implements PortHandler.PortController {
this(name, port, address, 300); this(name, port, address, 300);
} }
/**
* Method converts double to LAMBDA string
*
* @param d double that should be converted to string
* @return string
*/
private static String d2s(double d) {
return LAMBDAformat.format(d);
}
public void setListener(MagnetStateListener listener) { public void setListener(MagnetStateListener listener) {
this.listener = listener; this.listener = listener;
} }
@ -180,7 +174,7 @@ public class MagnetController implements PortHandler.PortController {
if (!setState("PC", current)) { if (!setState("PC", current)) {
error("Can't set the current", null); error("Can't set the current", null);
} else { } else {
lastUpdate = Instant.now(); lastUpdate = DateTimeUtils.now();
} }
} }
@ -199,7 +193,6 @@ public class MagnetController implements PortHandler.PortController {
* Gets status of magnet for current moment * Gets status of magnet for current moment
* *
* @return status of magnet * @return status of magnet
* @throws inr.numass.control.magnet.PortException
*/ */
private MagnetStatus getStatus() throws PortException { private MagnetStatus getStatus() throws PortException {
try { try {
@ -326,7 +319,7 @@ public class MagnetController implements PortHandler.PortController {
} else { } else {
//Choose optimal speed but do not exceed maximum speed //Choose optimal speed but do not exceed maximum speed
step = Math.min(MAX_STEP_SIZE, step = Math.min(MAX_STEP_SIZE,
(double) lastUpdate.until(Instant.now(), ChronoUnit.MILLIS) / 60000d * getSpeed()); (double) lastUpdate.until(DateTimeUtils.now(), ChronoUnit.MILLIS) / 60000d * getSpeed());
} }
double res; double res;

View File

@ -19,12 +19,14 @@ import ch.qos.logback.classic.Level;
import hep.dataforge.control.ports.PortFactory; import hep.dataforge.control.ports.PortFactory;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.exceptions.PortException; import hep.dataforge.exceptions.PortException;
import hep.dataforge.utils.DateTimeUtils;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Locale; import java.util.Locale;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -57,10 +59,10 @@ public class Talk {
while (!"exit".equals(nextString)) { while (!"exit".equals(nextString)) {
try { try {
Instant start = Instant.now(); Instant start = DateTimeUtils.now();
String answer = handler.sendAndWait(nextString + "\r", null, 1000); String answer = handler.sendAndWait(nextString + "\r", null, 1000);
//String answer = controller.request(nextString); //String answer = controller.request(nextString);
System.out.printf("ANSWER (latency = %s): %s;%n", Duration.between(start, Instant.now()), answer.trim()); System.out.printf("ANSWER (latency = %s): %s;%n", Duration.between(start, DateTimeUtils.now()), answer.trim());
} catch (PortException ex) { } catch (PortException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }

View File

@ -35,6 +35,7 @@ import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint; import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.TableFormat; import hep.dataforge.tables.TableFormat;
import hep.dataforge.tables.TableFormatBuilder; import hep.dataforge.tables.TableFormatBuilder;
import hep.dataforge.utils.DateTimeUtils;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import java.time.Instant; import java.time.Instant;
@ -405,7 +406,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
TableFormat format = builder.build(); TableFormat format = builder.build();
String suffix = Integer.toString((int) Instant.now().toEpochMilli()); String suffix = Integer.toString((int) DateTimeUtils.now().toEpochMilli());
PointLoader loader = LoaderFactory PointLoader loader = LoaderFactory
.buildPointLoder(storage, "msp" + suffix, "", "timestamp", format); .buildPointLoder(storage, "msp" + suffix, "", "timestamp", format);
return loader; return loader;
@ -491,7 +492,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
throw new IllegalStateException("Peal map is not initialized"); throw new IllegalStateException("Peal map is not initialized");
} }
Instant time = Instant.now(); Instant time = DateTimeUtils.now();
MapPoint.Builder point = new MapPoint.Builder(); MapPoint.Builder point = new MapPoint.Builder();
point.putValue("timestamp", time); point.putValue("timestamp", time);

View File

@ -14,7 +14,7 @@ import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.tables.TableFormatBuilder; import hep.dataforge.tables.TableFormatBuilder;
import hep.dataforge.values.ValueType; import hep.dataforge.values.ValueType;
import inr.numass.client.NumassClient; import inr.numass.client.ClientUtils;
import inr.numass.readvac.devices.*; import inr.numass.readvac.devices.*;
import inr.numass.readvac.fx.VacCollectorController; import inr.numass.readvac.fx.VacCollectorController;
import javafx.application.Application; import javafx.application.Application;
@ -35,6 +35,13 @@ public class ReadVac extends Application {
VacCollectorController controller; VacCollectorController controller;
Logger logger = LoggerFactory.getLogger("ReadVac"); Logger logger = LoggerFactory.getLogger("ReadVac");
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
String configFileName = getParameters().getNamed().get("config"); String configFileName = getParameters().getNamed().get("config");
@ -78,18 +85,18 @@ public class ReadVac extends Application {
controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> { controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> {
try { try {
String runName = device.meta().getString("numass.run", ""); String runName = ClientUtils.getRunName(config);
if (config.hasMeta("numass")) { // String runName = device.meta().getString("numass.run", "");
try { // if (config.hasMeta("numass.server")) {
logger.info("Obtaining run information from cetral server..."); // try {
NumassClient client = new NumassClient(config.getString("numass.ip", "192.168.111.1"), // logger.info("Obtaining run information from cetral server...");
config.getInt("numass.port", 8335)); // NumassClient client = new NumassClient(get);
runName = client.getCurrentRun().getString("path", ""); // runName = client.getCurrentRun().getString("path", "");
logger.info("Run name is '{}'", runName); // logger.info("Run name is '{}'", runName);
} catch (Exception ex) { // } catch (Exception ex) {
logger.warn("Failed to download current run information", ex); // logger.warn("Failed to download current run information", ex);
} // }
} // }
TableFormatBuilder format = new TableFormatBuilder().setType("timestamp", ValueType.TIME); TableFormatBuilder format = new TableFormatBuilder().setType("timestamp", ValueType.TIME);
device.getSensors().stream().forEach((s) -> { device.getSensors().stream().forEach((s) -> {
@ -120,11 +127,4 @@ public class ReadVac extends Application {
super.stop(); super.stop();
} }
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
} }

View File

@ -17,6 +17,7 @@ import hep.dataforge.exceptions.MeasurementException;
import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.DataPoint;
import hep.dataforge.tables.MapPoint; import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.PointListener; import hep.dataforge.tables.PointListener;
import hep.dataforge.utils.DateTimeUtils;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import java.time.Instant; import java.time.Instant;
@ -134,7 +135,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
private DataPoint terminator() { private DataPoint terminator() {
MapPoint.Builder p = new MapPoint.Builder(); MapPoint.Builder p = new MapPoint.Builder();
p.putValue("timestamp", Instant.now()); p.putValue("timestamp", DateTimeUtils.now());
sensorMap.keySet().stream().forEach((n) -> { sensorMap.keySet().stream().forEach((n) -> {
p.putValue(n, null); p.putValue(n, null);
}); });

View File

@ -15,11 +15,9 @@
*/ */
package inr.numass.readvac; package inr.numass.readvac;
import java.time.Instant; import hep.dataforge.utils.DateTimeUtils;
import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.*;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
/** /**
* *
@ -31,7 +29,7 @@ public class TimeShiftTest {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Instant now = Instant.now(); Instant now = DateTimeUtils.now();
System.out.println(now.toString()); System.out.println(now.toString());
LocalDateTime ldt = LocalDateTime.now(); LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt.toString()); System.out.println(ldt.toString());

View File

@ -8,17 +8,17 @@ import java.io.IOException;
* Created by darksnake on 09-Oct-16. * Created by darksnake on 09-Oct-16.
*/ */
public class ClientUtils { public class ClientUtils {
public String getRunName(Meta config) { public static String getRunName(Meta config) {
if (config.hasValue("numass.run")) { if (config.hasValue("numass.run")) {
return config.getString("numass.run"); return config.getString("numass.run");
} else if (config.hasMeta("numass.server")) { } else if (config.hasMeta("numass.server")) {
try { try {
return new NumassClient(config.getMeta("numass.server")).getCurrentRun().getString("path"); return new NumassClient(config.getMeta("numass.server")).getCurrentRun().getString("path");
} catch (IOException e) { } catch (IOException e) {
return "default"; return "";
} }
} else { } else {
return "default"; return "";
} }
} }
} }

View File

@ -7,6 +7,8 @@ package inr.numass.server;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.utils.DateTimeUtils;
import java.io.Serializable; import java.io.Serializable;
import java.time.Instant; import java.time.Instant;
@ -17,20 +19,9 @@ import java.time.Instant;
*/ */
public class NumassNote implements Serializable { public class NumassNote implements Serializable {
public static NumassNote buildFrom(Meta meta) {
String text = meta.getString("text", "");
if (meta.hasValue("time")) {
Instant time = meta.getValue("time").timeValue();
return new NumassNote(text, time);
} else {
return new NumassNote(text);
}
}
private final String content; private final String content;
private final String ref; private final String ref;
private final Instant time; private final Instant time;
public NumassNote(String content, Instant time) { public NumassNote(String content, Instant time) {
this.content = content; this.content = content;
this.time = time; this.time = time;
@ -39,10 +30,20 @@ public class NumassNote implements Serializable {
public NumassNote(String content) { public NumassNote(String content) {
this.content = content; this.content = content;
this.time = Instant.now(); this.time = DateTimeUtils.now();
this.ref = "#" + time.hashCode(); this.ref = "#" + time.hashCode();
} }
public static NumassNote buildFrom(Meta meta) {
String text = meta.getString("text", "");
if (meta.hasValue("time")) {
Instant time = meta.getValue("time").timeValue();
return new NumassNote(text, time);
} else {
return new NumassNote(text);
}
}
/** /**
* Text content * Text content
* *