-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample_device_location.ex
49 lines (42 loc) · 1 KB
/
example_device_location.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
defmodule Parser do
use Platform.Parsing.Behaviour
require Logger
#
# Example parser for using device location in reading.
#
# Name: Example parser for using the device location
# Changelog:
# 2019-09-30 [jb]: Initial implementation
#
def preloads() do
[device: []]
end
# Using matching
def parse(<<1, 2, 3>>, %{device: %{location: %{coordinates: {lon, lat}}}} = _meta) do
%{
gps_lat: lat,
gps_lon: lon
}
end
# Using get()
def parse(<<1, 2, 3>>, meta) do
%{
gps_lat: get(meta, [:device, :location, :coordinates, 1]),
gps_lon: get(meta, [:device, :location, :coordinates, 0])
}
end
def parse(payload, meta) do
Logger.warn(
"Could not parse payload #{inspect(payload)} with frame_port #{
inspect(get_in(meta, [:meta, :frame_port]))
}"
)
[]
end
def tests() do
[
{:parse_hex, "010203", %{device: %{location: %{coordinates: {9.99, 53.55}}}},
%{gps_lat: 53.55, gps_lon: 9.99}}
]
end
end