lishen2 / isotp-c

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

message in isotp_on_can_message #20

Closed Sayahimed closed 2 years ago

Sayahimed commented 3 years ago

hello everyone , message in isotp_on_can_message function is declared in the function and it is used just afer the declaration can anyone tell me message.as.common.type when it was declared ?

zorce commented 3 years ago

Hi, Yes that is correct and part of the library? Can't really understand your question. You should write the code to receive the can frames and then send the frame data to this function. As the example on the main readme says.

Sayahimed commented 3 years ago

thank you for your answer this is the start of the function please read the comments
void isotp_on_can_message(IsoTpLink link, uint8_t data, uint8_t len) { IsoTpCanMessage message; // here we declare an empty message variable that's ok int ret;

if (len < 2 || len > 8) {
    return;
}

memcpy(message.as.data_array.ptr, data, len);
memset(message.as.data_array.ptr + len, 0, sizeof(message.as.data_array.ptr) - len);

switch (message.as.common.type) { /* and here we us the common.type of the message !!! is that is correct ? the message variable is already empty  yes ?*/
zorce commented 3 years ago

It's correct? It is a union struct defined in isotp_defines.h

lishen2 commented 2 years ago

Yes, the code is correct.

michel-ux commented 1 year ago

Why is "message.as.common.type" evaluated as a "switch" when no value is assigned to it?