I am not sure I even understand what is going on here with this data, but I am trying to replicate functionality like here, here or here to decode the data I am receiving over UART from my Plantower PMS5003 sensor (see datasheet) sensor in Elixir.
It's delimited by 0x42
and 0x4d
and starts like this:
iex(mygadget@nerves.local)4> {:ok, data} = Circuits.UART.read(pid, 60000)
{:ok,
<<66, 77, 0, 28, 0, 23, 0, 32, 0, 32, 0, 22, 0, 31, 0, 32, 17, 124, 4, 211, 0,
171, 0, 8, 0, 0, 0, 0, 151, 0, 4, 5, 66, 77, 0, 28, 0, 23, 0, 32, 0, 32, 0,
22, 0, 31, 0, 32, ...>>}
I then base16 encode it:
iex(mygadget@nerves.local)5> Base.encode16(data)
"424D001C0017002000200016001F0020117C04D300AB00080000000097000405424D001C0017002000200016001F0020117C04D300AB00080000000097000405424D001C0017001F001F0016001E001F115804BE0098000800
000000970003B5424D001C0018002000200016001F002011BB04D8009F0008000000009700043E424D001C0016001F001F0015001E001F11DC04C3009300080000000097000437424D001C0017001E001E0015001D001E11E20
4C300850008000000009700042C424D001C0016001E001E0015001D001E117304B70087000600000000970003B0424D001C0016001D001D0015001D001D111F049B007B00060000000097000331424D001C0017001E001E0016
001E001E10F5048D007D00060000000097000400424D001C0017001E001E0016001E001E10FB0496008B0004000000009700041B424D001C0016001E001E0015001E001E10B304810089000400000000970003BA424D001C001
5001C001C0014001C001C104A045E008000020000000097000319424D001C0016001C001
And split by 424D
decoded |> String.split("424D")
["", "001C0017002000200016001F0020117C04D300AB00080000000097000405",
"001C0017002000200016001F0020117C04D300AB00080000000097000405",
"001C0017001F001F0016001E001F115804BE0098000800000000970003B5",
"001C0018002000200016001F002011BB04D8009F0008000000009700043E",
Then break it into chunks of 2
iex(mygadget@nerves.local)10> "001C0017002000200016001F0020117C04D300AB00080000000097000405" |> String.codepoints |> Enum.chunk(2) |> Enum.map(&Enum.join/1)
["00", "1C", "00", "17", "00", "20", "00", "20", "00", "16", "00", "1F", "00",
"20", "11", "7C", "04", "D3", "00", "AB", "00", "08", "00", "00", "00", "00",
"97", "00", "04", "05"]
I am fairly at a loss as to where to go from here. I found this discussion about how to do it in Java but I don't really understand what is going on there with the framebuffers.
Any insight appreciated
EDIT: tags