Changeset 165 in tmcsimulator for branches/green_dot


Ignore:
Timestamp:
10/23/2017 11:44:05 AM (9 years ago)
Author:
jtorres
Message:

green_dot now has datapacking implemented

Location:
branches/green_dot
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/green_dot/build

    r164 r165  
    11#!/bin/bash 
    22# Compile everything and produce the executable client 
    3 g++ -g fep_client.cpp fep_clnt.c fep_xdr.c -o client  
     3g++ -g DataPacker.cpp fep_client.cpp fep_clnt.c fep_xdr.c -o client  
    44 
    55 
  • branches/green_dot/fep_client.cpp

    r138 r165  
    2828} 
    2929 
    30 void xfer_replys(CLIENT *clnt, FEP_LINE_LDS *lines, int lines_size, LDS_LOOP *ldsMap) 
     30void xfer_replys(CLIENT *clnt, FEP_LINE_LDS *lines, int lines_size, STATION *ldsMap) 
    3131{ 
    3232        int i, j; // i == line_index, j == lds_index 
     
    140140        FEP_LINE_LDS *lines = load_lines(&lines_size, "./lines_atms.txt"); 
    141141        printf("Loading ldsMap...\n"); 
    142         LDS_LOOP *ldsMap = load_lds("./lds_atms.txt"); 
     142        STATION *ldsMap = load_lds("./lds_atms.txt"); 
    143143 
    144144        /* Transfer data to ATMS */ 
  • branches/green_dot/network.h

    r138 r165  
    99const int CONTROL_DATA_LEN = 27; 
    1010char * const dp5[8] = { "ML_1", "ML_2", "ML_3", "ML_4", "ML_5", 
    11                                                 "ML_6", "HOV_Lane", "FYW_Conn"}; 
     11   "ML_6", "HOV_Lane", "FYW_Conn"}; 
    1212char * const dp6[8] = { "OS_1", "OS_2", "OS_3", "OS_4", "OS_5", 
    13                                                 "OS_6", "COLL_DIST_2", "COLL_DIST_OFF"}; 
     13   "OS_6", "COLL_DIST_2", "COLL_DIST_OFF"}; 
    1414char * const dp7[8] = { "DEMAND", "PASSAGE", "QUEUE", "RAMP_ON", 
    15                                                 "RAMP_OFF", "RAMP_HOV", "COLL_DIST_1", "COLL_DIST_ON"}; 
     15   "RAMP_OFF", "RAMP_HOV", "COLL_DIST_1", "COLL_DIST_ON"}; 
    1616char * const dp8[8] = { "SD_1", "SD_2", "SD_3", "SD_4", "SD_5", 
    17                                                 "SD_6", "Pass_Vol_Count", "X"}; 
     17   "SD_6", "Pass_Vol_Count", "X"}; 
    1818 
    1919/*** NETWORK STRUCTS ***/ 
     
    2121struct loopagg 
    2222{ 
    23         int             index; 
    24         char    lane;                   // how namy lanes at the detector station 
    25         long    time; 
    26         int             interval; 
    27         int     g_vol; 
    28         float   g_occ; 
    29         double  g_spd; 
    30         int             *vol; 
    31         float   *occ; 
    32         double  *spd; 
     23   int          index; 
     24   char lane;                   // how namy lanes at the detector station 
     25   long time; 
     26   int          interval; 
     27   int  g_vol; 
     28   float        g_occ; 
     29   double       g_spd; 
     30   int          *vol; 
     31   float        *occ; 
     32   double       *spd; 
    3333}; 
    3434 
     
    3737struct  fep_line_lds 
    3838{ 
    39         int             lineNum; 
    40         vector<long> lds; 
    41         vector<long> ldsIndex;  // location in ldsMap 
    42         short   ldsNum;                 // actual number of lds on the line 
     39   int          lineNum; 
     40   vector<long> lds; 
     41   vector<long> ldsIndex;       // location in ldsMap 
     42   short        ldsNum;                 // actual number of lds on the line 
    4343 
    44         short   count;  // actual count from caltrans 
    45         int             schedule; 
    46         int             lineInfo; 
    47         long    systemKey; 
    48         long    globalSeq; 
    49         long    schedleSeq; 
     44   short        count;  // actual count from caltrans 
     45   int          schedule; 
     46   int          lineInfo; 
     47   long systemKey; 
     48   long globalSeq; 
     49   long schedleSeq; 
     50}; 
     51// Loop detector 
     52typedef struct loop LOOP; 
     53struct loop 
     54{ 
     55   long loopID; 
     56   char *loop_loc; 
     57 
     58   int vol; 
     59   float occ; 
     60   double spd; 
    5061}; 
    5162 
    5263// Loop detector station: has several loops 
    53 typedef struct Lds_loop LDS_LOOP; 
    54 struct  Lds_loop  
     64typedef struct Station STATION; 
     65struct  Station  
    5566{ 
    56         // Each lds has its own line_num and drop (Caltrans use) 
    57         long    lds; 
    58         short   line_num; 
    59         short   drop; 
     67   // Each lds has its own line_num and drop (Caltrans use) 
     68   long lds; 
     69   short        line_num; 
     70   short        drop; 
    6071 
    61         int             num;    // number of loops 
    62         long    *loopID; 
    63         char    **loop_loc; 
     72   vector<LOOP*> loops; 
    6473 
    65         // LDS data 
    66         unsigned char   *dataPack; 
    67         int             length;         // total length of data (max: 87) 
    68         int             pos;            // pointer for data preparation 
    69         int             MlTotVol;       // each 30 sec, the following will be updated 
    70         int             OppTotVol;      // each 30 sec, the following will be updated 
     74   int          num;    // number of loops 
     75   // LDS data 
     76   unsigned char        *dataPack; 
     77   int          length;         // total length of data (max: 87) 
     78   int          pos;            // pointer for data preparation 
     79   int          MlTotVol;       // each 30 sec, the following will be updated 
     80   int          OppTotVol;      // each 30 sec, the following will be updated 
     81}; 
     82// A helper structure used to pack the volume and occupancy at a loop into 
     83// // a two byte message 
     84typedef struct volOcc VOLOCC; 
     85struct  volOcc 
     86{ 
     87   char high; 
     88   char low; 
    7189}; 
    7290 
     91 
     92 
    7393#endif 
  • branches/green_dot/network_factory.cpp

    r164 r165  
    11#include "network.h" 
     2#include "DataPacker.h" 
    23#include <vector> 
    34#include <math.h> 
     
    67#include <cstdlib> 
    78 
    8 // determine if a loop has data based on lane config data 
    9 bool DataAvail(char flag, int num) { 
    10         int mag, fel; 
    11  
    12         // find mask value 
    13         if (num == 1) 
    14                 mag = 0x01; 
    15         else if (num == 2) 
    16                 mag = 0x02; 
    17         else if (num == 3) 
    18                 mag = 0x04; 
    19         else if (num == 4) 
    20                 mag = 0x08; 
    21         else if (num == 5) 
    22                 mag = 0x10; 
    23         else if (num == 6) 
    24                 mag = 0x20; 
    25         else if (num == 7) 
    26                 mag = 0x40; 
    27         else if (num == 8) 
    28                 mag = 0x80; 
    29          
    30         fel = flag & mag; 
    31         fel = fel >> (num - 1); 
    32          
    33         if (fel == 1) 
    34                 return true; 
    35         else  
    36                 return false; 
    37 } 
    38  
    39 // Initializes the LDS_LOOP dataPack with all necessary static data and default dynamic data 
    40 void init_loop_dataPack(LDS_LOOP *loop) 
    41 { 
    42         int j; 
    43         // Allocate memory for dataPack 
    44         loop->dataPack = (unsigned char *) calloc(sizeof(unsigned char), loop->length); 
    45  
    46         // dataPack 5-8: lane config 
    47         char d5 = 0, d6 = 0, d7 = 0, d8 = 0;             
    48         for (j = 0; j < loop->num; j++) 
    49         { 
    50                 for (int k = 0; k < 8; k++) 
    51                 { 
    52                         if (strcmp(loop->loop_loc[j], dp5[k]) == 0) 
    53                                 d5 += pow(2, k); 
    54                         if (strcmp(loop->loop_loc[j], dp6[k]) == 0) 
    55                                 d6 += pow(2, k); 
    56                         if (strcmp(loop->loop_loc[j], dp7[k]) == 0) 
    57                                 d7 += pow(2, k); 
    58                         if (strcmp(loop->loop_loc[j], dp8[k]) == 0) 
    59                                 d8 += pow(2, k); 
    60                 } 
    61         } 
    62         loop->dataPack[5-1] = d5; 
    63         loop->dataPack[6-1] = d6; 
    64         loop->dataPack[7-1] = d7; 
    65         loop->dataPack[8-1] = d8; 
    66  
    67         // dataPack 1: Drop number, i.e. station address 
    68         loop->dataPack[1-1] = loop->drop; 
    69  
    70         // dataPack2 (2 bytes per loop) 
    71         loop->dataPack[2-1] = loop->num * 2 + Fixed_Byte_To_Checksum; 
    72  
    73         // dataPacket 3 (lowbyte: # of mainline loops, highbyte: # of opposite loops) 
    74         int low = 0, high = 0; 
    75         for (j = 1; j <= 6; j++) 
    76         { 
    77                 low += DataAvail(loop->dataPack[5-1], j); 
    78                 high += DataAvail(loop->dataPack[6-1], j); 
    79         } 
    80         high = high << 4; 
    81         loop->dataPack[3-1] = high | low; 
    82  
    83         // dataPack4 (Miscl. flags: samples are: 80, A0, E0, 00) 
    84         loop->dataPack[4-1] = 0xA0; 
    85  
    86         // dataPack 9: initialized as 00 (meaning no metering); need to be updated every 30 sec 
    87         loop->dataPack[9-1] = 0; 
    88  
    89         // datadataPack 10-13: lane malfunction? Assuming all functional 
    90         loop->dataPack[10-1] = 0; 
    91         loop->dataPack[11-1] = 0; 
    92         loop->dataPack[12-1] = 0; 
    93         loop->dataPack[13-1] = 0; 
    94  
    95         // dataPack 14-22: ramp metering data 
    96         // BYTE 16 and 22 need to be updated every 30 sec 
    97         bool found = false; 
    98         for (j = 0; j < loop->num; j++) 
    99         { 
    100                 if (strcmp(loop->loop_loc[j], "DEMAND") == 0) 
    101                 { 
    102                         found = true; 
    103                         break; 
    104                 } 
    105         } 
    106         if (found) 
    107         { 
    108                 // BYTE 14: mostly 07, some are 05, 03, 00 
    109                 loop->dataPack[14-1] = 0x07; 
    110                 // mostly 06(TOD table 1); some are 0B (No metering) or 05(traffic responsive) 
    111                 loop->dataPack[15-1] = 0x06; 
    112                 // most 00, some are 01 (queue override) or 80(Meter ON sign) 
    113                 loop->dataPack[16-1] = 0x00; 
    114                 // Field Manual Rate 
    115                 loop->dataPack[17-1] = 0xFF; 
    116                 // TOC Manual Rate 
    117                 loop->dataPack[18-1] = 0xFF; 
    118                 // PSO Manual Rate 
    119                 loop->dataPack[19-1] = 0xFF; 
    120                 // CORM Rate 
    121                 loop->dataPack[20-1] = 0xFF; 
    122                 // Local Responsive Rate. DON'T UNDERSTAND YET 
    123                 loop->dataPack[21-1] = 0x00; 
    124                 // TOD Rate: need to query RAMP plugin!  
    125                 loop->dataPack[22-1] = 0x00; 
    126         } 
    127         // LDS: NO Metering 
    128         else 
    129         { 
    130                 loop->dataPack[14-1] = 0x00; 
    131                 loop->dataPack[15-1] = 0x0B; 
    132                 loop->dataPack[16-1] = 0x00;                     
    133                 loop->dataPack[17-1] = 0xFF; 
    134                 loop->dataPack[18-1] = 0xFF; 
    135                 loop->dataPack[19-1] = 0xFF; 
    136                 loop->dataPack[20-1] = 0xFF; 
    137                 loop->dataPack[21-1] = 0x00; 
    138                 loop->dataPack[22-1] = 0x00; 
    139         } 
    140  
    141         // dataPack 23-24: sum of mainline/Oppsite traffic data; need to be updated every 30 sec 
    142         loop->MlTotVol = 0; 
    143         loop->OppTotVol = 0; 
    144         loop->dataPack[23-1] = loop->MlTotVol;   
    145         loop->dataPack[24-1] = loop->OppTotVol;  
    146          
    147         // dataPack 25-26: BYTE 25 is fixed, i.e. 03; BYTE 26 is either 0xA2 or 0x84 
    148         loop->dataPack[25-1] = 0x03; 
    149         loop->dataPack[26-1] = 0x84; 
    150  
    151         printf("lds=%d (%d), p1=%2X, p2=%2X, p3=%2X, p5=%2X, p6=%X, p7=%X, p8=%2X\n",  
    152                 loop->lds, loop->length, loop->dataPack[1-1], loop->dataPack[2-1],  
    153                 loop->dataPack[3-1], loop->dataPack[5-1],  
    154                 loop->dataPack[6-1], loop->dataPack[7-1], loop->dataPack[8-1]); 
    155 } 
    1569 
    15710// TEST DATA 
     
    19043 
    19144//55    S       6.88    1203103 1203110 1203114 ML      4       ML_4            55s6.88ml       1 
    192 LDS_LOOP * load_lds(const char * fName) 
     45STATION * load_lds(const char * fName) 
    19346{ 
    19447        /* Read loop meta data */ 
    195         LDS_LOOP *lds_map = (LDS_LOOP *) calloc(sizeof(LDS_LOOP), 1); 
     48        STATION *lds_map = (STATION *) calloc(sizeof(STATION), 1); 
    19649        lds_map[0].lds = 1203103; 
    19750        lds_map[0].line_num = 50; 
     
    19952        lds_map[0].num = 1; 
    20053 
    201         // Loop ids 
    202         long *loopIDs = (long *) calloc(sizeof(long), lds_map[0].num); 
    203         loopIDs[0] = 1203113; 
    204         lds_map[0].loopID = loopIDs; 
    205          
    206         // Loop locations 
    207         char *loc = "ML_3"; 
    208         lds_map[0].loop_loc = &loc; 
    209  
     54   LOOP *loop = new LOOP; 
     55   loop->loopID = 1203113; 
     56   loop->loop_loc = "ML_3"; 
     57   loop->vol = 40; 
     58   loop->occ = 10; 
     59   loop->spd = 10; 
     60    
     61   lds_map[0].loops.push_back(loop); 
     62    
    21063        // Init Loop dataPack 
    21164        lds_map[0].length = lds_map[0].num * 2 + CONTROL_DATA_LEN; 
    212         init_loop_dataPack(lds_map); 
     65 
     66   lds_map[0].dataPack = DataPacker::packData(&lds_map[0]); 
    21367 
    21468        lds_map[0].pos = 0; 
Note: See TracChangeset for help on using the changeset viewer.