Changeset 79 in tmcsimulator for branches/fep_rpc_client/FEPClient.cpp
- Timestamp:
- 10/05/2017 12:51:23 PM (9 years ago)
- File:
-
- 1 edited
-
branches/fep_rpc_client/FEPClient.cpp (modified) (6 diffs)
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 }
Note: See TracChangeset
for help on using the changeset viewer.
