Changeset 82 in tmcsimulator for branches/FEPSimulator


Ignore:
Timestamp:
10/06/2017 06:54:21 PM (9 years ago)
Author:
jtorres
Message:

Added socket client to ATMSDriver. Added socket server to FEPSim

Location:
branches/FEPSimulator
Files:
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/FEPSimulator/DataPacker.h

    r80 r82  
    1414 
    1515// Include dependencies 
    16 #include "network.h"; 
     16#include "network.h" 
    1717#include <iostream> 
    1818#include <string.h> 
  • branches/FEPSimulator/FEPSim.cpp

    r80 r82  
    1 #include "FEPClient.h" 
     1#include "FEPSim.h" 
    22 
    33/** 
     
    77 * @param networkFile the xml network file 
    88 */ 
    9 FEPClient::FEPClient(char * host, char * networkFile) { 
    10     networkReader = new NetworkReader(networkFile); 
    11     createClient(host); 
     9FEPSim::FEPSim(char * ATMShost, char * xml) { 
     10    networkReader = new NetworkReader(xml); 
     11    this->ATMSHost = ATMShost; 
    1212    updateATMS(); 
    1313} 
     
    1616 * Destructor 
    1717 */ 
    18 FEPClient::~FEPClient() { 
     18FEPSim::~FEPSim() { 
    1919    cout << "Destroying client..." << endl; 
    2020    clnt_destroy(clnt); 
     
    2525 * @param response pointer to fep_reply struct 
    2626 */ 
    27 void FEPClient::handleCallResponse(void *response) { 
     27void FEPSim::handleCallResponse(void *response) { 
    2828    /* If ATMS reply call fails */ 
    2929    if (response == NULL) { 
    3030        clnt_perror(clnt, "RPC call failed"); 
    31     }        /* If ATMS reply is successful */ 
     31    }/* If ATMS reply is successful */ 
    3232    else { 
    3333        cout << "Successful RPC call to ATMS..." << endl; 
     
    3838 * Sends an fep_reply for every line in the FEP. 
    3939 */ 
    40 void FEPClient::updateATMS() { 
     40void FEPSim::updateATMS() { 
    4141    int i, j; // i == line_index, j == lds_index 
    4242    void *rv; 
    43  
    4443    vector<FEP_LINE*> lines = networkReader->getLines(); 
    4544    vector<STATION*> ldsMap = networkReader->getStations(); 
     
    122121 * @param host rpc server ip 
    123122 */ 
    124 void FEPClient::createClient(char * host) { 
     123void FEPSim::createClient(char * host) { 
    125124    /* Create RPC Client to communicate with ATMS */ 
    126125    cout << "Creating RPC Client" << endl; 
     
    142141int main(int argc, char *argv[]) { 
    143142 
    144     char *host; 
    145     char *networkFile; 
    146  
    147     if (argc < 3) { 
    148         cout << "usage:  " << argv[0] << " server_host networkFile" << endl; 
     143    int sockfd, newsockfd, portno, clilen; 
     144    char buffer[BUFF_SIZE]; 
     145    struct sockaddr_in serv_addr, cli_addr; 
     146    int n; 
     147     
     148    char *FEPSimHost = argv[1]; 
     149    portno = atoi(argv[2]); 
     150 
     151    /* First call to socket() function */ 
     152    sockfd = socket(AF_INET, SOCK_STREAM, 0); 
     153 
     154    if (sockfd < 0) { 
     155        perror("ERROR opening socket"); 
    149156        exit(1); 
    150157    } 
    151158 
    152     /* Create RPC Client to send an fep_reply to ATMS */ 
    153     host = argv[1]; 
    154     networkFile = argv[2]; 
    155  
    156     FEPClient *client = new FEPClient(host, networkFile); 
    157     delete client; 
     159    /* Initialize socket structure */ 
     160    bzero((char *) &serv_addr, sizeof (serv_addr)); 
     161 
     162    serv_addr.sin_family = AF_INET; 
     163    serv_addr.sin_addr.s_addr = INADDR_ANY; 
     164    serv_addr.sin_port = htons(portno); 
     165 
     166    /* Now bind the host address using bind() call.*/ 
     167    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) { 
     168        perror("ERROR on binding"); 
     169        exit(1); 
     170    } 
     171 
     172    /* Now start listening for the clients, here process will 
     173     * go in sleep mode and will wait for the incoming connection 
     174     */ 
     175 
     176    listen(sockfd, 5); 
     177    clilen = sizeof (cli_addr); 
     178 
     179    /* Accept actual connection from the client */ 
     180    while(1) { 
     181        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen); 
     182 
     183        if (newsockfd < 0) { 
     184            perror("ERROR on accept"); 
     185            exit(1); 
     186        } 
     187 
     188        /* If connection is established then start communicating */ 
     189        bzero(buffer, BUFF_SIZE); 
     190         
     191        // NEEDS OUTER LOOP TO GET WHOLE MESSAGE FROM TCP CONN 
     192        n = read(newsockfd, buffer, sizeof(buffer)); 
     193 
     194        if (n < 0) { 
     195            perror("ERROR reading from socket"); 
     196            exit(1); 
     197        } 
     198         
     199        /* Create RPC Client to send an fep_reply to ATMS */ 
     200 
     201        FEPSim *client = new FEPSim(FEPSimHost, buffer); 
     202        delete client; 
     203    } 
    158204 
    159205    return 0; 
  • branches/FEPSimulator/FEPSim.h

    r80 r82  
    11/*  
    2  * File: FEPClient.h 
     2 * File: FEPSim.h 
    33 *  
    4  * The FEPClient is an RPC Client which transfers network data to the 
     4 * The FEPSim is an RPC Client which transfers network data to the 
    55 * ATMS Server. 
    66 * 
    7  * An FEPClient is created every 30 seconds, and an fep_reply structure 
     7 * An FEPSim is created every 30 seconds, and an fep_reply structure 
    88 * for every FEP_LINE_LDS is transferred to the ATMS through an RPC Call. 
    9  * After the FEPClient has transferred all fep_replys, it is destroyed. 
     9 * After the FEPSim has transferred all fep_replys, it is destroyed. 
    1010 * 
    11  * An FEPClient is script-like in nature. There are no public methods other than 
    12  * the constructor. To construct an FEPClient, an input file (containing network  
     11 * An FEPSim is script-like in nature. There are no public methods other than 
     12 * the constructor. To construct an FEPSim, an input file (containing network  
    1313 * data in xml form) and a host server_ip (for the ATMS) are necessary. The  
    1414 * format of the xml input file can be fount in "networkReader.cpp" source file. 
     
    1919 
    2020// Include guard 
    21 #ifndef __FEPCLIENT_H_INCLUDED__ 
    22 #define __FEPCLIENT_H_INCLUDED__ 
     21#ifndef __FEPSIM_H_INCLUDED__ 
     22#define __FEPSIM_H_INCLUDED__ 
    2323 
    2424// Forward declared dependencies 
     
    2828#include "fep.h" 
    2929#include <iostream> 
     30#include <stdio.h> 
    3031#include <stdlib.h> 
    3132#include "time.h" 
    3233#include "NetworkReader.h" 
     34#include <netdb.h> 
     35#include <sys/types.h>  
     36#include <sys/socket.h> 
     37#include <netinet/in.h> 
     38#include <unistd.h> 
    3339 
    34 class FEPClient 
     40const int BUFF_SIZE = 1000000; 
     41 
     42class FEPSim 
    3543{ 
    3644        public: 
     
    3947 
    4048        /* methods */ 
    41                 FEPClient(char * host, char * networkFile); // Constructor 
    42                 ~FEPClient(); // Destructor 
     49                FEPSim(char * host, char * networkFile); // Constructor 
     50                ~FEPSim(); // Destructor 
    4351 
    4452        private: 
    4553        /* members */ 
    4654        NetworkReader *networkReader; 
    47  
     55        char * ATMSHost; 
     56         
    4857        /* methods */ 
    49                 void handleCallResponse(void *response); // 
    50                 void createClient(char *host); 
     58        void handleCallResponse(void *response); // 
     59        void createClient(char *host); 
    5160        void updateATMS(); // updates ATMS 
    5261 
    5362}; 
    5463 
    55 #endif // __FEPCLIENT_H_INCLUDED__ 
     64#endif // __FEPSIM_H_INCLUDED__ 
  • branches/FEPSimulator/NetworkReader.cpp

    r80 r82  
    55 * @param networkFileName input xml file 
    66 */ 
    7 NetworkReader::NetworkReader(const char * networkFileName) { 
     7NetworkReader::NetworkReader(const char * xml) { 
    88    ldsIndex = 0; 
    9     loadLines(networkFileName); 
     9    loadLines(xml); 
    1010} 
    1111 
     
    108108 * @param networkFileName the input xml file 
    109109 */ 
    110 void NetworkReader::loadLines(const char * networkFileName) { 
     110void NetworkReader::loadLines(const char * xml) { 
    111111    // Load network xml file 
    112     TiXmlDocument doc(networkFileName); 
    113     if (!doc.LoadFile()) { 
    114         cerr << "TiXmlDocument did not load network file..." << endl; 
    115         return; 
    116     } 
     112    TiXmlDocument doc; 
     113    doc.Parse((const char*)xml, 0, TIXML_ENCODING_UTF8); 
    117114 
    118115    // grab <Network> element 
  • branches/FEPSimulator/nbproject/Makefile-Debug.mk

    r80 r82  
    2222 
    2323# Macros 
    24 CND_PLATFORM=GNU-Linux-x86 
    25 CND_DLIB_EXT=so 
     24CND_PLATFORM=GNU-MacOSX 
     25CND_DLIB_EXT=dylib 
    2626CND_CONF=Debug 
    2727CND_DISTDIR=dist 
     
    3737OBJECTFILES= \ 
    3838        ${OBJECTDIR}/DataPacker.o \ 
    39         ${OBJECTDIR}/FEPClient.o \ 
     39        ${OBJECTDIR}/FEPSim.o \ 
    4040        ${OBJECTDIR}/NetworkReader.o \ 
    4141        ${OBJECTDIR}/fep_clnt.o \ 
     
    5757 
    5858# Link Libraries and Options 
    59 LDLIBSOPTIONS=tinyxml/tinyxml.a 
     59LDLIBSOPTIONS=tinyxml/libosxtinyxml.a 
    6060 
    6161# Build Targets 
    6262.build-conf: ${BUILD_SUBPROJECTS} 
    63         "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client 
     63        "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fepsimulator 
    6464 
    65 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: tinyxml/tinyxml.a 
     65${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fepsimulator: tinyxml/libosxtinyxml.a 
    6666 
    67 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client: ${OBJECTFILES} 
     67${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fepsimulator: ${OBJECTFILES} 
    6868        ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} 
    69         ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client ${OBJECTFILES} ${LDLIBSOPTIONS} 
     69        ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fepsimulator ${OBJECTFILES} ${LDLIBSOPTIONS} 
    7070 
    7171${OBJECTDIR}/DataPacker.o: DataPacker.cpp  
     
    7474        $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataPacker.o DataPacker.cpp 
    7575 
    76 ${OBJECTDIR}/FEPClient.o: FEPClient.cpp  
     76${OBJECTDIR}/FEPSim.o: FEPSim.cpp  
    7777        ${MKDIR} -p ${OBJECTDIR} 
    7878        ${RM} "$@.d" 
    79         $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/FEPClient.o FEPClient.cpp 
     79        $(COMPILE.cc) -g -Itinyxml -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/FEPSim.o FEPSim.cpp 
    8080 
    8181${OBJECTDIR}/NetworkReader.o: NetworkReader.cpp  
     
    100100.clean-conf: ${CLEAN_SUBPROJECTS} 
    101101        ${RM} -r ${CND_BUILDDIR}/${CND_CONF} 
    102         ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client 
     102        ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fepsimulator 
    103103 
    104104# Subprojects 
  • branches/FEPSimulator/nbproject/Makefile-impl.mk

    r77 r82  
    2525 
    2626# Project Name 
    27 PROJECTNAME=fep_rpc_client 
     27PROJECTNAME=FEPSimulator 
    2828 
    2929# Active Configuration 
  • branches/FEPSimulator/nbproject/Makefile-variables.mk

    r77 r82  
    88CND_DISTDIR=dist 
    99# Debug configuration 
    10 CND_PLATFORM_Debug=GNU-Linux-x86 
    11 CND_ARTIFACT_DIR_Debug=dist/Debug/GNU-Linux-x86 
    12 CND_ARTIFACT_NAME_Debug=fep_rpc_client 
    13 CND_ARTIFACT_PATH_Debug=dist/Debug/GNU-Linux-x86/fep_rpc_client 
    14 CND_PACKAGE_DIR_Debug=dist/Debug/GNU-Linux-x86/package 
    15 CND_PACKAGE_NAME_Debug=feprpcclient.tar 
    16 CND_PACKAGE_PATH_Debug=dist/Debug/GNU-Linux-x86/package/feprpcclient.tar 
     10CND_PLATFORM_Debug=GNU-MacOSX 
     11CND_ARTIFACT_DIR_Debug=dist/Debug/GNU-MacOSX 
     12CND_ARTIFACT_NAME_Debug=fepsimulator 
     13CND_ARTIFACT_PATH_Debug=dist/Debug/GNU-MacOSX/fepsimulator 
     14CND_PACKAGE_DIR_Debug=dist/Debug/GNU-MacOSX/package 
     15CND_PACKAGE_NAME_Debug=fepsimulator.tar 
     16CND_PACKAGE_PATH_Debug=dist/Debug/GNU-MacOSX/package/fepsimulator.tar 
    1717# Release configuration 
    1818CND_PLATFORM_Release=GNU-Linux-x86 
  • branches/FEPSimulator/nbproject/Package-Debug.bash

    r77 r82  
    77# Macros 
    88TOP=`pwd` 
    9 CND_PLATFORM=GNU-Linux-x86 
     9CND_PLATFORM=GNU-MacOSX 
    1010CND_CONF=Debug 
    1111CND_DISTDIR=dist 
    1212CND_BUILDDIR=build 
    13 CND_DLIB_EXT=so 
     13CND_DLIB_EXT=dylib 
    1414NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging 
    1515TMPDIRNAME=tmp-packaging 
    16 OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fep_rpc_client 
    17 OUTPUT_BASENAME=fep_rpc_client 
    18 PACKAGE_TOP_DIR=feprpcclient/ 
     16OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/fepsimulator 
     17OUTPUT_BASENAME=fepsimulator 
     18PACKAGE_TOP_DIR=fepsimulator/ 
    1919 
    2020# Functions 
     
    6161# Copy files and create directories and links 
    6262cd "${TOP}" 
    63 makeDirectory "${NBTMPDIR}/feprpcclient/bin" 
     63makeDirectory "${NBTMPDIR}/fepsimulator/bin" 
    6464copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 
    6565 
     
    6767# Generate tar file 
    6868cd "${TOP}" 
    69 rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/feprpcclient.tar 
     69rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/fepsimulator.tar 
    7070cd ${NBTMPDIR} 
    71 tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/feprpcclient.tar * 
     71tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/fepsimulator.tar * 
    7272checkReturnCode 
    7373 
  • branches/FEPSimulator/nbproject/configurations.xml

    r80 r82  
    66                   projectFiles="true"> 
    77      <itemPath>DataPacker.h</itemPath> 
    8       <itemPath>FEPClient.h</itemPath> 
     8      <itemPath>FEPSim.h</itemPath> 
    99      <itemPath>NetworkReader.h</itemPath> 
    1010      <itemPath>fep.h</itemPath> 
     
    1919                   projectFiles="true"> 
    2020      <itemPath>DataPacker.cpp</itemPath> 
    21       <itemPath>FEPClient.cpp</itemPath> 
     21      <itemPath>FEPSim.cpp</itemPath> 
    2222      <itemPath>NetworkReader.cpp</itemPath> 
    2323      <itemPath>fep_clnt.c</itemPath> 
     
    5252        <linkerTool> 
    5353          <linkerLibItems> 
    54             <linkerLibFileItem>tinyxml/tinyxml.a</linkerLibFileItem> 
     54            <linkerLibFileItem>tinyxml/libosxtinyxml.a</linkerLibFileItem> 
    5555          </linkerLibItems> 
    5656        </linkerTool> 
     
    6060      <item path="DataPacker.h" ex="false" tool="3" flavor2="0"> 
    6161      </item> 
    62       <item path="FEPClient.cpp" ex="false" tool="1" flavor2="0"> 
     62      <item path="FEPSim.cpp" ex="false" tool="1" flavor2="0"> 
    6363      </item> 
    64       <item path="FEPClient.h" ex="false" tool="3" flavor2="0"> 
     64      <item path="FEPSim.h" ex="false" tool="3" flavor2="0"> 
    6565      </item> 
    6666      <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0"> 
     
    101101      <item path="DataPacker.h" ex="false" tool="3" flavor2="0"> 
    102102      </item> 
    103       <item path="FEPClient.cpp" ex="false" tool="1" flavor2="0"> 
     103      <item path="FEPSim.cpp" ex="false" tool="1" flavor2="0"> 
    104104      </item> 
    105       <item path="FEPClient.h" ex="false" tool="3" flavor2="0"> 
     105      <item path="FEPSim.h" ex="false" tool="3" flavor2="0"> 
    106106      </item> 
    107107      <item path="NetworkReader.cpp" ex="false" tool="1" flavor2="0"> 
  • branches/FEPSimulator/nbproject/private/configurations.xml

    r80 r82  
    66      <toolsSet> 
    77        <developmentServer>localhost</developmentServer> 
    8         <platform>2</platform> 
     8        <platform>4</platform> 
    99      </toolsSet> 
    1010      <dbx_gdbdebugger version="1"> 
     
    2828          <runcommandpicklistitem>"${OUTPUT_PATH}" localhost networkFile.txt</runcommandpicklistitem> 
    2929          <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27 networkFile.txt</runcommandpicklistitem> 
     30          <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27</runcommandpicklistitem> 
     31          <runcommandpicklistitem>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommandpicklistitem> 
    3032        </runcommandpicklist> 
    31         <runcommand>"${OUTPUT_PATH}" 192.168.251.27 networkFile.txt</runcommand> 
     33        <runcommand>"${OUTPUT_PATH}" 192.168.251.27 8080</runcommand> 
    3234        <rundir></rundir> 
    3335        <buildfirst>true</buildfirst> 
Note: See TracChangeset for help on using the changeset viewer.