lishen2 / isotp-c

An implementation of the ISO-TP (ISO15765-2) CAN protocol in C
MIT License
213 stars 79 forks source link

handling multi-frame send.. #19

Closed zorce closed 2 years ago

zorce commented 3 years ago

Hi, Got the multi-frame receive to work just fine. but have some trouble with the multi-frame send.. Trying to send back a reply when I received a multi-frame message with a multi-frame response. The below handle_message parse the received payload and respond with a pointer to a 8 byte buffer. I CAN monitor the signals go out on CAN but never handles the flow control frame.

Send first frame 10 00 62 04 08 0A Receive Flow control 30 08 00 Then nothing.

Also running the isotp_poll separately to the below function call

void isotp_user_recv(can_frame_t frame) {
    int ret;

    isotp_on_can_message(&g_link, frame.data, frame.dlc);

        /* Poll link to handle multiple frame transmission */
    isotp_poll(&g_link);

    ret = isotp_receive(&g_link, payload, payload_size, &out_size);
    if (ISOTP_RET_OK == ret) {
        // receive ok
        /* Handle received message */
        data_t * data = handle_message(payload, &out_size);
        if (NULL != data) {
            ret = isotp_send(&g_link, data->buffer, data->size);
            if (ISOTP_RET_OK == ret)
            {
                // send ok
            }
        }
    }   
}
zorce commented 3 years ago

This is solved for me now.. maybe a clarification in the example glue. My implemented isotp_user_send_can returned CAN_OK from my low level driver, = 1 and when received in isotp as return code for sending the first frame it didnt see it as OK. So after checking and return ISOTP_RET_OK back it worked fine! Maybe just add a note on that

/* required, this must send a single CAN message with the given arbitration
 * ID (i.e. the CAN message ID) and data. The size will never be more than 8
 * bytes. **Should return ISOTP_RET_OK if success***/
int  isotp_user_send_can(const uint32_t arbitration_id,
                         const uint8_t* data, const uint8_t size) {
    // ...
}
lishen2 commented 2 years ago

Good idea, add now.