Changeset 86 in tmcsimulator for branches/FEPSimulator
- Timestamp:
- 10/09/2017 11:58:19 PM (9 years ago)
- Location:
- branches/FEPSimulator
- Files:
-
- 10 added
- 7 edited
-
FEPSim.cpp (modified) (6 diffs)
-
FEPSim.h (modified) (3 diffs)
-
Main.cpp (added)
-
NetworkReader.cpp (modified) (7 diffs)
-
NetworkReader.h (modified) (1 diff)
-
build/Debug/GNU-MacOSX (added)
-
build/Debug/GNU-MacOSX/DataPacker.o.d (added)
-
build/Debug/GNU-MacOSX/FEPSim.o.d (added)
-
build/Debug/GNU-MacOSX/Main.o.d (added)
-
build/Debug/GNU-MacOSX/NetworkReader.o.d (added)
-
build/Debug/GNU-MacOSX/fep_clnt.o.d (added)
-
build/Debug/GNU-MacOSX/fep_xdr.o.d (added)
-
dist/Debug/GNU-MacOSX (added)
-
dist/Debug/GNU-MacOSX/fepsimulator (added)
-
nbproject/Makefile-Debug.mk (modified) (2 diffs)
-
nbproject/configurations.xml (modified) (3 diffs)
-
nbproject/private/configurations.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/FEPSimulator/FEPSim.cpp
r84 r86 1 1 #include "FEPSim.h" 2 2 3 /** 4 * Constructor 5 * 6 * @param host The host rpc server ip address 7 * @param networkFile the xml network file 8 */ 9 FEPSim::FEPSim(char * ATMShost) { 3 FEPSim::FEPSim(char * ATMShost, int FEP_PROG, int FEP_REV, int SOCK_PORT) { 10 4 this->ATMSHost = ATMShost; 5 this->FEP_PROG = FEP_PROG; 6 this->FEP_REV = FEP_REV; 7 this->SOCK_PORT = SOCK_PORT; 11 8 } 12 9 13 /**14 * Destructor15 */16 10 FEPSim::~FEPSim() { 17 cout << "Destroying client..." << endl; 18 clnt_destroy(clnt); 11 19 12 } 20 13 21 /**22 * Handler for the ATMS RPC Response (to the client RPC Call)23 * @param response pointer to fep_reply struct24 */25 14 void FEPSim::handleCallResponse(void *response) { 26 15 // Failed RPC Call … … 34 23 } 35 24 36 void FEPSim::sendReplys(char * xml) 37 { 25 void FEPSim::sendReplys(char * xml) { 38 26 NetworkReader networkReader = NetworkReader(xml); 39 27 vector<FEP_LINE*> lines = networkReader.getLines(); 40 28 vector<STATION*> ldsMap = networkReader.getStations(); 41 29 42 30 // Send one reply for every FEPLine 43 31 for (int i = 0; i < lines.size(); i++) { … … 104 92 } 105 93 106 /**107 * Sends an fep_reply for every line in the FEP.108 */109 94 void FEPSim::updateATMS(char * xml) { 110 if(createClient(this->ATMSHost)) 111 { 95 if (createClient()) { 112 96 sendReplys(xml); 97 cout << "Destroying client..." << endl; 98 clnt_destroy(clnt); 113 99 } 114 100 } 115 101 116 /** 117 * Creates the RPC Client. If not successful, exit with status 1. 118 * @param host rpc server ip 119 */ 120 bool FEPSim::createClient(char * host) { 102 bool FEPSim::createClient() { 121 103 /* Create RPC Client to communicate with ATMS */ 122 104 bool success = true; 123 cout << "Creating RPC Client" << endl; 124 clnt = clnt_create( host, /*100090,*/ 103121, 32, "tcp");105 106 clnt = clnt_create(this->ATMSHost, FEP_PROG, FEP_REV, "tcp"); 125 107 /* Check if client creation failed */ 126 108 if (clnt == (CLIENT *) NULL) { 127 cerr << "Can't create client to " << host << endl;109 cerr << "Can't create client to " << this->ATMSHost << endl; 128 110 success = false; 129 } 130 else { 111 } else { 131 112 cout << "Client created" << endl; 132 113 } … … 134 115 } 135 116 136 /** 137 * Main driver for ATMSCommunicator. Creates an RPC Client from command line args. 138 * @param argc 139 * @param argv 140 * @return 141 */ 142 int main(int argc, char *argv[]) { 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 117 void FEPSim::runSockServer() { 151 118 int sockfd, newsockfd, portno, clilen; 152 119 char buffer[BUFF_SIZE]; 153 120 struct sockaddr_in serv_addr, cli_addr; 154 121 int n; 155 portno = atoi(argv[2]);122 portno = this->SOCK_PORT; 156 123 157 124 /* First call to socket() function */ … … 184 151 185 152 /* Accept actual connections from the client */ 186 while (1) {187 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *) &clilen);153 while (1) { 154 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *) & clilen); 188 155 189 156 if (newsockfd < 0) { … … 195 162 // zero out buffer 196 163 bzero(buffer, BUFF_SIZE); 197 164 198 165 // read XML from socket 199 166 int totBytes = 0; 200 while ((n = recv(newsockfd, &buffer[totBytes], sizeof (buffer), 0)) > 0) {167 while ((n = recv(newsockfd, &buffer[totBytes], sizeof (buffer), 0)) > 0) { 201 168 totBytes += n; 202 169 } 203 170 204 171 if (n < 0) { 205 172 perror("ERROR reading from socket"); 206 173 exit(1); 207 174 } 208 175 209 176 // send data to atms 210 fep.updateATMS(buffer);177 updateATMS(buffer); 211 178 } 212 213 return 0;214 179 } -
branches/FEPSimulator/FEPSim.h
r84 r86 2 2 * File: FEPSim.h 3 3 * 4 * The FEPSim is an RPC Client which transfers network data to the 5 * ATMS Server. 4 * The FEP Simulator simulates the Front End Processor(FEP), which has the 5 * responsibility of "polling" Loop Detector Stations for highway status data. 6 * The real FEP "polls" real stations over serial communication lines, whereas 7 * the FEP Simulator recieves highway status data through a socket from the Java 8 * ATMS Driver. 9 * 10 * Highway status data is transmitted to the FEP Simulator over the socket in 11 * XML Form. The XML highway status data is then parsed by the Network Reader. 12 * 13 * The data is then sent to the ATMS, using RPC Calls. The RPC Calls to the 14 * ATMS Server send an fep_reply structure. There is one fep_reply structure 15 * sent to the ATMS for every FEP_LINE. 6 16 * 7 * An FEPSim is created every 30 seconds, and an fep_reply structure 8 * for every FEP_LINE_LDS is transferred to the ATMS through an RPC Call. 9 * After the FEPSim has transferred all fep_replys, it is destroyed. 10 * 11 * An FEPSim is script-like in nature. There are no public methods other than 12 * the constructor. To construct an FEPSim, an input file (containing network 13 * data in xml form) and a host server_ip (for the ATMS) are necessary. The 14 * format of the xml input file can be fount in "networkReader.cpp" source file. 17 * The FEP Simulator is a socket server that runs persistently and awaits the 18 * XML highway status data over the socket. When the XML highway status data is 19 * recieved, it executes the RPC Calls to update the ATMS. 15 20 * 16 21 * @author John A. Torres … … 42 47 class FEPSim { 43 48 public: 44 / * members */45 CLIENT *clnt; // RPC Client49 // The RPC Client 50 CLIENT *clnt; 46 51 47 /* methods */ 48 FEPSim(char * ATMSHost); // Constructor 52 /** 53 * Constructor. Sets data values for RPC Client and socket server. 54 * 55 * @param ATMSHost The IP of ATMS Server 56 * @param FEP RPC program number 57 * @param FEP RPC program revision number 58 * @param Socket Server listen port 59 */ 60 FEPSim(char * ATMSHost, int FEP_PROG, int FEP_REV, int SOCK_PORT); 49 61 50 void updateATMS(char * xml); // updates ATMS 51 62 /** 63 * Creates a socket server and awaits the highway status XML responses from the 64 * ATMS Driver. Upon reciept of the highway status XML message, creates an RPC 65 * client and sends the fep_replys to the ATMS. 66 */ 67 void runSockServer(); 68 69 /** 70 * Creates an RPC Client, and on successful creation, sends fep_replys to ATMS. 71 * @param The recieved highway status xml. 72 */ 73 void updateATMS(char * xml); 74 75 /** 76 * Destructor: Does nothing, no cleaning necessary 77 */ 52 78 ~FEPSim(); // Destructor 53 79 … … 55 81 /* members */ 56 82 char * ATMSHost; 83 int FEP_PROG; 84 int FEP_REV; 85 int SOCK_PORT; 57 86 58 /* methods */ 59 void handleCallResponse(void *response); // 60 bool createClient(char *host); 87 /** 88 * Handler for the ATMS RPC Response (to the client RPC Call) 89 * @param response pointer to fep_reply struct 90 */ 91 void handleCallResponse(void *response); 92 93 /** 94 * Creates the RPC Client. If not successful, returns false. 95 */ 96 bool createClient(); 97 98 /** 99 * Sends an fep_reply for each FEP_LINE. Gets highway status from recieved XML 100 * data. 101 * @param xml The recieved highway status XML. 102 */ 61 103 void sendReplys(char * xml); 62 104 -
branches/FEPSimulator/NetworkReader.cpp
r84 r86 1 1 #include "NetworkReader.h" 2 2 3 /**4 * Constructor5 * @param networkFileName input xml file6 */7 3 NetworkReader::NetworkReader(const char * xml) { 8 4 ldsIndex = 0; … … 11 7 12 8 LOOP * NetworkReader::parseLoop(TiXmlElement * loopElem) { 13 LOOP *loop = new LOOP;9 LOOP *loop = new LOOP; 14 10 15 TiXmlElement *subLoopElem = loopElem->FirstChildElement();16 loop->loopID = atoi(subLoopElem->GetText());17 subLoopElem = subLoopElem->NextSiblingElement();18 loop->loop_loc = (char *) subLoopElem->GetText();19 subLoopElem = subLoopElem->NextSiblingElement();20 loop->vol = atoi(subLoopElem->GetText());21 subLoopElem = subLoopElem->NextSiblingElement();22 loop->occ = atof(subLoopElem->GetText());23 subLoopElem = subLoopElem->NextSiblingElement();24 loop->spd = atof(subLoopElem->GetText());25 26 return loop;11 TiXmlElement *subLoopElem = loopElem->FirstChildElement(); 12 loop->loopID = atoi(subLoopElem->GetText()); 13 subLoopElem = subLoopElem->NextSiblingElement(); 14 loop->loop_loc = (char *) subLoopElem->GetText(); 15 subLoopElem = subLoopElem->NextSiblingElement(); 16 loop->vol = atoi(subLoopElem->GetText()); 17 subLoopElem = subLoopElem->NextSiblingElement(); 18 loop->occ = atof(subLoopElem->GetText()); 19 subLoopElem = subLoopElem->NextSiblingElement(); 20 loop->spd = atof(subLoopElem->GetText()); 21 22 return loop; 27 23 } 28 24 29 /**30 * Parses a station xml element into an "STATION"31 *32 * @param stationElem the station xml element33 * @param the parent line34 * @return the new station35 */36 25 STATION * NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) { 37 26 STATION *station = new STATION; 38 27 39 28 TiXmlElement *stationSubElem = stationElem->FirstChildElement(); 40 29 station->lds = atol(stationSubElem->GetText()); … … 56 45 57 46 station->pos = 0; // NOT SURE WHY WE NEED THIS? 58 47 59 48 // Add loops to station 60 49 TiXmlElement *loopElem = stationSubElem->NextSiblingElement()->FirstChildElement(); … … 68 57 cout << station->loops.size() << endl; 69 58 station->dataPack = DataPacker::packData(station); 70 59 71 60 return station; 72 61 } 73 62 74 /**75 * Parses a "Line" xml element into an FEP_LINE76 * @param lineElem the xml element77 * @return FEP_LINE78 */79 63 FEP_LINE * NetworkReader::parseLine(TiXmlElement * lineElem) { 80 64 FEP_LINE *line = new FEP_LINE; … … 104 88 } 105 89 106 /**107 * Loads FEPLines from a specified xml file108 * @param networkFileName the input xml file109 */110 90 void NetworkReader::loadLines(const char * xml) { 111 91 // Load network xml file 112 92 TiXmlDocument doc; 113 doc.Parse((const char*) xml, 0, TIXML_ENCODING_UTF8);93 doc.Parse((const char*) xml, 0, TIXML_ENCODING_UTF8); 114 94 115 95 // grab <Network> element … … 126 106 } 127 107 128 /**129 * Getter for lines130 * @return List of FEP_LINES131 */132 108 vector<FEP_LINE*> NetworkReader::getLines() { 133 109 … … 135 111 } 136 112 137 /**138 * Getter for stations139 * @return List of STATIONs140 */141 113 vector<STATION*> NetworkReader::getStations() { 142 114 -
branches/FEPSimulator/NetworkReader.h
r80 r86 58 58 #include "DataPacker.h" 59 59 60 class NetworkReader 61 { 62 public: 63 NetworkReader(const char * networkFile); // Constructor 64 ~NetworkReader(); // Destructor 65 66 vector<FEP_LINE*> getLines(); // Getter for FEP_LINE list 67 vector<STATION*> getStations(); // Getter for STATION list 68 private: 69 vector<FEP_LINE*> lines; 70 vector<STATION*> stations; 71 int ldsIndex; 72 73 void loadLines(const char * networkFileName); 74 LOOP * parseLoop(TiXmlElement * loopElem); 75 STATION * parseStation(TiXmlElement *stationElem, FEP_LINE *line); 76 FEP_LINE * parseLine(TiXmlElement *lineElem); 60 class NetworkReader { 61 public: 62 /** 63 * Constructor 64 * @param xml Highway Status XML data 65 */ 66 NetworkReader(const char * xml); 67 68 /** 69 * Destructor: no cleaning necessary 70 */ 71 ~NetworkReader(); 72 73 /** 74 * Returns FEP_LINE list. 75 * 76 * @return List of FEP_LINES 77 */ 78 vector<FEP_LINE*> getLines(); 79 80 /** 81 * Returns STATIONS list. 82 * @return List of STATIONs 83 */ 84 vector<STATION*> getStations(); 85 86 private: 87 vector<FEP_LINE*> lines; 88 vector<STATION*> stations; 89 int ldsIndex; 90 91 /** 92 * Loads Highway Status data from xml. 93 * 94 * @param xml Highway Status XML. 95 */ 96 void loadLines(const char * networkFileName); 97 98 /** 99 * Parses a single LOOP 100 * @param loopElem TinyXML loop elem 101 * @return LOOP 102 */ 103 LOOP * parseLoop(TiXmlElement * loopElem); 104 105 /** 106 * Parses a single STATION 107 * 108 * @param TinyXML station element 109 * @param the parent FEP_LINE 110 * @return STATION 111 */ 112 STATION * parseStation(TiXmlElement *stationElem, FEP_LINE *line); 113 114 /** 115 * Parses a single FEP_LINE 116 * @param TinyXML line element 117 * @return FEP_LINE 118 */ 119 FEP_LINE * parseLine(TiXmlElement *lineElem); 77 120 }; 78 121 -
branches/FEPSimulator/nbproject/Makefile-Debug.mk
r82 r86 38 38 ${OBJECTDIR}/DataPacker.o \ 39 39 ${OBJECTDIR}/FEPSim.o \ 40 ${OBJECTDIR}/Main.o \ 40 41 ${OBJECTDIR}/NetworkReader.o \ 41 42 ${OBJECTDIR}/fep_clnt.o \ … … 79 80 $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/FEPSim.o FEPSim.cpp 80 81 82 ${OBJECTDIR}/Main.o: Main.cpp 83 ${MKDIR} -p ${OBJECTDIR} 84 ${RM} "$@.d" 85 $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Main.o Main.cpp 86 81 87 ${OBJECTDIR}/NetworkReader.o: NetworkReader.cpp 82 88 ${MKDIR} -p ${OBJECTDIR} -
branches/FEPSimulator/nbproject/configurations.xml
r82 r86 20 20 <itemPath>DataPacker.cpp</itemPath> 21 21 <itemPath>FEPSim.cpp</itemPath> 22 <itemPath>Main.cpp</itemPath> 22 23 <itemPath>NetworkReader.cpp</itemPath> 23 24 <itemPath>fep_clnt.c</itemPath> … … 64 65 <item path="FEPSim.h" ex="false" tool="3" flavor2="0"> 65 66 </item> 67 <item path="Main.cpp" ex="false" tool="1" flavor2="0"> 68 </item> 66 69 <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0"> 67 70 </item> … … 105 108 <item path="FEPSim.h" ex="false" tool="3" flavor2="0"> 106 109 </item> 110 <item path="Main.cpp" ex="false" tool="1" flavor2="0"> 111 </item> 107 112 <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0"> 108 113 </item> -
branches/FEPSimulator/nbproject/private/configurations.xml
r82 r86 30 30 <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27</runcommandpicklistitem> 31 31 <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommandpicklistitem> 32 <runcommandpicklistitem>"${OUTPUT_PATH}" 1192.168.251.27 103121 32 8080</runcommandpicklistitem> 32 33 </runcommandpicklist> 33 <runcommand>"${OUTPUT_PATH}" 1 92.168.251.278080</runcommand>34 <runcommand>"${OUTPUT_PATH}" 1192.168.251.27 103121 32 8080</runcommand> 34 35 <rundir></rundir> 35 36 <buildfirst>true</buildfirst>
Note: See TracChangeset
for help on using the changeset viewer.
