use of de.avanux.smartapplianceenabler.modbus.ModbusTcp in project SmartApplianceEnabler by camueller.
the class SaeController method setSettings.
@RequestMapping(value = SETTINGS_URL, method = RequestMethod.PUT, consumes = "application/json")
@CrossOrigin(origins = CROSS_ORIGIN_URL)
public void setSettings(@RequestBody Settings settings) {
logger.debug("Received request to set " + settings);
List<PulseReceiver> pulseReceivers = null;
if (settings.isPulseReceiverEnabled()) {
PulseReceiver pulseReceiver = new PulseReceiver();
pulseReceiver.setId(PulseReceiver.DEFAULT_ID);
pulseReceiver.setPort(settings.getPulseReceiverPort());
pulseReceivers = Collections.singletonList(pulseReceiver);
}
List<ModbusTcp> modbusTCPs = null;
if (settings.isModbusEnabled()) {
ModbusTcp modbusTcp = new ModbusTcp();
modbusTcp.setId(ModbusTcp.DEFAULT_ID);
modbusTcp.setHost(settings.getModbusTcpHost());
modbusTcp.setPort(settings.getModbusTcpPort());
modbusTCPs = Collections.singletonList(modbusTcp);
}
Connectivity connectivity = null;
if (pulseReceivers != null || modbusTCPs != null) {
connectivity = new Connectivity();
connectivity.setPulseReceivers(pulseReceivers);
connectivity.setModbusTCPs(modbusTCPs);
}
ApplianceManager.getInstance().setConnectivity(connectivity);
List<Configuration> configurations = null;
if (settings.isHolidaysEnabled()) {
Configuration configuration = new Configuration();
configuration.setParam(HolidaysDownloader.urlConfigurationParamName);
configuration.setValue(settings.getHolidaysUrl());
configurations = Collections.singletonList(configuration);
}
ApplianceManager.getInstance().setConfiguration(configurations);
}
use of de.avanux.smartapplianceenabler.modbus.ModbusTcp in project SmartApplianceEnabler by camueller.
the class Appliance method start.
public void start(Timer timer, GpioController gpioController, Map<String, PulseReceiver> pulseReceiverIdWithPulseReceiver, Map<String, ModbusTcp> modbusIdWithModbusTcp) {
if (runningTimeMonitor != null) {
runningTimeMonitor.setTimer(timer);
}
for (GpioControllable gpioControllable : getGpioControllables()) {
logger.info("{}: Starting {}", id, gpioControllable.getClass().getSimpleName());
gpioControllable.setGpioController(gpioController);
gpioControllable.start();
}
if (meter != null && meter instanceof S0ElectricityMeterNetworked) {
S0ElectricityMeterNetworked s0ElectricityMeterNetworked = (S0ElectricityMeterNetworked) meter;
logger.info("{}: Starting {}", id, S0ElectricityMeterNetworked.class.getSimpleName());
String pulseReceiverId = s0ElectricityMeterNetworked.getIdref();
PulseReceiver pulseReceiver = pulseReceiverIdWithPulseReceiver.get(pulseReceiverId);
s0ElectricityMeterNetworked.setPulseReceiver(pulseReceiver);
s0ElectricityMeterNetworked.start();
}
if (meter != null && meter instanceof HttpElectricityMeter) {
((HttpElectricityMeter) meter).start(timer);
}
for (ModbusSlave modbusSlave : getModbusSlaves()) {
logger.info("{}: Starting {}", id, modbusSlave.getClass().getSimpleName());
modbusSlave.setApplianceId(id);
String modbusId = modbusSlave.getIdref();
ModbusTcp modbusTcp = modbusIdWithModbusTcp.get(modbusId);
modbusSlave.setModbusTcp(modbusTcp);
}
if (meter != null && meter instanceof ModbusElectricityMeter) {
((ModbusElectricityMeter) meter).start(timer);
}
if (control != null && control instanceof StartingCurrentSwitch) {
logger.info("{}: Starting {}", id, StartingCurrentSwitch.class.getSimpleName());
((StartingCurrentSwitch) control).start(new LocalDateTime(), getMeter(), timer);
}
}
use of de.avanux.smartapplianceenabler.modbus.ModbusTcp in project SmartApplianceEnabler by camueller.
the class ApplianceManager method init.
public void init() {
Map<String, PulseReceiver> pulseReceiverIdWithPulseReceiver = new HashMap<String, PulseReceiver>();
Map<String, ModbusTcp> modbusIdWithModbusTcp = new HashMap<String, ModbusTcp>();
Connectivity connectivity = appliances.getConnectivity();
if (connectivity != null) {
// make PulseReceiver accessible by id
if (connectivity.getPulseReceivers() != null) {
for (PulseReceiver pulseReceiver : connectivity.getPulseReceivers()) {
logger.info("PulseReceiver (" + pulseReceiver.getId() + ") configured for port " + pulseReceiver.getPort());
pulseReceiverIdWithPulseReceiver.put(pulseReceiver.getId(), pulseReceiver);
pulseReceiver.start();
}
}
// make ModbusTcp accessible by id
if (connectivity.getModbusTCPs() != null) {
for (ModbusTcp modbusTCP : connectivity.getModbusTCPs()) {
logger.info("ModBus (" + modbusTCP.getId() + ") configured for " + modbusTCP.toString());
modbusIdWithModbusTcp.put(modbusTCP.getId(), modbusTCP);
}
}
}
Integer additionRunningTime = null;
String additionRunningTimeString = appliances.getConfigurationValue("TimeframeIntervalAdditionalRunningTime");
if (additionRunningTimeString != null) {
additionRunningTime = Integer.valueOf(additionRunningTimeString);
}
boolean holidaysUsed = false;
for (Appliance appliance : getAppliances()) {
if (appliance.hasTimeframeForHolidays()) {
holidaysUsed = true;
}
appliance.init(additionRunningTime);
appliance.start(timer, gpioController, pulseReceiverIdWithPulseReceiver, modbusIdWithModbusTcp);
}
if (holidaysUsed) {
logger.debug("Holidays are used.");
/**
* Once a day check availability of holidays file - the year might have changed!
* Download it if it is not available. If it is available (either downloaded or just placed there)
* load holidays from the file pass them on to all appliances.
*/
timer.schedule(new TimerTask() {
@Override
public void run() {
FileHandler fileHandler = new FileHandler();
if (!fileHandler.isHolidayFileAvailable()) {
HolidaysDownloader downloader = new HolidaysDownloader();
String downloadUrl = appliances.getConfigurationValue(HolidaysDownloader.urlConfigurationParamName);
if (downloadUrl != null) {
downloader.setUrl(downloadUrl);
}
Map<LocalDate, String> holidayWithName = downloader.downloadHolidays();
fileHandler.saveHolidays(holidayWithName);
}
List<LocalDate> holidays = fileHandler.loadHolidays();
if (holidays != null) {
for (Appliance appliance : getAppliances()) {
appliance.setHolidays(holidays);
}
}
}
}, 0, 24 * 60 * 60 * 1000);
} else {
logger.debug("Holidays are NOT used.");
}
}
use of de.avanux.smartapplianceenabler.modbus.ModbusTcp in project SmartApplianceEnabler by camueller.
the class SaeController method getSettings.
@RequestMapping(value = SETTINGS_URL, method = RequestMethod.GET, produces = "application/json")
@CrossOrigin(origins = CROSS_ORIGIN_URL)
public Settings getSettings() {
logger.debug("Received request for Settings");
Settings settings = new Settings();
Appliances appliances = ApplianceManager.getInstance().getAppliancesRoot();
Connectivity connectivity = appliances.getConnectivity();
if (connectivity != null) {
List<PulseReceiver> pulseReceivers = connectivity.getPulseReceivers();
if (pulseReceivers != null && pulseReceivers.size() > 0) {
settings.setPulseReceiverEnabled(true);
PulseReceiver pulseReceiver = pulseReceivers.get(0);
settings.setPulseReceiverPort(pulseReceiver.getPort());
}
List<ModbusTcp> modbusTCPs = connectivity.getModbusTCPs();
if (modbusTCPs != null && modbusTCPs.size() > 0) {
settings.setModbusEnabled(true);
ModbusTcp modbusTcp = modbusTCPs.get(0);
settings.setModbusTcpHost(modbusTcp.getHost());
settings.setModbusTcpPort(modbusTcp.getPort());
}
}
String holidaysUrl = appliances.getConfigurationValue(HolidaysDownloader.urlConfigurationParamName);
settings.setHolidaysEnabled(holidaysUrl != null);
settings.setHolidaysUrl(holidaysUrl);
logger.debug("Returning Settings " + settings);
return settings;
}
Aggregations