Changeset 233 in tmcsimulator for branches/FEPSimulator
- Timestamp:
- 11/13/2017 06:07:07 PM (8 years ago)
- Location:
- branches/FEPSimulator
- Files:
-
- 7 edited
-
DataPacker.cpp (modified) (6 diffs)
-
DataPacker.h (modified) (1 diff)
-
FEPSim.cpp (modified) (6 diffs)
-
FEPSim.h (modified) (5 diffs)
-
HighwaysParser.cpp (modified) (6 diffs)
-
HighwaysParser.h (modified) (2 diffs)
-
Main.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/FEPSimulator/DataPacker.cpp
r202 r233 1 1 #include "DataPacker.h" 2 2 3 // declare static message var 3 4 unsigned char * DataPacker::msg; 4 5 6 /** 7 * Returns packed data message to be sent to ATMS Server in fep_reply via RPC 8 * 9 * @param station The station for which the message is to be made 10 * @return The packed data message 11 */ 5 12 unsigned char * DataPacker::packData(STATION *station) { 6 13 int pos = 26; … … 44 51 } 45 52 53 /** 54 * Packs the dynamic (occ/vol) data into the message 55 * 56 * @param station the station being packed 57 * @param packNo number that specifies which lane types to compare 58 * @param pos position in the message (byte number) 59 * @return position (int) 60 */ 46 61 int DataPacker::dynamicDataPack(STATION *station, int packNo, int pos) { 47 62 … … 97 112 return pos; 98 113 } 99 114 /** 115 * Packs the static meta data into the msg 116 * 117 * @param station station being packed 118 * @return the msg 119 */ 100 120 unsigned char * DataPacker::staticDataPack(STATION *station) { 101 121 int j; … … 208 228 } 209 229 230 /** 231 * Checks if there is data available at the specified lane 232 * @param flag 233 * @param num 234 * @return bool (is data available) 235 */ 210 236 bool DataPacker::DataAvail(char flag, int num) { 211 237 int mag, fel; … … 238 264 } 239 265 240 // checksum based on data from byte 1 (after 0DOA) to the second last byte (the 266 /** 267 * Returns the sum of values from byte 1 (after 0x0D0A) to the second to last byte 268 * 269 * @param dataptr msg data pointer 270 * @param len length of message 271 * @return checksum value 272 */ 241 273 char DataPacker::chksum(unsigned char *dataptr, int len) { 242 274 int i; … … 249 281 } 250 282 251 // convert vol and occ data to a two-byte data packet 283 /** 284 * Convert volume and occupancy data to a two-byte data packet 285 * @param vol 286 * @param occ 287 * @return the volume occupancy two byte data packet struct 288 */ 252 289 VOLOCC DataPacker::packVOLOCC(int vol, int occ) 253 290 { -
branches/FEPSimulator/DataPacker.h
r159 r233 31 31 32 32 private: 33 // static message var 33 34 static unsigned char *msg; 34 // Packs the static data in message sent to ATMS 35 /** 36 * Packs the static meta data into the msg 37 * 38 * @param station station being packed 39 * @return the msg 40 */ 35 41 unsigned char * staticDataPack(STATION *station); 36 // Packs dynamic data in message sent to ATMS 42 /** 43 * Packs the dynamic (occ/vol) data into the message 44 * 45 * @param station the station being packed 46 * @param packNo number that specifies which lane types to compare 47 * @param pos position in the message (byte number) 48 * @return position (int) 49 */ 37 50 int dynamicDataPack(STATION *station, int packNo, int pos); 38 // Sets last byte of message 51 /** 52 * Returns the sum of values from byte 1 (after 0x0D0A) to the second to last byte 53 * 54 * @param dataptr msg data pointer 55 * @param len length of message 56 * @return checksum value 57 */ 39 58 char chksum(unsigned char *dataptr, int len); 40 // Tells whether or not data is available for specified lane 59 /** 60 * Checks if there is data available at the specified lane 61 * @param flag 62 * @param num 63 * @return bool (is data available) 64 */ 41 65 bool DataAvail(char flag, int num); 42 // Helper function: packs vol and occ into two byte data packet 66 /** 67 * Convert volume and occupancy data to a two-byte data packet 68 * @param vol 69 * @param occ 70 * @return the volume occupancy two byte data packet struct 71 */ 43 72 VOLOCC packVOLOCC(int vol, int occ); 44 73 -
branches/FEPSimulator/FEPSim.cpp
r224 r233 1 1 #include "FEPSim.h" 2 #include <time.h> 3 2 3 /** 4 * Constructor. Sets data values for RPC Client and socket server. 5 * 6 * @param ATMSHost The IP of ATMS Server 7 * @param FEP RPC program number 8 * @param FEP RPC program revision number 9 * @param Socket Server listen port 10 */ 4 11 FEPSim::FEPSim(char * ATMShost, int FEP_PROG, int FEP_REV, int SOCK_PORT) { 5 12 this->ATMSHost = ATMShost; … … 13 20 } 14 21 22 /** 23 * Destructor: closes the log file if open 24 */ 15 25 FEPSim::~FEPSim() { 16 26 FEPLogFile.close(); 17 27 } 18 28 29 /** 30 * Handler for the ATMS RPC Response (to the client RPC Call) 31 * @param response pointer to fep_reply struct 32 */ 19 33 void FEPSim::handleCallResponse(void *response) { 20 34 // Failed RPC Call … … 28 42 } 29 43 44 /** 45 * Sends an fep_reply for each station on the FEPLine. 46 * Gets highway status from recieved socket msg. 47 * 48 * @param buffer The recieved highway status msg. 49 */ 30 50 void FEPSim::sendReplys(char * buffer) { 31 51 HighwaysParser highwaysParser = HighwaysParser(buffer); … … 106 126 } 107 127 128 /** 129 * Creates an RPC Client, and on successful creation, sends fep_replys to ATMS. 130 * @param The recieved highway status msg. 131 */ 108 132 void FEPSim::manageClientConnection(char * buffer) 109 133 { … … 120 144 } 121 145 122 146 /** 147 * Creates an RPC Client to the ATMS Server. If unsuccessful, returns false 148 * @return bool success 149 */ 123 150 bool FEPSim::createClient() { 124 151 /* Create RPC Client to communicate with ATMS */ … … 137 164 } 138 165 166 /** 167 * Creates a socket server and awaits the highway status message from the 168 * ATMS Driver. Upon receipt of the highway status message, creates an RPC 169 * client and sends the fep_replys to the ATMS. 170 */ 139 171 void FEPSim::runSockServer() { 140 172 int sockfd, newsockfd, portno, clilen; -
branches/FEPSimulator/FEPSim.h
r221 r233 4 4 * The FEP Simulator simulates the Front End Processor(FEP), which has the 5 5 * responsibility of "polling" Loop Detector Stations for highway status data. 6 * The real FEP "polls" real stations over serial communication lines, whereas7 * the FEP Simulator rec ieves highway status data througha socket from the Java8 * ATMS Driver. 6 * The actual FEP "polls" actual stations over serial communication lines, whereas 7 * the FEP Simulator receives highways status data over a socket from the Java 8 * ATMS Driver. The highways status data is then parsed by the Network Reader. 9 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. 16 * 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. 10 * The data is reconfigured into an fep_reply struct, then sent to the ATMS via 11 * RPC Calls. The RPC Calls to the ATMS Server send an the fep_reply structs. 12 * There is one fep_reply structure sent to the ATMS for every station. 20 13 * 21 14 * @author John A. Torres … … 43 36 #include <netinet/in.h> 44 37 #include <unistd.h> 38 #include <time.h> 45 39 40 // this buffer is the size of the entire highways data message + 1 for the 41 // appended newline character, when sent over the socket 46 42 const int BUFF_SIZE = 1266341; 43 // Log file for FEPSimulator 47 44 static ofstream FEPLogFile; 48 45 … … 63 60 64 61 /** 65 * Creates a socket server and awaits the highway status XML responsesfrom the66 * ATMS Driver. Upon rec iept of the highway status XMLmessage, creates an RPC62 * Creates a socket server and awaits the highway status message from the 63 * ATMS Driver. Upon receipt of the highway status message, creates an RPC 67 64 * client and sends the fep_replys to the ATMS. 68 65 */ … … 71 68 /** 72 69 * Creates an RPC Client, and on successful creation, sends fep_replys to ATMS. 73 * @param The recieved highway status xml.70 * @param The recieved highway status msg. 74 71 */ 75 void manageClientConnection(char * xml);72 void manageClientConnection(char * buffer); 76 73 77 74 /** 78 * Destructor: Does nothing, no cleaning necessary75 * Destructor: closes the log file if open 79 76 */ 80 77 ~FEPSim(); // Destructor 81 78 82 79 private: 83 / * members */80 // atms ip address 84 81 char * ATMSHost; 82 // rpc program number 85 83 int FEP_PROG; 84 // rpc revision number 86 85 int FEP_REV; 86 // socket port 87 87 int SOCK_PORT; 88 // name of logging file 88 89 char * FEPLogFileName; 89 90 … … 95 96 96 97 /** 97 * Creates the RPC Client. If not successful, returns false. 98 * Creates an RPC Client to the ATMS Server. If unsuccessful, returns false 99 * @return bool success 98 100 */ 99 101 bool createClient(); 100 102 101 103 /** 102 * Sends an fep_reply for each FEP_LINE. Gets highway status from recieved XML 103 * data. 104 * @param xml The recieved highway status XML. 104 * Sends an fep_reply for each station on the FEPLine. 105 * Gets highway status from recieved socket msg. 106 * 107 * @param buffer The recieved highway status msg. 105 108 */ 106 void sendReplys(char * xml); 107 109 void sendReplys(char * buffer); 108 110 }; 109 111 -
branches/FEPSimulator/HighwaysParser.cpp
r218 r233 1 1 /* 2 * File: HighwaysParser.cpp 3 * Author: jtorres 2 * File: HighwaysParser.h 4 3 * 5 * Created on October 28, 2017, 7:23 PM 4 * The HighwaysParser class takes in a character buffer and parses it into a 5 * vector of FEP_LINEs and a vector of STATIONS. The buffer is sent in via the 6 * constructor and the FEP_LINE and STATION vectors are accessible via public 7 * members. 8 * 9 * @author John A. Torres 6 10 */ 7 11 8 12 #include "HighwaysParser.h" 9 /* 43 // "number of lines" 10 * 32 0 13 // "line id" "count num" "number of stations" 11 * 1210831 1 5 S 0.9 8 // "station id" "drop num" "route num"... 12 * // ..."direction" "postmile" "number of loops" 13 * 1210832 0.0 0 // "loop id" "occ" "vol" 14 * 1210833 0.0 0 // .. 15 * 1210834 0.0 0 // .. 16 * 1210835 0.0 0 // .. 17 * 1210836 0.0 0 // .. 18 * 1210837 0.0 0 // .. 19 * 1210838 0.0 0 // .. 20 * 1210839 0.0 0 // .. 21 * */ 13 14 // The public stations member, containing the parsed vector of STATIONS 22 15 HighwaysParser::HighwaysParser(char * hwyData) { 23 16 parseLines(hwyData); 24 17 } 25 18 19 // Frees all allocated memory in the class 26 20 HighwaysParser::~HighwaysParser() { 27 21 // deallocate FEPLines … … 48 42 } 49 43 44 /** 45 * Parses the buffer into FEP_LINE and STATION vectors. 46 * 47 * @param highwaysData buffer 48 */ 50 49 void HighwaysParser::parseLines(char * hwyData) 51 50 { 51 // convert buffer to cpp string type 52 52 string highwaysData = hwyData; 53 // create buffer stream 53 54 istringstream highwaysStream(highwaysData); 55 // get the number of FEPLines 54 56 string currLine; 55 57 getline(highwaysStream, currLine); 56 58 int numLines; 57 59 sscanf(currLine.c_str(), "%d", &numLines); 60 61 // declare variables used in parsing lines and stations 58 62 int lineNum = 0; 59 63 long lds = 0; … … 72 76 int vol = 0; 73 77 78 // for each line 74 79 for(int lineIndex = 0; lineIndex < numLines; lineIndex++) 75 80 { … … 87 92 newLine->schedleSeq = schedleSeq; 88 93 94 // for each station 89 95 for(int stationIndex = 0; stationIndex < numStations; stationIndex++) 90 96 { … … 104 110 newStation->MlTotVol = 0; 105 111 newStation->OppTotVol = 0; 106 112 // for each loop 107 113 for(int loopIndex = 0; loopIndex < numLoops; loopIndex++) 108 114 { … … 121 127 newStation->dataPack = DataPacker::packData(newStation); 122 128 129 // add new station to stations vector 123 130 this->stations.push_back(newStation); 124 131 } 132 // add new line to lines vector 125 133 this->lines.push_back(newLine); 126 134 } -
branches/FEPSimulator/HighwaysParser.h
r209 r233 1 1 /* 2 2 * File: HighwaysParser.h 3 * Author: jtorres 4 * 5 * Created on October 28, 2017, 7:23 PM 3 * 4 * The HighwaysParser class takes in a character buffer and parses it into a 5 * vector of FEP_LINEs and a vector of STATIONS. The buffer is sent in via the 6 * constructor and the FEP_LINE and STATION vectors are accessible via public 7 * members. 8 * 9 * @author John A. Torres 6 10 */ 7 11 … … 18 22 class HighwaysParser { 19 23 public: 24 /** 25 * Constructor. Takes in the character buffer to be parsed. 26 * 27 * @param highwaysData buffer 28 */ 20 29 HighwaysParser(char * highwaysData); 30 /** 31 * Parses the buffer into FEP_LINE and STATION vectors. 32 * 33 * @param highwaysData buffer 34 */ 21 35 void parseLines(char * highwaysData); 36 // The public lines member, containing the parsed vector of FEP_LINES 22 37 vector<FEP_LINE*> lines; 38 // The public stations member, containing the parsed vector of STATIONS 23 39 vector<STATION*> stations; 40 // Frees all allocated memory in the class 24 41 virtual ~HighwaysParser(); 25 42 private: -
branches/FEPSimulator/Main.cpp
r100 r233 1 /* 2 * File: Main.cpp 3 * Author: John A. Torres 4 * 5 * Created on October 7, 2017, 4:27 PM 1 /** 2 * File: Main.cpp 3 * 4 * Main driver for FEP Simulator. Creates an FEPSimulator that reads Highway 5 * Status from the ATMS Driver over a socket. Runs persistently. 6 * 7 * @author John A. Torres 6 8 */ 7 9 … … 11 13 using namespace std; 12 14 13 /**14 * Main driver for FEP Simulator. Creates a socket server that reads Highway15 * Status from the ATMS Driver over the socket, in XML form. Runs persistently.16 *17 * @param argc argument count18 * @param argv args19 * @return20 */21 15 int main(int argc, char *argv[]) { 16 // if argument count is not correct, display usage message 22 17 if(argc != 5) 23 18 { … … 26 21 exit(1); 27 22 } 23 // get the FEP Sim command line arguments 28 24 char *FEPSimHost = argv[1]; 29 25 int fep_prog = atoi(argv[2]); … … 31 27 int portno = atoi(argv[4]); 32 28 29 // run the FEPSim 33 30 cout << "Running FEP Simulator..." << endl; 34 35 31 FEPSim fep = FEPSim(FEPSimHost, fep_prog, fep_rev, portno); 36 32 fep.runSockServer();
Note: See TracChangeset
for help on using the changeset viewer.
