Changeset 86 in tmcsimulator for branches/FEPSimulator


Ignore:
Timestamp:
10/09/2017 11:58:19 PM (9 years ago)
Author:
jtorres
Message:

branches/FEPSimulator: updated and improved comments, added Main.cpp which creates the FEPSimulator, minor project configurations (runtime command line arguments / tinyxml.a libosxtinyxml.a)

Location:
branches/FEPSimulator
Files:
10 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/FEPSimulator/FEPSim.cpp

    r84 r86  
    11#include "FEPSim.h" 
    22 
    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) { 
     3FEPSim::FEPSim(char * ATMShost, int FEP_PROG, int FEP_REV, int SOCK_PORT) { 
    104    this->ATMSHost = ATMShost; 
     5    this->FEP_PROG = FEP_PROG; 
     6    this->FEP_REV = FEP_REV; 
     7    this->SOCK_PORT = SOCK_PORT; 
    118} 
    129 
    13 /** 
    14  * Destructor 
    15  */ 
    1610FEPSim::~FEPSim() { 
    17     cout << "Destroying client..." << endl; 
    18     clnt_destroy(clnt); 
     11 
    1912} 
    2013 
    21 /** 
    22  * Handler for the ATMS RPC Response (to the client RPC Call) 
    23  * @param response pointer to fep_reply struct 
    24  */ 
    2514void FEPSim::handleCallResponse(void *response) { 
    2615    // Failed RPC Call 
     
    3423} 
    3524 
    36 void FEPSim::sendReplys(char * xml) 
    37 { 
     25void FEPSim::sendReplys(char * xml) { 
    3826    NetworkReader networkReader = NetworkReader(xml); 
    3927    vector<FEP_LINE*> lines = networkReader.getLines(); 
    4028    vector<STATION*> ldsMap = networkReader.getStations(); 
    41      
     29 
    4230    // Send one reply for every FEPLine 
    4331    for (int i = 0; i < lines.size(); i++) { 
     
    10492} 
    10593 
    106 /** 
    107  * Sends an fep_reply for every line in the FEP. 
    108  */ 
    10994void FEPSim::updateATMS(char * xml) { 
    110     if(createClient(this->ATMSHost)) 
    111     { 
     95    if (createClient()) { 
    11296        sendReplys(xml); 
     97        cout << "Destroying client..." << endl; 
     98        clnt_destroy(clnt); 
    11399    } 
    114100} 
    115101 
    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) { 
     102bool FEPSim::createClient() { 
    121103    /* Create RPC Client to communicate with ATMS */ 
    122104    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"); 
    125107    /* Check if client creation failed */ 
    126108    if (clnt == (CLIENT *) NULL) { 
    127         cerr << "Can't create client to " << host << endl; 
     109        cerr << "Can't create client to " << this->ATMSHost << endl; 
    128110        success = false; 
    129     } 
    130     else { 
     111    } else { 
    131112        cout << "Client created" << endl; 
    132113    } 
     
    134115} 
    135116 
    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      
     117void FEPSim::runSockServer() { 
    151118    int sockfd, newsockfd, portno, clilen; 
    152119    char buffer[BUFF_SIZE]; 
    153120    struct sockaddr_in serv_addr, cli_addr; 
    154121    int n; 
    155     portno = atoi(argv[2]); 
     122    portno = this->SOCK_PORT; 
    156123 
    157124    /* First call to socket() function */ 
     
    184151 
    185152    /* 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); 
    188155 
    189156        if (newsockfd < 0) { 
     
    195162        // zero out buffer 
    196163        bzero(buffer, BUFF_SIZE); 
    197          
     164 
    198165        // read XML from socket 
    199166        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) { 
    201168            totBytes += n; 
    202169        } 
    203          
     170 
    204171        if (n < 0) { 
    205172            perror("ERROR reading from socket"); 
    206173            exit(1); 
    207174        } 
    208          
     175 
    209176        // send data to atms 
    210         fep.updateATMS(buffer); 
     177        updateATMS(buffer); 
    211178    } 
    212  
    213     return 0; 
    214179} 
  • branches/FEPSimulator/FEPSim.h

    r84 r86  
    22 * File: FEPSim.h 
    33 *  
    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. 
    616 * 
    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. 
    1520 * 
    1621 * @author John A. Torres 
     
    4247class FEPSim { 
    4348public: 
    44     /* members */ 
    45     CLIENT *clnt; // RPC Client 
     49    // The RPC Client 
     50    CLIENT *clnt; 
    4651 
    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); 
    4961     
    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     */ 
    5278    ~FEPSim(); // Destructor 
    5379 
     
    5581    /* members */ 
    5682    char * ATMSHost; 
     83    int FEP_PROG; 
     84    int FEP_REV; 
     85    int SOCK_PORT; 
    5786 
    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     */ 
    61103    void sendReplys(char * xml); 
    62104 
  • branches/FEPSimulator/NetworkReader.cpp

    r84 r86  
    11#include "NetworkReader.h" 
    22 
    3 /** 
    4  * Constructor 
    5  * @param networkFileName input xml file 
    6  */ 
    73NetworkReader::NetworkReader(const char * xml) { 
    84    ldsIndex = 0; 
     
    117 
    128LOOP * NetworkReader::parseLoop(TiXmlElement * loopElem) { 
    13         LOOP *loop = new LOOP; 
     9    LOOP *loop = new LOOP; 
    1410 
    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; 
    2723} 
    2824 
    29 /** 
    30  * Parses a station xml element into an "STATION" 
    31  *  
    32  * @param stationElem the station xml element 
    33  * @param the parent line 
    34  * @return the new station 
    35  */ 
    3625STATION * NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) { 
    3726    STATION *station = new STATION; 
    38      
     27 
    3928    TiXmlElement *stationSubElem = stationElem->FirstChildElement(); 
    4029    station->lds = atol(stationSubElem->GetText()); 
     
    5645 
    5746    station->pos = 0; // NOT SURE WHY WE NEED THIS? 
    58      
     47 
    5948    // Add loops to station 
    6049    TiXmlElement *loopElem = stationSubElem->NextSiblingElement()->FirstChildElement(); 
     
    6857    cout << station->loops.size() << endl; 
    6958    station->dataPack = DataPacker::packData(station); 
    70      
     59 
    7160    return station; 
    7261} 
    7362 
    74 /** 
    75  * Parses a "Line" xml element into an FEP_LINE 
    76  * @param lineElem the xml element 
    77  * @return FEP_LINE 
    78  */ 
    7963FEP_LINE * NetworkReader::parseLine(TiXmlElement * lineElem) { 
    8064    FEP_LINE *line = new FEP_LINE; 
     
    10488} 
    10589 
    106 /** 
    107  * Loads FEPLines from a specified xml file 
    108  * @param networkFileName the input xml file 
    109  */ 
    11090void NetworkReader::loadLines(const char * xml) { 
    11191    // Load network xml file 
    11292    TiXmlDocument doc; 
    113     doc.Parse((const char*)xml, 0, TIXML_ENCODING_UTF8); 
     93    doc.Parse((const char*) xml, 0, TIXML_ENCODING_UTF8); 
    11494 
    11595    // grab <Network> element 
     
    126106} 
    127107 
    128 /** 
    129  * Getter for lines 
    130  * @return List of FEP_LINES 
    131  */ 
    132108vector<FEP_LINE*> NetworkReader::getLines() { 
    133109 
     
    135111} 
    136112 
    137 /** 
    138  * Getter for stations 
    139  * @return List of STATIONs 
    140  */ 
    141113vector<STATION*> NetworkReader::getStations() { 
    142114 
  • branches/FEPSimulator/NetworkReader.h

    r80 r86  
    5858#include "DataPacker.h" 
    5959 
    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); 
     60class NetworkReader { 
     61public: 
     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     
     86private: 
     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); 
    77120}; 
    78121 
  • branches/FEPSimulator/nbproject/Makefile-Debug.mk

    r82 r86  
    3838        ${OBJECTDIR}/DataPacker.o \ 
    3939        ${OBJECTDIR}/FEPSim.o \ 
     40        ${OBJECTDIR}/Main.o \ 
    4041        ${OBJECTDIR}/NetworkReader.o \ 
    4142        ${OBJECTDIR}/fep_clnt.o \ 
     
    7980        $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/FEPSim.o FEPSim.cpp 
    8081 
     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 
    8187${OBJECTDIR}/NetworkReader.o: NetworkReader.cpp  
    8288        ${MKDIR} -p ${OBJECTDIR} 
  • branches/FEPSimulator/nbproject/configurations.xml

    r82 r86  
    2020      <itemPath>DataPacker.cpp</itemPath> 
    2121      <itemPath>FEPSim.cpp</itemPath> 
     22      <itemPath>Main.cpp</itemPath> 
    2223      <itemPath>NetworkReader.cpp</itemPath> 
    2324      <itemPath>fep_clnt.c</itemPath> 
     
    6465      <item path="FEPSim.h" ex="false" tool="3" flavor2="0"> 
    6566      </item> 
     67      <item path="Main.cpp" ex="false" tool="1" flavor2="0"> 
     68      </item> 
    6669      <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0"> 
    6770      </item> 
     
    105108      <item path="FEPSim.h" ex="false" tool="3" flavor2="0"> 
    106109      </item> 
     110      <item path="Main.cpp" ex="false" tool="1" flavor2="0"> 
     111      </item> 
    107112      <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0"> 
    108113      </item> 
  • branches/FEPSimulator/nbproject/private/configurations.xml

    r82 r86  
    3030          <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27</runcommandpicklistitem> 
    3131          <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommandpicklistitem> 
     32          <runcommandpicklistitem>"${OUTPUT_PATH}" 1192.168.251.27 103121 32 8080</runcommandpicklistitem> 
    3233        </runcommandpicklist> 
    33         <runcommand>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommand> 
     34        <runcommand>"${OUTPUT_PATH}" 1192.168.251.27 103121 32 8080</runcommand> 
    3435        <rundir></rundir> 
    3536        <buildfirst>true</buildfirst> 
Note: See TracChangeset for help on using the changeset viewer.