- Timestamp:
- 10/13/2017 02:54:56 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/tmcsim/client/ATMSDriverClient.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/ATMSDriverClient.java
r109 r112 11 11 import java.rmi.RemoteException; 12 12 import java.rmi.server.UnicastRemoteObject; 13 import java.text.ParseException; 14 import java.text.SimpleDateFormat; 15 import java.util.Date; 16 import java.util.InputMismatchException; 13 17 import java.util.LinkedList; 14 18 import java.util.Properties; … … 34 38 * to fire update commands at the desired time. 35 39 * Note: Sim Mgr must be running before starting this application. 36 * 40 * TODO: We probably want to be able to "override" a command, to force 41 * clearing an incident. 42 37 43 * @author jdalbey 38 44 */ … … 42 48 private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 43 49 private final static int ONE_SECOND = 1000; 50 private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); 44 51 /** 45 52 * Error logger. … … 126 133 // READ THE BATCH FILE OF COMMANDS and put in a queue 127 134 readBatchFile(); 128 // Consider special cases: 1) time to fire first command129 // has already past when application starts.130 // 2. Two commands have same fire time specified.131 // 3. How to "override" a command, to clear an incident.132 135 133 136 // Create a timer that fetches the simulation time every second. … … 137 140 { 138 141 String currentClock = ""; 142 Date simClock = new Date(); 143 // Obtain the simulation time from the CAD server 139 144 try 140 145 { 141 146 long simtime = theCoorInt.getCurrentSimulationTime(); 142 147 currentClock = formatInterval(simtime); 148 try { 149 simClock = formatter.parse(currentClock); 150 } catch (ParseException ex) { 151 Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex); 152 System.out.println("Invalid simulation clock time found in ATMSDriverClient"); 153 System.exit(-1); 154 } 143 155 System.out.println("Current clock: " + currentClock); 144 156 } catch (RemoteException ex) … … 146 158 Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.SEVERE, null, ex); 147 159 } 160 // If we have any events left to process 148 161 if (!eventQueue.isEmpty()) 149 162 { 150 // Check the queue of commands to see if the first 151 // item matches the current time. IF so, 163 // Get the time to launch the next event 164 String nextEvent = eventQueue.peek(); 165 String eventTimeField = nextEvent.substring(0,8); 166 Date eventTime = new Date(); 167 try { 168 eventTime = formatter.parse(eventTimeField); 169 } catch (ParseException ex) { 170 Logger.getLogger(ATMSDriverClient.class.getName()).log(Level.WARNING, null, ex); 171 System.out.println("Unable to parse event time: " + nextEvent + " skipping."); 172 eventQueue.remove(); 173 } 174 System.out.println("Next event will be launched at: " + formatter.format(eventTime)); 175 // Check the queue of events to see if the first 176 // item should be launched. IF so, 152 177 // issue that command and remove it from queue. 153 String nextEvent = eventQueue.peek(); 154 String eventTime = nextEvent.substring(0,8); 155 System.out.println("Next event will be launched at: " + eventTime); 156 if (eventTime.equals(currentClock)) 178 if (eventTime.before(simClock) || eventTime.equals(simClock)) 157 179 { 158 180 System.out.println("LAUNCHING EVENT at " + nextEvent ); 159 181 // Extract fields from event and prepare them 160 182 Scanner lineScan = new Scanner(nextEvent); 183 try 184 { 161 185 lineScan.next(); // skip time field 162 186 int routeNumber = lineScan.nextInt(); … … 169 193 // Remove this event from the queue, we're done with it. 170 194 eventQueue.remove(); 195 } 196 catch (InputMismatchException ex) 197 { 198 System.out.println("Wrong format data in batch event file: " + nextEvent + " \nskipping."); 199 eventQueue.remove(); 200 } 171 201 } 172 202 }
Note: See TracChangeset
for help on using the changeset viewer.
