Changeset 217 in tmcsimulator for branches/FEPSimulator


Ignore:
Timestamp:
11/02/2017 10:53:38 PM (9 years ago)
Author:
jtorres
Message:

Implemented logging into FEPSimulator. Now logs output into FEPSimLog.txt. Error messages are still output to console so you know immediately if there is an error. The log file is cleared upon FEPSim start-up.

Location:
branches/FEPSimulator
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/FEPSimulator/FEPSim.cpp

    r215 r217  
    77    this->FEP_REV = FEP_REV; 
    88    this->SOCK_PORT = SOCK_PORT; 
     9     
     10    // clear log file 
     11    FEPLogFile.open(FEPLogFileName, ios::trunc); 
     12    FEPLogFile.close(); 
    913} 
    1014 
    11 FEPSim::~FEPSim() {  
     15FEPSim::~FEPSim() { 
     16    FEPLogFile.close(); 
    1217} 
    1318 
    1419void FEPSim::handleCallResponse(void *response) { 
    1520    // Failed RPC Call  
    16     if (response == NULL) { clnt_perror(clnt, "RPC call failed"); 
     21    if (response == NULL) {  
     22        clnt_perror(clnt, "RPC call failed"); 
    1723    } 
    1824    // Successful RPC Call 
    19     else { cout << "Successful RPC call to ATMS..." << endl; 
     25    else {  
     26        FEPLogFile << "Successful RPC call to ATMS..." << endl; 
    2027    } 
    2128} 
     
    3037    for (int i = 0; i < lines.size(); i++) { 
    3138        fep_reply fepReply; 
    32         cout << "Sending fepReply for line #" << lines.at(i)->lineNum << endl; 
     39         
    3340        // populate reply 
    3441        fepReply.reply = SHORTPOLL; 
     
    3744        fepReply.kind = (enum polltype) 0; 
    3845        fepReply.flag = (enum replykind) 0; 
    39  
    40         /*********************************** 
    41          * We might need to handle this on the java side if its an 
    42          * issue 
    43         lines.at(i).schedleSeq += 1; 
    44         lines.at(i).globalSeq += 51; 
    45          */ 
    4646 
    4747        fepReply.schedule_sequence = lines.at(i)->schedleSeq; 
     
    9090            fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa; 
    9191            // send out data 
    92             //printf("Transferring line=%d, lds_drop_no=%d...\n", lines.at(i)->lineNum, (int)ldsMap.at(index)->drop); 
    93             // Make RPC Call and handle response 
    94             // printf("Handling ATMS response...\n"); 
     92             
     93            FEPLogFile << "Sending fepReply for line #" << lines.at(i)->lineNum  
     94                    << " station number #"  
     95                    << ldsMap.at(lines.at(i)->ldsIndex.at(j)) << endl; 
     96             
    9597            // Transfer the station data to ATMS and listen for response 
    9698            handleCallResponse(fep_reply_xfer_32(&fepReply, clnt)); 
    97             unsigned int sleepseconds = 50000; 
    98             usleep(sleepseconds); 
    9999        } 
    100100    } 
     
    108108        // Prepare and send the highway status as FEP replies 
    109109        sendReplys(buffer); 
    110         cout << "Destroying client..." << endl; 
     110        FEPLogFile << "Destroying client..." << endl; 
    111111        clnt_destroy(clnt); 
    112112        int startTime = time(NULL); 
    113         cout << "time is: " << startTime << endl; 
     113        FEPLogFile << "time is: " << startTime << endl; 
    114114    } 
    115115} 
     
    127127        success = false; 
    128128    } else { 
    129         cout << "Client created" << endl; 
     129        FEPLogFile << "Client created" << endl; 
    130130    } 
    131131    return success; 
     
    185185            totBytes += n; 
    186186        } 
    187         HighwaysParser highwaysParser = HighwaysParser(buffer); 
    188  
    189187 
    190188        if (n < 0) { 
     
    192190            exit(1); 
    193191        } 
    194  
     192         
     193        FEPLogFile.open(FEPLogFileName, ios::app); 
    195194        // send data to atms 
    196195        manageClientConnection(buffer); 
     196        FEPLogFile << "attempt" << endl; 
     197        FEPLogFile.close(); 
    197198    } 
    198199} 
  • branches/FEPSimulator/FEPSim.h

    r214 r217  
    3333#include "fep.h" 
    3434#include <iostream> 
     35#include <fstream> 
    3536#include <stdio.h> 
    3637#include <stdlib.h> 
     
    4445 
    4546const int BUFF_SIZE = 1266341; 
    46  
     47const string FEPLogFileName = "FEPSimLog.txt"; 
     48static ofstream FEPLogFile; 
     49     
    4750class FEPSim { 
    4851public: 
     
    8487    int FEP_REV; 
    8588    int SOCK_PORT; 
    86  
     89     
    8790    /** 
    8891     * Handler for the ATMS RPC Response (to the client RPC Call) 
     
    102105     */ 
    103106    void sendReplys(char * xml); 
    104  
     107     
    105108}; 
    106109 
  • branches/FEPSimulator/HighwaysParser.cpp

    r209 r217  
    9999            newStation->length = newStation->loops.size() * 2 + CONTROL_DATA_LEN; 
    100100            newStation->dataPack = DataPacker::packData(newStation); 
    101             for(int byte = 0; byte < newStation->length; byte++) 
    102             { 
    103                 printf("%02X", (unsigned char) newStation->dataPack[byte]); 
    104             } 
    105             printf("\n"); 
    106101             
    107102            this->stations.push_back(newStation); 
  • branches/FEPSimulator/nbproject/private/private.xml

    r212 r217  
    88    <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> 
    99        <group> 
     10            <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/network.h</file> 
     11            <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/FEPSim.cpp</file> 
     12            <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/fep.h</file> 
     13            <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/FEPSim.h</file> 
    1014            <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/HighwaysParser.cpp</file> 
    11             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/fep.h</file> 
    12             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/DataPacker.cpp</file> 
    13             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/HighwaysParser.h</file> 
    14             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/FEPSim.cpp</file> 
    15             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/network.h</file> 
    16             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/Makefile</file> 
    17             <file>file:/Users/jtorres/tmcsimulator/branches/FEPSimulator/tests/HighwaysParserTest.cpp</file> 
    1815        </group> 
    1916    </open-files> 
Note: See TracChangeset for help on using the changeset viewer.