Warning: Can't use blame annotator:
svn blame failed on branches/fep_rpc_client/FEPClient.cpp: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/branches/fep_rpc_client/FEPClient.cpp @ 78

Revision 78, 4.6 KB checked in by jtorres, 9 years ago (diff)

All green dots are showing. This is a checkpoint before adding dynamic data packing.

RevLine 
1#include "FEPClient.h"
2
3/**
4 * Constructor
5 *
6 * @param host The host rpc server ip address
7 * @param networkFile the xml network file
8 */
9FEPClient::FEPClient(char * host, char * networkFile)
10{
11        createClient(host);
12        networkReader = new NetworkReader(networkFile);
13        updateATMS();
14}
15
16/**
17 * Destructor
18 */
19FEPClient::~FEPClient()
20{
21        cout << "Destroying client..." << endl;
22        clnt_destroy(clnt);
23}
24
25/**
26 * Handler for the ATMS RPC Response (to the client RPC Call)
27 * @param response pointer to fep_reply struct
28 */
29void 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        }
41}
42
43/**
44 * Sends an fep_reply for every line in the FEP.
45 */
46void FEPClient::updateATMS()
47{
48        int i, j; // i == line_index, j == lds_index
49        void *rv;
50
51    vector<FEP_LINE> lines = networkReader->getLines();
52    vector<LDS_LOOP> ldsMap = networkReader->getStations();
53
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;
65
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                */
71
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);
80
81                fepReply.user_info1 = lines.at(i).lineNum;
82                fepReply.user_info2 = lines.at(i).lineNum;
83                fepReply.system_key = lines.at(i).systemKey;
84
85                fepReply.answers.size = 1;
86                fepReply.answers.fep_answer_list_u.shortp.count = 1;
87
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 ?????
103
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;
114
115                        //fepReply.answers.fep_answer_list_u.shortp.answers[j] = fsa;
116                        fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa;
117
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);
121
122                        /* Handle ATMS response to RPC Call */
123                        printf("Handling ATMS response...\n");
124                        handleCallResponse(rv);
125                }
126        }
127}
128
129/**
130 * Creates the RPC Client. If not successful, exit with status 1.
131 * @param host rpc server ip
132 */
133void 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        }
145}
146
147/**
148 * Main driver for ATMSCommunicator. Creates an RPC Client from command line args.
149 * @param argc
150 * @param argv
151 * @return
152 */
153int main(int argc, char *argv[]) {
154
155        char *host;
156        char *networkFile;
157
158        if (argc < 3)
159        {
160                cout << "usage:  " << argv[0] << " server_host networkFile" << endl;
161                exit(1);
162        }
163
164        /* Create RPC Client to send an fep_reply to ATMS */
165        host = argv[1];
166        networkFile = argv[2];
167
168        FEPClient *client = new FEPClient(host, networkFile);
169        delete client;
170
171        return 0;
172}
Note: See TracBrowser for help on using the repository browser.