Changeset 84 in tmcsimulator
- Timestamp:
- 10/06/2017 11:44:52 PM (9 years ago)
- Files:
-
- 16 edited
- 1 moved
-
branches/FEPSimulator/FEPSim.cpp (modified) (13 diffs)
-
branches/FEPSimulator/FEPSim.h (modified) (1 diff)
-
branches/FEPSimulator/NetworkReader.cpp (modified) (3 diffs)
-
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/built-jar.properties (modified) (1 diff)
-
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/atmsdriver/ATMSDriver$PROPERTIES.class (modified) (previous)
-
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/atmsdriver/ATMSDriver.class (modified) (previous)
-
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/atmsdriver/model/HighwayStatusWriter.class (modified) (previous)
-
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/tmcsim/application.properties (modified) (1 diff)
-
branches/trunk/IDE_metadata/NetBeans/TMCSim/dist/TMCSim.jar (modified) (previous)
-
branches/trunk/src/atmsdriver/ATMSDriver.java (modified) (1 diff)
-
branches/trunk/src/atmsdriver/NetworkLoader.java (modified) (1 diff)
-
branches/trunk/src/atmsdriver/model/HighwayStatusWriter.java (modified) (1 diff)
-
branches/trunk/src/tmcsim/application.properties (modified) (1 diff)
-
trunk/config/atms_driver_config.properties (modified) (1 diff)
-
trunk/src/atmsdriver/NetworkLoader.java (modified) (7 diffs)
-
trunk/src/atmsdriver/model/FEPLine.java (modified) (3 diffs)
-
trunk/src/atmsdriver/model/Station.java (moved) (moved from trunk/src/atmsdriver/model/LoopDetectorStation.java) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/FEPSimulator/FEPSim.cpp
r82 r84 7 7 * @param networkFile the xml network file 8 8 */ 9 FEPSim::FEPSim(char * ATMShost, char * xml) { 10 networkReader = new NetworkReader(xml); 9 FEPSim::FEPSim(char * ATMShost) { 11 10 this->ATMSHost = ATMShost; 12 updateATMS();13 11 } 14 12 … … 26 24 */ 27 25 void FEPSim::handleCallResponse(void *response) { 28 / * If ATMS reply call fails */26 // Failed RPC Call 29 27 if (response == NULL) { 30 28 clnt_perror(clnt, "RPC call failed"); 31 }/* If ATMS reply is successful */ 29 } 30 // Successful RPC Call 32 31 else { 33 32 cout << "Successful RPC call to ATMS..." << endl; … … 35 34 } 36 35 37 /** 38 * Sends an fep_reply for every line in the FEP. 39 */ 40 void FEPSim::updateATMS() { 41 int i, j; // i == line_index, j == lds_index 42 void *rv; 43 vector<FEP_LINE*> lines = networkReader->getLines(); 44 vector<STATION*> ldsMap = networkReader->getStations(); 45 46 // Send one reply for every "line" in the FEP 47 for (i = 0; i < lines.size(); i++) { 36 void FEPSim::sendReplys(char * xml) 37 { 38 NetworkReader networkReader = NetworkReader(xml); 39 vector<FEP_LINE*> lines = networkReader.getLines(); 40 vector<STATION*> ldsMap = networkReader.getStations(); 41 42 // Send one reply for every FEPLine 43 for (int i = 0; i < lines.size(); i++) { 48 44 fep_reply fepReply; 49 45 cout << "Sending fepReply for line #" << lines.at(i)->lineNum << endl; … … 56 52 57 53 /*********************************** 58 This is an update to an extern, this should happen on the Java driver side?? 54 * We might need to handle this on the java side if its an 55 * issue 59 56 lines.at(i).schedleSeq += 1; 60 57 lines.at(i).globalSeq += 51; … … 63 60 fepReply.schedule_sequence = lines.at(i)->schedleSeq; 64 61 fepReply.global_sequence = lines.at(i)->globalSeq; 65 /************************************ 66 Need to find out what appropriate schedule time is: look at uci_unix_simulation_time src code 67 fepReply.schedule_time = 68 uci_unix_simulation_time(uci_simulation_time()); // GMT time 69 */ 62 63 // using current unix time, may need to look at later 70 64 fepReply.schedule_time = time(NULL); 71 65 … … 77 71 fepReply.answers.fep_answer_list_u.shortp.count = 1; 78 72 79 / * for each LDS in the Line.... (constructs the short_answer message) */80 for ( j = 0; j < lines.at(i)->lds.size(); j++) {73 // construct a shortanswer for each station in line 74 for (int j = 0; j < lines.at(i)->lds.size(); j++) { 81 75 fep_shortanswer fsa; 82 76 int index = lines.at(i)->ldsIndex.at(j); … … 90 84 int aa = ldsMap.at(index)->length; 91 85 fsa.msg.message[2 + aa] = 0x0d; 92 fsa.msg.message[3 + aa] = 0xff; //????????????? warning ?????86 fsa.msg.message[3 + aa] = 0xff; 93 87 94 88 // info 95 89 fsa.info.poll_error_count = 0; 96 /***************************************97 Need to find out polltime uci time function src code98 fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time());99 */100 90 fsa.info.poll_user_info1 = ldsMap.at(index)->drop; // drop number 101 91 fsa.info.poll_user_info2 = 1; //always 1 … … 103 93 fsa.info.status = (enum replystatus) 1; 104 94 105 //fepReply.answers.fep_answer_list_u.shortp.answers[j +1] = fsa;106 95 fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa; 107 96 108 97 // send out data 109 98 printf("Transferring line=%d, lds_drop_no=%d...\n", lines.at(i)->lineNum, ldsMap.at(index)->drop); 110 rv = fep_reply_xfer_32(&fepReply, clnt); 111 112 /* Handle ATMS response to RPC Call */ 99 // Make RPC Call and handle response 113 100 printf("Handling ATMS response...\n"); 114 handleCallResponse(rv); 115 } 101 handleCallResponse(fep_reply_xfer_32(&fepReply, clnt)); 102 } 103 } 104 } 105 106 /** 107 * Sends an fep_reply for every line in the FEP. 108 */ 109 void FEPSim::updateATMS(char * xml) { 110 if(createClient(this->ATMSHost)) 111 { 112 sendReplys(xml); 116 113 } 117 114 } … … 121 118 * @param host rpc server ip 122 119 */ 123 voidFEPSim::createClient(char * host) {120 bool FEPSim::createClient(char * host) { 124 121 /* Create RPC Client to communicate with ATMS */ 122 bool success = true; 125 123 cout << "Creating RPC Client" << endl; 126 124 clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp"); 127 cout << "Client created" << endl;128 125 /* Check if client creation failed */ 129 126 if (clnt == (CLIENT *) NULL) { 130 127 cerr << "Can't create client to " << host << endl; 131 exit(1); 132 } 128 success = false; 129 } 130 else { 131 cout << "Client created" << endl; 132 } 133 return success; 133 134 } 134 135 … … 140 141 */ 141 142 int main(int argc, char *argv[]) { 142 143 if(argc != 3) 144 { 145 cerr << "Usage: FEPSim <ATMS_Host> <FEP_ATMSDriver_PortNo" << endl; 146 exit(1); 147 } 148 char *FEPSimHost = argv[1]; 149 FEPSim fep = FEPSim(FEPSimHost); 150 143 151 int sockfd, newsockfd, portno, clilen; 144 152 char buffer[BUFF_SIZE]; 145 153 struct sockaddr_in serv_addr, cli_addr; 146 154 int n; 147 148 char *FEPSimHost = argv[1];149 155 portno = atoi(argv[2]); 150 156 … … 177 183 clilen = sizeof (cli_addr); 178 184 179 /* Accept actual connection from the client */185 /* Accept actual connections from the client */ 180 186 while(1) { 181 187 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen); … … 187 193 188 194 /* If connection is established then start communicating */ 195 // zero out buffer 189 196 bzero(buffer, BUFF_SIZE); 190 197 191 // NEEDS OUTER LOOP TO GET WHOLE MESSAGE FROM TCP CONN 192 n = read(newsockfd, buffer, sizeof(buffer)); 193 198 // read XML from socket 199 int totBytes = 0; 200 while ((n = recv(newsockfd, &buffer[totBytes], sizeof(buffer), 0)) > 0) { 201 totBytes += n; 202 } 203 194 204 if (n < 0) { 195 205 perror("ERROR reading from socket"); … … 197 207 } 198 208 199 /* Create RPC Client to send an fep_reply to ATMS */ 200 201 FEPSim *client = new FEPSim(FEPSimHost, buffer); 202 delete client; 209 // send data to atms 210 fep.updateATMS(buffer); 203 211 } 204 212 -
branches/FEPSimulator/FEPSim.h
r82 r84 40 40 const int BUFF_SIZE = 1000000; 41 41 42 class FEPSim 43 { 44 public: 45 /* members */ 46 CLIENT *clnt; // RPC Client 42 class FEPSim { 43 public: 44 /* members */ 45 CLIENT *clnt; // RPC Client 47 46 48 /* methods */ 49 FEPSim(char * host, char * networkFile); // Constructor 50 ~FEPSim(); // Destructor 47 /* methods */ 48 FEPSim(char * ATMSHost); // Constructor 49 50 void updateATMS(char * xml); // updates ATMS 51 51 52 private: 53 /* members */ 54 NetworkReader *networkReader; 55 char * ATMSHost; 56 57 /* methods */ 58 void handleCallResponse(void *response); // 59 void createClient(char *host); 60 void updateATMS(); // updates ATMS 52 ~FEPSim(); // Destructor 53 54 private: 55 /* members */ 56 char * ATMSHost; 57 58 /* methods */ 59 void handleCallResponse(void *response); // 60 bool createClient(char *host); 61 void sendReplys(char * xml); 61 62 62 63 }; -
branches/FEPSimulator/NetworkReader.cpp
r82 r84 15 15 TiXmlElement *subLoopElem = loopElem->FirstChildElement(); 16 16 loop->loopID = atoi(subLoopElem->GetText()); 17 cout << "LOOPID: " << subLoopElem->GetText() << endl;18 17 subLoopElem = subLoopElem->NextSiblingElement(); 19 18 loop->loop_loc = (char *) subLoopElem->GetText(); … … 40 39 TiXmlElement *stationSubElem = stationElem->FirstChildElement(); 41 40 station->lds = atol(stationSubElem->GetText()); 41 cout << "Station: " << station->lds << endl; 42 42 line->lds.push_back(station->lds); 43 43 line->ldsIndex.push_back(ldsIndex++); … … 63 63 station->loops.push_back(loop); 64 64 } 65 65 cout << "Number of Loops: " << station->loops.size() << endl; 66 66 // Data pack ATMS message 67 67 station->length = station->loops.size() * 2 + CONTROL_DATA_LEN; -
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/built-jar.properties
r82 r84 1 # Fri, 06 Oct 2017 19:49:49-07001 #Sat, 07 Oct 2017 00:43:14 -0700 2 2 3 3 -
branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/tmcsim/application.properties
r82 r84 1 # Fri, 06 Oct 2017 19:49:49-07001 #Sat, 07 Oct 2017 00:43:14 -0700 2 2 3 Application.revision= 03 Application.revision=83 4 4 5 Application.buildnumber=5 05 Application.buildnumber=58 -
branches/trunk/src/atmsdriver/ATMSDriver.java
r83 r84 53 53 54 54 /** Sleep Time (10 seconds). **/ 55 private static final int SLEEP_TIME = 10000;55 private static final int SLEEP_TIME = 30000; 56 56 57 57 /** Exchange Reader */ -
branches/trunk/src/atmsdriver/NetworkLoader.java
r82 r84 143 143 private void constructFEPLines() 144 144 { 145 try { 146 System.out.println("Building network..."); 147 145 try { 148 146 // Get FEPLine IDs 149 147 ArrayList<Integer> lineNums = getLineNums(new Scanner(LDSFile)); -
branches/trunk/src/atmsdriver/model/HighwayStatusWriter.java
r82 r84 31 31 Socket sock = new Socket(host, port); 32 32 PrintWriter out = new PrintWriter(sock.getOutputStream(), true); 33 out.print (xml);33 out.println(xml); 34 34 sock.close(); 35 35 } -
branches/trunk/src/tmcsim/application.properties
r82 r84 1 # Fri, 06 Oct 2017 19:49:49-07001 #Sat, 07 Oct 2017 00:43:14 -0700 2 2 3 Application.revision= 03 Application.revision=83 4 4 5 Application.buildnumber=5 05 Application.buildnumber=58 -
trunk/config/atms_driver_config.properties
r79 r84 3 3 NetworkFileName = networkFile.txt 4 4 ExchangeFileName = exchange.xml 5 FEPWriterHost = localhost 6 FEPWriterPort = 8080 -
trunk/src/atmsdriver/NetworkLoader.java
r79 r84 2 2 3 3 import atmsdriver.model.FEPLine; 4 import atmsdriver.model. LoopDetectorStation;4 import atmsdriver.model.Station; 5 5 import atmsdriver.model.LoopDetector; 6 import atmsdriver.model. LoopDetectorStation.DIRECTION;6 import atmsdriver.model.Station.DIRECTION; 7 7 import java.io.File; 8 8 import java.io.FileNotFoundException; … … 17 17 * 18 18 * The public method getFEPLines() method can be used to get all the FEPLines 19 *within a network. All other methods are private and are used to construct20 *the FEPLines.21 *22 * The "LDSFile" contains LoopDetectorStation and FEPLine information.23 *ex.24 *< Insert file here >19 within a network. All other methods are private and are used to construct 20 the FEPLines. 21 22 The "LDSFile" contains Station and FEPLine information. 23 ex. 24 < Insert file here > 25 25 * The "loopFile" contains individual LoopDetector information. 26 26 * ex. … … 157 157 158 158 // Create each Station for the current FEPLine 159 ArrayList< LoopDetectorStation> stns = new ArrayList<>();159 ArrayList<Station> stns = new ArrayList<>(); 160 160 for(Integer stnNum : stnNums) 161 161 { … … 165 165 166 166 // Create the Station and add to list for curr FEPLine 167 LoopDetectorStation stn =167 Station stn = 168 168 createStation(stnNum, new Scanner(LDSFile), loops); 169 169 stns.add(stn); … … 181 181 182 182 // Creates line 183 private FEPLine createLine(int lineNum, Scanner scLine, ArrayList< LoopDetectorStation> stns)183 private FEPLine createLine(int lineNum, Scanner scLine, ArrayList<Station> stns) 184 184 { 185 185 FEPLine line = null; … … 239 239 240 240 // creates a Station 241 private LoopDetectorStation createStation(int stnNum, Scanner sc, ArrayList<LoopDetector> detectors)242 { 243 LoopDetectorStation LDS = null;241 private Station createStation(int stnNum, Scanner sc, ArrayList<LoopDetector> detectors) 242 { 243 Station LDS = null; 244 244 245 245 sc.nextLine(); … … 264 264 double postmile = scLine.nextDouble(); 265 265 String ldsName = getLocation(strLine); /************* DOESNT GRAB WHOLE???? *///// 266 LDS = new LoopDetectorStation(lineNum, ldsID, drop, ldsName, detectors, fwy, dir, postmile);266 LDS = new Station(lineNum, ldsID, drop, ldsName, detectors, fwy, dir, postmile); 267 267 268 268 break; -
trunk/src/atmsdriver/model/FEPLine.java
r79 r84 19 19 /* Static FEPLine meta data */ 20 20 final private int lineNum; 21 final private List< LoopDetectorStation> stations;21 final private List<Station> stations; 22 22 final private int count; 23 23 // NOT SURE IF NEXT IS FINAL … … 28 28 final private long scheduleSeq; 29 29 30 public FEPLine(int lineNum, List< LoopDetectorStation> stations, int count,30 public FEPLine(int lineNum, List<Station> stations, int count, 31 31 int schedule, int lineInfo, long systemKey, long globalSeq, 32 32 long scheduleSeq) … … 79 79 Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag); 80 80 lineElement.appendChild(stationsElement); 81 for( LoopDetectorStation station : stations)81 for(Station station : stations) 82 82 { 83 83 station.toXML(stationsElement); -
trunk/src/atmsdriver/model/Station.java
r79 r84 5 5 import org.w3c.dom.Element; 6 6 7 /** A LoopDetectorStation is a simulation of a station in a traffic network.7 /** A Station is a simulation of a station in a traffic network. 8 8 * 9 * A LoopDetectorStation (LDS) contains static meta data about the station, and10 *two dynamic attributes, MLTotVol and OppTotVol.11 *12 *A single LDS contains multiple LoopDetectors, which13 *contain data for a single lane on one direction of the freeway. A LDS14 *is specific to a single freeway, direction, and postmile.9 * A Station (LDS) contains static meta data about the station, and 10 two dynamic attributes, MLTotVol and OppTotVol. 11 12 A single LDS contains multiple LoopDetectors, which 13 contain data for a single lane on one direction of the freeway. A LDS 14 is specific to a single freeway, direction, and postmile. 15 15 * 16 16 * @author John A. Torres 17 17 * @version 9/10/2017 18 18 */ 19 public class LoopDetectorStation{20 /* Static LoopDetectorStation meta data */19 public class Station implements Comparable { 20 /* Static Station meta data */ 21 21 final private int lineNum; 22 22 final private int ldsID; // double check … … 28 28 final private DIRECTION direction; 29 29 30 /* Dynamic LoopDetectorStation data */30 /* Dynamic Station data */ 31 31 private int MLTotVol; 32 32 private int OppTotVol; 33 33 34 34 /* Constructor */ 35 public LoopDetectorStation(int lineNum, int ldsID, int drop,35 public Station(int lineNum, int ldsID, int drop, 36 36 String location, List<LoopDetector> loops, int fwy, 37 37 DIRECTION direction, double postmile) … … 48 48 this.MLTotVol = 0; 49 49 this.OppTotVol = 0; 50 } 51 52 @Override 53 public int compareTo(Object o) { 54 50 55 } 51 56
Note: See TracChangeset
for help on using the changeset viewer.
