Warning: Can't use blame annotator:
svn blame failed on trunk/src/atmsdriver/model/LoopDetector.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/atmsdriver/model/LoopDetector.java @ 118

Revision 118, 3.6 KB checked in by jtorres, 9 years ago (diff)

Highways.java: hardcoded ip to JD's laptop in writeToFep(). LoopDetector?.java: currently hardcoded 'red' values in constructor. application.properties added the console driver custom config. Added trunk/config/console_driver_config.properties

RevLine 
1package atmsdriver.model;
2
3import java.util.ArrayList;
4import java.util.List;
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7
8/** A LoopDetector represents a single detector for a single lane in a network.
9 *
10 *  A LoopDetector contains static meta data, and three dynamic attributes: vol,
11 *  occ, and spd.
12 *
13 * @author John A. Torres
14 * @version 09/10/2017
15 */
16public class LoopDetector 
17{
18    /* static data */
19    final public int loopID;
20    final public String loopLocation;
21    final public int laneNum;
22   
23    /* dynamic data */
24    public int vol;
25    public int occ;
26    private int spd;
27   
28    public LoopDetector(int loopID, String loopLocation, int laneNum)
29    {
30        /* Set static data */
31        this.loopID = loopID;
32        this.loopLocation = loopLocation;
33        this.laneNum = laneNum;
34       
35        /* Init dynamic data */
36        this.vol = 0;
37        this.spd = 0;
38        this.occ = 0;
39    }
40   
41    private static enum XML_TAGS
42    {
43        LOOP_ID("Loop_ID"),
44        LOOP_LOCATION("Loop_Location"),
45        LANE_NUM("Lane_Num"),
46        VOL("Vol"),
47        SPD("Spd"),
48        OCC("Occ"),
49        LOOP("Loop");
50       
51        String tag;
52       
53        private XML_TAGS(String n)
54        {
55            tag = n;
56        }
57    }
58   
59    /**
60     * Returns the loop metadata in condensed form.
61     * This is just a quick script function to make a proper highway
62     * metadata configuration file, so that we can read the network
63     * faster.
64     *
65     * @return loop metadata
66     */
67    public String getLoopMeta()
68    {
69        StringBuilder build = new StringBuilder();
70        build.append(Integer.toString(this.loopID));
71        build.append(" ");
72        build.append(Integer.toString(this.laneNum));
73        build.append(" ");
74        build.append(this.loopLocation);
75        build.append("\n");
76        return build.toString();
77    }
78   
79    /**
80     * Updates loop detector dynamic attributes.
81     * @param vol volume
82     * @param occ occupancy
83     * @param spd speed
84     */
85    public void updateLoop(int vol, int occ, int spd)
86    {
87        this.vol = vol;
88        this.occ = occ;
89        this.spd = spd;
90    }
91   
92    public void toXML(Element currElem)
93    {
94        Document theDoc = currElem.getOwnerDocument();
95       
96        Element loopElement = theDoc.createElement(XML_TAGS.LOOP.tag);
97        currElem.appendChild(loopElement);
98       
99        Element loopIDElement = theDoc.createElement(XML_TAGS.LOOP_ID.tag);
100        loopIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.loopID)));
101        loopElement.appendChild(loopIDElement);
102       
103        Element loopLocElement = theDoc.createElement(XML_TAGS.LOOP_LOCATION.tag);
104        loopLocElement.appendChild(theDoc.createTextNode(this.loopLocation));
105        loopElement.appendChild(loopLocElement);
106       
107        Element laneNumElement = theDoc.createElement(XML_TAGS.LANE_NUM.tag);
108        laneNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.laneNum)));
109        loopElement.appendChild(laneNumElement);
110       
111        Element volElement = theDoc.createElement(XML_TAGS.VOL.tag);
112        volElement.appendChild(theDoc.createTextNode(String.valueOf(this.vol)));
113        loopElement.appendChild(volElement);
114       
115        Element occElement = theDoc.createElement(XML_TAGS.OCC.tag);
116        occElement.appendChild(theDoc.createTextNode(String.valueOf(this.occ)));
117        loopElement.appendChild(occElement);
118       
119        Element spdElement = theDoc.createElement(XML_TAGS.SPD.tag);
120        spdElement.appendChild(theDoc.createTextNode(String.valueOf(this.spd)));
121        loopElement.appendChild(spdElement);
122    }
123}
Note: See TracBrowser for help on using the repository browser.