source: tmcsimulator/branches/FEPSimulator/FEPSim.h @ 217

Revision 217, 3.0 KB checked in by jtorres, 9 years ago (diff)

Implemented logging into FEPSimulator. Now logs output into FEPSimLog.txt. Error messages are still output to console so you know immediately if there is an error. The log file is cleared upon FEPSim start-up.

Line 
1/*
2 * File: FEPSim.h
3 *
4 * The FEP Simulator simulates the Front End Processor(FEP), which has the
5 * responsibility of "polling" Loop Detector Stations for highway status data.
6 * The real FEP "polls" real stations over serial communication lines, whereas
7 * the FEP Simulator recieves highway status data through a socket from the Java
8 * ATMS Driver.
9 *
10 * Highway status data is transmitted to the FEP Simulator over the socket in
11 * XML Form. The XML highway status data is then parsed by the Network Reader.
12 *
13 * The data is then sent to the ATMS, using RPC Calls. The RPC Calls to the
14 * ATMS Server send an fep_reply structure. There is one fep_reply structure
15 * sent to the ATMS for every FEP_LINE.
16 *
17 * The FEP Simulator is a socket server that runs persistently and awaits the
18 * XML highway status data over the socket. When the XML highway status data is
19 * recieved, it executes the RPC Calls to update the ATMS.
20 *
21 * @author John A. Torres
22 * @version 9/8/2017
23 */
24
25// Include guard
26#ifndef __FEPSIM_H_INCLUDED__
27#define __FEPSIM_H_INCLUDED__
28
29// Forward declared dependencies
30class HighwaysParser;
31
32// Included dependencies
33#include "fep.h"
34#include <iostream>
35#include <fstream>
36#include <stdio.h>
37#include <stdlib.h>
38#include "time.h"
39#include "HighwaysParser.h"
40#include <netdb.h>
41#include <sys/types.h>
42#include <sys/socket.h>
43#include <netinet/in.h>
44#include <unistd.h>
45
46const int BUFF_SIZE = 1266341;
47const string FEPLogFileName = "FEPSimLog.txt";
48static ofstream FEPLogFile;
49   
50class FEPSim {
51public:
52    // The RPC Client
53    CLIENT *clnt;
54
55    /**
56     * Constructor. Sets data values for RPC Client and socket server.
57     *
58     * @param ATMSHost The IP of ATMS Server
59     * @param FEP RPC program number
60     * @param FEP RPC program revision number
61     * @param Socket Server listen port
62     */
63    FEPSim(char * ATMSHost, int FEP_PROG, int FEP_REV, int SOCK_PORT);
64   
65    /**
66     * Creates a socket server and awaits the highway status XML responses from the
67     * ATMS Driver. Upon reciept of the highway status XML message, creates an RPC
68     * client and sends the fep_replys to the ATMS.
69     */
70    void runSockServer();
71   
72    /**
73     * Creates an RPC Client, and on successful creation, sends fep_replys to ATMS.
74     * @param The recieved highway status xml.
75     */
76    void manageClientConnection(char * xml);
77   
78    /**
79     * Destructor: Does nothing, no cleaning necessary
80     */
81    ~FEPSim(); // Destructor
82
83private:
84    /* members */
85    char * ATMSHost;
86    int FEP_PROG;
87    int FEP_REV;
88    int SOCK_PORT;
89   
90    /**
91     * Handler for the ATMS RPC Response (to the client RPC Call)
92     * @param response pointer to fep_reply struct
93     */
94    void handleCallResponse(void *response);
95   
96    /**
97     * Creates the RPC Client. If not successful, returns false.
98     */
99    bool createClient();
100   
101    /**
102     * Sends an fep_reply for each FEP_LINE. Gets highway status from recieved XML
103     * data.
104     * @param xml The recieved highway status XML.
105     */
106    void sendReplys(char * xml);
107   
108};
109
110#endif // __FEPSIM_H_INCLUDED__
Note: See TracBrowser for help on using the repository browser.