-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcan_control_function.hpp
80 lines (65 loc) · 3.32 KB
/
can_control_function.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//================================================================================================
/// @file can_control_function.hpp
///
/// @brief Defines a base class to represent a generic ISOBUS control function.
/// @author Adrian Del Grosso
/// @author Daan Steenbergen
///
/// @copyright 2024 The Open-Agriculture Developers
//================================================================================================
#ifndef CAN_CONTROL_FUNCTION_HPP
#define CAN_CONTROL_FUNCTION_HPP
#include "can_NAME.hpp"
#include "thread_synchronization.hpp"
#include <memory>
#include <string>
namespace isobus
{
/// @brief A class that describes an ISO11783 control function, which includes a NAME and address.
class ControlFunction
{
public:
/// @brief The type of the control function
enum class Type
{
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
};
/// @brief The constructor of a control function. In most cases use `CANNetworkManager::create_internal_control_function()` or
/// `CANNetworkManager::create_partnered_control_function()` instead, only use this constructor if you have advanced needs.
/// @param[in] NAMEValue The NAME of the control function
/// @param[in] addressValue The current address of the control function
/// @param[in] CANPort The CAN channel index that the control function communicates on
/// @param[in] type The 'Type' of control function to create
ControlFunction(NAME NAMEValue, std::uint8_t addressValue, std::uint8_t CANPort, Type type = Type::External);
virtual ~ControlFunction() = default;
/// @brief Returns the current address of the control function
/// @returns The current address of the control function
std::uint8_t get_address() const;
/// @brief Describes if the control function has a valid address (not NULL or global)
/// @returns true if the address is < 0xFE
bool get_address_valid() const;
/// @brief Returns the CAN channel index the control function communicates on
/// @returns The control function's CAN channel index
std::uint8_t get_can_port() const;
/// @brief Returns the NAME of the control function as described by its address claim message
/// @returns The control function's NAME
NAME get_NAME() const;
/// @brief Returns the `Type` of the control function
/// @returns The control function type
Type get_type() const;
///@brief Returns the 'Type' of the control function as a string
///@returns The control function type as a string
std::string get_type_string() const;
protected:
friend class CANNetworkManager; ///< The network manager needs access to the control function's internals
static Mutex controlFunctionProcessingMutex; ///< Protects the control function tables
const Type controlFunctionType; ///< The Type of the control function
NAME controlFunctionNAME; ///< The NAME of the control function
bool claimedAddressSinceLastAddressClaimRequest = false; ///< Used to mark CFs as stale if they don't claim within a certain time
std::uint8_t address; ///< The address of the control function
const std::uint8_t canPortIndex; ///< The CAN channel index of the control function
};
} // namespace isobus
#endif // CAN_CONTROL_FUNCTION_HPP