Giter Site home page Giter Site logo

canserial's Introduction

CanSerial

Serial port emulation over CAN bus. Working on Raspberry Pi with MCP2515 module. Main goal - emulate serial port to use tiny external modules together with Klipper controller for 3D-printers https://github.com/KevinOConnor/klipper

Adding CAN bus to Raspberry Pi completely described here https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=141052

Protocol

Only Base Frame format (CAN 2.0 B) implemented. Master node periodically sends frame with ID 0x321 and zero length as UUID request. Slave node responds to this frame with ID 0x323, containing 6 bytes of unique serial number. Master will check local dictionary and responds with ID 0x322, containig port number. After receiving port number slave node should ignore next UUID requests and accepts only frames with id 0x17F+(2 x PortNumber)

After assigning port to slave, Emulator creates /tmp/ttyCANxx node emulating serial port.

Build procedure

git clone [email protected]:Delsian/CanSerial.git
cd CanSerial
cmake .
make
./canserial

If you get "Socket init error: xxx" - check your CAN configuration.

Run CanSerial as service

$ sudo cp canserial.service /lib/systemd/system/canserial.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable canserial.service
$ sudo systemctl start canserial.service

canserial's People

Contributors

delsian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

canserial's Issues

Readme.md protocol is not the same as implemented. ID assignment cause canbus collisions.

In Readme.md it states that nodes should use id 0x17F+(2 x PortNumber). Neither the klipper code or this canserial code does that, they use 0x180+PortNumber, and 0x180+PortNumber+1 as a response ID.
Since they do not do that "x 2" and the CAN nodes responds to the host using canid+1 there will be ID collisions on the CAN bus if nodes get port numbers next to each other. Collisions leads to all kind of problems.

A very ugly small fix is a change in cansocket.c in ConfigurePort():

-       // port number + ID offset
-       int portid = PnGetNumber(frame.data);
+       // (port number*2) + ID offset
+       int portid = PnGetNumber(frame.data)*2;

Easiest is probably to fix this issue in canserial and leave the STM32 code alone.
I will make a better fix...

Are you still planning on maintaining this code? It's been a while since last modification

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.