Merge origin/master

pull/363/head
connor rigby 2017-08-16 10:27:41 -07:00
commit 4740f7ca04
6 changed files with 29 additions and 19 deletions

1
.gitignore vendored
View File

@ -41,6 +41,5 @@ dump.rdb
# this file isnt stored here but just in case. # this file isnt stored here but just in case.
fwup-key.priv fwup-key.priv
.env .env
# secret config stuffs for dev environment. # secret config stuffs for dev environment.
config/auth_secret.exs config/auth_secret.exs

View File

@ -1 +1 @@
5.0.1 5.0.2

View File

@ -31,6 +31,12 @@ defmodule Farmbot.Sequence.Manager do
{:noreply, %{state | context: ctx}} {:noreply, %{state | context: ctx}}
end end
def handle_info({_pid, {:error, ex}}, state) do
debug_log "Sequence error."
send state.caller, {self(), {:error, ex}}
{:stop, :normal, state}
end
def handle_info({:EXIT, _pid, :normal}, %{sequence_pid: _sequence_pid} = state) do def handle_info({:EXIT, _pid, :normal}, %{sequence_pid: _sequence_pid} = state) do
debug_log "Sequence completed successfully." debug_log "Sequence completed successfully."
send state.caller, {self(), state.context} send state.caller, {self(), state.context}
@ -40,7 +46,7 @@ defmodule Farmbot.Sequence.Manager do
def handle_info({:EXIT, _pid, reason}, %{sequence_pid: _sequence_pid} = state) do def handle_info({:EXIT, _pid, reason}, %{sequence_pid: _sequence_pid} = state) do
debug_log "Caught sequence exit error: #{inspect reason}" debug_log "Caught sequence exit error: #{inspect reason}"
send state.caller, {self(), {:error, reason}} send state.caller, {self(), {:error, reason}}
{:stop, reason, state} {:stop, :normal, state}
end end
end end

View File

@ -34,12 +34,10 @@ defmodule Farmbot.Sequence.Runner do
end end
def init({ast, first_context, caller}) do def init({ast, first_context, caller}) do
Process.flag(:trap_exit, true)
debug_log "[#{inspect self()}] Sequence init." debug_log "[#{inspect self()}] Sequence init."
# Setup the firt step # Setup the firt step
[first | rest] = ast.body [first | rest] = ast.body
pid = spawn __MODULE__, :work, [{first, first_context}, self()] pid = spawn __MODULE__, :work, [{first, first_context}, self()]
Process.link(pid)
timer = Process.send_after(:timeout, self(), @step_timeout) timer = Process.send_after(:timeout, self(), @step_timeout)
state = %{ state = %{
body: rest, body: rest,
@ -51,6 +49,12 @@ defmodule Farmbot.Sequence.Runner do
{:ok, state} {:ok, state}
end end
def handle_cast({:error, ex}, state) do
Process.cancel_timer(state.timer)
send(state.caller, {self(), {:error, ex}})
{:stop, :normal, state}
end
# When a stop finishes and there is no more steps # When a stop finishes and there is no more steps
def handle_cast({:finished, next_context}, %{body: []} = state) do def handle_cast({:finished, next_context}, %{body: []} = state) do
Process.cancel_timer(state.timer) Process.cancel_timer(state.timer)
@ -73,14 +77,6 @@ defmodule Farmbot.Sequence.Runner do
{:noreply, new_state} {:noreply, new_state}
end end
def handle_info({:EXIT, _, :normal}, state), do: {:noreply, state}
def handle_info({:EXIT, pid, reason}, %{worker: worker} = state)
when pid == worker do
debug_log "Sequence terminating."
{:stop, reason, state}
end
def handle_info(:timeout, state), do: {:stop, :timeout, %{state | timer: nil}} def handle_info(:timeout, state), do: {:stop, :timeout, %{state | timer: nil}}
@spec work({Ast.t, Context.t}, sequence_pid) :: :ok @spec work({Ast.t, Context.t}, sequence_pid) :: :ok
@ -88,7 +84,12 @@ defmodule Farmbot.Sequence.Runner do
debug_log "[#{inspect self()}] doing work: #{inspect ast}" debug_log "[#{inspect self()}] doing work: #{inspect ast}"
Process.sleep(1000) Process.sleep(1000)
# this might raise. # this might raise.
new_context = do_command(ast, context)
GenServer.cast(sequence, {:finished, new_context}) try do
new_context = do_command(ast, context)
GenServer.cast(sequence, {:finished, new_context})
rescue
e -> GenServer.cast(sequence, {:error, e})
end
end end
end end

View File

@ -396,7 +396,9 @@ defmodule Farmbot.Serial.Handler do
<< "R09", _ :: binary >> -> {:error, :invalid} << "R09", _ :: binary >> -> {:error, :invalid}
# R87 is E stop # R87 is E stop
<< "R87", _ :: binary >> -> {:error, :emergency_lock} << "R87", _ :: binary >> -> {:error, :emergency_lock}
other -> {:error, "unhandled echo: #{other}"} other ->
debug_log "Got an unhandled echo. Expecting: #{writeme} but got: #{echo}"
{:error, "unhandled echo: #{other}"}
end end
end end
@ -457,7 +459,7 @@ defmodule Farmbot.Serial.Handler do
defp handle_done(current, context) do defp handle_done(current, context) do
debug_log "replying to #{inspect current.from} with: #{inspect current.reply}" debug_log "replying to #{inspect current.from} with: #{inspect current.reply}"
Farmbot.BotState.set_busy(context, false) :ok = Farmbot.BotState.set_busy(context, false)
if current.callback do if current.callback do
Process.cancel_timer(current.timer) Process.cancel_timer(current.timer)
handshake = generate_handshake() handshake = generate_handshake()
@ -484,7 +486,6 @@ defmodule Farmbot.Serial.Handler do
@spec handle_gcode(any, Context.t) :: {:status, any} | {:reply, any} | nil @spec handle_gcode(any, Context.t) :: {:status, any} | {:reply, any} | nil
defp handle_gcode(:report_emergency_lock, _), do: {:status, :locked} defp handle_gcode(:report_emergency_lock, _), do: {:status, :locked}
defp handle_gcode(:idle, %Context{} = _ctx), do: {:status, :idle}
defp handle_gcode(:busy, %Context{} = _ctx), do: {:status, :busy} defp handle_gcode(:busy, %Context{} = _ctx), do: {:status, :busy}
defp handle_gcode(:done, %Context{} = _ctx), do: {:status, :done} defp handle_gcode(:done, %Context{} = _ctx), do: {:status, :done}
defp handle_gcode(:received, %Context{} = _ctx), do: {:status, :received} defp handle_gcode(:received, %Context{} = _ctx), do: {:status, :received}
@ -492,6 +493,10 @@ defmodule Farmbot.Serial.Handler do
defp handle_gcode(:report_params_complete, _), do: {:reply, :report_params_complete} defp handle_gcode(:report_params_complete, _), do: {:reply, :report_params_complete}
defp handle_gcode(:noop, %Context{} = _ctx), do: nil defp handle_gcode(:noop, %Context{} = _ctx), do: nil
defp handle_gcode(:idle, %Context{} = ctx) do
:ok = Farmbot.BotState.set_busy(ctx, false)
{:status, :idle}
end
defp handle_gcode({:debug_message, message}, %Context{} = _ctx) do defp handle_gcode({:debug_message, message}, %Context{} = _ctx) do
debug_log "R99 #{message}" debug_log "R99 #{message}"
nil nil

View File

@ -23,7 +23,6 @@ h2 {
text-align: center; text-align: center;
} }
.portal-problem-note { .portal-problem-note {
display: block;
margin: auto; margin: auto;
width: 75%; width: 75%;
text-align: center; text-align: center;