AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
isobus::AddressClaimStateMachine Class Reference

Forward declare CANMessage. More...

#include <can_address_claim_state_machine.hpp>

Collaboration diagram for isobus::AddressClaimStateMachine:
[legend]

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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ State

Defines the state machine states for address claiming.

Enumerator
None 

Address claiming is uninitialized.

WaitForClaim 

State machine is waiting for the random delay time.

SendRequestForClaim 

State machine is sending the request for address claim.

WaitForRequestContentionPeriod 

State machine is waiting for the address claim contention period.

SendPreferredAddressClaim 

State machine is claiming the preferred address.

ContendForPreferredAddress 

State machine is contending the preferred address.

SendArbitraryAddressClaim 

State machine is claiming an address.

SendReclaimAddressOnRequest 

An ECU requested address claim, inform the bus of our current address.

UnableToClaim 

State machine could not claim an address.

AddressClaimingComplete 

Address claiming is complete and we have an address.

Definition at line 32 of file can_address_claim_state_machine.hpp.

Constructor & Destructor Documentation

◆ AddressClaimStateMachine()

isobus::AddressClaimStateMachine::AddressClaimStateMachine ( std::uint8_t preferredAddressValue,
NAME ControlFunctionNAME,
std::uint8_t portIndex )

The constructor of the state machine class.

Parameters
[in]preferredAddressValueThe address you prefer to claim
[in]ControlFunctionNAMEThe NAME you want to claim
[in]portIndexThe CAN channel index to claim on

Definition at line 21 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:

◆ ~AddressClaimStateMachine()

isobus::AddressClaimStateMachine::~AddressClaimStateMachine ( )

The destructor for the address claim state machine.

Definition at line 41 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ get_claimed_address()

std::uint8_t isobus::AddressClaimStateMachine::get_claimed_address ( ) const

Returns the address claimed by the state machine or 0xFE if none claimed.

Returns
The address claimed by the state machine or 0xFE if no address has been claimed

Definition at line 106 of file can_address_claim_state_machine.cpp.

Here is the caller graph for this function:

◆ get_current_state()

AddressClaimStateMachine::State isobus::AddressClaimStateMachine::get_current_state ( ) const

Returns the current state of the state machine.

Returns
The current state of the state machine

Definition at line 47 of file can_address_claim_state_machine.cpp.

Here is the caller graph for this function:

◆ get_enabled()

bool isobus::AddressClaimStateMachine::get_enabled ( ) const

Returns if the address claimer is enabled.

Returns
true if the class will address claim, false if in sniffing mode

Definition at line 101 of file can_address_claim_state_machine.cpp.

Here is the caller graph for this function:

◆ on_address_violation()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_commanded_address()

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.

Parameters
[in]commandedAddressThe address to attempt to claim

Definition at line 63 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_rx_message()

void isobus::AddressClaimStateMachine::process_rx_message ( const CANMessage & message,
void * parentPointer )
staticprivate

Processes a CAN message.

Parameters
[in]messageThe CAN message being received
[in]parentPointerA context variable to find the relevant address claimer

Definition at line 271 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_address_claim()

bool isobus::AddressClaimStateMachine::send_address_claim ( std::uint8_t address)
private

Sends the address claim message.

Parameters
[in]addressThe address to claim
Returns
true if the message was sent, otherwise false

Definition at line 370 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_request_to_claim()

bool isobus::AddressClaimStateMachine::send_request_to_claim ( ) const
private

Sends the PGN request for the address claim PGN.

Returns
true if the message was sent, otherwise false

Definition at line 344 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_current_state()

void isobus::AddressClaimStateMachine::set_current_state ( State value)
private

Sets the current state machine state.

Parameters
[in]valueThe state to set the state machine to

Definition at line 339 of file can_address_claim_state_machine.cpp.

Here is the caller graph for this function:

◆ set_is_enabled()

void isobus::AddressClaimStateMachine::set_is_enabled ( bool value)

Enables or disables the address claimer.

Parameters
[in]valuetrue 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.

◆ update()

void isobus::AddressClaimStateMachine::update ( )

Updates the state machine, should be called periodically.

Todo
Non-arbitratable address contention (there is not a good reason to use this, but we should add support anyways)

Definition at line 111 of file can_address_claim_state_machine.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_claimedAddress

std::uint8_t isobus::AddressClaimStateMachine::m_claimedAddress = NULL_CAN_ADDRESS
private

The actual address we ended up claiming.

Definition at line 110 of file can_address_claim_state_machine.hpp.

◆ m_currentState

State isobus::AddressClaimStateMachine::m_currentState = State::None
private

The address claim state machine state.

Definition at line 105 of file can_address_claim_state_machine.hpp.

◆ m_enabled

bool isobus::AddressClaimStateMachine::m_enabled = true
private

Enable/disable state for this state machine.

Definition at line 111 of file can_address_claim_state_machine.hpp.

◆ m_isoname

NAME isobus::AddressClaimStateMachine::m_isoname
private

The ISO NAME to claim as.

Definition at line 104 of file can_address_claim_state_machine.hpp.

◆ m_portIndex

std::uint8_t isobus::AddressClaimStateMachine::m_portIndex
private

The CAN channel index to claim on.

Definition at line 107 of file can_address_claim_state_machine.hpp.

◆ m_preferredAddress

std::uint8_t isobus::AddressClaimStateMachine::m_preferredAddress
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.

◆ m_randomClaimDelay_ms

std::uint8_t isobus::AddressClaimStateMachine::m_randomClaimDelay_ms
private

The random delay as required by the ISO11783 standard.

Definition at line 109 of file can_address_claim_state_machine.hpp.

◆ m_timestamp_ms

std::uint32_t isobus::AddressClaimStateMachine::m_timestamp_ms = 0
private

A generic timestamp in milliseconds used to find timeouts.

Definition at line 106 of file can_address_claim_state_machine.hpp.


The documentation for this class was generated from the following files: