AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_address_claim_state_machine.hpp
Go to the documentation of this file.
1//================================================================================================
8//================================================================================================
9
10#ifndef CAN_ADDRESS_CLAIM_STATE_MACHINE_HPP
11#define CAN_ADDRESS_CLAIM_STATE_MACHINE_HPP
12
15
16namespace isobus
17{
18 class CANMessage;
19
20 //================================================================================================
27 //================================================================================================
29 {
30 public:
45
50 AddressClaimStateMachine(std::uint8_t preferredAddressValue, NAME ControlFunctionNAME, std::uint8_t portIndex);
51
54
58
63
68 void process_commanded_address(std::uint8_t commandedAddress);
69
72 void set_is_enabled(bool value);
73
76 bool get_enabled() const;
77
80 std::uint8_t get_claimed_address() const;
81
83 void update();
84
85 private:
89 static void process_rx_message(const CANMessage &message, void *parentPointer);
90
93 void set_current_state(State value);
94
97 bool send_request_to_claim() const;
98
102 bool send_address_claim(std::uint8_t address);
103
106 std::uint32_t m_timestamp_ms = 0;
107 std::uint8_t m_portIndex;
108 std::uint8_t m_preferredAddress;
111 bool m_enabled = true;
112 };
113
114} // namespace isobus
115
116#endif // CAN_ADDRESS_CLAIM_STATE_MACHINE_HPP
A class that represents a control function's NAME.
General constants used throughout this library.
std::uint8_t m_randomClaimDelay_ms
The random delay as required by the ISO11783 standard.
bool send_address_claim(std::uint8_t address)
Sends the address claim message.
void process_commanded_address(std::uint8_t commandedAddress)
Attempts to process a commanded address.
void update()
Updates the state machine, should be called periodically.
void set_current_state(State value)
Sets the current state machine state.
std::uint32_t m_timestamp_ms
A generic timestamp in milliseconds used to find timeouts.
std::uint8_t m_preferredAddress
The address we'd prefer to claim as (we may not get it)
std::uint8_t get_claimed_address() const
Returns the address claimed by the state machine or 0xFE if none claimed.
State get_current_state() const
Returns the current state of the state machine.
std::uint8_t m_portIndex
The CAN channel index to claim on.
std::uint8_t m_claimedAddress
The actual address we ended up claiming.
bool send_request_to_claim() const
Sends the PGN request for the address claim PGN.
State
Defines the state machine states for address claiming.
@ WaitForRequestContentionPeriod
State machine is waiting for the address claim contention period.
@ SendRequestForClaim
State machine is sending the request for address claim.
@ UnableToClaim
State machine could not claim an address.
@ SendReclaimAddressOnRequest
An ECU requested address claim, inform the bus of our current address.
@ None
Address claiming is uninitialized.
@ SendPreferredAddressClaim
State machine is claiming the preferred address.
@ WaitForClaim
State machine is waiting for the random delay time.
@ ContendForPreferredAddress
State machine is contending the preferred address.
@ SendArbitraryAddressClaim
State machine is claiming an address.
@ AddressClaimingComplete
Address claiming is complete and we have an address.
void on_address_violation()
Used to inform the address claim state machine that two CFs are using the same source address....
bool m_enabled
Enable/disable state for this state machine.
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.
void set_is_enabled(bool value)
Enables or disables the address claimer.
State m_currentState
The address claim state machine state.
static void process_rx_message(const CANMessage &message, void *parentPointer)
Processes a CAN message.
bool get_enabled() const
Returns if the address claimer is enabled.
A class that represents a generic CAN message of arbitrary length.
A class that represents an ISO11783 control function NAME from an address claim.
Definition can_NAME.hpp:24
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
constexpr std::uint8_t NULL_CAN_ADDRESS
The NULL CAN address defined by J1939 and ISO11783.