Changeset 44 in tmcsimulator for trunk/src/tmcsim/cadsimulator/managers
- Timestamp:
- 06/23/2016 06:30:20 PM (10 years ago)
- Location:
- trunk/src/tmcsim/cadsimulator/managers
- Files:
-
- 2 edited
-
MediaManager.java (modified) (4 diffs)
-
ParamicsSimulationManager.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/managers/MediaManager.java
r2 r44 19 19 import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; 20 20 import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; 21 import tmcsim.cadsimulator.viewer. CADSimulatorViewer;21 import tmcsim.cadsimulator.viewer.model.CADSimulatorModel; 22 22 import tmcsim.common.CCTVDirections; 23 23 import tmcsim.common.CCTVInfo; … … 73 73 private StillImagesDB theImage_DB = null; 74 74 75 /** Reference to the CADSimulator Viewer. */76 private CADSimulator Viewer theViewer;75 /** Reference to the CADSimulatorModel. */ 76 private CADSimulatorModel theModel; 77 77 78 78 /** Properties object for the Media portion of the CAD. */ … … 90 90 */ 91 91 public MediaManager(String propertiesFile, ATMSManager theATMSManager, 92 CADSimulator Viewer viewer) {92 CADSimulatorModel model) { 93 93 theDVD_DB = new DVDPlayerDB(); 94 94 theImage_DB = new StillImagesDB(); 95 95 96 the Viewer = viewer;96 theModel = model; 97 97 98 98 try { … … 166 166 ((DVDStatusUpdate)arg).exception); 167 167 } 168 the Viewer.updateDVDStatus((DVDStatusUpdate)arg);168 theModel.updateDVDStatus((DVDStatusUpdate)arg); 169 169 } 170 170 else if(arg instanceof DVDTitleUpdate) { 171 the Viewer.updateDVDTitle((DVDTitleUpdate)arg);171 theModel.updateDVDTitle((DVDTitleUpdate)arg); 172 172 } 173 173 } -
trunk/src/tmcsim/cadsimulator/managers/ParamicsSimulationManager.java
r20 r44 6 6 import java.util.logging.Level; 7 7 import java.util.logging.Logger; 8 9 8 import tmcsim.cadmodels.CMSInfo; 10 9 import tmcsim.cadsimulator.Coordinator; … … 13 12 import tmcsim.cadsimulator.paramicscontrol.ParamicsIncidentWriter; 14 13 import tmcsim.cadsimulator.paramicscontrol.ParamicsStatusReader; 14 import tmcsim.common.CADEnums.PARAMICS_STATUS; 15 15 import tmcsim.common.SimulationException; 16 16 import tmcsim.common.XMLIncident; 17 import tmcsim.common.CADEnums.PARAMICS_STATUS;18 17 19 18 /** … … 22 21 * Upon construction all ParamicsReaders and ParamicsWriters are initialized 23 22 * with data parsed from the Properties file. When a connection is established 24 * the ParamicsStatusReader is registered to read Paramics Status updates. 25 * These updates are received through the updateParamicsStatus() method, which26 * notifies the Coordinator of the new status. The loadParamicsNetwork() must27 * becalled to register the ParamicsIncidentWriter which will write the28 * information to cause Paramics to begin loading a traffic network. When the23 * the ParamicsStatusReader is registered to read Paramics Status updates. These 24 * updates are received through the updateParamicsStatus() method, which 25 * notifies the Coordinator of the new status. The loadParamicsNetwork() must be 26 * called to register the ParamicsIncidentWriter which will write the 27 * information to cause Paramics to begin loading a traffic network. When the 29 28 * status becomes LOADED, the ParamicsCameraStatusReader is registered and 30 * begins reading. All camera speed updates are received through the31 * updateCameraInfo() method. The startSimulation(), resetSimulation(), and32 * sendIncidentUpdate() methods are used to control the flow of Incident 33 * update information to Paramics. The updateIncident() and updateDiversion()34 * methodsare used to update the information that is sent to Paramics.35 * 36 * 29 * begins reading. All camera speed updates are received through the 30 * updateCameraInfo() method. The startSimulation(), resetSimulation(), and 31 * sendIncidentUpdate() methods are used to control the flow of Incident update 32 * information to Paramics. The updateIncident() and updateDiversion() methods 33 * are used to update the information that is sent to Paramics. 34 * 35 * 37 36 * @see PARAMICS_STATUS 38 37 * @author Matthew Cechini 39 38 * @version 40 39 */ 41 public class ParamicsSimulationManager { 42 43 /** Error logger. */ 40 public class ParamicsSimulationManager 41 { 42 43 /** 44 * Error logger. 45 */ 44 46 private static Logger paramLogger = Logger.getLogger("tmcsim.cadsimulator.paramicscontrol"); 45 47 46 48 /** 47 49 * Enumeration containing property names for Properties parsing. 50 * 48 51 * @author Matthew Cechini 49 52 */ 50 private static enum PROPERTIES { 51 PARAMICS_HOST ("ParamicsCommHost"), 52 PARAMICS_PORT ("ParamicsCommPort"), 53 INCIDENT_UPDATE_INT ("IncidentUpdateInterval"), 54 INCIDENT_UPDATE_FILE ("IncidentUpdateFile"), 55 PARAMICS_STATUS_INT ("ParamicsStatusInterval"), 56 PARAMICS_STATUS_FILE ("ParamicsStatusFile"), 57 CAMERA_STATUS_INT ("CameraStatusInterval"), 58 CAMERA_STATUS_FILE ("CameraStatusFile"); 59 53 private static enum PROPERTIES 54 { 55 56 PARAMICS_HOST("ParamicsCommHost"), 57 PARAMICS_PORT("ParamicsCommPort"), 58 INCIDENT_UPDATE_INT("IncidentUpdateInterval"), 59 INCIDENT_UPDATE_FILE("IncidentUpdateFile"), 60 PARAMICS_STATUS_INT("ParamicsStatusInterval"), 61 PARAMICS_STATUS_FILE("ParamicsStatusFile"), 62 CAMERA_STATUS_INT("CameraStatusInterval"), 63 CAMERA_STATUS_FILE("CameraStatusFile"); 60 64 String name; 61 62 private PROPERTIES(String n) { 65 66 private PROPERTIES(String n) 67 { 63 68 name = n; 64 69 } 65 70 }; 66 67 /** ParamicsCommunicator Object used for communication. */ 71 /** 72 * ParamicsCommunicator Object used for communication. 73 */ 68 74 private ParamicsCommunicator theCommunicator; 69 70 /** Reference to the Coordinator Object. */ 75 /** 76 * Reference to the Coordinator Object. 77 */ 71 78 private Coordinator theCoordinator; 72 73 /** Reference to the MediaManager Object. */ 79 /** 80 * Reference to the MediaManager Object. 81 */ 74 82 private MediaManager theMediaMgr; 75 76 /** ParamicsIncidentWriter used to send incident updates to Paramics. */ 77 private ParamicsIncidentWriter paramicsIncidentWriter; 78 79 /** ParamicsStatusReader used to read status information from Paramics. */ 83 /** 84 * ParamicsIncidentWriter used to send incident updates to Paramics. 85 */ 86 private ParamicsIncidentWriter paramicsIncidentWriter; 87 /** 88 * ParamicsStatusReader used to read status information from Paramics. 89 */ 80 90 private ParamicsStatusReader paramicsStatusReader; 81 82 /** ParamicsCameraStatusReader used to read speed information from Paramics. */ 91 /** 92 * ParamicsCameraStatusReader used to read speed information from Paramics. 93 */ 83 94 private ParamicsCameraStatusReader paramicsCameraStatusReader; 84 85 /** Properties file. */ 95 /** 96 * Properties file. 97 */ 86 98 private Properties paramicsProperties; 87 88 89 /** 90 * Constructor. Loads the Properties file and initializes all Paramics 99 100 /** 101 * Constructor. Loads the Properties file and initializes all Paramics 91 102 * Writers and Readers with the parsed data. 92 * 103 * 93 104 * @param propertiesFile Target file path of properties file. 94 105 * @param coor Coordinator Object. 95 106 * @param mediaMgr MediaManager Object. 96 107 */ 97 public ParamicsSimulationManager(String propertiesFile, Coordinator coor, MediaManager mediaMgr) { 98 99 try { 108 public ParamicsSimulationManager(String propertiesFile, Coordinator coor, MediaManager mediaMgr) 109 { 110 111 try 112 { 100 113 paramicsProperties = new Properties(); 101 114 paramicsProperties.load(new FileInputStream(propertiesFile)); 102 115 103 116 theCoordinator = coor; 104 theMediaMgr = mediaMgr;105 106 theCommunicator = new ParamicsCommunicator(this, 117 theMediaMgr = mediaMgr; 118 119 theCommunicator = new ParamicsCommunicator(this, 107 120 paramicsProperties.getProperty(PROPERTIES.PARAMICS_HOST.name), 108 121 Integer.parseInt(paramicsProperties.getProperty( 109 PROPERTIES.PARAMICS_PORT.name).trim()));110 122 PROPERTIES.PARAMICS_PORT.name).trim())); 123 111 124 paramicsIncidentWriter = new ParamicsIncidentWriter(Integer.parseInt( 112 paramicsProperties.getProperty(PROPERTIES.INCIDENT_UPDATE_INT.name).trim())); 113 paramicsIncidentWriter.writerID = theCommunicator.nextID();125 paramicsProperties.getProperty(PROPERTIES.INCIDENT_UPDATE_INT.name).trim())); 126 paramicsIncidentWriter.writerID = theCommunicator.nextID(); 114 127 paramicsIncidentWriter.targetFile = paramicsProperties.getProperty( 115 PROPERTIES.INCIDENT_UPDATE_FILE.name); 116 128 PROPERTIES.INCIDENT_UPDATE_FILE.name); 129 117 130 paramicsStatusReader = new ParamicsStatusReader(this); 118 paramicsStatusReader.readerID = theCommunicator.nextID();119 paramicsStatusReader.interval = paramicsProperties.getProperty(131 paramicsStatusReader.readerID = theCommunicator.nextID(); 132 paramicsStatusReader.interval = paramicsProperties.getProperty( 120 133 PROPERTIES.PARAMICS_STATUS_INT.name).trim(); 121 134 paramicsStatusReader.targetFile = paramicsProperties.getProperty( 122 135 PROPERTIES.PARAMICS_STATUS_FILE.name); 123 136 124 137 paramicsCameraStatusReader = new ParamicsCameraStatusReader(this); 125 paramicsCameraStatusReader.readerID = theCommunicator.nextID();126 paramicsCameraStatusReader.interval = paramicsProperties.getProperty(138 paramicsCameraStatusReader.readerID = theCommunicator.nextID(); 139 paramicsCameraStatusReader.interval = paramicsProperties.getProperty( 127 140 PROPERTIES.CAMERA_STATUS_INT.name).trim(); 128 141 paramicsCameraStatusReader.targetFile = paramicsProperties.getProperty( 129 PROPERTIES.CAMERA_STATUS_FILE.name); 130 } 131 catch (Exception e){132 paramLogger.logp(Level.SEVERE, "ParamicsSimulationManager", 142 PROPERTIES.CAMERA_STATUS_FILE.name); 143 } catch (Exception e) 144 { 145 paramLogger.logp(Level.SEVERE, "ParamicsSimulationManager", 133 146 "Constructor", "Exception in parsing properties file.", e); 134 147 } 135 136 } 137 148 149 } 150 138 151 /** 139 152 * Returns whether a connection exists to the remote ParamicsCommunicator. 153 * 140 154 * @return true if a connection exists, false if not. 141 155 */ 142 public boolean isConnected() { 156 public boolean isConnected() 157 { 143 158 return theCommunicator.isConnected(); 144 159 } 145 160 146 161 /** 147 162 * Returns the integer Network ID that has been loaded into Paramics. 163 * 148 164 * @return Network ID. 149 165 */ 150 public int getParamicsNetworkLoaded() { 166 public int getParamicsNetworkLoaded() 167 { 151 168 return paramicsStatusReader.getNetworkID(); 152 169 } 153 170 154 171 /** 155 172 * Returns the current status of the Paramics traffic modeler. 156 * @return Current PARAMICS_STATUS 157 */ 158 public PARAMICS_STATUS getParamicsStatus() { 173 * 174 * @return Current PARAMICS_STATUS 175 */ 176 public PARAMICS_STATUS getParamicsStatus() 177 { 159 178 return paramicsStatusReader.getStatus(); 160 179 } 161 180 162 181 /** 163 182 * Updates the ParamicsIncidentWriter with new Incident information. 183 * 164 184 * @param xmlInc Updated Incident information. 165 185 */ 166 public void updateIncident(XMLIncident xmlInc) { 186 public void updateIncident(XMLIncident xmlInc) 187 { 167 188 paramicsIncidentWriter.updateIncident(xmlInc); 168 189 } 169 190 170 191 /** 171 192 * Updates the ParamicsIncidentWriter with the new Diversion information. 193 * 172 194 * @param theDiversion Updated diversion information. 173 195 */ 174 public void updateDiversion(CMSInfo theDiversion) { 196 public void updateDiversion(CMSInfo theDiversion) 197 { 175 198 paramicsIncidentWriter.updateDiversion(theDiversion); 176 199 } 177 200 178 201 /** 179 202 * Notifies the ParamicsIncidentWriter to start the simulation. 180 203 */ 181 public void startSimulation() { 204 public void startSimulation() 205 { 182 206 paramicsIncidentWriter.startSimulation(); 183 207 } 184 208 185 209 /** 186 210 * Notifies the ParamicsIncidentWriter to reset the simulation. 187 211 */ 188 public void resetSimulation() { 212 public void resetSimulation() 213 { 189 214 paramicsIncidentWriter.resetSimulation(); 190 215 } … … 192 217 /** 193 218 * Notifies the ParamicsIncidentWriter to send an Incident update. 219 * 194 220 * @param currentSimTime Current simulation time (in seconds). 195 221 */ 196 public void sendIncidentUpdate(long currentSimTime) { 222 public void sendIncidentUpdate(long currentSimTime) 223 { 197 224 paramicsIncidentWriter.sendUpdate(currentSimTime); 198 225 } 199 200 /** 201 * Establish a connection to the remote ParamicsCommunicator. Register 202 * the ParamicsStatusReader and update the current status to CONNECTED. 203 * If an exception occurs in connecting to the ParamicsCommunicator, 204 * update the current status to UNREACHABLE. 205 */ 206 public void connectToParamics() { 207 try { 208 theCommunicator.connect(); 226 227 /** 228 * Establish a connection to the remote ParamicsCommunicator. Register the 229 * ParamicsStatusReader and update the current status to CONNECTED. If an 230 * exception occurs in connecting to the ParamicsCommunicator, update the 231 * current status to UNREACHABLE. 232 */ 233 public void connectToParamics() 234 { 235 try 236 { 237 theCommunicator.connect(); 209 238 theCommunicator.registerReader(paramicsStatusReader); 210 239 211 240 updateParamicsStatus(PARAMICS_STATUS.CONNECTED); 212 } 213 catch (IOException ioe){214 paramLogger.logp(Level.SEVERE, "Coordinator", "connectToParamics", 241 } catch (IOException ioe) 242 { 243 paramLogger.logp(Level.SEVERE, "Coordinator", "connectToParamics", 215 244 "Communication error in connecting to Paramics.", ioe); 216 245 217 246 updateParamicsStatus(PARAMICS_STATUS.UNREACHABLE); 218 } 219 } 220 221 /** 222 * Close the connection to the remote ParamicsCommunicator. Unregister223 * all Readers and Wrtiers from the ParamicsCommunicator.Reset the status224 * information in the ParamicsStatusReader. Update the current status to247 } 248 } 249 250 /** 251 * Close the connection to the remote ParamicsCommunicator. Unregister all 252 * Readers and Wrtiers from the ParamicsCommunicator. Reset the status 253 * information in the ParamicsStatusReader. Update the current status to 225 254 * DISCONNECTED. 226 255 */ 227 public void disconnectFromParamics() { 228 256 public void disconnectFromParamics() 257 { 258 229 259 theCommunicator.disconnect(); 230 260 theCommunicator.unregisterReader(paramicsStatusReader); 231 theCommunicator.unregisterWriter(paramicsIncidentWriter); 261 theCommunicator.unregisterWriter(paramicsIncidentWriter); 232 262 theCommunicator.unregisterReader(paramicsCameraStatusReader); 233 263 234 264 paramicsStatusReader.resetStatusInfo(); 235 265 236 266 updateParamicsStatus(PARAMICS_STATUS.DISCONNECTED); 237 267 } 238 239 /** 240 * Updates the current paramics status. If the new status is LOADED,241 * then notify the ParamicsIncidentWriter that the network has been loaded242 * andregister the ParamicsCameraStatusReader with the ParamicsCommunicator.268 269 /** 270 * Updates the current paramics status. If the new status is LOADED, then 271 * notify the ParamicsIncidentWriter that the network has been loaded and 272 * register the ParamicsCameraStatusReader with the ParamicsCommunicator. 243 273 * Notify the Coordinator of all Paramics status updates. 244 274 * 245 * @param newStatus New Paramics status. 246 */ 247 public void updateParamicsStatus(PARAMICS_STATUS newStatus) { 248 275 * @param newStatus New Paramics status. 276 */ 277 public void updateParamicsStatus(PARAMICS_STATUS newStatus) 278 { 279 249 280 //the network has finished loading 250 if(newStatus == PARAMICS_STATUS.LOADED) { 251 281 if (newStatus == PARAMICS_STATUS.LOADED) 282 { 283 252 284 paramicsIncidentWriter.networkLoaded(); 253 254 theCommunicator.registerReader(paramicsCameraStatusReader); 255 } 256 else if(newStatus == PARAMICS_STATUS.DROPPED) { 257 paramLogger.logp(Level.WARNING, "Coordinator", "updateParamicsStatus", 285 286 theCommunicator.registerReader(paramicsCameraStatusReader); 287 288 } else if (newStatus == PARAMICS_STATUS.DROPPED) 289 { 290 paramLogger.logp(Level.WARNING, "Coordinator", "updateParamicsStatus", 258 291 "Connection to Paramics has been dropped."); 259 }else 260 { 261 paramLogger.logp(Level.INFO, "ParamicsSimulationManager", "updateParamicsStatus", 262 "Received: " + newStatus); 263 } 264 265 theCoordinator.setParamicsStatus(newStatus); 266 267 } 268 269 /** 270 * If a connection has been made, register the ParamicsIncidentWriter 271 * and use it to notify Paramics of the Network ID to load. 272 * 292 } 293 294 theCoordinator.setParamicsStatus(newStatus); 295 296 } 297 298 /** 299 * If a connection has been made, register the ParamicsIncidentWriter and 300 * use it to notify Paramics of the Network ID to load. 301 * 273 302 * @param networkID Network ID to load. 274 * @throws SimulationException if a connection has not been made to the 275 * remote ParamicsCommunicator. 276 */ 277 public void loadParamicsNetwork(int networkID) throws SimulationException { 278 279 if(theCommunicator.isConnected()) { 303 * @throws SimulationException if a connection has not been made to the 304 * remote ParamicsCommunicator. 305 */ 306 public void loadParamicsNetwork(int networkID) throws SimulationException 307 { 308 309 if (theCommunicator.isConnected()) 310 { 280 311 theCommunicator.registerWriter(paramicsIncidentWriter); 281 312 paramicsIncidentWriter.loadNetwork(networkID); 282 } 283 else313 } else 314 { 284 315 throw new SimulationException(SimulationException.PARAMICS_NOT_CONNECTED); 285 } 286 287 /** 288 * Receive updated camera speed information. Notify the MediaManager with 289 * the updated data. 290 * 316 } 317 } 318 319 /** 320 * Receive updated camera speed information. Notify the MediaManager with 321 * the updated data. 322 * 291 323 * @param cameraID CCTV camera ID 292 324 * @param avgSpeed_NE Average speed of traffic flowing N or E 293 325 * @param avgSpeed_SW Average speed of traffic flowing S or W 294 326 */ 295 public void updateCameraInfo(Integer cameraID, float avgSpeed_NE, float avgSpeed_SW) { 327 public void updateCameraInfo(Integer cameraID, float avgSpeed_NE, float avgSpeed_SW) 328 { 296 329 theMediaMgr.updateCameraInfo(cameraID, avgSpeed_NE, avgSpeed_SW); 297 330 }
Note: See TracChangeset
for help on using the changeset viewer.
