Move firmware naming convetions into their own module
parent
3306e331a8
commit
c8da9d880e
|
@ -9,6 +9,7 @@ defimpl FarmbotCore.AssetWorker, for: FarmbotCore.Asset.FbosConfig do
|
|||
require FarmbotCore.Logger
|
||||
alias FarmbotCeleryScript.AST
|
||||
alias FarmbotCore.{Asset.FbosConfig, BotState, Config}
|
||||
import FarmbotFirmware.PackageUtils, only: [package_to_string: 1]
|
||||
|
||||
@firmware_flash_attempt_threshold Application.get_env(:farmbot_core, __MODULE__)[:firmware_flash_attempt_threshold]
|
||||
@firmware_flash_attempt_threshold || Mix.raise """
|
||||
|
@ -110,7 +111,7 @@ defimpl FarmbotCore.AssetWorker, for: FarmbotCore.Asset.FbosConfig do
|
|||
|> FarmbotCeleryScript.execute(make_ref())
|
||||
|
||||
new_hardware != old_hardware ->
|
||||
FarmbotCore.Logger.warn 1, "Firmware hardware change from #{old_hardware} to #{new_hardware} flashing firmware"
|
||||
FarmbotCore.Logger.warn 1, "Firmware hardware change from #{package_to_string(old_hardware)} to #{package_to_string(new_hardware)} flashing firmware"
|
||||
new_hardware
|
||||
|> fbos_config_to_flash_firmware_rpc()
|
||||
|> FarmbotCeleryScript.execute(make_ref())
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
defmodule FarmbotFirmware.PackageUtils do
|
||||
@doc "Returns the absolute path to the hex file assosiated with `package`"
|
||||
def find_hex_file(package)
|
||||
|
||||
def find_hex_file("arduino") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "arduino_firmware.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
def find_hex_file("farmduino") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "farmduino.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
def find_hex_file("farmduino_k14") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "farmduino_k14.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
def find_hex_file("express_k10") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "express_k10.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
def find_hex_file(hardware) when is_binary(hardware),
|
||||
do: {:error, "unknown firmware hardware: #{hardware}"}
|
||||
|
||||
def find_hex_file(hardware)
|
||||
|
||||
@doc "Returns the human readable string describing `package`"
|
||||
def package_to_string(package)
|
||||
|
||||
def package_to_string("arduino"),
|
||||
do: "Arduino/RAMPS (Genesis v1.2)"
|
||||
|
||||
def package_to_string("farmduino"),
|
||||
do: "Farmduino (Genesis v1.3)"
|
||||
|
||||
def package_to_string("farmduino_k14"),
|
||||
do: "Farmduino (Genesis v1.4)"
|
||||
|
||||
def package_to_string("express_k10"),
|
||||
do: "Farmduino (Express v1.0)"
|
||||
|
||||
def package_to_string(package),
|
||||
do: package
|
||||
|
||||
defp assert_exists(fname) do
|
||||
if File.exists?(fname) do
|
||||
{:ok, fname}
|
||||
else
|
||||
{:error,
|
||||
"""
|
||||
File does not exist: #{fname}
|
||||
The arduino firmware is a git submodule to the farmbot project.
|
||||
Please call `make arudino_firmware`.
|
||||
"""}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,11 +2,12 @@ defmodule FarmbotOS.SysCalls.FlashFirmware do
|
|||
alias FarmbotCore.{Asset, Asset.Private}
|
||||
alias FarmbotFirmware
|
||||
alias FarmbotCore.FirmwareTTYDetector
|
||||
import FarmbotFirmware.PackageUtils, only: [find_hex_file: 1, package_to_string: 1]
|
||||
require FarmbotCore.Logger
|
||||
require Logger
|
||||
|
||||
def flash_firmware(package) do
|
||||
FarmbotCore.Logger.busy(2, "Starting firmware flash for package: #{package}")
|
||||
FarmbotCore.Logger.busy(2, "Flashing #{package_to_string(package)} firmware")
|
||||
|
||||
with {:ok, hex_file} <- find_hex_file(package),
|
||||
{:ok, tty} <- find_tty(),
|
||||
|
@ -45,25 +46,6 @@ defmodule FarmbotOS.SysCalls.FlashFirmware do
|
|||
end
|
||||
end
|
||||
|
||||
defp find_hex_file("arduino") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "arduino_firmware.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
defp find_hex_file("farmduino") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "farmduino.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
defp find_hex_file("farmduino_k14") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "farmduino_k14.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
defp find_hex_file("express_k10") do
|
||||
Application.app_dir(:farmbot_firmware, ["priv", "express_k10.hex"]) |> assert_exists()
|
||||
end
|
||||
|
||||
defp find_hex_file(hardware) when is_binary(hardware),
|
||||
do: {:error, "unknown firmware hardware: #{hardware}"}
|
||||
|
||||
defp find_reset_fun(_) do
|
||||
config = Application.get_env(:farmbot_firmware, FarmbotFirmware.UARTTransport)
|
||||
|
||||
|
@ -73,17 +55,4 @@ defmodule FarmbotOS.SysCalls.FlashFirmware do
|
|||
{:ok, fn -> :ok end}
|
||||
end
|
||||
end
|
||||
|
||||
defp assert_exists(fname) do
|
||||
if File.exists?(fname) do
|
||||
{:ok, fname}
|
||||
else
|
||||
{:error,
|
||||
"""
|
||||
File does not exist: #{fname}
|
||||
The arduino firmware is a git submodule to the farmbot project.
|
||||
Please call `make arudino_firmware`.
|
||||
"""}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue