hive

hive

Hi Folks,

Does anyone have a good pointer to a guide or tutorial on pattern matching to parse a binary protocol? I’m trying to monitor a serial protocol using Circuits.UART.

Here is an example of the protocol I’m trying to parse: Infinity Framing Protocol · nebulous/infinitude Wiki · GitHub

Thanks!

Showing Posts 1 to 6

tomkonidas

tomkonidas

Shows a nice way by using Mixin module. Highly recommend this talk

hive

hive OP

Thanks! That talk is very useful.

hauleth

hauleth

In this case parsing these messages is ultra easy:

def parse(<<destination_address,
            destination_bus,
            source_address,
            source_bus,
            length,
            pid,
            ext,
            function,
            data::binary-size(length),
            checksum::32>>
) do
  if valid_checksum?(<<destination_address,
            destination_bus,
            source_address,
            source_bus,
            length,
            pid,
            ext,
            function,
            data::binary>>) do
    {:ok, %{
      destination_address: destination_address,
      destination_bus: destination_bus,
      source_address: source_address,
      source_bus: source_bus,
      pid: pid,
      ext: ext,
      function: function,
      data: data
    }}
  else
    {:error, :invalid_checksum}
  end
end

Unfortunately, the spec didn’t specified which CRC16 they meant so I cannot provide that one.

hive

hive OP

Nice. Thank you!

axelson

axelson

Scenic Core Team

Have you seen this blog post?

It’s my goto binary pattern matching blog post.

hive

hive OP

That’s great. Thanks for sharing that post.

— All posts loaded —

Where Next? Top

Trending in Chat/Questions Top

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews