AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
isobus_maintain_power_interface.hpp
Go to the documentation of this file.
1//================================================================================================
15//================================================================================================
16#ifndef ISOBUS_MAINTAIN_POWER_INTERFACE_HPP
17#define ISOBUS_MAINTAIN_POWER_INTERFACE_HPP
18
21#include "isobus/utility/event_dispatcher.hpp"
22#include "isobus/utility/processing_flags.hpp"
23
24#include <memory>
25
26namespace isobus
27{
30 {
31 public:
34 {
35 public:
38 enum class ImplementInWorkState : std::uint8_t
39 {
40 ImplementNotInWorkState = 0,
42 ErrorIndication = 2,
43 NotAvailable = 3
44 };
45
49 {
50 ImplementNotReadyForFieldWork = 0,
51 ImplementReadyForFieldWork = 1,
52 ErrorIndication = 2,
53 NotAvailable = 3
54 };
55
59 {
60 ImplementMayNotBeDisconnected = 0,
61 ImplementMayBeDisconnected = 1,
62 ErrorIndication = 2,
63 NotAvailable = 3
64 };
65
69 {
70 ImplementMayNotBeTransported = 0,
71 ImplementMayBeTransported = 1,
72 ErrorIndication = 2,
73 NotAvailable = 3
74 };
75
79 {
80 NoFurtherRequirementForPWR = 0,
81 RequirementFor2SecondsMoreForPWR = 1,
82 Reserved = 2,
83 DontCare = 3
84 };
85
89 {
90 NoFurtherRequirementForECU_PWR = 0,
91 RequirementFor2SecondsMoreForECU_PWR = 1,
92 Reserved = 2,
93 DontCare = 3
94 };
95
98 explicit MaintainPowerData(std::shared_ptr<ControlFunction> sendingControlFunction);
99
104
108
113
117
122
126
131
135
140
144
148 bool set_maintain_ecu_power(MaintainECUPower maintainState);
149
153
161 std::shared_ptr<ControlFunction> get_sender_control_function() const;
162
165 void set_timestamp_ms(std::uint32_t timestamp);
166
169 std::uint32_t get_timestamp_ms() const;
170
171 private:
172 MaintainPowerData() = delete;
173 std::shared_ptr<ControlFunction> sendingControlFunction = nullptr;
174 std::uint32_t timestamp_ms = 0;
175 ImplementInWorkState currentImplementInWorkState = ImplementInWorkState::NotAvailable;
176 ImplementReadyToWorkState currentImplementReadyToWorkState = ImplementReadyToWorkState::NotAvailable;
177 ImplementParkState currentImplementParkState = ImplementParkState::NotAvailable;
178 ImplementTransportState currentImplementTransportState = ImplementTransportState::NotAvailable;
180 MaintainECUPower currentMaintainECUPowerState = MaintainECUPower::DontCare;
181 };
182
185 explicit MaintainPowerInterface(std::shared_ptr<InternalControlFunction> sourceControlFunction);
186
189
192 void initialize();
193
196 bool get_initialized() const;
197
208 void set_maintain_power_time(std::uint32_t timeToMaintainPower);
209
213 std::uint32_t get_maintain_power_time() const;
214
218
223 std::shared_ptr<MaintainPowerData> get_received_maintain_power(std::size_t index);
224
227 EventDispatcher<const std::shared_ptr<MaintainPowerData>, bool> &get_maintain_power_data_event_publisher();
228
235
238
241 void update();
242
243 protected:
246 bool send_maintain_power() const;
247
251 static void process_flags(std::uint32_t flag, void *parentPointer);
252
256 static void process_rx_message(const CANMessage &message, void *parentPointer);
257
258 ProcessingFlags txFlags;
259
260 private:
262 enum class TransmitFlags : std::uint32_t
263 {
265
267 };
268
270 enum class KeySwitchState : std::uint8_t
271 {
272 Off = 0,
273 NotOff = 1,
274 Error = 2,
275 NotAvailable = 3
276 };
277
278 static constexpr std::uint32_t MAINTAIN_POWER_TIMEOUT_MS = 2000;
279 std::vector<std::shared_ptr<MaintainPowerData>> receivedMaintainPowerMessages;
280 EventDispatcher<const std::shared_ptr<MaintainPowerData>, bool> maintainPowerDataEventPublisher;
281 EventDispatcher<> keySwitchOffEventPublisher;
282 std::uint32_t keyNotOffTimestamp = 0;
283 std::uint32_t keyOffTimestamp = 0;
285 std::uint32_t maintainPowerTime_ms = 0;
286 bool initialized = false;
287 };
288} // namespace isobus
289#endif // ISOBUS_MAINTAIN_POWER_INTERFACE_HPP
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
An abstraction of a CAN message, could be > 8 data bytes.
A class that represents a generic CAN message of arbitrary length.
Stores information sent/received in a maintain power message.
MaintainActuatorPower
Enumerates the different states that can be requested in the "Maintain Actuator Power" SPN.
ImplementTransportState get_implement_transport_state() const
Returns the reported implement transport state.
bool set_implement_transport_state(ImplementTransportState transportState)
Sets the reported implement transport state.
MaintainActuatorPower currentMaintainActuatorPowerState
The reported state for maintaining actuator power for 2 more seconds.
bool set_implement_in_work_state(ImplementInWorkState inWorkState)
Sets the reported implement in-work state.
bool set_implement_park_state(ImplementParkState parkState)
Sets the reported implement park state.
ImplementInWorkState currentImplementInWorkState
The reported implement in-work state.
std::shared_ptr< ControlFunction > get_sender_control_function() const
Returns a pointer to the sender of the message. If an ICF is the sender, returns the ICF being used t...
std::uint32_t get_timestamp_ms() const
Returns the timestamp for when the message was received, in milliseconds.
MaintainECUPower get_maintain_ecu_power() const
Returns the reported maintain ECU power state.
bool set_implement_ready_to_work_state(ImplementReadyToWorkState readyToWorkState)
Sets the reported implement ready to work state.
bool set_maintain_ecu_power(MaintainECUPower maintainState)
Sets the reported maintain ECU power state.
ImplementParkState get_implement_park_state() const
Returns the reported implement park state.
ImplementReadyToWorkState
Signal that indicates that an implement is connected to a tractor or power unit and is ready for work...
ImplementInWorkState
Signal that indicates that an implement is connected to a tractor or power unit and is in work state.
MaintainECUPower
Enumerates the different states that can be requested in the "Maintain ECU Power" SPN.
ImplementTransportState currentImplementTransportState
The reported transport state of the implement.
MaintainECUPower currentMaintainECUPowerState
The reported state for maintaining ECU power for 2 more seconds.
std::shared_ptr< ControlFunction > sendingControlFunction
The control function that is sending the message.
ImplementInWorkState get_implement_in_work_state() const
Returns the reported implement in-work state.
ImplementReadyToWorkState currentImplementReadyToWorkState
The reported implement ready to work state.
MaintainActuatorPower get_maintain_actuator_power() const
Returns the reported maintain actuator power state.
std::uint32_t timestamp_ms
A timestamp for when the message was released in milliseconds.
bool set_maintain_actuator_power(MaintainActuatorPower maintainState)
Sets the reported maintain actuator power state.
ImplementReadyToWorkState get_implement_ready_to_work_state() const
Returns the reported implement ready to work state.
ImplementParkState
Indicates the state of an implement where it may be disconnected from a tractor or power unit.
ImplementTransportState
Indicates the transport state of an implement connected to a tractor or power unit.
void set_timestamp_ms(std::uint32_t timestamp)
Sets the timestamp for when the message was received or sent.
ImplementParkState currentImplementParkState
The reported implement park state.
Manages sending and receiving the maintain power message (PGN 65095)
EventDispatcher< const std::shared_ptr< MaintainPowerData >, bool > maintainPowerDataEventPublisher
An event publisher for notifying when new maintain power messages are received.
std::uint32_t maintainPowerTime_ms
The amount of time to ask the TECU to maintain actuator/section power. Will be rounded up to the next...
std::uint32_t maintainPowerTransmitTimestamp_ms
Timestamp used to know when to transmit the maintain power message in milliseconds.
bool initialized
Stores if the interface has been initialized.
KeySwitchState
Enumerates the key switch states of the tractor or power unit.
@ NotOff
Key is not off (does not always mean that it's on!)
std::shared_ptr< MaintainPowerData > get_received_maintain_power(std::size_t index)
Returns the content of a received maintain power message based on the index of the sender....
std::uint32_t keyNotOffTimestamp
A timestamp to track when the key was detected as ON, used to detect transitions to "Not On".
MaintainPowerInterface(std::shared_ptr< InternalControlFunction > sourceControlFunction)
Constructor for a MaintainPowerInterface.
void set_maintain_power_time(std::uint32_t timeToMaintainPower)
Use this to tell the interface how long it should transmit the maintain power message after it detect...
TransmitFlags
Enumerates a set of flags to manage transmitting messages owned by this interface.
@ SendMaintainPower
A flag to manage sending the maintain power message.
@ NumberOfFlags
The number of flags in this enumeration.
bool send_maintain_power() const
Transmits the maintain power message.
ProcessingFlags txFlags
Tx flag for sending the maintain power message. Handles retries automatically.
EventDispatcher< const std::shared_ptr< MaintainPowerData >, bool > & get_maintain_power_data_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated maintain power messag...
static void process_rx_message(const CANMessage &message, void *parentPointer)
Processes a CAN message.
~MaintainPowerInterface()
Destructor for a MaintainPowerInterface.
std::uint32_t keyOffTimestamp
A timestamp to track when the key is off, used to calculate how many messages to send and when to sen...
EventDispatcher & get_key_switch_transition_off_event_publisher()
Returns an event dispatcher which you can use to get callbacks when the key switch transitions from t...
bool get_initialized() const
Returns if the interface has been initialized.
MaintainPowerData maintainPowerTransmitData
Use this to configure the transmission of the maintain power message.
std::size_t get_number_received_maintain_power_sources() const
Returns the number of unique senders of the maintain power message.
EventDispatcher keySwitchOffEventPublisher
An event publisher for notifying when the key switch transitions to the off state.
void update()
Call this cyclically to update the interface. Transmits messages if needed and processes timeouts for...
std::uint32_t get_maintain_power_time() const
Returns the amount of time that the interface will continue to send the maintain power message after ...
static constexpr std::uint32_t MAINTAIN_POWER_TIMEOUT_MS
The amount of time that power can be maintained per message, used as the timeout as well.
static void process_flags(std::uint32_t flag, void *parentPointer)
Processes one flag (which sends the associated message)
std::vector< std::shared_ptr< MaintainPowerData > > receivedMaintainPowerMessages
A list of all received maintain power messages.
void initialize()
Sets up the class and registers it to receive callbacks from the network manager for processing messa...
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...