| 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 | * */ |
|---|
| 22 | HighwaysParser::HighwaysParser(char * hwyData) { |
|---|
| 23 | parseLines(hwyData); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | HighwaysParser::~HighwaysParser() { |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | void 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 | char direction; |
|---|
| 79 | sscanf(currLine.c_str(), "%ld %hd %d %c %f %d", &lds, &dropNum, &routeNum, &direction, |
|---|
| 80 | &postmile, &numLoops); |
|---|
| 81 | newLine->lds.push_back(lds); |
|---|
| 82 | newLine->ldsIndex.push_back(ldsIndex++); |
|---|
| 83 | newStation->lds = lds; |
|---|
| 84 | newStation->line_num = lineNum; |
|---|
| 85 | newStation->drop = dropNum; |
|---|
| 86 | newStation->pos = 0; |
|---|
| 87 | newStation->MlTotVol = 0; |
|---|
| 88 | newStation->OppTotVol = 0; |
|---|
| 89 | |
|---|
| 90 | for(int loopIndex = 0; loopIndex < numLoops; loopIndex++) |
|---|
| 91 | { |
|---|
| 92 | LOOP * newLoop = new LOOP; |
|---|
| 93 | |
|---|
| 94 | getline(highwaysStream, currLine); |
|---|
| 95 | cout << currLine << endl; |
|---|
| 96 | sscanf(currLine.c_str(), "%ld %f %d %s", &loopID, &occ, &vol, loopLoc); |
|---|
| 97 | newLoop->loopID = loopID; |
|---|
| 98 | newLoop->occ = occ; |
|---|
| 99 | newLoop->vol = vol; |
|---|
| 100 | newLoop->spd = 0; |
|---|
| 101 | newLoop->loop_loc = loopLoc; |
|---|
| 102 | cout << "Adding " << newLoop->loopID << " to " << newStation->lds << endl; |
|---|
| 103 | newStation->loops.push_back(newLoop); |
|---|
| 104 | } |
|---|
| 105 | newStation->length = newStation->loops.size() * 2 + CONTROL_DATA_LEN; |
|---|
| 106 | newStation->dataPack = DataPacker::packData(newStation); |
|---|
| 107 | for(int byte = 0; byte < newStation->length; byte++) |
|---|
| 108 | { |
|---|
| 109 | printf("%02X", (unsigned char) newStation->dataPack[byte]); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | cout << "Adding " << newStation->lds << " to ldsMap " << " at index " << ldsIndex << endl; |
|---|
| 113 | this->stations.push_back(newStation); |
|---|
| 114 | } |
|---|
| 115 | cout << "Adding " << newLine->lineNum << " to lines" << endl; |
|---|
| 116 | this->lines.push_back(newLine); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|