AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
|
Manages sending and receiving the maintain power message (PGN 65095) More...
#include <isobus_maintain_power_interface.hpp>
Classes | |
class | MaintainPowerData |
Stores information sent/received in a maintain power message. More... | |
Public Member Functions | |
MaintainPowerInterface (std::shared_ptr< InternalControlFunction > sourceControlFunction) | |
Constructor for a MaintainPowerInterface. | |
~MaintainPowerInterface () | |
Destructor for a MaintainPowerInterface. | |
void | initialize () |
Sets up the class and registers it to receive callbacks from the network manager for processing messages. The class will not receive messages if this is not called. | |
bool | get_initialized () const |
Returns if the interface has been initialized. | |
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 detects a key state transition to off. The interface will use whatever you have set in maintainPowerTransmitData when performing automatic transmission of the message. | |
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 it detects a key transition to off. | |
std::size_t | get_number_received_maintain_power_sources () const |
Returns the number of unique senders of the maintain power message. | |
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. Use this to read the received messages' content. | |
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 messages are received. | |
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 the not-off state to the off state. When you get this callback, you can then shutdown your application safely. | |
void | update () |
Call this cyclically to update the interface. Transmits messages if needed and processes timeouts for received messages. | |
Public Attributes | |
MaintainPowerData | maintainPowerTransmitData |
Use this to configure the transmission of the maintain power message. | |
Protected Member Functions | |
bool | send_maintain_power () const |
Transmits the maintain power message. | |
Static Protected Member Functions | |
static void | process_flags (std::uint32_t flag, void *parentPointer) |
Processes one flag (which sends the associated message) | |
static void | process_rx_message (const CANMessage &message, void *parentPointer) |
Processes a CAN message. | |
Protected Attributes | |
ProcessingFlags | txFlags |
Tx flag for sending the maintain power message. Handles retries automatically. | |
Private Types | |
enum class | TransmitFlags : std::uint32_t { SendMaintainPower = 0 , NumberOfFlags } |
Enumerates a set of flags to manage transmitting messages owned by this interface. More... | |
enum class | KeySwitchState : std::uint8_t { Off = 0 , NotOff = 1 , Error = 2 , NotAvailable = 3 } |
Enumerates the key switch states of the tractor or power unit. More... | |
Private Attributes | |
std::vector< std::shared_ptr< MaintainPowerData > > | receivedMaintainPowerMessages |
A list of all received maintain power messages. | |
EventDispatcher< const std::shared_ptr< MaintainPowerData >, bool > | maintainPowerDataEventPublisher |
An event publisher for notifying when new maintain power messages are received. | |
EventDispatcher | keySwitchOffEventPublisher |
An event publisher for notifying when the key switch transitions to the off state. | |
std::uint32_t | keyNotOffTimestamp = 0 |
A timestamp to track when the key was detected as ON, used to detect transitions to "Not On". | |
std::uint32_t | keyOffTimestamp = 0 |
A timestamp to track when the key is off, used to calculate how many messages to send and when to send them. | |
std::uint32_t | maintainPowerTransmitTimestamp_ms = 0 |
Timestamp used to know when to transmit the maintain power message in milliseconds. | |
std::uint32_t | maintainPowerTime_ms = 0 |
The amount of time to ask the TECU to maintain actuator/section power. Will be rounded up to the next 2s mark when sent. | |
bool | initialized = false |
Stores if the interface has been initialized. | |
Static Private Attributes | |
static constexpr std::uint32_t | MAINTAIN_POWER_TIMEOUT_MS = 2000 |
The amount of time that power can be maintained per message, used as the timeout as well. | |
Manages sending and receiving the maintain power message (PGN 65095)
Definition at line 29 of file isobus_maintain_power_interface.hpp.
|
strongprivate |
Enumerates the key switch states of the tractor or power unit.
Enumerator | |
---|---|
Off | Key is off. |
NotOff | Key is not off (does not always mean that it's on!) |
Definition at line 270 of file isobus_maintain_power_interface.hpp.
|
strongprivate |
Enumerates a set of flags to manage transmitting messages owned by this interface.
Enumerator | |
---|---|
SendMaintainPower | A flag to manage sending the maintain power message. |
NumberOfFlags | The number of flags in this enumeration. |
Definition at line 262 of file isobus_maintain_power_interface.hpp.
|
explicit |
Constructor for a MaintainPowerInterface.
[in] | sourceControlFunction | The control function to send the message from, or nullptr to listen only |
Definition at line 13 of file isobus_maintain_power_interface.cpp.
isobus::MaintainPowerInterface::~MaintainPowerInterface | ( | ) |
Destructor for a MaintainPowerInterface.
Definition at line 19 of file isobus_maintain_power_interface.cpp.
bool isobus::MaintainPowerInterface::get_initialized | ( | ) | const |
Returns if the interface has been initialized.
Definition at line 166 of file isobus_maintain_power_interface.cpp.
EventDispatcher & isobus::MaintainPowerInterface::get_key_switch_transition_off_event_publisher | ( | ) |
Returns an event dispatcher which you can use to get callbacks when the key switch transitions from the not-off state to the off state. When you get this callback, you can then shutdown your application safely.
Definition at line 33 of file isobus_maintain_power_interface.cpp.
EventDispatcher< const std::shared_ptr< MaintainPowerInterface::MaintainPowerData >, bool > & isobus::MaintainPowerInterface::get_maintain_power_data_event_publisher | ( | ) |
Returns an event dispatcher which you can use to get callbacks when new/updated maintain power messages are received.
Definition at line 28 of file isobus_maintain_power_interface.cpp.
std::uint32_t isobus::MaintainPowerInterface::get_maintain_power_time | ( | ) | const |
Returns the amount of time that the interface will continue to send the maintain power message after it detects a key transition to off.
Definition at line 176 of file isobus_maintain_power_interface.cpp.
std::size_t isobus::MaintainPowerInterface::get_number_received_maintain_power_sources | ( | ) | const |
Returns the number of unique senders of the maintain power message.
Definition at line 181 of file isobus_maintain_power_interface.cpp.
std::shared_ptr< MaintainPowerInterface::MaintainPowerData > isobus::MaintainPowerInterface::get_received_maintain_power | ( | std::size_t | index | ) |
Returns the content of a received maintain power message based on the index of the sender. Use this to read the received messages' content.
[in] | index | An index of senders of the maintain power message |
Definition at line 186 of file isobus_maintain_power_interface.cpp.
void isobus::MaintainPowerInterface::initialize | ( | ) |
Sets up the class and registers it to receive callbacks from the network manager for processing messages. The class will not receive messages if this is not called.
Definition at line 156 of file isobus_maintain_power_interface.cpp.
|
staticprotected |
Processes one flag (which sends the associated message)
[in] | flag | The flag to process |
[in] | parentPointer | A pointer to the interface instance |
Definition at line 219 of file isobus_maintain_power_interface.cpp.
|
staticprotected |
Processes a CAN message.
[in] | message | The CAN message being received |
[in] | parentPointer | A context variable to find the relevant instance of this class |
Definition at line 233 of file isobus_maintain_power_interface.cpp.
|
protected |
Transmits the maintain power message.
Definition at line 197 of file isobus_maintain_power_interface.cpp.
void isobus::MaintainPowerInterface::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 detects a key state transition to off. The interface will use whatever you have set in maintainPowerTransmitData when performing automatic transmission of the message.
[in] | timeToMaintainPower | The amount of time in milliseconds that the interface will send the maintain power message when the key transitions to off. |
Definition at line 171 of file isobus_maintain_power_interface.cpp.
void isobus::MaintainPowerInterface::update | ( | ) |
Call this cyclically to update the interface. Transmits messages if needed and processes timeouts for received messages.
Definition at line 38 of file isobus_maintain_power_interface.cpp.
|
private |
Stores if the interface has been initialized.
Definition at line 286 of file isobus_maintain_power_interface.hpp.
|
private |
A timestamp to track when the key was detected as ON, used to detect transitions to "Not On".
Definition at line 282 of file isobus_maintain_power_interface.hpp.
|
private |
A timestamp to track when the key is off, used to calculate how many messages to send and when to send them.
Definition at line 283 of file isobus_maintain_power_interface.hpp.
|
private |
An event publisher for notifying when the key switch transitions to the off state.
Definition at line 281 of file isobus_maintain_power_interface.hpp.
|
staticconstexprprivate |
The amount of time that power can be maintained per message, used as the timeout as well.
Definition at line 278 of file isobus_maintain_power_interface.hpp.
|
private |
An event publisher for notifying when new maintain power messages are received.
Definition at line 280 of file isobus_maintain_power_interface.hpp.
|
private |
The amount of time to ask the TECU to maintain actuator/section power. Will be rounded up to the next 2s mark when sent.
Definition at line 285 of file isobus_maintain_power_interface.hpp.
MaintainPowerData isobus::MaintainPowerInterface::maintainPowerTransmitData |
Use this to configure the transmission of the maintain power message.
Definition at line 237 of file isobus_maintain_power_interface.hpp.
|
private |
Timestamp used to know when to transmit the maintain power message in milliseconds.
Definition at line 284 of file isobus_maintain_power_interface.hpp.
|
private |
A list of all received maintain power messages.
Definition at line 279 of file isobus_maintain_power_interface.hpp.
|
protected |
Tx flag for sending the maintain power message. Handles retries automatically.
Definition at line 258 of file isobus_maintain_power_interface.hpp.