Changeset 202 in tmcsimulator for branches/FEPSimulator/HighwaysParser.cpp


Ignore:
Timestamp:
10/30/2017 06:35:42 PM (9 years ago)
Author:
jtorres
Message:

Further progress on condensed format reader, not all green dots showing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FEPSimulator/HighwaysParser.cpp

    r199 r202  
    2121      * */ 
    2222HighwaysParser::HighwaysParser(char * hwyData) { 
    23     string highwaysData = hwyData; 
    24     istringstream stream(highwaysData); 
    25     parseLines(highwaysData); 
     23    parseLines(hwyData); 
    2624} 
    2725 
     
    2927} 
    3028 
    31 vector<FEP_LINE *> HighwaysParser::getLines() { 
    32      
    33 } 
    34  
    35 vector<STATION *> HighwaysParser::getStations() { 
    36      
    37 } 
    38  
    39 // Loop Detector: A single sensor that detects the volume, occupancy, and speed 
    40 // in a single highway lane 
    41 typedef struct loop LOOP; 
    42 struct loop 
     29void HighwaysParser::parseLines(char * hwyData) 
    4330{ 
    44     // meta data 
    45     long loopID; 
    46     char *loop_loc; 
    47      
    48     // dynamic data 
    49     int vol; 
    50     float occ; 
    51     double spd; 
    52 }; 
    53 void HighwaysParser::parseLines(istringstream highwaysData) 
    54 { 
     31    string highwaysData = hwyData; 
     32    istringstream highwaysStream(highwaysData); 
    5533    string currLine; 
    56     getline(highwaysData, currLine); 
     34    getline(highwaysStream, currLine); 
    5735    int numLines; 
    58     sscanf(highwaysData, "%d", &numLines); 
    59      
     36    sscanf(currLine.c_str(), "%d", &numLines); 
     37    cout << currLine << endl; 
    6038    int lineNum = 0; 
    6139    long lds = 0; 
     
    6947    short dropNum = 0; 
    7048    int routeNum = 0; 
    71     char * direction = ""; 
    7249    float postmile = 0; 
    7350    long loopID = 0; 
    7451    float occ = 0; 
    7552    int vol = 0; 
    76      
     53    char loopLoc[25]; 
    7754    for(int lineIndex = 0; lineIndex < numLines; lineIndex++) 
    7855    { 
    7956        FEP_LINE * newLine = new FEP_LINE; 
    8057         
    81         getline(highwaysData, currLine); 
     58        getline(highwaysStream, currLine); 
    8259        int numStations = 0; 
    83         sscanf(currLine, "%d %d %d", &lineNum, &count, &numStations); 
    84  
     60        sscanf(currLine.c_str(), "%d %hd %d", &lineNum, &count, &numStations); 
     61        cout << "Line num: " << lineNum << endl; 
     62        cout << "Count: " << count << endl; 
     63        cout << "numStations: " << numStations << endl; 
    8564        newLine->lineNum = lineNum; 
    8665        newLine->count = count; 
     
    9473        { 
    9574            STATION * newStation = new STATION; 
    96              
     75     
    9776            int numLoops = 0; 
    98             getline(highwaysData, currLine); 
    99             sscanf(currLine, "%ld %d %d %s %d %d", &lds, &dropNum,&routeNum,  
    100                     direction, postmile, &numLoops); 
    101              
     77            getline(highwaysStream, currLine); 
     78            cout << currLine << endl; 
     79            char direction; 
     80            sscanf(currLine.c_str(), "%ld %hd %d %c %f %d", &lds, &dropNum, &routeNum, &direction, 
     81                    &postmile, &numLoops); 
     82            cout << "NumberLoops: " << numLoops << endl; 
     83            cout << "DropNum: " << dropNum << endl; 
     84            cout << "LDS: " << lds << endl; 
     85            cout << "LDSIndex: " << ldsIndex << endl; 
     86            cout << "postmile: " << postmile << endl; 
    10287            newLine->lds.push_back(lds); 
    10388            newLine->ldsIndex.push_back(ldsIndex++); 
     89            newStation->lds = lds; 
     90            newStation->line_num = lineNum; 
     91            newStation->drop = dropNum; 
     92            newStation->pos = 0; 
     93            newStation->MlTotVol = 0; 
     94            newStation->OppTotVol = 0; 
    10495             
    10596            for(int loopIndex = 0; loopIndex < numLoops; loopIndex++) 
    10697            { 
    107                 getline(highwaysData, currLine); 
    108                 sscanf(currLine, "%ld %f %d", &loopID, &occ, &vol); 
     98                LOOP * newLoop = new LOOP; 
     99                 
     100                getline(highwaysStream, currLine); 
     101                cout << currLine << endl; 
     102                sscanf(currLine.c_str(), "%ld %f %d %s", &loopID, &occ, &vol, loopLoc); 
     103                cout << "LOOP ID: " << loopID << endl; 
     104                cout << "OCC: " << occ << endl; 
     105                cout << "VOL: " << vol << endl; 
     106                cout << "LOOPLOC: " << loopLoc << endl; 
     107                newLoop->loopID = loopID; 
     108                newLoop->occ = occ; 
     109                newLoop->vol = vol; 
     110                newLoop->loop_loc = loopLoc; 
     111                 
     112                newStation->loops.push_back(newLoop); 
    109113            } 
     114            newStation->length = newStation->loops.size() * 2 + CONTROL_DATA_LEN; 
     115            newStation->dataPack = DataPacker::packData(newStation); 
     116             
     117            cout << "NUMBER OF LOOPS: " << newStation->loops.size() << endl; 
     118             
     119            this->stations.push_back(newStation); 
    110120        } 
    111121         
     
    113123    } 
    114124} 
    115  
    116 FEP_LINE * HighwaysParser::parseLine(istringstream highwaysData) 
    117 { 
    118  
    119 } 
    120  
    121 STATION * HighwaysParser::parseStation(istringstream highwaysData) 
    122 { 
    123      
    124 } 
    125  
    126 LOOP * HighwaysParser::parseLoop(istringstream highwaysData) 
    127 { 
    128      
    129 } 
Note: See TracChangeset for help on using the changeset viewer.