- Timestamp:
- 11/12/2019 07:25:32 AM (6 years ago)
- Location:
- trunk/src/tmcsim/cadsimulator
- Files:
-
- 2 edited
-
Coordinator.java (modified) (15 diffs)
-
managers/TrafficModelManager.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/Coordinator.java
r475 r524 12 12 import java.rmi.server.UnicastRemoteObject; 13 13 import java.text.DateFormat; 14 import java.text.ParseException; 14 15 import java.text.SimpleDateFormat; 15 16 import java.util.ArrayList; … … 22 23 import java.util.TreeSet; 23 24 import java.util.Vector; 25 import java.util.concurrent.TimeUnit; 24 26 import java.util.logging.Level; 25 27 import java.util.logging.Logger; … … 138 140 /** The 'rolodex' of contact info */ 139 141 private static CardfileData cardfileData; 142 /** List of simulator start/pause messages for CAD Log. When Sim Mgr is 143 * started or paused add a message to the CAD log. Ticket 189. 144 */ 145 private static ArrayList<String> simMgrMsgLog; 140 146 /** The model for the state of the CAD Server */ 141 147 private CADSimulatorState cadModel; … … 155 161 kCADcommentLog = commentLogname; 156 162 clientList = new LinkedList<CADClientInterface>(); 163 simMgrMsgLog = new ArrayList<String>(); 157 164 cadData = new CADData(); 158 165 cardfileData = new CardfileData(); … … 200 207 public void startSimulation() throws RemoteException, ScriptException 201 208 { 202 209 // Verify we are ready to start the simulation 203 210 if (!CADServer.theIncidentMgr.areIncidentsLoaded()) 204 211 { … … 261 268 CADServer.theSimulationCntrlMgr.startSimulation(); 262 269 CADServer.theSoundPlayer.setAudioEnabled(true); 263 } 270 // Implement ticket 189 271 // Create a string containing all the incidents numbers for this simulation 272 String incNums = ""; 273 for (Incident inc: getIncidentList()) 274 { 275 incNums += inc.logNum + " "; 276 } 277 // combine all the log entry fields 278 final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); 279 String logItem = timeFormat.format(new Date()) 280 + " CAD log, " 281 + "Simulation Started, loaded incidents " 282 + incNums + "\n"; 283 simMgrMsgLog.add(logItem); // add the item to the msg log 284 } 285 } 286 public void pauseSimulation() throws RemoteException 287 { 288 final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); 289 simMgrMsgLog.add(timeFormat.format(new Date()) 290 + " CAD log, " 291 + "Simulation Paused.\n"); 292 // pausing the simulation will halt writing of CAD log, 293 // so manually force the write here before calling pause. 294 writeCADlog(); 295 CADServer.theSimulationCntrlMgr.pauseSimulation(); 296 CADServer.theSoundPlayer.setAudioEnabled(false); 297 } 298 299 public void resetSimulation() throws RemoteException 300 { 301 302 CADServer.theIncidentMgr.resetIncidents(); 303 cadData.resetSimulation(); 304 305 CADServer.theSoundPlayer.setAudioEnabled(false); 306 CADServer.theSoundPlayer.deQueueAll(); 307 308 cadModel.setTime(0); 309 310 setScriptStatus(SCRIPT_STATUS.SCRIPT_STOPPED_NOT_STARTED); 311 312 CMSDiversionDB.getInstance().resetDiversions(); 313 314 CADServer.theSimulationCntrlMgr.resetSimulation(); 315 CADServer.theParamicsSimMgr.resetSimulation(); 316 317 notifyObservers(new ObserverMessage(ObserverMessage.messageType.RESET_SIMULATION, null)); 318 264 319 } 265 320 /** Convenience method for clients to get ATMS time. … … 283 338 } 284 339 285 public void pauseSimulation() throws RemoteException286 {287 CADServer.theSimulationCntrlMgr.pauseSimulation();288 CADServer.theSoundPlayer.setAudioEnabled(false);289 }290 291 public void resetSimulation() throws RemoteException292 {293 294 CADServer.theIncidentMgr.resetIncidents();295 cadData.resetSimulation();296 297 CADServer.theSoundPlayer.setAudioEnabled(false);298 CADServer.theSoundPlayer.deQueueAll();299 300 cadModel.setTime(0);301 302 setScriptStatus(SCRIPT_STATUS.SCRIPT_STOPPED_NOT_STARTED);303 304 CMSDiversionDB.getInstance().resetDiversions();305 306 CADServer.theSimulationCntrlMgr.resetSimulation();307 CADServer.theParamicsSimMgr.resetSimulation();308 309 notifyObservers(new ObserverMessage(ObserverMessage.messageType.RESET_SIMULATION, null));310 311 }312 340 313 341 public void gotoSimulationTime(final long newSimTime) throws RemoteException … … 475 503 return CADServer.theSimulationCntrlMgr.getCurrentSimTime(); 476 504 } 477 505 /** 506 * Format an elapsed time in seconds as HH:MM:SS 507 * 508 * @param seconds 509 * @return HH:MM:SS formatted string 510 */ 511 public static String formatTimeInSeconds(final long seconds) 512 { 513 final long hr = TimeUnit.SECONDS.toHours(seconds); 514 final long min = TimeUnit.SECONDS.toMinutes(seconds - TimeUnit.HOURS.toSeconds(hr)); 515 final long sec = TimeUnit.SECONDS.toSeconds(seconds - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 516 return String.format("%02d:%02d:%02d", hr, min, sec); 517 } 478 518 public void triggerIncident(Integer incidentNumber) throws RemoteException, ScriptException 479 519 { … … 755 795 756 796 CADServer.theIncidentMgr.tick(currentSimTime); 757 writeCADlog();758 797 writeSimTime(currentSimTime); 759 798 } … … 763 802 timeThread.start(); 764 803 } 804 writeCADlog(); 765 805 } 766 806 /** Helper method to write the current CAD comment log to a file. … … 786 826 for (String item: getSortedComments(incList)) 787 827 { 828 // Write the line without the timestamp 788 829 writer.print(item.substring(9)); 789 830 } … … 797 838 /** Extract a list of comments from the current incidents, ordered 798 839 * by timestamp. Fixes defect #175. 840 * Note that the timestamp is used for ordering the comments, 841 * but not written to the CADlog. 799 842 * Package private to allow unit testing. 800 843 * … … 815 858 { 816 859 // Combine the fields into one output entry 817 String timestamp = (String)notesTable.getValueAt(row,1); 860 String timestamp = (String)notesTable.getValueAt(row,1);//wall clock time 818 861 String initials = (String) notesTable.getValueAt(row,2); // user initials 819 862 // If there are user intials, include this item. … … 830 873 } 831 874 } 875 } 876 // Append Sim Mgr start and pause messages to comment list. ticket 189 877 for (String simMsg: simMgrMsgLog) 878 { 879 commentList.add(simMsg); 832 880 } 833 881 // Order the comments by timestamp instead of incident number. … … 857 905 } 858 906 }); 907 859 908 return commentList; 860 909 } -
trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java
r457 r524 158 158 { 159 159 long simtime = theCoordinator.getCurrentSimulationTime(); 160 currentClock = formatTimeInSeconds(simtime);160 currentClock = theCoordinator.formatTimeInSeconds(simtime); 161 161 // For Debugging, show the ATMS time 162 162 // long ATMStime = theCoorInt.getATMStime(); … … 390 390 * @return HH:MM:SS formatted string 391 391 */ 392 public static String formatTimeInSeconds(final long seconds)393 {394 final long hr = TimeUnit.SECONDS.toHours(seconds);395 final long min = TimeUnit.SECONDS.toMinutes(seconds - TimeUnit.HOURS.toSeconds(hr));396 final long sec = TimeUnit.SECONDS.toSeconds(seconds - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min));397 return String.format("%02d:%02d:%02d", hr, min, sec);398 }392 // public static String formatTimeInSeconds(final long seconds) 393 // { 394 // final long hr = TimeUnit.SECONDS.toHours(seconds); 395 // final long min = TimeUnit.SECONDS.toMinutes(seconds - TimeUnit.HOURS.toSeconds(hr)); 396 // final long sec = TimeUnit.SECONDS.toSeconds(seconds - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 397 // return String.format("%02d:%02d:%02d", hr, min, sec); 398 // } 399 399 400 400 /** Writes the highway model to a GeoJson file for reading
Note: See TracChangeset
for help on using the changeset viewer.
