hive

hive

Wanted: Tutorial on Pattern Matching to parse a binary protocol

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!

Most Liked

axelson

axelson

Scenic Core Team

Have you seen this blog post?

It’s my goto binary pattern matching blog post.

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.

tomkonidas

tomkonidas

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

Last Post!

hive

hive

That’s great. Thanks for sharing that post.

Where Next?

Popular in Chat/Questions Top

ericmachine88
Hi all, I am currently on this course https://www.ludu.co/course/discover-elixir-phoenix Half a way thru, and struggled a bit.. someti...
New
Santheepkumar
Hi all, I am a Fullstack JS developer for last 2 years. I need a good guide to learn elixer. Any suggestions please
New
dopomecana
The title of this topic may sound silly at the first glance. But why I trying to ask you guys is how to go to the next level? I am curre...
New
zeroexcuses
Besides https://elixir-lang.org/getting-started/basic-types.html are there any other well recommended “elixir by example” style resources...
New
TwistingTwists
I want to learn DSL. Don’t know how to write one. What;s the best introductory resource? I see some macro being used here. Is DSL only ...
New
shansiddiqui94
Hello all, I recently did my first app in Phoenix and Liveview, many thanks to all the users who assisted me. I found that the tutorial ...
New
lgmfred
Hello, I want to get started with elixir today. Having learnt the basics of Erlang (my first ever language) and seen what it’s can do, I’...
New

Other popular topics Top

ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement