// PCAN-ISO-TP_2016.cs
//
// ~~~~~~~~~~~~
//
// PCAN-ISO-TP API
//
// ~~~~~~~~~~~~
//
// ------------------------------------------------------------------
// Author : Fabrice Vergnaud
// Last changed by: $Author: Fabrice $
// Last changed date: $Date: 2023-03-23 11:37:15 +0100 (Thu, 23 Mar 2023) $
//
// Language: C#
// ------------------------------------------------------------------
//
// Copyright (C) 2020 PEAK-System Technik GmbH, Darmstadt
// more Info at http://www.peak-system.com
//
// To use PCAN-ISO-TP_2004 and PCAN-ISO-TP_2016 together: do define PCANTP_API_COMPATIBILITY_ISO_2004"
// #define PCANTP_API_COMPATIBILITY_ISO_2004
// To accept unsafe functions, define UNSAFE
//#define UNSAFE
using System;
using System.Runtime.InteropServices;
using System.Text;
using Peak.Can.Basic;
namespace Peak.Can.IsoTp
{
////////////////////////////////////////////////////////////
// Types definition
////////////////////////////////////////////////////////////
using cantp_bitrate = String; // Represents a PCAN-FD bit rate string
using cantp_timestamp = UInt64; // Timestamp
using cantp_pcanstatus = UInt32; // Represents the PCAN error and status codes
// Reserved extra information
using cantp_msginfo_flag = UInt32;
using cantp_msginfo_extra = UIntPtr;
using cantp_isotp_info = UIntPtr;
#region Enumerations
///
/// Represents currently defined and supported PCANTP handle (a.k.a. channels)
///
public enum cantp_handle : UInt32
{
///
/// Undefined/default value for a PCAN bus
///
PCANTP_HANDLE_NONEBUS = PCANBasic.PCAN_NONEBUS,
///
/// PCAN-ISA interface, channel 1
///
PCANTP_HANDLE_ISABUS1 = PCANBasic.PCAN_ISABUS1,
///
/// PCAN-ISA interface, channel 2
///
PCANTP_HANDLE_ISABUS2 = PCANBasic.PCAN_ISABUS2,
///
/// PCAN-ISA interface, channel 3
///
PCANTP_HANDLE_ISABUS3 = PCANBasic.PCAN_ISABUS3,
///
/// PCAN-ISA interface, channel 4
///
PCANTP_HANDLE_ISABUS4 = PCANBasic.PCAN_ISABUS4,
///
/// PCAN-ISA interface, channel 5
///
PCANTP_HANDLE_ISABUS5 = PCANBasic.PCAN_ISABUS5,
///
/// PCAN-ISA interface, channel 6
///
PCANTP_HANDLE_ISABUS6 = PCANBasic.PCAN_ISABUS6,
///
/// PCAN-ISA interface, channel 7
///
PCANTP_HANDLE_ISABUS7 = PCANBasic.PCAN_ISABUS7,
///
/// PCAN-ISA interface, channel 8
///
PCANTP_HANDLE_ISABUS8 = PCANBasic.PCAN_ISABUS8,
///
/// PCAN-Dongle/LPT interface, channel 1
///
PCANTP_HANDLE_DNGBUS1 = PCANBasic.PCAN_DNGBUS1,
///
/// PCAN-PCI interface, channel 1
///
PCANTP_HANDLE_PCIBUS1 = PCANBasic.PCAN_PCIBUS1,
///
/// PCAN-PCI interface, channel 2
///
PCANTP_HANDLE_PCIBUS2 = PCANBasic.PCAN_PCIBUS2,
///
/// PCAN-PCI interface, channel 3
///
PCANTP_HANDLE_PCIBUS3 = PCANBasic.PCAN_PCIBUS3,
///
/// PCAN-PCI interface, channel 4
///
PCANTP_HANDLE_PCIBUS4 = PCANBasic.PCAN_PCIBUS4,
///
/// PCAN-PCI interface, channel 5
///
PCANTP_HANDLE_PCIBUS5 = PCANBasic.PCAN_PCIBUS5,
///
/// PCAN-PCI interface, channel 6
///
PCANTP_HANDLE_PCIBUS6 = PCANBasic.PCAN_PCIBUS6,
///
/// PCAN-PCI interface, channel 7
///
PCANTP_HANDLE_PCIBUS7 = PCANBasic.PCAN_PCIBUS7,
///
/// PCAN-PCI interface, channel 8
///
PCANTP_HANDLE_PCIBUS8 = PCANBasic.PCAN_PCIBUS8,
///
/// PCAN-PCI interface, channel 9
///
PCANTP_HANDLE_PCIBUS9 = PCANBasic.PCAN_PCIBUS9,
///
/// PCAN-PCI interface, channel 10
///
PCANTP_HANDLE_PCIBUS10 = PCANBasic.PCAN_PCIBUS10,
///
/// PCAN-PCI interface, channel 11
///
PCANTP_HANDLE_PCIBUS11 = PCANBasic.PCAN_PCIBUS11,
///
/// PCAN-PCI interface, channel 12
///
PCANTP_HANDLE_PCIBUS12 = PCANBasic.PCAN_PCIBUS12,
///
/// PCAN-PCI interface, channel 13
///
PCANTP_HANDLE_PCIBUS13 = PCANBasic.PCAN_PCIBUS13,
///
/// PCAN-PCI interface, channel 14
///
PCANTP_HANDLE_PCIBUS14 = PCANBasic.PCAN_PCIBUS14,
///
/// PCAN-PCI interface, channel 15
///
PCANTP_HANDLE_PCIBUS15 = PCANBasic.PCAN_PCIBUS15,
///
/// PCAN-PCI interface, channel 16
///
PCANTP_HANDLE_PCIBUS16 = PCANBasic.PCAN_PCIBUS16,
///
/// PCAN-USB interface, channel 1
///
PCANTP_HANDLE_USBBUS1 = PCANBasic.PCAN_USBBUS1,
///
/// PCAN-USB interface, channel 2
///
PCANTP_HANDLE_USBBUS2 = PCANBasic.PCAN_USBBUS2,
///
/// PCAN-USB interface, channel 3
///
PCANTP_HANDLE_USBBUS3 = PCANBasic.PCAN_USBBUS3,
///
/// PCAN-USB interface, channel 4
///
PCANTP_HANDLE_USBBUS4 = PCANBasic.PCAN_USBBUS4,
///
/// PCAN-USB interface, channel 5
///
PCANTP_HANDLE_USBBUS5 = PCANBasic.PCAN_USBBUS5,
///
/// PCAN-USB interface, channel 6
///
PCANTP_HANDLE_USBBUS6 = PCANBasic.PCAN_USBBUS6,
///
/// PCAN-USB interface, channel 7
///
PCANTP_HANDLE_USBBUS7 = PCANBasic.PCAN_USBBUS7,
///
/// PCAN-USB interface, channel 8
///
PCANTP_HANDLE_USBBUS8 = PCANBasic.PCAN_USBBUS8,
///
/// PCAN-USB interface, channel 9
///
PCANTP_HANDLE_USBBUS9 = PCANBasic.PCAN_USBBUS9,
///
/// PCAN-USB interface, channel 10
///
PCANTP_HANDLE_USBBUS10 = PCANBasic.PCAN_USBBUS10,
///
/// PCAN-USB interface, channel 11
///
PCANTP_HANDLE_USBBUS11 = PCANBasic.PCAN_USBBUS11,
///
/// PCAN-USB interface, channel 12
///
PCANTP_HANDLE_USBBUS12 = PCANBasic.PCAN_USBBUS12,
///
/// PCAN-USB interface, channel 13
///
PCANTP_HANDLE_USBBUS13 = PCANBasic.PCAN_USBBUS13,
///
/// PCAN-USB interface, channel 14
///
PCANTP_HANDLE_USBBUS14 = PCANBasic.PCAN_USBBUS14,
///
/// PCAN-USB interface, channel 15
///
PCANTP_HANDLE_USBBUS15 = PCANBasic.PCAN_USBBUS15,
///
/// PCAN-USB interface, channel 16
///
PCANTP_HANDLE_USBBUS16 = PCANBasic.PCAN_USBBUS16,
///
/// PCAN-PC Card interface, channel 1
///
PCANTP_HANDLE_PCCBUS1 = PCANBasic.PCAN_PCCBUS1,
///
/// PCAN-PC Card interface, channel 2
///
PCANTP_HANDLE_PCCBUS2 = PCANBasic.PCAN_PCCBUS2,
///
/// PCAN-LAN interface, channel 1
///
PCANTP_HANDLE_LANBUS1 = PCANBasic.PCAN_LANBUS1,
///
/// PCAN-LAN interface, channel 2
///
PCANTP_HANDLE_LANBUS2 = PCANBasic.PCAN_LANBUS2,
///
/// PCAN-LAN interface, channel 3
///
PCANTP_HANDLE_LANBUS3 = PCANBasic.PCAN_LANBUS3,
///
/// PCAN-LAN interface, channel 4
///
PCANTP_HANDLE_LANBUS4 = PCANBasic.PCAN_LANBUS4,
///
/// PCAN-LAN interface, channel 5
///
PCANTP_HANDLE_LANBUS5 = PCANBasic.PCAN_LANBUS5,
///
/// PCAN-LAN interface, channel 6
///
PCANTP_HANDLE_LANBUS6 = PCANBasic.PCAN_LANBUS6,
///
/// PCAN-LAN interface, channel 7
///
PCANTP_HANDLE_LANBUS7 = PCANBasic.PCAN_LANBUS7,
///
/// PCAN-LAN interface, channel 8
///
PCANTP_HANDLE_LANBUS8 = PCANBasic.PCAN_LANBUS8,
///
/// PCAN-LAN interface, channel 9
///
PCANTP_HANDLE_LANBUS9 = PCANBasic.PCAN_LANBUS9,
///
/// PCAN-LAN interface, channel 10
///
PCANTP_HANDLE_LANBUS10 = PCANBasic.PCAN_LANBUS10,
///
/// PCAN-LAN interface, channel 11
///
PCANTP_HANDLE_LANBUS11 = PCANBasic.PCAN_LANBUS11,
///
/// PCAN-LAN interface, channel 12
///
PCANTP_HANDLE_LANBUS12 = PCANBasic.PCAN_LANBUS12,
///
/// PCAN-LAN interface, channel 13
///
PCANTP_HANDLE_LANBUS13 = PCANBasic.PCAN_LANBUS13,
///
/// PCAN-LAN interface, channel 14
///
PCANTP_HANDLE_LANBUS14 = PCANBasic.PCAN_LANBUS14,
///
/// PCAN-LAN interface, channel 15
///
PCANTP_HANDLE_LANBUS15 = PCANBasic.PCAN_LANBUS15,
///
/// PCAN-LAN interface, channel 16
///
PCANTP_HANDLE_LANBUS16 = PCANBasic.PCAN_LANBUS16,
}
///
/// Represents the baudrate register for the PCANTP channel
///
public enum cantp_baudrate : UInt32
{
///
/// Channel Baudrate 1 MBit/s
///
PCANTP_BAUDRATE_1M = TPCANBaudrate.PCAN_BAUD_1M,
///
/// Channel Baudrate 800 kBit/s
///
PCANTP_BAUDRATE_800K = TPCANBaudrate.PCAN_BAUD_800K,
///
/// Channel Baudrate 500 kBit/s
///
PCANTP_BAUDRATE_500K = TPCANBaudrate.PCAN_BAUD_500K,
///
/// Channel Baudrate 250 kBit/s
///
PCANTP_BAUDRATE_250K = TPCANBaudrate.PCAN_BAUD_250K,
///
/// Channel Baudrate 125 kBit/s
///
PCANTP_BAUDRATE_125K = TPCANBaudrate.PCAN_BAUD_125K,
///
/// Channel Baudrate 100 kBit/s
///
PCANTP_BAUDRATE_100K = TPCANBaudrate.PCAN_BAUD_100K,
///
/// Channel Baudrate 95,238 kBit/s
///
PCANTP_BAUDRATE_95K = TPCANBaudrate.PCAN_BAUD_95K,
///
/// Channel Baudrate 83,333 kBit/s
///
PCANTP_BAUDRATE_83K = TPCANBaudrate.PCAN_BAUD_83K,
///
/// Channel Baudrate 50 kBit/s
///
PCANTP_BAUDRATE_50K = TPCANBaudrate.PCAN_BAUD_50K,
///
/// Channel Baudrate 47,619 kBit/s
///
PCANTP_BAUDRATE_47K = TPCANBaudrate.PCAN_BAUD_47K,
///
/// Channel Baudrate 33,333 kBit/s
///
PCANTP_BAUDRATE_33K = TPCANBaudrate.PCAN_BAUD_33K,
///
/// Channel Baudrate 20 kBit/s
///
PCANTP_BAUDRATE_20K = TPCANBaudrate.PCAN_BAUD_20K,
///
/// Channel Baudrate 10 kBit/s
///
PCANTP_BAUDRATE_10K = TPCANBaudrate.PCAN_BAUD_10K,
///
/// Channel Baudrate 5 kBit/s
///
PCANTP_BAUDRATE_5K = TPCANBaudrate.PCAN_BAUD_5K,
}
///
/// Type of PCAN (non plug-n-play) hardware
///
public enum cantp_hwtype : UInt32
{
///
/// PCAN-ISA 82C200
///
PCANTP_HWTYPE_ISA = TPCANType.PCAN_TYPE_ISA,
///
/// PCAN-ISA SJA1000
///
PCANTP_HWTYPE_ISA_SJA = TPCANType.PCAN_TYPE_ISA_SJA,
///
/// PHYTEC ISA
///
PCANTP_HWTYPE_ISA_PHYTEC = TPCANType.PCAN_TYPE_ISA_PHYTEC,
///
/// PCAN-Dongle 82C200
///
PCANTP_HWTYPE_DNG = TPCANType.PCAN_TYPE_DNG,
///
/// PCAN-Dongle EPP 82C200
///
PCANTP_HWTYPE_DNG_EPP = TPCANType.PCAN_TYPE_DNG_EPP,
///
/// PCAN-Dongle SJA1000
///
PCANTP_HWTYPE_DNG_SJA = TPCANType.PCAN_TYPE_DNG_SJA,
///
/// PCAN-Dongle EPP SJA1000
///
PCANTP_HWTYPE_DNG_SJA_EPP = TPCANType.PCAN_TYPE_DNG_SJA_EPP,
}
///
/// PCAN devices
///
public enum cantp_device : UInt32
{
///
/// Undefined, unknown or not selected PCAN device value
///
PCANTP_DEVICE_NONE = TPCANDevice.PCAN_NONE,
///
/// PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API
///
PCANTP_DEVICE_PEAKCAN = TPCANDevice.PCAN_PEAKCAN,
///
/// PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
///
PCANTP_DEVICE_ISA = TPCANDevice.PCAN_ISA,
///
/// PCAN-Dongle
///
PCANTP_DEVICE_DNG = TPCANDevice.PCAN_DNG,
///
/// PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
///
PCANTP_DEVICE_PCI = TPCANDevice.PCAN_PCI,
///
/// PCAN-USB and PCAN-USB Pro
///
PCANTP_DEVICE_USB = TPCANDevice.PCAN_USB,
///
/// PCAN-PC Card
///
PCANTP_DEVICE_PCC = TPCANDevice.PCAN_PCC,
///
/// PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API
///
PCANTP_DEVICE_VIRTUAL = TPCANDevice.PCAN_VIRTUAL,
///
/// PCAN Gateway devices
///
PCANTP_DEVICE_LAN = TPCANDevice.PCAN_LAN,
}
////////////////////////////////////////////////////////////
// Enums definition for ISO-TP API
////////////////////////////////////////////////////////////
///
/// Represents each group of errors a status can hold
///
[Flags]
public enum cantp_statustype : UInt32
{
///
/// no error
///
PCANTP_STATUSTYPE_OK = 0x00,
///
/// general error
///
PCANTP_STATUSTYPE_ERR = 0x01,
///
/// bus status
///
PCANTP_STATUSTYPE_BUS = 0x02,
///
/// network status
///
PCANTP_STATUSTYPE_NET = 0x04,
///
/// extra information
///
PCANTP_STATUSTYPE_INFO = 0x08,
///
/// encapsulated PCAN-Basic status
///
PCANTP_STATUSTYPE_PCAN = 0x10,
}
///
/// Represents the network result of the communication of an ISO-TP message (used in cantp_status).
///
public enum cantp_netstatus : UInt32
{
// ISO-TP network errors:
///
/// No network error
///
PCANTP_NETSTATUS_OK = 0x00,
///
/// timeout occured between 2 frames transmission (sender and receiver side)
///
PCANTP_NETSTATUS_TIMEOUT_A = 0x01,
///
/// sender side timeout while waiting for flow control frame
///
PCANTP_NETSTATUS_TIMEOUT_Bs = 0x02,
///
/// receiver side timeout while waiting for consecutive frame
///
PCANTP_NETSTATUS_TIMEOUT_Cr = 0x03,
///
/// unexpected sequence number
///
PCANTP_NETSTATUS_WRONG_SN = 0x04,
///
/// invalid or unknown FlowStatus
///
PCANTP_NETSTATUS_INVALID_FS = 0x05,
///
/// unexpected protocol data unit
///
PCANTP_NETSTATUS_UNEXP_PDU = 0x06,
///
/// reception of flow control WAIT frame that exceeds the maximum counter defined by PCANTP_PARAMETER_WFT_MAX
///
PCANTP_NETSTATUS_WFT_OVRN = 0x07,
///
/// buffer on the receiver side cannot store the data length (server side only)
///
PCANTP_NETSTATUS_BUFFER_OVFLW = 0x08,
///
/// general error
///
PCANTP_NETSTATUS_ERROR = 0x09,
///
/// message was invalid and ignored
///
PCANTP_NETSTATUS_IGNORED = 0x0A,
///
/// sender side timeout while transmitting
///
PCANTP_NETSTATUS_TIMEOUT_As = 0x0B,
///
/// receiver side timeout while transmitting
///
PCANTP_NETSTATUS_TIMEOUT_Ar = 0x0C,
// NON ISO-TP related network results:
///
/// transmit queue is full (failed too many times)
///
PCANTP_NETSTATUS_XMT_FULL = 0x0D,
///
/// CAN bus error
///
PCANTP_NETSTATUS_BUS_ERROR = 0x0E,
///
/// memory allocation error
///
PCANTP_NETSTATUS_NO_MEMORY = 0x0F,
}
///
/// Represents the status of a CAN bus (used in cantp_status).
///
[Flags]
public enum cantp_busstatus : UInt32
{
///
/// Bus is in active state
///
PCANTP_BUSSTATUS_OK = 0x00,
///
/// Bus error: an error counter reached the 'light' limit
///
PCANTP_BUSSTATUS_LIGHT = 0x01,
///
/// Bus error: an error counter reached the 'heavy' limit
///
PCANTP_BUSSTATUS_HEAVY = 0x02,
///
/// Bus error: an error counter reached the 'warning/heavy' limit
///
PCANTP_BUSSTATUS_WARNING = PCANTP_BUSSTATUS_HEAVY,
///
/// Bus error: the CAN controller is error passive
///
PCANTP_BUSSTATUS_PASSIVE = 0x04,
///
/// Bus error: the CAN controller is in bus-off state
///
PCANTP_BUSSTATUS_OFF = 0x08,
///
/// Mask for all bus errors
///
PCANTP_BUSSTATUS_ANY = PCANTP_BUSSTATUS_LIGHT | PCANTP_BUSSTATUS_HEAVY | PCANTP_BUSSTATUS_WARNING | PCANTP_BUSSTATUS_PASSIVE | PCANTP_BUSSTATUS_OFF,
}
///
/// Represents an general error (used in cantp_status).
///
public enum cantp_errstatus : UInt32
{
///
/// No error
///
PCANTP_ERRSTATUS_OK = 0x00,
///
/// Not Initialized
///
PCANTP_ERRSTATUS_NOT_INITIALIZED = 0x01,
///
/// Already Initialized
///
PCANTP_ERRSTATUS_ALREADY_INITIALIZED = 0x02,
///
/// Could not obtain memory
///
PCANTP_ERRSTATUS_NO_MEMORY = 0x03,
///
/// Input buffer overflow
///
PCANTP_ERRSTATUS_OVERFLOW = 0x04,
///
/// No Message available
///
PCANTP_ERRSTATUS_NO_MESSAGE = 0x07,
///
/// Parameter has an invalid or unexpected type
///
PCANTP_ERRSTATUS_PARAM_INVALID_TYPE = 0x08,
///
/// Parameter has an invalid value
///
PCANTP_ERRSTATUS_PARAM_INVALID_VALUE = 0x09,
///
/// PCANTP mapping not initialized
///
PCANTP_ERRSTATUS_MAPPING_NOT_INITIALIZED = 0x0D,
///
/// PCANTP mapping parameters are invalid
///
PCANTP_ERRSTATUS_MAPPING_INVALID = 0x0E,
///
/// PCANTP mapping already defined
///
PCANTP_ERRSTATUS_MAPPING_ALREADY_INITIALIZED = 0x0F,
///
///
///
PCANTP_ERRSTATUS_PARAM_BUFFER_TOO_SMALL = 0x10,
///
/// Tx queue is full
///
PCANTP_ERRSTATUS_QUEUE_TX_FULL = 0x11,
///
/// Failed to get an access to the internal lock
///
PCANTP_ERRSTATUS_LOCK_TIMEOUT = 0x12,
///
/// Invalid cantp_handle
///
PCANTP_ERRSTATUS_INVALID_HANDLE = 0x13,
///
/// unknown/generic error
///
PCANTP_ERRSTATUS_UNKNOWN = 0xFF,
}
///
/// Represents additional status information (used in cantp_status).
///
[Flags]
public enum cantp_infostatus : UInt32
{
///
/// no extra information
///
PCANTP_INFOSTATUS_OK = 0x00,
///
/// input was modified by the API
///
PCANTP_INFOSTATUS_CAUTION_INPUT_MODIFIED = 0x01,
///
/// DLC value was modified by the API
///
PCANTP_INFOSTATUS_CAUTION_DLC_MODIFIED = 0x02,
///
/// Data Length value was modified by the API
///
PCANTP_INFOSTATUS_CAUTION_DATA_LENGTH_MODIFIED = 0x04,
///
/// FD related flags value were modified by the API
///
PCANTP_INFOSTATUS_CAUTION_FD_FLAG_MODIFIED = 0x08,
///
/// Message receive queue is full (oldest messages may be lost)
///
PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_FULL = 0x10,
///
/// Buffer is used by another thread or API
///
PCANTP_INFOSTATUS_CAUTION_BUFFER_IN_USE = 0x20,
///
/// Internal queue read too late (a frame was lost)
///
PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_OVERRUN = 0x30,
}
///
/// Defines constants used by the next enum: cantp_status
///
public enum cantp_status_offset : byte
{
PCANTP_STATUS_OFFSET_BUS = 8,
PCANTP_STATUS_OFFSET_NET = (PCANTP_STATUS_OFFSET_BUS + 5),
PCANTP_STATUS_OFFSET_INFO = (PCANTP_STATUS_OFFSET_NET + 5),
}
///
/// Represent the PCANTP error and status codes .
///
/// Bits information:
/// 32| 28| 24| 20| 16| 12| 8| 4| 0|
/// | | | | | | | | |
/// 0000 0000 0000 0000 0000 0000 0000 0000
/// | | | | | [0000 0000] => PCAN-ISO-TP API errors
/// | | | | | [0 0000] => CAN Bus status
/// | | | | [00 000] => Networking message status
/// | | [0000 00] => API extra information
/// |[000 0000] => Reserved
/// [0] => PCANBasic error flag (overrides the meaning of all bits)
///
public enum cantp_status : UInt32
{
PCANTP_STATUS_OK = cantp_errstatus.PCANTP_ERRSTATUS_OK,
PCANTP_STATUS_NOT_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_NOT_INITIALIZED,
PCANTP_STATUS_ALREADY_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_ALREADY_INITIALIZED,
PCANTP_STATUS_NO_MEMORY = cantp_errstatus.PCANTP_ERRSTATUS_NO_MEMORY,
PCANTP_STATUS_OVERFLOW = cantp_errstatus.PCANTP_ERRSTATUS_OVERFLOW,
PCANTP_STATUS_NO_MESSAGE = cantp_errstatus.PCANTP_ERRSTATUS_NO_MESSAGE,
PCANTP_STATUS_PARAM_INVALID_TYPE = cantp_errstatus.PCANTP_ERRSTATUS_PARAM_INVALID_TYPE,
PCANTP_STATUS_PARAM_INVALID_VALUE = cantp_errstatus.PCANTP_ERRSTATUS_PARAM_INVALID_VALUE,
PCANTP_STATUS_MAPPING_NOT_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_MAPPING_NOT_INITIALIZED,
PCANTP_STATUS_MAPPING_INVALID = cantp_errstatus.PCANTP_ERRSTATUS_MAPPING_INVALID,
PCANTP_STATUS_MAPPING_ALREADY_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_MAPPING_ALREADY_INITIALIZED,
PCANTP_STATUS_PARAM_BUFFER_TOO_SMALL = cantp_errstatus.PCANTP_ERRSTATUS_PARAM_BUFFER_TOO_SMALL,
PCANTP_STATUS_QUEUE_TX_FULL = cantp_errstatus.PCANTP_ERRSTATUS_QUEUE_TX_FULL,
PCANTP_STATUS_LOCK_TIMEOUT = cantp_errstatus.PCANTP_ERRSTATUS_LOCK_TIMEOUT,
PCANTP_STATUS_HANDLE_INVALID = cantp_errstatus.PCANTP_ERRSTATUS_INVALID_HANDLE,
PCANTP_STATUS_UNKNOWN = cantp_errstatus.PCANTP_ERRSTATUS_UNKNOWN,
#region Bus status flags (bits [8..11])
///
/// PCANTP Channel is in BUS-LIGHT error state
///
PCANTP_STATUS_FLAG_BUS_LIGHT = (cantp_busstatus.PCANTP_BUSSTATUS_LIGHT << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS),
///
/// PCANTP Channel is in BUS-HEAVY error state
///
PCANTP_STATUS_FLAG_BUS_HEAVY = (cantp_busstatus.PCANTP_BUSSTATUS_HEAVY << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS),
///
/// PCANTP Channel is in BUS-HEAVY error state
///
PCANTP_STATUS_FLAG_BUS_WARNING = PCANTP_STATUS_FLAG_BUS_HEAVY,
///
/// PCANTP Channel is error passive state
///
PCANTP_STATUS_FLAG_BUS_PASSIVE = (cantp_busstatus.PCANTP_BUSSTATUS_PASSIVE << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS),
///
/// PCANTP Channel is in BUS-OFF error state
///
PCANTP_STATUS_FLAG_BUS_OFF = (cantp_busstatus.PCANTP_BUSSTATUS_OFF << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS),
///
///
///
PCANTP_STATUS_FLAG_BUS_ANY = (cantp_busstatus.PCANTP_BUSSTATUS_ANY << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS),
#endregion
#region Network status (bits [13..17])
///
/// This flag states if one of the following network errors occured with the fetched message
///
PCANTP_STATUS_FLAG_NETWORK_RESULT = (1 << cantp_status_offset.PCANTP_STATUS_OFFSET_NET),
///
/// timeout occured between 2 frames transmission (sender and receiver side)
///
PCANTP_STATUS_NETWORK_TIMEOUT_A = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_A << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// sender side timeout while waiting for flow control frame
///
PCANTP_STATUS_NETWORK_TIMEOUT_Bs = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_Bs << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// receiver side timeout while waiting for consecutive frame
///
PCANTP_STATUS_NETWORK_TIMEOUT_Cr = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_Cr << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// unexpected sequence number
///
PCANTP_STATUS_NETWORK_WRONG_SN = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_WRONG_SN << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// invalid or unknown FlowStatus
///
PCANTP_STATUS_NETWORK_INVALID_FS = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_INVALID_FS << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// unexpected protocol data unit
///
PCANTP_STATUS_NETWORK_UNEXP_PDU = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_UNEXP_PDU << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// reception of flow control WAIT frame that exceeds the maximum counter defined by PCANTP_PARAMETER_WFT_MAX
///
PCANTP_STATUS_NETWORK_WFT_OVRN = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_WFT_OVRN << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// buffer on the receiver side cannot store the data length (server side only)
///
PCANTP_STATUS_NETWORK_BUFFER_OVFLW = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_BUFFER_OVFLW << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// general error
///
PCANTP_STATUS_NETWORK_ERROR = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_ERROR << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// message was invalid and ignored
///
PCANTP_STATUS_NETWORK_IGNORED = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_IGNORED << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
#endregion
#region ISO-TP extra information flags
///
/// Receiver side timeout while transmitting
///
PCANTP_STATUS_NETWORK_TIMEOUT_Ar = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_Ar << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// Sender side timeout while transmitting
///
PCANTP_STATUS_NETWORK_TIMEOUT_As = (PCANTP_STATUS_FLAG_NETWORK_RESULT | (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_As << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1))),
///
/// input was modified
///
PCANTP_STATUS_CAUTION_INPUT_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_INPUT_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
///
/// DLC value of the input was modified
///
PCANTP_STATUS_CAUTION_DLC_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_DLC_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
///
/// Data Length value of the input was modified
///
PCANTP_STATUS_CAUTION_DATA_LENGTH_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_DATA_LENGTH_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
///
/// FD flags of the input was modified
///
PCANTP_STATUS_CAUTION_FD_FLAG_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_FD_FLAG_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
///
/// Receive queue is full
///
PCANTP_STATUS_CAUTION_RX_QUEUE_FULL = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_FULL << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
///
/// Buffer is used by another thread or API
///
PCANTP_STATUS_CAUTION_BUFFER_IN_USE = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_BUFFER_IN_USE << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
///
/// Internal queue read too late (a frame was lost)
///
PCANTP_STATUS_CAUTION_RX_QUEUE_OVERRUN = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_OVERRUN << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO),
#endregion
#region Lower API status code: see also PCANTP_STATUS_xx macros
///
/// PCAN error flag, remove flag to get a usable PCAN error/status code (cf. PCANBasic API)
///
PCANTP_STATUS_FLAG_PCAN_STATUS = 0x80000000U,
#endregion
#region Masks to merge/retrieve different PCANTP status by type in a cantp_status
///
/// filter by PCANTP_STATUSTYPE_ERR type
///
PCANTP_STATUS_MASK_ERROR = 0x000000FFU,
///
/// filter by PCANTP_STATUSTYPE_BUS type
///
PCANTP_STATUS_MASK_BUS = 0x00001F00U,
///
/// filter by PCANTP_STATUSTYPE_NET type
///
PCANTP_STATUS_MASK_ISOTP_NET = 0x0003E000U,
///
/// filter by PCANTP_STATUSTYPE_INFO type
///
PCANTP_STATUS_MASK_INFO = 0x00FC0000U,
///
/// filter by PCANTP_STATUSTYPE_PCAN type
///
PCANTP_STATUS_MASK_PCAN = ~PCANTP_STATUS_FLAG_PCAN_STATUS,
#endregion
}
///
/// List of parameters handled by PCAN-ISO-TP (rev. 2016)
/// Note: PCAN-Basic parameters (PCAN_PARAM_xxx) are compatible via casting.
///
public enum cantp_parameter : UInt32
{
///
/// PCAN-ISO-TP API version parameter
///
PCANTP_PARAMETER_API_VERSION = 0x101,
///
/// 1 BYTE data describing the condition of a channel.
///
PCANTP_PARAMETER_CHANNEL_CONDITION = 0x102,
///
/// 1 BYTE data describing the debug mode
///
PCANTP_PARAMETER_DEBUG = 0x103,
///
/// data is pointer to a HANDLE created by CreateEvent function
///
PCANTP_PARAMETER_RECEIVE_EVENT = 0x104,
///
/// 1 BYTE data stating if unsegmented (NON-ISO-TP) CAN frames can be received
///
PCANTP_PARAMETER_FRAME_FILTERING = 0x105,
///
/// 1 BYTE data stating the default DLC to use when transmitting messages with CAN FD
///
PCANTP_PARAMETER_CAN_TX_DL = 0x106,
///
/// 1 BYTE data stating if CAN frame DLC uses padding or not
///
PCANTP_PARAMETER_CAN_DATA_PADDING = 0x107,
///
/// 1 BYTE data stating the value used for CAN data padding
///
PCANTP_PARAMETER_CAN_PADDING_VALUE = 0x108,
///
/// 1 BYTE data stating which revision of ISO 15765-2 to use (see PCANTP_ISO_REV_*).
///
PCANTP_PARAMETER_ISO_REV = 0x109,
///
/// 1 BYTE data stating the default priority value for normal fixed, mixed and enhanced addressing (default=6)
///
PCANTP_PARAMETER_J1939_PRIORITY = 0x10A,
///
/// 1 BYTE data stating if pending messages are displayed/hidden
///
PCANTP_PARAMETER_MSG_PENDING = 0x10B,
///
/// 1 BYTE data describing the block size parameter (BS)
///
PCANTP_PARAMETER_BLOCK_SIZE = 0x10C,
///
/// 2 BYTE data describing the transmit block size parameter (BS_TX)
///
PCANTP_PARAMETER_BLOCK_SIZE_TX = 0x10D,
///
/// 1 BYTE data describing the seperation time parameter (STmin)
///
PCANTP_PARAMETER_SEPARATION_TIME = 0x10E,
///
/// 2 BYTE data describing the transmit seperation time parameter (STmin_TX)
///
PCANTP_PARAMETER_SEPARATION_TIME_TX = 0x10F,
///
/// 4 BYTE data describing the Wait Frame Transmissions parameter.
///
PCANTP_PARAMETER_WFT_MAX = 0x110,
///
/// 4 BYTE data describing ISO-15765-2:Timeout As.
///
PCANTP_PARAMETER_TIMEOUT_AS = 0x111,
///
/// 4 BYTE data describing ISO-15765-2:Timeout Ar.
///
PCANTP_PARAMETER_TIMEOUT_AR = 0x112,
///
/// 4 BYTE data describing ISO-15765-2:Timeout Bs.
///
PCANTP_PARAMETER_TIMEOUT_BS = 0x113,
///
/// 4 BYTE data describing ISO-15765-2:Timeout Cr.
///
PCANTP_PARAMETER_TIMEOUT_CR = 0x114,
///
/// 1 BYTE data describing the tolerence to apply to all timeout as a percentage ([0..100].
///
PCANTP_PARAMETER_TIMEOUT_TOLERANCE = 0x115,
///
/// 1 BYTE data to set predefined ISO values for timeouts (see PCANTP_ISO_TIMEOUTS_*).
///
PCANTP_PARAMETER_ISO_TIMEOUTS = 0x116,
///
/// 1 BYTE data to set optimization options to improve delay between ISO-TP consecutive frames.
///
PCANTP_PARAMETER_SELFRECEIVE_LATENCY = 0x117,
///
/// 2 BYTE data describing the maximum number of messages in the Rx queue.
///
PCANTP_PARAMETER_MAX_RX_QUEUE = 0x118,
///
/// 1 BYTE data stating if messages handled by higher layer APIs are still available in this API (default=0).
///
PCANTP_PARAMETER_KEEP_HIGHER_LAYER_MESSAGES = 0x119,
///
/// 1 BYTE data stating if the white-list CAN IDs filtering mechanism is enabled.
///
PCANTP_PARAMETER_FILTER_CAN_ID = 0x11A,
///
/// 1 BYTE data stating if the 29 bit Enhanced Diagnostic CAN identifier is supported (ISO-15765-3:2004, default is false with ISO revision 2016).
///
PCANTP_PARAMETER_SUPPORT_29B_ENHANCED = 0x11B,
///
/// 1 BYTE data stating if the 29 bit Fixed Normal addressing CAN identifier is supported (default is true).
///
PCANTP_PARAMETER_SUPPORT_29B_FIXED_NORMAL = 0x11C,
///
/// 1 BYTE data stating if the 29 bit Mixed addressing CAN identifier is supported (default is true).
///
PCANTP_PARAMETER_SUPPORT_29B_MIXED = 0x11D,
///
/// Pointer to a cantp_msg, checks if the message is valid and can be sent (ex. if a mapping is needed) and corrects input if needed.
///
PCANTP_PARAMETER_MSG_CHECK = 0x11E,
///
/// 1 BYTE data stating to clear Rx/Tx queues and CAN controller (channel is unitialized and re-initialized but settings and mappings are kept)
///
PCANTP_PARAMETER_RESET_HARD = 0x11F,
///
/// 1 BYTE data stating if network is full-duplex (default) or half-duplex
///
PCANTP_PARAMETER_NETWORK_LAYER_DESIGN = 0x120,
///
/// 1 BYTE data stating if API allows receiption PCANTP_MSGTYPE_CANINFO from lower layer APIs
///
PCANTP_PARAMETER_ALLOW_MSGTYPE_CANINFO = 0x124,
///
/// Data is a pointer to a user-defined callback triggered when a message is received.
///
PCANTP_PARAMETER_RECEIVE_EVENT_CALLBACK = 0x125,
///
/// Data is a pointer to a user-defined structure. It can be used to pass user arguments to the reception callback function.
///
PCANTP_PARAMETER_RECEIVE_EVENT_CALLBACK_USER_CONTEXT = 0x126,
///
/// PCAN hardware name parameter
///
PCANTP_PARAMETER_HARDWARE_NAME = TPCANParameter.PCAN_HARDWARE_NAME,
///
/// PCAN-USB device identifier parameter
///
PCANTP_PARAMETER_DEVICE_ID = TPCANParameter.PCAN_DEVICE_NUMBER,
///
/// Deprecated use PCANTP_PARAMETER_DEVICE_ID instead
///
PCANTP_PARAMETER_DEVICE_NUMBER = TPCANParameter.PCAN_DEVICE_NUMBER,
///
/// CAN-Controller number of a PCAN-Channel
///
PCANTP_PARAMETER_CONTROLLER_NUMBER = TPCANParameter.PCAN_CONTROLLER_NUMBER,
///
/// Capabilities of a PCAN device (FEATURE_***)
///
PCANTP_PARAMETER_CHANNEL_FEATURES = TPCANParameter.PCAN_CHANNEL_FEATURES
}
///
/// Represents the type of a CANTP message (see field "cantp_msg.type").
///
[Flags]
public enum cantp_msgtype : UInt32
{
///
/// uninitialized message (data is NULL)
///
PCANTP_MSGTYPE_NONE = 0,
///
/// standard CAN frame
///
PCANTP_MSGTYPE_CAN = 1,
///
/// CAN frame with FD support
///
PCANTP_MSGTYPE_CANFD = 2,
///
/// ISO-TP message (ISO:15765)
///
PCANTP_MSGTYPE_ISOTP = 4,
///
/// CAN bus information
///
PCANTP_MSGTYPE_CANINFO = 8,
///
/// frame only: unsegmented messages
///
PCANTP_MSGTYPE_FRAME = PCANTP_MSGTYPE_CAN | PCANTP_MSGTYPE_CANFD,
///
/// any supported message type
///
PCANTP_MSGTYPE_ANY = PCANTP_MSGTYPE_FRAME | PCANTP_MSGTYPE_ISOTP | 0xFFFFFFFF
}
///
/// Represents the flags common to all types of cantp_msg (see field "cantp_msg.msgdata.flags").
///
public enum cantp_msgflag : UInt32
{
///
/// no flag
///
PCANTP_MSGFLAG_NONE = 0,
///
/// message is the confirmation of a transmitted message
///
PCANTP_MSGFLAG_LOOPBACK = 1,
///
/// message is a frame of a segmented ISO-TP message
///
PCANTP_MSGFLAG_ISOTP_FRAME = 2,
}
///
/// Represents the flags of a CAN or CAN FD frame (must be used as flags for ex. EXTENDED|FD|BRS.) (see field "cantp_msg.can_info.can_msgtype")
///
public enum cantp_can_msgtype : UInt32
{
///
/// The PCAN message is a CAN Standard Frame (11-bit identifier)
///
PCANTP_CAN_MSGTYPE_STANDARD = TPCANMessageType.PCAN_MESSAGE_STANDARD,
///
/// The PCAN message is a CAN Remote-Transfer-Request Frame
///
PCANTP_CAN_MSGTYPE_RTR = TPCANMessageType.PCAN_MESSAGE_RTR,
///
/// The PCAN message is a CAN Extended Frame (29-bit identifier)
///
PCANTP_CAN_MSGTYPE_EXTENDED = TPCANMessageType.PCAN_MESSAGE_EXTENDED,
///
/// The PCAN message represents a FD frame in terms of CiA Specs
///
PCANTP_CAN_MSGTYPE_FD = TPCANMessageType.PCAN_MESSAGE_FD,
///
/// The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
///
PCANTP_CAN_MSGTYPE_BRS = TPCANMessageType.PCAN_MESSAGE_BRS,
///
/// The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
///
PCANTP_CAN_MSGTYPE_ESI = TPCANMessageType.PCAN_MESSAGE_ESI,
///
/// The PCAN message represents an error frame.
///
PCANTP_CAN_MSGTYPE_ERRFRAME = TPCANMessageType.PCAN_MESSAGE_ERRFRAME,
///
/// The PCAN message represents a PCAN status message.
///
PCANTP_CAN_MSGTYPE_STATUS = TPCANMessageType.PCAN_MESSAGE_STATUS,
///
/// Echo messages reception status within a PCAN-Channel
///
PCANTP_CAN_MSGTYPE_ECHO = TPCANMessageType.PCAN_MESSAGE_ECHO,
///
/// Flag stating that the message is not a CAN Frame
///
PCANTP_CAN_MSGTYPE_FLAG_INFO = (TPCANMessageType.PCAN_MESSAGE_ERRFRAME | TPCANMessageType.PCAN_MESSAGE_STATUS)
}
///
/// Represents the type of an ISO-TP message (see field "cantp_msg.msgdata_isotp.netaddrinfo.msgtype").
///
public enum cantp_isotp_msgtype : UInt32
{
///
/// Unknown (non-ISO-TP) message
///
PCANTP_ISOTP_MSGTYPE_UNKNOWN = 0x00,
///
/// Diagnostic message (request or confirmation)
///
PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC = 0x01,
///
/// Remote Diagnostic message (request or confirmation)
///
PCANTP_ISOTP_MSGTYPE_REMOTE_DIAGNOSTIC = 0x02,
///
/// Multi-Frame Message is being received
///
PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION_RX = 0x10,
///
/// Multi-Frame Message is being transmitted
///
PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION_TX = 0x20,
///
/// Multi-Frame Message is being communicated (Tx or Rx)
///
PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION = (0x10 | 0x20),
///
/// Mask to remove Indication flags
///
PCANTP_ISOTP_MSGTYPE_MASK_INDICATION = 0x0F
}
///
/// Represents the addressing format of an ISO-TP message (see field "cantp_msg.msgdata_isotp.netaddrinfo.format").
///
public enum cantp_isotp_format : UInt32
{
///
/// unknown adressing format
///
PCANTP_ISOTP_FORMAT_UNKNOWN = 0xFF,
///
/// unsegmented CAN frame
///
PCANTP_ISOTP_FORMAT_NONE = 0x00,
///
/// normal adressing format from ISO 15765-2
///
PCANTP_ISOTP_FORMAT_NORMAL = 0x01,
///
/// fixed normal adressing format from ISO 15765-2
///
PCANTP_ISOTP_FORMAT_FIXED_NORMAL = 0x02,
///
/// extended adressing format from ISO 15765-2
///
PCANTP_ISOTP_FORMAT_EXTENDED = 0x03,
///
/// mixed adressing format from ISO 15765-2
///
PCANTP_ISOTP_FORMAT_MIXED = 0x04,
///
/// enhanced adressing format from ISO 15765-3
///
PCANTP_ISOTP_FORMAT_ENHANCED = 0x05,
}
///
/// Represents the type of target of an ISO-TP message (see field "cantp_msg.msgdata_isotp.netaddrinfo.target_type").
///
public enum cantp_isotp_addressing : UInt32
{
///
/// Unknown adressing format
///
PCANTP_ISOTP_ADDRESSING_UNKNOWN = 0x00,
///
/// Physical addressing ("peer to peer")
///
PCANTP_ISOTP_ADDRESSING_PHYSICAL = 0x01,
///
/// Functional addressing ("peer to any")
///
PCANTP_ISOTP_ADDRESSING_FUNCTIONAL = 0x02,
}
///
/// Represents the options of a message (mainly supported for ISO-TP message) (see field "cantp_msg.msgdata.options").
///
public enum cantp_option : UInt32
{
///
/// 1 BYTE data stating if unsegmented (NON-ISO-TP) CAN frames can be received
///
PCANTP_OPTION_FRAME_FILTERING = cantp_parameter.PCANTP_PARAMETER_FRAME_FILTERING,
///
/// 1 BYTE data stating if CAN frame DLC uses padding or not
///
PCANTP_OPTION_CAN_DATA_PADDING = cantp_parameter.PCANTP_PARAMETER_CAN_DATA_PADDING,
///
/// 1 BYTE data stating the value used for CAN data padding
///
PCANTP_OPTION_CAN_PADDING_VALUE = cantp_parameter.PCANTP_PARAMETER_CAN_PADDING_VALUE,
///
/// 1 BYTE data stating the default priority value for normal fixed, mixed and enhanced addressing (default=6)
///
PCANTP_OPTION_J1939_PRIORITY = cantp_parameter.PCANTP_PARAMETER_J1939_PRIORITY,
///
/// 1 BYTE data stating if pending messages are displayed/hidden
///
PCANTP_OPTION_MSG_PENDING = cantp_parameter.PCANTP_PARAMETER_MSG_PENDING,
///
/// 1 BYTE data describing the block size parameter (BS)
///
PCANTP_OPTION_BLOCK_SIZE = cantp_parameter.PCANTP_PARAMETER_BLOCK_SIZE,
///
/// 2 BYTE data describing the transmit block size parameter (BS_TX)
///
PCANTP_OPTION_BLOCK_SIZE_TX = cantp_parameter.PCANTP_PARAMETER_BLOCK_SIZE_TX,
///
/// 1 BYTE data describing the seperation time parameter (STmin)
///
PCANTP_OPTION_SEPARATION_TIME = cantp_parameter.PCANTP_PARAMETER_SEPARATION_TIME,
///
/// 2 BYTE data describing the transmit seperation time parameter (STmin_TX)
///
PCANTP_OPTION_SEPARATION_TIME_TX = cantp_parameter.PCANTP_PARAMETER_SEPARATION_TIME_TX,
///
/// 4 BYTE data describing the Wait Frame Transmissions parameter.
///
PCANTP_OPTION_WFT_MAX = cantp_parameter.PCANTP_PARAMETER_WFT_MAX,
///
/// 1 BYTE data to set optimization options to improve delay between ISO-TP consecutive frames.
///
PCANTP_OPTION_SELFRECEIVE_LATENCY = cantp_parameter.PCANTP_PARAMETER_SELFRECEIVE_LATENCY
}
///
/// Represents the status for a message whose transmission is in progress.
///
public enum cantp_msgprogress_state : UInt32
{
///
/// Message is not yet handled.
///
PCANTP_MSGPROGRESS_STATE_QUEUED = 0,
///
/// Message is being processed (received or transmitted).
///
PCANTP_MSGPROGRESS_STATE_PROCESSING = 1,
///
/// Message is completed.
///
PCANTP_MSGPROGRESS_STATE_COMPLETED = 2,
///
/// Message is unknown/not found.
///
PCANTP_MSGPROGRESS_STATE_UNKNOWN = 3
}
///
/// Represents the direction of a message's communication.
///
public enum cantp_msgdirection : UInt32
{
///
/// Message is being received.
///
PCANTP_MSGDIRECTION_RX = 0,
///
/// Message is being transmitted.
///
PCANTP_MSGDIRECTION_TX = 1,
}
#endregion
#region Structures
////////////////////////////////////////////////////////////
// miscellaneous message related definitions
////////////////////////////////////////////////////////////
///
/// Internal information about cantp_msg message (reserved).
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msginfo
{
///
/// (read-only) size of the message object
///
public UInt32 size;
///
/// (read-only) reserved
///
public cantp_msginfo_flag flags;
///
/// (read-only) reserved
///
public cantp_msginfo_extra extra;
}
///
/// Represents message's options to override.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgoption
{
///
/// Name of the option.
///
[MarshalAs(UnmanagedType.U4)]
public cantp_option name;
///
/// Value of the option.
///
public UInt32 value;
}
///
/// Represents a list of message's options to override.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgoption_list
{
///
/// Pointer to an array of cantp_msgoption.
/// Use it with unsafe { cantp_msgoption* opts = (cantp_msgoption*)buffer.ToPointer(); }
/// Or with Marshal.Copy, Marshal.ReadInt32, Marshal.WriteInt32
/// See special C# functions
///
public IntPtr buffer;
///
/// Number of options in the array.
///
public UInt32 count;
}
///
/// Represents common CAN information.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_can_info
{
///
/// CAN identifier
///
public UInt32 can_id;
///
/// Types and flags of the CAN/CAN-FD frame (see cantp_can_msgtype)
///
[MarshalAs(UnmanagedType.U4)]
public cantp_can_msgtype can_msgtype;
///
/// Data Length Code of the frame (0..15)
///
public byte dlc;
}
///
/// Represents the network address information of an ISO-TP message.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_netaddrinfo
{
///
/// ISO-TP message type
///
[MarshalAs(UnmanagedType.U4)]
public cantp_isotp_msgtype msgtype;
///
/// ISO-TP format addressing
///
[MarshalAs(UnmanagedType.U4)]
public cantp_isotp_format format;
///
/// ISO-TP addressing/target type
///
[MarshalAs(UnmanagedType.U4)]
public cantp_isotp_addressing target_type;
///
/// source address
///
public UInt16 source_addr;
///
/// target address
///
public UInt16 target_addr;
///
/// extension address
///
public byte extension_addr;
}
///
/// Represents a mapping between an ISO-TP network address information and a CAN ID.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_mapping
{
///
/// Mapping's unique ID
///
public UIntPtr uid;
///
/// CAN ID mapped to the Network Address Information
///
public UInt32 can_id;
///
/// CAN ID used for the flow control frame (formerly 'can_id_resp')
///
public UInt32 can_id_flow_ctrl;
///
/// CAN frame msgtype (only PCANTP_CAN_MSGTYPE_STANDARD or PCANTP_CAN_MSGTYPE_EXTENDED is mandatory)
///
[MarshalAs(UnmanagedType.U4)]
public cantp_can_msgtype can_msgtype;
///
/// Default CAN DLC value to use with segmented messages
///
public byte can_tx_dlc;
///
/// ISO-TP Network Address Information
///
public cantp_netaddrinfo netaddrinfo;
}
///
/// Represents a message rule for filtering.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgrule
{
///
/// Unique ID (read-only)
///
public UIntPtr uid;
///
/// Type of the message
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgtype type;
///
/// common CAN information
///
public cantp_can_info can_info;
///
/// ISO-TP network address information
///
public cantp_netaddrinfo netaddrinfo;
///
/// specific options to override global CAN configuration
///
public cantp_msgoption_list options;
///
/// reserved
///
public UIntPtr reserved;
}
////////////////////////////////////////////////////////////
// Message definitions
////////////////////////////////////////////////////////////
///
/// Represents the content of a generic message.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgdata
{
///
/// structure specific flags
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgflag flags;
///
/// Length of the message
///
public UInt32 length;
///
/// Data of the message
/// Array of bytes
/// Use it with unsafe { byte* don = (byte*)data.ToPointer(); }
/// or with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
/// See special C# functions
///
public IntPtr data;
///
/// Network status
///
[MarshalAs(UnmanagedType.U4)]
public cantp_netstatus netstatus;
///
/// Defines specific options to override global message configuration
/// Pointer to a cantp_msgoption_list
/// Use it with Marshal.PtrToStructure() and Marshal.StructureToPtr()
/// or with unsafe {options.toPointer()}
/// See special C# functions
///
public IntPtr options;
}
///
/// Represents the content of a standard CAN frame.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgdata_can
{
///
/// structure specific flags
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgflag flags;
///
/// Length of the message (0..8)
///
public UInt32 length;
///
/// Data of the message
/// Array of bytes
/// Use it with unsafe { byte* don = (byte*)data.ToPointer(); }
/// or with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
/// See special C# functions
///
public IntPtr data;
///
/// Network status
///
[MarshalAs(UnmanagedType.U4)]
public cantp_netstatus netstatus;
///
/// Defines specific options to override global CAN configuration (not used yet)
/// Pointer to a cantp_msgoption_list
/// Use it with Marshal.PtrToStructure() and Marshal.StructureToPtr()
/// or with unsafe {options.toPointer()}
/// See special C# functions
///
public IntPtr options;
///
/// Data of the message (DATA[0]..DATA[7])
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = CanTpApi.PCANTP_MAX_LENGTH_CAN_STANDARD)]
public byte[] data_max;
}
///
/// Represents the content of a CAN FD frame.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgdata_canfd
{
///
/// structure specific flags
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgflag flags;
///
/// Length of the message (0..64)
///
public UInt32 length;
///
/// Data of the message
/// Array of bytes
/// Use it with unsafe { byte* don = (byte*)data.ToPointer(); }
/// or with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
/// See special C# functions
///
public IntPtr data;
///
/// Network status
///
[MarshalAs(UnmanagedType.U4)]
public cantp_netstatus netstatus;
///
/// Defines specific options to override global CAN configuration (not used yet)
/// Pointer to a cantp_msgoption_list
/// Use it with Marshal.PtrToStructure() and Marshal.StructureToPtr()
/// or with unsafe {options.toPointer()}
/// See special C# functions
///
public IntPtr options;
///
/// Data of the message (DATA[0]..DATA[63])
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = CanTpApi.PCANTP_MAX_LENGTH_CAN_FD)]
public byte[] data_max;
}
///
/// Represents the content of an ISO-TP message.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgdata_isotp
{
///
/// structure specific flags
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgflag flags;
///
/// Length of the data
///
public UInt32 length;
///
/// Data of the message
/// Array of bytes
/// Use it with unsafe { byte* don = (byte*)data.ToPointer(); }
/// or with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
/// See special C# functions
///
public IntPtr data;
///
/// Network status
///
[MarshalAs(UnmanagedType.U4)]
public cantp_netstatus netstatus;
///
/// Defines specific options to override global CAN configuration
/// Pointer to a cantp_msgoption_list
/// Use it with Marshal.PtrToStructure() and Marshal.StructureToPtr()
/// or with unsafe {options.toPointer()}
/// See special C# functions
///
public IntPtr options;
///
/// ISO-TP network address information
///
public cantp_netaddrinfo netaddrinfo;
///
/// Reserved ISO-TP information
///
public cantp_isotp_info reserved;
}
///
/// A cantp_msg message is a generic CAN related message than can be either a standard CAN frame,
/// a CAN FD frame, an ISO-TP message, etc.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msg
{
///
/// type of the message
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgtype type;
///
/// misc. read-only information
///
public cantp_msginfo reserved;
///
/// common CAN information
///
public cantp_can_info can_info;
///
/// data of the message
/// pointer to different structures depending on the message type
/// Use it with following properties (Msgdata_any_Copy, Msgdata_can_copy etc.)
/// Or with Marshal.PtrToStructure and Marshal.StructureToPtr
/// Or with unsafe {msgdata.ToPointer()}
/// See special C# functions
///
private IntPtr msgdata;
///
/// get msgdata field as a property
///
public IntPtr Msgdata
{
get { return msgdata; }
}
///
/// get msgdata field as a cantp_msgdata property
/// The fields of this property will not be writable except (not directly) those whose type is "IntPtr".
/// Before using this property, check if msgdata is not IntPtr.Zero
///
public cantp_msgdata Msgdata_any_Copy
{
get
{
return (cantp_msgdata)Marshal.PtrToStructure(msgdata, typeof(cantp_msgdata));
}
}
///
/// get msgdata field as a cantp_msgdata_can property
/// The fields of this property will not be writable except (not directly) those whose type is "IntPtr".
/// Before using this property, check if msgdata is not IntPtr.Zero
///
public cantp_msgdata_can Msgdata_can_Copy
{
get
{
return (cantp_msgdata_can)Marshal.PtrToStructure(msgdata, typeof(cantp_msgdata_can));
}
}
///
/// get msgdata field as a cantp_msgdata_canfd property
/// The fields of this property will not be writable except (not directly) those whose type is "IntPtr".
/// Before using this property, check if msgdata is not IntPtr.Zero
///
public cantp_msgdata_canfd Msgdata_canfd_Copy
{
get
{
return (cantp_msgdata_canfd)Marshal.PtrToStructure(msgdata, typeof(cantp_msgdata_canfd));
}
}
///
/// get msgdata field as a cantp_msgdata_isotp property
/// The fields of this property will not be writable except (not directly) those whose type is "IntPtr".
/// Before using this property, check if msgdata is not IntPtr.Zero
///
public cantp_msgdata_isotp Msgdata_isotp_Copy
{
get
{
return (cantp_msgdata_isotp)Marshal.PtrToStructure(msgdata, typeof(cantp_msgdata_isotp));
}
}
#if (UNSAFE)
///
/// get the msgdata field as a pointer to cantp_msgdata
/// all fields of this property will be writable (in unsafe mode) since it is a pointer.
/// Before using this property, check if msgdata is not IntPtr.Zero
///
public unsafe cantp_msgdata* Msgdata_any
{
get
{
cantp_msgdata* str = (cantp_msgdata*)msgdata.ToPointer();
return str;
}
}
///
/// get the msgdata field as a pointer to cantp_msgdata_isotp
/// all fields of this property will be writable (in unsafe mode) since it is a pointer.
/// Before using this property, check if msgdata is not IntPtr.Zero
///
public unsafe cantp_msgdata_isotp* Msgdata_isotp
{
get
{
cantp_msgdata_isotp* str = (cantp_msgdata_isotp*)msgdata.ToPointer();
return str;
}
}
#endif
}
///
/// Holds information on the communication progress of a message.
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct cantp_msgprogress
{
///
/// State of the message
///
[MarshalAs(UnmanagedType.U4)]
public cantp_msgprogress_state state;
///
/// Progress of the transmission/reception in percent.
///
public byte percentage;
///
/// Buffer to get a copy of the pending message.
/// Pointer to a cantp_msg
/// If this is not needed, set it to IntPtr.Zero.
/// If this is needed, set it with unsafe { buffer = IntPtr(&msg);}
/// Use it in read-only mode with cantp_msg mp = (cantp_msg)Marshal.PtrToStructure(buffer, typeof(cantp_msg));
/// or with unsafe {(cantp_msg*)buffer.toPointer();}
/// See special C# functions
///
public IntPtr buffer;
}
#endregion
#region PCANTP Api
public static partial class CanTpApi
{
#region bitrate
// Represents the configuration for a CAN bit rate
// Note:
// * Each parameter and its value must be separated with a '='.
// * Each pair of parameter/value must be separated using ','.
//
// Example:
// f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
//
public const string PCANTP_BITRATE_CLOCK = PCANBasic.PCAN_BR_CLOCK;
public const string PCANTP_BITRATE_CLOCK_MHZ = PCANBasic.PCAN_BR_CLOCK_MHZ;
public const string PCANTP_BITRATE_NOM_BRP = PCANBasic.PCAN_BR_NOM_BRP;
public const string PCANTP_BITRATE_NOM_TSEG1 = PCANBasic.PCAN_BR_NOM_TSEG1;
public const string PCANTP_BITRATE_NOM_TSEG2 = PCANBasic.PCAN_BR_NOM_TSEG2;
public const string PCANTP_BITRATE_NOM_SJW = PCANBasic.PCAN_BR_NOM_SJW;
public const string PCANTP_BITRATE_NOM_SAMPLE = PCANBasic.PCAN_BR_NOM_SAMPLE;
public const string PCANTP_BITRATE_DATA_BRP = PCANBasic.PCAN_BR_DATA_BRP;
public const string PCANTP_BITRATE_DATA_TSEG1 = PCANBasic.PCAN_BR_DATA_TSEG1;
public const string PCANTP_BITRATE_DATA_TSEG2 = PCANBasic.PCAN_BR_DATA_TSEG2;
public const string PCANTP_BITRATE_DATA_SJW = PCANBasic.PCAN_BR_DATA_SJW;
public const string PCANTP_BITRATE_DATA_SAMPLE = PCANBasic.PCAN_BR_DATA_SAMPLE;
#endregion
#region PCANTP parameter values
public const byte PCANTP_VALUE_PARAMETER_OFF = PCANBasic.PCAN_PARAMETER_OFF;
public const byte PCANTP_VALUE_PARAMETER_ON = PCANBasic.PCAN_PARAMETER_ON;
///
/// Enable debug messages (only notices, informations, warnings, errors)
///
public const byte PCANTP_DEBUG_NOTICE = 0xF4;
///
/// Enable debug messages (only informations, warnings, errors)
///
public const byte PCANTP_DEBUG_INFO = 0xF3;
///
/// Enable debug messages (only warnings, errors)
///
public const byte PCANTP_DEBUG_WARNING = 0xF2;
///
/// Enable debug messages (only errors)
///
public const byte PCANTP_DEBUG_ERROR = 0xF1;
#if (!PCANTP_API_COMPATIBILITY_ISO_2004)
///
/// No debug messages
///
public const byte PCANTP_DEBUG_NONE = 0x00;
///
/// Puts CAN debug messages to stdout
///
public const byte PCANTP_DEBUG_CAN = 0x01;
///
/// The Channel is illegal or not available
///
public const byte PCANTP_CHANNEL_UNAVAILABLE = 0x00;
///
/// The Channel is available
///
public const byte PCANTP_CHANNEL_AVAILABLE = 0x01;
///
/// The Channel is valid, and is being used
///
public const byte PCANTP_CHANNEL_OCCUPIED = 0x02;
///
/// if set Flow Control frame shall not use the WT flow status value
///
public const byte PCANTP_WFT_MAX_UNLIMITED = 0x00;
///
/// an integer describing the Wait Frame Transmissions parameter.
///
public const byte PCANTP_WFT_MAX_DEFAULT = 0x10;
///
/// hide messages with type PCANTP_MESSAGE_INDICATION from CANTP_Read function
///
public const byte PCANTP_MSG_PENDING_HIDE = 0x00;
///
/// show messages with type PCANTP_MESSAGE_INDICATION from CANTP_Read function
///
public const byte PCANTP_MSG_PENDING_SHOW = 0x01;
///
/// uses CAN frame data optimization
///
public const byte PCANTP_CAN_DATA_PADDING_NONE = 0x00;
///
/// uses CAN frame data padding (default, i.e. CAN DLC = 8)
///
public const byte PCANTP_CAN_DATA_PADDING_ON = 0x01;
///
/// default value used if CAN data padding is enabled
///
public const byte PCANTP_CAN_DATA_PADDING_VALUE = 0x55;
#endif
///
/// disable reception of unformatted (NON-ISO-TP) CAN frames (default)
/// only ISO 15765 messages will be received
///
public const byte PCANTP_FRAME_FILTERING_ISOTP = 0x00;
///
/// enable reception of unformatted (NON-ISO-TP) CAN frames
/// received messages will be treated as either ISO 15765 or as an unformatted CAN frame
///
public const byte PCANTP_FRAME_FILTERING_CAN = 0x01;
///
/// enable reception of unformatted (NON-ISO-TP) CAN frames
/// received messages will be treated as ISO 15765, unformatted CAN frame, or both (user will able to read fragmented CAN frames)
///
public const byte PCANTP_FRAME_FILTERING_VERBOSE = 0x02;
#if (!PCANTP_API_COMPATIBILITY_ISO_2004)
///
/// default priority for ISO-TP messages (only available fot normal fixed, mixed and enhanced addressing)
///
public const byte PCANTP_J1939_PRIORITY_DEFAULT = 0x06;
#endif
///
/// maximum size of a CAN (non-FD) frame (8)
///
public const byte PCANTP_MAX_LENGTH_CAN_STANDARD = 0x08;
///
/// maximum size of a CAN FD frame (64)
///
public const byte PCANTP_MAX_LENGTH_CAN_FD = 0x40;
///
/// maximum size of an ISO-TP rev. 2004 frame (4095)
///
public const UInt32 PCANTP_MAX_LENGTH_ISOTP2004 = 0xFFF;
///
/// maximum size of an ISO-TP rev. 2016 frame (4294967295)
///
public const UInt32 PCANTP_MAX_LENGTH_ISOTP2016 = 0xFFFFFFFF;
///
/// maximum size before using virtual allocation for ISO-TP messages
///
public const UInt32 PCANTP_MAX_LENGTH_ALLOC = 0xFFFFFFU;
///
/// default DLC for fragmented frames when transmiting ISO-TP messages
///
public const byte PCANTP_CAN_TX_DL_DEFAULT = PCANTP_MAX_LENGTH_CAN_STANDARD;
///
/// ISO-15765-2:2004(E)
///
public const byte PCANTP_ISO_REV_2004 = 0x01;
///
/// ISO-15765-2:2016(E)
///
public const byte PCANTP_ISO_REV_2016 = 0x02;
///
/// disables the feature "ignore received BlockSize value"
///
public const UInt32 PCANTP_BLOCK_SIZE_TX_IGNORE = 0xFFFF;
///
/// disables the feature "ignore received STMin value"
///
public const UInt32 PCANTP_SEPERATION_TIME_TX_IGNORE = 0xFFFF;
///
/// sets timeouts according to ISO-15765-2
///
public const byte PCANTP_ISO_TIMEOUTS_15765_2 = 0;
///
/// sets timeouts according to ISO-15765-4 (OBDII)
///
public const byte PCANTP_ISO_TIMEOUTS_15765_4 = 1;
///
/// no optimization (use this parameter if ECU requires strict respect of Minimum Separation Time)
///
public const byte PCANTP_SELFRECEIVE_LATENCY_NONE = 0;
///
/// (DEFAULT) fragmented self-receive frame mechanism is ignored when STmin is set to = 0xF3 and lower (<300µs)
///
public const byte PCANTP_SELFRECEIVE_LATENCY_LIGHT = 1;
///
/// as LIGHT value plus optimize self-receive latency by predicting the time to effectively write frames on bus
///
public const byte PCANTP_SELFRECEIVE_LATENCY_OPTIMIZED = 2;
///
/// (DEFAULT) maxinum number of items in the receive queue
///
public const UInt32 PCANTP_MAX_RX_QUEUE_DEFAULT = 32767;
///
/// (DEFAULT) Network layer design is full-duplex
///
public const byte PCANTP_NETWORK_LAYER_FULL_DUPLEX = 0;
///
/// Network layer design is half-duplex (only one transmission/reception of the same NAI at a time)
///
public const byte PCANTP_NETWORK_LAYER_HALF_DUPLEX = 1;
// Standard ISO-15765-2 values
///
/// Default value for Separation time
///
public const byte PCANTP_STMIN_ISO_15765_2 = 10;
///
/// Default value for BlockSize
///
public const byte PCANTP_BS_ISO_15765_2 = 10;
///
/// Default value for Timeout Ar in µs
///
public const UInt32 PCANTP_TIMEOUT_AR_ISO_15765_2 = (1000 * 1000);
///
/// Default value for Timeout As in µs
///
public const UInt32 PCANTP_TIMEOUT_AS_ISO_15765_2 = (1000 * 1000);
///
/// Default value for Timeout Br in µs
///
public const UInt32 PCANTP_TIMEOUT_BR_ISO_15765_2 = (1000 * 1000);
///
/// Default value for Timeout Bs in µs
///
public const UInt32 PCANTP_TIMEOUT_BS_ISO_15765_2 = (1000 * 1000);
///
/// Default value for Timeout Cr in µs
///
public const UInt32 PCANTP_TIMEOUT_CR_ISO_15765_2 = (1000 * 1000);
///
/// Default value for Timeout Cs in µs
///
public const UInt32 PCANTP_TIMEOUT_CS_ISO_15765_2 = (1000 * 1000);
///
/// Default value for timeout tolerance [0..100] (timeout = t * (1 + tolerance/100))
///
public const byte PCANTP_TIMEOUT_TOLERANCE = 0;
// Standard ISO-15765-4 (OBDII) values
///
/// OBDII value for Separation time
///
public const byte PCANTP_STMIN_ISO_15765_4 = 0;
///
/// OBDII value for BlockSize
///
public const byte PCANTP_BS_ISO_15765_4 = 0;
///
/// OBDII value for Timeout Ar in µs
///
public const UInt32 PCANTP_TIMEOUT_AR_ISO_15765_4 = (1000 * 25);
///
/// OBDII value for Timeout As in µs
///
public const UInt32 PCANTP_TIMEOUT_AS_ISO_15765_4 = (1000 * 25);
///
/// OBDII value for Timeout Br in µs
///
public const UInt32 PCANTP_TIMEOUT_BR_ISO_15765_4 = (1000 * 75);
///
/// OBDII value for Timeout Bs in µs
///
public const UInt32 PCANTP_TIMEOUT_BS_ISO_15765_4 = (1000 * 75);
///
/// OBDII value for Timeout Cr in µs
///
public const UInt32 PCANTP_TIMEOUT_CR_ISO_15765_4 = (1000 * 150);
///
/// OBDII value for Timeout Cs in µs
///
public const UInt32 PCANTP_TIMEOUT_CS_ISO_15765_4 = (1000 * 150);
// Values for cfg_value
///
/// Mask for the 29bits ISOTP priority value (stored in bits [0..2])
///
public const byte PCANTP_FLAG_MASK_PRIORITY = 0x07;
///
/// Padding is enabled
///
public const byte PCANTP_FLAG_PADDING_ON = 0x08;
///
/// Message's indication is enabled
///
public const byte PCANTP_FLAG_INDICATION_ON = 0x10;
///
/// Echo of fragmented frames is enabled
///
public const byte PCANTP_FLAG_ECHO_FRAMES_ON = 0x20;
#endregion
#region constants
////////////////////////////////////////////////////////////
// Constants definition
////////////////////////////////////////////////////////////
///
/// Mapping does not require a Flow Control frame.
///
public const UInt32 PCANTP_MAPPING_FLOW_CTRL_NONE = 0xFFFFFFFF;
#endregion
#region PCAN ISO-TP API Implementation
///
/// Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
///
/// Only one PCANTP-Client can be initialized per CAN-Channel
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The CAN Hardware speed
/// NON PLUG-N-PLAY: The type of hardware and operation mode
/// NON PLUG-N-PLAY: The I/O address for the parallel port
/// NON PLUG-N-PLAY: Interrupt number of the parallel port
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_Initialize_2016")]
public static extern cantp_status Initialize_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_baudrate baudrate,
[MarshalAs(UnmanagedType.U4)]
cantp_hwtype hw_type,
UInt32 io_port,
UInt16 interrupt);
///
/// Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
///
/// Only one PCANTP-Client can be initialized per CAN-Channel
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The CAN Hardware speed
/// NON PLUG-N-PLAY: The type of hardware and operation mode
/// NON PLUG-N-PLAY: The I/O address for the parallel port
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
public static cantp_status Initialize_2016(
cantp_handle channel,
cantp_baudrate baudrate,
cantp_hwtype hw_type,
UInt32 io_port)
{
return Initialize_2016(channel, baudrate, hw_type, io_port, 0);
}
///
/// Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
///
/// Only one PCANTP-Client can be initialized per CAN-Channel
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The CAN Hardware speed
/// NON PLUG-N-PLAY: The type of hardware and operation mode
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
public static cantp_status Initialize_2016(
cantp_handle channel,
cantp_baudrate baudrate,
cantp_hwtype hw_type)
{
return Initialize_2016(channel, baudrate, hw_type, 0, 0);
}
///
/// Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
///
/// Only one PCANTP-Client can be initialized per CAN-Channel
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The CAN Hardware speed
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
public static cantp_status Initialize_2016(
cantp_handle channel,
cantp_baudrate baudrate)
{
return Initialize_2016(channel, baudrate, (cantp_hwtype)0, 0, 0);
}
///
/// Initializes a PCANTP-Client based on a CANTP Channel (including CAN-FD support)
///
/// "The handle of a FD capable PCAN Channel"
/// "The speed for the communication (FD bit rate string)"
/// Only one PCANTP-Client can be initialized per CAN-Channel.
/// See PCAN_BR_* values
/// * Parameter and values must be separated by '='
/// * Couples of Parameter/value must be separated by ','
/// * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
/// nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
/// * Following Parameters are optional (not used yet): data_ssp_offset, nom_samp
///
/// f_clock_mhz=80,nom_brp=0,nom_tseg1=13,nom_tseg2=0,nom_sjw=0,data_brp=0,
/// data_tseg1=13,data_tseg2=0,data_sjw=0
/// "A cantp_status code"
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_InitializeFD_2016")]
public static extern cantp_status InitializeFD_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.LPStr)]
cantp_bitrate bitrate_fd);
///
/// Uninitializes a PCANTP-Client initialized before
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_Uninitialize_2016")]
public static extern cantp_status Uninitialize_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel);
///
/// Resets the receive and transmit queues of a PCANTP-Client
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_Reset_2016")]
public static extern cantp_status Reset_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel);
///
/// Gets information about the internal BUS status of a PCANTP-Channel.
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetCanBusStatus_2016")]
public static extern cantp_status GetCanBusStatus_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel);
///
/// Reads a PCANTP message from the receive queue of a PCANTP-Client
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_msg structure buffer to store the PUDS message
/// A cantp_timestamp structure buffer to get
/// the reception time of the message.
/// A cantp_msgtype structure buffer to filter the message to read.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_Read_2016")]
public static extern cantp_status Read_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
out cantp_msg msg_buffer,
out cantp_timestamp timestamp_buffer,
[MarshalAs(UnmanagedType.U4)]
cantp_msgtype msg_type);
///
/// Reads a PCANTP message from the receive queue of a PCANTP-Client
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_msg structure buffer to store the PUDS message
/// A cantp_timestamp structure buffer to get
/// the reception time of the message.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
public static cantp_status Read_2016(
cantp_handle channel,
out cantp_msg msg_buffer,
out cantp_timestamp timestamp_buffer)
{
return Read_2016(channel, out msg_buffer, out timestamp_buffer, cantp_msgtype.PCANTP_MSGTYPE_ANY);
}
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_Read_2016")]
private static extern cantp_status Read_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
out cantp_msg msg_buffer,
IntPtr timestamp_buffer,
[MarshalAs(UnmanagedType.U4)]
cantp_msgtype msg_type);
///
/// Reads a PCANTP message from the receive queue of a PCANTP-Client
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_msg structure buffer to store the PUDS message
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
public static cantp_status Read_2016(
cantp_handle channel,
out cantp_msg msg_buffer)
{
return Read_2016(channel, out msg_buffer, IntPtr.Zero, cantp_msgtype.PCANTP_MSGTYPE_ANY);
}
///
/// Gets progress information on a specific message
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_msg structure buffer matching the message to look for
/// The expected direction (incoming/outgoing) of the message
/// A cantp_msgprogress structure buffer to store the progress information
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetMsgProgress_2016")]
public static extern cantp_status GetMsgProgress_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[In]ref cantp_msg msg_buffer,
[MarshalAs(UnmanagedType.U4)]
cantp_msgdirection direction,
out cantp_msgprogress msgprogress_buffer);
///
/// Adds a PCANTP message to the Transmit queue
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A cantp_msg buffer with the message to be sent
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_Write_2016")]
public static extern cantp_status Write_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
ref cantp_msg msg_buffer);
///
/// Retrieves a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to get
/// Buffer for the parameter value
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetValue_2016")]
public static extern cantp_status GetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
StringBuilder StringBuffer,
UInt32 BufferLength);
///
/// Retrieves a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to get
/// Buffer for the parameter value
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetValue_2016")]
public static extern cantp_status GetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
out UInt32 NumericBuffer,
UInt32 BufferLength);
///
/// Retrieves a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to get
/// Buffer for the parameter value
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetValue_2016")]
public static extern cantp_status GetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
[MarshalAs(UnmanagedType.LPArray)]
[Out] Byte[] Buffer,
UInt32 BufferLength);
///
/// Retrieves a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to get
/// Buffer for the parameter value
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetValue_2016")]
public static extern cantp_status GetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
out UInt64 NumericBuffer,
UInt32 BufferLength);
///
/// Configures or sets a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to set
/// Buffer with the value to be set
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_SetValue_2016")]
public static extern cantp_status SetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
ref UInt32 NumericBuffer,
UInt32 BufferLength);
///
/// Configures or sets a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to set
/// Buffer with the value to be set
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_SetValue_2016")]
public static extern cantp_status SetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
ref UInt64 NumericBuffer,
UInt32 BufferLength);
///
/// Configures or sets a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to set
/// Buffer with the value to be set
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_SetValue_2016")]
public static extern cantp_status SetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
[MarshalAs(UnmanagedType.LPStr, SizeParamIndex = 3)]
string StringBuffer,
UInt32 BufferLength);
///
/// Configures or sets a PCANTP-Client value
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The cantp_parameter parameter to set
/// Buffer with the value to be set
/// Size in bytes of the buffer
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_SetValue_2016")]
public static extern cantp_status SetValue_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.U4)]
cantp_parameter parameter,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)]
Byte[] Buffer,
UInt32 BufferLength);
///
/// Adds a user-defined PCAN-TP mapping between CAN ID and Network Address Information
///
///
/// Defining a mapping enables ISO-TP communication with 11BITS CAN ID or
/// with opened Addressing Formats (like PCANTP_ISOTP_FORMAT_NORMAL or PCANTP_ISOTP_FORMAT_EXTENDED).
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// Buffer to the mapping to be added
/// A cantp_status code : PCANTP_STATUS_OK is returned on success,
/// PCANTP_STATUS_WRONG_PARAM states invalid Network Address Information parameters.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_AddMapping_2016")]
public static extern cantp_status AddMapping_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
ref cantp_mapping mapping);
///
/// Removes all user-defined PCAN-TP mappings corresponding to a CAN ID
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The mapped CAN ID to search for
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_RemoveMappings_2016")]
public static extern cantp_status RemoveMappings_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
UInt32 can_id);
///
/// Removes a user-defined PCAN-TP mapping between a CAN ID and Network Address Information
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The identifier of the mapping
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_RemoveMapping_2016")]
public static extern cantp_status RemoveMapping_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
UIntPtr uid);
///
/// Retrieves all the mappings defined for a PCAN-TP channel
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// A buffer to store an array of cantp_mapping
/// [In]The number of cantp_mapping element the buffer can store. of the mapping.
/// [Out]The actual number of element copied in the buffer.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success,
/// PCANTP_STATUS_PARAM_BUFFER_TOO_SMALL if the number of mappings exceeds buffer_length.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetMappings_2016")]
public static extern cantp_status GetMappings_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
[Out] cantp_mapping[] buffer,
ref UInt32 buffer_length);
///
/// Adds an entry to the CAN-ID white-list filtering.
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The lowest CAN ID wanted to be received
/// The highest CAN ID wanted to be received
/// States if filter should check the CAN message type.
/// If ignore_can_msgtype is false, the value states which types of CAN frame should be allowed.
/// A cantp_status code : PCANTP_STATUS_OK is returned on success, and PCANTP_STATUS_ALREADY_INITIALIZED otherwise.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_AddFiltering_2016")]
public static extern cantp_status AddFiltering_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
UInt32 can_id_from,
UInt32 can_id_to,
[MarshalAs(UnmanagedType.U1)]
bool ignore_can_msgtype,
[MarshalAs(UnmanagedType.U4)]
cantp_can_msgtype can_msgtype);
///
/// Removes an entry from the CAN-ID white-list filtering.
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The lowest CAN ID wanted to be removed
/// The highest CAN ID wanted to be removed
/// States if filter should check the CAN message type.
/// If ignore_can_msgtype is false, the value states which types of CAN frame should be allowed.
/// A cantp_status code : PCANTP_STATUS_OK is returned on success, and PCANTP_STATUS_ALREADY_INITIALIZED otherwise.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_RemoveFiltering_2016")]
public static extern cantp_status RemoveFiltering_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
UInt32 can_id_from,
UInt32 can_id_to,
[MarshalAs(UnmanagedType.U1)]
bool ignore_can_msgtype,
[MarshalAs(UnmanagedType.U4)]
cantp_can_msgtype can_msgtype);
///
/// Adds an entry to the message's rules.
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The rule to insert.
/// A cantp_status code : PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_AddMsgRule_2016")]
public static extern cantp_status AddMsgRule_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
ref cantp_msgrule msgrule);
///
/// Removes an entry from the message's rules.
///
/// A PCANTP Channel Handle representing a PCANTP-Client
/// The unique ID of the rule to remove.
/// A cantp_status code : PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_RemoveMsgRule_2016")]
public static extern cantp_status RemoveMsgRule_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_handle channel,
UIntPtr uid);
///
/// Returns a descriptive text of a given cantp_status error
/// code, in any desired language
///
/// The current languages available for translation are:
/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
/// Italian (0x10) and French (0x0C)
/// A cantp_status error code
/// Indicates a 'Primary language ID'
/// Buffer for a null terminated char array
/// Buffer size
/// A cantp_status error code
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_GetErrorText_2016")]
public static extern cantp_status GetErrorText_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_status error,
UInt16 language,
StringBuilder StringBuffer,
UInt32 bufferSize);
///
/// Allocates a PCAN-TP message based on the given type
///
/// A cantp_msg structure buffer (it will be freed if required)
/// Type of the message to allocate
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgDataAlloc_2016")]
public static extern cantp_status MsgDataAlloc_2016(
out cantp_msg msg_buffer,
[MarshalAs(UnmanagedType.U4)]
cantp_msgtype type);
///
/// Initializes an allocated PCAN-TP message
///
/// An allocated cantp_msg structure buffer
/// CAN identifier (ISO-TP message may ignore this parameter and use PCANTP_MAPPING_FLOW_CTRL_NONE (-1))
/// Combination of CAN message types (like "extended CAN ID", "FD", "RTR", etc. flags)
/// Length of the data
/// A buffer to initialize the message's data with. If NULL, message's data is initialized with zeros.
/// Network address information of the ISO-TP message (only valid with an ISO-TP message)
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgDataInit_2016")]
public static extern cantp_status MsgDataInit_2016(
out cantp_msg msg_buffer,
UInt32 can_id,
[MarshalAs(UnmanagedType.U4)]
cantp_can_msgtype can_msgtype,
UInt32 data_length,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)]
Byte[] data,
ref cantp_netaddrinfo netaddrinfo);
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgDataInit_2016")]
private static extern cantp_status MsgDataInit_2016(
out cantp_msg msg_buffer,
UInt32 can_id,
[MarshalAs(UnmanagedType.U4)]
cantp_can_msgtype can_msgtype,
UInt32 data_length,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)]
Byte[] data,
IntPtr netaddrinfo);
///
/// Initializes an allocated PCAN-TP message
///
/// An allocated cantp_msg structure buffer
/// CAN identifier (ISO-TP message may ignore this parameter and use PCANTP_MAPPING_FLOW_CTRL_NONE (-1))
/// Combination of CAN message types (like "extended CAN ID", "FD", "RTR", etc. flags)
/// Length of the data
/// A buffer to initialize the message's data with. If NULL, message's data is initialized with zeros.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
public static cantp_status MsgDataInit_2016(
out cantp_msg msg_buffer,
UInt32 can_id,
cantp_can_msgtype can_msgtype,
UInt32 data_length,
Byte[] data)
{
return MsgDataInit_2016(out msg_buffer, can_id, can_msgtype, data_length, data, IntPtr.Zero);
}
///
/// Initializes a number of options for the PCAN-TP message that will override the channel's parameter(s)
///
/// An allocated cantp_msg structure buffer.
/// Number of options to initialize.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgDataInitOptions_2016")]
public static extern cantp_status MsgDataInitOptions_2016(
out cantp_msg msg_buffer,
UInt32 nb_options);
///
/// Deallocates a PCAN-TP message
///
/// An allocated cantp_msg structure buffer.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgDataFree_2016")]
public static extern cantp_status MsgDataFree_2016(
ref cantp_msg msg_buffer);
///
/// Checks if two PCAN-TP messages are equal.
/// If one message is the indication of an incoming/outgoing ISO-TP message, the actual data-content will not be compared.
/// In that case the function checks if the messages' network address information matches.
///
/// A cantp_msg structure buffer.
/// Another cantp_msg structure buffer to compare with first parameter.
/// States if comparison should ignore loopback flag
/// (i.e if true the function will return true when comparing a request and its loopback confirmation).
/// A boolean stating if the cantp_msgs are equal.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgEqual_2016")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool MsgEqual_2016(
[In]ref cantp_msg msg_buffer1,
[In]ref cantp_msg msg_buffer2,
[MarshalAs(UnmanagedType.I1)]
bool ignoreSelfReceiveFlag);
///
/// Copies a PCAN-TP message to another buffer.
///
/// A cantp_msg structure buffer to store the copied message.
/// The cantp_msg structure buffer used as the source.
/// A cantp_status code. PCANTP_STATUS_OK is returned on success
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgCopy_2016")]
public static extern cantp_status MsgCopy_2016(
out cantp_msg msg_buffer_dst,
[In]ref cantp_msg msg_buffer_src);
///
/// Converts a CAN DLC to its corresponding length.
///
/// The Data Length Code (DLC) to convert.
/// The corresponding length of the dlc parameter.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgDlcToLength_2016")]
public static extern UInt32 MsgDlcToLength_2016(
byte dlc);
///
/// Converts a data length to a corresponding CAN DLC.
/// Note: the returned DLC can hold more data that the requested length.
///
/// The length to convert.
/// The smallest DLC that can hold the requested length (0x00-0x0F).
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_MsgLengthToDlc_2016")]
public static extern byte MsgLengthToDlc_2016(
UInt32 length);
///
/// Lists the subtypes contained in the PCAN-TP status.
///
/// The status to analyze.
/// An aggregation of cantp_statustype values.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_StatusListTypes_2016")]
public static extern cantp_statustype StatusListTypes_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_status status);
///
/// Retrieves the value of a cantp_status subtype (like cantp_errstatus, cantp_busstatus, etc.).
///
/// The status to analyze.
/// The type of status to filter.
/// The value of the enumeration matching the requested type.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_StatusGet_2016")]
public static extern UInt32 StatusGet_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_status status,
[MarshalAs(UnmanagedType.U4)]
cantp_statustype type);
///
/// Checks if a status matches an expected result.
///
/// The status to analyze.
/// The expected status.
/// Enable strict mode. Strict mode ensures that bus or extra information are the same.
/// Returns true if the status matches expected parameter.
[DllImport("PCAN-ISO-TP.dll", EntryPoint = "CANTP_StatusIsOk_2016")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool StatusIsOk_2016(
[MarshalAs(UnmanagedType.U4)]
cantp_status status,
[MarshalAs(UnmanagedType.U4)]
cantp_status status_expected,
[MarshalAs(UnmanagedType.I1)]
bool strict);
///
/// Checks if a status matches an expected result in non-strict mode.
/// (Strict mode ensures that bus or extra information are the same)
///
/// The status to analyze.
/// The expected status.
/// Returns true if the status matches expected parameter.
public static bool StatusIsOk_2016(
cantp_status status,
cantp_status status_expected
)
{
return StatusIsOk_2016(status, status_expected, false);
}
///
/// Checks if a status matches PCANTP_STATUS_OK in non-strict mode.
/// (Strict mode ensures that bus or extra information are the same)
///
/// The status to analyze.
/// Returns true if the status matches expected parameter.
public static bool StatusIsOk_2016(
cantp_status status
)
{
return StatusIsOk_2016(status, cantp_status.PCANTP_STATUS_OK, false);
}
#region special C# functions, examples of how to use the structures IntPtr fields in safe mode, with Marshaling operations
///
/// Get an option value of an option list
///
/// option list
/// number of the option
/// where to store a copy of the option
/// true if ok, false if not ok
private static bool getOption_2016(ref cantp_msgoption_list l, int number, out cantp_msgoption option)
{
option = new cantp_msgoption();
if (number < l.count && l.buffer != IntPtr.Zero)
{
option.name = (cantp_option)Marshal.ReadInt32(l.buffer, number * 8);
option.value = (UInt32)Marshal.ReadInt32(l.buffer, number * 8 + 4);
return true;
}
return false;
}
///
/// Modifies an option
///
/// option list
/// number of the option
/// value to set to the option
/// true if ok, false if not ok
private static bool setOption_2016(ref cantp_msgoption_list l, int number, ref cantp_msgoption option)
{
if (number < l.count && l.buffer != IntPtr.Zero)
{
Marshal.WriteInt32(l.buffer, number * 8, (Int32)option.name);
Marshal.WriteInt32(l.buffer, number * 8 + 4, (Int32)option.value);
return true;
}
return false;
}
///
/// in a progress structure, allocate a buffer to receive a copy of the pending message.
/// when finished, must be released with freeProgressBuffer_2016()
///
/// progress structure
/// type of the pending message
/// resulting status
public static cantp_status allocProgressBuffer_2016(ref cantp_msgprogress prog, cantp_msgtype type)
{
cantp_msg pendingMsg;
cantp_status status = CanTpApi.MsgDataAlloc_2016(out pendingMsg, type);
if (status == cantp_status.PCANTP_STATUS_OK)
{
try
{
// Initialize unmanaged memory to hold the struct.
prog.buffer = Marshal.AllocHGlobal(Marshal.SizeOf(pendingMsg));
}
catch
{
prog.buffer = IntPtr.Zero;
}
if (prog.buffer != IntPtr.Zero)
Marshal.StructureToPtr(pendingMsg, prog.buffer, true);
else
status = cantp_status.PCANTP_STATUS_NO_MEMORY;
}
return status;
}
///
/// free the buffer receiving the pending message in a progress object,
/// if allocated with allocProgressBuffer_2016()
///
/// progress object
public static void freeProgressBuffer_2016(ref cantp_msgprogress prog)
{
// Free unmanaged memory holding the struct.
if (prog.buffer != IntPtr.Zero)
{
Marshal.FreeHGlobal(prog.buffer);
prog.buffer = IntPtr.Zero;
}
}
///
/// get the current pending message of a progress structure.
///
/// progress structure
/// pending message
/// true if ok, false if not ok
public static bool getProgressBuffer_2016(ref cantp_msgprogress prog, ref cantp_msg pendmsg)
{
if (prog.buffer != IntPtr.Zero)
{
pendmsg = (cantp_msg)Marshal.PtrToStructure(prog.buffer, typeof(cantp_msg));
return true;
}
return false;
}
///
/// get the flags of a message
///
/// Message structure
/// value of the flags
/// true if ok, false if not ok
public static bool getFlags_2016(ref cantp_msg msg, out cantp_msgflag flags)
{
if (msg.Msgdata != IntPtr.Zero)
{
flags = msg.Msgdata_any_Copy.flags;
return true;
}
flags = cantp_msgflag.PCANTP_MSGFLAG_NONE;
return false;
}
///
/// set the length of a message
/// use carefully
///
/// value to set
/// true if ok, false if not ok
public static bool setLength_2016(ref cantp_msg msg, UInt32 len)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = (cantp_msgdata)Marshal.PtrToStructure(msg.Msgdata, typeof(cantp_msgdata));
msgdata.length = len;
Marshal.StructureToPtr(msgdata, msg.Msgdata, true);
return true;
}
return false;
}
///
/// get the length of a message
///
/// Message structure
/// value of the length
/// true if ok, false if not ok
public static bool getLength_2016(ref cantp_msg msg, out UInt32 len)
{
if (msg.Msgdata != IntPtr.Zero)
{
len = msg.Msgdata_any_Copy.length;
return true;
}
len = 0;
return false;
}
///
/// set a byte of the data of a message
///
/// Message structure to modify.
/// offset of the byte, cannot be more than 2147483647
/// value to set
/// true if ok, false if not ok
public static bool setData_2016(ref cantp_msg msg, Int32 i, byte val)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.length > 0 && msgdata.data != IntPtr.Zero && i >= 0 && i < msgdata.length)
{
Marshal.WriteByte(msgdata.data, i, val);
return true;
}
}
return false;
}
///
/// set bytes of the data of a message from a contiguous byte array
///
/// Message structure to modify.
/// offset of the first byte in the message, cannot be more than 2147483647
/// number of bytes
/// values to set, from offset 0
/// true if ok, false if not ok
public static bool setData_2016(ref cantp_msg msg, Int32 i, byte[] vals, Int32 nb)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.length > 0 && msgdata.data != IntPtr.Zero && i >= 0 && i + nb - 1 < msgdata.length && vals.Length >= nb)
{
if (i == 0)
{
Marshal.Copy(vals, 0, msgdata.data, nb);
}
else
{
for (Int32 j = 0; j < nb; j++)
Marshal.WriteByte(msgdata.data, j + i, vals[j]);
}
return true;
}
}
return false;
}
///
/// get a byte of the data of a message
///
/// Message structure containing data.
/// offset of the bytes in the message, cannot be more than 2147483647
/// value of the byte
/// true if ok, false if not ok
public static bool getData_2016(ref cantp_msg msg, Int32 i, out byte val)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.length > 0 && msgdata.data != IntPtr.Zero && i >= 0 && i < msgdata.length)
{
val = Marshal.ReadByte(msgdata.data, i);
return true;
}
}
val = 0;
return false;
}
///
/// get bytes of the data of a message
///
/// Message structure containing data.
/// offset of the first byte to get in the message, cannot be more than 2147483647
/// number of bytes
/// values of the bytes, from offset 0
/// true if ok, false if not ok
public static bool getData_2016(ref cantp_msg msg, Int32 i, byte[] vals, Int32 nb)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.length > 0 && msgdata.data != IntPtr.Zero && i >= 0 && i + nb - 1 < msgdata.length && nb <= vals.Length)
{
if (i == 0)
{
Marshal.Copy(msgdata.data, vals, 0, nb);
}
else
{
for (Int32 j = 0; j < nb; j++)
vals[j] = Marshal.ReadByte(msgdata.data, j + i);
}
return true;
}
}
return false;
}
///
/// get the net status of a message
///
/// Message structure containing the network status
/// value of the status
/// true if ok, false if not ok
public static bool getNetStatus_2016(ref cantp_msg msg, out cantp_netstatus status)
{
if (msg.Msgdata != IntPtr.Zero)
{
status = msg.Msgdata_any_Copy.netstatus;
return true;
}
status = new cantp_netstatus();
return false;
}
///
/// Get an option of a message
///
/// number of the option
/// where to store a copy of the option
/// true if ok, false if not ok
public static bool getOption_2016(ref cantp_msg msg, int number, out cantp_msgoption option)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.options != IntPtr.Zero)
{
cantp_msgoption_list l = (cantp_msgoption_list)Marshal.PtrToStructure(msgdata.options, typeof(cantp_msgoption_list));
return getOption_2016(ref l, number, out option);
}
}
option = new cantp_msgoption();
return false;
}
///
/// Modifies an option of a message
///
/// Message structure to modify
/// number of the option
/// value to set to the option
/// true if ok, false if not ok
public static bool setOption_2016(ref cantp_msg msg, int number, ref cantp_msgoption option)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.options != IntPtr.Zero)
{
cantp_msgoption_list l = (cantp_msgoption_list)Marshal.PtrToStructure(msgdata.options, typeof(cantp_msgoption_list));
return setOption_2016(ref l, number, ref option);
}
}
return false;
}
///
/// Get the number of options of a message
///
/// message
/// number of options
/// true if ok, false if Not ok
public static bool getOptionsNumber_2016(ref cantp_msg msg, out UInt32 number)
{
if (msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata msgdata = msg.Msgdata_any_Copy;
if (msgdata.options != IntPtr.Zero)
{
cantp_msgoption_list l = (cantp_msgoption_list)Marshal.PtrToStructure(msgdata.options, typeof(cantp_msgoption_list));
number = l.count;
return true;
}
}
number = 0;
return false;
}
///
/// set the network address information of an ISO-TP message
///
/// address to set
/// true if ok, false if not ok
public static bool setNetaddrinfo_2016(ref cantp_msg msg, ref cantp_netaddrinfo adr)
{
if (msg.type == cantp_msgtype.PCANTP_MSGTYPE_ISOTP && msg.Msgdata != IntPtr.Zero)
{
cantp_msgdata_isotp msgdata = (cantp_msgdata_isotp)Marshal.PtrToStructure(msg.Msgdata, typeof(cantp_msgdata_isotp));
msgdata.netaddrinfo = adr;
Marshal.StructureToPtr(msgdata, msg.Msgdata, true);
return true;
}
return false;
}
///
/// get the network address information of an ISO-TP message
///
/// value of address
/// true if ok, false if not ok
public static bool getNetaddrinfo_2016(ref cantp_msg msg, out cantp_netaddrinfo adr)
{
if (msg.type == cantp_msgtype.PCANTP_MSGTYPE_ISOTP && msg.Msgdata != IntPtr.Zero)
{
adr = msg.Msgdata_isotp_Copy.netaddrinfo;
return true;
}
adr = new cantp_netaddrinfo();
return false;
}
#endregion
#region special C# functions, examples of how to use the structures IntPtr fields in unsafe mode
#if (UNSAFE)
///
/// Get a copy of an option in an option list
///
/// option list
/// number of the option
/// where to store a copy of the option
/// true if ok, false if not ok
private unsafe static bool getOption_unsafe_2016(cantp_msgoption_list* l, int number, out cantp_msgoption option)
{
option = new cantp_msgoption();
if (l != null && number < l->count && l->buffer != IntPtr.Zero)
{
cantp_msgoption* opts = (cantp_msgoption*)l->buffer.ToPointer();
if (opts != null)
{
option = opts[number];
return true;
}
}
return false;
}
///
/// Modifies an option
///
/// option list
/// number of the option
/// value to set to the option
/// true if ok, false if not ok
private unsafe static bool setOption_unsafe_2016(cantp_msgoption_list* l, int number, ref cantp_msgoption option)
{
if (l != null && number < l->count && l->buffer != IntPtr.Zero)
{
cantp_msgoption* opts = (cantp_msgoption*)l->buffer.ToPointer();
if (opts != null)
{
opts[number] = option;
return true;
}
}
return false;
}
///
/// set a buffer to receive a copy of the pending message, in a progress structure
///
/// buffer to set
public unsafe static void setProgressBuffer_unsafe_2016(ref cantp_msgprogress prog, ref cantp_msg pendingMsg)
{
fixed (cantp_msg* pt = &pendingMsg) { prog.buffer = new IntPtr(pt); }
}
///
/// get the flags of a message
///
/// Message structure
/// value of the flags
/// true if ok, false if not ok
public unsafe static bool getFlags_unsafe_2016(ref cantp_msg msg, out cantp_msgflag flags)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null)
{
flags = msg.Msgdata_any->flags;
return true;
}
flags = new cantp_msgflag();
return false;
}
///
/// set the length of a message
/// use carefully
///
/// value to set
/// true if ok, false if not ok
public unsafe static bool setLength_unsafe_2016(ref cantp_msg msg, UInt32 len)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null)
{
msg.Msgdata_any->length = len;
return true;
}
return false;
}
///
/// get the length of a message
///
/// Message structure
/// value of the length
/// true if ok, false if not ok
public unsafe static bool getLength_unsafe_2016(ref cantp_msg msg, out UInt32 len)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null)
{
len = msg.Msgdata_any->length;
return true;
}
len = 0;
return false;
}
///
/// set a byte of the data of a message
///
/// Message structure to modify.
/// offset of the byte, cannot be more than 2147483647
/// value to set
/// true if ok, false if not ok
public unsafe static bool setData_unsafe_2016(ref cantp_msg msg, Int32 i, byte val)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->data != IntPtr.Zero)
{
byte* don = (byte*)msg.Msgdata_any->data.ToPointer();
if (don != null && msg.Msgdata_any->length > 0 && i >= 0 && i < msg.Msgdata_any->length)
{
don[i] = val;
return true;
}
}
return false;
}
///
/// set bytes of the data of a message
///
/// Message structure to modify.
/// offset of the first byte in the message, cannot be more than 2147483647
/// number of bytes
/// values to set, from offset 0
/// true if ok, false if not ok
public unsafe static bool setData_unsafe_2016(ref cantp_msg msg, Int32 i, byte[] vals, Int32 nb)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->data != IntPtr.Zero)
{
byte* don = (byte*)msg.Msgdata_any->data.ToPointer();
if (don != null && msg.Msgdata_any->length > 0 && i >= 0 && i + nb - 1 < msg.Msgdata_any->length && nb <= vals.Length)
{
for (Int32 j = 0; j < nb; j++)
don[j + i] = vals[j];
return true;
}
}
return false;
}
///
/// get a byte of the data of a message
///
/// Message structure containing data.
/// offset of the byte, cannot be more than 2147483647
/// value of the byte
/// true if ok, false if not ok
public unsafe static bool getData_unsafe_2016(ref cantp_msg msg, Int32 i, out byte val)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->data != IntPtr.Zero)
{
byte* don = (byte*)msg.Msgdata_any->data.ToPointer();
if (don != null && msg.Msgdata_any->length > 0 && i >= 0 && i < msg.Msgdata_any->length)
{
val = don[i];
return true;
}
}
val = 0;
return false;
}
///
/// get bytes of the data of a message
///
/// Message structure containing data.
/// offset of the first byte in the message, cannot be more than 2147483647
/// number of bytes
/// values of the bytes, from offset 0
/// true if ok, false if not ok
public unsafe static bool getData_unsafe_2016(ref cantp_msg msg, Int32 i, byte[] vals, Int32 nb)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->data != IntPtr.Zero)
{
byte* don = (byte*)msg.Msgdata_any->data.ToPointer();
if (don != null && msg.Msgdata_any->length > 0 && i >= 0 && i + nb - 1 < msg.Msgdata_any->length && vals.Length >= nb)
{
for (Int32 j = 0; j < nb; j++)
vals[j] = don[j + i];
return true;
}
}
return false;
}
///
/// get the net status of a message
///
/// Message structure containing the network status
/// value of the status
/// true if ok, false if not ok
public unsafe static bool getNetStatus_unsafe_2016(ref cantp_msg msg, out cantp_netstatus status)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null)
{
status = msg.Msgdata_any->netstatus;
return true;
}
status = new cantp_netstatus();
return false;
}
///
/// Get a copy of an option of a message
///
/// number of the option
/// where to store a copy of the option
/// true if ok, false if not ok
public unsafe static bool getOption_unsafe_2016(ref cantp_msg msg, int number, out cantp_msgoption option)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->options != IntPtr.Zero)
{
return getOption_unsafe_2016((cantp_msgoption_list*)msg.Msgdata_any->options.ToPointer(), number, out option);
}
option = new cantp_msgoption();
return false;
}
///
/// Modifies an option of a message
///
/// number of the option
/// value to set to the option
/// true if ok, false if not ok
public unsafe static bool setOption_unsafe_2016(ref cantp_msg msg, int number, ref cantp_msgoption option)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->options != IntPtr.Zero)
{
return setOption_unsafe_2016((cantp_msgoption_list*)msg.Msgdata_any->options.ToPointer(), number, ref option);
}
return false;
}
///
/// Get the number of options of a message
///
/// message
/// number of options
/// true if ok, false if not ok
public unsafe static bool getOptionsNumber_unsafe_2016(ref cantp_msg msg, out UInt32 number)
{
if (msg.Msgdata != IntPtr.Zero && msg.Msgdata_any != null && msg.Msgdata_any->options != IntPtr.Zero)
{
cantp_msgoption_list* l = (cantp_msgoption_list*)msg.Msgdata_any->options.ToPointer();
if (l != null)
{
number = l->count;
return true;
}
}
number = 0;
return false;
}
///
/// set the network address information of an ISO-TP message
///
/// address to set
/// true if ok, false if not ok
public unsafe static bool setNetaddrinfo_unsafe_2016(ref cantp_msg msg, ref cantp_netaddrinfo adr)
{
if (msg.type == cantp_msgtype.PCANTP_MSGTYPE_ISOTP && msg.Msgdata != IntPtr.Zero && msg.Msgdata_isotp != null)
{
msg.Msgdata_isotp->netaddrinfo = adr;
return true;
}
return false;
}
///
/// get the network address information of an ISO-TP message
///
/// value of address
/// true if ok, false if not ok
public unsafe static bool getNetaddrinfo_unsafe_2016(ref cantp_msg msg, out cantp_netaddrinfo adr)
{
if (msg.type == cantp_msgtype.PCANTP_MSGTYPE_ISOTP && msg.Msgdata != IntPtr.Zero && msg.Msgdata_isotp != null)
{
adr = msg.Msgdata_isotp->netaddrinfo;
return true;
}
adr = new cantp_netaddrinfo();
return false;
}
#endif
#endregion
#endregion
}
#endregion
}