Changeset 79 in tmcsimulator for branches/fep_rpc_client
- Timestamp:
- 10/05/2017 12:51:23 PM (9 years ago)
- Location:
- branches/fep_rpc_client
- Files:
-
- 14 added
- 12 edited
-
DataPacker.cpp (added)
-
DataPacker.h (added)
-
FEPClient.cpp (modified) (6 diffs)
-
FEPClient.h (modified) (2 diffs)
-
NetworkReader.cpp (modified) (3 diffs)
-
NetworkReader.h (modified) (4 diffs)
-
build/Debug/GNU-Linux-x86/DataPacker.o.d (added)
-
build/Debug/GNU-Linux-x86/FEPClient.o.d (modified) (2 diffs)
-
build/Debug/GNU-Linux-x86/NetworkReader.o.d (modified) (2 diffs)
-
dist/Debug/GNU-Linux-x86/fep_rpc_client (modified) (previous)
-
nbproject/Makefile-Debug.mk (modified) (3 diffs)
-
nbproject/Makefile-Release.mk (modified) (2 diffs)
-
nbproject/configurations.xml (modified) (4 diffs)
-
nbproject/private/private.xml (modified) (1 diff)
-
network.h (modified) (4 diffs)
-
tinyxml/tinystr.cpp (added)
-
tinyxml/tinystr.o (added)
-
tinyxml/tinyxml.a (added)
-
tinyxml/tinyxml.cpp (added)
-
tinyxml/tinyxml.o (added)
-
tinyxml/tinyxmlerror.cpp (added)
-
tinyxml/tinyxmlerror.o (added)
-
tinyxml/tinyxmlparser.cpp (added)
-
tinyxml/tinyxmlparser.o (added)
-
tinyxml/xmltest.cpp (added)
-
tinyxml/xmltest.o (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/fep_rpc_client/FEPClient.cpp
r78 r79 7 7 * @param networkFile the xml network file 8 8 */ 9 FEPClient::FEPClient(char * host, char * networkFile) 10 { 11 createClient(host); 12 networkReader = new NetworkReader(networkFile); 13 updateATMS(); 9 FEPClient::FEPClient(char * host, char * networkFile) { 10 networkReader = new NetworkReader(networkFile); 11 createClient(host); 12 updateATMS(); 14 13 } 15 14 … … 17 16 * Destructor 18 17 */ 19 FEPClient::~FEPClient() 20 { 21 cout << "Destroying client..." << endl; 22 clnt_destroy(clnt); 18 FEPClient::~FEPClient() { 19 cout << "Destroying client..." << endl; 20 clnt_destroy(clnt); 23 21 } 24 22 … … 27 25 * @param response pointer to fep_reply struct 28 26 */ 29 void FEPClient::handleCallResponse(void *response) 30 { 31 /* If ATMS reply call fails */ 32 if (response == NULL) 33 { 34 clnt_perror(clnt, "RPC call failed"); 35 } 36 /* If ATMS reply is successful */ 37 else 38 { 39 cout << "Successful RPC call to ATMS..." << endl; 40 } 27 void FEPClient::handleCallResponse(void *response) { 28 /* If ATMS reply call fails */ 29 if (response == NULL) { 30 clnt_perror(clnt, "RPC call failed"); 31 } /* If ATMS reply is successful */ 32 else { 33 cout << "Successful RPC call to ATMS..." << endl; 34 } 41 35 } 42 36 … … 44 38 * Sends an fep_reply for every line in the FEP. 45 39 */ 46 void FEPClient::updateATMS() 47 { 48 int i, j; // i == line_index, j == lds_index 49 void *rv; 40 void FEPClient::updateATMS() { 41 int i, j; // i == line_index, j == lds_index 42 void *rv; 50 43 51 vector<FEP_LINE > lines = networkReader->getLines();52 vector<LDS_LOOP > ldsMap = networkReader->getStations();44 vector<FEP_LINE*> lines = networkReader->getLines(); 45 vector<LDS_LOOP*> ldsMap = networkReader->getStations(); 53 46 54 // Send one reply for every "line" in the FEP 55 for (i = 0; i < lines.size(); i++) 56 { 57 fep_reply fepReply; 58 cout << "Sending fepReply for line #" << lines.at(i).lineNum << endl; 59 // populate reply 60 fepReply.reply = SHORTPOLL; 61 fepReply.schedule = lines.at(i).schedule; 62 fepReply.lineinfo = lines.at(i).lineInfo; 63 fepReply.kind = (enum polltype) 0; 64 fepReply.flag = (enum replykind) 0; 47 // Send one reply for every "line" in the FEP 48 for (i = 0; i < lines.size(); i++) { 49 fep_reply fepReply; 50 cout << "Sending fepReply for line #" << lines.at(i)->lineNum << endl; 51 // populate reply 52 fepReply.reply = SHORTPOLL; 53 fepReply.schedule = lines.at(i)->schedule; 54 fepReply.lineinfo = lines.at(i)->lineInfo; 55 fepReply.kind = (enum polltype) 0; 56 fepReply.flag = (enum replykind) 0; 65 57 66 /***********************************67 This is an update to an extern, this should happen on the Java driver side??68 lines.at(i).schedleSeq += 1;69 lines.at(i).globalSeq += 51;70 */58 /*********************************** 59 This is an update to an extern, this should happen on the Java driver side?? 60 lines.at(i).schedleSeq += 1; 61 lines.at(i).globalSeq += 51; 62 */ 71 63 72 fepReply.schedule_sequence = lines.at(i).schedleSeq;73 fepReply.global_sequence = lines.at(i).globalSeq;74 /************************************75 Need to find out what appropriate schedule time is: look at uci_unix_simulation_time src code76 fepReply.schedule_time =77 uci_unix_simulation_time(uci_simulation_time()); // GMT time78 */79 fepReply.schedule_time = time(NULL);64 fepReply.schedule_sequence = lines.at(i)->schedleSeq; 65 fepReply.global_sequence = lines.at(i)->globalSeq; 66 /************************************ 67 Need to find out what appropriate schedule time is: look at uci_unix_simulation_time src code 68 fepReply.schedule_time = 69 uci_unix_simulation_time(uci_simulation_time()); // GMT time 70 */ 71 fepReply.schedule_time = time(NULL); 80 72 81 fepReply.user_info1 = lines.at(i).lineNum;82 fepReply.user_info2 = lines.at(i).lineNum;83 fepReply.system_key = lines.at(i).systemKey;73 fepReply.user_info1 = lines.at(i)->lineNum; 74 fepReply.user_info2 = lines.at(i)->lineNum; 75 fepReply.system_key = lines.at(i)->systemKey; 84 76 85 fepReply.answers.size = 1;86 fepReply.answers.fep_answer_list_u.shortp.count = 1;77 fepReply.answers.size = 1; 78 fepReply.answers.fep_answer_list_u.shortp.count = 1; 87 79 88 /* for each LDS in the Line.... (constructs the short_answer message) */ 89 for (j = 0; j < lines.at(i).lds.size(); j++) 90 { 91 fep_shortanswer fsa; 92 int index = lines.at(i).ldsIndex.at(j); 93 cout << "LDS index: " << index << endl; 94 // msg: oa, od, ldsMap.at(index).dataPack, od, ff 95 fsa.msg.message_len = ldsMap.at(index).length + 2; 96 fsa.msg.message[0] = 0x0d; 97 fsa.msg.message[1] = 0x0a; 98 for (int k = 0; k < ldsMap.at(index).length; k++) 99 fsa.msg.message[2 + k] = ldsMap.at(index).dataPack[k]; 100 int aa = ldsMap.at(index).length; 101 fsa.msg.message[2 + aa] = 0x0d; 102 fsa.msg.message[3 + aa] = 0xff; //????????????? warning ????? 80 /* for each LDS in the Line.... (constructs the short_answer message) */ 81 for (j = 0; j < lines.at(i)->lds.size(); j++) { 82 fep_shortanswer fsa; 83 int index = lines.at(i)->ldsIndex.at(j); 84 cout << "LDS index: " << index << endl; 85 // msg: oa, od, ldsMap.at(index).dataPack, od, ff 86 fsa.msg.message_len = ldsMap.at(index)->length + 2; 87 fsa.msg.message[0] = 0x0d; 88 fsa.msg.message[1] = 0x0a; 89 for (int k = 0; k < ldsMap.at(index)->length; k++) 90 fsa.msg.message[2 + k] = ldsMap.at(index)->dataPack[k]; 91 int aa = ldsMap.at(index)->length; 92 fsa.msg.message[2 + aa] = 0x0d; 93 fsa.msg.message[3 + aa] = 0xff; //????????????? warning ????? 103 94 104 // info105 fsa.info.poll_error_count = 0;106 /***************************************107 Need to find out polltime uci time function src code108 fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time());109 */110 fsa.info.poll_user_info1 = ldsMap.at(index).drop;// drop number111 fsa.info.poll_user_info2 = 1;//always 1112 fsa.info.retries = 0;113 fsa.info.status = (enum replystatus) 1;95 // info 96 fsa.info.poll_error_count = 0; 97 /*************************************** 98 Need to find out polltime uci time function src code 99 fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time()); 100 */ 101 fsa.info.poll_user_info1 = ldsMap.at(index)->drop; // drop number 102 fsa.info.poll_user_info2 = 1; //always 1 103 fsa.info.retries = 0; 104 fsa.info.status = (enum replystatus) 1; 114 105 115 //fepReply.answers.fep_answer_list_u.shortp.answers[j] = fsa;116 fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa;106 //fepReply.answers.fep_answer_list_u.shortp.answers[j +1] = fsa; 107 fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa; 117 108 118 // send out data119 printf("Transferring line=%d, lds_drop_no=%d...\n", lines.at(i).lineNum, ldsMap.at(index).drop);120 rv = fep_reply_xfer_32(&fepReply, clnt);109 // send out data 110 printf("Transferring line=%d, lds_drop_no=%d...\n", lines.at(i)->lineNum, ldsMap.at(index)->drop); 111 rv = fep_reply_xfer_32(&fepReply, clnt); 121 112 122 /* Handle ATMS response to RPC Call */123 printf("Handling ATMS response...\n");124 handleCallResponse(rv);125 }126 }113 /* Handle ATMS response to RPC Call */ 114 printf("Handling ATMS response...\n"); 115 handleCallResponse(rv); 116 } 117 } 127 118 } 128 119 … … 131 122 * @param host rpc server ip 132 123 */ 133 void FEPClient::createClient(char * host) 134 { 135 /* Create RPC Client to communicate with ATMS */ 136 cout << "Creating RPC Client" << endl; 137 clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp"); 138 cout << "Client created" << endl; 139 /* Check if client creation failed */ 140 if (clnt == (CLIENT *) NULL) 141 { 142 cerr << "Can't create client to " << host << endl; 143 exit(1); 144 } 124 void FEPClient::createClient(char * host) { 125 /* Create RPC Client to communicate with ATMS */ 126 cout << "Creating RPC Client" << endl; 127 clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp"); 128 cout << "Client created" << endl; 129 /* Check if client creation failed */ 130 if (clnt == (CLIENT *) NULL) { 131 cerr << "Can't create client to " << host << endl; 132 exit(1); 133 } 145 134 } 146 135 … … 153 142 int main(int argc, char *argv[]) { 154 143 155 char *host;156 char *networkFile;144 char *host; 145 char *networkFile; 157 146 158 if (argc < 3) 159 { 160 cout << "usage: " << argv[0] << " server_host networkFile" << endl; 161 exit(1); 162 } 147 if (argc < 3) { 148 cout << "usage: " << argv[0] << " server_host networkFile" << endl; 149 exit(1); 150 } 163 151 164 /* Create RPC Client to send an fep_reply to ATMS */165 host = argv[1];166 networkFile = argv[2];152 /* Create RPC Client to send an fep_reply to ATMS */ 153 host = argv[1]; 154 networkFile = argv[2]; 167 155 168 FEPClient *client = new FEPClient(host, networkFile);169 delete client;156 FEPClient *client = new FEPClient(host, networkFile); 157 delete client; 170 158 171 return 0;159 return 0; 172 160 } -
branches/fep_rpc_client/FEPClient.h
r77 r79 1 /* The FEPClient is an RPC Client which transfers network data to the 1 /* 2 * File: FEPClient.h 3 * 4 * The FEPClient is an RPC Client which transfers network data to the 2 5 * ATMS Server. 3 6 * … … 14 17 * @version 9/8/2017 15 18 */ 19 16 20 // Include guard 17 21 #ifndef __FEPCLIENT_H_INCLUDED__ -
branches/fep_rpc_client/NetworkReader.cpp
r78 r79 10 10 } 11 11 12 LOOP * NetworkReader::parseLoop(TiXmlElement * loopElem) { 13 LOOP *loop = new LOOP; 14 15 TiXmlElement *subLoopElem = loopElem->FirstChildElement(); 16 loop->loopID = atoi(subLoopElem->GetText()); 17 cout << "LOOPID: " << subLoopElem->GetText() << endl; 18 subLoopElem = subLoopElem->NextSiblingElement(); 19 loop->loop_loc = (char *) subLoopElem->GetText(); 20 subLoopElem = subLoopElem->NextSiblingElement(); 21 loop->vol = atoi(subLoopElem->GetText()); 22 subLoopElem = subLoopElem->NextSiblingElement(); 23 loop->occ = atof(subLoopElem->GetText()); 24 subLoopElem = subLoopElem->NextSiblingElement(); 25 loop->spd = atof(subLoopElem->GetText()); 26 27 return loop; 28 } 29 12 30 /** 13 31 * Parses a station xml element into an "LDS_LOOP" … … 17 35 * @return the new station 18 36 */ 19 LDS_LOOP NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) {20 LDS_LOOP station;21 37 LDS_LOOP * NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) { 38 LDS_LOOP *station = new LDS_LOOP; 39 22 40 TiXmlElement *stationSubElem = stationElem->FirstChildElement(); 23 cout << "Station id: " << stationSubElem->GetText() << endl; 24 station.lds = atol(stationSubElem->GetText()); 25 line->lds.push_back(station.lds); 41 station->lds = atol(stationSubElem->GetText()); 42 line->lds.push_back(station->lds); 26 43 line->ldsIndex.push_back(ldsIndex++); 27 44 stationSubElem = stationSubElem->NextSiblingElement(); 28 station .line_num = atoi(stationSubElem->GetText());45 station->line_num = atoi(stationSubElem->GetText()); 29 46 stationSubElem = stationSubElem->NextSiblingElement(); 30 station .drop = atoi(stationSubElem->GetText());47 station->drop = atoi(stationSubElem->GetText()); 31 48 stationSubElem = stationSubElem->NextSiblingElement(); 32 49 stationSubElem = stationSubElem->NextSiblingElement(); // skip location … … 34 51 stationSubElem = stationSubElem->NextSiblingElement(); // skip direction 35 52 stationSubElem = stationSubElem->NextSiblingElement(); // skip freeway 36 station .MlTotVol = atoi(stationSubElem->GetText());53 station->MlTotVol = atoi(stationSubElem->GetText()); 37 54 stationSubElem = stationSubElem->NextSiblingElement(); 38 station .OppTotVol = atoi(stationSubElem->GetText());55 station->OppTotVol = atoi(stationSubElem->GetText()); 39 56 40 station.pos = 0; 57 station->pos = 0; // NOT SURE WHY WE NEED THIS? 58 41 59 // Add loops to station 42 TiXmlElement *loopsElem = stationSubElem->NextSiblingElement(); 43 TiXmlElement *loopElem = loopsElem->FirstChildElement(); 44 TiXmlElement *saveLoopElem = loopElem; 45 // get number of loops in station and assign to station.num 46 station.num = 0; 60 TiXmlElement *loopElem = stationSubElem->NextSiblingElement()->FirstChildElement(); 47 61 for (loopElem; loopElem; loopElem = loopElem->NextSiblingElement()) { 48 station.num += 1; 62 LOOP *loop = parseLoop(loopElem); 63 station->loops.push_back(loop); 49 64 } 50 65 51 // get loopIDS and locations 52 long int loopIDS[station.num]; 53 char * loopLocs[station.num]; 54 int index = 0; 55 for (saveLoopElem; saveLoopElem; saveLoopElem = saveLoopElem->NextSiblingElement()) { 56 TiXmlElement *subLoopElem = saveLoopElem->FirstChildElement(); 57 loopIDS[index] = atoi(subLoopElem->GetText()); 58 subLoopElem = subLoopElem->NextSiblingElement(); 59 loopLocs[index++] = (char *) subLoopElem->GetText(); 66 // Data pack ATMS message 67 station->length = station->loops.size() * 2 + CONTROL_DATA_LEN; 68 cout << station->loops.size() << endl; 69 station->dataPack = DataPacker::packData(station); 70 71 return station; 72 } 73 74 /** 75 * Parses a "Line" xml element into an FEP_LINE 76 * @param lineElem the xml element 77 * @return FEP_LINE 78 */ 79 FEP_LINE * NetworkReader::parseLine(TiXmlElement * lineElem) { 80 FEP_LINE *line = new FEP_LINE; 81 82 TiXmlElement *lineSubElem = lineElem->FirstChildElement(); 83 line->lineNum = atoi(lineSubElem->GetText()); 84 cout << "Line: " << line->lineNum << endl; 85 lineSubElem = lineSubElem->NextSiblingElement(); 86 line->count = atoi(lineSubElem->GetText()); 87 lineSubElem = lineSubElem->NextSiblingElement(); 88 line->schedule = atoi(lineSubElem->GetText()); 89 lineSubElem = lineSubElem->NextSiblingElement(); 90 line->lineInfo = atoi(lineSubElem->GetText()); 91 lineSubElem = lineSubElem->NextSiblingElement(); 92 line->systemKey = atol(lineSubElem->GetText()); 93 lineSubElem = lineSubElem->NextSiblingElement(); 94 line->globalSeq = atol(lineSubElem->GetText()); 95 lineSubElem = lineSubElem->NextSiblingElement(); 96 line->schedleSeq = atol(lineSubElem->GetText()); 97 98 TiXmlElement *stationsElem = lineSubElem->NextSiblingElement(); 99 TiXmlElement *stationElem = stationsElem->FirstChildElement(); 100 for (stationElem; stationElem; stationElem = stationElem->NextSiblingElement()) { 101 stations.push_back(parseStation(stationElem, line)); 60 102 } 61 station.loopID = loopIDS;62 station.loop_loc = loopLocs; 103 return line; 104 } 63 105 64 // Data pack ATMS message 65 station.length = station.num * 2 + CONTROL_DATA_LEN; 66 station.dataPack = staticDataPack(station); 67 /* 68 // fill in dynamic data to dataPack[] 69 for (i = 0; i < g_ldsNum; i++) { 70 // Loop detector data 71 int pos = 26; 72 pos = pp_data_packing(i, 5, pos); 73 pos = pp_data_packing(i, 6, pos); 74 pos = pp_data_packing(i, 7, pos); 75 pos = pp_data_packing(i, 8, pos); 76 77 // Update data for BYTE 9, 16, 21, 22, 23, 24 78 79 // what is the current metering rate? 80 // check each LDS, if there is demand detector, the downstream node the 81 // ldsMap[i].dataPack[22-1] = ldsMap[i].dataPack[9-1] = ; 82 83 // will need to check if queue override is enabled (Currently, no queue 84 // ldsMap[i].dataPack[16-1] = ; 85 86 // byte 23: MAINLINE total volume 87 ldsMap[i].dataPack[23 - 1] = ldsMap[i].MlTotVol; 88 89 // byte 24: opposite total volume 90 ldsMap[i].dataPack[24 - 1] = ldsMap[i].OppTotVol; 91 92 // last BYTE: checksum 93 ldsMap[i].dataPack[ldsMap[i].length - 1] = 94 chksum(ldsMap[i].dataPack, ldsMap[i].length - 1 - 1); 95 96 // print out 97 // print out 98 for (j = 0; j < ldsMap[i].length; j++) { 99 fprintf(fi_lds, "%02X", ldsMap[i].dataPack[j]); 100 } 101 fprintf(fi_lds, "\n"); 102 fflush(fi_lds); 103 */ 104 105 return station; 106 /** 107 * Loads FEPLines from a specified xml file 108 * @param networkFileName the input xml file 109 */ 110 void NetworkReader::loadLines(const char * networkFileName) { 111 // Load network xml file 112 TiXmlDocument doc(networkFileName); 113 if (!doc.LoadFile()) { 114 cerr << "TiXmlDocument did not load network file..." << endl; 115 return; 106 116 } 107 117 108 /** 109 * Parses a "Line" xml element into an FEP_LINE 110 * @param lineElem the xml element 111 * @return FEP_LINE 112 */ 113 FEP_LINE NetworkReader::parseLine(TiXmlElement * lineElem) { 114 FEP_LINE line; 115 TiXmlElement *lineSubElem = lineElem->FirstChildElement(); 116 line.lineNum = atoi(lineSubElem->GetText()); 117 cout << "Line: " << line.lineNum << endl; 118 lineSubElem = lineSubElem->NextSiblingElement(); 119 line.count = atoi(lineSubElem->GetText()); 120 lineSubElem = lineSubElem->NextSiblingElement(); 121 line.schedule = atoi(lineSubElem->GetText()); 122 lineSubElem = lineSubElem->NextSiblingElement(); 123 line.lineInfo = atoi(lineSubElem->GetText()); 124 lineSubElem = lineSubElem->NextSiblingElement(); 125 line.systemKey = atol(lineSubElem->GetText()); 126 lineSubElem = lineSubElem->NextSiblingElement(); 127 line.globalSeq = atol(lineSubElem->GetText()); 128 lineSubElem = lineSubElem->NextSiblingElement(); 129 line.schedleSeq = atol(lineSubElem->GetText()); 118 // grab <Network> element 119 TiXmlHandle hDoc(&doc); 120 TiXmlElement *networkElem = hDoc.FirstChildElement().Element(); 130 121 131 TiXmlElement *stationsElem = lineSubElem->NextSiblingElement();132 TiXmlElement *stationElem = stationsElem->FirstChildElement();133 for (stationElem; stationElem; stationElem = stationElem->NextSiblingElement()) { 134 stations.push_back(parseStation(stationElem, &line));135 }136 return line;122 // grab first <Line> element 123 TiXmlElement *lineElem = networkElem->FirstChildElement(); 124 125 // iterate through each line element to create FEP_LINE list 126 for (lineElem; lineElem; lineElem = lineElem->NextSiblingElement()) { 127 lines.push_back(parseLine(lineElem)); 137 128 } 129 } 138 130 139 /** 140 * Loads FEPLines from a specified xml file 141 * @param networkFileName the input xml file 142 */ 143 void NetworkReader::loadLines(const char * networkFileName) { 144 // Load network xml file 145 TiXmlDocument doc(networkFileName); 146 if (!doc.LoadFile()) { 147 cerr << "TiXmlDocument did not load network file..." << endl; 148 return; 149 } 131 /** 132 * Getter for lines 133 * @return List of FEP_LINES 134 */ 135 vector<FEP_LINE*> NetworkReader::getLines() { 150 136 151 // grab <Network> element 152 TiXmlHandle hDoc(&doc); 153 TiXmlElement *networkElem = hDoc.FirstChildElement().Element(); 137 return lines; 138 } 154 139 155 // grab first <Line> element 156 TiXmlElement *lineElem = networkElem->FirstChildElement(); 140 /** 141 * Getter for stations 142 * @return List of LDS_LOOPs 143 */ 144 vector<LDS_LOOP*> NetworkReader::getStations() { 157 145 158 // iterate through each line element to create FEP_LINE list 159 for (lineElem; lineElem; lineElem = lineElem->NextSiblingElement()) { 160 lines.push_back(parseLine(lineElem)); 161 } 162 } 146 return stations; 147 } 163 148 164 // determine if a loop has data based on lane config data 149 NetworkReader::~NetworkReader() { 165 150 166 bool NetworkReader::DataAvail(char flag, int num) { 167 int mag, fel; 168 169 // find mask value 170 if (num == 1) 171 mag = 0x01; 172 else if (num == 2) 173 mag = 0x02; 174 else if (num == 3) 175 mag = 0x04; 176 else if (num == 4) 177 mag = 0x08; 178 else if (num == 5) 179 mag = 0x10; 180 else if (num == 6) 181 mag = 0x20; 182 else if (num == 7) 183 mag = 0x40; 184 else if (num == 8) 185 mag = 0x80; 186 187 fel = flag & mag; 188 fel = fel >> (num - 1); 189 190 if (fel == 1) 191 return true; 192 else 193 return false; 194 } 195 /* 196 int pp_data_packing(int index, int packNo, int pos) { 197 int i, j, k, vol, occ, lane, haveData; 198 LOOPAGG in; 199 DETECTOR *aaa; 200 VOLOCC bbb; 201 long loop; 202 203 i = index; 204 205 //used for data byte 23 and 24 206 ldsMap[i].MlTotVol = 0; 207 ldsMap[i].OppTotVol = 0; 208 209 for (j = 1; j <= 8; j++) { 210 if (DataAvail(ldsMap[i].dataPack[packNo - 1], j)) { 211 // loop at bit j has data 212 for (k = 0; k < ldsMap[i].num; k++) { 213 // what's the corresponding loop of bit j 214 if (packNo == 5) 215 haveData = strcmp(ldsMap[i].loop_loc[k], dp5[j - 1]); 216 else if (packNo == 6) 217 haveData = strcmp(ldsMap[i].loop_loc[k], dp6[j - 1]); 218 else if (packNo == 7) 219 haveData = strcmp(ldsMap[i].loop_loc[k], dp7[j - 1]); 220 else if (packNo == 8) 221 haveData = strcmp(ldsMap[i].loop_loc[k], dp8[j - 1]); 222 else 223 return -1; 224 225 if (haveData == 0) { 226 loop = ldsMap[i].loopID[k]; 227 if (strcmp(chu[loop].paramicsName, "?") == 0) { 228 { 229 vol = 0; 230 occ = 900; 231 } else { 232 aaa = qpg_NET_detector(chu[loop].paramicsName); 233 Bool status = uci_loop_aggregation(qpg_DTC_index(aaa), POLLING 234 if (status) { 235 if (chu[loop].paramicsLane == 0) 236 lane = 0; 237 else 238 lane = chu[loop].paramicsLane - 1; 239 vol = in.vol[lane]; 240 occ = (int) (in.occ[lane] * 900 + 0.5); 241 // qps_GUI_printf("%d(%s), lane=%d, vol=%d(%d), occ=%.3f(%.3f, 242 // qpg_DTC_index(aaa), chu[loop].paramicsName, in.lane, in. 243 // vol, in.g_occ, in.occ[lane], occ); 244 } else 245 qps_GUI_printf("Data query error for %s\n", chu[loop].param 246 } 247 248 bbb = pp_vol_occ_word(vol, occ); 249 pos++; 250 ldsMap[i].dataPack[pos - 1] = bbb.high; 251 pos++; 252 ldsMap[i].dataPack[pos - 1] = bbb.low; 253 254 if (packNo == 5) { 255 ldsMap[i].MlTotVol += vol; 256 } else if (packNo == 6) { 257 258 ldsMap[i].OppTotVol += vol; 259 } 260 261 fprintf(fi_lds, "lds=%d, loop=%d, paramics=%s, lane=%d, vol=%d(%X 262 ldsMap[i].lds, loop, chu[loop].paramicsName, chu[loop].paramic 263 bbb.high, occ, bbb.low); 264 fflush(fi_lds); 265 } 266 } 267 } 268 } 269 270 return pos; 271 } 272 */ 273 // Initializes the LDS_LOOP dataPack with all necessary static data and default dynamic data 274 unsigned char * NetworkReader::staticDataPack(LDS_LOOP loop) { 275 int j; 276 // Allocate memory for dataPack 277 unsigned char *dataPack = (unsigned char *) calloc(1, sizeof (unsigned char) * loop.length); 278 279 // dataPack 5-8: lane config 280 char d5 = 0, d6 = 0, d7 = 0, d8 = 0; 281 for (j = 0; j < loop.num; j++) { 282 for (int k = 0; k < 8; k++) { 283 if (strcmp(loop.loop_loc[j], dp5[k]) == 0) 284 d5 += pow(2, k); 285 if (strcmp(loop.loop_loc[j], dp6[k]) == 0) 286 d6 += pow(2, k); 287 if (strcmp(loop.loop_loc[j], dp7[k]) == 0) 288 d7 += pow(2, k); 289 if (strcmp(loop.loop_loc[j], dp8[k]) == 0) 290 d8 += pow(2, k); 291 } 292 } 293 dataPack[5 - 1] = d5; 294 dataPack[6 - 1] = d6; 295 dataPack[7 - 1] = d7; 296 dataPack[8 - 1] = d8; 297 298 // dataPack 1: Drop number, i.e. station address 299 dataPack[1 - 1] = loop.drop; 300 301 // dataPack2 (2 bytes per loop) 302 dataPack[2 - 1] = loop.num * 2 + Fixed_Byte_To_Checksum; 303 304 // dataPacket 3 (lowbyte: # of mainline loops, highbyte: # of opposite loops) 305 int low = 0, high = 0; 306 for (j = 1; j <= 6; j++) { 307 low += DataAvail(dataPack[5 - 1], j); 308 high += DataAvail(dataPack[6 - 1], j); 309 } 310 high = high << 4; 311 dataPack[3 - 1] = high | low; 312 313 // dataPack4 (Miscl. flags: samples are: 80, A0, E0, 00) 314 dataPack[4 - 1] = 0xA0; 315 316 // dataPack 9: initialized as 00 (meaning no metering); need to be updated every 30 sec 317 dataPack[9 - 1] = 0; 318 319 // datadataPack 10-13: lane malfunction? Assuming all functional 320 dataPack[10 - 1] = 0; 321 dataPack[11 - 1] = 0; 322 dataPack[12 - 1] = 0; 323 dataPack[13 - 1] = 0; 324 325 // dataPack 14-22: ramp metering data 326 // BYTE 16 and 22 need to be updated every 30 sec 327 bool found = false; 328 for (j = 0; j < loop.num; j++) { 329 if (strcmp(loop.loop_loc[j], "DEMAND") == 0) { 330 found = true; 331 break; 332 } 333 } 334 if (found) { 335 // BYTE 14: mostly 07, some are 05, 03, 00 336 dataPack[14 - 1] = 0x07; 337 // mostly 06(TOD table 1); some are 0B (No metering) or 05(traffic responsive) 338 dataPack[15 - 1] = 0x06; 339 // most 00, some are 01 (queue override) or 80(Meter ON sign) 340 dataPack[16 - 1] = 0x00; 341 // Field Manual Rate 342 dataPack[17 - 1] = 0xFF; 343 // TOC Manual Rate 344 dataPack[18 - 1] = 0xFF; 345 // PSO Manual Rate 346 dataPack[19 - 1] = 0xFF; 347 // CORM Rate 348 dataPack[20 - 1] = 0xFF; 349 // Local Responsive Rate. DON'T UNDERSTAND YET 350 dataPack[21 - 1] = 0x00; 351 // TOD Rate: need to query RAMP plugin! 352 dataPack[22 - 1] = 0x00; 353 } // LDS: NO Metering 354 else { 355 dataPack[14 - 1] = 0x00; 356 dataPack[15 - 1] = 0x0B; 357 dataPack[16 - 1] = 0x00; 358 dataPack[17 - 1] = 0xFF; 359 dataPack[18 - 1] = 0xFF; 360 dataPack[19 - 1] = 0xFF; 361 dataPack[20 - 1] = 0xFF; 362 dataPack[21 - 1] = 0x00; 363 dataPack[22 - 1] = 0x00; 364 } 365 366 // dataPack 23-24: sum of mainline/Oppsite traffic data; need to be updated every 30 sec 367 loop.MlTotVol = 0; 368 loop.OppTotVol = 0; 369 dataPack[23 - 1] = loop.MlTotVol; 370 dataPack[24 - 1] = loop.OppTotVol; 371 372 // dataPack 25-26: BYTE 25 is fixed, i.e. 03; BYTE 26 is either 0xA2 or 0x84 373 dataPack[25 - 1] = 0x03; 374 dataPack[26 - 1] = 0x84; 375 376 return dataPack; 377 } 378 379 /** 380 * Getter for lines 381 * @return List of FEP_LINES 382 */ 383 vector<FEP_LINE> NetworkReader::getLines() { 384 385 return lines; 386 } 387 388 /** 389 * Getter for stations 390 * @return List of LDS_LOOPs 391 */ 392 vector<LDS_LOOP> NetworkReader::getStations() { 393 394 return stations; 395 } 396 397 NetworkReader::~NetworkReader() { 398 399 } 151 } -
branches/fep_rpc_client/NetworkReader.h
r78 r79 1 /** A NetworkReader reads in data about the traffic network from a specified 1 /** 2 * File: NetworkReader.h 3 * 4 * A NetworkReader reads in data about the traffic network from a specified 2 5 * xml file. 3 6 * … … 5 8 * which are getters for the list of FEP_LINES, and LDS_LOOPS, respectively. 6 9 * 7 * Example xmlfile:10 * Example XML file: 8 11 * <code> 9 12 * <Network> … … 47 50 #define __NETWORKREADER_H_INCLUDED__ 48 51 49 // Forward declared dependencies50 51 52 // Included dependencies 52 53 #include "network.h" 53 54 #include <vector> 54 #include <string>55 55 #include <string.h> 56 56 #include <iostream> 57 57 #include "tinyxml.h" 58 #include "DataPacker.h" 58 59 59 60 class NetworkReader … … 63 64 ~NetworkReader(); // Destructor 64 65 65 vector<FEP_LINE > getLines(); // Getter for FEP_LINE list66 vector<LDS_LOOP > getStations(); // Getter for LDS_LOOP list66 vector<FEP_LINE*> getLines(); // Getter for FEP_LINE list 67 vector<LDS_LOOP*> getStations(); // Getter for LDS_LOOP list 67 68 private: 68 vector<FEP_LINE > lines;69 vector<LDS_LOOP > stations;69 vector<FEP_LINE*> lines; 70 vector<LDS_LOOP*> stations; 70 71 int ldsIndex; 71 72 72 73 void loadLines(const char * networkFileName); 73 LDS_LOOP parseStation(TiXmlElement *stationElem, FEP_LINE *line); 74 FEP_LINE parseLine(TiXmlElement *lineElem); 75 76 bool DataAvail(char flag, int num); // Helper function for msgDataPack 77 unsigned char * staticDataPack(LDS_LOOP loop); // Packs the static data in message sent to ATMS 78 // int pp_data_packing(int index, int packNo, int pos); // Packs dynamic data in message sent to ATMS 74 LOOP * parseLoop(TiXmlElement * loopElem); 75 LDS_LOOP * parseStation(TiXmlElement *stationElem, FEP_LINE *line); 76 FEP_LINE * parseLine(TiXmlElement *lineElem); 79 77 }; 80 78 -
branches/fep_rpc_client/build/Debug/GNU-Linux-x86/FEPClient.o.d
r77 r79 1 1 build/Debug/GNU-Linux-x86/FEPClient.o: FEPClient.cpp FEPClient.h fep.h \ 2 NetworkReader.h network.h tinyxml/tinyxml.h tinyxml/tinystr.h 2 NetworkReader.h network.h tinyxml/tinyxml.h tinyxml/tinystr.h \ 3 DataPacker.h 3 4 4 5 FEPClient.h: … … 13 14 14 15 tinyxml/tinystr.h: 16 17 DataPacker.h: -
branches/fep_rpc_client/build/Debug/GNU-Linux-x86/NetworkReader.o.d
r77 r79 1 1 build/Debug/GNU-Linux-x86/NetworkReader.o: NetworkReader.cpp \ 2 NetworkReader.h network.h tinyxml/tinyxml.h tinyxml/tinystr.h 2 NetworkReader.h network.h tinyxml/tinyxml.h tinyxml/tinystr.h \ 3 DataPacker.h 3 4 4 5 NetworkReader.h: … … 9 10 10 11 tinyxml/tinystr.h: 12 13 DataPacker.h: -
branches/fep_rpc_client/nbproject/Makefile-Debug.mk
r77 r79 36 36 # Object Files 37 37 OBJECTFILES= \ 38 ${OBJECTDIR}/DataPacker.o \ 38 39 ${OBJECTDIR}/FEPClient.o \ 39 40 ${OBJECTDIR}/NetworkReader.o \ … … 56 57 57 58 # Link Libraries and Options 58 LDLIBSOPTIONS=tinyxml/ libtinyxml.a59 LDLIBSOPTIONS=tinyxml/tinyxml.a 59 60 60 61 # Build Targets … … 62 63 "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client 63 64 64 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: tinyxml/ libtinyxml.a65 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: tinyxml/tinyxml.a 65 66 66 67 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: ${OBJECTFILES} 67 68 ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 68 69 ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client ${OBJECTFILES} ${LDLIBSOPTIONS} 70 71 ${OBJECTDIR}/DataPacker.o: DataPacker.cpp 72 ${MKDIR} -p ${OBJECTDIR} 73 ${RM} "$@.d" 74 $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataPacker.o DataPacker.cpp 69 75 70 76 ${OBJECTDIR}/FEPClient.o: FEPClient.cpp -
branches/fep_rpc_client/nbproject/Makefile-Release.mk
r77 r79 36 36 # Object Files 37 37 OBJECTFILES= \ 38 ${OBJECTDIR}/DataPacker.o \ 38 39 ${OBJECTDIR}/FEPClient.o \ 39 40 ${OBJECTDIR}/NetworkReader.o \ … … 65 66 ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 66 67 ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client ${OBJECTFILES} ${LDLIBSOPTIONS} 68 69 ${OBJECTDIR}/DataPacker.o: DataPacker.cpp 70 ${MKDIR} -p ${OBJECTDIR} 71 ${RM} "$@.d" 72 $(COMPILE.cc) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataPacker.o DataPacker.cpp 67 73 68 74 ${OBJECTDIR}/FEPClient.o: FEPClient.cpp -
branches/fep_rpc_client/nbproject/configurations.xml
r77 r79 5 5 displayName="Header Files" 6 6 projectFiles="true"> 7 <itemPath>DataPacker.h</itemPath> 7 8 <itemPath>FEPClient.h</itemPath> 8 9 <itemPath>NetworkReader.h</itemPath> … … 17 18 displayName="Source Files" 18 19 projectFiles="true"> 20 <itemPath>DataPacker.cpp</itemPath> 19 21 <itemPath>FEPClient.cpp</itemPath> 20 22 <itemPath>NetworkReader.cpp</itemPath> … … 50 52 <linkerTool> 51 53 <linkerLibItems> 52 <linkerLibFileItem>tinyxml/ libtinyxml.a</linkerLibFileItem>54 <linkerLibFileItem>tinyxml/tinyxml.a</linkerLibFileItem> 53 55 </linkerLibItems> 54 56 </linkerTool> 55 57 </compileType> 58 <item path="DataPacker.cpp" ex="false" tool="1" flavor2="0"> 59 </item> 60 <item path="DataPacker.h" ex="false" tool="3" flavor2="0"> 61 </item> 56 62 <item path="FEPClient.cpp" ex="false" tool="1" flavor2="0"> 57 63 </item> … … 91 97 </asmTool> 92 98 </compileType> 99 <item path="DataPacker.cpp" ex="false" tool="1" flavor2="0"> 100 </item> 101 <item path="DataPacker.h" ex="false" tool="3" flavor2="0"> 102 </item> 93 103 <item path="FEPClient.cpp" ex="false" tool="1" flavor2="0"> 94 104 </item> -
branches/fep_rpc_client/nbproject/private/private.xml
r78 r79 8 8 <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> 9 9 <group> 10 <file>file:/home/andrew/tmcsim/branches/fep_rpc_client/NetworkReader.h</file> 11 <file>file:/home/andrew/tmcsim/branches/fep_rpc_client/FEPClient.cpp</file> 12 <file>file:/home/andrew/tmcsim/branches/fep_rpc_client/network.h</file> 13 <file>file:/home/andrew/tmcsim/branches/fep_rpc_client/fep.h</file> 14 <file>file:/home/andrew/tmcsim/branches/fep_rpc_client/NetworkReader.cpp</file> 10 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/NetworkReader.cpp</file> 11 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/NetworkReader.h</file> 12 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/network.h</file> 13 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/FEPClient.cpp</file> 14 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/fep.h</file> 15 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/DataPacker.h</file> 16 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/DataPacker.cpp</file> 17 <file>file:/home/andrew/tmcsimulator/branches/fep_rpc_client/FEPClient.h</file> 15 18 </group> 16 19 </open-files> -
branches/fep_rpc_client/network.h
r77 r79 11 11 const int Fixed_Byte_To_Checksum = 25; // the first byte is not considered in the calculation of "BYTE 2" 12 12 const int CONTROL_DATA_LEN = 27; 13 13 14 char * const dp5[8] = { "ML_1", "ML_2", "ML_3", "ML_4", "ML_5", 14 15 "ML_6", "HOV_Lane", "FYW_Conn"}; … … 20 21 "SD_6", "Pass_Vol_Count", "X"}; 21 22 22 /*** NETWORK STRUCTS ***/23 typedef struct loopagg LOOPAGG;24 struct loopagg25 {26 int index;27 char lane; // how namy lanes at the detector station28 long time;29 int interval;30 int g_vol;31 float g_occ;32 double g_spd;33 int *vol;34 float *occ;35 double *spd;36 };37 38 23 // FEP line: has several lds 39 24 typedef struct fep_line FEP_LINE; 40 25 struct fep_line 41 26 { 42 int lineNum; 43 vector<long> lds; 44 vector<long> ldsIndex; // location in ldsMap 45 short ldsNum; // actual number of lds on the line 27 int lineNum; 28 vector<long> lds; 29 vector<long> ldsIndex; // location in ldsMap 46 30 47 short count; // actual count from caltrans48 int schedule;49 int lineInfo;31 short count; // actual count from caltrans 32 int schedule; 33 int lineInfo; 50 34 long systemKey; 51 35 long globalSeq; 52 36 long schedleSeq; 37 }; 38 39 // Loop detector 40 typedef struct loop LOOP; 41 struct loop 42 { 43 long loopID; 44 char *loop_loc; 45 46 int vol; 47 float occ; 48 double spd; 53 49 }; 54 50 … … 61 57 short line_num; 62 58 short drop; 63 64 int num; // number of loops 65 long *loopID; 66 char **loop_loc; 59 60 vector<LOOP*> loops; 67 61 68 62 // LDS data … … 74 68 }; 75 69 70 typedef struct volOcc VOLOCC; 71 struct volOcc 72 { 73 char high; 74 char low; 75 }; 76 77 76 78 #endif
Note: See TracChangeset
for help on using the changeset viewer.
