fix everything for merge Field
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| package ch.hevs.isi; | ||||
|  | ||||
| import ch.hevs.isi.db.DatabaseConnector; | ||||
| import ch.hevs.isi.field.FieldConnector; | ||||
| import ch.hevs.isi.utils.Utility; | ||||
| import ch.hevs.isi.web.WebConnector; | ||||
|  | ||||
| @@ -87,18 +88,22 @@ public class MinecraftController { | ||||
|         } | ||||
|  | ||||
|         // 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 | ||||
|   | ||||
| @@ -178,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(); | ||||
|   | ||||
| @@ -20,6 +20,9 @@ public class BooleanRegister extends ModbusRegister{ | ||||
|     } | ||||
|     @Override | ||||
|     public void read() { | ||||
|         if(bdp.isOutput()){ | ||||
|             return;      //if it is an output datapoint, it is not read | ||||
|         } | ||||
|         bdp.setValue(ModbusAccessor.getMySelf().readBoolean(this.getAddress()));    //read the value | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -15,6 +15,7 @@ public class FieldConnector implements DataPointListener { | ||||
|  | ||||
|     private FieldConnector(){ | ||||
|         initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv"); | ||||
|         DataPointListener.subscribeUpdate(this); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -44,10 +45,10 @@ 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 and put it in the map of registers | ||||
|   | ||||
| @@ -8,6 +8,8 @@ import java.util.HashMap; | ||||
| public class FloatRegister extends ModbusRegister{ | ||||
|     private Float value; | ||||
|     private FloatDataPoint fdp; | ||||
|     private int range; | ||||
|     private int offset; | ||||
|  | ||||
|     /** | ||||
|      * public constructor of the Float Register | ||||
| @@ -18,14 +20,22 @@ public class FloatRegister extends ModbusRegister{ | ||||
|      * @param range range of the datapoint value | ||||
|      * @param offset offset of the datapoint value | ||||
|      */ | ||||
|     public FloatRegister(String label, boolean isOutPut, int address, float range, float offset) { | ||||
|     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()));  //read the value | ||||
|         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 | ||||
|   | ||||
| @@ -13,7 +13,7 @@ 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;;313;600;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 | ||||
|   | ||||
| 
 | 
| @@ -8,12 +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); | ||||
|         WebConnector.getMySelf().initialize(null, 0); | ||||
|  | ||||
|         clock.setValue(0f); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user