Changeset 524 in tmcsimulator for trunk/src/tmcsim


Ignore:
Timestamp:
11/12/2019 07:25:32 AM (6 years ago)
Author:
jdalbey
Message:

Implement #189 in Coordinator.java: Add sim start and pause msgs to unified log.

Location:
trunk/src/tmcsim/cadsimulator
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/Coordinator.java

    r475 r524  
    1212import java.rmi.server.UnicastRemoteObject; 
    1313import java.text.DateFormat; 
     14import java.text.ParseException; 
    1415import java.text.SimpleDateFormat; 
    1516import java.util.ArrayList; 
     
    2223import java.util.TreeSet; 
    2324import java.util.Vector; 
     25import java.util.concurrent.TimeUnit; 
    2426import java.util.logging.Level; 
    2527import java.util.logging.Logger; 
     
    138140    /** The 'rolodex' of contact info */ 
    139141    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; 
    140146    /** The model for the state of the CAD Server */ 
    141147    private CADSimulatorState cadModel; 
     
    155161        kCADcommentLog = commentLogname; 
    156162        clientList = new LinkedList<CADClientInterface>(); 
     163        simMgrMsgLog = new ArrayList<String>(); 
    157164        cadData = new CADData(); 
    158165        cardfileData = new CardfileData(); 
     
    200207    public void startSimulation() throws RemoteException, ScriptException 
    201208    { 
    202  
     209        // Verify we are ready to start the simulation 
    203210        if (!CADServer.theIncidentMgr.areIncidentsLoaded()) 
    204211        { 
     
    261268            CADServer.theSimulationCntrlMgr.startSimulation(); 
    262269            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 
    264319    } 
    265320    /** Convenience method for clients to get ATMS time. 
     
    283338    } 
    284339 
    285     public void pauseSimulation() throws RemoteException 
    286     { 
    287         CADServer.theSimulationCntrlMgr.pauseSimulation(); 
    288         CADServer.theSoundPlayer.setAudioEnabled(false); 
    289     } 
    290  
    291     public void resetSimulation() throws RemoteException 
    292     { 
    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     } 
    312340 
    313341    public void gotoSimulationTime(final long newSimTime) throws RemoteException 
     
    475503        return CADServer.theSimulationCntrlMgr.getCurrentSimTime(); 
    476504    } 
    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    } 
    478518    public void triggerIncident(Integer incidentNumber) throws RemoteException, ScriptException 
    479519    { 
     
    755795 
    756796                    CADServer.theIncidentMgr.tick(currentSimTime); 
    757                     writeCADlog(); 
    758797                    writeSimTime(currentSimTime); 
    759798                } 
     
    763802            timeThread.start(); 
    764803        } 
     804        writeCADlog(); 
    765805    } 
    766806    /** Helper method to write the current CAD comment log to a file.   
     
    786826            for (String item: getSortedComments(incList)) 
    787827            { 
     828                // Write the line without the timestamp 
    788829                writer.print(item.substring(9)); 
    789830            } 
     
    797838    /** Extract a list of comments from the current incidents, ordered 
    798839     * by timestamp.  Fixes defect #175. 
     840     * Note that the timestamp is used for ordering the comments, 
     841     * but not written to the CADlog. 
    799842     * Package private to allow unit testing. 
    800843     *  
     
    815858            { 
    816859                // 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 
    818861                String initials = (String) notesTable.getValueAt(row,2); // user initials 
    819862                // If there are user intials, include this item. 
     
    830873                } 
    831874            } 
     875        } 
     876        // Append Sim Mgr start and pause messages to comment list. ticket 189 
     877        for (String simMsg: simMgrMsgLog) 
     878        { 
     879            commentList.add(simMsg); 
    832880        } 
    833881        // Order the comments by timestamp instead of incident number. 
     
    857905            } 
    858906        }); 
     907 
    859908        return commentList; 
    860909    } 
  • trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java

    r457 r524  
    158158                { 
    159159                    long simtime = theCoordinator.getCurrentSimulationTime(); 
    160                     currentClock = formatTimeInSeconds(simtime); 
     160                    currentClock = theCoordinator.formatTimeInSeconds(simtime); 
    161161                    // For Debugging, show the ATMS time 
    162162//                    long ATMStime = theCoorInt.getATMStime();        
     
    390390     * @return HH:MM:SS formatted string 
    391391     */ 
    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//    } 
    399399 
    400400    /** Writes the highway model to a GeoJson file for reading 
Note: See TracChangeset for help on using the changeset viewer.