Remove VCR playback functionality for now

This has never been helpful to me so i don't feel bad.
pull/974/head
Connor Rigby 2019-09-12 11:18:38 -07:00
parent c570a20c71
commit 812a11aac1
No known key found for this signature in database
GPG Key ID: 29A88B24B70456E0
2 changed files with 0 additions and 97 deletions

View File

@ -1,63 +0,0 @@
defmodule FarmbotFirmware.VCR do
@moduledoc """
Helpers for working with Firmware tapes
"""
alias FarmbotFirmware.GCODE
@doc "Convert a .txt file to Elixir terms"
def to_elixir!(path) do
File.stream!(path)
|> Stream.map(&split_decode/1)
|> Enum.to_list()
end
@doc "Play a tape back on a server"
def playback!(path, firmware_server \\ FarmbotFirmware) do
path
|> to_elixir!()
|> Enum.reject(fn
{:in, _timestamp, _type, _code} -> true
{:out, _timestamp, _type, _code} -> false
end)
|> Enum.each(fn {:out, _timestamp, type, code} ->
apply(FarmbotFirmware, type, [firmware_server, code])
end)
end
defp split_decode(data) do
data
|> do_split()
|> do_decode()
end
defp do_split(data) do
data
|> String.trim()
|> String.split(" ")
end
defp do_decode([direction, timestamp | rest]) do
direction = decode_direction(direction)
timestamp = decode_timestamp(timestamp)
case GCODE.decode(Enum.join(rest, " ")) do
{_, {kind, _args}} = code
when kind not in [
:parameter_read,
:status_read,
:pin_read,
:end_stops_read,
:position_read,
:software_version_read
] ->
{direction, timestamp, :command, code}
code ->
{direction, timestamp, :request, code}
end
end
defp decode_direction("<"), do: :in
defp decode_direction(">"), do: :out
defp decode_timestamp(timestamp), do: String.to_integer(timestamp)
end

View File

@ -1,34 +0,0 @@
defmodule FarmbotFirmware.VCRTest do
use ExUnit.Case
alias FarmbotFirmware.StubTransport
alias FarmbotFirmware.VCR
test "saves a vcr when starting a server" do
vcr_path = path()
{:ok, server} = FarmbotFirmware.start_link([transport: StubTransport, vcr_path: vcr_path], [])
:ok = FarmbotFirmware.exit_vcr_mode(server)
assert File.exists?(vcr_path)
end
test "saves a vcr at runtime" do
vcr_path = path()
{:ok, server} = FarmbotFirmware.start_link([transport: StubTransport], [])
refute File.exists?(vcr_path)
:ok = FarmbotFirmware.enter_vcr_mode(server, vcr_path)
:ok = FarmbotFirmware.exit_vcr_mode(server)
assert File.exists?(vcr_path)
end
test "plays back a vcr" do
vcr_path = path()
{:ok, server} = FarmbotFirmware.start_link([transport: StubTransport, vcr_path: vcr_path], [])
FarmbotFirmware.command(server, {:pin_write, [p: 13, v: 1]})
FarmbotFirmware.request(server, {:pin_read, [p: 13]})
:ok = FarmbotFirmware.exit_vcr_mode(server)
VCR.playback!(vcr_path)
end
defp path do
"/tmp/#{:os.system_time()}.vcr.txt"
end
end