Giter VIP home page Giter VIP logo

iso-tp's People

Contributors

altelch avatar brandonros avatar dexterbg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iso-tp's Issues

Can not receive CAN message Package over 255 bytes

I was trying receive 1 CAN message package with 256 bytes, but it not worked.
After I debugging Source Code , I realized it has 1 issue .
At the uint8_t IsoTp::rcv_ff(struct Message_t* msg) function :


   msg->len = (rxBuffer[0] & 0x0F) << 8;
  msg->len += rxBuffer[1];

the value of msg->len can't over 256.
So if we want to receive a package over 256 bytes, it will not work.
This is my solution for that :

over256size = rxBuffer[0] & 0x0F;
 if(over256size != 0)
 {
     msg->len = over256size  << 8;
     msg->len += rxBuffer[1];
 else
 {
     msg->len = rxBuffer[1];
 }

Please check it and update your library.
Thank you so much.

Compile errors

C:\Users\Brandon\Documents\Arduino\libraries\iso-tp\iso-tp.cpp: In member function 'uint8_t IsoTp::can_receive()':
C:\Users\Brandon\Documents\Arduino\libraries\iso-tp\iso-tp.cpp:50:46: error: invalid conversion from 'uint32_t* {aka unsigned int*}' to 'long unsigned int*' [-fpermissive]
      _bus->readMsgBuf(&rxId, &rxLen, rxBuffer); // Read data: buf = data byte(s)
                                              ^
In file included from C:\Users\Brandon\Documents\Arduino\libraries\iso-tp\iso-tp.h:4:0,
                 from C:\Users\Brandon\Documents\Arduino\libraries\iso-tp\iso-tp.cpp:2:
C:\Users\Brandon\Documents\Arduino\libraries\MCP_CAN_lib/mcp_can.h:117:11: note:   initializing argument 1 of 'byte MCP_CAN::readMsgBuf(long unsigned int*, byte*, byte*)'
     INT8U readMsgBuf(INT32U *id, INT8U *len, INT8U *buf);               // Read message from receive buffer
           ^
exit status 1
Error compiling for board ESP32 Dev Module.

Stack with multi frame messages

I made a hardware with your example, with minor modifications due to a compilation error. I send 32 bytes from one device to another in an infinite loop with a delay of 1 second. Everything works fine for about 50 times and then arduino uno receiver get some wrong data and then arduino uno sender stack and reset. I think the problem is with some buffer overflow. I am trying to solve the problem but my programming skills is not enough. Please, help me. Thank you.

My codes:
send

#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <iso-tp.h>

#define MCP_INT 2

MCP_CAN CAN0(10);
IsoTp isotp(&CAN0,MCP_INT);

int p=0;

struct Message_t TxMsg, RxMsg;

uint8_t sf_test[] = { 0x00, 0x01, 0xAA, 0xBB, 0xCC, 0xDD, 0x12};
uint8_t mf_test[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};

uint32_t can_id = 0x222;

void setup()
{
Serial.begin(115200);
pinMode(MCP_INT, INPUT);
CAN0.begin(MCP_ANY, CAN_125KBPS, MCP_16MHZ);
CAN0.setMode(MCP_NORMAL);
TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
RxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
}

void loop()
{
TxMsg.len=sizeof(mf_test);
TxMsg.tx_id=can_id;
TxMsg.rx_id=0x111;
memcpy(TxMsg.Buffer,mf_test,sizeof(mf_test));
Serial.println(F("Send..."));
isotp.send(&TxMsg);

delay(1000);
p=p+1;
Serial.println(p);
}

receive

#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <iso-tp.h>

#define MCP_INT 2

MCP_CAN CAN0(10);
IsoTp isotp(&CAN0,MCP_INT);

struct Message_t TxMsg, RxMsg;

uint8_t sf_test[] = { 0x00, 0x01 };
uint8_t mf_test[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
uint32_t can_id = 0x111;

void setup()
{
Serial.begin(115200);
pinMode(MCP_INT, INPUT);
CAN0.begin(MCP_ANY, CAN_125KBPS, MCP_16MHZ);
CAN0.setMode(MCP_NORMAL);
TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
RxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
}

void loop()
{
if(!digitalRead(MCP_INT))
{
RxMsg.tx_id=can_id;
RxMsg.rx_id=0x222;
Serial.println(F("Receive..."));
isotp.receive(&RxMsg);
isotp.print_buffer(RxMsg.rx_id, RxMsg.Buffer, RxMsg.len);
}
}

mf_test

Hi all,

I've got a question about sending the mf_test buffer using the example send_receive provided.

When I change the code to hold the mf_test values it doesn't get send?!

   txMsg.len = sizeof(mf_test);
   txMsg.tx_id = tx_can_id;
   txMsg.rx_id = rx_can_id;
   memcpy(txMsg.Buffer,mf_test,sizeof(mf_test));
   Serial.println(F("Send..."));
   isotp.send(&txMsg);

The buffer is being filled with the 32 values.

What am I doing wrong?

Incomplete Message Received

Thank you for this library, it is the needed solution i'm looking for.
I was trying out the library using the example code i found here, however i encounter a little problem. This seems to be a little problem but i don't know exactly where it is. As attached below, i'm sending 12 bytes of data but at the receiver side, i can only correctly receive the first 6 bytes, all the others are zeros. Attached is the code, please what could be the problem. Thank you

//Sender:
#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <iso-tp.h>

#define MCP_INT 2
MCP_CAN CAN0(10);
IsoTp isotp(&CAN0,MCP_INT);

struct Message_t TxMsg, RxMsg;

//uint32_t can_tx = 0x8801F456;

uint32_t can_tx =0x7FF;
//long unsigned int can_tx = 0x18263598;

byte data1[] = {0x09, 0x60, 0x01, 0x90, 0x1F, 0x40, 0x03, 0x20, 0xC8, 0x02, 0x58, 0x02};

void setup()
{
Serial.begin(115200);
pinMode(MCP_INT, INPUT);
CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ);
CAN0.setMode(MCP_NORMAL);
TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
}

void loop()
{
TxMsg.len=sizeof(data1);
TxMsg.tx_id=can_tx;
//TxMsg.tx_id=(can_tx|0x80000000);
memcpy(TxMsg.Buffer,data1,(sizeof(data1)));
Serial.println(F("Send..."));
isotp.print_buffer(TxMsg.tx_id, TxMsg.Buffer, TxMsg.len);
isotp.send(&TxMsg);
}
//Receiver:
#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <iso-tp.h>

#define MCP_INT 2 // "IRQ: if pin is low, read receive buffer"

MCP_CAN CAN0(53);
IsoTp isotp(&CAN0,MCP_INT);

struct Message_t TxMsg, RxMsg;

//uint32_t can_rx = 0x8801F456;

uint32_t can_rx = 0x7FF;
//long unsigned int can_rx = 0x18263598;

void setup()
{
Serial.begin(115200);
pinMode(MCP_INT, INPUT);
CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ);
CAN0.setMode(MCP_NORMAL);

RxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
//RxMsg.rx_id=(can_rx|0x80000000);


//RxMsg.rx_id=can_rx;

}

void loop()
{
RxMsg.rx_id=can_rx;
isotp.receive(&RxMsg);
isotp.print_buffer(RxMsg.rx_id, RxMsg.Buffer, RxMsg.len);
//Serial.println(RxMsg.Buffer[7]);
}

Receiver
Sender

fc_delay suggestion for exception

Hello,

I would like to ask whether it corrects to use the fc_delay function, changing like below, for exceptional case about minimum separation time.

Original Script
void IsoTp::fc_delay(uint8_t sep_time)
{
if(sep_time < 0x80)
delay(sep_time);
else
delayMicroseconds((sep_time-0xF0)*100);
}

Change version
void IsoTp::fc_delay(uint8_t sep_time)
{
/*
* 0x00 - 0x7F: 0 - 127ms
* 0x80 - 0xF0: reserved
* 0xF1 - 0xF9: 100us - 900us
* 0xFA - 0xFF: reserved
* default 0x7F, 127ms
*/
if(sep_time <= 0x7F)
delay(sep_time);
else if ((sep_time >= 0xF1) && (sep_time <= 0xF9))
delayMicroseconds((sep_time-0xF0)*100);
else
delay(0x7F);
}

& instead of &&

Hi!
I think here && is preferable otherwise you get

home/gorgo/Arduino/libraries/iso-tp-master/iso-tp.cpp:358:48: error: suggest parentheses around comparison in operand of '&' [-Werror=parentheses]
                                  while(msg->len>7 & !bs)
                                                ^
cc1plus: some warnings being treated as errors

with new gcc/Arduino IDE.

while(msg->len>7 & !bs)

Problem

Hi! I need your help .
My code for Arduino :
`#include <mcp_can.h>
#include <mcp_can_dfs.h>
#include <SPI.h>
#include <iso-tp.h>

#define MCP_INT 2

MCP_CAN CAN0(9);
IsoTp isotp(&CAN0,MCP_INT);

struct Message_t TxMsg, RxMsg;
uint32_t can_tx = 0x714;
uint32_t can_rx = 0x77E;

byte sesion[] = { 0x10, 0x03 };
byte reset[] = { 0x11, 0x01 };
//byte sesion[] = { 0x3E, 0x00 };
byte id[] = { 0x22, 0xF1 , 0x87 };
byte hw[] = { 0x22, 0xF1 , 0x89 };
byte type[] = { 0x22, 0xF1 , 0x9E };

void setup()
{
Serial.begin(1000000);
pinMode(MCP_INT, INPUT);
CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ);
CAN0.setMode(MCP_NORMAL);
}

void print_buf(uint32_t id, byte *buf, uint16_t len)
{
Serial.print(F("Buffer: "));
Serial.print(id,HEX); Serial.print(F(" ["));
Serial.print(len); Serial.print(F("] "));
for(byte i=0;i<len;i++)
{
if(buf[i] < 0x10) Serial.print(F("0"));
Serial.print(buf[i],HEX);
Serial.print(F(" "));
}

    for (byte k = 0; k < len; k++) {
      if ((buf[k] >= 0x00)&(buf[k] <= 0x19)){
      buf[k]= 0x2E;
      }
    Serial.print(char(buf[k]));
    }

Serial.println();
}

void send_to_can(byte data[],int a)
{
TxMsg.len=a;
TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
TxMsg.tx_id=can_tx;
TxMsg.rx_id=can_rx;
memcpy(TxMsg.Buffer,data,a);
isotp.print_buffer(TxMsg.tx_id, TxMsg.Buffer, TxMsg.len);
isotp.send(&TxMsg);

RxMsg.tx_id=can_tx;
RxMsg.rx_id=can_rx;
RxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
Serial.println(F("Receive..."));
isotp.receive(&RxMsg);
print_buf(RxMsg.rx_id, RxMsg.Buffer, RxMsg.len);

}

void loop()
{
if (Serial.available() > 0){
byte x = Serial.read();

switch (x) {
case 0x30:
send_to_can(sesion,2);
break;
case 0x31:
send_to_can(id,3);
break;
case 0x32:
send_to_can(hw,3);
break;
case 0x33:
send_to_can(type,3);
break;
}
}
}`

Arduino sends to can bus 2 times one and the same ((((

TxMsg does not name a type on example

Hey there,

Getting the following issue when trying to run the example code running the MCP library from it's master repo.

send_receive:17:1: error: 'TxMsg' does not name a type
 TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
 ^
send_receive:18:1: error: 'RxMsg' does not name a type
 RxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));
 ^
exit status 1
'TxMsg' does not name a type

Ideas?

HVAC seq_id wrong order

Hi!
I'm trying to get a 54B message from the HVAC from a Nissan Leaf 2018.
Most of the time I send the message, the lib timeouts because it reads seq_ids in wrong order (or the OBD sends them in a wrong order).

I don't get why I can successfully get a 331B msg without any error from another ECU but the HVAC seems to be problematic.

ISO-TP State: 1
Length      : 2
Send SF
Send CAN RAW Data:
Buffer: 744 [8] 02 21 10 00 00 00 00 00 
Start receive...
Received CAN RAW Data:
Buffer: 764 [8] 10 36 61 10 33 3C 36 00 
rxId OK!
FF
First frame received with message length: 48
Send flow controll.
ISO-TP state: 6
Send CAN RAW Data:
Buffer: 744 [8] 30 00 00 00 00 00 00 00 
Received CAN RAW Data:
Buffer: 764 [8] 21 33 3C 00 34 00 00 00 
rxId OK!
CF
ISO-TP state: 6
CF received with message rest length: 48
CF received with seq. ID: 1
Received CAN RAW Data:
Buffer: 764 [8] 22 84 9D 00 00 00 00 00 
rxId OK!
CF
ISO-TP state: 6
CF received with message rest length: 41
CF received with seq. ID: 2
Received CAN RAW Data:
Buffer: 764 [8] 23 00 00 00 00 00 00 00 
rxId OK!
CF
ISO-TP state: 6
CF received with message rest length: 34
CF received with seq. ID: 3
Received CAN RAW Data:
Buffer: 764 [8] 24 32 93 00 00 00 06 00 
rxId OK!
CF
ISO-TP state: 6
CF received with message rest length: 27
CF received with seq. ID: 4
Received CAN RAW Data:
Buffer: 764 [8] 26 00 00 00 00 2C 2C 2C 
rxId OK!
CF
ISO-TP state: 6
CF received with message rest length: 20
Got sequence ID: 6 Expected: 5
Received CAN RAW Data:
Buffer: 764 [8] 27 29 00 28 00 00 00 FF 
rxId OK!
CF
ISO-TP state: 0
CF received with message rest length: 20
Received CAN RAW Data:
Buffer: 764 [8] 25 60 A0 08 90 00 00 00 
rxId OK!
CF
ISO-TP state: 0
CF received with message rest length: 20
ISO-TP Session timeout wait_session=33190 delta=500

In the file attached I pasted the LBC 331B msg (First request), multiple bad requests to HVAC until it eventually got one good answer and the Buffer is correctly filled.

Extra question:
I'm interested in first two bytes from 0x22 frame. Is there a way to get that frame only by any chance? Maybe setting the FC somehow for this particular case.
Is there also a way to 'clean' the flow control in order to restart the request? Sometimes I get some dirty frames from previous requests when I try to stop some and retry.

hvac-errors.log

'AND' operator

Hello

In 'send' function, would you please check below 'AND' operation? It showed compile error for me.

It is under case ISOTP_SEND_CF.
There is "while(msg->len>7 & !bs)".
Is it "while(msg->len>7 && !bs)"?

Thanks,
Jin

FC Frame not send tx_id

when i receive canbus messages, i can receive single frame mesages. But i want to receive cf messages, i couldn't get any message after fc. on debug mode, i saw library not send tx_id on fc , i addedd tx_id manually to IsoTp::send_fc in iso-tp.cpp of library. After that, i can receive cf messages.

'TxMsg' does not name a type

Thank you for this library, it is the needed solution i'm looking for.
When trying to compile the code on Arduino IDE 1.8.10 version, i receive this error message

'TxMsg' does not name a type, at this line of code

TxMsg.Buffer=(uint8_t *)calloc(MAX_MSGBUF,sizeof(uint8_t));

please what could be the problem. I have installed the necessary libraries.
Thank you

Inclusion of Extended CAN

Although the project description clearly states the implementation being for 11-bit standard CAN messages, I wanted to get an insight into its usage for Extended CAN messages with 29-bit identifier. In the header file, macro CAN_MAX_DLEN holds value 8 (commented as "Not extended CAN"). Could you kindly elaborate on what changes are expected in the library files for updating to 29-bit identifier support? It would be of immense help!

fc_delay function for exceptional case

Hello,

I would like to ask whether it corrects to use the fc_delay function, changing like below, for exceptional case about minimum separation time.

Original Script
void IsoTp::fc_delay(uint8_t sep_time)
{
if(sep_time < 0x80)
delay(sep_time);
else
delayMicroseconds((sep_time-0xF0)*100);
}

Change version
void IsoTp::fc_delay(uint8_t sep_time)
{
/*
* 0x00 - 0x7F: 0 - 127ms
* 0x80 - 0xF0: reserved
* 0xF1 - 0xF9: 100us - 900us
* 0xFA - 0xFF: reserved
* default 0x7F, 127ms
*/
if(sep_time <= 0x7F)
delay(sep_time);
else if ((sep_time >= 0xF1) && (sep_time <= 0xF9))
delayMicroseconds((sep_time-0xF0)*100);
else
delay(0x7F);
}

Messages with blocksize > 16

when try to transmit messages with blocksize higher then 16 it failes, because it waits for fc frame which will never come.
Change line 378 in iso-tp.cpp to:

if (msg->blocksize < 16)
msg->seq_id %= 16;
else
msg->seq_id %= msg->blocksize;

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.