Recent

Author Topic: CAN-BUS SocketCAN  (Read 71917 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #135 on: October 19, 2021, 08:54:22 pm »
Thanks for the reminder about grounding and the extra link, I actually had much of that stuff drummed into me when I was hooking up an early not-quite-PC LAN in about 1984 :-)

For the moment this is strictly desktop-experimentation (well, desktop plus a cable to my antenna mast) and if anything production comes of it cost will be little object (you ought to see the cost of the traditional opposition...)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #136 on: October 19, 2021, 08:55:13 pm »
Noting that this is the dominant Canbus thread: what interface hardware are people using for general development on a PC? I might need to prod at a vehicle subsystem with Canbus as one (fortunately not the only one) of the interfaces.

Linux has best tools and allows greatest hacking capability, so you could use these (Pi based on MCP2515):
For the Beagle I have a cape with the CAN and RS485 driver.  For the Pi I have a single and dual CAN cape both using SPI.

Lawicel based ones work with both Windows and Linux (and can occasionally drop frames on very congested 1Mbit networks), but above ones are my favorites (especially if you have proper DBC files for automatic data decoding). For software/hardware specifics read my older messages.

Yes the problem with the Lawicel using the COMx: on windows is more to do with the USB side of things.  The CANUSB buffers a fair number of messages and uses the 8bit bus based SJA1000 CAN device.  But if the USB can't get them out fast enough (the serial port driver is the issue) then at really high bus speeds with 100% utilized bus there can be problems. 

There is a DLL based driver that doesn't have the overhead of the serial port.  However I don't think that's supported on Linux.

If you are using 29 bit Extended IDs then you can use 135 bits as a general rule for largest message size including stuff bits.  So at 1MBps we're talking 135uS per message with the bus at 100%.  That's only about 7.5kHz with the largest messages.  But if you are running standard IDs with only one or two bytes in the messages now you can go back to back about 64 bits and double the message rate just over 15kHz.    A 10Mhz SPI bus has no trouble with this.  But it's hard to do that with a PC unless it's USB with a dedicated driver, not the serial port.

For example:  15kHz for a Lawicel message might be t12325566<CR>  which is 10 characters.  That's 150 kbaud and most USB interfaces start to break down above 115Kbaud.  Although DMX512A for light shows are 250kbaud.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #137 on: October 19, 2021, 08:59:52 pm »
most USB interfaces start to break down above 115Kbaud.  Although DMX512A for light shows are 250kbaud.

Particularly if they use a counterfeit chip. I'm amassing a photo collection...

As a slight aside, if deciding on a default "Baud rate" ** for a serial link it's worth considering that some Arduino-like devices (e.g. ESP32) don't support below 38k4.

MarkMLl

** I know, that's why I put it in quotes.
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #138 on: October 19, 2021, 09:01:02 pm »
Thanks for the reminder about grounding and the extra link, I actually had much of that stuff drummed into me when I was hooking up an early not-quite-PC LAN in about 1984 :-)

For the moment this is strictly desktop-experimentation (well, desktop plus a cable to my antenna mast) and if anything production comes of it cost will be little object (you ought to see the cost of the traditional opposition...)

MarkMLl

I started working with CAN and the 82C200 in 1992.  Before there were CAN drivers.  The 82C200 (now SJA1000) had drivers on board for resistive termination and was rated at max 100kbps.  We were using it at 333kbps only because the original author made a config mistake aiming for 500kbps.  By the time I figured that out there were too many systems in the field.

A year later Philips came out with the 82C250 and we were given 250 to play with.  A bunch of machines went out with those and only later when we started having problems did we learn they were pre-production prototypes never meant for distribution in the field.  They had a serious issue with returning to recessive state and floated all over the place.

My solution was a resistor array that pulled the CAN_H to 2.4V and the CAN_L to 2.6V during the recessive state.  During dominant the device would still go 4.0V for CAN_H and 1.0V for CAN_L and all was good. 

Good times....

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #139 on: October 19, 2021, 09:04:01 pm »
most USB interfaces start to break down above 115Kbaud.  Although DMX512A for light shows are 250kbaud.

Particularly if they use a counterfeit chip. I'm amassing a photo collection...

As a slight aside, if deciding on a default "Baud rate" ** for a serial link it's worth considering that some Arduino-like devices (e.g. ESP32) don't support below 38k4.

MarkMLl


** I know, that's why I put it in quotes.
Just remember that UARTs have 'BAUD' rates and CAN has BitRates.  BAUD is derived from Baudot and 5 bits of data with a start bit and two stop bits.  Now of course we tend to use 8 bits with one start and one stop.  So a Baud rate of 9600 baud means exactly 960 characters per second.  Calling CAN rate a baud rate tells you nothing. 

Pet peeve of mine.  Sorry.... %)



MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #140 on: October 19, 2021, 09:04:23 pm »
A colleague at Lowbrow had had his PhD (possibly at Liverpool) paid for by Ripaults designing a vehicle data bus. He joined at the same time as I did- late '83- which gives some idea of the timeframe... there must have been many companies working on the same thing.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #141 on: October 19, 2021, 09:06:35 pm »
A colleague at Lowbrow had had his PhD (possibly at Liverpool) paid for by Ripaults designing a vehicle data bus. He joined at the same time as I did- late '83- which gives some idea of the timeframe... there must have been many companies working on the same thing.

MarkMLl

I think that's why you see so many busses on the OBD-II connector.  Now I think it's all standardized on CAN and for heavy vehicles J1939.  For the military stuff I worked on it was MilCAN which is still standard J1939 but with some 'rules' of behavior for the messaging.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #142 on: October 19, 2021, 09:07:58 pm »
Yes, I've also seen RS232 on it. Range Rover suspension...

(Later:) I've ordered one of those cheap interfaces and will report back. My suspicion is that that jumper probably ties one side of the data to (USB) ground...

At a pinch I should be able to monitor the bus with my logic analyser, which is good for +-40V :-)

MarkMLl
« Last Edit: October 19, 2021, 09:24:11 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #143 on: October 20, 2021, 02:04:59 pm »
Ground is a fundamental part of the circuit and it's find if you have an arduino or Pi which is also powered from the vehicle 12V power system as at some point the arduino power ground matches up with the vehicle CAN bus ground.
There are galvanic isolated Pi shields like https://www.sg-electronic-systems.com/can-bus-dual-iso-v2-1-shield-for-raspberry/ which help when you must have separate power supply for your equipment. I solve that problem simply by powering Pi from the vehicle (Pi Zero is sufficient for CAN hacking), and then ssh or vnc to Pi from my laptop via WiFi. I even have a 4.3" display and small wireless keyboard for the Pi, but I find laptop access more convenient in 90% of the cases.
« Last Edit: October 20, 2021, 02:13:59 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #144 on: October 20, 2021, 02:18:46 pm »
(Later:) I've ordered one of those cheap interfaces and will report back.
There are AVR, ESP32 and STM32 projects which implement Lawicel protocol, so if at the end you become unsatisfied with your device then you can go DIY path.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #145 on: October 20, 2021, 02:24:11 pm »
(Later:) I've ordered one of those cheap interfaces and will report back.
There are AVR, ESP32 and STM32 projects which implement Lawicel protocol, so if at the end you become unsatisfied with your device then you can go DIY path.

Understood, and the transceiver boards are available cheaply in this country from the usual suspects... unlike cheap USB-connected interfaces. So I'm just trying to think ahead...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #146 on: October 28, 2021, 07:12:46 pm »
... I solve that problem simply by powering Pi from the vehicle (Pi Zero is sufficient for CAN hacking), and then ssh or vnc to Pi from my laptop via WiFi.
Happy me just ordered 2 of these new toys: https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #147 on: November 16, 2021, 11:44:31 am »
(Later:) I've ordered one of those cheap interfaces and will report back. My suspicion is that that jumper probably ties one side of the data to (USB) ground...

The cheap interface (little black box with a blue/white label) has a jumper which controls whether a resistor is across the lines, but neither line is tied to ground unless there's provision for that in the interface chip (SIT1050). The markings on the main chip are obliterated but plugged into an unconfigured Linux system is identified as 10c4:ea60 CP210x (/dev/ttyUSBx).

Spurious rules in 60-gpsd.rules aliased this as a GPS device, I chopped those since I've got several things with one of those chips in it and I don't want anything getting in the way (now all I need to do is re-enable all the gpsd stuff before I forget about it).

I find I need to load a custom module and bring a link up manually, after which I can see an interface:


# modprobe slcan
# slcand -o -c -f -s4 /dev/ttyUSB2 can0
# ip link set can0 up

6: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can


At this point I need to do more research. I'm attached on a one-to-one basis to a device with documented addresses, and I need to read and possibly write some of those. Any suggestions would be appreciated, and I'll post any updates I work out myself.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #148 on: November 24, 2021, 12:33:25 am »
I need to load a custom module and bring a link up manually
That is normal. See https://pascal-walter.blogspot.com/2015/08/installing-lawicel-canusb-on-linux.html

I'm attached on a one-to-one basis to a device with documented addresses, and I need to read and possibly write some of those. Any suggestions would be appreciated
Install can-utils. Although there are other tools you can find if you search through my older messages in this thread, everything needed is already there. It is best if you have CAN messaging docs for your devices, but CAN hacking is not that hard, either. In hacking you try to physically change something on your device and while spying CAN network you try to interpret data changes you see in the messages (CAN data messages are usually heavily bit packed records with no bits wasted and no byte alignment). Without docs it will be hard to guess how to send data to device, so it might be helpful to already have a device which writes to target device. Then all you need is to spy those messages and simply replicate them or try to guess the message data structure when you need to have a variable parameter.

Here is some real life example. Let's say that you're lucky and in your car you have a button without any function attached to it, and you are not satisfied with just 2 speeds for your rain wiper blades. You need to spy the vehicle CAN network (usually there are more CAN networks then just one you access through OBD-II interface), and then look for new messages, or changes in existing messages when you press that button. Then you spy for message which shows when you press button for a single manual rain wiper blade cycle. Now, you should have everything needed to write a program which waits for a single, double, or long click on unused button to set custom interval which will be used for commanding rain wiper blades, and increase or decrease it in case of a need. When everything works the way you want on your Pi, you can program some Arduino like board and leave your custom device permanently in the car.

Happy you, problem solved!  :D :D :D

Now imagine other ideas like protecting your vehicle start up with morse like taps on a button. Sky is the limit.... Have fun!  %) 8) %)

PS: If you do not have unused button in your car, you will probably be able to find a button to which you can safely add double, triple or long click. There are even cheap wireless bluetooth multimedia buttons which you can attach to your wheel or on your dashboard. They can be used as custom additional buttons for your bluetooth Arduino (all ESP microcontrollers have BT) when you can not find any unused button in your car.
« Last Edit: November 24, 2021, 12:50:42 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #149 on: November 24, 2021, 08:25:13 am »
Current situation is that I've been looking through dumps that various other people have captured, but they don't interact with the specific device I've got standalone. I'm in the middle of making a T-cable to tap into a live system, which needs a couple of moderately-expensive connectors: until then I can't be 100% sure that slcan etc. is working properly.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018