source: tmcsimulator/branches/SimpleFEPclient/fep_client.cpp @ 136

Revision 136, 5.3 KB checked in by jtorres, 9 years ago (diff)

branches/SimpleFEPclient/ checking in SimpleFEPclient work, not currently up to par. trunk/IDE_metadata/NetBeans/TMCSim/nbproject/configs/ConsoleDriver.properties added the original ConsoleDriver?.properties, may be unnecessary and can be removed, check with JD.

Line 
1#include "fep_client.h"
2#include "fep.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <vector>
6#include "network.h"
7#include "DataPacker.h"
8
9/* Author: John A. Torres
10   The fep_program_32 function creates a new RPC Client which
11   sends an fep_reply structure to the ATMS Server. After the
12   reply is sent, the ATMS Sends a response and the RPC Client
13   is destroyed.
14   */
15void FEPClient::fep_program_32(char *host)
16{
17   CLIENT *clnt;
18
19   /* Declerations to construct an fep_reply */
20   fep_answer_info fai;
21   fep_answer_short_msg fasm;
22   fep_shortanswer fsa;
23   fep_reply  fep_reply; // the reply to be sent to ATMS
24
25   /* Var to recieve message back from ATMS */
26   void  *rv;
27
28   /* Create RPC Client to communicate with ATMS */
29   printf("Preparing to create RPC client\n");
30   clnt = clnt_create(host, FEP_PROGRAM, FEP_VERSION, "tcp");
31
32   /* Check if client creation failed */
33   if (clnt == (CLIENT *) NULL)
34   {
35      fprintf(stderr, "can't create client to %s\n", host);
36      /* Show why rpc handle couldn't be created */
37      clnt_pcreateerror("");
38      exit(1);
39   }
40
41   /* Populate fep_shortmessage data */
42   printf("setting reply values\n");
43
44   // DUMMY DATA FOR SINGLE GREEN DOT
45   // STATION
46   // lds_id  line    drop sch lineinfo       system_key      sch_seq glo_seq         count   freeway Dir     ca_pm   lds_name
47   // 1204666 45      10      11      11      1123005841      26484   1357646         19      5       N       20      LAKE FOR2
48
49   // LOOPS
50   // FWY     Dir     POSTMI  LDS_ID  VDS_ID  LOOP_ID LOC    LANE LOOP_LOC            PARAMICS_NAME  PARAMICS_LANE
51   //
52
53   vector<LOOP*> loops;
54/*
55   LOOP * newLoopOne = new LOOP;
56   newLoopOne->loopID = 1210490;
57   newLoopOne->loop_loc = "ML_1";
58   newLoopOne->vol = 0;
59   newLoopOne->occ = 0;
60   newLoopOne->spd = 0;
61
62   LOOP * newLoopTwo = new LOOP;
63   newLoopTwo->loopID = 1210492;
64   newLoopTwo->loop_loc = "ML_2";
65   newLoopTwo->vol = 0;
66   newLoopTwo->occ = 0;
67   newLoopTwo->spd = 0;
68
69   LOOP * newLoopThree = new LOOP;
70   newLoopThree->loopID = 1210493;
71   newLoopThree->loop_loc = "ML_3";
72   newLoopThree->vol = 0;
73   newLoopThree->occ = 0;
74   newLoopThree->spd = 0;
75
76   LOOP * newLoopFour = new LOOP;
77   newLoopFour->loopID = 1210769;
78   newLoopFour->loop_loc = "RAMP_ON";
79   newLoopFour->vol = 0;
80   newLoopFour->occ = 0;
81   newLoopFour->spd = 0;
82
83   loops.push_back(newLoopOne);
84   loops.push_back(newLoopTwo);
85   loops.push_back(newLoopThree);
86   loops.push_back(newLoopFour);
87*/
88   STATION * dummyStation = new STATION;
89   dummyStation->lds = 1204666;
90   dummyStation->line_num = 45;
91   dummyStation->drop = 10;
92   // dummyStation->loops = loops;
93
94   dummyStation->MlTotVol = 0;
95   dummyStation->OppTotVol = 0;
96   dummyStation->length = dummyStation->loops.size() * 2 + 27 /* CONTROL_DATA_LEN */;
97
98   printf("Station length: %d\n", dummyStation->length);
99   // CHECK TO SEE IF I AM UPDATING THIS EVERY 30S
100   /*
101   for(int i = 0; i < 3; i++)
102   {
103      dummyStation->MlTotVol += loops.at(i)->vol;
104   }
105   */
106   printf("Station MLTOTVOL: %d\n", dummyStation->MlTotVol);
107
108   dummyStation->dataPack = DataPacker::packData(dummyStation);
109
110
111   fep_reply.reply = SHORTPOLL;
112   fep_reply.schedule = 0;
113   fep_reply.lineinfo = 0;
114   fep_reply.kind = (enum polltype) 0;
115   fep_reply.flag = (enum replykind) 0;
116
117   fep_reply.schedule_sequence = 0;
118   fep_reply.global_sequence = 0;
119
120   fep_reply.schedule_time = time(NULL);
121
122   fep_reply.user_info1 = dummyStation->line_num; // LINE NUM;
123   fep_reply.user_info2 = dummyStation->line_num; // LINE NUM;
124   fep_reply.system_key = 0;
125
126   fep_reply.answers.size = 1;
127   fep_reply.answers.fep_answer_list_u.shortp.count = 1;
128
129   fasm.message_len = dummyStation->length + 2; // MESSAGE LEN;
130   fasm.message[0] = 0x0d;
131   fasm.message[1] = 0x0a;
132
133   for (int k = 0; k < dummyStation->length; k++) {
134      printf("Adding: %d %02X\n", k, dummyStation->dataPack[k]); 
135      fasm.message[2 + k] = dummyStation->dataPack[k];
136   }
137
138   int length = dummyStation->length + 2; // NEED CORRECT LENGTH
139   fasm.message[length + 2] = 0x0d;
140   fasm.message[length + 3] = 0xff;
141
142   for(int l = 0; l < fasm.message_len + 2; l++)
143   {
144      printf("%02X", (unsigned char) fasm.message[l]);
145   }
146   printf("\n");
147
148   fai.poll_error_count = 0;
149   fai.poll_user_info1 = 0 ;// DROP NUMBER HERE
150   fai.poll_user_info2 = 1;
151   fai.retries = 0;
152   fai.status = (enum replystatus) 1;
153
154   fsa.info = fai;
155   fsa.msg = fasm;
156   fep_reply.answers.fep_answer_list_u.shortp.answers[0] = fsa;
157
158   /* Make RPC Call to transfer reply to ATMS */
159   printf("transferring data\n");
160   rv = fep_reply_xfer_32(&fep_reply, clnt);
161   printf("checking reply`\n");
162
163   /* If ATMS reply call fails */
164   if (rv == (void *) NULL)
165   {
166      clnt_perror(clnt, "call failed");
167   }
168   /* If recieved reply is successful, but empty */
169   else if ((char *) rv == "")
170   {
171      printf("rv is empty\n");
172   }
173   /* If recieved reply is successful */
174   else
175   {
176      printf("Result = %s\n", (char *)rv);
177   }
178
179   /* Destroy client */
180   printf("destroying client\n");
181   clnt_destroy(clnt);
182   printf("returning to main\n");
183}
184
185/* Creates a single client and sends an fep_reply to the ATMS */
186int main(int argc, char *argv[]) {
187   char *host;
188
189   if (argc < 2)
190   {
191      printf("usage:  %s server_host\n", argv[0]);
192      exit(1);
193   }
194
195   /* Create RPC Client to send an fep_reply to ATMS */
196   host = argv[1];
197   FEPClient cli;
198   cli.fep_program_32(host);
199
200   return 0;
201}
Note: See TracBrowser for help on using the repository browser.