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

Revision 209, 3.6 KB checked in by jtorres, 9 years ago (diff)

branches/FEPSimulator/tests: added unit test HighwaysParserTest?.cpp, which yielded a bug in HighwayParser?.cpp (not returning correct loop_loc... garbage data...), this likely explains why not all green dots were 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    int lineNum = 0;
38    long lds = 0;
39    long ldsIndex = 0;
40    short count = 0;
41    int schedule = 0;
42    int lineInfo = 0;
43    long systemKey = 0;
44    long globalSeq = 0;
45    long schedleSeq = 0;
46    short dropNum = 0;
47    int routeNum = 0;
48    float postmile = 0;
49    long loopID = 0;
50    float occ = 0;
51    int vol = 0;
52
53    for(int lineIndex = 0; lineIndex < numLines; lineIndex++)
54    {
55        FEP_LINE * newLine = new FEP_LINE;
56       
57        getline(highwaysStream, currLine);
58        int numStations = 0;
59        sscanf(currLine.c_str(), "%d %hd %d", &lineNum, &count, &numStations);
60        newLine->lineNum = lineNum;
61        newLine->count = count;
62        newLine->schedule = schedule;
63        newLine->lineInfo = lineInfo;
64        newLine->systemKey = systemKey;
65        newLine->globalSeq = globalSeq;
66        newLine->schedleSeq = schedleSeq;
67       
68        for(int stationIndex = 0; stationIndex < numStations; stationIndex++)
69        {
70            STATION * newStation = new STATION;
71   
72            int numLoops = 0;
73            getline(highwaysStream, currLine);
74            char direction;
75            sscanf(currLine.c_str(), "%ld %hd %d %c %f %d", &lds, &dropNum, &routeNum, &direction,
76                    &postmile, &numLoops);
77            newLine->lds.push_back(lds);
78            newLine->ldsIndex.push_back(ldsIndex++);
79            newStation->lds = lds;
80            newStation->line_num = lineNum;
81            newStation->drop = dropNum;
82            newStation->pos = 0;
83            newStation->MlTotVol = 0;
84            newStation->OppTotVol = 0;
85           
86            for(int loopIndex = 0; loopIndex < numLoops; loopIndex++)
87            {
88                LOOP * newLoop = new LOOP;
89               
90                getline(highwaysStream, currLine);
91                newLoop->loop_loc = (char *) malloc(25 * sizeof(char));
92                sscanf(currLine.c_str(), "%ld %f %d %s", &loopID, &occ, &vol, newLoop->loop_loc);
93                newLoop->loopID = loopID;
94                newLoop->occ = occ;
95                newLoop->vol = vol;
96                newLoop->spd = 0;
97                newStation->loops.push_back(newLoop);
98            }
99            newStation->length = newStation->loops.size() * 2 + CONTROL_DATA_LEN;
100            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");
106           
107            this->stations.push_back(newStation);
108        }
109        this->lines.push_back(newLine);
110    }
111}
Note: See TracBrowser for help on using the repository browser.