Index: branches/fep_client_cpp/fep_client.cpp
===================================================================
--- branches/fep_client_cpp/fep_client.cpp	(revision 69)
+++ branches/fep_client_cpp/fep_client.cpp	(revision 70)
@@ -1,6 +1,8 @@
 #include "fep.h"
-#include "fep_print.cpp"
 #include <stdio.h>
 #include <stdlib.h>
+#include "network.h"
+#include "network_factory.cpp"
+#include "time.h"
 
 /* Author: John A. Torres
@@ -23,74 +25,90 @@
 	{
 		printf("Successful RPC call to ATMS...\n");
-		printf("Printing ATMS RPC Call response...\n");
-		print_reply_ret(*(reply_ret *) (&response));
 	}
 }
 
-fep_reply generate_reply()
+
+void xfer_replys(CLIENT *clnt, FEP_LINE_LDS *lines, int lines_size, LDS_LOOP *ldsMap)
 {
-	/* Declarations to construct an fep_reply */
-	fep_answer_info fai;
-	fep_pollerror fpe;
-	fep_answer_short_msg fasm;
-	fep_shortanswer fsa;
-	fep_reply  fep_reply_xfer_32_arg; // the reply to be sent to ATMS
+	int i, j; // i == line_index, j == lds_index
 
-	/* Populate fep_shortmessage data */
-	printf("Setting fep_reply values...\n");
+	// Send one reply for every "line" in the FEP
+	for (i = 0; i < lines_size; i++)
+	{
+		fep_reply  fepReply;
+		
+		// populate reply
+		fepReply.reply = SHORTPOLL;
+		fepReply.schedule = fepLine[i].schedule;
+		fepReply.lineinfo = fepLine[i].lineInfo;
+		fepReply.kind = (enum polltype) 0;
+		fepReply.flag = (enum replykind) 0;
+		
+		/***********************************
+			 This is an update to an extern, this should happen on the Java driver side?? 
+		fepLine[i].schedleSeq += 1;
+		fepLine[i].globalSeq += 51;
+		*/
 
-	fasm.message_len = 5;
-	fasm.message[0] = 0x0a;
-	fasm.message[1] = 0x0d;
-	fasm.message[2] = 0x11;
-	fasm.message[3] = 0x12;
-	fasm.message[4] = 0x13;
+		fepReply.schedule_sequence = fepLine[i].schedleSeq;
+		fepReply.global_sequence = fepLine[i].globalSeq;
+		/************************************
+			 Need to find out what appropriate schedule time is: look at uci_unix_simulation_time src code		
+		fepReply.schedule_time = 
+			uci_unix_simulation_time(uci_simulation_time());	// GMT time
+		*/
+		fepReply.user_info1 = fepLine[i].lineNum;
+		fepReply.user_info2 = fepLine[i].lineNum;
+		fepReply.system_key = fepLine[i].systemKey;
 
-	fpe.msgerror = (enum answererror) 0;
-	fpe.state = (enum Polling_FSM_States) 0x00;
-	fpe.perrno = 0;
-	fpe.termination = 0;
-	fpe.count = 0;
+		fepReply.answers.size = 1;
+		fepReply.answers.fep_answer_list_u.shortp.count = 1;
+		
+		/* for each LDS in the Line.... (constructs the short_answer message) */
+		for (j = 0; j < fepLine[i].ldsNum; j++)
+		{
+			fep_shortanswer fsa;
+			int index = fepLine[i].ldsIndex[j];
 
-	fai.poll_time = 1111443466;
-	fai.status = (enum replystatus) 1;
-	fai.poll_user_info1 = 1;
-	fai.poll_user_info2 = 2;
-	fai.retries = 0;
-	fai.poll_error_count = 1;
-	fai.pollerror[0] = fpe;
+			// msg: oa, od, ldsMap[index].dataPack, od, ff
+			fsa.msg.message_len = ldsMap[index].length + 2;
+			fsa.msg.message[0] = 0x0d;
+			fsa.msg.message[1] = 0x0a;
+			for (int k = 0; k < ldsMap[index].length; k++)
+				fsa.msg.message[2 + k]	= ldsMap[index].dataPack[k];
+			int aa = ldsMap[index].length;
+			fsa.msg.message[2 + aa] = 0x0d;
+			fsa.msg.message[3 + aa] = 0xff;	//????????????? warning ?????
 
-	fsa.info = fai;
-	fsa.msg = fasm;
+			// info
+			fsa.info.poll_error_count = 0; 
+			/***************************************
+				 Need to find out polltime uci time function src code
+			fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time()); 
+			*/
+			fsa.info.poll_user_info1 = ldsMap[index].drop;	// drop number
+			fsa.info.poll_user_info2 = 1;	//always 1
+			fsa.info.retries = 0;
+			fsa.info.status = REPLY_DONE;
+			
+			//fepReply.answers.fep_answer_list_u.shortp.answers[j] = fsa;	
+			fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa;	
+			
+			// send out data
+			printf("line=%d, lds=%d\n", fepLine[i].lineNum, ldsMap[index].drop);
+			rv = fep_reply_xfer_32(&fepReply, clnt);
 
-	fep_reply_xfer_32_arg.reply = 0;
-	fep_reply_xfer_32_arg.schedule = 0;
-	fep_reply_xfer_32_arg.lineinfo = 0;
-	fep_reply_xfer_32_arg.kind = (enum polltype)0;
-	fep_reply_xfer_32_arg.flag = (enum replykind) 0;
-	fep_reply_xfer_32_arg.schedule_sequence = 0;
-	fep_reply_xfer_32_arg.global_sequence = 0;
-	fep_reply_xfer_32_arg.schedule_time = 1111443466;
-	fep_reply_xfer_32_arg.user_info1 = 0;
-	fep_reply_xfer_32_arg.user_info2 = 0;
-	fep_reply_xfer_32_arg.system_key = 0;
-	fep_reply_xfer_32_arg.answers.size = 1;
-	fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.count = 1;
-	fep_reply_xfer_32_arg.answers.fep_answer_list_u.shortp.answers[0] = fsa;
-
-	return fep_reply_xfer_32_arg;
+			/* Handle ATMS response to RPC Call */
+			printf("Handling ATMS response...\n");
+			handle_ATMS_response(clnt, rv);
+		}
+	}		
 }
 
-/* Creates an RPC client, populates the fep_reply data structure,
-   makes an RPC Call to the ATMS Server to pass the fep_reply,
-   destroys the RPC Client and returns
- */
-void fep_program_32(char *host)
+/* Creates an RPC Client which communicates with the ATMS through RPC Calls */
+CLIENT * create_client()
 {
 	CLIENT *clnt;
-
-	/* Var to recieve message back from ATMS */
-	void  *rv;
-
+	
 	/* Create RPC Client to communicate with ATMS */
 	printf("Preparing to create RPC client...\n");
@@ -103,13 +121,23 @@
 		exit(1);
 	}
+	
+	return clnt;
+}
 
-	/* Make RPC Call to transfer reply to ATMS */
-	printf("Transferring data to ATMS Server...\n");
-	fep_reply reply = generate_reply();
-	rv = fep_reply_xfer_32(&reply, clnt);
+/* update_ATMS transfers fep_replys to the ATMS Server. 
+	It creates an RPC client, loads data from line_atms.txt and lds_atms.txt,
+	updates the ATMS with the fep_reply data, and destroys the RPC client.
+ */
+void update_ATMS(char *host)
+{
+	CLIENT *clnt = create_client();
+	
+	/* Load data to be xfered to ATMS */
+	FEP_LINE_LDS *lines;
+	int lines_size = load_lines(&lines, "./lines_atms.txt");
+	FEP_LDS *ldsMap = load_lds("./lds_atms.txt");
 
-	/* Handle ATMS response to RPC Call */
-	printf("Handling ATMS response...\n");
-	handle_ATMS_response(clnt, rv);
+	/* Transfer data to ATMS */
+	xfer_replys(clnt, lines, lines_size, ldsMap);
 
 	/* Destroy client */
@@ -132,5 +160,5 @@
 	/* Create RPC Client to send an fep_reply to ATMS */
 	host = argv[1];
-	fep_program_32(host);
+	update_ATMS(host);
 
 	return 0;
