36#ifndef ISOBUS_DIAGNOSTIC_PROTOCOL_HPP
37#define ISOBUS_DIAGNOSTIC_PROTOCOL_HPP
41#include "isobus/utility/processing_flags.hpp"
130 SAEJ1939Network1PrimaryVehicleNetwork = 0,
134 OtherManufacturerSpecifiedPort = 4,
137 SAEJ1939Network2 = 7,
138 SAEJ1939Network4 = 8,
139 ProprietaryNetwork2 = 9,
140 ProprietaryNetwork1 = 10,
141 SAEJ1939Network3 = 11,
142 SAEJ1939Network5 = 25,
143 SAEJ1939Network6 = 26,
144 SAEJ1939Network7 = 27,
145 SAEJ1939Network8 = 28,
146 SAEJ1939Network11 = 29,
147 SAEJ1939Network10 = 30,
148 SAEJ1939Network9 = 31,
470 std::shared_ptr<ControlFunction> requestingControlFunction,
482 std::shared_ptr<ControlFunction> requestingControlFunction,
485 void *parentPointer);
490 static void process_flags(std::uint32_t flag,
void *parentPointer);
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
A class that represents a generic CAN message of arbitrary length.
Manages the control function functionalities message.
A storage class for describing a complete DTC.
std::uint32_t suspectParameterNumber
This 19-bit number is used to identify the item for which diagnostics are being reported.
std::uint8_t occurrenceCount
Number of times the DTC has been active (0 to 126 with 127 being not available)
DiagnosticTroubleCode()=default
Constructor for a DTC, sets default values at construction time.
LampStatus lampState
The J1939 lamp state for this DTC.
bool operator==(const DiagnosticTroubleCode &obj) const
A useful way to compare DTC objects to each other for equality.
std::uint8_t get_occurrence_count() const
Returns the occurrence count, which will be kept track of by the protocol.
std::uint32_t get_suspect_parameter_number() const
Returns the suspect parameter number.
FailureModeIdentifier get_failure_mode_identifier() const
Returns the failure mode indicator.
FailureModeIdentifier failureModeIdentifier
The FMI defines the type of failure detected in the sub-system identified by an SPN.
Manages the DM1, DM2, and DM3 messages for ISO11783 or J1939.
SuspendSignalState
Enumerates the different suspend signals for DM13.
@ IndefiniteSuspension
Indefinite suspension of all broadcasts.
@ PartialTemporarySuspension
Temporary suspension of some messages.
@ Resuming
Resuming normal broadcast pattern.
@ PartialIndefiniteSuspension
Indefinite suspension of some messages.
@ TemporarySuspension
Temporary suspension of all broadcasts.
bool broadcastState
Bitfield for tracking the network broadcast state for DM13.
~DiagnosticProtocol()
The destructor for this protocol.
void process_message(const CANMessage &message)
A generic way for a protocol to process a received message.
FailureModeIdentifier
FMI as defined in ISO11783-12 Annex E.
@ VoltageBelowNormal
A voltage signal, data or otherwise, is below the predefined limits that bound the range.
@ ReceivedNetworkDataInError
Any failure that is detected when the data received through the network are found replaced by the �er...
@ DataValidBelowNormalMostSevere
Condition is below normal as determined by the predefined most severe level limits for that particula...
@ DataValidAboveNormalMostSevere
Condition is above normal as determined by the predefined most severe level limits for that particula...
@ DataValidBelowNormalModeratelySevere
Condition is below what would be considered normal as determined by the predefined moderately severe ...
@ AbnormalUpdateRate
Any failure that is detected when receipt of data through the data network is not at the update rate ...
@ MechanicalSystemNotResponding
Any fault that is detected as the result of an improper mechanical adjustment, an improper response o...
@ RootCauseNotKnown
It has been detected that a failure has occurred in a particular subsystem but the exact nature of th...
@ DataValidAboveNormalLeastSevere
Condition is above what would be considered normal as determined by the predefined least severe level...
@ DataValidAboveNormalModeratelySevere
Condition is above what would be considered normal as determined by the predefined moderately severe ...
@ VoltageAboveNormal
A voltage signal, data or otherwise, is above the predefined limits that bound the range.
@ DataValidBelowNormalLeastSevere
Condition is below what would be considered normal as determined by the predefined least severe level...
@ OutOfCalibration
A failure that can be identified as the result of improper calibration.
@ AbnormalRateOfChange
Any data, exclusive of FMI 2, that are considered valid but which are changing at a rate that is outs...
@ SpecialInstructions
Used when the on-board system can isolate the failure to a small number of choices but not to a singl...
@ ConditionExists
The condition that is identified by the SPN exists when no applicable FMI exists (any other error)
@ DataErratic
Erratic or intermittent data include all measurements that change at a rate not considered possible i...
@ CurrentAboveNormal
A current signal, data or otherwise, is above the predefined limits that bound the range.
@ CurrentBelowNormal
A current signal, data or otherwise, is below the predefined limits that bound the range.
@ AbnormalFrequency
Any frequency or PWM signal that is outside the predefined limits which bound the signal range for fr...
@ BadIntelligentDevice
Internal diagnostic procedures have determined that the failure is one which requires the replacement...
ProcessingFlags txFlags
An instance of the processing flags to handle retries of some messages.
void get_inactive_list_lamp_state_and_flash_state(Lamps targetLamp, FlashState &flash, bool &lampOn) const
This is a way to find the overall lamp states to report.
std::string productIdentificationBrand
The product identification brand for sending the product identification message.
static void process_flags(std::uint32_t flag, void *parentPointer)
A generic callback for a the class to process flags from the ProcessingFlags
void clear_software_id_fields()
Clears all previously configured software ID fields set with set_software_id_field.
NetworkType networkType
The diagnostic network type that this protocol will use.
bool get_initialized() const
Returns if the protocol has been initialized.
bool set_product_identification_model(const std::string &value)
Sets the product identification model used in the diagnostic protocol "Product Identification" messag...
static constexpr std::uint16_t MAX_PAYLOAD_SIZE_BYTES
DM 1 and 2 are limited to the BAM message max, because ETP does not allow global destinations.
EventCallbackHandle addressViolationEventHandle
Stores the handle from registering for address violation events.
static constexpr std::uint32_t DM_MAX_FREQUENCY_MS
You are technically allowed to send more than this under limited circumstances, but a hard limit save...
bool suspend_broadcasts(std::uint16_t suspendTime_seconds=0xFFFF)
Informs the diagnostic protocol that you are going to suspend broadcasts.
bool send_ecu_identification() const
Sends the ECU ID message.
NetworkType
Enumerates the different networks in the DM13.
bool send_dm13_announce_suspension(std::uint16_t suspendTime_seconds) const
Sends the DM13 to alert network devices of impending suspended broadcasts.
bool send_diagnostic_protocol_identification() const
Sends a message that identifies which diagnostic protocols are supported.
StopStartCommand
Enumerates the commands in the DM13.
@ StopBroadcast
Stop broadcast.
@ StartBroadcast
Start broadcast.
@ DontCareNoAction
Don’t Care/take no action (leave as is)
std::vector< std::string > ecuIdentificationFields
Stores the ECU ID fields so we can transmit them when ECU ID's PGN is requested.
FlashState
Enumerates lamp flash states in J1939.
std::uint16_t customDM13SuspensionTime
If using a non-standard DM13 suspension time, this tracks that duration in milliseconds.
void update()
Updates the diagnostic protocol.
DiagnosticProtocol(std::shared_ptr< InternalControlFunction > internalControlFunction, NetworkType networkType=NetworkType::ProprietaryNetwork1)
The constructor for this protocol.
bool set_diagnostic_trouble_code_active(const DiagnosticTroubleCode &dtc, bool active)
Adds a DTC to the active list, or removes one from the active list.
std::shared_ptr< InternalControlFunction > myControlFunction
The internal control function that this protocol will send from.
LampStatus
The DTC lamp status as defined in J1939-73. Not used when in ISO11783 mode.
@ EngineProtectLampSolid
This lamp is used to relay trouble code information that is reporting a problem with a vehicle system...
@ EngineProtectLampSlowFlash
This lamp is used to relay trouble code information that is reporting a problem with a vehicle system...
@ EngineProtectLampFastFlash
This lamp is used to relay trouble code information that is reporting a problem with a vehicle system...
@ AmberWarningLampSlowFlash
This lamp is used to relay trouble code information that is reporting a problem with the vehicle syst...
@ AmberWarningLampFastFlash
This lamp is used to relay trouble code information that is reporting a problem with the vehicle syst...
@ AmberWarningLampSolid
This lamp is used to relay trouble code information that is reporting a problem with the vehicle syst...
@ MalfunctionIndicatorLampSolid
A lamp used to relay only emissions-related trouble code information.
@ RedStopLampSolid
This lamp is used to relay trouble code information that is of a severe-enough condition that it warr...
@ MalfunctionIndicatorLampSlowFlash
A lamp used to relay only emissions-related trouble code information.
@ MalfunctionIndicatorLampFastFlash
A lamp used to relay only emissions-related trouble code information.
@ RedStopLampFastFlash
This lamp is used to relay trouble code information that is of a severe-enough condition that it warr...
@ RedStopLampSlowFlash
This lamp is used to relay trouble code information that is of a severe-enough condition that it warr...
Lamps
Lists the different lamps in J1939-73.
@ MalfunctionIndicatorLamp
The "MIL".
@ AmberWarningLamp
The "AWL".
@ ProtectLamp
The engine protect lamp.
std::uint32_t lastDM13ReceivedTimestamp
A timestamp in milliseconds when we last got a DM13 message.
void clear_inactive_diagnostic_trouble_codes()
Clears the list of inactive DTCs and clears occurrence counts.
DM22ControlByte
The DM22 multiplexer bytes. All bytes not given a value here are reserved by SAE.
@ NegativeAcknowledgeOfPreviouslyActiveDTCClear
NACK for clearing a previously active DTC.
@ RequestToClearPreviouslyActiveDTC
Clear a previously active DTC.
@ PositiveAcknowledgeOfPreviouslyActiveDTCClear
ACK for clearing a previously active DTC.
@ RequestToClearActiveDTC
Clear an active DTC.
@ PositiveAcknowledgeOfActiveDTCClear
ACK clearing an active DTC.
@ NegativeAcknowledgeOfActiveDTCClear
NACK clearing an active DTC.
bool set_product_identification_brand(const std::string &value)
Sets the product identification brand used in the diagnostic protocol "Product Identification" messag...
static constexpr std::uint32_t DM13_TIMEOUT_MS
The timeout in 5.7.13 after which nodes shall revert back to the normal broadcast state.
DM22NegativeAcknowledgeIndicator
The negative acknowledge (NACK) reasons for a DM22 message.
@ General
General negative acknowledge.
@ DTCNoLongerActive
DTC is inactive, not active, but active was requested to be cleared.
@ DTCNoLongerPreviouslyActive
The DTC in in the active list but it was requested to clear from inactive list.
@ UnknownOrDoesNotExist
The DTC is unknown or does not exist.
@ AccessDenied
Security denied access.
std::string productIdentificationModel
The product identification model name for sending the product identification message.
std::vector< std::string > softwareIdentificationFields
Stores the Software ID fields so we can transmit them when the PGN is requested.
static constexpr std::uint8_t DM13_NETWORK_BITMASK
Used to mask the network SPN values.
static constexpr std::uint8_t PRODUCT_IDENTIFICATION_MAX_STRING_LENGTH
The max string length allowed in the fields of product ID, as defined in ISO 11783-12.
ControlFunctionFunctionalities ControlFunctionFunctionalitiesMessageInterface
Use this interface to configure your CF's functionalities. This info will be reported to any ECU that...
std::string productIdentificationCode
The product identification code for sending the product identification message.
bool set_product_identification_code(const std::string &value)
Sets the product ID code used in the diagnostic protocol "Product Identification" message (PGN 0xFC8D...
void terminate()
The protocol's terminate function.
bool get_j1939_mode() const
Returns true if the protocol is in J1939 mode instead of ISO11783 mode, false if using ISO11783 mode.
std::uint8_t convert_flash_state_to_byte(FlashState flash) const
A utility function to get the CAN representation of a FlashState.
std::vector< DM22Data > dm22ResponseQueue
Maintaining a list of DM22 responses we need to send to allow for retrying in case of Tx failures.
bool get_diagnostic_trouble_code_active(const DiagnosticTroubleCode &dtc)
Returns if a DTC is active.
bool initialize()
The protocol's initializer function.
bool send_diagnostic_message_2() const
Sends a DM2 encoded CAN message.
bool j1939Mode
Tells the protocol to operate according to J1939 instead of ISO11783.
void set_software_id_field(std::uint32_t index, const std::string &value)
Adds an ascii string to this internal control function's software ID.
bool get_broadcast_state() const
Gets the current broadcast state for the connected network type.
void set_ecu_id_field(ECUIdentificationFields field, const std::string &value)
Sets one of the ECU identification strings for the ECU ID message.
static constexpr std::uint8_t DM13_BITS_PER_NETWORK
Number of bits for the network SPNs.
TransmitFlags
A set of transmit flags to manage sending DM1, DM2, and protocol ID.
@ DM1
A flag to manage sending the DM1 message.
@ ProductIdentification
A flag to manage sending the product identification message.
@ DM2
A flag to manage sending the DM2 message.
@ SoftwareIdentification
A flag to manage sending the software ID message.
@ ECUIdentification
A flag to manage sending the ECU ID message.
@ DiagnosticProtocolID
A flag to manage sending the Diagnostic protocol ID message.
@ DM22
Process queued up DM22 responses.
@ NumberOfFlags
The number of flags in the enum.
std::vector< DiagnosticTroubleCode > inactiveDTCList
Keeps track of all the previously active DTCs.
void clear_active_diagnostic_trouble_codes()
Clears the list of active DTCs and makes them all inactive.
void set_j1939_mode(bool value)
Enables the protocol to run in J1939 mode instead of ISO11783 mode.
static constexpr std::uint8_t DM13_NUMBER_OF_J1939_NETWORKS
The number of networks in DM13 that are set aside for J1939.
bool parse_j1939_network_states(const CANMessage &message)
Parses out the DM13 J1939 network states from a CAN message.
static constexpr std::uint8_t DM_PAYLOAD_BYTES_PER_DTC
The number of payload bytes per DTC that gets encoded into the messages.
void get_active_list_lamp_state_and_flash_state(Lamps targetLamp, FlashState &flash, bool &lampOn) const
This is a way to find the overall lamp states to report.
static constexpr std::uint32_t DM13_HOLD_SIGNAL_TRANSMIT_INTERVAL_MS
Defined in 5.7.13.13 SPN 1236.
void on_address_violation(std::shared_ptr< InternalControlFunction > affectedControlFunction)
A callback function used to consume address violation events and activate a DTC as required in ISO117...
bool send_product_identification() const
Sends the product identification message (PGN 0xFC8D)
bool send_diagnostic_message_1() const
Sends a DM1 encoded CAN message.
std::uint32_t lastDM1SentTimestamp
A timestamp in milliseconds of the last time a DM1 was sent.
ECUIdentificationFields
Enumerates the different fields in the ECU identification message.
@ ManufacturerName
Manufacturer name string.
@ Type
The type of ECU. One example of a use of the ECU type could be for classifying ECU capabilities,...
@ SerialNumber
The serial number of the physical ECU.
@ NumberOfFields
The number of fields currently defined in the ISO standard.
@ Location
The location of the ECU within a network.
@ HardwareID
ISO 11783 only, This parameter is used to associate the hardware version of an ECU connected to the I...
@ PartNumber
The part number of the physical ECU.
bool initialized
Stores if the interface has been initialized.
std::vector< DiagnosticTroubleCode > activeDTCList
Keeps track of all the active DTCs.
bool process_parameter_group_number_request(std::uint32_t parameterGroupNumber, std::shared_ptr< ControlFunction > requestingControlFunction, bool &acknowledge, AcknowledgementType &acknowledgementType)
Handles PGN requests for the diagnostic protocol.
bool process_all_dm22_responses()
Processes any DM22 responses from the queue.
bool send_software_identification() const
Sends the software ID message.
static constexpr std::uint16_t MAX_DM13_CUSTOM_SUSPEND_TIME_MS
The max valid value for a DM13 suspension time in milliseconds.
Defines a class that manages the control function functionalities message data. (PGN 64654,...
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
AcknowledgementType
The types of acknowledgement that can be sent in the Ack PGN.
A structure to hold data about DM22 responses we need to send.
std::uint8_t nackIndicator
The NACK reason, if applicable.
std::uint32_t suspectParameterNumber
SPN of the DTC for the DM22.
bool nack
true if we are sending a NACK instead of PACK. Determines if we use nackIndicator
bool clearActive
true if the DM22 was for an active DTC, false for previously active
std::shared_ptr< ControlFunction > destination
Destination for the DM22 message.
std::uint8_t failureModeIdentifier
FMI of the DTC for the DM22.