AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_partnered_control_function.cpp
Go to the documentation of this file.
1//================================================================================================
10//================================================================================================
12
15
16#include <algorithm>
17#include <cassert>
18
19namespace isobus
20{
21 PartneredControlFunction::PartneredControlFunction(std::uint8_t CANPort, const std::vector<NAMEFilter> NAMEFilters, CANLibBadge<PartneredControlFunction>) :
22 ControlFunction(NAME(0), NULL_CAN_ADDRESS, CANPort, Type::Partnered),
23 NAMEFilterList(NAMEFilters)
24 {
26 LOCK_GUARD(Mutex, processingMutex);
27 }
28
29 std::shared_ptr<PartneredControlFunction> PartneredControlFunction::create(std::uint8_t CANPort, const std::vector<NAMEFilter> NAMEFilters)
30 {
31 // Unfortunately, we can't use `std::make_shared` here because the constructor is meant to be protected
32 auto controlFunction = std::shared_ptr<PartneredControlFunction>(new PartneredControlFunction(CANPort, NAMEFilters, {}));
34 return controlFunction;
35 }
36
37 void PartneredControlFunction::add_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent, std::shared_ptr<InternalControlFunction> internalControlFunction)
38 {
39 parameterGroupNumberCallbacks.emplace_back(parameterGroupNumber, callback, parent, internalControlFunction);
40 }
41
42 void PartneredControlFunction::remove_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent, std::shared_ptr<InternalControlFunction> internalControlFunction)
43 {
44 ParameterGroupNumberCallbackData tempObject(parameterGroupNumber, callback, parent, internalControlFunction);
45 auto callbackLocation = std::find(parameterGroupNumberCallbacks.begin(), parameterGroupNumberCallbacks.end(), tempObject);
46 if (parameterGroupNumberCallbacks.end() != callbackLocation)
47 {
48 parameterGroupNumberCallbacks.erase(callbackLocation);
49 }
50 }
51
56
58 {
59 return NAMEFilterList.size();
60 }
61
62 bool PartneredControlFunction::get_name_filter_parameter(std::size_t index, NAME::NAMEParameters &parameter, std::uint32_t &filterValue) const
63 {
64 bool retVal = false;
65
66 if (index < get_number_name_filters())
67 {
68 parameter = NAMEFilterList[index].get_parameter();
69 filterValue = NAMEFilterList[index].get_value();
70 retVal = true;
71 }
72 return retVal;
73 }
74
76 {
77 std::size_t retVal = 0;
78
79 for (std::size_t i = 0; i < NAMEFilterList.size(); i++)
80 {
81 if (parameter == NAMEFilterList[i].get_parameter())
82 {
83 retVal++;
84 }
85 }
86 return retVal;
87 }
88
90 {
91 std::uint32_t currentFilterValue;
92 NAME::NAMEParameters currentFilterParameter;
93 bool retVal = true;
94
95 if (0 == get_number_name_filters())
96 {
97 retVal = false;
98 }
99
100 for (std::uint32_t i = 0; i < get_number_name_filters(); i++)
101 {
102 get_name_filter_parameter(i, currentFilterParameter, currentFilterValue);
103
104 switch (currentFilterParameter)
105 {
107 {
108 retVal = (currentFilterValue == NAMEToCheck.get_identity_number());
109 }
110 break;
111
113 {
114 retVal = (currentFilterValue == NAMEToCheck.get_manufacturer_code());
115 }
116 break;
117
119 {
120 retVal = (currentFilterValue == NAMEToCheck.get_ecu_instance());
121 }
122 break;
123
125 {
126 retVal = (currentFilterValue == NAMEToCheck.get_function_instance());
127 }
128 break;
129
131 {
132 retVal = (currentFilterValue == NAMEToCheck.get_function_code());
133 }
134 break;
135
137 {
138 retVal = (currentFilterValue == NAMEToCheck.get_device_class());
139 }
140 break;
141
143 {
144 retVal = (currentFilterValue == NAMEToCheck.get_device_class_instance());
145 }
146 break;
147
149 {
150 retVal = (currentFilterValue == NAMEToCheck.get_industry_group());
151 }
152 break;
153
155 {
156 retVal = ((0 != currentFilterValue) == NAMEToCheck.get_arbitrary_address_capable());
157 }
158 break;
159
160 default:
161 {
162 retVal = false;
163 }
164 break;
165 }
166
167 if (false == retVal)
168 {
169 break;
170 }
171 }
172 return retVal;
173 }
174
180
181} // namespace isobus
General constants used throughout this library.
The main class that manages the ISOBUS stack including: callbacks, Name to Address management,...
A class that describes a control function on the bus that the stack should communicate with....
This is a way to protect functions on public interfaces from being accessed by objects that shouldn't...
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.
static Mutex controlFunctionProcessingMutex
Protects the control function tables.
Type
The type of the control function.
A class that represents an ISO11783 control function NAME from an address claim.
Definition can_NAME.hpp:24
std::uint8_t get_ecu_instance() const
Gets the ecu instance encoded in the NAME.
Definition can_NAME.cpp:106
bool get_arbitrary_address_capable() const
Returns if the ECU is capable of address arbitration.
Definition can_NAME.cpp:24
std::uint8_t get_function_instance() const
Gets the function instance encoded in the NAME.
Definition can_NAME.cpp:91
NAMEParameters
The encoded components that comprise a NAME.
Definition can_NAME.hpp:28
@ IndustryGroup
The industry group associated with this ECU, such as "agricultural".
@ DeviceClass
Also known as the vehicle system from J1939, describes general ECU type.
@ DeviceClassInstance
The instance number of this device class.
@ ArbitraryAddressCapable
Defines if this ECU supports address arbitration.
@ FunctionCode
The function of the ECU, as defined by ISO11783.
@ EcuInstance
The ECU instance of the ECU with this NAME. Usually increments in NAME order with similar CFs.
@ FunctionInstance
The function instance of the ECU. Similar to Virtual Terminal number.
@ ManufacturerCode
The J1939/ISO11783 manufacturer code of the ECU with this NAME.
@ IdentityNumber
Usually the serial number of the ECU, unique for all similar control functions.
std::uint16_t get_manufacturer_code() const
Gets the manufacturer code encoded in the NAME.
Definition can_NAME.cpp:121
std::uint8_t get_function_code() const
Gets the function code encoded in the NAME.
Definition can_NAME.cpp:80
std::uint8_t get_device_class_instance() const
Returns the device class (vehicle system) encoded in the NAME.
Definition can_NAME.cpp:50
std::uint8_t get_industry_group() const
Returns the industry group encoded in the NAME.
Definition can_NAME.cpp:35
std::uint8_t get_device_class() const
Returns the device class (vehicle system) encoded in the NAME.
Definition can_NAME.cpp:65
std::uint32_t get_identity_number() const
Gets the identity number encoded in the NAME.
Definition can_NAME.cpp:136
A storage class to hold data about callbacks for a specific PGN.
bool check_matches_name(NAME NAMEToCheck) const
Checks to see if a NAME matches this CF's NAME filters.
std::size_t get_number_name_filters_with_parameter_type(NAME::NAMEParameters parameter)
Returns the number of NAME filters with a specific NAME parameter component, like manufacturer code.
std::size_t get_number_parameter_group_number_callbacks() const
Returns the number of parameter group number callbacks associated with this control function.
ParameterGroupNumberCallbackData & get_parameter_group_number_callback(std::size_t index)
Returns a parameter group number associated with this control function by index.
void remove_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent, std::shared_ptr< InternalControlFunction > internalControlFunction=nullptr)
Removes a callback matching exactly the parameters passed in.
void add_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent, std::shared_ptr< InternalControlFunction > internalControlFunction=nullptr)
This is how you get notified that this control function has sent you a destination specific message.
static std::shared_ptr< PartneredControlFunction > create(std::uint8_t CANPort, const std::vector< NAMEFilter > NAMEFilters)
The factory function to construct a partnered control function.
std::vector< ParameterGroupNumberCallbackData > parameterGroupNumberCallbacks
A list of all parameter group number callbacks associated with this control function.
const std::vector< NAMEFilter > NAMEFilterList
A list of NAME parameters that describe this control function's identity.
std::size_t get_number_name_filters() const
Returns the number of NAME filter objects that describe the identity of this control function.
bool get_name_filter_parameter(std::size_t index, NAME::NAMEParameters &parameter, std::uint32_t &filterValue) const
Returns a NAME filter by index.
PartneredControlFunction(std::uint8_t CANPort, const std::vector< NAMEFilter > NAMEFilters, CANLibBadge< PartneredControlFunction >)
the constructor for a PartneredControlFunction, which is called by the factory function
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.
void(*)(const CANMessage &message, void *parentPointer) CANLibCallback
A callback for control functions to get CAN messages.