Changeset 79 in tmcsimulator for branches/fep_rpc_client


Ignore:
Timestamp:
10/05/2017 12:51:23 PM (9 years ago)
Author:
jtorres
Message:

new atmsdriver package in trunk. fep_rpc_client dynamic data packing added in branches. fep_rpc_client refactored data packing code into static DataPacker? class. Added vds_data folder into config/. Added new project configuration for ATMSDriver.

Location:
branches/fep_rpc_client
Files:
14 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/fep_rpc_client/FEPClient.cpp

    r78 r79  
    77 * @param networkFile the xml network file 
    88 */ 
    9 FEPClient::FEPClient(char * host, char * networkFile) 
    10 { 
    11         createClient(host); 
    12         networkReader = new NetworkReader(networkFile); 
    13         updateATMS(); 
     9FEPClient::FEPClient(char * host, char * networkFile) { 
     10    networkReader = new NetworkReader(networkFile); 
     11    createClient(host); 
     12    updateATMS(); 
    1413} 
    1514 
     
    1716 * Destructor 
    1817 */ 
    19 FEPClient::~FEPClient() 
    20 { 
    21         cout << "Destroying client..." << endl; 
    22         clnt_destroy(clnt); 
     18FEPClient::~FEPClient() { 
     19    cout << "Destroying client..." << endl; 
     20    clnt_destroy(clnt); 
    2321} 
    2422 
     
    2725 * @param response pointer to fep_reply struct 
    2826 */ 
    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         } 
     27void 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    } 
    4135} 
    4236 
     
    4438 * Sends an fep_reply for every line in the FEP. 
    4539 */ 
    46 void FEPClient::updateATMS() 
    47 { 
    48         int i, j; // i == line_index, j == lds_index 
    49         void *rv; 
     40void FEPClient::updateATMS() { 
     41    int i, j; // i == line_index, j == lds_index 
     42    void *rv; 
    5043 
    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(); 
    5346 
    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; 
    6557 
    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         */ 
    7163 
    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 code 
    76                 fepReply.schedule_time = 
    77                         uci_unix_simulation_time(uci_simulation_time());        // GMT time 
    78                 */ 
    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); 
    8072 
    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; 
    8476 
    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; 
    8779 
    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 ????? 
    10394 
    104                         // info 
    105                         fsa.info.poll_error_count = 0; 
    106                         /*************************************** 
    107                                 Need to find out polltime uci time function src code 
    108                         fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time()); 
    109                         */ 
    110                         fsa.info.poll_user_info1 = ldsMap.at(index).drop;       // drop number 
    111                         fsa.info.poll_user_info2 = 1;   //always 1 
    112                         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; 
    114105 
    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; 
    117108 
    118                         // send out data 
    119                         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); 
    121112 
    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    } 
    127118} 
    128119 
     
    131122 * @param host rpc server ip 
    132123 */ 
    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         } 
     124void 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    } 
    145134} 
    146135 
     
    153142int main(int argc, char *argv[]) { 
    154143 
    155         char *host; 
    156         char *networkFile; 
     144    char *host; 
     145    char *networkFile; 
    157146 
    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    } 
    163151 
    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]; 
    167155 
    168         FEPClient *client = new FEPClient(host, networkFile); 
    169         delete client; 
     156    FEPClient *client = new FEPClient(host, networkFile); 
     157    delete client; 
    170158 
    171         return 0; 
     159    return 0; 
    172160} 
  • 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 
    25 * ATMS Server. 
    36 * 
     
    1417 * @version 9/8/2017 
    1518 */ 
     19 
    1620// Include guard 
    1721#ifndef __FEPCLIENT_H_INCLUDED__ 
  • branches/fep_rpc_client/NetworkReader.cpp

    r78 r79  
    1010} 
    1111 
     12LOOP * 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 
    1230/** 
    1331 * Parses a station xml element into an "LDS_LOOP" 
     
    1735 * @return the new station 
    1836 */ 
    19 LDS_LOOP NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) { 
    20     LDS_LOOP station; 
    21  
     37LDS_LOOP * NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) { 
     38    LDS_LOOP *station = new LDS_LOOP; 
     39     
    2240    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); 
    2643    line->ldsIndex.push_back(ldsIndex++); 
    2744    stationSubElem = stationSubElem->NextSiblingElement(); 
    28     station.line_num = atoi(stationSubElem->GetText()); 
     45    station->line_num = atoi(stationSubElem->GetText()); 
    2946    stationSubElem = stationSubElem->NextSiblingElement(); 
    30     station.drop = atoi(stationSubElem->GetText()); 
     47    station->drop = atoi(stationSubElem->GetText()); 
    3148    stationSubElem = stationSubElem->NextSiblingElement(); 
    3249    stationSubElem = stationSubElem->NextSiblingElement(); // skip location 
     
    3451    stationSubElem = stationSubElem->NextSiblingElement(); // skip direction 
    3552    stationSubElem = stationSubElem->NextSiblingElement(); // skip freeway 
    36     station.MlTotVol = atoi(stationSubElem->GetText()); 
     53    station->MlTotVol = atoi(stationSubElem->GetText()); 
    3754    stationSubElem = stationSubElem->NextSiblingElement(); 
    38     station.OppTotVol = atoi(stationSubElem->GetText()); 
     55    station->OppTotVol = atoi(stationSubElem->GetText()); 
    3956 
    40     station.pos = 0; 
     57    station->pos = 0; // NOT SURE WHY WE NEED THIS? 
     58     
    4159    // 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(); 
    4761    for (loopElem; loopElem; loopElem = loopElem->NextSiblingElement()) { 
    48         station.num += 1; 
     62        LOOP *loop = parseLoop(loopElem); 
     63        station->loops.push_back(loop); 
    4964    } 
    5065 
    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 */ 
     79FEP_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)); 
    60102    } 
    61     station.loopID = loopIDS; 
    62     station.loop_loc = loopLocs; 
     103    return line; 
     104} 
    63105 
    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 */ 
     110void 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; 
    106116    } 
    107117 
    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(); 
    130121 
    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)); 
    137128    } 
     129} 
    138130 
    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 */ 
     135vector<FEP_LINE*> NetworkReader::getLines() { 
    150136 
    151         // grab <Network> element 
    152         TiXmlHandle hDoc(&doc); 
    153         TiXmlElement *networkElem = hDoc.FirstChildElement().Element(); 
     137    return lines; 
     138} 
    154139 
    155         // grab first <Line> element 
    156         TiXmlElement *lineElem = networkElem->FirstChildElement(); 
     140/** 
     141 * Getter for stations 
     142 * @return List of LDS_LOOPs 
     143 */ 
     144vector<LDS_LOOP*> NetworkReader::getStations() { 
    157145 
    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} 
    163148 
    164     // determine if a loop has data based on lane config data 
     149NetworkReader::~NetworkReader() { 
    165150 
    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 
    25 * xml file. 
    36 *  
     
    58 * which are getters for the list of FEP_LINES, and LDS_LOOPS, respectively. 
    69 *  
    7  * Example xml file: 
     10 * Example XML file: 
    811 * <code> 
    912 * <Network> 
     
    4750#define __NETWORKREADER_H_INCLUDED__ 
    4851 
    49 // Forward declared dependencies 
    50  
    5152// Included dependencies 
    5253#include "network.h" 
    5354#include <vector> 
    54 #include <string> 
    5555#include <string.h> 
    5656#include <iostream> 
    5757#include "tinyxml.h" 
     58#include "DataPacker.h" 
    5859 
    5960class NetworkReader 
     
    6364        ~NetworkReader(); // Destructor 
    6465         
    65         vector<FEP_LINE> getLines(); // Getter for FEP_LINE list 
    66         vector<LDS_LOOP> getStations(); // Getter for LDS_LOOP list 
     66        vector<FEP_LINE*> getLines(); // Getter for FEP_LINE list 
     67        vector<LDS_LOOP*> getStations(); // Getter for LDS_LOOP list 
    6768    private: 
    68         vector<FEP_LINE> lines; 
    69         vector<LDS_LOOP> stations; 
     69        vector<FEP_LINE*> lines; 
     70        vector<LDS_LOOP*> stations; 
    7071        int ldsIndex; 
    7172 
    7273        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); 
    7977}; 
    8078 
  • branches/fep_rpc_client/build/Debug/GNU-Linux-x86/FEPClient.o.d

    r77 r79  
    11build/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 
    34 
    45FEPClient.h: 
     
    1314 
    1415tinyxml/tinystr.h: 
     16 
     17DataPacker.h: 
  • branches/fep_rpc_client/build/Debug/GNU-Linux-x86/NetworkReader.o.d

    r77 r79  
    11build/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 
    34 
    45NetworkReader.h: 
     
    910 
    1011tinyxml/tinystr.h: 
     12 
     13DataPacker.h: 
  • branches/fep_rpc_client/nbproject/Makefile-Debug.mk

    r77 r79  
    3636# Object Files 
    3737OBJECTFILES= \ 
     38        ${OBJECTDIR}/DataPacker.o \ 
    3839        ${OBJECTDIR}/FEPClient.o \ 
    3940        ${OBJECTDIR}/NetworkReader.o \ 
     
    5657 
    5758# Link Libraries and Options 
    58 LDLIBSOPTIONS=tinyxml/libtinyxml.a 
     59LDLIBSOPTIONS=tinyxml/tinyxml.a 
    5960 
    6061# Build Targets 
     
    6263        "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client 
    6364 
    64 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: tinyxml/libtinyxml.a 
     65${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: tinyxml/tinyxml.a 
    6566 
    6667${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: ${OBJECTFILES} 
    6768        ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 
    6869        ${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 
    6975 
    7076${OBJECTDIR}/FEPClient.o: FEPClient.cpp  
  • branches/fep_rpc_client/nbproject/Makefile-Release.mk

    r77 r79  
    3636# Object Files 
    3737OBJECTFILES= \ 
     38        ${OBJECTDIR}/DataPacker.o \ 
    3839        ${OBJECTDIR}/FEPClient.o \ 
    3940        ${OBJECTDIR}/NetworkReader.o \ 
     
    6566        ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 
    6667        ${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 
    6773 
    6874${OBJECTDIR}/FEPClient.o: FEPClient.cpp  
  • branches/fep_rpc_client/nbproject/configurations.xml

    r77 r79  
    55                   displayName="Header Files" 
    66                   projectFiles="true"> 
     7      <itemPath>DataPacker.h</itemPath> 
    78      <itemPath>FEPClient.h</itemPath> 
    89      <itemPath>NetworkReader.h</itemPath> 
     
    1718                   displayName="Source Files" 
    1819                   projectFiles="true"> 
     20      <itemPath>DataPacker.cpp</itemPath> 
    1921      <itemPath>FEPClient.cpp</itemPath> 
    2022      <itemPath>NetworkReader.cpp</itemPath> 
     
    5052        <linkerTool> 
    5153          <linkerLibItems> 
    52             <linkerLibFileItem>tinyxml/libtinyxml.a</linkerLibFileItem> 
     54            <linkerLibFileItem>tinyxml/tinyxml.a</linkerLibFileItem> 
    5355          </linkerLibItems> 
    5456        </linkerTool> 
    5557      </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> 
    5662      <item path="FEPClient.cpp" ex="false" tool="1" flavor2="0"> 
    5763      </item> 
     
    9197        </asmTool> 
    9298      </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> 
    93103      <item path="FEPClient.cpp" ex="false" tool="1" flavor2="0"> 
    94104      </item> 
  • branches/fep_rpc_client/nbproject/private/private.xml

    r78 r79  
    88    <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> 
    99        <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> 
    1518        </group> 
    1619    </open-files> 
  • branches/fep_rpc_client/network.h

    r77 r79  
    1111const int Fixed_Byte_To_Checksum = 25; // the first byte is not considered in the calculation of "BYTE 2" 
    1212const int CONTROL_DATA_LEN = 27; 
     13 
    1314char * const dp5[8] = { "ML_1", "ML_2", "ML_3", "ML_4", "ML_5", 
    1415                                                "ML_6", "HOV_Lane", "FYW_Conn"}; 
     
    2021                                                "SD_6", "Pass_Vol_Count", "X"}; 
    2122 
    22 /*** NETWORK STRUCTS ***/ 
    23 typedef struct loopagg LOOPAGG; 
    24 struct loopagg 
    25 { 
    26         int             index; 
    27         char    lane;                   // how namy lanes at the detector station 
    28         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  
    3823// FEP line: has several lds 
    3924typedef struct fep_line FEP_LINE; 
    4025struct  fep_line 
    4126{ 
    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 
    4630 
    47         short   count;  // actual count from caltrans 
    48         int             schedule; 
    49         int             lineInfo; 
     31        short   count;  // actual count from caltrans 
     32        int     schedule; 
     33        int     lineInfo; 
    5034        long    systemKey; 
    5135        long    globalSeq; 
    5236        long    schedleSeq; 
     37}; 
     38 
     39// Loop detector 
     40typedef struct loop LOOP; 
     41struct loop 
     42{ 
     43    long loopID; 
     44    char *loop_loc; 
     45     
     46    int vol; 
     47    float occ; 
     48    double spd; 
    5349}; 
    5450 
     
    6157        short   line_num; 
    6258        short   drop; 
    63  
    64         int             num;    // number of loops 
    65         long    *loopID; 
    66         char    **loop_loc; 
     59         
     60        vector<LOOP*> loops; 
    6761 
    6862        // LDS data 
     
    7468}; 
    7569 
     70typedef struct volOcc VOLOCC; 
     71struct  volOcc 
     72{ 
     73   char high; 
     74   char low; 
     75}; 
     76 
     77 
    7678#endif 
Note: See TracChangeset for help on using the changeset viewer.