AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_control_function.cpp
Go to the documentation of this file.
1//================================================================================================
9//================================================================================================
10
12
15
16#include <string>
17
18namespace isobus
19{
21
22 isobus::ControlFunction::ControlFunction(NAME NAMEValue, std::uint8_t addressValue, std::uint8_t CANPort, Type type) :
23 controlFunctionType(type),
24 controlFunctionNAME(NAMEValue),
25 address(addressValue),
26 canPortIndex(CANPort)
27 {
28 }
29
30 std::shared_ptr<ControlFunction> ControlFunction::create(NAME NAMEValue, std::uint8_t addressValue, std::uint8_t CANPort)
31 {
32 // Unfortunately, we can't use `std::make_shared` here because the constructor is private
33 auto controlFunction = std::shared_ptr<ControlFunction>(new ControlFunction(NAMEValue, addressValue, CANPort));
35 return controlFunction;
36 }
37
38 bool ControlFunction::destroy(std::uint32_t expectedRefCount)
39 {
40 LOCK_GUARD(Mutex, controlFunctionProcessingMutex);
41
43
44 return static_cast<std::uint32_t>(shared_from_this().use_count()) == expectedRefCount + 1;
45 }
46
47 std::uint8_t ControlFunction::get_address() const
48 {
49 return address;
50 }
51
56
57 std::uint8_t ControlFunction::get_can_port() const
58 {
59 return canPortIndex;
60 }
61
66
71
73 {
74 switch (controlFunctionType)
75 {
76 case Type::Internal:
77 return "Internal";
78 case Type::External:
79 return "External";
80 case Type::Partnered:
81 return "Partnered";
82 default:
83 return "Unknown";
84 }
85 }
86
87} // namespace isobus
General constants used throughout this library.
Defines a base class to represent a generic ISOBUS control function.
The main class that manages the ISOBUS stack including: callbacks, Name to Address management,...
This is a way to protect functions on public interfaces from being accessed by objects that shouldn't...
void on_control_function_destroyed(std::shared_ptr< ControlFunction > controlFunction, CANLibBadge< ControlFunction >)
Informs the network manager that a control function object has been destroyed, so that it can be purg...
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 ...
static Mutex controlFunctionProcessingMutex
Protects the control function tables.
std::string get_type_string() const
Returns the 'Type' of the control function as a string.
bool get_address_valid() const
Describes if the control function has a valid address (not NULL or global)
std::uint8_t get_can_port() const
Returns the CAN channel index the control function communicates on.
static std::shared_ptr< ControlFunction > create(NAME NAMEValue, std::uint8_t addressValue, std::uint8_t CANPort)
The factory function to construct a control function.
std::uint8_t address
The address of the control function.
NAME controlFunctionNAME
The NAME of the control function.
Type
The type of the control function.
@ Internal
The control function is part of our stack and can address claim.
@ External
The control function is some other device on the bus.
@ Partnered
An external control function that you explicitly want to talk to.
NAME get_NAME() const
Returns the NAME of the control function as described by its address claim message.
std::uint8_t get_address() const
Returns the current address of the control function.
const Type controlFunctionType
The Type of the control function.
ControlFunction(NAME NAMEValue, std::uint8_t addressValue, std::uint8_t CANPort, Type type=Type::External)
The protected constructor for the control function, which is called by the (inherited) factory functi...
Type get_type() const
Returns 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.
const std::uint8_t canPortIndex
The CAN channel index of the control function.
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.
constexpr std::uint8_t BROADCAST_CAN_ADDRESS
The global/broadcast CAN address.