cangaroo/types

Type definitions for cangaroo.

This module defines the core types used throughout cangaroo for representing CAN sockets, clients, frames, and filters. The main types you’ll interact with are:

Types

Internal message type used by the CAN client actor.

These messages are handled internally by cangaroo and are not typically used directly by application code.

  • RawCanData: Contains raw CAN frame data received from the bus
  • Shutdown: Signals the actor to close the socket and stop
pub type ActorMessage {
  RawCanData(frame_data: dynamic.Dynamic)
  Shutdown
}

Constructors

An opaque type representing an active CAN client connection.

A CanClient is the primary handle for interacting with a CAN interface. It encapsulates:

  • The underlying CAN socket connection
  • An OTP actor that handles incoming frames
  • A subject for receiving CAN frames in your application

Create a client using cangaroo.start_link() and close it with cangaroo.close() when you’re done.

To receive incoming CAN frames, use the messages() function to get the subject, then select on it with gleam/erlang/process selectors.

pub opaque type CanClient

Defines a filter for receiving certain CAN frames.

Filters control which CAN frames are delivered to your application. Each filter has two components:

  • id: The CAN identifier to match against
  • mask: A bitmask that determines which bits of the ID must match

A frame passes the filter if: (frame_id & mask) == (filter_id & mask)

Example

import cangaroo/types

// Exact match for ID 0x123 (all 11 bits must match)
let exact = types.CanFilter(id: 0x123, mask: 0x7FF)

// Match IDs 0x100-0x1FF (upper 3 bits must be 0x1)
let range = types.CanFilter(id: 0x100, mask: 0x700)

// Accept all frames (no filtering)
let accept_all = types.CanFilter(id: 0x000, mask: 0x000)
pub type CanFilter {
  CanFilter(id: Int, mask: Int)
}

Constructors

  • CanFilter(id: Int, mask: Int)

Represents a CAN frame with an identifier and data payload.

A CAN frame is the basic unit of communication on a CAN bus. Each frame contains:

  • id: The CAN identifier, either 11-bit (standard length) or 29-bit (extended)
  • data: The payload as a BitArray, up to 8 bytes for standard CAN

Example

import cangaroo/types

// Create a frame with ID 0x123 and 4 bytes of data
let frame = types.CanFrame(id: 0x123, data: <<0x01, 0x02, 0x03, 0x04>>)
pub type CanFrame {
  CanFrame(id: Int, data: BitArray)
}

Constructors

  • CanFrame(id: Int, data: BitArray)

An opaque type representing a CAN socket connection.

This type wraps the underlying Excansock process and is managed internally by CanClient. You typically don’t interact with CanSocket directly, use CanClient and the functions in the main cangaroo module instead.

pub opaque type CanSocket

Values

Search Document