head 1.21; access; symbols bg2_23:1.20 bg2_22:1.19 bg2_21:1.18 bg2_20:1.17 bg2_16:1.13 bg2_15:1.13 bg2_12:1.11 bg2_07:1.9; locks; strict; comment @# @; 1.21 date 2008.10.14.22.52.44; author martin; state Exp; branches; next 1.20; commitid 64e248f522b84567; 1.20 date 2008.08.12.17.01.26; author martin; state Exp; branches; next 1.19; commitid 383048a1c1e24567; 1.19 date 2008.08.04.07.18.29; author martin; state Exp; branches; next 1.18; commitid 24024896ad424567; 1.18 date 2008.08.02.14.07.28; author martin; state Exp; branches; next 1.17; commitid e4348946a1b4567; 1.17 date 2008.07.22.19.48.46; author martin; state Exp; branches; next 1.16; commitid 51194886399b4567; 1.16 date 2008.07.13.14.07.45; author martin; state Exp; branches; next 1.15; commitid 7f00487a0c2d4567; 1.15 date 2008.07.04.19.53.13; author martin; state Exp; branches; next 1.14; commitid e60486e7fa74567; 1.14 date 2008.06.30.21.10.40; author martin; state Exp; branches; next 1.13; commitid 4b7748694bce4567; 1.13 date 2008.06.16.08.17.50; author martin; state Exp; branches; next 1.12; commitid 33a5485621ac4567; 1.12 date 2008.06.08.11.52.10; author martin; state Exp; branches; next 1.11; commitid 1ef2484bc7e74567; 1.11 date 2008.05.27.16.36.19; author martin; state Exp; branches; next 1.10; commitid 308a483c387f4567; 1.10 date 2008.05.24.13.44.15; author martin; state Exp; branches; next 1.9; commitid f6848381bab4567; 1.9 date 2008.05.22.16.29.11; author martin; state Exp; branches; next 1.8; commitid 167b48359f524567; 1.8 date 2008.04.25.22.14.47; author martin; state Exp; branches; next 1.7; commitid 39f1481257d44567; 1.7 date 2008.04.19.20.59.46; author martin; state Exp; branches; next 1.6; commitid 402a480a5d3e4567; 1.6 date 2008.03.27.20.50.10; author martin; state Exp; branches; next 1.5; commitid 16fc47ec087f4567; 1.5 date 2008.03.25.19.27.26; author martin; state Exp; branches; next 1.4; commitid 49847e9521b4567; 1.4 date 2008.03.14.16.00.51; author martin; state Exp; branches; next 1.3; commitid 63b647daa1324567; 1.3 date 2008.03.13.17.25.19; author martin; state Exp; branches; next 1.2; commitid 446347d9637d4567; 1.2 date 2008.03.12.22.24.20; author martin; state Exp; branches; next 1.1; commitid 698147d858114567; 1.1 date 2008.03.11.18.43.36; author martin; state Exp; branches; next ; commitid 492847d6d2d64567; desc @@ 1.21 log @BG V 2.25 @ text @/* This file is part of JOP, the Java Optimized Processor see Copyright (C) 2005-2008, Martin Schoeberl (martin@@jopdesign.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /** * */ package oebb; import util.Dbg; import util.Timer; import ejip.LinkLayer; import ejip.Packet; import ejip.Udp; /** * Contains the state of the BG. Will substitute the class Status. * * @@author martin * */ public class State extends ejip.UdpHandler implements Runnable { // State of the system - exchanged periodically int bgid; int date; int time; int strnr; int zugnr; private volatile int pos; // set in Gps.checkStrMelnr() int start; int end; int startNF; int ankVerl; volatile int type; // changed at anmelden, on Verschub int alarmFlags; int cmdAck; int versionStrecke; // set in Gps.process() volatile int gpsLat; volatile int gpsLong; final static int TYPE_UNKNOWN = 0; final static int TYPE_ZUG = 1; // fix in menu final static int TYPE_NF = 2; // fix in menu final static int TYPE_VERSCH = 3; final static int TYPE_LERN = 4; final static int TYPE_ES221 = 5; final static int TYPE_UPDATE = 6; final static int TYPE_INFO = 7; final static int BG_SND_PORT = 2004; final static int ZLB_RCV_PORT = 2005; int destIp; // Alarm and flags public static final int ALARM_UEBERF = 1; public static final int ALARM_RICHTUNG = 2; public static final int ALARM_FAEHRT = 3; public static final int ALARM_ES221 = 4; public static final int FLAG_ANK = 5; public static final int FLAG_VERL = 6; public static final int FLAG_ZIEL = 7; public static final int ALARM_MLR = 8; public static final int FLAG_LERN = 9; private final static int AFLAG_ANK = 1<<(FLAG_ANK-1); private final static int AFLAG_VERL = 1<<(FLAG_VERL-1); private final static int AFLAG_ZIEL = 1<<(FLAG_ZIEL-1); private final static int AFLAG_LERN = 1<<(FLAG_LERN-1); private final static int ALARM_MSK = (1<<(ALARM_UEBERF-1)) | (1<<(ALARM_RICHTUNG-1)) | (1<<(ALARM_FAEHRT-1)) | (1<<(ALARM_ES221-1)) | (1<<(ALARM_MLR-1)); // Meldungen von der Zentrale zum BG final static int CFLAG_ABM = 0x00000001; // Abmelden final static int CFLAG_FWR = 0x00000002; // Fahrtwiderruf final static int CFLAG_NOT = 0x00000004; // Nothalt final static int CFLAG_ANMOK = 0x00000008; // Anmelden OK final static int CFLAG_ZLB_INT= 0x00000010; // used only internally by ZLB final static int CFLAG_IGNORE = 0x00000020; // ignore message final static int CFLAG_DOWNLOAD = 0x00000040; // downloadind SW or Strecke /** * The alarm was ack by the TFZ. Set the flags to zero when * FDL has also acked the alarm. */ private boolean alarmQuit; // local states /** * Send the status all 5 seconds. */ final static int SEND_PERIOD = 5; /** * Send timer */ int sendTimer; /** * A recieved packet from the ZLB. */ Packet zlbMsg; /** * Did we have a contact with the ZLB? */ boolean contactZLB; /** * Timestamp of last ZLB message. */ int lastMsgTimestamp; /** * Date of last message. */ int lastMsgDate; /** * Get at least on message all 22 seconds. */ final static int ZLB_TIMEOUT = 22; /** * Watch ZLB timer */ int zlbTimer; private LinkLayer ipLink; /** * FWR was acknowledged by TFZF */ boolean fwrQuitPending; /** * NOTHALT was acknowledged by TFZF */ boolean nothaltQuitPending; // save some fields and use static /** * Ignore flag is set */ static boolean ignore; /** * Do the reset as we got back a message after ABM */ static boolean forceReset; // reset not yet used - we have a reset function in Logic. // /** // * RESET timer // */ // private static int rtim; // /** // * reset pending // */ // private static boolean scheduleReset; /** * some network statistics */ private int[] stat; public State(LinkLayer link) { ipLink = link; // setTimestamp(2001, 1, 1, 0, 0, 0, 1); sendTimer = Timer.getTimeoutSec(SEND_PERIOD); stat = new int[5]; /* * start = 1; end = 2; startNF = 3; ankVerl = 4; type = 5; alarmFlags = * 2; cmdAck = 4; versionStrecke = 789; gpsLat = 6; gpsLong = 7; */ } public void setUDPData(int[] arr, int off) { arr[off] = bgid; arr[off + 1] = date; arr[off + 2] = time; arr[off + 3] = (strnr << 20) + zugnr; arr[off + 4] = (getPos() << 16) + start; arr[off + 5] = (end << 16) + startNF; int gpsFix = Gps.fix; if (gpsFix == -1) gpsFix = 0; // TODO: BgPpp.getConnType(); arr[off + 6] = (ankVerl << 16) + (type << 13) + (gpsFix << 11); arr[off + 7] = alarmFlags; arr[off + 8] = cmdAck; arr[off + 9] = (((Main.VER_MAJ << 8) + Main.VER_MIN) << 16) + versionStrecke; arr[off + 10] = gpsLat; arr[off + 11] = gpsLong; } static int getDate() { int d = Gps.getDate(); return (((d%100) + 2000) << 16) + ((d/100%100) << 8) + d/10000%100; } static int getTime() { int t = Gps.getTime(); return (t/10000000%100 << (32 - 6)) + (t/100000%100 << (32 - 12)) + (t/1000%100 << (32 - 18)) + (t%1000 << 32 - 28); } static int cnt; boolean send() { // get an IP packet Packet p = Packet.getPacket(Packet.FREE, Packet.ALLOC, ipLink); if (p == null) { // got no free buffer! Dbg.wr('!'); Dbg.wr('b'); return false; } date = getDate(); time = getTime(); setUDPData(p.buf, Udp.DATA); p.len = (Udp.DATA + 12) << 2; Dbg.wr("BG: "); printMsg(p); // and send it Udp.build(p, destIp, BG_SND_PORT); return true; } /** * Get one UDP status packet from the ZLB. * Just store it zlbMsg for further handling in run(). */ public void request(Packet p) { System.out.println("ZLB pkt"); // just store the received package p.setStatus(Packet.ALLOC); synchronized(this) { if (zlbMsg==null) { zlbMsg = p; } else { // this should not happen p.setStatus(Packet.FREE); } } } /** * Handle a message received from the ZLB. * zlbMsg point to the received package * */ private void handleMsg() { Packet p; synchronized (this) { p = zlbMsg; zlbMsg = null; } if (!checkPkt(p)) { p.setStatus(Packet.FREE); return; } int date = p.buf[Udp.DATA + 1]; int time = p.buf[Udp.DATA + 2]; if (!contactZLB) { lastMsgDate = date; lastMsgTimestamp = time; contactZLB = true; } else { // check date and time of the message if (date>lastMsgDate || (date==lastMsgDate && time>lastMsgTimestamp)) { lastMsgDate = date; lastMsgTimestamp = time; } else { Main.logger.print("Msg. too old"); // it's a too old packet p.setStatus(Packet.FREE); return; } } int[] buf = p.buf; // extract data // fist set cmd as it is used in isDownloading() int cmd = buf[Udp.DATA+8]; int strZugnr = buf[Udp.DATA + 3]; // use data from ZLB if not yet set - synchronization if restarted // but only if we are not in download check! if (Logic.state!=Logic.DL_CHECK && !isDownloading() && !stickyDl && (strZugnr & 0xfffff)!=0) { if (strnr==0) { // that one will probably never happen strnr = strZugnr >> 20; } if (zugnr==0) { zugnr = strZugnr & 0xfffff; } if (type==TYPE_UNKNOWN) { type = (buf[Udp.DATA+6]&0xffff)>>>13; } } // first set ignore flag, then connection state ignore = (cmd & CFLAG_IGNORE)!=0; // reset ZLB timeout zlbTimer = Timer.getTimeoutSec(ZLB_TIMEOUT); Status.connOk = true; // ack just this flag, but ignore the rest // work-around: also Ack the download flag if (ignore) { cmdAck |= CFLAG_IGNORE; // set the download flag cmdAck &= ~CFLAG_DOWNLOAD; cmdAck |= cmd & CFLAG_DOWNLOAD; Dbg.wr("ZLB ignored"); Dbg.lf(); p.setStatus(Packet.FREE); return; } if (cmd!=cmdAck) { // send the ack requestSend(); } // type int val = (buf[Udp.DATA+6]&0xffff)>>>13; // all state update synchronized synchronized (this) { // update when Verschub if (val==TYPE_VERSCH) { type = val; } // update ack with cmd as default action cmdAck = cmd; // but keep some when not acked from TFZF or Logic // Abmelden if ((cmd & CFLAG_ABM)!=0) { Logic.state = Logic.ABGEMELDET; } // Hack for Charlys Abmelden issue: // don't reset the ABM flag when reset is pending if ((cmd & CFLAG_ABM)==0 && Logic.state==Logic.ABGEMELDET) { cmdAck |= CFLAG_ABM; forceReset = true; } // Angemeldet if ((cmd & CFLAG_ANMOK)!=0) { Events.anmeldenOk = true; } // FWR if ((cmd & CFLAG_FWR)!=0) { if (!fwrQuitPending) { Logic.state = Logic.WIDERRUF; // we cannot ack it, reset the flag cmdAck &= ~CFLAG_FWR; } } else { // reset pending when FWR flag was reset by ZLB fwrQuitPending = false; } // NOTHALT if ((cmd & CFLAG_NOT)!=0) { if (!nothaltQuitPending) { Logic.state = Logic.NOTHALT; // we cannot ack it, reset the flag cmdAck &= ~CFLAG_NOT; } } else { // reset pending when NOT flag was reset by ZLB nothaltQuitPending = false; } } // Alarm and flag quits int alarmAck = buf[Udp.DATA+7]; synchronized (this) { // we can reset some of the flags here // check them individual as Charly does not // always ack the whole flag field - but he should if ((alarmAck & AFLAG_ANK)!=0) { alarmFlags &= ~AFLAG_ANK; ankVerl = 0; } if ((alarmAck & AFLAG_VERL)!=0) { alarmFlags &= ~AFLAG_VERL; ankVerl = 0; } if ((alarmAck & AFLAG_ZIEL)!=0) { alarmFlags &= ~AFLAG_ZIEL; } if ((alarmAck & AFLAG_LERN)!=0) { alarmFlags &= ~AFLAG_LERN; Status.lernOk = true; } if ((alarmAck&ALARM_MSK)==(alarmFlags&ALARM_MSK)) { // Alarm has been reset by FDL and seen by ZLB // we can reset it in the flags if (alarmQuit) { alarmFlags &= ~ALARM_MSK; alarmQuit = false; } } } boolean ferlChanged = false; val = buf[Udp.DATA+5]>>>16; if (val!=end) ferlChanged = true; val = buf[Udp.DATA+5]&0xffff; if (val!=startNF) ferlChanged = true; val = buf[Udp.DATA+4]&0xffff; if (val!=start) ferlChanged = true; // logging if (ferlChanged) { Main.logger.printSmall("Ferl changed, Logic.state=", Logic.state); Main.logger.printSmall("From ", buf[Udp.DATA+4]&0xffff); Main.logger.printSmall("To " , buf[Udp.DATA+5]>>>16); } if (val!=0 && ferlChanged && (Logic.state==Logic.ANM_OK || Logic.state==Logic.ZIEL || Logic.state==Logic.NOTHALT_OK || Logic.state==Logic.ERLAUBNIS)) { Main.logger.printSmall("new ferl accepted with state check, from=", buf[Udp.DATA+4]&0xffff); } // For a test accept FERL in any Logic.state if (val!=0 && ferlChanged) { // this is now a FERL event and we accept the change synchronized (this) { start = buf[Udp.DATA+4]&0xffff; end = buf[Udp.DATA+5]>>>16; startNF = buf[Udp.DATA+5]&0xffff; } Main.logger.printSmall("new ferl accepted, from=", start); synchronized (Status.dirMutex) { // let Logik.check() update the direction Status.direction = Gps.DIR_UNKNOWN; } Dbg.wr("set FERL"); Logic.state = Logic.ERLAUBNIS; } Dbg.wr("ZLB: "); printMsg(p); p.setStatus(Packet.FREE); } /** * Some sanity checks on the received packet. * @@param p * @@return */ private boolean checkPkt(Packet p) { stat[2]++; stat[3] += p.len; if (p.len != ((Udp.DATA+9)*4)) { // fix length // Status.commErr = Logic.COMM_SHORT; Dbg.wr("wrong length"); Dbg.intVal(p.len); Dbg.lf(); Main.logger.printHex("wrong length", p.len); stat[4]++; return false; } if (p.buf[Udp.DATA + 0] != bgid) { // Status.commErr = Logic.COMM_WRBGID; Dbg.wr("wrong bgid"); Dbg.intVal(p.buf[Udp.DATA+0]); Dbg.lf(); Main.logger.printHex("wrong bgid", p.buf[Udp.DATA+0]); return false; } return true; } /** * Debug output of a message. * @@param p */ private void printMsg(Packet p) { int[] buf = p.buf; int i; Dbg.wr("date="); i = p.buf[Udp.DATA+1]; Dbg.intVal(i>>>16); Dbg.intVal((i>>8) & 0xff); Dbg.intVal(i & 0xff); Dbg.wr("time="); i = p.buf[Udp.DATA+2]; Dbg.intVal((i>>26)&0x3f); Dbg.intVal((i>>20)&0x3f); Dbg.intVal((i>>14)&0x3f); Dbg.intVal(i&0x3ff); Dbg.wr("strnr="); Dbg.intVal(buf[Udp.DATA+3]>>>20); Dbg.wr("zugnr="); Dbg.intVal(buf[Udp.DATA+3]&0xfffff); Dbg.wr("pos="); Dbg.intVal(buf[Udp.DATA+4]>>>16); Dbg.wr("start="); Dbg.intVal(buf[Udp.DATA+4]&0xffff); Dbg.wr("end="); Dbg.intVal(buf[Udp.DATA+5]>>>16); Dbg.wr("NFstart="); Dbg.intVal(buf[Udp.DATA+5]&0xffff); Dbg.wr("ankVerl="); Dbg.intVal(buf[Udp.DATA+6]>>>16); Dbg.wr("type="); Dbg.intVal((buf[Udp.DATA+6]&0xffff)>>>13); Dbg.wr("alarm="); Dbg.hexVal(buf[Udp.DATA+7]); Dbg.wr("cmd="); Dbg.hexVal(buf[Udp.DATA+8]); Dbg.lf(); } /** * Periodically invoked to send a status message or handle * an incoming message. Check if ZLB and * connection is still alive. */ public void run() { // a hack for a lost bgid in the Flash if (bgid==-1 && Gps.ok()) { bgid = (getDate()<<16) + (getTime()>>>16); Dbg.wr("bgid is -1 => set a new one"); Dbg.lf(); BgTftp.programBgid(bgid); bgid = Flash.getId(); Main.logger.printHex("bgid is -1 set to", bgid); // enough done this round return; } if (Timer.timeout(sendTimer)) { sendTimer = Timer.getTimeoutSec(SEND_PERIOD); if (ipLink.getIpAddress()!=0 && destIp!=0) { send(); } } else { if (zlbMsg!=null) { handleMsg(); } } if (!Status.connOk) { // reset ZLB timeout zlbTimer = Timer.getTimeoutSec(ZLB_TIMEOUT); } else if (Timer.timeout(zlbTimer)) { // trigger a reconnect and display error // force a reconnect in Ppp-Modem ipLink.reconnect(); Status.connOk = false; Status.commErr = Logic.COMM_FDLERR; Main.logger.print("connection lost"); Dbg.wr("connection lost"); } // not yet used // if (scheduleReset) { // Dbg.wr('$'); // ++rtim; // if (rtim==20) { // Main.reset = true; // } // } } /** * Request to send a message immediately. */ public void requestSend() { sendTimer = Timer.getTimeoutSec(0); } public void sendZiel() { synchronized (this) { alarmFlags |= AFLAG_ZIEL; } requestSend(); } public boolean isVerschub() { return type==TYPE_VERSCH; } /** * Set alarm flag * @@param alarmType */ public void setAlarm(int alarmType) { if (alarmType==0) { alarmQuit = true; } else { alarmFlags |= 1<<(alarmType-1); } requestSend(); } /** * Quit FWR flag after Enter from TFZF */ public void fwrQuit() { fwrQuitPending = true; requestSend(); } /** * Quit NOT flag after Enter from TFZF */ public void nothaltQuit() { nothaltQuitPending = true; requestSend(); } /** * Flag Ankunft at position melnr * @@param melnr */ public void ankunft(int melnr) { synchronized(this) { ankVerl = melnr; alarmFlags |= AFLAG_ANK; // reset a pending verl if ((alarmFlags & AFLAG_VERL)!=0) { alarmFlags &= ~AFLAG_VERL; } } requestSend(); } /** * Flag Verlassen at position melnr * @@param melnr */ public void verlassen(int melnr) { synchronized(this) { ankVerl = melnr; alarmFlags |= AFLAG_VERL; // reset a pending verl if ((alarmFlags & AFLAG_ANK)!=0) { alarmFlags &= ~AFLAG_ANK; } } requestSend(); } /** * Got ack for ANK from ZLB * @@return */ public boolean ankuftAck() { return (alarmFlags & AFLAG_ANK) == 0; } /** * Got ack for VERL from ZLB * @@return */ public boolean verlassenAck() { return (alarmFlags & AFLAG_VERL) == 0; } public boolean isDownloading() { return (cmdAck & CFLAG_DOWNLOAD) != 0; } boolean stickyDl; public boolean isDownloadSticky() { if ((cmdAck & CFLAG_DOWNLOAD)!=0) { stickyDl = true; } return stickyDl; } public void setInfo() { type = TYPE_INFO; } public void resetInfo() { type = TYPE_UNKNOWN; } public void setLern() { type = TYPE_LERN; } public void resetLern() { type = TYPE_UNKNOWN; } public void lern(int melnr, int latAvg, int lonAvg) { synchronized (this) { pos = melnr; gpsLat = latAvg; gpsLong = lonAvg; alarmFlags |= AFLAG_LERN; } // TODO Auto-generated method stub } public void setESAlarm() { setAlarm(ALARM_ES221); } void setPos(int pos) { int oldPos = this.pos; this.pos = pos; // trigger actions on position change if (pos != oldPos) { requestSend(); Main.logic.posChanged(); } } int getPos() { return pos; } } @ 1.20 log @BG V 2.23 @ text @d300 1 d450 9 d461 4 d471 1 @ 1.19 log @BG V 2.22 @ text @a211 1 d213 1 a213 2 void setTimestamp() { d215 5 d221 2 a222 3 date = (((d%100) + 2000) << 16) + ((d/100%100) << 8) + d/10000%100; time = (t/10000000%100 << (32 - 6)) + (t/100000%100 << (32 - 12)) + (t/1000%100 << (32 - 18)) + (t%1000 << 32 - 28); d237 2 a238 1 setTimestamp(); d414 19 a432 17 if (alarmAck==alarmFlags) { // we can reset some of the flags here if ((alarmAck & AFLAG_ANK)!=0) { alarmFlags &= ~AFLAG_ANK; ankVerl = 0; } if ((alarmAck & AFLAG_VERL)!=0) { alarmFlags &= ~AFLAG_VERL; ankVerl = 0; } if ((alarmAck & AFLAG_ZIEL)!=0) { alarmFlags &= ~AFLAG_ZIEL; } if ((alarmAck & AFLAG_LERN)!=0) { alarmFlags &= ~AFLAG_LERN; Status.lernOk = true; } d443 14 a456 14 synchronized (this) { val = buf[Udp.DATA+4]&0xffff; if (val!=start) ferlChanged = true; start = val; val = buf[Udp.DATA+5]>>>16; if (val!=end) ferlChanged = true; end = val; val = buf[Udp.DATA+5]&0xffff; if (val!=startNF) ferlChanged = true; startNF = val; } if (start!=0 && ferlChanged && (Logic.state==Logic.ANM_OK || Logic.state==Logic.ZIEL || Logic.state==Logic.NOTHALT_OK)) { // this is now a FERL event d481 2 a482 2 Status.commErr = Logic.COMM_SHORT; Dbg.wr("wl"); d484 2 a485 1 Dbg.wr('\n'); d490 2 a491 3 Status.commErr = Logic.COMM_WRBGID; Dbg.wr('w'); Dbg.wr('i'); d493 2 a494 1 System.out.println("wrong bgid"); d548 13 d580 1 @ 1.18 log @BG V 2.21 @ text @d131 1 a131 1 * Get at least on message all 17 seconds. d133 5 a137 1 final static int ZLB_TIMEOUT = 17; d288 1 d291 10 a300 5 } if (time - lastMsgTimestamp < 0) { // it's a too old packet p.setStatus(Packet.FREE); return; @ 1.17 log @work around for Chary's issue with the reset @ text @d296 19 a314 11 int strPos = buf[Udp.DATA + 3]; // use data from ZLB if not yet set if (strnr==0) { // that one will probably never happen strnr = strPos >> 20; } if (zugnr==0) { zugnr = strPos & 0xfffff; } if (type==TYPE_UNKNOWN) { type = (buf[Udp.DATA+6]&0xffff)>>>13; a316 1 int cmd = buf[Udp.DATA+8]; d490 6 d497 5 a501 3 Dbg.intVal(Gps.getTime()); // Dbg.wr("seconds="); // Dbg.intVal((p.buf[Udp.DATA+2]>>14) & 0x3f); @ 1.16 log @BG V 2.19 @ text @d155 5 a331 2 // TODO check a cmd change d353 7 @ 1.15 log @BG V 2.18 @ text @d313 1 d316 3 @ 1.14 log @BG V 2.17 @ text @d151 4 a286 3 // reset ZLB timeout zlbTimer = Timer.getTimeoutSec(ZLB_TIMEOUT); Status.connOk = true; d305 7 a311 1 d313 1 a313 1 if ((cmd & CFLAG_IGNORE)!=0) { d321 1 d418 2 a419 1 if (start!=0 && ferlChanged && (Logic.state==Logic.ANM_OK || Logic.state==Logic.ZIEL)) { @ 1.13 log @BG V 2.15 @ text @a345 1 Logic.state = Logic.WIDERRUF; d347 1 a357 1 Logic.state = Logic.NOTHALT; d359 1 @ 1.12 log @BG V 2.13 @ text @d630 9 @ 1.11 log @BG V 2.07 @ text @d100 1 a199 15 // public void setTimestamp(int year, int month, int day, int hour, // int minute, int second, int milli) { // // date = (year << 16) + (month << 8) + day; // time = (hour << (32 - 6)) + (minute << (32 - 12)) // + (second << (32 - 18)) + (milli << 32 - 28); // } // // public void setTimestamp(int date, int time) { // // this.date = date; // this.time = time; // // increment millis // this.time += (1 << 32 - 28); // } a221 5 // TODO: workaround for first connect // if (!contactZLB) { // ++cnt; // setTimestamp(2001, 1, 1, 0, 0, 0, cnt); // } d291 11 a301 2 int str = strPos >> 20; int zugnr = strPos & 0xfffff; d626 4 @ 1.10 log @BG V 2.08 @ text @d83 1 d88 1 d98 1 d395 4 d654 8 @ 1.9 log @BG V 2.07 @ text @d96 1 a273 1 * TODO: check timestamp a302 2 // just now - use the ZLB time for our message timing // setTimestamp(date, time); d311 10 d339 1 a339 1 // but keep some when not acked from TFZF or Loigc @ 1.8 log @BG 2.03 @ text @d163 1 a163 1 setTimestamp(2001, 1, 1, 0, 0, 0, 1); d195 17 a211 9 public void setTimestamp(int year, int month, int day, int hour, int minute, int second, int milli) { date = (year << 16) + (month << 8) + day; time = (hour << (32 - 6)) + (minute << (32 - 12)) + (second << (32 - 18)) + (milli << 32 - 28); } public void setTimestamp(int date, int time) { d213 5 a217 4 this.date = date; this.time = time; // increment millis this.time += (1 << 32 - 28); d233 5 a237 4 if (!contactZLB) { ++cnt; setTimestamp(2001, 1, 1, 0, 0, 0, cnt); } d304 1 a304 1 setTimestamp(date, time); d455 4 a458 2 Dbg.wr("seconds="); Dbg.intVal((p.buf[Udp.DATA+2]>>14) & 0x3f); @ 1.7 log @BG V 2.02 (Hilsbetrieb) @ text @d330 1 a330 4 // if (Main.logic.state!=Logic.ANM_OK) { // // not yet seen in Logic // cmdAck &= ~CFLAG_ANMOK; // } a529 4 public boolean anmOk() { return (cmdAck & CFLAG_ANMOK) != 0; } @ 1.6 log @BG 2.01 @ text @d145 10 d309 1 d319 1 a319 1 // update ack with cmd d321 15 a335 1 d338 1 d350 1 d424 1 a424 1 Status.commErr = 2; d432 1 a432 1 Status.commErr = 4; d498 1 a498 1 Status.commErr = 1; d501 10 d639 1 a639 2 // TODO Auto-generated method stub @ 1.5 log @check Ziel @ text @d73 17 a89 8 // Alarme vom BG zur Zentrale final static int AFLAG_MLR = 0x00000001; // Melderaum ueberfahren final static int AFLAG_RICHTUNG = 0x00000002; // Falsche Richtung final static int AFLAG_FERL = 0x00000004; // Keine Fahrerlaubnis final static int AFLAG_ES221 = 0x00000008; // ES221 Mode final static int AFLAG_ANK = 0x00000010; // Ankunft final static int AFLAG_VERL = 0x00000020; // Verlassen final static int AFLAG_ZIEL = 0x00000040; // Ziel Erreicht d97 6 d334 1 a334 1 // Alarm flag quits d347 9 d484 4 a487 1 // TODO Auto-generated method stub a504 10 // TODO Auto-generated method stub // if (alarmType==Cmd.ALARM_UEBERF) { // Display.write("", "ZIEL ÜBERFAHREN", ""); // } else if (alarmType==Cmd.ALARM_FAEHRT) { // Display.write("KEINE", "FAHRERLAUBNIS", ""); // } else if (alarmType==Cmd.ALARM_RICHTUNG) { // Display.write("Falsche", "Richtung", ""); // } else { // Display.write("Alarm", "Nummer", alarmType, ""); // } d507 3 a509 4 // reset the alarm // or better mark it as reset alarm pending // we should not loose a alarm message due to a // too fast quite from the TFZF d565 1 a565 1 * Got ack for ANK from ZLB so flag is reset d573 1 a573 1 * Got ack for VERL from ZLB so flag is reset @ 1.4 log @flags @ text @d46 1 a46 1 volatile int pos; // set in Gps.checkStrMelnr() d138 1 a138 1 setTimestamp(2001, 1, 1, 0, 0, 0, 0); d155 1 a155 1 arr[off + 4] = (pos << 16) + start; d186 2 d198 6 d335 1 a335 1 // TODO: any sanity checks? action on change of start/end? d337 9 a345 3 start = buf[Udp.DATA+4]&0xffff; end = buf[Udp.DATA+5]>>>16; startNF = buf[Udp.DATA+5]&0xffff; d347 1 a347 1 if (start!=0 && (Logic.state==Logic.ANM_OK || Logic.state==Logic.ZIEL)) { d353 1 d590 14 @ 1.3 log @first BG 2.0 version @ text @d78 3 a80 4 final static int AFLAG_NOTQUIT = 0x00000010; // NOTHALT Quit final static int AFLAG_ZIEL = 0x00000020; // Ziel Erreicht final static int AFLAG_ANK = 0x00000040; // Ankunft final static int AFLAG_VERL = 0x00000080; // Verlassen @ 1.2 log @backup @ text @d190 1 a190 1 Packet p = Packet.getPacket(Packet.FREE, Packet.ALLOC, TestMain.ipLink); a199 1 d230 2 d328 16 d417 1 a417 1 if (ipLink.getIpAddress()!=0) { @ 1.1 log @new state messages @ text @d46 1 a46 1 int pos; d51 1 a51 1 int type; d55 7 a61 5 int gpsLat; int gpsLong; final static int TYPE_ZUG = 1; final static int TYPE_NF = 2; d66 6 d80 2 d120 5 d127 6 a132 1 * some statistics a143 5 bgid = 0x1234; strnr = 155; zugnr = 4711; pos = 43; type = TYPE_ZUG; d161 1 d199 1 d201 2 a202 1 Dbg.wr("send packet "); d205 1 a205 1 Udp.build(p, (192 << 24) + (168 << 16) + (0 << 8) + 5, 2004); d271 4 a274 1 // todo check a cmd change d276 51 a326 1 cmdAck = cmd; d400 3 a402 1 send(); d417 1 a417 1 Dbg.wr("conection lost"); d421 3 d428 131 @