📄 station.java
字号:
package kfl;/*** All Functions for MS in Zentrale.** WICHTIG: Fehler fuehren zu Stopp der Anlage (mit for (;;) loop).* Neustart erforderlich!*/public class Station { public static final int MIN_SENS_CNT = 3; public static final int MAX_SENS_CNT = 24; // Sensor is valid for maximum 27 public static final int MAX_DIFF = 20; // = 10 cm public static final int CONTROL_DIFF = 10; // = 5 cm public static final int MAX_COMM_ERR = 3; // maximum (continous) errors befor stop// public static final int MAX_COMM_ERR = 10; // maximum (continous) errors befor stop// bei SEHR hohem Wert Timer.wd in cmdAll und cmd!!! public static final int LUNKNOWN = 0; // unbekannt public static final int LU = 1; // unten public static final int LO = 2; // oben public static final int LZ = 3; // zwischen public static final int LUZ = 4; // unten zwischen private static int cnt; // how many MS private static int ltg; // state of Leitung private static int[] ret; public static int[] temp; private static int[] maxCnt; // up position of cnt (down pos. is 0) private static int[] upCnt; // impuls count after up sensor private static int[] downCnt; // impuls count after down sensor private static int[] lastCnt; // last known value of MS cnt private static int[] servCnt; // used for service public static void init() { int i; ltg = LUNKNOWN; ret = new int[16]; // maximum maxCnt = new int[16]; upCnt = new int[16]; downCnt = new int[16]; servCnt = new int[16]; temp = new int[16]; // maximum for (i=0; i<16; ++i) temp[i] = 0; cnt = Config.getCnt(); getVals();dispVals(); }/*private static void setXXX() {int i;// set valuesfor (i=0; i<3; ++i) { Config.setMSmaxCnt(i+1, maxCnt[i]); Config.setMSdwnCnt(i+1, downCnt[i]); Config.setMSupCnt(i+1, upCnt[i]);}}*/ private static void getVals() { int i; for (i=0; i<cnt; ++i) { maxCnt[i] = Config.getMSmaxCnt(i+1); upCnt[i] = Config.getMSupCnt(i+1); downCnt[i] = Config.getMSdwnCnt(i+1); }/*maxCnt[0] = 1051;maxCnt[1] = 1051;maxCnt[2] = 1052;downCnt[0] = 20;downCnt[1] = 10;downCnt[2] = 18;upCnt[0] = 8; // should be 3 minimum!!!upCnt[1] = 7;upCnt[2] = 8;*/ boolean ok = true; // check possibility of values for (i=0; i<cnt; ++i) { if (maxCnt[i]==0 || maxCnt[i]>1100) { ok = false; } if (upCnt[i]<MIN_SENS_CNT || upCnt[i]>MAX_SENS_CNT) { ok = false; upCnt[i] = MIN_SENS_CNT; } if (downCnt[i]<MIN_SENS_CNT || downCnt[i]>MAX_SENS_CNT) { ok = false; downCnt[i] = MIN_SENS_CNT; } } if (!ok) { Menu.msg(Texte.notjust, Texte.secval); for (i=0; i<cnt; ++i) { maxCnt[i] = 0; } } }/*** only for info.*/ private static void dispVals() { int i; Display.cls(); for (i=0; i<cnt; ++i) { Display.intVal(downCnt[i]); Display.data(' '); } Timer.sleepWd(1000); Display.cls(); for (i=0; i<cnt; ++i) { Display.intVal(upCnt[i]); Display.data(' '); } Timer.sleepWd(1000); Display.cls(); for (i=0; i<cnt; ++i) { Display.intVal(maxCnt[i]); Display.data(' '); } Timer.sleepWd(1000); Display.cls(); }//// some properties// public static boolean isDown() { return ltg==LU; } public static boolean isUp() { return ltg==LO; } public static boolean isBetween() { return ltg==LZ; } public static boolean upOk() { return ltg==LU || ltg==LUZ || ltg==LZ; } public static boolean downOk() { return ltg==LO || ltg==LZ; } public static int getCnt() { return cnt; }//// cmd handling// private static int cmd(int nr, int val) { return cmd(nr, val, 0); } private static int cmd(int nr, int val, int data) { int ret = Msg.exchg(nr, val, data); if (ret>=0) { return ret; } // more tries int tryCnt = MAX_COMM_ERR-1; for (; ret<0 && tryCnt>0; --tryCnt) { ret = Msg.exchg(nr, val, data);Timer.wd(); // bei zu hohem MAX_COMM_ERR } return ret; } private static boolean cmdAll(int val) { return cmdAll(val, 0); }/*** send a command to all MS.*/ private static boolean cmdAll(int val, int data) { int i, j; boolean ok = true; // first try for (i=0; i<cnt; ++i) { j = Msg.exchg(i+1, val, data); ret[i] = j; if (j<0) ok = false; } // more tries int tryCnt = MAX_COMM_ERR-1; for (; !ok && tryCnt>0; --tryCnt) { ok = true; for (i=0; i<cnt; ++i) { j = ret[i]; if (j<0) { j = Msg.exchg(i+1, val, data); ret[i] = j; } if (j<0) ok = false; }Timer.wd(); // bei zu hohem MAX_COMM_ERR } return ok; } private static boolean cmdAll(int val, int[] data) { int i, j; boolean ok = true; // first try for (i=0; i<cnt; ++i) { j = Msg.exchg(i+1, val, data[i]); ret[i] = j; if (j<0) ok = false; } // more tries int tryCnt = MAX_COMM_ERR-1; for (; !ok && tryCnt>0; --tryCnt) { ok = true; for (i=0; i<cnt; ++i) { j = ret[i]; if (j<0) { j = Msg.exchg(i+1, val, data[i]); ret[i] = j; } if (j<0) ok = false; }Timer.wd(); // bei zu hohem MAX_COMM_ERR } return ok; } public static void powerOff() { JopSys.wr(0, BBSys.IO_TRIAC); } // be careful when using this in another program! public static void powerOn() { JopSys.wr(BBSys.BIT_TR_ON, BBSys.IO_TRIAC); } public static void error(int nr) { error(nr, 0); }/* not used private static void errorFindMS(int nr) { int i, msnr; msnr = 0; for (i=0; i<cnt; ++i) { if (ret[i]<0) { msnr = i+1; break; } } error(nr, msnr); }*//*** error display with endless loop.* allow Menu, but no 'real' function.* be WARNED: menu function 'download' (Debug.echo()) switches Power ON!!!*/ public static void error(int nr, int msnr) { powerOff(); Zentrale.chkNot(); if (msnr!=0) { Display.line1(Texte.mserr, msnr); } else { Display.line1(Texte.error); } Display.line2(Texte.errTxt(nr)); Log.write(Log.ERROR, nr, msnr);//// allow Menu cmd's for error correction// but no way out for (;;) { Keyboard.loop(); if (Keyboard.pressed) { if (Keyboard.rd()==Keyboard.B) { Menu.doit(); Display.line1(Texte.errMode); Display.line2(Texte.startNew); } } Timer.waitForNextInterval(); Timer.wd(); } }/*** communication error display with secial display!*/ private static void comErr() { int i; int msnr = 0; powerOff(); Zentrale.chkNot(); Display.cls(); Display.line1(Texte.comErr); Display.line2(); for (i=0; i<cnt; ++i) { Timer.wd(); if (ret[i]<0) { msnr = i+1; Display.intVal(msnr); Display.data(' '); } } Log.write(Log.ERROR, Err.COMM, msnr); for (;;) { Timer.wd(); } }/** Werte Sensoren der Masten aus.* Leitung unten nur wenn ALLE Sensoren unten anzeigen.* Das Freigaberelais wird aber nur in down() nach einer erfolgreichen Fahrt* gesetzt. Die LEDs in der Zentrale aber auch nach Einschalten und in LUZ.*/ private static void chkLtg() { int i, val; boolean u, o; int cntU, cntO, cntZ; cntU = 0; cntO = 0; cntZ = 0; if (!cmdAll(BBSys.CMD_INP)) { comErr(); } for (i=0; i<cnt; ++i) { val = ret[i]>> 4; // TASTER und Sensoren! o = (val & BBSys.BIT_SENSO) != 0; u = (val & BBSys.BIT_SENSU) != 0; if (o && u) { error(Err.SENS_UP_AND_DOWN, i+1); } else if (o) { ++cntO; } else if (u) { ++cntU; } else { ++cntZ; } } if (cntU==0 && cntO==0) { ltg = LZ; JopSys.wr(BBSys.BIT_LED_U + BBSys.BIT_LED_O, BBSys.IO_LED); } else if (cntU==cnt && cntO==0) { ltg = LU; JopSys.wr(BBSys.BIT_LED_U, BBSys.IO_LED); } else if (cntU!=0 && cntO==0) { ltg = LUZ; } else if (cntU==0 && cntO!=0) { ltg = LO; JopSys.wr(BBSys.BIT_LED_O, BBSys.IO_LED); } else { JopSys.wr(0, BBSys.IO_LED); error(Err.SENS_UP_AND_DOWN); } }/*** see if a new MS is at address 0 after boot timeout.* more than one MS can be changed, BUT only one at a time AND* lowest number first!*/ private static void chkNewMS() { int i, j, missing; i = 0; missing = -1; for (j=0; j<cnt; ++j) { if (ret[j]<0) { missing = j; break; // stop on first found! } } if (missing!=-1 && cmd(0, BBSys.CMD_STATUS)>=0) { // found ! ++missing; // base 1 Display.line1(Texte.newms, missing); cmd(0, BBSys.CMD_SET_STATE, BBSys.MS_DBG); cmd(0, BBSys.CMD_SETAD, missing); Timer.sleepWd(2000); Display.line1(Texte.reboot); for(;;) ; } }/*** something went wrong during boot.*/ private static void bootErr() { int i, j; i = 0; for (j=0; j<cnt; ++j) { if (ret[j]<0) ++i; } if (i==cnt) error(Err.NO_MS); for (j=0; j<cnt; ++j) { if (ret[j]<0) { error(Err.NO_ANSW_MS, j+1); // endless loop } } error(Err.NO_ANSW_MS); // endless loop } private static final int BOOT_TIME = 100; // max. 10s/*** boot all MS and check MS error*/ private static boolean boot() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -