|
@ -1,8 +1,19 @@ |
|
|
package com.my.graphiteDigesterBg.diframe; |
|
|
package com.my.graphiteDigesterBg.diframe; |
|
|
|
|
|
import com.my.graphiteDigesterBg.diframe.connection.DiConSerialPort; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Constructor; |
|
|
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
|
|
|
|
@Component |
|
|
@Component |
|
|
public class DiDevice { |
|
|
public class DiDevice { |
|
|
|
|
|
@Resource |
|
|
|
|
|
private Environment env; |
|
|
|
|
|
// connection |
|
|
|
|
|
private DiDeviceConnection connection; |
|
|
// io manager |
|
|
// io manager |
|
|
private DiDeviceIOManager io; |
|
|
private DiDeviceIOManager io; |
|
|
// actuator manager |
|
|
// actuator manager |
|
@ -12,11 +23,38 @@ public class DiDevice { |
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
@PostConstruct |
|
|
public void init() { |
|
|
public void init() { |
|
|
|
|
|
this.setupConnection(); |
|
|
this.io = new DiDeviceIOManager(this); |
|
|
this.io = new DiDeviceIOManager(this); |
|
|
this.actuators = new DiDeviceActuatorManager(this); |
|
|
this.actuators = new DiDeviceActuatorManager(this); |
|
|
this.taskManager = new DiTaskManager(this); |
|
|
this.taskManager = new DiTaskManager(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// setup connection |
|
|
|
|
|
private void setupConnection() { |
|
|
|
|
|
String connectionClassName = this.env.getProperty("device.connection.class"); |
|
|
|
|
|
Class<?> connectionClass = null; |
|
|
|
|
|
try { |
|
|
|
|
|
connectionClass = Class.forName(connectionClassName); |
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Constructor<?> connectionConstructor = null; |
|
|
|
|
|
try { |
|
|
|
|
|
connectionConstructor = connectionClass.getDeclaredConstructor(); |
|
|
|
|
|
} catch (NoSuchMethodException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
this.connection = (DiDeviceConnection) connectionConstructor.newInstance(); |
|
|
|
|
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
this.connection.setDevice(this); |
|
|
|
|
|
this.connection.connect(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// get io manager |
|
|
// get io manager |
|
|
public DiDeviceIOManager getIO() { |
|
|
public DiDeviceIOManager getIO() { |
|
|
return this.io; |
|
|
return this.io; |
|
@ -31,4 +69,14 @@ public class DiDevice { |
|
|
public DiTaskManager getTaskManager() { |
|
|
public DiTaskManager getTaskManager() { |
|
|
return this.taskManager; |
|
|
return this.taskManager; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get connection |
|
|
|
|
|
public DiDeviceConnection getConnection() { |
|
|
|
|
|
return this.connection; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get env |
|
|
|
|
|
public Environment getEnv() { |
|
|
|
|
|
return this.env; |
|
|
|
|
|
} |
|
|
} |
|
|
} |