BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
models/TDKLambdaPowerSupplyFactory.java
1 package kernel.models;
2 
3 import devices.PowerSupply;
6 import gnu.io.PortInUseException;
7 import gnu.io.UnsupportedCommOperationException;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import kernel.Kernel;
16 
17 import java.io.IOException;
18 
25 public class TDKLambdaPowerSupplyFactory implements kernel.controllers.TDKLambdaPowerSupplyFactory {
29  @Autowired
30  private Kernel kernel;
31 
35  private String portName;
36 
44  private static final Integer deviceAddress = 6;
45 
49  private static Logger log = LoggerFactory.getLogger(
50  "kernel.models.TDKLambdaPowerSupplyFactory");
51 
55  @Override
56  public Kernel getKernel(){
57  return kernel;
58  }
59 
63  @Override
64  public void setKernel(Kernel kernel){
65  this.kernel = kernel;
66  }
67 
71  @Override
72  public void setPortName(String portName){
73  this.portName = portName;
74  }
75 
76 
77  @Override
78  public PowerSupply getPowerSupply() throws PortInUseException,
79  IOException, UnsupportedCommOperationException,
81 
82  DeviceContainer registry = kernel.getDeviceRegistryView();
83 
84  if (!registry.hasPowerSupply()){
86  }
87  PowerSupply supply = registry.getPowerSupply();
88  writeEntryForSupply(supply);
89 
90  return supply;
91  }
92 
93  @Override
94  public void makePowerSupply() throws PortInUseException, IOException,
95  UnsupportedCommOperationException, DeviceAlreadyCreatedException {
96  assertPowerSupplyDoesNotExist();
97  writeEntryForNoPowerSupply();
98 
99  kernel.controllers.DeviceRegistry registry = kernel
100  .getDeviceRegistryController();
101 
102  PowerSupply supply = createPowerSupplyInstance();
103 
104  registry.setPowerSupply(supply);
105  }
106 
107  private PowerSupply createPowerSupplyInstance() throws PortInUseException,
108  IOException, UnsupportedCommOperationException
109  {
110  SerialPort port = kernel.getPortDriver().getPortByName(this.portName);
111 
112  configurePort(port);
113 
114  port.open();
115 
117  deviceAddress);
118 
119  kernel.getVariableProvidersController().setVoltageProvider(
120  new VoltageProvider(supply, kernel)
121  );
122 
123  return supply;
124  }
125 
126  private void configurePort(SerialPort port){
127  port.setConfig(new PortConfig());
128  }
129 
130  private void assertPowerSupplyDoesNotExist() throws
132  DeviceContainer registry = kernel.getDeviceRegistryView();
133  if (registry.hasPowerSupply()){
135  "A power supply has already been made"
136  );
137  }
138  }
139 
140  private static void writeEntryForNoPowerSupply(){
141  log.debug("No Power Supply. Creating a new one");
142  }
143 
144  private static void writeEntryForSupply(PowerSupply supply){
145  log.debug(
146  String.format("Found Power supply %s", supply.toString())
147  );
148  }
149 
150  private class PortConfig implements PortConfiguration {
151  @Override
152  public int getStopBits(){
153  return STOPBITS_1;
154  }
155 
156  @Override
157  public int getBaudRate(){
158  return BAUD_RATE_9600;
159  }
160 
161  @Override
162  public int getParityBits(){
163  return PARITY_NONE;
164  }
165 
166  @Override
167  public int getDataBits(){
168  return DATABITS_8;
169  }
170  }
171 }
PortCommunicator getCommunicator()
void setConfig(PortConfiguration newConfig)
Git Repo