Skip to content
Permalink
Browse files

Update uart code to use circuits_uart instead of nerves_uart

  • Loading branch information...
ConnorRigby committed Apr 8, 2019
1 parent 2133ba5 commit fbee9ca955e6d6c764ae2f880653cf23e0244d9a
Showing with 19 additions and 20 deletions.
  1. +15 −15 lib/farmbot/firmware/uart_handler/uart_handler.ex
  2. +4 −4 lib/farmbot/firmware/uart_handler/update.ex
  3. +0 −1 mix.lock
@@ -199,10 +199,10 @@ defmodule Farmbot.Firmware.UartHandler do
do
Logger.debug 3, "Waiting for firmware idle."
receive do
{:nerves_uart, _, {:error, reason}} -> {:stop, reason}
{:nerves_uart, _, {:partial, _}} -> loop_until_idle(nerves, idle_count)
{:nerves_uart, _, {_, :idle}} -> loop_until_idle(nerves, idle_count + 1)
{:nerves_uart, _, {_, {:debug_message, msg}}} ->
{:circuits_uart, _, {:error, reason}} -> {:stop, reason}
{:circuits_uart, _, {:partial, _}} -> loop_until_idle(nerves, idle_count)
{:circuits_uart, _, {_, :idle}} -> loop_until_idle(nerves, idle_count + 1)
{:circuits_uart, _, {_, {:debug_message, msg}}} ->
if String.contains?(msg, "STARTUP") do
Logger.success 3, "Got #{msg}. UART is up."
UART.write(nerves, "F22 P2 V0")
@@ -211,7 +211,7 @@ defmodule Farmbot.Firmware.UartHandler do
Logger.debug 3, "Got arduino debug while booting up: #{msg}"
loop_until_idle(nerves, idle_count)
end
{:nerves_uart, _, _msg} -> loop_until_idle(nerves, idle_count)
{:circuits_uart, _, _msg} -> loop_until_idle(nerves, idle_count)
after
10_000 -> {:stop, "Firmware didn't send any info for 10 seconds."}
end
@@ -236,25 +236,25 @@ defmodule Farmbot.Firmware.UartHandler do

# if there is an error, we assume something bad has happened, and we probably
# Are better off crashing here, and being restarted.
def handle_info({:nerves_uart, _, {:error, :eio}}, state) do
def handle_info({:circuits_uart, _, {:error, :eio}}, state) do
Logger.error 1, "UART device removed."
old_env = Application.get_env(:farmbot, :behaviour)
new_env = Keyword.put(old_env, :firmware_handler, Firmware.StubHandler)
Application.put_env(:farmbot, :behaviour, new_env)
{:stop, {:error, :eio}, state}
end

def handle_info({:nerves_uart, _, {:error, reason}}, state) do
def handle_info({:circuits_uart, _, {:error, reason}}, state) do
{:stop, {:error, reason}, state}
end

# Unhandled gcodes just get ignored.
def handle_info({:nerves_uart, _, {:unhandled_gcode, code_str}}, state) do
def handle_info({:circuits_uart, _, {:unhandled_gcode, code_str}}, state) do
Logger.debug 3, "Got unhandled gcode: #{code_str}"
{:noreply, [], state}
end

def handle_info({:nerves_uart, _, {_, {:report_software_version, v}}}, state) do
def handle_info({:circuits_uart, _, {_, {:report_software_version, v}}}, state) do
expected = Application.get_env(:farmbot, :expected_fw_versions)
if v in expected do
{:noreply, [{:report_software_version, v}], state}
@@ -268,14 +268,14 @@ defmodule Farmbot.Firmware.UartHandler do
end
end

def handle_info({:nerves_uart, _, {:echo, _}}, %{current_cmd: nil} = state) do
def handle_info({:circuits_uart, _, {:echo, _}}, %{current_cmd: nil} = state) do
{:noreply, [], state}
end
def handle_info({:nerves_uart, _, {:echo, {:echo, "*F43" <> _}}}, state) do
def handle_info({:circuits_uart, _, {:echo, {:echo, "*F43" <> _}}}, state) do
{:noreply, [], state}
end

def handle_info({:nerves_uart, _, {:echo, {:echo, code}}}, state) do
def handle_info({:circuits_uart, _, {:echo, {:echo, code}}}, state) do
distance = String.jaro_distance(state.current_cmd, code)
if distance > 0.85 do
:ok
@@ -286,15 +286,15 @@ defmodule Farmbot.Firmware.UartHandler do
{:noreply, [], %{state | current_cmd: nil}}
end

def handle_info({:nerves_uart, _, {_q, :done}}, state) do
def handle_info({:circuits_uart, _, {_q, :done}}, state) do
{:noreply, [:done], %{state | current_cmd: nil, config_busy: false}}
end

def handle_info({:nerves_uart, _, {_q, gcode}}, state) do
def handle_info({:circuits_uart, _, {_q, gcode}}, state) do
{:noreply, [gcode], state}
end

def handle_info({:nerves_uart, _, bin}, state) when is_binary(bin) do
def handle_info({:circuits_uart, _, bin}, state) when is_binary(bin) do
Logger.warn(3, "Unparsed Gcode: #{bin}")
{:noreply, [], state}
end
@@ -50,9 +50,9 @@ defmodule Farmbot.Firmware.UartHandler.Update do

defp do_fw_loop(uart, tty, flag, hardware) do
receive do
{:nerves_uart, _, {:error, reason}} ->
{:circuits_uart, _, {:error, reason}} ->
Logger.error 1, "Failed to connect to firmware for update during idle step: #{inspect reason}"
{:nerves_uart, _, data} ->
{:circuits_uart, _, data} ->
if String.contains?(data, "R00") do
case flag do
:idle ->
@@ -77,9 +77,9 @@ defmodule Farmbot.Firmware.UartHandler.Update do

defp do_wait_version(uart, tty, hardware) do
receive do
{:nerves_uart, _, {:error, reason}} ->
{:circuits_uart, _, {:error, reason}} ->
Logger.error 1, "Failed to connect to firmware for update: #{inspect reason}"
{:nerves_uart, _, data} ->
{:circuits_uart, _, data} ->
case String.split(data, "R83 ") do
[_] ->
# IO.puts "got data: #{data}"
@@ -71,7 +71,6 @@
"nerves_toolchain_arm_unknown_linux_gnueabihf": {:hex, :nerves_toolchain_arm_unknown_linux_gnueabihf, "1.1.0", "ca466a656f8653346a8551a35743f7c41046f3d53e945723e970cb4a7811e617", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.5.0", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_toolchain_armv6_rpi_linux_gnueabi": {:hex, :nerves_toolchain_armv6_rpi_linux_gnueabi, "1.1.0", "2753102e667d9778047b351618f3dfdc016b81148df58d142fee7630d96a31fe", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.5.0", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.5.0", "34b8f5664858ff6ce09730b26221441398acd1fa361b8c6d744d9ec18238c16b", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_uart": {:hex, :nerves_uart, "1.2.1", "ae3247e14915f79dde7d4f450ad4c0d4bdc7ab505e3d7c4d4799ac1121e0b505", [:mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_wpa_supplicant": {:hex, :nerves_wpa_supplicant, "0.5.2", "4ec392fc08faf35f50d1070446c2e5019f6b85bd53f5716f904e3f75716d9596", [:make, :mix], [{:elixir_make, "~> 0.5", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"one_dhcpd": {:hex, :one_dhcpd, "0.2.1", "421ff729bd90e245ff54f7ee2b09ca1f9c2d5983eb7723561c0d43df5673e553", [:make, :mix], [{:elixir_make, "~> 0.5", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},

0 comments on commit fbee9ca

Please sign in to comment.
You can’t perform that action at this time.