Giter VIP home page Giter VIP logo

Comments (1)

Sauci avatar Sauci commented on July 1, 2024

Setting the CAN_ISOTP_WAIT_TX_DONE doesn't indeed affect the return value of write(2). Bellow a sample code illustrating this behavior:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <net/if.h>
#include <linux/can.h>
#include <linux/can/isotp.h>

static const u_int8_t tx_buffer[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int main() {
    int status = 0;

    int fd;
    struct sockaddr_can address;
    static struct can_isotp_options isotp_options;
    static struct can_isotp_ll_options isotp_ll_loptions;

    address.can_family = AF_CAN;
    address.can_addr.tp.rx_id = 0x98DAF900u;
    address.can_addr.tp.tx_id = 0x98DA00F9u;
    address.can_ifindex = (signed) if_nametoindex("can1");

    isotp_options.flags = CAN_ISOTP_DEFAULT_FLAGS | CAN_ISOTP_WAIT_TX_DONE;

    isotp_ll_loptions.mtu = 16u;
    isotp_ll_loptions.tx_dl = 8u;
    isotp_ll_loptions.tx_flags = 0u;

    if ((fd = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP)) >= 0) {
        if ((setsockopt(fd, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &isotp_options, sizeof(isotp_options))) >= 0) {
            if ((setsockopt(fd, SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, &isotp_ll_loptions, sizeof(isotp_ll_loptions))) >= 0) {
                if ((bind(fd, (struct sockaddr *)&address, sizeof(address))) >= 0) {
                    ssize_t result = write(fd, &tx_buffer, sizeof(tx_buffer) / sizeof(tx_buffer[0]));
                    printf("result = %d", result);
                } else {
                    status = 4;
                }
            } else {
                status = 3;
            }
        } else {
            status = 2;
        }
    } else {
        status = 1;
    }

    return status;
}

This executable outputs:

/home/pi/isotp/cmake-build-debug-rpi/isotp
result = 10
Process finished with exit code 0

While the can dump utility outputs:

$ candump can1
  can1  18DA00F9   [8]  10 08 01 02 03 04 05 06

Should the call to write(2) return a negative value? Or should it return the number of byte effectively written (in this case 6) if the writing operations are configured in blocking mode trough CAN_ISOTP_WAIT_TX_DONE option?

from can-isotp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.