source: tmcsimulator/branches/FEPSimulator/HighwaysParser.cpp @ 202

Revision 202, 4.2 KB checked in by jtorres, 9 years ago (diff)

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

Line 
1/*
2 * File:   HighwaysParser.cpp
3 * Author: jtorres
4 *
5 * Created on October 28, 2017, 7:23 PM
6 */
7
8#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      * */
22HighwaysParser::HighwaysParser(char * hwyData) {
23    parseLines(hwyData);
24}
25
26HighwaysParser::~HighwaysParser() {
27}
28
29void HighwaysParser::parseLines(char * hwyData)
30{
31    string highwaysData = hwyData;
32    istringstream highwaysStream(highwaysData);
33    string currLine;
34    getline(highwaysStream, currLine);
35    int numLines;
36    sscanf(currLine.c_str(), "%d", &numLines);
37    cout << currLine << endl;
38    int lineNum = 0;
39    long lds = 0;
40    long ldsIndex = 0;
41    short count = 0;
42    int schedule = 0;
43    int lineInfo = 0;
44    long systemKey = 0;
45    long globalSeq = 0;
46    long schedleSeq = 0;
47    short dropNum = 0;
48    int routeNum = 0;
49    float postmile = 0;
50    long loopID = 0;
51    float occ = 0;
52    int vol = 0;
53    char loopLoc[25];
54    for(int lineIndex = 0; lineIndex < numLines; lineIndex++)
55    {
56        FEP_LINE * newLine = new FEP_LINE;
57       
58        getline(highwaysStream, currLine);
59        int numStations = 0;
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;
64        newLine->lineNum = lineNum;
65        newLine->count = count;
66        newLine->schedule = schedule;
67        newLine->lineInfo = lineInfo;
68        newLine->systemKey = systemKey;
69        newLine->globalSeq = globalSeq;
70        newLine->schedleSeq = schedleSeq;
71       
72        for(int stationIndex = 0; stationIndex < numStations; stationIndex++)
73        {
74            STATION * newStation = new STATION;
75   
76            int numLoops = 0;
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;
87            newLine->lds.push_back(lds);
88            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;
95           
96            for(int loopIndex = 0; loopIndex < numLoops; loopIndex++)
97            {
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);
113            }
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);
120        }
121       
122        this->lines.push_back(newLine);
123    }
124}
Note: See TracBrowser for help on using the repository browser.