Changeset 217 in tmcsimulator for branches/FEPSimulator/FEPSim.cpp


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.

File:
1 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} 
Note: See TracChangeset for help on using the changeset viewer.