AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_internal_control_function.cpp
Go to the documentation of this file.
1//================================================================================================
10//================================================================================================
12
16
17#include <algorithm>
18
19namespace isobus
20{
21 InternalControlFunction::InternalControlFunction(NAME desiredName, std::uint8_t preferredAddress, std::uint8_t CANPort, CANLibBadge<InternalControlFunction>) :
22 ControlFunction(desiredName, NULL_CAN_ADDRESS, CANPort, Type::Internal),
23 stateMachine(preferredAddress, desiredName, CANPort)
24 {
25 }
26
27 std::shared_ptr<InternalControlFunction> InternalControlFunction::create(NAME desiredName, std::uint8_t preferredAddress, std::uint8_t CANPort)
28 {
29 // Unfortunately, we can't use `std::make_shared` here because the constructor is private
30 CANLibBadge<InternalControlFunction> badge; // This badge is used to allow creation of the PGN request protocol only from within this class
31 auto controlFunction = std::shared_ptr<InternalControlFunction>(new InternalControlFunction(desiredName, preferredAddress, CANPort, badge));
32 controlFunction->pgnRequestProtocol.reset(new ParameterGroupNumberRequestProtocol(controlFunction, badge));
34 return controlFunction;
35 }
36
37 std::shared_ptr<InternalControlFunction> InternalControlFunction::create(NAME desiredName, std::uint8_t CANPort)
38 {
39 return create(desiredName, NULL_CAN_ADDRESS, CANPort);
40 }
41
42 bool InternalControlFunction::destroy(std::uint32_t expectedRefCount)
43 {
44 // We need to destroy the PGN request protocol before we destroy the control function
45 pgnRequestProtocol.reset();
46
47 return ControlFunction::destroy(expectedRefCount);
48 }
49
54
59
61 {
62 std::uint8_t previousAddress = address;
65
66 return previousAddress != address;
67 }
68
69 std::weak_ptr<ParameterGroupNumberRequestProtocol> InternalControlFunction::get_pgn_request_protocol() const
70 {
71 return pgnRequestProtocol;
72 }
73
74} // namespace isobus
General constants used throughout this library.
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
The main class that manages the ISOBUS stack including: callbacks, Name to Address management,...
A protocol that handles PGN requests.
This is a way to protect functions on public interfaces from being accessed by objects that shouldn't...
void process_commanded_address(std::uint8_t commandedAddress)
Attempts to process a commanded address.
void update()
Updates the state machine, should be called periodically.
std::uint8_t get_claimed_address() const
Returns the address claimed by the state machine or 0xFE if none claimed.
void on_address_violation()
Used to inform the address claim state machine that two CFs are using the same source address....
static CANNetworkManager CANNetwork
Static singleton of the one network manager. Use this to access stack functionality.
void on_control_function_created(std::shared_ptr< ControlFunction > controlFunction, CANLibBadge< ControlFunction >)
Informs the network manager that a control function object has been created, so that it can be added ...
A class that describes an ISO11783 control function, which includes a NAME and address.
std::uint8_t address
The address of the control function.
Type
The type of the control function.
virtual bool destroy(std::uint32_t expectedRefCount=1)
Destroys this control function, by removing it from the network manager.
static std::shared_ptr< InternalControlFunction > create(NAME desiredName, std::uint8_t preferredAddress, std::uint8_t CANPort)
The factory function to construct an internal control function.
AddressClaimStateMachine stateMachine
The address claimer for this ICF.
void on_address_violation(CANLibBadge< CANNetworkManager >)
Used to inform the member address claim state machine that two CFs are using the same source address.
bool destroy(std::uint32_t expectedRefCount=1) override
Destroys this control function, by removing it from the network manager.
std::weak_ptr< ParameterGroupNumberRequestProtocol > get_pgn_request_protocol() const
Gets the PGN request protocol for this ICF.
void process_commanded_address(std::uint8_t commandedAddress, CANLibBadge< CANNetworkManager >)
Used by the network manager to tell the ICF that the address claim state machine needs to process a J...
bool update_address_claiming(CANLibBadge< CANNetworkManager >)
Updates the internal control function together with it's associated address claim state machine.
std::shared_ptr< ParameterGroupNumberRequestProtocol > pgnRequestProtocol
The PGN request protocol for this ICF.
InternalControlFunction(NAME desiredName, std::uint8_t preferredAddress, std::uint8_t CANPort, CANLibBadge< InternalControlFunction >)
The protected constructor for the internal control function, which is called by the (inherited) facto...
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.