Changeset 233 in tmcsimulator


Ignore:
Timestamp:
11/13/2017 06:07:07 PM (8 years ago)
Author:
jtorres
Message:

FEPSim: finalized comments, added to both header and source files.

Location:
branches/FEPSimulator
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/FEPSimulator/DataPacker.cpp

    r202 r233  
    11#include "DataPacker.h" 
    22 
     3// declare static message var 
    34unsigned char * DataPacker::msg; 
    45 
     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 */ 
    512unsigned char * DataPacker::packData(STATION *station) { 
    613    int pos = 26; 
     
    4451} 
    4552 
     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 */ 
    4661int DataPacker::dynamicDataPack(STATION *station, int packNo, int pos) { 
    4762     
     
    97112    return pos; 
    98113} 
    99  
     114/** 
     115 * Packs the static meta data into the msg 
     116 *  
     117 * @param station station being packed 
     118 * @return the msg 
     119 */ 
    100120unsigned char * DataPacker::staticDataPack(STATION *station) { 
    101121    int j; 
     
    208228} 
    209229 
     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 */ 
    210236bool DataPacker::DataAvail(char flag, int num) { 
    211237    int mag, fel; 
     
    238264} 
    239265 
    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 */ 
    241273char DataPacker::chksum(unsigned char *dataptr, int len) { 
    242274    int i; 
     
    249281} 
    250282 
    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 */ 
    252289VOLOCC DataPacker::packVOLOCC(int vol, int occ) 
    253290{ 
  • branches/FEPSimulator/DataPacker.h

    r159 r233  
    3131 
    3232private: 
     33    // static message var 
    3334    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     */ 
    3541    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     */ 
    3750    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     */ 
    3958    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     */ 
    4165    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     */ 
    4372    VOLOCC packVOLOCC(int vol, int occ); 
    4473 
  • branches/FEPSimulator/FEPSim.cpp

    r224 r233  
    11#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 */ 
    411FEPSim::FEPSim(char * ATMShost, int FEP_PROG, int FEP_REV, int SOCK_PORT) { 
    512    this->ATMSHost = ATMShost; 
     
    1320} 
    1421 
     22/** 
     23 * Destructor: closes the log file if open 
     24 */ 
    1525FEPSim::~FEPSim() { 
    1626    FEPLogFile.close(); 
    1727} 
    1828 
     29/** 
     30 * Handler for the ATMS RPC Response (to the client RPC Call) 
     31 * @param response pointer to fep_reply struct 
     32 */ 
    1933void FEPSim::handleCallResponse(void *response) { 
    2034    // Failed RPC Call  
     
    2842} 
    2943 
     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 */ 
    3050void FEPSim::sendReplys(char * buffer) { 
    3151    HighwaysParser highwaysParser = HighwaysParser(buffer); 
     
    106126} 
    107127 
     128/** 
     129 * Creates an RPC Client, and on successful creation, sends fep_replys to ATMS. 
     130 * @param The recieved highway status msg. 
     131 */ 
    108132void FEPSim::manageClientConnection(char * buffer)  
    109133{ 
     
    120144} 
    121145 
    122  
     146/** 
     147  * Creates an RPC Client to the ATMS Server. If unsuccessful, returns false 
     148  * @return bool success 
     149  */ 
    123150bool FEPSim::createClient() { 
    124151    /* Create RPC Client to communicate with ATMS */ 
     
    137164} 
    138165 
     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 */ 
    139171void FEPSim::runSockServer() { 
    140172    int sockfd, newsockfd, portno, clilen; 
  • branches/FEPSimulator/FEPSim.h

    r221 r233  
    44 * The FEP Simulator simulates the Front End Processor(FEP), which has the 
    55 * 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. 
     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. 
    99 *  
    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. 
    2013 * 
    2114 * @author John A. Torres 
     
    4336#include <netinet/in.h> 
    4437#include <unistd.h> 
     38#include <time.h> 
    4539 
     40// this buffer is the size of the entire highways data message + 1 for the 
     41// appended newline character, when sent over the socket 
    4642const int BUFF_SIZE = 1266341; 
     43// Log file for FEPSimulator 
    4744static ofstream FEPLogFile; 
    4845     
     
    6360     
    6461    /** 
    65      * Creates a socket server and awaits the highway status XML responses from the 
    66      * ATMS Driver. Upon reciept of the highway status XML message, creates an RPC 
     62     * 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 
    6764     * client and sends the fep_replys to the ATMS. 
    6865     */ 
     
    7168    /** 
    7269     * 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. 
    7471     */ 
    75     void manageClientConnection(char * xml); 
     72    void manageClientConnection(char * buffer); 
    7673     
    7774    /** 
    78      * Destructor: Does nothing, no cleaning necessary 
     75     * Destructor: closes the log file if open 
    7976     */ 
    8077    ~FEPSim(); // Destructor 
    8178 
    8279private: 
    83     /* members */ 
     80    // atms ip address 
    8481    char * ATMSHost; 
     82    // rpc program number 
    8583    int FEP_PROG; 
     84    // rpc revision number 
    8685    int FEP_REV; 
     86    // socket port 
    8787    int SOCK_PORT; 
     88    // name of logging file 
    8889    char * FEPLogFileName; 
    8990     
     
    9596     
    9697    /** 
    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 
    98100     */ 
    99101    bool createClient(); 
    100102     
    101103    /** 
    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. 
    105108     */ 
    106     void sendReplys(char * xml); 
    107      
     109    void sendReplys(char * buffer); 
    108110}; 
    109111 
  • branches/FEPSimulator/HighwaysParser.cpp

    r218 r233  
    11/*  
    2  * File:   HighwaysParser.cpp 
    3  * Author: jtorres 
     2 * File:   HighwaysParser.h 
    43 *  
    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 
    610 */ 
    711 
    812#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 
    2215HighwaysParser::HighwaysParser(char * hwyData) { 
    2316    parseLines(hwyData); 
    2417} 
    2518 
     19// Frees all allocated memory in the class 
    2620HighwaysParser::~HighwaysParser() { 
    2721    // deallocate FEPLines 
     
    4842} 
    4943 
     44/** 
     45 * Parses the buffer into FEP_LINE and STATION vectors. 
     46 *  
     47 * @param highwaysData buffer 
     48 */ 
    5049void HighwaysParser::parseLines(char * hwyData) 
    5150{ 
     51    // convert buffer to cpp string type 
    5252    string highwaysData = hwyData; 
     53    // create buffer stream 
    5354    istringstream highwaysStream(highwaysData); 
     55    // get the number of FEPLines 
    5456    string currLine; 
    5557    getline(highwaysStream, currLine); 
    5658    int numLines; 
    5759    sscanf(currLine.c_str(), "%d", &numLines); 
     60     
     61    // declare variables used in parsing lines and stations 
    5862    int lineNum = 0; 
    5963    long lds = 0; 
     
    7276    int vol = 0; 
    7377 
     78    // for each line 
    7479    for(int lineIndex = 0; lineIndex < numLines; lineIndex++) 
    7580    { 
     
    8792        newLine->schedleSeq = schedleSeq; 
    8893         
     94        // for each station 
    8995        for(int stationIndex = 0; stationIndex < numStations; stationIndex++) 
    9096        { 
     
    104110            newStation->MlTotVol = 0; 
    105111            newStation->OppTotVol = 0; 
    106              
     112            // for each loop 
    107113            for(int loopIndex = 0; loopIndex < numLoops; loopIndex++) 
    108114            { 
     
    121127            newStation->dataPack = DataPacker::packData(newStation); 
    122128             
     129            // add new station to stations vector 
    123130            this->stations.push_back(newStation); 
    124131        } 
     132        // add new line to lines vector 
    125133        this->lines.push_back(newLine); 
    126134    } 
  • branches/FEPSimulator/HighwaysParser.h

    r209 r233  
    11/*  
    22 * 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 
    610 */ 
    711 
     
    1822class HighwaysParser { 
    1923public: 
     24    /** 
     25     * Constructor. Takes in the character buffer to be parsed. 
     26     *  
     27     * @param highwaysData buffer 
     28     */ 
    2029    HighwaysParser(char * highwaysData); 
     30    /** 
     31     * Parses the buffer into FEP_LINE and STATION vectors. 
     32     *  
     33     * @param highwaysData buffer 
     34     */ 
    2135    void parseLines(char * highwaysData); 
     36    // The public lines member, containing the parsed vector of FEP_LINES 
    2237    vector<FEP_LINE*> lines; 
     38    // The public stations member, containing the parsed vector of STATIONS 
    2339    vector<STATION*> stations; 
     40    // Frees all allocated memory in the class 
    2441    virtual ~HighwaysParser(); 
    2542private: 
  • 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 
    68 */ 
    79 
     
    1113using namespace std; 
    1214 
    13 /** 
    14  * Main driver for FEP Simulator. Creates a socket server that reads Highway 
    15  * Status from the ATMS Driver over the socket, in XML form. Runs persistently. 
    16  *  
    17  * @param argc argument count 
    18  * @param argv args 
    19  * @return  
    20  */ 
    2115int main(int argc, char *argv[]) { 
     16    // if argument count is not correct, display usage message 
    2217    if(argc != 5) 
    2318    { 
     
    2621        exit(1); 
    2722    } 
     23    // get the FEP Sim command line arguments 
    2824    char *FEPSimHost = argv[1]; 
    2925    int fep_prog = atoi(argv[2]); 
     
    3127    int portno = atoi(argv[4]); 
    3228 
     29    // run the FEPSim 
    3330    cout << "Running FEP Simulator..." << endl; 
    34      
    3531    FEPSim fep = FEPSim(FEPSimHost, fep_prog, fep_rev, portno); 
    3632    fep.runSockServer(); 
Note: See TracChangeset for help on using the changeset viewer.