Skip to content

🦘 Gleam bindings for SocketCAN communication on Linux

License

Notifications You must be signed in to change notification settings

DaanVervacke/cangaroo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦘 cangaroo

Package Version Hex Docs

cangaroo provides Gleam bindings to the Excansock Elixir library, enabling Gleam applications to communicate with SocketCAN devices on Linux.

gleam add cangaroo@1

Start GenServer and open socket

import cangaroo
import gleam/io

pub fn main() {
  let assert Ok(client) = cangaroo.start_link("can0")

  io.println("Connected!")
}

Sending frames

import cangaroo
import cangaroo/types.{CanFrame}

pub fn main() {
  let assert Ok(client) = cangaroo.start_link("can0")

  let frame = CanFrame(id: 0x123, data: <<0x01, 0x02, 0x03, 0x04>>)

  let assert Ok(Nil) = cangaroo.send(client, frame)
}

Receiving frames

import cangaroo
import cangaroo/types
import gleam/erlang/process

pub fn main() {
  let assert Ok(client) = cangaroo.start_link("can0")

  let messages = types.messages(client)

  let selector =
    process.new_selector()
    |> process.select(for: messages)

  let frame = process.selector_receive_forever(from: selector)
  // do something with the frame
}

Running tests

Run as root to setup the virtual can interface.

sudo gleam test

About

🦘 Gleam bindings for SocketCAN communication on Linux

Resources

License

Stars

Watchers

Forks