Index: /branches/FEPSimulator/FEPSim.h
===================================================================
--- /branches/FEPSimulator/FEPSim.h	(revision 84)
+++ /branches/FEPSimulator/FEPSim.h	(revision 86)
@@ -2,15 +2,20 @@
  * File: FEPSim.h
  * 
- * The FEPSim is an RPC Client which transfers network data to the
- * ATMS Server.
+ * The FEP Simulator simulates the Front End Processor(FEP), which has the
+ * responsibility of "polling" Loop Detector Stations for highway status data.
+ * The real FEP "polls" real stations over serial communication lines, whereas
+ * the FEP Simulator recieves highway status data through a socket from the Java
+ * ATMS Driver.
+ * 
+ * Highway status data is transmitted to the FEP Simulator over the socket in
+ * XML Form. The XML highway status data is then parsed by the Network Reader.
+ * 
+ * The data is then sent to the ATMS, using RPC Calls. The RPC Calls to the
+ * ATMS Server send an fep_reply structure. There is one fep_reply structure
+ * sent to the ATMS for every FEP_LINE.
  *
- * An FEPSim is created every 30 seconds, and an fep_reply structure
- * for every FEP_LINE_LDS is transferred to the ATMS through an RPC Call.
- * After the FEPSim has transferred all fep_replys, it is destroyed.
- *
- * An FEPSim is script-like in nature. There are no public methods other than
- * the constructor. To construct an FEPSim, an input file (containing network 
- * data in xml form) and a host server_ip (for the ATMS) are necessary. The 
- * format of the xml input file can be fount in "networkReader.cpp" source file.
+ * The FEP Simulator is a socket server that runs persistently and awaits the
+ * XML highway status data over the socket. When the XML highway status data is
+ * recieved, it executes the RPC Calls to update the ATMS.
  *
  * @author John A. Torres
@@ -42,12 +47,33 @@
 class FEPSim {
 public:
-    /* members */
-    CLIENT *clnt; // RPC Client
+    // The RPC Client
+    CLIENT *clnt;
 
-    /* methods */
-    FEPSim(char * ATMSHost); // Constructor
+    /**
+     * Constructor. Sets data values for RPC Client and socket server.
+     * 
+     * @param ATMSHost The IP of ATMS Server
+     * @param FEP RPC program number
+     * @param FEP RPC program revision number
+     * @param Socket Server listen port
+     */
+    FEPSim(char * ATMSHost, int FEP_PROG, int FEP_REV, int SOCK_PORT);
     
-    void updateATMS(char * xml); // updates ATMS
-
+    /**
+     * Creates a socket server and awaits the highway status XML responses from the
+     * ATMS Driver. Upon reciept of the highway status XML message, creates an RPC
+     * client and sends the fep_replys to the ATMS.
+     */
+    void runSockServer();
+    
+    /**
+     * Creates an RPC Client, and on successful creation, sends fep_replys to ATMS.
+     * @param The recieved highway status xml.
+     */
+    void updateATMS(char * xml);
+    
+    /**
+     * Destructor: Does nothing, no cleaning necessary
+     */
     ~FEPSim(); // Destructor
 
@@ -55,8 +81,24 @@
     /* members */
     char * ATMSHost;
+    int FEP_PROG;
+    int FEP_REV;
+    int SOCK_PORT;
 
-    /* methods */
-    void handleCallResponse(void *response); //
-    bool createClient(char *host);
+    /**
+     * Handler for the ATMS RPC Response (to the client RPC Call)
+     * @param response pointer to fep_reply struct
+     */
+    void handleCallResponse(void *response);
+    
+    /**
+     * Creates the RPC Client. If not successful, returns false.
+     */
+    bool createClient();
+    
+    /**
+     * Sends an fep_reply for each FEP_LINE. Gets highway status from recieved XML
+     * data.
+     * @param xml The recieved highway status XML.
+     */
     void sendReplys(char * xml);
 
Index: /branches/FEPSimulator/nbproject/configurations.xml
===================================================================
--- /branches/FEPSimulator/nbproject/configurations.xml	(revision 82)
+++ /branches/FEPSimulator/nbproject/configurations.xml	(revision 86)
@@ -20,4 +20,5 @@
       <itemPath>DataPacker.cpp</itemPath>
       <itemPath>FEPSim.cpp</itemPath>
+      <itemPath>Main.cpp</itemPath>
       <itemPath>NetworkReader.cpp</itemPath>
       <itemPath>fep_clnt.c</itemPath>
@@ -64,4 +65,6 @@
       <item path="FEPSim.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="Main.cpp" ex="false" tool="1" flavor2="0">
+      </item>
       <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0">
       </item>
@@ -105,4 +108,6 @@
       <item path="FEPSim.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="Main.cpp" ex="false" tool="1" flavor2="0">
+      </item>
       <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0">
       </item>
Index: /branches/FEPSimulator/nbproject/private/configurations.xml
===================================================================
--- /branches/FEPSimulator/nbproject/private/configurations.xml	(revision 82)
+++ /branches/FEPSimulator/nbproject/private/configurations.xml	(revision 86)
@@ -30,6 +30,7 @@
           <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27</runcommandpicklistitem>
           <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommandpicklistitem>
+          <runcommandpicklistitem>"${OUTPUT_PATH}" 1192.168.251.27 103121 32 8080</runcommandpicklistitem>
         </runcommandpicklist>
-        <runcommand>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommand>
+        <runcommand>"${OUTPUT_PATH}" 1192.168.251.27 103121 32 8080</runcommand>
         <rundir></rundir>
         <buildfirst>true</buildfirst>
Index: /branches/FEPSimulator/nbproject/Makefile-Debug.mk
===================================================================
--- /branches/FEPSimulator/nbproject/Makefile-Debug.mk	(revision 82)
+++ /branches/FEPSimulator/nbproject/Makefile-Debug.mk	(revision 86)
@@ -38,4 +38,5 @@
 	${OBJECTDIR}/DataPacker.o \
 	${OBJECTDIR}/FEPSim.o \
+	${OBJECTDIR}/Main.o \
 	${OBJECTDIR}/NetworkReader.o \
 	${OBJECTDIR}/fep_clnt.o \
@@ -79,4 +80,9 @@
 	$(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/FEPSim.o FEPSim.cpp
 
+${OBJECTDIR}/Main.o: Main.cpp 
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Main.o Main.cpp
+
 ${OBJECTDIR}/NetworkReader.o: NetworkReader.cpp 
 	${MKDIR} -p ${OBJECTDIR}
Index: /branches/FEPSimulator/NetworkReader.cpp
===================================================================
--- /branches/FEPSimulator/NetworkReader.cpp	(revision 84)
+++ /branches/FEPSimulator/NetworkReader.cpp	(revision 86)
@@ -1,8 +1,4 @@
 #include "NetworkReader.h"
 
-/**
- * Constructor
- * @param networkFileName input xml file
- */
 NetworkReader::NetworkReader(const char * xml) {
     ldsIndex = 0;
@@ -11,30 +7,23 @@
 
 LOOP * NetworkReader::parseLoop(TiXmlElement * loopElem) {
-        LOOP *loop = new LOOP;
+    LOOP *loop = new LOOP;
 
-        TiXmlElement *subLoopElem = loopElem->FirstChildElement();
-        loop->loopID = atoi(subLoopElem->GetText());
-        subLoopElem = subLoopElem->NextSiblingElement();
-        loop->loop_loc = (char *) subLoopElem->GetText();
-        subLoopElem = subLoopElem->NextSiblingElement();
-        loop->vol = atoi(subLoopElem->GetText());
-        subLoopElem = subLoopElem->NextSiblingElement();
-        loop->occ = atof(subLoopElem->GetText());
-        subLoopElem = subLoopElem->NextSiblingElement();
-        loop->spd = atof(subLoopElem->GetText());
-        
-        return loop;
+    TiXmlElement *subLoopElem = loopElem->FirstChildElement();
+    loop->loopID = atoi(subLoopElem->GetText());
+    subLoopElem = subLoopElem->NextSiblingElement();
+    loop->loop_loc = (char *) subLoopElem->GetText();
+    subLoopElem = subLoopElem->NextSiblingElement();
+    loop->vol = atoi(subLoopElem->GetText());
+    subLoopElem = subLoopElem->NextSiblingElement();
+    loop->occ = atof(subLoopElem->GetText());
+    subLoopElem = subLoopElem->NextSiblingElement();
+    loop->spd = atof(subLoopElem->GetText());
+
+    return loop;
 }
 
-/**
- * Parses a station xml element into an "STATION"
- * 
- * @param stationElem the station xml element
- * @param the parent line
- * @return the new station
- */
 STATION * NetworkReader::parseStation(TiXmlElement *stationElem, FEP_LINE *line) {
     STATION *station = new STATION;
-    
+
     TiXmlElement *stationSubElem = stationElem->FirstChildElement();
     station->lds = atol(stationSubElem->GetText());
@@ -56,5 +45,5 @@
 
     station->pos = 0; // NOT SURE WHY WE NEED THIS?
-    
+
     // Add loops to station
     TiXmlElement *loopElem = stationSubElem->NextSiblingElement()->FirstChildElement();
@@ -68,13 +57,8 @@
     cout << station->loops.size() << endl;
     station->dataPack = DataPacker::packData(station);
-    
+
     return station;
 }
 
-/**
- * Parses a "Line" xml element into an FEP_LINE
- * @param lineElem the xml element
- * @return FEP_LINE
- */
 FEP_LINE * NetworkReader::parseLine(TiXmlElement * lineElem) {
     FEP_LINE *line = new FEP_LINE;
@@ -104,12 +88,8 @@
 }
 
-/**
- * Loads FEPLines from a specified xml file
- * @param networkFileName the input xml file
- */
 void NetworkReader::loadLines(const char * xml) {
     // Load network xml file
     TiXmlDocument doc;
-    doc.Parse((const char*)xml, 0, TIXML_ENCODING_UTF8);
+    doc.Parse((const char*) xml, 0, TIXML_ENCODING_UTF8);
 
     // grab <Network> element
@@ -126,8 +106,4 @@
 }
 
-/**
- * Getter for lines
- * @return List of FEP_LINES
- */
 vector<FEP_LINE*> NetworkReader::getLines() {
 
@@ -135,8 +111,4 @@
 }
 
-/**
- * Getter for stations
- * @return List of STATIONs
- */
 vector<STATION*> NetworkReader::getStations() {
 
Index: /branches/FEPSimulator/build/Debug/GNU-MacOSX/fep_xdr.o.d
===================================================================
--- /branches/FEPSimulator/build/Debug/GNU-MacOSX/fep_xdr.o.d	(revision 86)
+++ /branches/FEPSimulator/build/Debug/GNU-MacOSX/fep_xdr.o.d	(revision 86)
@@ -0,0 +1,3 @@
+build/Debug/GNU-MacOSX/fep_xdr.o: fep_xdr.c fep.h
+
+fep.h:
Index: /branches/FEPSimulator/build/Debug/GNU-MacOSX/fep_clnt.o.d
===================================================================
--- /branches/FEPSimulator/build/Debug/GNU-MacOSX/fep_clnt.o.d	(revision 86)
+++ /branches/FEPSimulator/build/Debug/GNU-MacOSX/fep_clnt.o.d	(revision 86)
@@ -0,0 +1,3 @@
+build/Debug/GNU-MacOSX/fep_clnt.o: fep_clnt.c fep.h
+
+fep.h:
Index: /branches/FEPSimulator/build/Debug/GNU-MacOSX/NetworkReader.o.d
===================================================================
--- /branches/FEPSimulator/build/Debug/GNU-MacOSX/NetworkReader.o.d	(revision 86)
+++ /branches/FEPSimulator/build/Debug/GNU-MacOSX/NetworkReader.o.d	(revision 86)
@@ -0,0 +1,12 @@
+build/Debug/GNU-MacOSX/NetworkReader.o: NetworkReader.cpp NetworkReader.h \
+  network.h tinyxml/tinyxml.h tinyxml/tinystr.h DataPacker.h
+
+NetworkReader.h:
+
+network.h:
+
+tinyxml/tinyxml.h:
+
+tinyxml/tinystr.h:
+
+DataPacker.h:
Index: /branches/FEPSimulator/build/Debug/GNU-MacOSX/DataPacker.o.d
===================================================================
--- /branches/FEPSimulator/build/Debug/GNU-MacOSX/DataPacker.o.d	(revision 86)
+++ /branches/FEPSimulator/build/Debug/GNU-MacOSX/DataPacker.o.d	(revision 86)
@@ -0,0 +1,6 @@
+build/Debug/GNU-MacOSX/DataPacker.o: DataPacker.cpp DataPacker.h \
+  network.h
+
+DataPacker.h:
+
+network.h:
Index: /branches/FEPSimulator/build/Debug/GNU-MacOSX/FEPSim.o.d
===================================================================
--- /branches/FEPSimulator/build/Debug/GNU-MacOSX/FEPSim.o.d	(revision 86)
+++ /branches/FEPSimulator/build/Debug/GNU-MacOSX/FEPSim.o.d	(revision 86)
@@ -0,0 +1,17 @@
+build/Debug/GNU-MacOSX/FEPSim.o: FEPSim.cpp FEPSim.h fep.h \
+  NetworkReader.h network.h tinyxml/tinyxml.h tinyxml/tinystr.h \
+  DataPacker.h
+
+FEPSim.h:
+
+fep.h:
+
+NetworkReader.h:
+
+network.h:
+
+tinyxml/tinyxml.h:
+
+tinyxml/tinystr.h:
+
+DataPacker.h:
Index: /branches/FEPSimulator/build/Debug/GNU-MacOSX/Main.o.d
===================================================================
--- /branches/FEPSimulator/build/Debug/GNU-MacOSX/Main.o.d	(revision 86)
+++ /branches/FEPSimulator/build/Debug/GNU-MacOSX/Main.o.d	(revision 86)
@@ -0,0 +1,16 @@
+build/Debug/GNU-MacOSX/Main.o: Main.cpp FEPSim.h fep.h NetworkReader.h \
+  network.h tinyxml/tinyxml.h tinyxml/tinystr.h DataPacker.h
+
+FEPSim.h:
+
+fep.h:
+
+NetworkReader.h:
+
+network.h:
+
+tinyxml/tinyxml.h:
+
+tinyxml/tinystr.h:
+
+DataPacker.h:
Index: /branches/FEPSimulator/NetworkReader.h
===================================================================
--- /branches/FEPSimulator/NetworkReader.h	(revision 80)
+++ /branches/FEPSimulator/NetworkReader.h	(revision 86)
@@ -58,21 +58,64 @@
 #include "DataPacker.h"
 
-class NetworkReader
-{
-    public:
-        NetworkReader(const char * networkFile); // Constructor
-        ~NetworkReader(); // Destructor
-        
-        vector<FEP_LINE*> getLines(); // Getter for FEP_LINE list
-        vector<STATION*> getStations(); // Getter for STATION list
-    private:
-        vector<FEP_LINE*> lines;
-        vector<STATION*> stations;
-        int ldsIndex;
-
-        void loadLines(const char * networkFileName);
-        LOOP * parseLoop(TiXmlElement * loopElem);
-        STATION * parseStation(TiXmlElement *stationElem, FEP_LINE *line);
-        FEP_LINE * parseLine(TiXmlElement *lineElem);
+class NetworkReader {
+public:
+    /**
+     * Constructor
+     * @param xml Highway Status XML data
+     */
+    NetworkReader(const char * xml);
+    
+    /**
+     * Destructor: no cleaning necessary
+     */
+    ~NetworkReader();
+    
+    /**
+     * Returns FEP_LINE list.
+     * 
+     * @return List of FEP_LINES
+     */
+    vector<FEP_LINE*> getLines();
+    
+    /**
+     * Returns STATIONS list.
+     * @return List of STATIONs
+     */
+    vector<STATION*> getStations();
+    
+private:
+    vector<FEP_LINE*> lines;
+    vector<STATION*> stations;
+    int ldsIndex;
+    
+    /**
+     * Loads Highway Status data from xml.
+     * 
+     * @param xml Highway Status XML.
+     */
+    void loadLines(const char * networkFileName);
+    
+    /**
+     * Parses a single LOOP
+     * @param loopElem TinyXML loop elem
+     * @return LOOP
+     */
+    LOOP * parseLoop(TiXmlElement * loopElem);
+    
+    /**
+     * Parses a single STATION
+     * 
+     * @param TinyXML station element
+     * @param the parent FEP_LINE
+     * @return STATION
+     */
+    STATION * parseStation(TiXmlElement *stationElem, FEP_LINE *line);
+    
+    /**
+     * Parses a single FEP_LINE
+     * @param TinyXML line element
+     * @return FEP_LINE
+     */
+    FEP_LINE * parseLine(TiXmlElement *lineElem);
 };
 
Index: /branches/FEPSimulator/FEPSim.cpp
===================================================================
--- /branches/FEPSimulator/FEPSim.cpp	(revision 84)
+++ /branches/FEPSimulator/FEPSim.cpp	(revision 86)
@@ -1,26 +1,15 @@
 #include "FEPSim.h"
 
-/**
- * Constructor
- * 
- * @param host The host rpc server ip address
- * @param networkFile the xml network file
- */
-FEPSim::FEPSim(char * ATMShost) {
+FEPSim::FEPSim(char * ATMShost, int FEP_PROG, int FEP_REV, int SOCK_PORT) {
     this->ATMSHost = ATMShost;
+    this->FEP_PROG = FEP_PROG;
+    this->FEP_REV = FEP_REV;
+    this->SOCK_PORT = SOCK_PORT;
 }
 
-/**
- * Destructor
- */
 FEPSim::~FEPSim() {
-    cout << "Destroying client..." << endl;
-    clnt_destroy(clnt);
+
 }
 
-/**
- * Handler for the ATMS RPC Response (to the client RPC Call)
- * @param response pointer to fep_reply struct
- */
 void FEPSim::handleCallResponse(void *response) {
     // Failed RPC Call
@@ -34,10 +23,9 @@
 }
 
-void FEPSim::sendReplys(char * xml)
-{
+void FEPSim::sendReplys(char * xml) {
     NetworkReader networkReader = NetworkReader(xml);
     vector<FEP_LINE*> lines = networkReader.getLines();
     vector<STATION*> ldsMap = networkReader.getStations();
-    
+
     // Send one reply for every FEPLine
     for (int i = 0; i < lines.size(); i++) {
@@ -104,29 +92,22 @@
 }
 
-/**
- * Sends an fep_reply for every line in the FEP.
- */
 void FEPSim::updateATMS(char * xml) {
-    if(createClient(this->ATMSHost))
-    {
+    if (createClient()) {
         sendReplys(xml);
+        cout << "Destroying client..." << endl;
+        clnt_destroy(clnt);
     }
 }
 
-/**
- * Creates the RPC Client. If not successful, exit with status 1.
- * @param host rpc server ip
- */
-bool FEPSim::createClient(char * host) {
+bool FEPSim::createClient() {
     /* Create RPC Client to communicate with ATMS */
     bool success = true;
-    cout << "Creating RPC Client" << endl;
-    clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp");
+
+    clnt = clnt_create(this->ATMSHost, FEP_PROG, FEP_REV, "tcp");
     /* Check if client creation failed */
     if (clnt == (CLIENT *) NULL) {
-        cerr << "Can't create client to " << host << endl;
+        cerr << "Can't create client to " << this->ATMSHost << endl;
         success = false;
-    }
-    else {
+    } else {
         cout << "Client created" << endl;
     }
@@ -134,24 +115,10 @@
 }
 
-/**
- * Main driver for ATMSCommunicator. Creates an RPC Client from command line args.
- * @param argc
- * @param argv
- * @return 
- */
-int main(int argc, char *argv[]) {
-    if(argc != 3)
-    {
-        cerr << "Usage: FEPSim <ATMS_Host> <FEP_ATMSDriver_PortNo" << endl;
-        exit(1);
-    }
-    char *FEPSimHost = argv[1];    
-    FEPSim fep = FEPSim(FEPSimHost);
-    
+void FEPSim::runSockServer() {
     int sockfd, newsockfd, portno, clilen;
     char buffer[BUFF_SIZE];
     struct sockaddr_in serv_addr, cli_addr;
     int n;
-    portno = atoi(argv[2]);
+    portno = this->SOCK_PORT;
 
     /* First call to socket() function */
@@ -184,6 +151,6 @@
 
     /* Accept actual connections from the client */
-    while(1) {
-        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
+    while (1) {
+        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *) & clilen);
 
         if (newsockfd < 0) {
@@ -195,20 +162,18 @@
         // zero out buffer
         bzero(buffer, BUFF_SIZE);
-        
+
         // read XML from socket
         int totBytes = 0;
-        while ((n = recv(newsockfd, &buffer[totBytes], sizeof(buffer), 0)) > 0) {
+        while ((n = recv(newsockfd, &buffer[totBytes], sizeof (buffer), 0)) > 0) {
             totBytes += n;
         }
-        
+
         if (n < 0) {
             perror("ERROR reading from socket");
             exit(1);
         }
-        
+
         // send data to atms
-        fep.updateATMS(buffer);
+        updateATMS(buffer);
     }
-
-    return 0;
 }
Index: /branches/FEPSimulator/Main.cpp
===================================================================
--- /branches/FEPSimulator/Main.cpp	(revision 86)
+++ /branches/FEPSimulator/Main.cpp	(revision 86)
@@ -0,0 +1,38 @@
+/* 
+ * File:   Main.cpp
+ * Author: John A. Torres
+ *
+ * Created on October 7, 2017, 4:27 PM
+ */
+
+#include <cstdlib>
+#include "FEPSim.h"
+
+using namespace std;
+
+/**
+ * Main driver for FEP Simulator. Creates a socket server that reads Highway
+ * Status from the ATMS Driver over the socket, in XML form. Runs persistently.
+ * 
+ * @param argc argument count
+ * @param argv args
+ * @return 
+ */
+int main(int argc, char *argv[]) {
+    if(argc != 5)
+    {
+        cerr << "Usage: FEPSim <ATMS_Host> <FEP_ATMSDriver_PortNo> <FEP_PROG_NUM>"
+                "<FEP_REVISION_NUM>" << endl;
+        exit(1);
+    }
+    char *FEPSimHost = argv[1];
+    int fep_prog = atoi(argv[2]);
+    int fep_rev = atoi(argv[3]);
+    int portno = atoi(argv[4]);
+    
+    FEPSim fep = FEPSim(FEPSimHost, fep_prog, fep_rev, portno);
+    fep.runSockServer();
+
+    return 0;
+}
+
