diff --git a/src/config.properties b/src/config.properties index bba40f7..8f4c695 100644 --- a/src/config.properties +++ b/src/config.properties @@ -1,3 +1,5 @@ -URL = https://influx.sdi.hevs.ch -ORG = SIn15 -BUCKET = SIn15 \ No newline at end of file +DB.URL = https://influx.sdi.hevs.ch +DB.ORG = SIn15 +DB.BUCKET = SIn15 +WEB.URL = localhost +WEB.PORT = 8888 \ No newline at end of file diff --git a/src/main/java/ch/hevs/isi/MinecraftController.java b/src/main/java/ch/hevs/isi/MinecraftController.java index 6bc5059..1e6b4ac 100644 --- a/src/main/java/ch/hevs/isi/MinecraftController.java +++ b/src/main/java/ch/hevs/isi/MinecraftController.java @@ -1,13 +1,18 @@ package ch.hevs.isi; -import ch.hevs.isi.core.BooleanDataPoint; -import ch.hevs.isi.core.FloatDataPoint; import ch.hevs.isi.db.DatabaseConnector; +import ch.hevs.isi.field.FieldConnector; import ch.hevs.isi.utils.Utility; +import ch.hevs.isi.web.WebConnector; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; public class MinecraftController { public static boolean ERASE_PREVIOUS_DATA_INB_DB = false; + private static final Properties properties = new Properties(); // Properties of the config.properties file public static void usage() { System.out.println(); @@ -75,21 +80,36 @@ public class MinecraftController { // ------------------------------------ /DO NOT CHANGE THE FOLLOWING LINES ------------------------------------- - // Start coding here ... + // Read the config.properties file + try (InputStream input = new FileInputStream("src/config.properties")) { + properties.load(input); + } catch (Exception e) { + e.printStackTrace(); + } // Initialize the database connector - if((dbProtocol != null) && (dbHostName != null)){ - DatabaseConnector.url = dbProtocol+ "://" + dbHostName; - DatabaseConnector.getMySelf().initialize(dbProtocol+ "://" + dbHostName); - } if(dbName != null){ DatabaseConnector.org = dbName; } if(dbUserName != null){ DatabaseConnector.bucket = dbUserName; } + if((dbProtocol != null) && (dbHostName != null)){ + DatabaseConnector.url = dbProtocol+ "://" + dbHostName; + Utility.pDebug("Database URL: " + DatabaseConnector.url); + Utility.pDebug("Config: " + properties.getProperty("DB.URL")); + DatabaseConnector.getMySelf().initialize(DatabaseConnector.url); + } // Initialize the Modbus TCP connector + FieldConnector.getMySelf().initialize(modbusTcpHost, modbusTcpPort,"src/main/resources/ModbusMap.csv"); + + + + // Initialize the web server + String host = properties.getProperty("WEB.URL"); + int port = Integer.parseInt(properties.getProperty("WEB.PORT")); + WebConnector.getMySelf().initialize(host, port); } diff --git a/src/main/java/ch/hevs/isi/core/BooleanDataPoint.java b/src/main/java/ch/hevs/isi/core/BooleanDataPoint.java index d18131f..dc78181 100644 --- a/src/main/java/ch/hevs/isi/core/BooleanDataPoint.java +++ b/src/main/java/ch/hevs/isi/core/BooleanDataPoint.java @@ -1,27 +1,42 @@ package ch.hevs.isi.core; -import ch.hevs.isi.core.DataPointListener; -import ch.hevs.isi.db.DatabaseConnector; -import ch.hevs.isi.field.FieldConnector; -import ch.hevs.isi.web.WebConnector; public class BooleanDataPoint extends DataPoint{ private boolean value; + /** + * Create a new DataPoint with a label and if is an Output or not + * @param label the label of this DataPoint + * @param isOutput true if this is an Output, false if it's an Input + */ public BooleanDataPoint(String label, boolean isOutput) { super(label, isOutput); } + + /** + * Set the value of this DataPoint and create it if it doesn't exist via the update method + * @param value the value to set + */ public void setValue(boolean value){ this.value = value; - if (getDataPointFromLabel(this.getLabel()) == null){ + if (getDataPointOnListFromLabel(this.getLabel()) == null){ this.update(true); } else { this.update(false); } } + + /** + * Get the value of this DataPoint + * @return the value of this DataPoint + */ public boolean getValue(){ return this.value; } + /** + * Convert this DataPoint to a string + * @return the string representation of this DataPoint + */ public String toString(){ String s; s = this.getLabel(); diff --git a/src/main/java/ch/hevs/isi/core/DataPoint.java b/src/main/java/ch/hevs/isi/core/DataPoint.java index 22d211d..981bda7 100644 --- a/src/main/java/ch/hevs/isi/core/DataPoint.java +++ b/src/main/java/ch/hevs/isi/core/DataPoint.java @@ -1,16 +1,35 @@ package ch.hevs.isi.core; +import ch.hevs.isi.db.DatabaseConnector; +import ch.hevs.isi.field.FieldConnector; +import ch.hevs.isi.web.WebConnector; + import java.util.HashMap; import java.util.Map; public abstract class DataPoint{ - private static Map dataPointMap = new HashMap<>(); - private String label; - private boolean isOutput; + + + public static Map dataPointMap = new HashMap<>(); // Map of all DataPoints + private final String label; // Label of this DataPoint + private final boolean isOutput; // True if this DataPoint is an output, false if it's an input + + /** + * Constructor of DataPoint + * @param label label of this DataPoint + * @param isOutput true if this DataPoint is an output, false if it's an input + */ protected DataPoint(String label, boolean isOutput){ this.label = label; this.isOutput = isOutput; } + + + /** + * Update the value of this DataPoint and notify every connector + * If this is a new value (doesn't exist), add it to the dataPointMap + * @param isNewValue true if this is a new value, false if it's an update + */ protected void update(boolean isNewValue){ if(isNewValue){ @@ -22,7 +41,13 @@ public abstract class DataPoint{ // Update every connector DataPointListener.listeners.forEach(listener -> listener.onNewValue(this)); } - public static DataPoint getDataPointFromLabel(String label){ + + /** + * Get the DataPoint from the label + * @param label label of the DataPoint + * @return the DataPoint if it exists, null otherwise + */ + public static DataPoint getDataPointOnListFromLabel(String label){ if( !dataPointMap.containsKey(label) ){ return null; } else { diff --git a/src/main/java/ch/hevs/isi/core/FloatDataPoint.java b/src/main/java/ch/hevs/isi/core/FloatDataPoint.java index c168dd4..6941ff8 100644 --- a/src/main/java/ch/hevs/isi/core/FloatDataPoint.java +++ b/src/main/java/ch/hevs/isi/core/FloatDataPoint.java @@ -1,27 +1,42 @@ package ch.hevs.isi.core; -import ch.hevs.isi.db.DatabaseConnector; -import ch.hevs.isi.field.FieldConnector; -import ch.hevs.isi.web.WebConnector; - public class FloatDataPoint extends DataPoint{ private float value; + + /** + * Create a new DataPoint with a label and if is an Output or not + * @param label the label of this DataPoint + * @param isOutput true if this is an Output, false if it's an Input + */ public FloatDataPoint(String label, boolean isOutput) { super(label, isOutput); } + + /** + * Set the value of this DataPoint and create it if it doesn't exist via the update method + * @param value the value to set + */ public void setValue(float value){ this.value = value; - if (getDataPointFromLabel(this.getLabel()) == null){ + if (getDataPointOnListFromLabel(this.getLabel()) == null){ this.update(true); } else { this.update(false); } } + /** + * Get the value of this DataPoint + * @return the value of this DataPoint + */ public float getValue(){ return this.value; } + /** + * Convert this DataPoint to a string + * @return the string representation of this DataPoint + */ public String toString(){ String s; s = this.getLabel(); diff --git a/src/main/java/ch/hevs/isi/db/DatabaseConnector.java b/src/main/java/ch/hevs/isi/db/DatabaseConnector.java index 163d6d2..63eb65a 100644 --- a/src/main/java/ch/hevs/isi/db/DatabaseConnector.java +++ b/src/main/java/ch/hevs/isi/db/DatabaseConnector.java @@ -7,20 +7,19 @@ import ch.hevs.isi.core.DataPointListener; import ch.hevs.isi.core.FloatDataPoint; import ch.hevs.isi.utils.Utility; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; -import java.net.ProtocolException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Properties; public class DatabaseConnector implements DataPointListener { private final Properties properties = new Properties(); // Properties of the config.properties file - private String fullURL = null; // Full URL of the InfluxDB server private URL urlForWrite = null; // URL of the InfluxDB server private HttpURLConnection con = null; // Connection to the InfluxDB server private boolean initialized = false; // Boolean to know if the database connector is initialized @@ -40,7 +39,7 @@ public class DatabaseConnector implements DataPointListener { */ private DatabaseConnector (){ // Read the config.properties file - try (InputStream input = new FileInputStream("src/config.properties")) { + try (InputStream input = Files.newInputStream(Paths.get("src/config.properties"))) { properties.load(input); } catch (Exception e) { e.printStackTrace(); @@ -48,13 +47,13 @@ public class DatabaseConnector implements DataPointListener { // Get the URL, the organization and the bucket from the config.properties file if their are null if (url == null){ - url = properties.getProperty("URL"); + url = properties.getProperty("DB.URL"); } if (org == null){ - org = properties.getProperty("ORG"); + org = properties.getProperty("DB.ORG"); } if (bucket == null){ - bucket = properties.getProperty("BUCKET"); + bucket = properties.getProperty("DB.BUCKET"); } // Subscribe to the update of DataPoints @@ -77,10 +76,12 @@ public class DatabaseConnector implements DataPointListener { * @param url URL of the database. If null take the URL from the config.properties file */ public void initialize(String url){ + // Full URL of the InfluxDB server + String fullURL = null; try{ if(urlForWrite == null){ if(url == null){ - url = properties.getProperty("URL"); + url = properties.getProperty("DB.URL"); } fullURL = url + "/api/v2/write?org=" + org + "&bucket=" + bucket; Utility.pDebug("URL: " + fullURL); @@ -106,10 +107,6 @@ public class DatabaseConnector implements DataPointListener { con.setRequestProperty("Content-Type", "text/plain"); con.setRequestProperty("Accept", "application/json"); con.setDoOutput(true); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } catch (ProtocolException e) { - throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } @@ -122,7 +119,7 @@ public class DatabaseConnector implements DataPointListener { data += "}"; Utility.pDebug(data); sendDataToDatabase(data); - fullURL=null; // Reset the full URL + fullURL =null; // Reset the full URL } } @@ -181,7 +178,7 @@ public class DatabaseConnector implements DataPointListener { */ @Override public void onNewValue(DataPoint dp) { - if(dp.getLabel().equals("CLOAK_FLOAT")) { + if(dp.getLabel().equals("CLOCK_FLOAT")) { FloatDataPoint fdp = (FloatDataPoint) dp; _timeManager.setTimestamp(fdp.getValue()); _timestamp = _timeManager.getNanosForDB(); diff --git a/src/main/java/ch/hevs/isi/field/BooleanRegister.java b/src/main/java/ch/hevs/isi/field/BooleanRegister.java index a71e5f0..205f596 100644 --- a/src/main/java/ch/hevs/isi/field/BooleanRegister.java +++ b/src/main/java/ch/hevs/isi/field/BooleanRegister.java @@ -7,18 +7,29 @@ public class BooleanRegister extends ModbusRegister{ private boolean value; private BooleanDataPoint bdp; + /** + * public constructor of the booleanRegister + * + * @param label label of the datapoint + * @param isOutput true if it is an output datapoint + * @param address modbus address of the datapoint + */ public BooleanRegister(String label, boolean isOutput, int address){ - this.bdp = new BooleanDataPoint(label, isOutput); - value = bdp.getValue(); - updateMapOfRegisters(bdp, address); + this.bdp = new BooleanDataPoint(label, isOutput); //create an empty datapoint for the NullPointerException + updateMapOfRegisters(label, address); //add the address to the map } @Override public void read() { - bdp.setValue(ModbusAccessor.getMySelf().readBoolean(this.getAddress())); + if(bdp.isOutput()){ + return; //if it is an output datapoint, it is not read + } + bdp.setValue(ModbusAccessor.getMySelf().readBoolean(this.getAddress())); //read the value } @Override - public void write() { - ModbusAccessor.getMySelf().writeBoolean(this.getAddress(), bdp.getValue()); + public void write(DataPoint dp) { + bdp = (BooleanDataPoint) dp; //make the empty datapoint to the desired datapoint, which is to be written on the address + value = bdp.getValue(); //store the value of the datapoint + ModbusAccessor.getMySelf().writeBoolean(this.getAddress(),bdp.getValue()); //write the desired value on the modbus address } } diff --git a/src/main/java/ch/hevs/isi/field/FieldConnector.java b/src/main/java/ch/hevs/isi/field/FieldConnector.java index 49f17b5..5b5b9c1 100644 --- a/src/main/java/ch/hevs/isi/field/FieldConnector.java +++ b/src/main/java/ch/hevs/isi/field/FieldConnector.java @@ -2,6 +2,7 @@ package ch.hevs.isi.field; import ch.hevs.isi.core.DataPoint; import ch.hevs.isi.core.DataPointListener; +import ch.hevs.isi.core.FloatDataPoint; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -11,9 +12,13 @@ import java.util.Timer; public class FieldConnector implements DataPointListener { private static FieldConnector mySelf = null; + private FieldConnector(){ + initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv"); + // Subscribe to the update of DataPoints + DataPointListener.subscribeUpdate(this); } @@ -44,19 +49,20 @@ public class FieldConnector implements DataPointListener { String[] splitLine = line.split(";"); // split line between ";" String label = splitLine[0]; // first split is the label of the register - boolean isOutput = splitLine[3].equals("N"); // third split declares if it is an output + boolean isOutput = splitLine[3].equals("Y"); // third split declares if it is an output int address = new Integer((splitLine[4])); // fourth split is the address of the register - float range = new Float(splitLine[5]); // if it is a floatDatapoint, the fifth split is the range of the data - float offset = new Float(splitLine[6]); // if it is a floatDatapoint, the sixth split is the offset of the data + int range = new Integer(splitLine[5]); // if it is a floatDatapoint, the fifth split is the range of the data + int offset = new Integer(splitLine[6]); // if it is a floatDatapoint, the sixth split is the offset of the data - /* - // create a float or a boolean register + + // create a float or a boolean register and put it in the map of registers if (splitLine[1].equals("B")){ BooleanRegister b = new BooleanRegister(label, isOutput, address); + b.updateMapOfRegisters(label, address); //save the register in map, the key is the label of the datapoint } else if(splitLine[1].equals("F")){ FloatRegister f = new FloatRegister(label, isOutput, address, range, offset); + f.updateMapOfRegisters(label, address); //save the register in map, the key is the label of the datapoint } - */ } } catch(FileNotFoundException e){ @@ -77,9 +83,9 @@ public class FieldConnector implements DataPointListener { */ public void initialize(String host, int port, String pathToFile){ - ModbusAccessor.getMySelf().connect(host,port); //connect with Modbus - createRegister(pathToFile); //read the csv file of the modbus registers - startPeriodicalPolling(); //start periodical reading of the float values + ModbusAccessor.getMySelf().connect(host,port); //connect to the modbus server + createRegister(pathToFile); //create the all needed modbus registers and save them in a map + startPeriodicalPolling(); //start periodical reading of the values } private void pushToField(String label, String value){ @@ -87,9 +93,20 @@ public class FieldConnector implements DataPointListener { } @Override public void onNewValue(DataPoint dp) { - ModbusRegister mR = ModbusRegister.getRegisterFromDatapoint(dp); - mR.write(); - pushToField(dp.getLabel(),dp.toString()); + ModbusRegister mR = ModbusRegister.getRegisterFromDatapoint(dp); //search the corresponding register to the datapoint + if(dp.isOutput()){ //write only on the datapoints, which are outputs + if(dp.getLabel().equals("REMOTE_SOLAR_SW") //write only boolean outputs + ||dp.getLabel().equals("REMOTE_WIND_SW") + ||dp.getLabel().equals("SOLAR_CONNECT_ST") + ||dp.getLabel().equals("WIND_CONNECT_ST")){ + BooleanRegister br = (BooleanRegister) ModbusRegister.getRegisterFromDatapoint(dp); //create a booleanregister, because they are only boolean datapoints + br.write(dp); //write with the correct dp value + }else{ //write only float outputs + FloatRegister fr = (FloatRegister) ModbusRegister.getRegisterFromDatapoint(dp); //create a floatregister, because they are only float datapoints + fr.write(dp); //write with the correct dp value + } + pushToField(dp.getLabel(),dp.toString()); + } } /** @@ -97,9 +114,9 @@ public class FieldConnector implements DataPointListener { * in our case it is the reading of the modbus registers */ public void startPeriodicalPolling(){ - Timer pollTimer = new Timer(); - PollTask pollTask = new PollTask(); + Timer pollTimer = new Timer(); //create a new timer, + PollTask pollTask = new PollTask(); //create a new task to do every period. + pollTimer.scheduleAtFixedRate(pollTask,0,100); //do the run-function of the polltask every period - pollTimer.scheduleAtFixedRate(pollTask,0,2000); } } diff --git a/src/main/java/ch/hevs/isi/field/FloatRegister.java b/src/main/java/ch/hevs/isi/field/FloatRegister.java index 214bcf0..56f5e03 100644 --- a/src/main/java/ch/hevs/isi/field/FloatRegister.java +++ b/src/main/java/ch/hevs/isi/field/FloatRegister.java @@ -8,19 +8,40 @@ import java.util.HashMap; public class FloatRegister extends ModbusRegister{ private Float value; private FloatDataPoint fdp; - public FloatRegister(String label, boolean isOutPut, int address, float range, float offset) { - this.fdp = new FloatDataPoint(label, isOutPut); - value = fdp.getValue(); - updateMapOfRegisters(fdp,address); + private int range; + private int offset; + + /** + * public constructor of the Float Register + * + * @param label label of the datapoint + * @param isOutPut true if it is an output datapoint + * @param address modbus address of the datapoint + * @param range range of the datapoint value + * @param offset offset of the datapoint value + */ + public FloatRegister(String label, boolean isOutPut, int address, int range, int offset) { + this.fdp = new FloatDataPoint(label, isOutPut); //create an empty datapoint for the NullPointerException + updateMapOfRegisters(label,address); //add the address to the map + this.range = range; + this.offset = offset; } @Override public void read() { - fdp.setValue(ModbusAccessor.getMySelf().readFloat(this.getAddress())); + if(fdp.isOutput()){ + return; //if it is an output datapoint, it is not read + } + Float value = ModbusAccessor.getMySelf().readFloat(this.getAddress()); //read the value + value = value * range; + value = value + offset; + fdp.setValue(value); } @Override - public void write() { - ModbusAccessor.getMySelf().writeFloat(this.getAddress(), fdp.getValue()); + public void write(DataPoint dp) { + fdp = (FloatDataPoint) dp; //make the empty datapoint to the desired datapoint, which is to be written on the address + value = fdp.getValue(); //store the value of the datapoint + ModbusAccessor.getMySelf().writeFloat(this.getAddress(), fdp.getValue()); //write the desired value on the modbus address } } \ No newline at end of file diff --git a/src/main/java/ch/hevs/isi/field/ModbusRegister.java b/src/main/java/ch/hevs/isi/field/ModbusRegister.java index f963845..6c87cff 100644 --- a/src/main/java/ch/hevs/isi/field/ModbusRegister.java +++ b/src/main/java/ch/hevs/isi/field/ModbusRegister.java @@ -7,7 +7,6 @@ import java.util.HashMap; public abstract class ModbusRegister { private int address; - /** * get the address of the modbus register * @return address of the modbus register @@ -15,29 +14,35 @@ public abstract class ModbusRegister { public int getAddress() { return address; } - private final static HashMap mapOfRegisters = new HashMap<>(); + private final static HashMap mapOfRegisters = new HashMap<>(); /** * get the modbus register from the desired datapoint * @param dp the desired datapoint - * @return modbus register + * @return modbus adress of the datapoint */ public static ModbusRegister getRegisterFromDatapoint(DataPoint dp){ - return mapOfRegisters.get(dp); + return mapOfRegisters.get(dp.getLabel()); //search the modbus address of the datapoint-label } - public void updateMapOfRegisters(DataPoint dp, int address){ + + /** + * add an register to the map of the modbus addresses + * @param label label of the datapoint + * @param address modbus address of the datapoint + */ + public void updateMapOfRegisters(String label, int address){ this.address = address; - mapOfRegisters.put(dp,this); + mapOfRegisters.put(label,this); //add an address to the map with the corresponding datapoint-label } /** * read periodically each modbus register */ public static void poll(){ - for (ModbusRegister mr : mapOfRegisters.values()){ - mr.read(); //read all values (registers) of the map + for (ModbusRegister mr : mapOfRegisters.values()){ //read through all the values (modbus addresses) of the map + mr.read(); //read each datapoint, which address is stored in the map } } public abstract void read(); //abstract prototype of the method read - public abstract void write(); //abstract prototype of the method read + public abstract void write(DataPoint dp); //abstract prototype of the method read } diff --git a/src/main/java/ch/hevs/isi/field/PollTask.java b/src/main/java/ch/hevs/isi/field/PollTask.java index a01ccc2..8fe9204 100644 --- a/src/main/java/ch/hevs/isi/field/PollTask.java +++ b/src/main/java/ch/hevs/isi/field/PollTask.java @@ -1,5 +1,7 @@ package ch.hevs.isi.field; +import ch.hevs.isi.core.DataPoint; + import java.util.TimerTask; public class PollTask extends TimerTask { diff --git a/src/main/resources/ModbusMap.csv b/src/main/resources/ModbusMap.csv new file mode 100644 index 0000000..0e6984d --- /dev/null +++ b/src/main/resources/ModbusMap.csv @@ -0,0 +1,27 @@ +Label;Type [FLOAT|Boolean];Input;Output;Address;Range;Offset +GRID_U_FLOAT;F;Y;N;89;1000;0 +BATT_P_FLOAT;F;Y;N;57;6000;-3000 +BATT_CHRG_FLOAT;F;Y;N;49;1;0 +SOLAR_P_FLOAT;F;Y;N;61;1500;0 +WIND_P_FLOAT;F;Y;N;53;1000;0 +COAL_P_FLOAT;F;Y;N;81;600;0 +COAL_AMOUNT;F;Y;N;65;1;0 +HOME_P_FLOAT;F;Y;N;101;1000;0 +PUBLIC_P_FLOAT;F;Y;N;97;500;0 +FACTORY_P_FLOAT;F;Y;N;105;2000;0 +BUNKER_P_FLOAT;F;Y;N;93;500;0 +WIND_FLOAT;F;Y;N;301;1;0 +WEATHER_FLOAT;F;Y;N;305;1;0 +WEATHER_FORECAST_FLOAT;F;Y;N;309;1;0 +WEATHER_COUNTDOWN_FLOAT;F;Y;N;313;600;0 +CLOCK_FLOAT;F;Y;N;317;1;0 +REMOTE_COAL_SP;F;Y;Y;209;1;0 +REMOTE_FACTORY_SP;F;Y;Y;205;1;0 +REMOTE_SOLAR_SW;B;Y;Y;401;1;0 +REMOTE_WIND_SW;B;Y;Y;405;1;0 +FACTORY_ENERGY;F;Y;N;341;3600000;0 +SCORE;F;Y;N;345;3600000;0 +COAL_ST;F;Y;N;601;1;0 +FACTORY_ST;F;Y;N;605;1;0 +SOLAR_CONNECT_ST;B;Y;N;609;1;0 +WIND_CONNECT_ST;B;Y;N;613;1;0 diff --git a/src/test/java/Database.java b/src/test/java/Database.java index 3ea14f7..cae80de 100644 --- a/src/test/java/Database.java +++ b/src/test/java/Database.java @@ -8,13 +8,11 @@ import ch.hevs.isi.web.WebConnector; public class Database { public static void main(String[] args) { MinecraftController.ERASE_PREVIOUS_DATA_INB_DB = true; - FloatDataPoint clock = new FloatDataPoint("CLOAK_FLOAT", false); + FloatDataPoint clock = new FloatDataPoint("CLOCK_FLOAT", false); FloatDataPoint gridVoltage = new FloatDataPoint("GRID_U_FLOAT", true); BooleanDataPoint solarPanel = new BooleanDataPoint("REMOTE_SOLAR_SW", true); DatabaseConnector.getMySelf().initialize(null); - FieldConnector.getMySelf().initialize(null, 0); - WebConnector.getMySelf().initialize(null, 0); clock.setValue(0f); diff --git a/src/test/java/Field.java b/src/test/java/Field.java index 7cd5802..fe282c5 100644 --- a/src/test/java/Field.java +++ b/src/test/java/Field.java @@ -7,28 +7,16 @@ import ch.hevs.isi.field.FloatRegister; public class Field { public static void main(String[] args) { + //create an FieldConnector + //reads the datapoint values and displays them in the consol + FieldConnector.getMySelf().initialize("LocalHost", 1502,"src/main/resources/ModbusMap.csv"); - //FloatRegister fRI = new FloatRegister("GRID_U_FLOAT",false,89); - BooleanRegister bRI = new BooleanRegister("SOLAR_CONNECT_ST", false ,609); - FieldConnector.getMySelf().startPeriodicalPolling(); + //create two datapoint to write a new value to them + BooleanDataPoint solarPanel = new BooleanDataPoint("REMOTE_SOLAR_SW", true); + FloatDataPoint remoteFactorySp = new FloatDataPoint("REMOTE_FACTORY_SP", true); - //FloatRegister fRO = new FloatRegister("REMOTE_FACTORY_SP",true,205); - BooleanRegister bRO = new BooleanRegister("REMOTE_SOLAR_SW", true ,401); - - /* - fRO.fdp.setValue(0.8F); - bRO.bdp.setValue(true); - */ - - while(true) - { - /* - float value = fRI.dataPoint.getValue()*1000; - System.out.println(value); - */ - /* - System.out.println(bRI.bdp.getValue()); - */ - } + //write to values + remoteFactorySp.setValue(0.74f); + solarPanel.setValue(true); } } diff --git a/src/test/java/Web.java b/src/test/java/Web.java index f289052..ff0c5e6 100644 --- a/src/test/java/Web.java +++ b/src/test/java/Web.java @@ -24,16 +24,16 @@ public class Web { Thread.sleep(2000); if(WebConnector.getMySelf().wss.getConnections().size() > 0){ - FloatDataPoint rfSP = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_FACTORY_SP"); + FloatDataPoint rfSP = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_FACTORY_SP"); if(rfSP != null) new FloatDataPoint("FACTORY_ST", true).setValue(rfSP.getValue()); - FloatDataPoint cfSP = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_COAL_SP"); + FloatDataPoint cfSP = (FloatDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_COAL_SP"); if(cfSP != null) new FloatDataPoint("COAL_ST", true).setValue(cfSP.getValue()); - BooleanDataPoint solar = (BooleanDataPoint) DataPoint.getDataPointFromLabel("REMOTE_SOLAR_SW"); + BooleanDataPoint solar = (BooleanDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_SOLAR_SW"); if(solar != null) new BooleanDataPoint("SOLAR_CONNECT_ST", true).setValue(solar.getValue()); - BooleanDataPoint wind = (BooleanDataPoint) DataPoint.getDataPointFromLabel("REMOTE_WIND_SW"); + BooleanDataPoint wind = (BooleanDataPoint) DataPoint.getDataPointOnListFromLabel("REMOTE_WIND_SW"); if(wind != null) new BooleanDataPoint("WIND_CONNECT_ST", true).setValue(wind.getValue()); time += 0.1f;