-
Notifications
You must be signed in to change notification settings - Fork 9
/
user_code_checksum_report.ex
45 lines (36 loc) · 1.03 KB
/
user_code_checksum_report.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
defmodule Grizzly.ZWave.Commands.UserCodeChecksumReport do
@moduledoc """
What does this command do??
Params:
"""
@behaviour Grizzly.ZWave.Command
import Bitwise
alias Grizzly.ZWave.{Command, DecodeError}
alias Grizzly.ZWave.CommandClasses.UserCode
@type param :: {:checksum, 0x0000..0xFFFF}
@impl Grizzly.ZWave.Command
@spec new([param()]) :: {:ok, Command.t()}
def new(params) do
command = %Command{
name: :user_code_checksum_report,
command_byte: 0x12,
command_class: UserCode,
params: params,
impl: __MODULE__
}
{:ok, command}
end
@impl Grizzly.ZWave.Command
@spec encode_params(Command.t()) :: binary()
def encode_params(command) do
checksum = Command.param!(command, :checksum)
msb = checksum >>> 8
lsb = checksum &&& 0xFF
<<msb::8, lsb::8>>
end
@impl Grizzly.ZWave.Command
@spec decode_params(binary()) :: {:ok, [param()]} | {:error, DecodeError.t()}
def decode_params(<<msb::8, lsb::8>>) do
{:ok, [checksum: msb <<< 8 ||| lsb]}
end
end