Commit c46976f9 authored by Jan Wagemakers's avatar Jan Wagemakers

checks for communication error

parent 0950f794
......@@ -29,11 +29,11 @@ public class StartupRunner implements CommandLineRunner {
private static final Serial SERIAL = new Serial();
private float oldOT = -1;
private float oldYY = -1;
private float oldMM = -1;
private float oldDD = -1;
private float oldhh = -1;
private float oldmm = -1;
private int oldYear = -1;
private int oldMonth = -1;
private int oldDay = -1;
private int oldHour = -1;
private int oldMin = -1;
// private static float outsideTemp;
@Autowired
......@@ -62,6 +62,9 @@ public class StartupRunner implements CommandLineRunner {
float sp = 0;
Calendar rightNow = Calendar.getInstance();
int year=rightNow.get(Calendar.YEAR)-2000;
int month=rightNow.get(Calendar.MONTH) + 1;
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
int min = rightNow.get(Calendar.MINUTE);
int day = rightNow.get(Calendar.DAY_OF_WEEK);
......@@ -111,37 +114,32 @@ public class StartupRunner implements CommandLineRunner {
if (SERIAL.setOT(outsideTemp)) oldOT = outsideTemp;
}
int YY=rightNow.get(Calendar.YEAR)-2000;
if (oldYY != YY) {
if (SERIAL.setYY(YY)) oldYY = YY;
if (oldYear != year) {
if (SERIAL.setYY(year)) oldYear = year;
}
int MM=rightNow.get(Calendar.MONTH) + 1;
if (oldMM != MM) {
if (SERIAL.setMM(MM)) oldMM = MM;
if (oldMonth != month) {
if (SERIAL.setMM(month)) oldMonth = month;
}
int DD=rightNow.get(Calendar.DAY_OF_MONTH);
if (oldDD != DD) {
if (SERIAL.setDD(DD)) oldDD = DD;
if (oldDay != day) {
if (SERIAL.setDD(day)) oldDay = day;
}
int hh=rightNow.get(Calendar.HOUR_OF_DAY);
if (oldhh != hh) {
if (SERIAL.sethh(hh)) oldhh = hh;
if (oldHour != hour) {
if (SERIAL.sethh(hour)) oldHour = hour;
}
int mm=rightNow.get(Calendar.MINUTE);
if (oldmm != mm) {
if (SERIAL.setmm(mm)) oldmm = mm;
if (oldMin != min) {
if (SERIAL.setmm(min)) oldMin = min;
}
// get status of thermostats relais (OutPut)
int op = SERIAL.getOP();
data.add("" + op);
int count = 20;
while (op == -1f) {
data.add("RETRY");
while (!(op == 0 || op == 1)) {
communicationError("RETRY");
op = SERIAL.getOP();
data.add("" + op);
if (count-- < 0) break;
......@@ -152,7 +150,7 @@ public class StartupRunner implements CommandLineRunner {
data.add("" + pv);
count = 20;
while (pv == -1f) {
data.add("RETRY");
communicationError("RETRY");
pv = SERIAL.getPV();
data.add("" + pv);
if (count-- < 0) break;
......@@ -190,7 +188,7 @@ public class StartupRunner implements CommandLineRunner {
count = 20;
while (SERIAL.getSP() != sp) {
while (!SERIAL.setSP(sp)) {
data.add("RETRY");
communicationError("RETRY");
if (count-- < 0) break;
}
if (count-- < 0) break;
......@@ -198,9 +196,14 @@ public class StartupRunner implements CommandLineRunner {
}
if (count >= 0) data.add("Control SP OK");
} else {
data.add("No BT connection");
communicationError("No BT connection");
}
}
private void communicationError(String string) {
data.add(string);
oldYear = oldMonth = oldDay = oldHour = oldMin = -1;
oldOT = -1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment