AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
|
Forward declare CANMessage. More...
#include <can_address_claim_state_machine.hpp>
Public Types | |
enum class | State { None , WaitForClaim , SendRequestForClaim , WaitForRequestContentionPeriod , SendPreferredAddressClaim , ContendForPreferredAddress , SendArbitraryAddressClaim , SendReclaimAddressOnRequest , UnableToClaim , AddressClaimingComplete } |
Defines the state machine states for address claiming. More... | |
Public Member Functions | |
AddressClaimStateMachine (std::uint8_t preferredAddressValue, NAME ControlFunctionNAME, std::uint8_t portIndex) | |
The constructor of the state machine class. | |
~AddressClaimStateMachine () | |
The destructor for the address claim state machine. | |
State | get_current_state () const |
Returns the current state of the state machine. | |
void | on_address_violation () |
Used to inform the address claim state machine that two CFs are using the same source address. This function may cause the state machine to emit an address claim depending on its state, as is required by ISO11783-5. | |
void | process_commanded_address (std::uint8_t commandedAddress) |
Attempts to process a commanded address. | |
void | set_is_enabled (bool value) |
Enables or disables the address claimer. | |
bool | get_enabled () const |
Returns if the address claimer is enabled. | |
std::uint8_t | get_claimed_address () const |
Returns the address claimed by the state machine or 0xFE if none claimed. | |
void | update () |
Updates the state machine, should be called periodically. | |
Private Member Functions | |
void | set_current_state (State value) |
Sets the current state machine state. | |
bool | send_request_to_claim () const |
Sends the PGN request for the address claim PGN. | |
bool | send_address_claim (std::uint8_t address) |
Sends the address claim message. | |
Static Private Member Functions | |
static void | process_rx_message (const CANMessage &message, void *parentPointer) |
Processes a CAN message. | |
Private Attributes | |
NAME | m_isoname |
The ISO NAME to claim as. | |
State | m_currentState = State::None |
The address claim state machine state. | |
std::uint32_t | m_timestamp_ms = 0 |
A generic timestamp in milliseconds used to find timeouts. | |
std::uint8_t | m_portIndex |
The CAN channel index to claim on. | |
std::uint8_t | m_preferredAddress |
The address we'd prefer to claim as (we may not get it) | |
std::uint8_t | m_randomClaimDelay_ms |
The random delay as required by the ISO11783 standard. | |
std::uint8_t | m_claimedAddress = NULL_CAN_ADDRESS |
The actual address we ended up claiming. | |
bool | m_enabled = true |
Enable/disable state for this state machine. | |
Forward declare CANMessage.
State machine for managing the J1939/ISO11783 address claim process
This class manages address claiming for internal control functions and keeps track of things like requests for address claim.
Definition at line 28 of file can_address_claim_state_machine.hpp.
|
strong |
Defines the state machine states for address claiming.
Definition at line 32 of file can_address_claim_state_machine.hpp.
isobus::AddressClaimStateMachine::AddressClaimStateMachine | ( | std::uint8_t | preferredAddressValue, |
NAME | ControlFunctionNAME, | ||
std::uint8_t | portIndex ) |
The constructor of the state machine class.
[in] | preferredAddressValue | The address you prefer to claim |
[in] | ControlFunctionNAME | The NAME you want to claim |
[in] | portIndex | The CAN channel index to claim on |
Definition at line 21 of file can_address_claim_state_machine.cpp.
isobus::AddressClaimStateMachine::~AddressClaimStateMachine | ( | ) |
The destructor for the address claim state machine.
Definition at line 41 of file can_address_claim_state_machine.cpp.
std::uint8_t isobus::AddressClaimStateMachine::get_claimed_address | ( | ) | const |
Returns the address claimed by the state machine or 0xFE if none claimed.
Definition at line 106 of file can_address_claim_state_machine.cpp.
AddressClaimStateMachine::State isobus::AddressClaimStateMachine::get_current_state | ( | ) | const |
Returns the current state of the state machine.
Definition at line 47 of file can_address_claim_state_machine.cpp.
bool isobus::AddressClaimStateMachine::get_enabled | ( | ) | const |
Returns if the address claimer is enabled.
Definition at line 101 of file can_address_claim_state_machine.cpp.
void isobus::AddressClaimStateMachine::on_address_violation | ( | ) |
Used to inform the address claim state machine that two CFs are using the same source address. This function may cause the state machine to emit an address claim depending on its state, as is required by ISO11783-5.
Definition at line 52 of file can_address_claim_state_machine.cpp.
void isobus::AddressClaimStateMachine::process_commanded_address | ( | std::uint8_t | commandedAddress | ) |
Attempts to process a commanded address.
If the state machine has claimed successfully before, this will attempt to move a NAME from the claimed address to the new, specified address.
[in] | commandedAddress | The address to attempt to claim |
Definition at line 63 of file can_address_claim_state_machine.cpp.
|
staticprivate |
Processes a CAN message.
[in] | message | The CAN message being received |
[in] | parentPointer | A context variable to find the relevant address claimer |
Definition at line 271 of file can_address_claim_state_machine.cpp.
|
private |
Sends the address claim message.
[in] | address | The address to claim |
Definition at line 370 of file can_address_claim_state_machine.cpp.
|
private |
Sends the PGN request for the address claim PGN.
Definition at line 344 of file can_address_claim_state_machine.cpp.
|
private |
Sets the current state machine state.
[in] | value | The state to set the state machine to |
Definition at line 339 of file can_address_claim_state_machine.cpp.
void isobus::AddressClaimStateMachine::set_is_enabled | ( | bool | value | ) |
Enables or disables the address claimer.
[in] | value | true if you want the class to claim, false if you want to be a sniffer only |
Definition at line 96 of file can_address_claim_state_machine.cpp.
void isobus::AddressClaimStateMachine::update | ( | ) |
Updates the state machine, should be called periodically.
Definition at line 111 of file can_address_claim_state_machine.cpp.
|
private |
The actual address we ended up claiming.
Definition at line 110 of file can_address_claim_state_machine.hpp.
|
private |
The address claim state machine state.
Definition at line 105 of file can_address_claim_state_machine.hpp.
|
private |
Enable/disable state for this state machine.
Definition at line 111 of file can_address_claim_state_machine.hpp.
|
private |
The ISO NAME to claim as.
Definition at line 104 of file can_address_claim_state_machine.hpp.
|
private |
The CAN channel index to claim on.
Definition at line 107 of file can_address_claim_state_machine.hpp.
|
private |
The address we'd prefer to claim as (we may not get it)
Definition at line 108 of file can_address_claim_state_machine.hpp.
|
private |
The random delay as required by the ISO11783 standard.
Definition at line 109 of file can_address_claim_state_machine.hpp.
|
private |
A generic timestamp in milliseconds used to find timeouts.
Definition at line 106 of file can_address_claim_state_machine.hpp.