-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd9de92
commit eebcf76
Showing
12 changed files
with
867 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
}; |
Oops, something went wrong.