Start, stop, and update config from main webserver

This commit is contained in:
Patrick McDonagh
2017-03-01 17:20:36 -06:00
parent 5ae934ce86
commit a90e776cdb
10 changed files with 263 additions and 507 deletions

View File

@@ -80,8 +80,8 @@ public class POC implements Runnable{
String dbHostname = "localhost";
if (args.length > 3){
dbHostname = args[3];
if (args.length > 2){
dbHostname = args[2];
}
if (args.length == 1){

View File

@@ -26,6 +26,7 @@ public class WebServer{
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext("/command", new CommandHandler());
server.createContext("/config", new ConfigHandler());
server.createContext("/shake", new HandshakeHandler());
server.setExecutor(null); // creates a default executor
server.start();
}
@@ -182,6 +183,19 @@ public class WebServer{
os.close();
}
}
class HandshakeHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
JSONObject respJSON = new JSONObject();
respJSON.put("shake", "shook");
String response = respJSON.toJSONString();
t.sendResponseHeaders(200, response.getBytes().length);
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
}

View File

@@ -27,13 +27,13 @@ import java.util.ArrayList;
*/
public class Well {
private String wellName;
protected Simulation sim;
protected Database db;
protected WellTest wellTest;
Simulation sim;
Database db;
WellTest wellTest;
/* IO */
AnalogIn inclinometer;
AnalogIn loadCell;
private AnalogIn inclinometer;
private AnalogIn loadCell;
private double currentSurfacePosition;
private double currentSurfaceLoad;
private double currentDownholePosition;
@@ -41,7 +41,7 @@ public class Well {
/* CARDS */
private Card currentCard;
public Card[] cardStorage = new Card[100];
Card[] cardStorage = new Card[100];
// CONSTANTS
private static double YM_STEEL = 30.5;
@@ -67,7 +67,6 @@ public class Well {
// CALCULATED TAPER PARAMETERS
private int nT1; // should always be equal to number of tapers + 1
private double frictionEstimate;
private double theoreticalMaxFluidLoad;
private double[] a = new double[11];
@@ -98,12 +97,12 @@ public class Well {
// Statuses
private volatile int runStatus;
public static final int RUNSTATUS_STOPPED = 0;
public static final int RUNSTATUS_STARTING = 1;
public static final int RUNSTATUS_RUNNING = 2;
public static final int RUNSTATUS_PUMPEDOFF = 3;
public static final int RUNSTATUS_FAULTED = 4;
public static final int RUNSTATUS_LOCKEDOUT = 5;
static final int RUNSTATUS_STOPPED = 0;
static final int RUNSTATUS_STARTING = 1;
static final int RUNSTATUS_RUNNING = 2;
static final int RUNSTATUS_PUMPEDOFF = 3;
static final int RUNSTATUS_FAULTED = 4;
static final int RUNSTATUS_LOCKEDOUT = 5;
private boolean permissiveOK;
private long strokesSinceStart = 0;
@@ -120,7 +119,7 @@ public class Well {
private int lastDirection = DIRECTION_UNKNOWN;
// MODES
private volatile int runMode;
private volatile int runMode = 0;
public static final int RUNMODE_POC = 0;
public static final int RUNMODE_MANUAL = 1;
public static final int RUNMODE_TIMER = 2;
@@ -410,6 +409,19 @@ public class Well {
return runMode;
}
public String getRunModeString(){
switch (runMode){
case RUNMODE_POC:
return "POC";
case RUNMODE_MANUAL:
return "MANUAL";
case RUNMODE_TIMER:
return "TIMER";
default:
return "UNKNOWN";
}
}
public double getCurrentSurfacePosition() {
return currentSurfacePosition;
}
@@ -681,6 +693,7 @@ public class Well {
Files.delete(toFile);
Files.move(fromFile, toFile);
}
updateTapers(true);
} catch (FileNotFoundException e) {
System.out.println("No configuration file found. Pulling latest value from database.");
@@ -734,11 +747,12 @@ public class Well {
Object newDampingFactor = taperObj.get("dampingFactor");
if (newDampingFactor != null) setDampingFactor(currentTaperNum, (Double) newDampingFactor);
}
updateTapers(false);
} catch (IOException | ParseException e) {
e.printStackTrace();
System.exit(3);
}
updateTapers();
}
@@ -814,8 +828,8 @@ public class Well {
};
private void updateTapers(){
nT1 = numTapers + 1;
private void updateTapers(boolean storeTapersInDB){
int nT1 = numTapers + 1;
// start by setting everything to 0
a[0] = 0.0;
@@ -902,8 +916,7 @@ public class Well {
frictionEstimate = dbFrictionEstimate;
}
db.storeWellSetup(this);
if (storeTapersInDB) db.storeWellSetup(this);
}
private double position(int p)
@@ -1057,8 +1070,7 @@ public class Well {
}
j++;
}
LPStatus downholeValues = new LPStatus(dPosition, dLoad, status);
return downholeValues;
return new LPStatus(dPosition, dLoad, status);
};
public void endOfStroke(){
@@ -1116,7 +1128,7 @@ public class Well {
}
public void gaugeOff(){
void gaugeOff(){
strokeSpeed.endOfDay();
downholeGrossStroke.endOfDay();
downholeNetStroke.endOfDay();