Elixir:模块 Platform.Parsing.Behaviour 未加载且无法找到

发布于 2025-01-12 22:44:34 字数 3860 浏览 1 评论 0原文


I try to fix the compiler error:

** (CompileError) main.exs:2: 模块 Platform.Parsing.Behaviour 未加载且无法找到 (elixir 1.12.2)扩展宏:Kernel.use/1 main.exs:2:解析器(模块)

您有解决这个问题的想法吗?
提前致谢 :)!

我不知道如何解决这个问题。

defmodule Parser do
  use Platform.Parsing.Behaviour
  require Logger

  # LPP_TEMP (Devicetype 0x0010)
  defp parse_payload(device_type, 0x01, <<temperature::signed-16>>)
       when device_type in [0x0010] do
    %{temperature: temperature * 10}
    |> Map.merge(parse_temperature(temperature))
  end

  # LPP_CO2 (Devicetype 0x0012)
  defp parse_payload(device_type, 0x01, <<co2::signed-16>>)
       when device_type in [0x0012] do
    %{co2: co2 / 1}
    |> Map.merge(parse_co(CO2))
  end

  # LPP_RHUM (Devicetype 0x0011)
  defp parse_payload(device_type, 0x01, <<lpp_rhum::signed-8>>)
       when device_type in [0x0011] do
    %{lpp_rhum: lpp_rhum}
    |> Map.merge(parse_rhum(lpp_rhum))
  end

  # LPP_VOC (Devicetype 0x0013)
  defp parse_payload(device_type, 0x01, <<lpp_voc::signed-16>>)
       when device_type in [0x0013] do
    %{lpp_voc: lpp_voc}
    |> Map.merge(parse_voc(lpp_voc))
  end

  # LPP_ATM_P (Devicetype 0x0030)
  defp parse_payload(device_type, 0x01, <<lpp_atm::signed-16>>)
       when device_type in [0x0030] do
    %{lpp_atm_p: lpp_atm_p}
    |> Map.merge(parse_atmp(lpp_atm_p))
  end

  # LPP_DP (Devicetype 0x0031)
  defp parse_payload(device_type, 0x01, <<lpp_dp::signed-16>>)
       when device_type in [0x0031] do
    %{lpp_dp: lpp_dp}
    |> Map.merge(parse_dp(lpp_dp))
  end

  # lpp_flow (Devicetype 0x0032)
  defp parse_payload(device_type, 0x01, <<lpp_flow::signed-16>>)
       when device_type in [0x0032] do
    %{lpp_flow: lpp_flow}
    |> Map.merge(parse_flow(lpp_flow))
  end

  # lpp_visible_light (Devicetype 0x0040)
  defp parse_payload(device_type, 0x01, <<lpp_visible_light::signed-16>>)
       when device_type in [0x0040] do
    %{lpp_visible_light: lpp_visible_light}
    |> Map.merge(parse_light(lpp_visible_light))
  end

  # lpp_vbat (Devicetype 0x0054)
  defp parse_payload(device_type, 0x01, <<lpp_vbat::signed-8>>)
       when device_type in [0x0054] do
    %{lpp_vbat: lpp_vbat}
    |> Map.merge(parse_vbat(lpp_vbat))
  end

  defp parse_payload(_device_type, _report_type, payload) do
    %{unknown_payload: Base.encode16(payload)}
  end

  defp parse_temperature(<<temperature::signed-16>>, field \\ :temperature, factor \\ 0.10) do
    %{field => temperature * factor}
  end

  defp parse_co(<<co2::signed-16>>, field \\ :CO2, factor \\ 1.0) do
    %{field => CO2 * factor}
  end

  defp parse_rhum(<<lpp_rhum::signed-8>>, field \\ :lpp_rhum, factor \\ 1.0) do
    %{field => lpp_RHUM * factor}
  end

  defp parse_voc(<<lpp_voc::signed-16>>, field \\ :lpp_voc, factor \\ 1.0) do
    %{field => lpp_VOC * factor}
  end

  defp parse_atmp(<<lpp_atm_p::signed-16>>, field \\ :lpp_atm_p, factor \\ 1.0) do
    %{field => lpp_atm_p * factor}
  end

  defp parse_dp(<<lpp_dp::signed-16>>, field \\ :lpp_dp, factor \\ 1.0) do
    %{field => lpp_dp * factor}
  end

  defp parse_flow(<<lpp_flow::signed-16>>, field \\ :lpp_flow, factor \\ 1.0) do
    %{field => lpp_flow * factor}
  end

  defp parse_light(<<lpp_visible_light::signed-16>>, field \\ :lpp_visible_light, factor \\ 1.0) do
    %{field => lpp_visible_light * factor}
  end

  defp parse_vbat(<<lpp_vbat::signed-8>>, field \\ :lpp_vbat, factor \\ 0.05) do
    %{field => lpp_vbat * factor}
  end

  def fields() do
    [...out of this example...]
  end
end

I try to fix the compiler error:

** (CompileError) main.exs:2: module Platform.Parsing.Behaviour is not loaded and could not be found
(elixir 1.12.2) expanding macro: Kernel.use/1
main.exs:2: Parser (module)

Do you have an idea to fix that?
Thanks in advance :)!

I don't have any idea, how to fix that.

defmodule Parser do
  use Platform.Parsing.Behaviour
  require Logger

  # LPP_TEMP (Devicetype 0x0010)
  defp parse_payload(device_type, 0x01, <<temperature::signed-16>>)
       when device_type in [0x0010] do
    %{temperature: temperature * 10}
    |> Map.merge(parse_temperature(temperature))
  end

  # LPP_CO2 (Devicetype 0x0012)
  defp parse_payload(device_type, 0x01, <<co2::signed-16>>)
       when device_type in [0x0012] do
    %{co2: co2 / 1}
    |> Map.merge(parse_co(CO2))
  end

  # LPP_RHUM (Devicetype 0x0011)
  defp parse_payload(device_type, 0x01, <<lpp_rhum::signed-8>>)
       when device_type in [0x0011] do
    %{lpp_rhum: lpp_rhum}
    |> Map.merge(parse_rhum(lpp_rhum))
  end

  # LPP_VOC (Devicetype 0x0013)
  defp parse_payload(device_type, 0x01, <<lpp_voc::signed-16>>)
       when device_type in [0x0013] do
    %{lpp_voc: lpp_voc}
    |> Map.merge(parse_voc(lpp_voc))
  end

  # LPP_ATM_P (Devicetype 0x0030)
  defp parse_payload(device_type, 0x01, <<lpp_atm::signed-16>>)
       when device_type in [0x0030] do
    %{lpp_atm_p: lpp_atm_p}
    |> Map.merge(parse_atmp(lpp_atm_p))
  end

  # LPP_DP (Devicetype 0x0031)
  defp parse_payload(device_type, 0x01, <<lpp_dp::signed-16>>)
       when device_type in [0x0031] do
    %{lpp_dp: lpp_dp}
    |> Map.merge(parse_dp(lpp_dp))
  end

  # lpp_flow (Devicetype 0x0032)
  defp parse_payload(device_type, 0x01, <<lpp_flow::signed-16>>)
       when device_type in [0x0032] do
    %{lpp_flow: lpp_flow}
    |> Map.merge(parse_flow(lpp_flow))
  end

  # lpp_visible_light (Devicetype 0x0040)
  defp parse_payload(device_type, 0x01, <<lpp_visible_light::signed-16>>)
       when device_type in [0x0040] do
    %{lpp_visible_light: lpp_visible_light}
    |> Map.merge(parse_light(lpp_visible_light))
  end

  # lpp_vbat (Devicetype 0x0054)
  defp parse_payload(device_type, 0x01, <<lpp_vbat::signed-8>>)
       when device_type in [0x0054] do
    %{lpp_vbat: lpp_vbat}
    |> Map.merge(parse_vbat(lpp_vbat))
  end

  defp parse_payload(_device_type, _report_type, payload) do
    %{unknown_payload: Base.encode16(payload)}
  end

  defp parse_temperature(<<temperature::signed-16>>, field \\ :temperature, factor \\ 0.10) do
    %{field => temperature * factor}
  end

  defp parse_co(<<co2::signed-16>>, field \\ :CO2, factor \\ 1.0) do
    %{field => CO2 * factor}
  end

  defp parse_rhum(<<lpp_rhum::signed-8>>, field \\ :lpp_rhum, factor \\ 1.0) do
    %{field => lpp_RHUM * factor}
  end

  defp parse_voc(<<lpp_voc::signed-16>>, field \\ :lpp_voc, factor \\ 1.0) do
    %{field => lpp_VOC * factor}
  end

  defp parse_atmp(<<lpp_atm_p::signed-16>>, field \\ :lpp_atm_p, factor \\ 1.0) do
    %{field => lpp_atm_p * factor}
  end

  defp parse_dp(<<lpp_dp::signed-16>>, field \\ :lpp_dp, factor \\ 1.0) do
    %{field => lpp_dp * factor}
  end

  defp parse_flow(<<lpp_flow::signed-16>>, field \\ :lpp_flow, factor \\ 1.0) do
    %{field => lpp_flow * factor}
  end

  defp parse_light(<<lpp_visible_light::signed-16>>, field \\ :lpp_visible_light, factor \\ 1.0) do
    %{field => lpp_visible_light * factor}
  end

  defp parse_vbat(<<lpp_vbat::signed-8>>, field \\ :lpp_vbat, factor \\ 0.05) do
    %{field => lpp_vbat * factor}
  end

  def fields() do
    [...out of this example...]
  end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文