Loading [MathJax]/extensions/tex2jax.js
  • <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>

  • DriveWorks SDK Reference
    5.8.83 Release
    For Test and Development only

    All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    Receiving and Sending Data

    CAN Bus Sensor Module workflow

    Initialization

    Initialization of the CAN bus sensor is achieved as follows:

    dwSensorParams params{};
    params.protocol = "can.socket";
    params.parameters = "device=can0";
    dwSensorHandle_t canSensor;
    dwSAL_createSensor(&canSensor, params, ...);
    const char8_t * protocol
    Name of the protocol.
    Definition: Sensors.h:99
    DW_API_PUBLIC dwStatus dwSAL_createSensor(dwSensorHandle_t *const sensor, dwSensorParams const params, dwSALHandle_t const sal)
    Creates a new sensor managed by the SAL module with the given parameters.
    struct dwSensorObject * dwSensorHandle_t
    Handle representing a sensor.
    Definition: Sensors.h:86
    Holds sets of parameters for sensor creation.
    Definition: Sensors.h:95

    Protocol

    The dwSensorParams.protocol expects one of the following can interfaces:

    • can.socket interface for system CAN bus.
    • can.aurix interface for CAN over Aurix.
    • can.virtual interface for reading CAN data from binary logs.

    Sensor parameters

    The dwSensorParams.parameters accepts the following parameters:

    For all:

    filter=id:mask[+id:mask]:

    • filter is a string of + seperated filters
    • id is a hex value
    • mask is a hex value

    Example: filter=123:FFF+60A:FFF

    See the Setting message filters section to see how these values are used.

    When using can.socket:

    device=can0[,fifo-size=1024]

    • device CAN device interface, usually canx, x starting from 0
      • on Linux, use ifconfig to list available CAN interfaces
      • on QNX, use pidin a | grep nvcan to list available CAN interfaces
    • fifo-size size of internal buffer, in number of dwCANMessage stored.
    • discard-threshold the timestamp of CAN data who is older than current timestamp by threshold will be discarded.
      • only apply on QNX(CANQnx)
    • read-number data size to be read from driver buffer in one syscall, default number is 256
      • only apply on QNX(CANQnx)
    • do-not-send disables send functionality when set to true.

    When using can.aurix in driveworks 3.5 and above (Aurix version 4.0 and above):

    ip=10.0.0.1,bus={a,b,c,d,e,f}[,aport=50000,bport=60395],[inIDMap=1:0x106+2:0x206][6,outIDMap=0x105:17+0x205:18][,fifo-size=1024]

    • ip IP of Aurix (Drive AGX: 10.42.0.146).
    • aport port on which CAN messages are sent to Aurix.
    • bport port on which CAN messages are received from Aurix.
    • fifo-size see above.
    • inIDMap a mapping of PDU ID to CAN ID in the format pduID:canID seperated by '+'. This should match the security model compiled onto the Aurix. ID values in decimal or hex format with leading 0x. Messages recieved from Aurix with pduID will be mapped to matched canID.
    • outIDMap a mapping of CAN ID to PDU ID in the format canID:pduUD seperated by '+'. This should match the security model compiled onto the Aurix. ID values in decimal or hex format with leading 0x. Messages with canID will be send to Aurix mapped to pduID.

    Note: Hardware timestamping is not available with Aurix version 4.0 and above.

    When using can.aurix in driveworks 3.0 and below (Aurix version 3.X and below)

    ip=10.42.0.146,bus={a,b,c,d,e,f}[,aport=50000,bport=60395],[config-file=/path/to/EasyCanConfigFile.conf][,fifo-size=1024]

    • ip IP of Aurix (Drive AGX: 10.42.0.146).
    • aport port on which CAN messages are sent to Aurix.
    • bport port on which CAN messages are received from Aurix.
    • fifo-size see above.
    • bus EasyCAN bus.
    • config-file path to EasyCanConfigFile.conf, when provided, configures Aurix EasyCAN message routing when starting sensor. An example is provided in the DriveWorks data folder, under /path/to/data/samples/sensors/can.

    When using can.simulator:

    Identical parameters to can.socket.

    When using can.virtual:

    file=/path/to/file.can[,create_seek,default_timeout_us,time-offset=0]

    • file path to CAN bus recording
    • create_seek create seek table
    • default_timeout_us period after which sensor times out
    • time-offset offset applied to CAN messages timestamps

    The CAN buses are setup with CAN FD if supported. If not supported sending and receiving CAN FD messages will fail.

    Starting, stopping and releasing sensor

    The CAN bus sensor can be started, stopped and released as follows:

    dwSensor_start(canSensor);
    dwSensor_stop(canSensor);
    dwSAL_releaseSensor(&canSensor);
    DW_API_PUBLIC dwStatus dwSensor_start(dwSensorHandle_t const sensor)
    Starts the sensor previously successfully created with 'dwSAL_createSensor()'.
    DW_API_PUBLIC dwStatus dwSensor_stop(dwSensorHandle_t const sensor)
    Stops the sensor.
    DW_API_PUBLIC dwStatus dwSAL_releaseSensor(dwSensorHandle_t const sensor)
    Releases a sensor managed by the SAL module.

    Reading CAN messages

    CAN messages can be read from the bus as follows:

    dwStatus status = dwSensorCAN_readMessage(&msg, 10000, canSensor);
    DW_API_PUBLIC dwStatus dwSensorCAN_readMessage(dwCANMessage *const msg, dwTime_t const timeoutUs, dwSensorHandle_t const sensor)
    Reads a CAN packet with a given timeout from the CAN bus.
    Holds a CAN package.
    Definition: CAN.h:113
    dwStatus
    Status definition.
    Definition: Status.h:171

    This will populate a dwCANMessage structure with the next CAN message received on the bus, in this example waiting up to 10000us, or 10ms, for a message to arrive. Timeout can be set to DW_TIMEOUT_INFINITE to indicate infinite waiting until new message arrives, or 0 to immediately return and only read messages already received. The dwCANMessage structure can hold up to 64 bytes to accommodate CAN FD messages.

    To only read messages available in the internal queue, without reading new messages on the CAN bus, the dwSensorCAN_popMessage() method can be used. Together with dwSensorCAN_processRawData(), raw binary CAN data can be read and parsed in dwCANMessage format, see Reading CAN Messages from Raw Data (Binary).

    Sending CAN messages

    CAN messages can be sent on the bus as follows:

    msg.id = 0x123;
    msg.data[0] = 0xFF;
    msg.size = 1;
    msg.timestamp = 0;
    dwSensorCAN_sendMessage(&msg, 10000, canSensor);
    uint32_t id
    CAN ID of the message sender.
    Definition: CAN.h:118
    DW_API_PUBLIC dwStatus dwSensorCAN_sendMessage(const dwCANMessage *const msg, dwTime_t const timeoutUs, dwSensorHandle_t const sensor)
    Sends a message over the CAN bus within a specified timeout.

    This sends a message over the CAN bus within a specified timeout. A message is guaranteed to have been sent when this method returns DW_SUCCESS. The method can block for up-to the specified amount of time if a bus is blocked or previous dwSensorCAN_readMessage() operation has not yet finished.

    If the msg.size value is from 9 - 64, then the message will be sent as a CAN FD message.

    Setting message filters

    CAN messages be filtered by ID as follows:

    uint32_t ids[2] = {0x100, 0x6AB};
    uint32_t masks[2] = {0xF00, 0xFFF};
    dwSensorCAN_setMessageFilter(&ids, &masks, 2, canSensor);
    DW_API_PUBLIC dwStatus dwSensorCAN_setMessageFilter(const uint32_t *ids, const uint32_t *masks, uint16_t num, dwSensorHandle_t sensor)
    Specifes a set of CAN IDs to be filtered.

    This function takes an array of IDs and an array of masks to setup filters. Once the filters are set, only messages with IDs matching the filters will be read. Each call to the above will reset previously set filters. To reset all filtering, call the above with 0 as number of filters.

    Internally, only messages that meet the following condition for at least one filter are read:

    (messageID & mask) == (id & mask)

    Masks are optional; when passing NULL, a default mask of 1FFFFFFF is used.

    Setting hardware timestamping

    The dwSensorCAN_setUseHwTimestamps() function allows the user to enable or disable hardware timestamping of messages on compatible CAN Bus devices. By default, hardware timestamping is enabled if available, but can be turned off if the default behavior is not working properly with the current hardware stack.

    The dwSensorCAN_readMessage() function reads the next available CAN message with a given timeout. The function call is blocking, until a CAN message is available or the timeout is exceeded. Filters can be set with dwSensorCAN_setMessageFilter() so that only specific messages are read from the bus. Messages can be sent with dwSensorCAN_sendMessage().

    The dwCANMessage structure holds a CAN message, consisting of a timestamp, an ID, message data (payload) and size. The CAN bus module supports the extended CAN frame format.

    Aurix version 3.01.3 information

    Sending CAN messages over Aurix

    As of software version 3.01.3, the Aurix is configured to cyclically send CAN messages with IDs 0x10f to 0x114 on buses A through F. These message IDs should be considered as reserved as this behavior cannot be disabled at run-time. Please refer to the Elektrobit Aurix Software User Guide for more details.

    Sending CAN with FD (Flexible Data-Rate) and BRS (Bit Rate Switch)

    As of software version 3.05.4, the Aurix can send CAN FD messages with BRS. Note that this is configured to use timing sample points of 0.8. Devices on the network must be setup using this timing or bus errors can occur. Please refer to Drive Developer Guide, Flashing Aurix documentation for more information.

    Setting message routing on Aurix with config file

    A message routing configuration has to be sent to Aurix prior to running the application in order to receive, over Aurix, select CAN messages on the desired Xavier device(s). This can be done by providing an EasyCAN configuration file when creating the CAN bus sensor for can.aurix protocol, by specifying the path to an Aurix EasyCAN configuration file with the config-file argument. The configuration file is a text file containing the following structures, one per CAN message to be routed:

    MsgId : 0x140
    CtrlId : EC_CAN_BUS_E
    FrmTyp : CAN_ID_STANDARD
    DestId : TEGRA_DEVICE_A
    DestSwc : SWC_ID_CANDATA

    Where:

    • MsgId is the message ID to be routed, in hexadecimal
    • CtrlId is the EasyCAN bus on which the message is received, in range EC_CAN_BUS_A to EC_CAN_BUS_F
    • FrmTyp is the CAN ID type selector, either CAN_ID_STANDARD or CAN_ID_EXTENDED
    • DestId is the destination device, either TEGRA_DEVICE_A or TEGRA_DEVICE_B
    • DestSwc is set to SWC_ID_CANDATA for CAN data

    Each structure, corresponding to one CAN message to be routed, is separated by an empty line from the next. An example file is provided in the DriveWorks data folder, under /path/to/data/samples/sensors/can.

    Please refer to the Elektrobit Aurix Software User Guide provided as part of PDK documentation for more information on the EasyCAN message routing feature and on how to configure Aurix.

    Example

    The following code shows the general structure of a program setting up CAN message filters and receiving/sending messages on the bus. Only messages with IDs 0x100-0x1FF and 0x6AB will be read.

    dwSensorParams params{};
    params.protocol = "can.socket";
    params.parameters = "device=can0";
    dwSensorHandle_t canSensor;
    dwSAL_createSensor(&canSensor, params, ...);
    uint32_t ids[2] = {0x100, 0x6AB};
    uint32_t masks[2] = {0xF00, 0xFFF};
    dwSensorCAN_setMessageFilter(&ids, &masks, 2, canSensor);
    dwSensor_start(canSensor);
    while(loop)
    {
    dwCANMessage msg{};
    // read all messages until internal queue is empty
    while(dwSensorCAN_readMessage(&msg, 0, canSensor) == DW_SUCCESS)
    {
    // use received can message
    }
    // send message, e.g. asking for more data
    msg.id = 0xAAA;
    msg.data[0] = 0xFF;
    msg.size = 1;
    msg.timestamp = 0;
    // wait for 10ms at most if bus is busy
    dwSensorCAN_sendMessage(&msg, 10000, canSensor);
    }
    dwSensor_stop(canSensor);
    dwSAL_releaseSensor(&canSensor);

    For more information, refer to CAN Message Logger Sample.

    人人超碰97caoporen国产