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 { ...@@ -29,11 +29,11 @@ public class StartupRunner implements CommandLineRunner {
private static final Serial SERIAL = new Serial(); private static final Serial SERIAL = new Serial();
private float oldOT = -1; private float oldOT = -1;
private float oldYY = -1; private int oldYear = -1;
private float oldMM = -1; private int oldMonth = -1;
private float oldDD = -1; private int oldDay = -1;
private float oldhh = -1; private int oldHour = -1;
private float oldmm = -1; private int oldMin = -1;
// private static float outsideTemp; // private static float outsideTemp;
@Autowired @Autowired
...@@ -62,6 +62,9 @@ public class StartupRunner implements CommandLineRunner { ...@@ -62,6 +62,9 @@ public class StartupRunner implements CommandLineRunner {
float sp = 0; float sp = 0;
Calendar rightNow = Calendar.getInstance(); 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 hour = rightNow.get(Calendar.HOUR_OF_DAY);
int min = rightNow.get(Calendar.MINUTE); int min = rightNow.get(Calendar.MINUTE);
int day = rightNow.get(Calendar.DAY_OF_WEEK); int day = rightNow.get(Calendar.DAY_OF_WEEK);
...@@ -111,37 +114,32 @@ public class StartupRunner implements CommandLineRunner { ...@@ -111,37 +114,32 @@ public class StartupRunner implements CommandLineRunner {
if (SERIAL.setOT(outsideTemp)) oldOT = outsideTemp; if (SERIAL.setOT(outsideTemp)) oldOT = outsideTemp;
} }
int YY=rightNow.get(Calendar.YEAR)-2000; if (oldYear != year) {
if (oldYY != YY) { if (SERIAL.setYY(year)) oldYear = year;
if (SERIAL.setYY(YY)) oldYY = YY;
} }
int MM=rightNow.get(Calendar.MONTH) + 1; if (oldMonth != month) {
if (oldMM != MM) { if (SERIAL.setMM(month)) oldMonth = month;
if (SERIAL.setMM(MM)) oldMM = MM;
} }
int DD=rightNow.get(Calendar.DAY_OF_MONTH); if (oldDay != day) {
if (oldDD != DD) { if (SERIAL.setDD(day)) oldDay = day;
if (SERIAL.setDD(DD)) oldDD = DD;
} }
int hh=rightNow.get(Calendar.HOUR_OF_DAY); if (oldHour != hour) {
if (oldhh != hh) { if (SERIAL.sethh(hour)) oldHour = hour;
if (SERIAL.sethh(hh)) oldhh = hh;
} }
int mm=rightNow.get(Calendar.MINUTE); if (oldMin != min) {
if (oldmm != mm) { if (SERIAL.setmm(min)) oldMin = min;
if (SERIAL.setmm(mm)) oldmm = mm;
} }
// get status of thermostats relais (OutPut) // get status of thermostats relais (OutPut)
int op = SERIAL.getOP(); int op = SERIAL.getOP();
data.add("" + op); data.add("" + op);
int count = 20; int count = 20;
while (op == -1f) { while (!(op == 0 || op == 1)) {
data.add("RETRY"); communicationError("RETRY");
op = SERIAL.getOP(); op = SERIAL.getOP();
data.add("" + op); data.add("" + op);
if (count-- < 0) break; if (count-- < 0) break;
...@@ -152,7 +150,7 @@ public class StartupRunner implements CommandLineRunner { ...@@ -152,7 +150,7 @@ public class StartupRunner implements CommandLineRunner {
data.add("" + pv); data.add("" + pv);
count = 20; count = 20;
while (pv == -1f) { while (pv == -1f) {
data.add("RETRY"); communicationError("RETRY");
pv = SERIAL.getPV(); pv = SERIAL.getPV();
data.add("" + pv); data.add("" + pv);
if (count-- < 0) break; if (count-- < 0) break;
...@@ -190,7 +188,7 @@ public class StartupRunner implements CommandLineRunner { ...@@ -190,7 +188,7 @@ public class StartupRunner implements CommandLineRunner {
count = 20; count = 20;
while (SERIAL.getSP() != sp) { while (SERIAL.getSP() != sp) {
while (!SERIAL.setSP(sp)) { while (!SERIAL.setSP(sp)) {
data.add("RETRY"); communicationError("RETRY");
if (count-- < 0) break; if (count-- < 0) break;
} }
if (count-- < 0) break; if (count-- < 0) break;
...@@ -198,9 +196,14 @@ public class StartupRunner implements CommandLineRunner { ...@@ -198,9 +196,14 @@ public class StartupRunner implements CommandLineRunner {
} }
if (count >= 0) data.add("Control SP OK"); if (count >= 0) data.add("Control SP OK");
} else { } 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