158 lines
4.8 KiB
Java
158 lines
4.8 KiB
Java
package com.henrypump.poc;
|
|
|
|
/**
|
|
* Created by patrickjmcd on 2/1/17.
|
|
* POC Class
|
|
*
|
|
*/
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
|
|
public class POC implements Runnable{
|
|
protected Well thisWell;
|
|
private int simLoops;
|
|
private Thread t;
|
|
private DigitalIn startBtn, stopBtn;
|
|
private DigitalOut led2, led3, led4, led5;
|
|
private DigitalOut runIndicator;
|
|
|
|
private boolean ioEnabled;
|
|
private boolean guiEnabled;
|
|
|
|
|
|
|
|
POC(String wellName, String wellSetupJsonFile, int simLoops){
|
|
ioEnabled = true;
|
|
guiEnabled = false;
|
|
thisWell = new Well(wellName, 99, 99, 7);
|
|
thisWell.parseJSONFile(wellSetupJsonFile);
|
|
thisWell.printTapers();
|
|
this.simLoops = simLoops;
|
|
|
|
// IO
|
|
startBtn = new DigitalIn(8);
|
|
stopBtn = new DigitalIn(9);
|
|
led2 = new DigitalOut(2, 0);
|
|
led3 = new DigitalOut(3, 0);
|
|
led4 = new DigitalOut(4, 0);
|
|
led5 = new DigitalOut(5, 0);
|
|
runIndicator = new DigitalOut(6,0);
|
|
|
|
|
|
String headlessProp = !guiEnabled ? "true" : "false";
|
|
System.setProperty("java.awt.headless", headlessProp);
|
|
System.out.println(java.awt.GraphicsEnvironment.isHeadless());
|
|
}
|
|
|
|
POC(String wellName, String wellSetupJsonFile, String simFileName, boolean ioEnabled, int simLoops){
|
|
this.ioEnabled = ioEnabled;
|
|
if (this.ioEnabled) {
|
|
guiEnabled = false;
|
|
thisWell = new Well(wellName, simFileName,99, 99, 7);
|
|
|
|
// IO
|
|
startBtn = new DigitalIn(8);
|
|
stopBtn = new DigitalIn(9);
|
|
led2 = new DigitalOut(2, 0);
|
|
led3 = new DigitalOut(3, 0);
|
|
led4 = new DigitalOut(4, 0);
|
|
led5 = new DigitalOut(5, 0);
|
|
runIndicator = new DigitalOut(6,0);
|
|
|
|
} else {
|
|
thisWell = new Well(wellName, simFileName,99, 99, 99);
|
|
guiEnabled = true;
|
|
// IO
|
|
startBtn = new DigitalIn(99);
|
|
stopBtn = new DigitalIn(99);
|
|
led2 = new DigitalOut(99, 0);
|
|
led3 = new DigitalOut(99, 0);
|
|
led4 = new DigitalOut(99, 0);
|
|
led5 = new DigitalOut(99, 0);
|
|
runIndicator = new DigitalOut(99,0);
|
|
}
|
|
|
|
String headlessProp = !guiEnabled ? "true" : "false";
|
|
System.setProperty("java.awt.headless", headlessProp);
|
|
System.out.println(java.awt.GraphicsEnvironment.isHeadless());
|
|
|
|
thisWell.parseJSONFile(wellSetupJsonFile);
|
|
thisWell.printTapers();
|
|
this.simLoops = simLoops;
|
|
}
|
|
|
|
public void allOutputsOff(){
|
|
led2.write(0,true);
|
|
led3.write(0,true);
|
|
led4.write(0,true);
|
|
led5.write(0,true);
|
|
}
|
|
|
|
public void run(){
|
|
int loopCounter = 0, loopLimit = simLoops, led2out, led3out, led4out,led5out;
|
|
double pos;
|
|
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
|
thisWell.setupFluidRatio(0.25, 0.75, 1.12);
|
|
thisWell.checkSafeties();
|
|
while (true) {
|
|
while (loopCounter < loopLimit && (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING)) {
|
|
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
|
if (startBtn.read() == 1) thisWell.start("startbutton");
|
|
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
|
|
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
|
System.exit(0);
|
|
}
|
|
|
|
|
|
thisWell.eval(i);
|
|
|
|
pos = thisWell.getCurrentSurfacePosition();
|
|
led2.write(pos > 20.0 ? 1 : 0);
|
|
led3.write(pos > 40.0 ? 1 : 0);
|
|
led4.write(pos > 60.0 ? 1 : 0);
|
|
led5.write(pos > 80.0 ? 1 : 0);
|
|
|
|
runIndicator.write(thisWell.getRunStatus()==Well.RUNSTATUS_RUNNING ? 1 : 0);
|
|
|
|
try {
|
|
Thread.sleep(sleepMilliseconds);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
loopCounter++;
|
|
}
|
|
|
|
|
|
if (startBtn.read() == 1) thisWell.start("startbutton");
|
|
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
|
|
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
|
System.exit(0);
|
|
}
|
|
led2.write(0);
|
|
led3.write(0);
|
|
led4.write(0);
|
|
led5.write(0);
|
|
}
|
|
|
|
}
|
|
|
|
public void start () {
|
|
System.out.println("Starting POC Thread");
|
|
if (t == null) {
|
|
t = new Thread (this, "POC-Thread");
|
|
t.start ();
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
final POC thisPOC = new POC("Barney", args[0], args[1], true, 100);
|
|
thisPOC.start();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|