Changeset 79 in tmcsimulator for trunk/src


Ignore:
Timestamp:
10/05/2017 12:51:23 PM (9 years ago)
Author:
jtorres
Message:

new atmsdriver package in trunk. fep_rpc_client dynamic data packing added in branches. fep_rpc_client refactored data packing code into static DataPacker? class. Added vds_data folder into config/. Added new project configuration for ATMSDriver.

Location:
trunk/src
Files:
4 added
1 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/ATMSDriver.java

    r77 r79  
    11package atmsdriver; 
    22 
    3 import atmsdriver.network.model.Network; 
     3import atmsdriver.model.Network; 
    44import java.io.File; 
     5import java.io.FileInputStream; 
     6import java.util.Properties; 
    57import java.util.logging.Level; 
    68import java.util.logging.Logger; 
    79 
    8 /**  
     10/** 
    911 * 
    1012 * @author John A. Torres 
    1113 * @version 09/10/2017 
    1214 */ 
    13 public class ATMSDriver { 
    14     final private String ldsFileName = "./lds_data/lookup_lds"; 
    15     final private String loopFileName = "./lds_data/lookup_loop"; 
    16     final private String networkFileName = "./networkFile.txt"; 
     15public class ATMSDriver implements Runnable { 
     16 
     17    /** ATMSDriver Error logger. */ 
     18    private static Logger ATMSDriverLogger = Logger.getLogger("atmsdriver"); 
     19 
     20    private static final String CONFIG_FILE_NAME = "atms_driver_config.properties"; 
     21 
     22    /** Properties object for the CADClient class. */ 
     23    private Properties ATMSDriverProperties; 
     24 
     25    /** 
     26     * Enumeration containing properties name values. See ATMSDriver class 
     27     * description for more information. 
     28     * 
     29     * @author John Torres 
     30     * @see ATMSDriver 
     31     */ 
     32    private static enum PROPERTIES { 
     33 
     34        LDS_FILE_NAME("LDSFileName"), 
     35        LOOP_FILE_NAME("LoopFileName"), 
     36        NETWORK_FILE_NAME("NetworkFileName"), 
     37        EXCHANGE_FILE_NAME("ExchangeFileName"); 
     38 
     39        public String name; 
     40 
     41        private PROPERTIES(String n) { 
     42            name = n; 
     43        } 
     44    } 
     45 
     46    /** Network model. */ 
    1747    final private Network network; 
    1848     
    19     public ATMSDriver() 
    20     { 
    21         File ldsFile = new File(ldsFileName); 
    22         File loopFile = new File(loopFileName); 
    23         File networkFile = new File(networkFileName); 
    24         network = new Network(ldsFile, loopFile, networkFile); 
    25         try { 
     49    /** Sleep Time (10 seconds). **/ 
     50    private static final int SLEEP_TIME = 10000; 
     51     
     52    /** Exchange Reader */ 
     53    private ExchangeReader exchangeReader; 
     54     
     55    @Override 
     56    public void run() { 
     57        // Check for packets and update the simulator 
     58        for (;;) { 
     59            // Flush the input file 
     60            ExchangeInfo exInfo = exchangeReader.parse(ATMSDriverProperties 
     61                    .getProperty(PROPERTIES.EXCHANGE_FILE_NAME.name)); 
    2662            network.toXML(); 
    27         } catch (Exception ex) { 
    28             Logger.getLogger(ATMSDriver.class.getName()).log(Level.SEVERE, null, ex); 
     63            // Update if packet is recieved 
     64            if (exInfo != null) { 
     65                System.out.println("Grabbed"); 
     66            } 
     67 
     68            // Sleep 
     69            try { 
     70                Thread.sleep(SLEEP_TIME); 
     71            } catch (InterruptedException ie) { 
     72                 
     73            } 
    2974        } 
    3075    } 
    31      
     76 
     77    public ATMSDriver(String propertiesFile) { 
     78 
     79        if (!verifyProperties(propertiesFile)) { 
     80            System.exit(0); 
     81        } 
     82 
     83        network = new Network( 
     84                new File(ATMSDriverProperties.getProperty( 
     85                                PROPERTIES.LDS_FILE_NAME.name)), 
     86                new File(ATMSDriverProperties.getProperty( 
     87                                PROPERTIES.LOOP_FILE_NAME.name)), 
     88                new File(ATMSDriverProperties.getProperty( 
     89                                PROPERTIES.NETWORK_FILE_NAME.name))); 
     90        network.toXML(); 
     91        exchangeReader = new ExchangeReader(); 
     92    } 
     93 
     94    private boolean verifyProperties(String propertiesFile) { 
     95        // Load the properties file. 
     96        try { 
     97            ATMSDriverProperties = new Properties(); 
     98            ATMSDriverProperties.load(new FileInputStream(propertiesFile)); 
     99        } catch (Exception e) { 
     100            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", 
     101                    "Constructor", "Exception in reading properties file.", e); 
     102        } 
     103 
     104        return true; 
     105    } 
     106 
    32107    /** 
    33      * @param args the command line arguments 
     108     * Runs the Paramics simulator. 
    34109     */ 
    35110    public static void main(String[] args) { 
    36         ATMSDriver driver = new ATMSDriver(); 
     111        try { 
     112            if (System.getProperty("ATMSDRIVER_PROPERTIES") != null) { 
     113                new Thread(new ATMSDriver(System.getProperty( 
     114                        "ATMSDRIVER_PROPERTIES"))).start(); 
     115            } else { 
     116                throw new Exception("ATMSDRIVER_PROPERTIES system property not defined."); 
     117            } 
     118        } catch (Exception e) { 
     119            ATMSDriverLogger.logp(Level.SEVERE, "ATMSDriver", "Main", 
     120                    "Error occured initializing application", e); 
     121            System.exit(-1); 
     122        } 
    37123    } 
    38      
    39124} 
  • trunk/src/atmsdriver/NetworkLoader.java

    r77 r79  
    11package atmsdriver; 
    22 
    3 import atmsdriver.network.model.FEPLine; 
    4 import atmsdriver.network.model.LoopDetectorStation; 
    5 import atmsdriver.network.model.LoopDetector; 
    6 import atmsdriver.network.model.LoopDetectorStation.DIRECTION; 
     3import atmsdriver.model.FEPLine; 
     4import atmsdriver.model.LoopDetectorStation; 
     5import atmsdriver.model.LoopDetector; 
     6import atmsdriver.model.LoopDetectorStation.DIRECTION; 
    77import java.io.File; 
    88import java.io.FileNotFoundException; 
     
    3030 * @version 09/10/2017 
    3131 */ 
    32 public class NetworkReader { 
     32public class NetworkLoader { 
    3333    // Two network config files 
    3434    private final File LDSFile; 
     
    4343     * @param loopFile contains individual LoopDetector static data 
    4444     */ 
    45     public NetworkReader(File LDSFile, File loopFile) 
     45    public NetworkLoader(File LDSFile, File loopFile) 
    4646    { 
    4747        this.LDSFile = LDSFile; 
     
    176176            } 
    177177        } catch (FileNotFoundException ex) { 
    178             Logger.getLogger(NetworkReader.class.getName()).log(Level.SEVERE, null, ex); 
     178            Logger.getLogger(NetworkLoader.class.getName()).log(Level.SEVERE, null, ex); 
    179179        } 
    180180    } 
  • trunk/src/atmsdriver/model/FEPLine.java

    r77 r79  
    1 package atmsdriver.network.model; 
     1package atmsdriver.model; 
    22 
    33import java.util.List; 
  • trunk/src/atmsdriver/model/LoopDetector.java

    r77 r79  
    1 package atmsdriver.network.model; 
     1package atmsdriver.model; 
    22 
    33import java.util.ArrayList; 
  • trunk/src/atmsdriver/model/LoopDetectorStation.java

    r77 r79  
    1 package atmsdriver.network.model; 
     1package atmsdriver.model; 
    22 
    33import java.util.List; 
  • trunk/src/atmsdriver/model/Network.java

    r77 r79  
    1 package atmsdriver.network.model; 
     1package atmsdriver.model; 
    22 
    3 import atmsdriver.NetworkReader; 
     3import atmsdriver.NetworkLoader; 
    44import java.io.File; 
    55import java.io.FileWriter; 
     6import java.io.IOException; 
    67import java.io.StringWriter; 
    78import java.io.Writer; 
     
    1415import javax.xml.transform.OutputKeys; 
    1516import javax.xml.transform.Transformer; 
     17import javax.xml.transform.TransformerConfigurationException; 
     18import javax.xml.transform.TransformerException; 
    1619import javax.xml.transform.TransformerFactory; 
    1720import javax.xml.transform.dom.DOMSource; 
     
    3134    { 
    3235        lines = (ArrayList<FEPLine>)  
    33                 new NetworkReader(LDSFile, loopFile).getFEPLines(); 
     36                new NetworkLoader(LDSFile, loopFile).getFEPLines(); 
    3437        this.networkFile = networkFile; 
    3538    } 
    3639     
    37     public void toXML() throws Exception 
     40    public void toXML() 
    3841    { 
    3942        try { 
     
    6669             
    6770             
    68         } catch (ParserConfigurationException ex) { 
     71        } catch (Exception ex) { 
    6972            Logger.getLogger(Network.class.getName()).log(Level.SEVERE, null, ex); 
    7073        } 
  • trunk/src/tmcsim/application.properties

    r66 r79  
    1 #Thu, 16 Mar 2017 12:41:52 -0700 
     1#Thu, 05 Oct 2017 10:44:21 -0700 
    22 
    3 Application.revision=65 
     3Application.revision=67 
    44 
    55Application.buildnumber=46 
Note: See TracChangeset for help on using the changeset viewer.