mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
C2: CAN error message support
This commit is contained in:
committed by
Kyle Schwarz
parent
f5f6d0828b
commit
9c4323987f
@@ -4,24 +4,24 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/icsneoc2types.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
enum class CANErrorCode : uint8_t
|
||||
enum class CANErrorCode : icsneoc2_can_error_code_t
|
||||
{
|
||||
NoError = 0,
|
||||
StuffError = 1,
|
||||
FormError = 2,
|
||||
AckError = 3,
|
||||
Bit1Error = 4,
|
||||
Bit0Error = 5,
|
||||
CRCError = 6,
|
||||
NoChange = 7
|
||||
NoError = icsneoc2_can_error_code_no_error,
|
||||
StuffError = icsneoc2_can_error_code_stuff_error,
|
||||
FormError = icsneoc2_can_error_code_form_error,
|
||||
AckError = icsneoc2_can_error_code_ack_error,
|
||||
Bit1Error = icsneoc2_can_error_code_bit1_error,
|
||||
Bit0Error = icsneoc2_can_error_code_bit0_error,
|
||||
CRCError = icsneoc2_can_error_code_crc_error,
|
||||
NoChange = icsneoc2_can_error_code_no_change
|
||||
};
|
||||
class CANErrorMessage : public Message {
|
||||
class CANErrorMessage : public RawMessage {
|
||||
public:
|
||||
CANErrorMessage() : Message(Type::CANError) {}
|
||||
Network network;
|
||||
CANErrorMessage() : RawMessage(Type::CANError) {}
|
||||
uint8_t transmitErrorCount;
|
||||
uint8_t receiveErrorCount;
|
||||
bool busOff;
|
||||
|
||||
@@ -16,6 +16,9 @@ public:
|
||||
bool isCANFD = false;
|
||||
bool baudrateSwitch = false; // CAN FD only
|
||||
bool errorStateIndicator = false; // CAN FD only
|
||||
bool txAborted = false;
|
||||
bool txLostArb = false;
|
||||
bool txError = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,17 @@ icsneoc2_error_t icsneoc2_message_free(icsneoc2_message_t* message);
|
||||
*/
|
||||
icsneoc2_error_t icsneoc2_message_is_transmit(icsneoc2_message_t* message, bool* value);
|
||||
|
||||
/**
|
||||
* Get the frame error status of a message.
|
||||
*
|
||||
* @param[in] message The message to check.
|
||||
* @param[out] value Pointer to a bool to copy the frame error status into.
|
||||
*
|
||||
* @return icsneoc2_error_t icsneoc2_error_success if successful, icsneoc2_error_invalid_parameters or
|
||||
* icsneoc2_error_invalid_type otherwise.
|
||||
*/
|
||||
icsneoc2_error_t icsneoc2_message_is_error(icsneoc2_message_t* message, bool* value);
|
||||
|
||||
/**
|
||||
* Get the Network ID (netid) of a bus message
|
||||
*
|
||||
@@ -97,11 +108,14 @@ icsneoc2_error_t icsneoc2_message_data_set(icsneoc2_message_t* message, uint8_t*
|
||||
*/
|
||||
icsneoc2_error_t icsneoc2_message_data_get(icsneoc2_message_t* message, uint8_t* data, size_t* data_length);
|
||||
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_RTR 0x01 // Remote Transmission Request
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_IDE 0x02 // Identifier Extension
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_FDF 0x04 // FD Format Indicator
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_BRS 0x08 // Bit Rate Switch (FD only)
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_ESI 0x10 // Error State Indicator (FD only)
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_RTR 0x01 // Remote Transmission Request
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_IDE 0x02 // Identifier Extension
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_FDF 0x04 // FD Format Indicator
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_BRS 0x08 // Bit Rate Switch (FD only)
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_ESI 0x10 // Error State Indicator (FD only)
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ABORTED 0x20 // CAN transmit was aborted
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_TX_LOST_ARB 0x40 // CAN transmit lost arbitration
|
||||
#define ICSNEOC2_MESSAGE_CAN_FLAGS_TX_ERROR 0x80 // CAN transmit reported an error
|
||||
|
||||
typedef uint64_t icsneoc2_message_can_flags_t;
|
||||
|
||||
@@ -122,6 +136,7 @@ icsneoc2_error_t icsneoc2_message_can_props_set(icsneoc2_message_t* message, con
|
||||
* @param[in] message The message to check.
|
||||
* @param[out] arb_id Pointer to a uint64_t to copy the arbitration ID into. If NULL, it's ignored.
|
||||
* @param[out] flags Pointer to a series of flags. If NULL, it's ignored. See icsneoc2_message_can_flags_t for details.
|
||||
* TX status flags are read-only and are only reported for CAN frames received back from the device.
|
||||
*
|
||||
* @return icsneoc2_error_t icsneoc2_error_success if successful, icsneoc2_error_invalid_parameters or icsneoc2_error_invalid_type otherwise.
|
||||
*/
|
||||
@@ -316,6 +331,35 @@ icsneoc2_error_t icsneoc2_message_lin_calc_checksum(icsneoc2_message_t* message)
|
||||
*/
|
||||
icsneoc2_error_t icsneoc2_message_network_type_get(icsneoc2_message_t* message, icsneoc2_network_type_t* network_type);
|
||||
|
||||
/**
|
||||
* Check if a message is a CAN error message
|
||||
*
|
||||
* @param[in] message The message to check.
|
||||
* @param[out] is_can_error Pointer to a bool to copy the CAN error status of the message into.
|
||||
*
|
||||
* @return icsneoc2_error_t icsneoc2_error_success if successful, icsneoc2_error_invalid_parameters otherwise.
|
||||
*/
|
||||
icsneoc2_error_t icsneoc2_message_is_can_error(icsneoc2_message_t* message, bool* is_can_error);
|
||||
|
||||
/**
|
||||
* Get the CAN error specific properties of a message
|
||||
*
|
||||
* @param[in] message The message to check.
|
||||
* @param[out] tx_err_count Pointer to a uint8_t to copy the transmit error count into. If NULL, it's ignored.
|
||||
* @param[out] rx_err_count Pointer to a uint8_t to copy the receive error count into. If NULL, it's ignored.
|
||||
* @param[out] error_code Pointer to a icsneoc2_can_error_code_t to copy the error code into. If NULL, it's ignored.
|
||||
* @param[out] data_error_code Pointer to a icsneoc2_can_error_code_t to copy the data phase error code into. If NULL, it's ignored.
|
||||
* @param[out] flags Pointer to a icsneoc2_message_can_error_flags_t to copy the error flags into. If NULL, it's ignored.
|
||||
* See ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_* for controller-error bits.
|
||||
*
|
||||
* @return icsneoc2_error_t icsneoc2_error_success if successful, icsneoc2_error_invalid_parameters or icsneoc2_error_invalid_type otherwise.
|
||||
*/
|
||||
icsneoc2_error_t icsneoc2_message_can_error_props_get(
|
||||
icsneoc2_message_t *message, uint8_t *tx_err_count, uint8_t *rx_err_count,
|
||||
icsneoc2_can_error_code_t *error_code,
|
||||
icsneoc2_can_error_code_t *data_error_code,
|
||||
icsneoc2_message_can_error_flags_t *flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -400,6 +400,28 @@ typedef enum _icsneoc2_memory_type_t {
|
||||
|
||||
typedef uint8_t icsneoc2_memory_type_t;
|
||||
|
||||
typedef enum _icsneoc2_can_error_code_t {
|
||||
icsneoc2_can_error_code_no_error = 0, // No error
|
||||
icsneoc2_can_error_code_stuff_error, // Stuff error
|
||||
icsneoc2_can_error_code_form_error, // Form error
|
||||
icsneoc2_can_error_code_ack_error, // Ack error
|
||||
icsneoc2_can_error_code_bit1_error, // Bit1 error
|
||||
icsneoc2_can_error_code_bit0_error, // Bit0 error
|
||||
icsneoc2_can_error_code_crc_error, // CRC error
|
||||
icsneoc2_can_error_code_no_change, // No change
|
||||
|
||||
// Must be last entry. Don't use as a CAN error code.
|
||||
icsneoc2_can_error_code_maxsize
|
||||
} _icsneoc2_can_error_code_t;
|
||||
|
||||
typedef uint8_t icsneoc2_can_error_code_t;
|
||||
|
||||
#define ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_BUS_OFF 0x01 // Bus off state
|
||||
#define ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_PASSIVE 0x02 // Error passive state
|
||||
#define ICSNEOC2_MESSAGE_CAN_ERROR_FLAGS_ERROR_WARN 0x04 // Error warning state
|
||||
|
||||
typedef uint64_t icsneoc2_message_can_error_flags_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user