AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Types | Private Attributes | Static Private Attributes | List of all members
isobus::MaintainPowerInterface Class Reference

Manages sending and receiving the maintain power message (PGN 65095) More...

#include <isobus_maintain_power_interface.hpp>

Collaboration diagram for isobus::MaintainPowerInterface:
[legend]

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< MaintainPowerDataget_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.
 

Detailed Description

Manages sending and receiving the maintain power message (PGN 65095)

Definition at line 29 of file isobus_maintain_power_interface.hpp.

Member Enumeration Documentation

◆ KeySwitchState

enum class isobus::MaintainPowerInterface::KeySwitchState : std::uint8_t
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.

◆ TransmitFlags

enum class isobus::MaintainPowerInterface::TransmitFlags : std::uint32_t
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.

Constructor & Destructor Documentation

◆ MaintainPowerInterface()

isobus::MaintainPowerInterface::MaintainPowerInterface ( std::shared_ptr< InternalControlFunction > sourceControlFunction)
explicit

Constructor for a MaintainPowerInterface.

Parameters
[in]sourceControlFunctionThe control function to send the message from, or nullptr to listen only

Definition at line 13 of file isobus_maintain_power_interface.cpp.

◆ ~MaintainPowerInterface()

isobus::MaintainPowerInterface::~MaintainPowerInterface ( )

Destructor for a MaintainPowerInterface.

Definition at line 19 of file isobus_maintain_power_interface.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ get_initialized()

bool isobus::MaintainPowerInterface::get_initialized ( ) const

Returns if the interface has been initialized.

Returns
true if initialize has been called for this interface, otherwise false

Definition at line 166 of file isobus_maintain_power_interface.cpp.

◆ get_key_switch_transition_off_event_publisher()

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.

Note
You can get more comprehensive key switch events by using the wheel-selected speed events in the SpeedMessagesInterface file.
Returns
The event publisher for key switch off transitions

Definition at line 33 of file isobus_maintain_power_interface.cpp.

◆ get_maintain_power_data_event_publisher()

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.

Returns
The event publisher for maintain power messages

Definition at line 28 of file isobus_maintain_power_interface.cpp.

◆ get_maintain_power_time()

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.

Returns
The amount of time in milliseconds that the interface will send the maintain power message for.

Definition at line 176 of file isobus_maintain_power_interface.cpp.

◆ get_number_received_maintain_power_sources()

std::size_t isobus::MaintainPowerInterface::get_number_received_maintain_power_sources ( ) const

Returns the number of unique senders of the maintain power message.

Returns
The number of unique senders of the maintain power message

Definition at line 181 of file isobus_maintain_power_interface.cpp.

◆ get_received_maintain_power()

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.

Parameters
[in]indexAn index of senders of the maintain power message
Returns
A pointer to the maintain power message data, or nullptr if the index is out of range

Definition at line 186 of file isobus_maintain_power_interface.cpp.

◆ initialize()

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.

Here is the call graph for this function:

◆ process_flags()

void isobus::MaintainPowerInterface::process_flags ( std::uint32_t flag,
void * parentPointer )
staticprotected

Processes one flag (which sends the associated message)

Parameters
[in]flagThe flag to process
[in]parentPointerA pointer to the interface instance

Definition at line 219 of file isobus_maintain_power_interface.cpp.

◆ process_rx_message()

void isobus::MaintainPowerInterface::process_rx_message ( const CANMessage & message,
void * parentPointer )
staticprotected

Processes a CAN message.

Parameters
[in]messageThe CAN message being received
[in]parentPointerA context variable to find the relevant instance of this class

Definition at line 233 of file isobus_maintain_power_interface.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_maintain_power()

bool isobus::MaintainPowerInterface::send_maintain_power ( ) const
protected

Transmits the maintain power message.

Returns
True if the message was sent, otherwise false

Definition at line 197 of file isobus_maintain_power_interface.cpp.

Here is the call graph for this function:

◆ set_maintain_power_time()

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.

Attention
The interface will always send the message at least once with what you have configured in maintainPowerTransmitData if it was set up with an internal control function, but you should take care to configure maintainPowerTransmitData with the parameters that will ensure you have enough time to safely stop your section control and shutdown your application, because when we stop sending this message the TECU may kill power to your device or the actuators without warning.
Parameters
[in]timeToMaintainPowerThe 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.

◆ update()

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.

Here is the call graph for this function:

Member Data Documentation

◆ initialized

bool isobus::MaintainPowerInterface::initialized = false
private

Stores if the interface has been initialized.

Definition at line 286 of file isobus_maintain_power_interface.hpp.

◆ keyNotOffTimestamp

std::uint32_t isobus::MaintainPowerInterface::keyNotOffTimestamp = 0
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.

◆ keyOffTimestamp

std::uint32_t isobus::MaintainPowerInterface::keyOffTimestamp = 0
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.

◆ keySwitchOffEventPublisher

EventDispatcher isobus::MaintainPowerInterface::keySwitchOffEventPublisher
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.

◆ MAINTAIN_POWER_TIMEOUT_MS

constexpr std::uint32_t isobus::MaintainPowerInterface::MAINTAIN_POWER_TIMEOUT_MS = 2000
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.

◆ maintainPowerDataEventPublisher

EventDispatcher<const std::shared_ptr<MaintainPowerData>, bool> isobus::MaintainPowerInterface::maintainPowerDataEventPublisher
private

An event publisher for notifying when new maintain power messages are received.

Definition at line 280 of file isobus_maintain_power_interface.hpp.

◆ maintainPowerTime_ms

std::uint32_t isobus::MaintainPowerInterface::maintainPowerTime_ms = 0
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.

◆ maintainPowerTransmitData

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.

◆ maintainPowerTransmitTimestamp_ms

std::uint32_t isobus::MaintainPowerInterface::maintainPowerTransmitTimestamp_ms = 0
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.

◆ receivedMaintainPowerMessages

std::vector<std::shared_ptr<MaintainPowerData> > isobus::MaintainPowerInterface::receivedMaintainPowerMessages
private

A list of all received maintain power messages.

Definition at line 279 of file isobus_maintain_power_interface.hpp.

◆ txFlags

ProcessingFlags isobus::MaintainPowerInterface::txFlags
protected

Tx flag for sending the maintain power message. Handles retries automatically.

Definition at line 258 of file isobus_maintain_power_interface.hpp.


The documentation for this class was generated from the following files: