Changeset 70 in tmcsimulator for branches/fep_client_cpp/fep_client.cpp


Ignore:
Timestamp:
09/07/2017 12:37:27 AM (9 years ago)
Author:
jtorres
Message:

expanded client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/fep_client_cpp/fep_client.cpp

    r69 r70  
    11#include "fep.h" 
    2 #include "fep_print.cpp" 
    32#include <stdio.h> 
    43#include <stdlib.h> 
     4#include "network.h" 
     5#include "network_factory.cpp" 
     6#include "time.h" 
    57 
    68/* Author: John A. Torres 
     
    2325        { 
    2426                printf("Successful RPC call to ATMS...\n"); 
    25                 printf("Printing ATMS RPC Call response...\n"); 
    26                 print_reply_ret(*(reply_ret *) (&response)); 
    2727        } 
    2828} 
    2929 
    30 fep_reply generate_reply() 
     30 
     31void xfer_replys(CLIENT *clnt, FEP_LINE_LDS *lines, int lines_size, LDS_LOOP *ldsMap) 
    3132{ 
    32         /* Declarations to construct an fep_reply */ 
    33         fep_answer_info fai; 
    34         fep_pollerror fpe; 
    35         fep_answer_short_msg fasm; 
    36         fep_shortanswer fsa; 
    37         fep_reply  fep_reply_xfer_32_arg; // the reply to be sent to ATMS 
     33        int i, j; // i == line_index, j == lds_index 
    3834 
    39         /* Populate fep_shortmessage data */ 
    40         printf("Setting fep_reply values...\n"); 
     35        // Send one reply for every "line" in the FEP 
     36        for (i = 0; i < lines_size; i++) 
     37        { 
     38                fep_reply  fepReply; 
     39                 
     40                // populate reply 
     41                fepReply.reply = SHORTPOLL; 
     42                fepReply.schedule = fepLine[i].schedule; 
     43                fepReply.lineinfo = fepLine[i].lineInfo; 
     44                fepReply.kind = (enum polltype) 0; 
     45                fepReply.flag = (enum replykind) 0; 
     46                 
     47                /*********************************** 
     48                         This is an update to an extern, this should happen on the Java driver side??  
     49                fepLine[i].schedleSeq += 1; 
     50                fepLine[i].globalSeq += 51; 
     51                */ 
    4152 
    42         fasm.message_len = 5; 
    43         fasm.message[0] = 0x0a; 
    44         fasm.message[1] = 0x0d; 
    45         fasm.message[2] = 0x11; 
    46         fasm.message[3] = 0x12; 
    47         fasm.message[4] = 0x13; 
     53                fepReply.schedule_sequence = fepLine[i].schedleSeq; 
     54                fepReply.global_sequence = fepLine[i].globalSeq; 
     55                /************************************ 
     56                         Need to find out what appropriate schedule time is: look at uci_unix_simulation_time src code           
     57                fepReply.schedule_time =  
     58                        uci_unix_simulation_time(uci_simulation_time());        // GMT time 
     59                */ 
     60                fepReply.user_info1 = fepLine[i].lineNum; 
     61                fepReply.user_info2 = fepLine[i].lineNum; 
     62                fepReply.system_key = fepLine[i].systemKey; 
    4863 
    49         fpe.msgerror = (enum answererror) 0; 
    50         fpe.state = (enum Polling_FSM_States) 0x00; 
    51         fpe.perrno = 0; 
    52         fpe.termination = 0; 
    53         fpe.count = 0; 
     64                fepReply.answers.size = 1; 
     65                fepReply.answers.fep_answer_list_u.shortp.count = 1; 
     66                 
     67                /* for each LDS in the Line.... (constructs the short_answer message) */ 
     68                for (j = 0; j < fepLine[i].ldsNum; j++) 
     69                { 
     70                        fep_shortanswer fsa; 
     71                        int index = fepLine[i].ldsIndex[j]; 
    5472 
    55         fai.poll_time = 1111443466; 
    56         fai.status = (enum replystatus) 1; 
    57         fai.poll_user_info1 = 1; 
    58         fai.poll_user_info2 = 2; 
    59         fai.retries = 0; 
    60         fai.poll_error_count = 1; 
    61         fai.pollerror[0] = fpe; 
     73                        // msg: oa, od, ldsMap[index].dataPack, od, ff 
     74                        fsa.msg.message_len = ldsMap[index].length + 2; 
     75                        fsa.msg.message[0] = 0x0d; 
     76                        fsa.msg.message[1] = 0x0a; 
     77                        for (int k = 0; k < ldsMap[index].length; k++) 
     78                                fsa.msg.message[2 + k]  = ldsMap[index].dataPack[k]; 
     79                        int aa = ldsMap[index].length; 
     80                        fsa.msg.message[2 + aa] = 0x0d; 
     81                        fsa.msg.message[3 + aa] = 0xff; //????????????? warning ????? 
    6282 
    63         fsa.info = fai; 
    64         fsa.msg = fasm; 
     83                        // info 
     84                        fsa.info.poll_error_count = 0;  
     85                        /*************************************** 
     86                                 Need to find out polltime uci time function src code 
     87                        fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time());  
     88                        */ 
     89                        fsa.info.poll_user_info1 = ldsMap[index].drop;  // drop number 
     90                        fsa.info.poll_user_info2 = 1;   //always 1 
     91                        fsa.info.retries = 0; 
     92                        fsa.info.status = REPLY_DONE; 
     93                         
     94                        //fepReply.answers.fep_answer_list_u.shortp.answers[j] = fsa;    
     95                        fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa;      
     96                         
     97                        // send out data 
     98                        printf("line=%d, lds=%d\n", fepLine[i].lineNum, ldsMap[index].drop); 
     99                        rv = fep_reply_xfer_32(&fepReply, clnt); 
    65100 
    66         fep_reply_xfer_32_arg.reply = 0; 
    67         fep_reply_xfer_32_arg.schedule = 0; 
    68         fep_reply_xfer_32_arg.lineinfo = 0; 
    69         fep_reply_xfer_32_arg.kind = (enum polltype)0; 
    70         fep_reply_xfer_32_arg.flag = (enum replykind) 0; 
    71         fep_reply_xfer_32_arg.schedule_sequence = 0; 
    72         fep_reply_xfer_32_arg.global_sequence = 0; 
    73         fep_reply_xfer_32_arg.schedule_time = 1111443466; 
    74         fep_reply_xfer_32_arg.user_info1 = 0; 
    75         fep_reply_xfer_32_arg.user_info2 = 0; 
    76         fep_reply_xfer_32_arg.system_key = 0; 
    77         fep_reply_xfer_32_arg.answers.size = 1; 
    78         fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.count = 1; 
    79         fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.answers[0] = fsa; 
    80  
    81         return fep_reply_xfer_32_arg; 
     101                        /* Handle ATMS response to RPC Call */ 
     102                        printf("Handling ATMS response...\n"); 
     103                        handle_ATMS_response(clnt, rv); 
     104                } 
     105        }                
    82106} 
    83107 
    84 /* Creates an RPC client, populates the fep_reply data structure, 
    85    makes an RPC Call to the ATMS Server to pass the fep_reply, 
    86    destroys the RPC Client and returns 
    87  */ 
    88 void fep_program_32(char *host) 
     108/* Creates an RPC Client which communicates with the ATMS through RPC Calls */ 
     109CLIENT * create_client() 
    89110{ 
    90111        CLIENT *clnt; 
    91  
    92         /* Var to recieve message back from ATMS */ 
    93         void  *rv; 
    94  
     112         
    95113        /* Create RPC Client to communicate with ATMS */ 
    96114        printf("Preparing to create RPC client...\n"); 
     
    103121                exit(1); 
    104122        } 
     123         
     124        return clnt; 
     125} 
    105126 
    106         /* Make RPC Call to transfer reply to ATMS */ 
    107         printf("Transferring data to ATMS Server...\n"); 
    108         fep_reply reply = generate_reply(); 
    109         rv = fep_reply_xfer_32(&reply, clnt); 
     127/* update_ATMS transfers fep_replys to the ATMS Server.  
     128        It creates an RPC client, loads data from line_atms.txt and lds_atms.txt, 
     129        updates the ATMS with the fep_reply data, and destroys the RPC client. 
     130 */ 
     131void update_ATMS(char *host) 
     132{ 
     133        CLIENT *clnt = create_client(); 
     134         
     135        /* Load data to be xfered to ATMS */ 
     136        FEP_LINE_LDS *lines; 
     137        int lines_size = load_lines(&lines, "./lines_atms.txt"); 
     138        FEP_LDS *ldsMap = load_lds("./lds_atms.txt"); 
    110139 
    111         /* Handle ATMS response to RPC Call */ 
    112         printf("Handling ATMS response...\n"); 
    113         handle_ATMS_response(clnt, rv); 
     140        /* Transfer data to ATMS */ 
     141        xfer_replys(clnt, lines, lines_size, ldsMap); 
    114142 
    115143        /* Destroy client */ 
     
    132160        /* Create RPC Client to send an fep_reply to ATMS */ 
    133161        host = argv[1]; 
    134         fep_program_32(host); 
     162        update_ATMS(host); 
    135163 
    136164        return 0; 
Note: See TracChangeset for help on using the changeset viewer.