Skip to content

Commit

Permalink
remove hard adress and tscg code
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic-smile committed Jun 5, 2024
1 parent dd9de92 commit eebcf76
Show file tree
Hide file tree
Showing 12 changed files with 867 additions and 101 deletions.
14 changes: 12 additions & 2 deletions include/enhanced_hnz_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <chrono>
#include <thread>
#include <mutex>

#include "state_machine.h"
#include "hnz_server.h"

/**
Expand All @@ -19,7 +19,7 @@ class EnhancedHNZServer
*/
EnhancedHNZServer(int port, int addr) : m_port(port),m_addr(addr)
{

m_state_machine = std::make_shared<StateMachine>();
};

EnhancedHNZServer(EnhancedHNZServer const &) = delete;
Expand Down Expand Up @@ -134,6 +134,13 @@ class EnhancedHNZServer
*/
static std::string frameToStr(const std::shared_ptr<MSG_TRAME> &frame);

/**
* Converts a frame to its string representation.
* @param frame The frame to convert.
* @return The string representation of the frame.
*/
static std::string frameToStr(const MSG_TRAME* frame);

/**
* Converts a vector of frames to their string representation.
* @param frames The vector of frames to convert.
Expand All @@ -153,6 +160,7 @@ class EnhancedHNZServer
*/
int getPort() const { return m_port;}

std::shared_ptr<StateMachine> getStateMachine() const { return m_state_machine; }
private:

HNZServer *server = nullptr;
Expand Down Expand Up @@ -197,4 +205,6 @@ class EnhancedHNZServer
* @param port The port to start the server on.
*/
static void m_start(HNZServer *server, int port) { server->start(port); };

std::shared_ptr<StateMachine> m_state_machine;
};
7 changes: 6 additions & 1 deletion include/hnz.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class HNZ
*/
void m_parseTVC(const ReadingParameters &params);

/**
* Parses TM data according to the given parameters.
* @param params The parameters required for parsing the TM data.
*/
void m_parseTM(const ReadingParameters &params);

/**
* Performs a specific operation with parameters.
Expand All @@ -174,7 +179,7 @@ class HNZ
*/
int operation(char *operation, int paramCount, char *names[], char *parameters[]);

std::unique_ptr<HnzConfig> m_hnz_config;
std::shared_ptr<HnzConfig> m_hnz_config;

std::map<int, std::vector<unsigned char>> m_hnz_data{};

Expand Down
5 changes: 4 additions & 1 deletion include/hnz_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class HnzConfig
GiStatus m_giStatus = GiStatus::IDLE;
};


unsigned char GetRemoteStationAddress() const { return m_remote_station_addr;}
std::vector<SouthPluginMonitor *> GetMonitoredSouthPlugins() const { return m_monitoredSouthPlugins; };

bool IsProtocolConfigComplete() const { return m_protocolConfigComplete; };
Expand All @@ -122,6 +124,7 @@ class HnzConfig

std::string CmdDest() const { return m_cmd_dest;};


private:
static bool m_isValidIPAddress(const std::string &addrStr);

Expand Down Expand Up @@ -150,7 +153,7 @@ class HnzConfig
unsigned int m_lastTSAddr = 0;
// Nested map of msg_code, remote_station_addr and msg_address
std::map<std::string, std::map<unsigned int, std::map<unsigned int, std::string>>> m_msg_list;
unsigned int m_remote_station_addr = 0;
unsigned char m_remote_station_addr = 0;

std::string m_cmd_dest;
};
37 changes: 37 additions & 0 deletions include/pa_hnz_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <array>

/**
* @class PaHnzData
* @brief Manages and processes HNZ protocol data.
*
* The PaHnzData class is responsible for handling HNZ protocol data,
* including setting values and converting them to a specific format.
*/
class PaHnzData {

public:
/**
* @brief Sets the value for a given address.
*
* @param addr The address for which the value is being set.
* @param valid A boolean indicating whether the value is valid.
* @param open A boolean indicating whether the value represents an open state.
*
* This method sets the value for a specific TS address in the HNZ protocol data.
*/
void setTsValue(unsigned char addr, bool valid, bool open);

/**
* @brief Converts the current values to the TSCG format.
*
* @return A vector of unsigned characters representing the values in TSCG format.
*
* This method converts the current HNZ protocol data values to a format
* specified by TSCG and returns them as a vector of unsigned characters.
*/
std::vector<unsigned char> tsValueToTSCG() const;
private:
std::array<unsigned char, 45> m_ts_data;
};
137 changes: 137 additions & 0 deletions include/state_machine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#pragma once
#include <memory>
#include "hnz_config.h"
#include "pa_hnz_data.h"

/**
* @class StateMachine
* @brief Manages the state and transitions for a communication protocol.
*
* The StateMachine class is responsible for handling various states and
* transitions within a communication protocol. It provides methods for
* receiving and sending information, managing control codes, and configuring
* the machine.
*/
class StateMachine {
public:
/**
* @brief Constructs a StateMachine object.
*
* Initializes the state machine and sets up necessary configurations.
*/
StateMachine();

/**
* @brief Handles the reception of a SARM (Set Asynchronous Response Mode) code.
*
* This method processes the SARM code received in the communication protocol.
*/
void receiveSARMCode();

/**
* @brief Handles the reception of a UA (Unnumbered Acknowledge) code.
*
* This method processes the UA code received in the communication protocol.
*/
void receiveUACode();

/**
* @brief Handles the reception of information frames.
*
* This method processes information frames received in the communication protocol.
*/
void receiveInformation();

/**
* @brief Sends information frames.
*
* This method is used to send information frames within the communication protocol.
*/
void sendInformation();

/**
* @brief Generates a Receiver Ready (RR) control code.
*
* @param p The parameter to be used in generating the RR code.
* @return The generated RR control code.
*
* This method generates and returns an RR control code based on the given parameter.
*/
int getControlRR(int p) const;

/**
* @brief Generates a Reject (REJ) control code.
*
* @param p The parameter to be used in generating the REJ code.
* @return The generated REJ control code.
*
* This method generates and returns a REJ control code based on the given parameter.
*/
int getControlREJ(int p) const;

/**
* @brief Generates an Information control code.
*
* @param p The parameter to be used in generating the information control code.
* @return The generated information control code.
*
* This method generates and returns an information control code based on the given parameter.
*/
int getControlInformation(int p) const;

/**
* @brief Checks if the state machine is connected.
*
* This method verifies the connection status of the state machine.
*/
void checkConnected();

/**
* @brief Sets the configuration for the state machine.
*
* @param config A shared pointer to an HnzConfig object containing the configuration settings.
*
* This method sets up the state machine configuration using the provided HnzConfig object.
*/
void setConfig(const std::shared_ptr<HnzConfig>& config);

/**
* @brief Retrieves the A address.
*
* @return The A address.
*
* This method returns the A address used in the communication protocol.
*/
int getAAddress() const;

/**
* @brief Retrieves the B address.
*
* @return The B address.
*
* This method returns the B address used in the communication protocol.
*/
int getBAddress() const;

/**
* @brief Retrieves pa hnz data
*
* @return pa hnz data.
*
* This method returns pa hnz data.
*/
PaHnzData & getHnzData() {
return m_hnz_data;
}


private:
bool m_is_hnz_initialised{false};
bool m_is_sarm_received{false};
bool m_is_ua_received{false};
int m_nr{0};
int m_ns{0};
std::shared_ptr<HnzConfig> m_hnz_config;
PaHnzData m_hnz_data;

};
Loading

0 comments on commit eebcf76

Please sign in to comment.