Skip to content
Permalink
Browse files

Merge pull request #1107 from FarmBot/qa/firmware_fixes_ii

v9.0.1-rc2
  • Loading branch information
RickCarlino committed Jan 9, 2020
2 parents b33be76 + 5c04f54 commit fd9886f23c5285dab3efd61c052e49ba7694cf05
@@ -1 +1 @@
9.0.1-rc1
9.0.1-rc2
@@ -27,7 +27,7 @@ defmodule FarmbotCore.FirmwareSideEffects do

@impl FarmbotFirmware.SideEffects
def handle_axis_timeout(axis) do
FarmbotCore.Logger.error 1, "Axis #{axis} timed out waiting for movement to complete"
FarmbotCore.Logger.error(1, "Axis #{axis} timed out waiting for movement to complete")
:noop
end

@@ -48,7 +48,7 @@ defmodule FarmbotCore.FirmwareSideEffects do

# this is a bug in the firmware code i think
def handle_encoders_scaled([]), do: :noop

@impl FarmbotFirmware.SideEffects
def handle_encoders_raw(x: x, y: y, z: z) do
:ok = BotState.set_encoders_raw(x, y, z)
@@ -64,6 +64,7 @@ defmodule FarmbotCore.FirmwareSideEffects do
%{param => value}
|> Asset.update_firmware_config!()
|> Asset.Private.mark_dirty!(%{})

:ok
end

@@ -75,27 +76,33 @@ defmodule FarmbotCore.FirmwareSideEffects do
@impl FarmbotFirmware.SideEffects
def handle_software_version([version]) do
:ok = BotState.set_firmware_version(version)

case String.split(version, ".") do
# Ramps
[_, _, _, "R"] ->
_ = Leds.red(:solid)
:ok = BotState.set_firmware_hardware("arduino")

# Farmduino
[_, _, _, "F"] ->
_ = Leds.red(:solid)
:ok = BotState.set_firmware_hardware("farmduino")

# Farmduino V14
[_, _, _, "G"] ->
_ = Leds.red(:solid)
:ok = BotState.set_firmware_hardware("farmduino_k14")

# Farmduino V15
[_, _, _, "H"] ->
_ = Leds.red(:solid)
:ok = BotState.set_firmware_hardware("farmduino_k15")

# Express V10
[_, _, _, "E"] ->
_ = Leds.red(:solid)
:ok = BotState.set_firmware_hardware("express_k10")

[_, _, _, "S"] ->
_ = Leds.red(:slow_blink)
:ok = BotState.set_firmware_version("none")
@@ -159,7 +166,7 @@ defmodule FarmbotCore.FirmwareSideEffects do
@impl FarmbotFirmware.SideEffects
def handle_debug_message([message]) do
fbos_config = Asset.fbos_config()
should_log? = fbos_config.firmware_debug_log || fbos_config.arduino_debug_messages
should_log? = fbos_config.firmware_debug_log || fbos_config.arduino_debug_messages
should_log? && FarmbotCore.Logger.debug(3, "Firmware debug message: " <> message)
end

@@ -37,7 +37,7 @@ defmodule FarmbotExt.JWT do
{:ok, jwt}
else
:error -> {:error, "base64_decode_fail"}
{:error, _resson} -> {:error, "json_decode_error"}
{:error, _reason} -> {:error, "json_decode_error"}
end
end

@@ -241,7 +241,7 @@ defmodule FarmbotFirmware do
args = Keyword.merge(args, global)
transport = Keyword.fetch!(args, :transport)
side_effects = Keyword.get(args, :side_effects)
reset = Keyword.fetch!(args, :reset)
reset = Keyword.get(args, :reset) || __MODULE__

vcr_fd =
case Keyword.get(args, :vcr_path) do
@@ -290,6 +290,11 @@ defmodule FarmbotFirmware do
Logger.debug("Firmware reset #{state.reset} started. #{inspect(state.transport_args)}")
{:noreply, %{state | reset_pid: pid}}

# TODO(Rick): I have no idea what's going on here.
{:error, {:already_started, pid}} ->
Logger.debug("Firmware reset complete. #{inspect(state.transport_args)}")
{:noreply, %{state | reset_pid: pid}}

error ->
Logger.error("Error starting Firmware Reset: #{inspect(error)}")
Process.send_after(self(), :timeout, @transport_init_error_retry_ms)
@@ -631,15 +636,15 @@ defmodule FarmbotFirmware do
{:noreply, goto(state, :busy)}
end

def handle_report({:report_error, []} = code, %{status: :configuration} = state) do
def handle_report({:report_error, _} = code, %{status: :configuration} = state) do
if state.caller_pid, do: send(state.caller_pid, {state.tag, code})
for {pid, _code} <- state.command_queue, do: send(pid, {state.tag, {:report_busy, []}})

side_effects(state, :handle_busy, [false])
{:stop, {:error, state.current}, state}
end

def handle_report({:report_error, []} = code, state) do
def handle_report({:report_error, _} = code, state) do
if state.caller_pid, do: send(state.caller_pid, {state.tag, code})
for {pid, _code} <- state.command_queue, do: send(pid, {state.tag, {:report_busy, []}})

@@ -46,7 +46,7 @@ defmodule FarmbotFirmware.Command do
debug_log("#{GCODE.encode(code)} position change")
wait_for_command_result(tag, code, retries, error)

{_, {:report_error, []}} ->
{_, {:report_error, _}} ->
debug_log("#{GCODE.encode(code)} firmware error")
if err, do: {:error, err}, else: {:error, :firmware_error}

@@ -91,6 +91,10 @@ defmodule FarmbotFirmware.GCODE.Decoder do
def decode_error(["V14"]), do: [:invalid_command]
def decode_error(["V15"]), do: [:no_config]
def decode_error([unk]), do: [unknown_error: unk]
# TODO(Rick): This is a guess. Can be removed if
# better solution is found.
# FarmBot/farmbot_os/issues/1105#issuecomment-572381069
def decode_error(unk), do: [unknown_error: [unk]]

defp decode_floats(list, acc \\ [])

@@ -8,7 +8,10 @@ defmodule FarmbotFirmware.GCODE.Encoder do
def do_encode(:report_idle, []), do: "R00"
def do_encode(:report_begin, []), do: "R01"
def do_encode(:report_success, []), do: "R02"
def do_encode(:report_error, []), do: "R03"
# TODO(Rick): Why are some `:report_error`s sending
# tuples instead of lists??
# https://github.com/FarmBot/farmbot_os/issues/1105#issuecomment-572381069
def do_encode(:report_error, _), do: "R03"
def do_encode(:report_busy, []), do: "R04"

def do_encode(:report_axis_state, xyz), do: "R05 " <> encode_axis_state(xyz)
@@ -84,6 +87,7 @@ defmodule FarmbotFirmware.GCODE.Encoder do

def do_encode(:command_emergency_unlock, _), do: "F09"
def do_encode(:command_emergency_lock, _), do: "E"
def do_encode(), do: "R03"

@spec encode_floats([{Param.t(), float()}]) :: binary()
defp encode_floats(args) do
@@ -65,7 +65,7 @@ defmodule FarmbotFirmware.Request do
do: {:ok, {tag, result}},
else: wait_for_request_result(tag, code, result)

{_, {:report_error, []}} ->
{_, {:report_error, _}} ->
{:error, :firmware_error}

{_, {:report_invalid, []}} ->
@@ -14,7 +14,7 @@ defmodule FarmbotFirmware.UARTTransport do
def init(args) do
device = Keyword.fetch!(args, :device)
handle_gcode = Keyword.fetch!(args, :handle_gcode)
reset = Keyword.fetch!(args, :reset)
reset = Keyword.get(args, :reset)
{:ok, uart} = UART.start_link()
{:ok, %{uart: uart, device: device, open: false, handle_gcode: handle_gcode, reset: reset}, 0}
end

0 comments on commit fd9886f

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