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!

First 6 of 6 Posts Switch mode

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

krisleech
Hey folks, I’ve been using Elixir for over a couple of years (phx, ecto, broadway, oban). For this kind of work you do not tend, in my e...
New
mhindujadheerajsudan
Hi, I’m Dheeraj Sudan from the UK. I’m a software developer and also run a business with my wife Meenu Hinduja. I’m interested in getting...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement