Merge branch 'main' into improvement
This commit is contained in:
commit
de288176d3
@ -15,6 +15,10 @@ public class FieldConnector implements DataPointListener {
|
|||||||
|
|
||||||
private FieldConnector(){
|
private FieldConnector(){
|
||||||
initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv");
|
initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv");
|
||||||
|
|
||||||
|
|
||||||
|
// Subscribe to the update of DataPoints
|
||||||
|
|
||||||
DataPointListener.subscribeUpdate(this);
|
DataPointListener.subscribeUpdate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +82,11 @@ public class FieldConnector implements DataPointListener {
|
|||||||
* @param pathToFile path to the file of all modbus registers (C:/.../ModbusMap.csv)
|
* @param pathToFile path to the file of all modbus registers (C:/.../ModbusMap.csv)
|
||||||
*/
|
*/
|
||||||
public void initialize(String host, int port, String pathToFile){
|
public void initialize(String host, int port, String pathToFile){
|
||||||
|
|
||||||
ModbusAccessor.getMySelf().connect(host,port); //connect to the modbus server
|
ModbusAccessor.getMySelf().connect(host,port); //connect to the modbus server
|
||||||
createRegister(pathToFile); //create the all needed modbus registers and save them in a map
|
createRegister(pathToFile); //create the all needed modbus registers and save them in a map
|
||||||
startPeriodicalPolling(); //start periodical reading of the values
|
startPeriodicalPolling(); //start periodical reading of the values
|
||||||
|
|
||||||
}
|
}
|
||||||
private void pushToField(String label, String value){
|
private void pushToField(String label, String value){
|
||||||
System.out.println("Field: " + label + " " + value);
|
System.out.println("Field: " + label + " " + value);
|
||||||
@ -111,5 +117,6 @@ public class FieldConnector implements DataPointListener {
|
|||||||
Timer pollTimer = new Timer(); //create a new timer,
|
Timer pollTimer = new Timer(); //create a new timer,
|
||||||
PollTask pollTask = new PollTask(); //create a new task to do every period.
|
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,100); //do the run-function of the polltask every period
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
src/main/java/ch/hevs/isi/field/SmartControl.java
Normal file
64
src/main/java/ch/hevs/isi/field/SmartControl.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package ch.hevs.isi.field;
|
||||||
|
|
||||||
|
import ch.hevs.isi.core.DataPoint;
|
||||||
|
import ch.hevs.isi.core.FloatDataPoint;
|
||||||
|
|
||||||
|
public class SmartControl {
|
||||||
|
|
||||||
|
public SmartControl(){
|
||||||
|
|
||||||
|
//time
|
||||||
|
FloatDataPoint clockFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("CLOCK_FLOAT");
|
||||||
|
int timeOfTheDay = 0; //0=default 1=beginning 2=day 3=end 4=night
|
||||||
|
if (clockFloat.getValue() > 0.2f && clockFloat.getValue() <= 0.3f) { //beginning of the day
|
||||||
|
timeOfTheDay =1;
|
||||||
|
}
|
||||||
|
if (clockFloat.getValue() > 0.3f && clockFloat.getValue() <= 0.7f){ //day
|
||||||
|
timeOfTheDay = 2;
|
||||||
|
}
|
||||||
|
if (clockFloat.getValue() > 0.7f && clockFloat.getValue() <= 0.8f){ //end of the day
|
||||||
|
timeOfTheDay = 3;
|
||||||
|
}
|
||||||
|
if (clockFloat.getValue() <= 0.2f && clockFloat.getValue() > 0.8f){ //night
|
||||||
|
timeOfTheDay = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Factory and coal
|
||||||
|
FloatDataPoint battChrgFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("BATT_CHRG_FLOAT");
|
||||||
|
FloatDataPoint remoteCoalSp = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_COAL_SP");
|
||||||
|
FloatDataPoint remoteFactorySp = (FloatDataPoint) DataPoint.getDataPointFromLabel("REMOTE_FACTORY_SP");
|
||||||
|
FloatDataPoint coalAmount = (FloatDataPoint) DataPoint.getDataPointFromLabel("COAL_AMOUNT");
|
||||||
|
|
||||||
|
if (battChrgFloat.getValue() <= 0.4f){ //if battery level is under 40 %
|
||||||
|
if(coalAmount.getValue() <= 0.5f){
|
||||||
|
remoteCoalSp.setValue(0.5f); //start the coal power plant with 50%
|
||||||
|
}else{
|
||||||
|
remoteCoalSp.setValue(1f); //start the coal power plant with 100%
|
||||||
|
}
|
||||||
|
remoteFactorySp.setValue(0f); //stop the consumption of the factory
|
||||||
|
}
|
||||||
|
if (battChrgFloat.getValue() > 0.4f && battChrgFloat.getValue() < 0.6f){ //if battery lever is between 40% and 60%
|
||||||
|
remoteCoalSp.setValue(0f); //stop the coal power plant
|
||||||
|
remoteFactorySp.setValue(0f); //stop the consumption of the factory
|
||||||
|
}
|
||||||
|
if(battChrgFloat.getValue() >= 0.6f){ //if battery level is over 60 %
|
||||||
|
remoteCoalSp.setValue(0f); //stop the coal power plant
|
||||||
|
remoteFactorySp.setValue(1f); //start the consumption of the factory
|
||||||
|
}
|
||||||
|
|
||||||
|
//Solar
|
||||||
|
FloatDataPoint weatherFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("WEATHER_FLOAT");
|
||||||
|
FloatDataPoint weatherCountdownFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("WEATHER_COUNTDOWN_FLOAT");
|
||||||
|
FloatDataPoint weatherForecastFloat = (FloatDataPoint) DataPoint.getDataPointFromLabel("WEATHER_FORECAST_FLOAT");
|
||||||
|
|
||||||
|
/** TODO Solar Smartcontrol
|
||||||
|
* check the value of weatherForecastFloat and weatherFloat
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Wind
|
||||||
|
/** TODO Wind Smartcontrol
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user