Merge origin/master
commit
4740f7ca04
|
@ -41,6 +41,5 @@ dump.rdb
|
|||
# this file isnt stored here but just in case.
|
||||
fwup-key.priv
|
||||
.env
|
||||
|
||||
# secret config stuffs for dev environment.
|
||||
config/auth_secret.exs
|
||||
|
|
|
@ -31,6 +31,12 @@ defmodule Farmbot.Sequence.Manager do
|
|||
{:noreply, %{state | context: ctx}}
|
||||
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
|
||||
debug_log "Sequence completed successfully."
|
||||
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
|
||||
debug_log "Caught sequence exit error: #{inspect reason}"
|
||||
send state.caller, {self(), {:error, reason}}
|
||||
{:stop, reason, state}
|
||||
{:stop, :normal, state}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -34,12 +34,10 @@ defmodule Farmbot.Sequence.Runner do
|
|||
end
|
||||
|
||||
def init({ast, first_context, caller}) do
|
||||
Process.flag(:trap_exit, true)
|
||||
debug_log "[#{inspect self()}] Sequence init."
|
||||
# Setup the firt step
|
||||
[first | rest] = ast.body
|
||||
pid = spawn __MODULE__, :work, [{first, first_context}, self()]
|
||||
Process.link(pid)
|
||||
timer = Process.send_after(:timeout, self(), @step_timeout)
|
||||
state = %{
|
||||
body: rest,
|
||||
|
@ -51,6 +49,12 @@ defmodule Farmbot.Sequence.Runner do
|
|||
{:ok, state}
|
||||
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
|
||||
def handle_cast({:finished, next_context}, %{body: []} = state) do
|
||||
Process.cancel_timer(state.timer)
|
||||
|
@ -73,14 +77,6 @@ defmodule Farmbot.Sequence.Runner do
|
|||
{:noreply, new_state}
|
||||
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}}
|
||||
|
||||
@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}"
|
||||
Process.sleep(1000)
|
||||
# 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
|
||||
|
|
|
@ -396,7 +396,9 @@ defmodule Farmbot.Serial.Handler do
|
|||
<< "R09", _ :: binary >> -> {:error, :invalid}
|
||||
# R87 is E stop
|
||||
<< "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
|
||||
|
||||
|
@ -457,7 +459,7 @@ defmodule Farmbot.Serial.Handler do
|
|||
|
||||
defp handle_done(current, context) do
|
||||
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
|
||||
Process.cancel_timer(current.timer)
|
||||
handshake = generate_handshake()
|
||||
|
@ -484,7 +486,6 @@ defmodule Farmbot.Serial.Handler do
|
|||
@spec handle_gcode(any, Context.t) :: {:status, any} | {:reply, any} | nil
|
||||
|
||||
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(:done, %Context{} = _ctx), do: {:status, :done}
|
||||
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(: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
|
||||
debug_log "R99 #{message}"
|
||||
nil
|
||||
|
|
|
@ -23,7 +23,6 @@ h2 {
|
|||
text-align: center;
|
||||
}
|
||||
.portal-problem-note {
|
||||
display: block;
|
||||
margin: auto;
|
||||
width: 75%;
|
||||
text-align: center;
|
||||
|
|
Loading…
Reference in New Issue