Giter VIP home page Giter VIP logo

elixir-fwup's Introduction

Fwup

CircleCI Hex version

Simple Elixir wrapper around FWUP

Usage

With a file on the filesystem:

iex()> fw = "/path/to/fwup_file.fw"
iex()> [[dev, _size]] = Fwup.devices()
iex()> {:ok, pid} = Fwup.apply(dev, "upgrade", fw)
iex()> flush
iex()> {:fwup, {:progress, 0}}
iex()> {:fwup, {:progress, 100}}
iex()> {:fwup, {:ok, 0, ""}}

With a Elixir File.stream:

iex()> fw = "/path/to/fwup_file.fw"
iex()> [[dev, _size]] = Fwup.devices()
iex()> args = ["-a", "-t", "complete", "-d", dev]
iex()> {:ok, fwup} = Fwup.stream(self(), args)
iex()> File.stream!(fw, [:bytes], 4096)
iex..>  |> Stream.map(fn chunk ->
iex..>    Fwup.send_chunk(fwup, chunk)
iex..>  end)
iex..>  |> Stream.run()
iex()> flush()
{:progress, 0}
{:progress, 1}
# many more
{:progress, 100}
{:ok, 0, ""}

Installation

If available in Hex, the package can be installed by adding fwup to your list of dependencies in mix.exs:

def deps do
  [
    {:fwup, "~> 1.0.1"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/fwup.

elixir-fwup's People

Contributors

connorrigby avatar fhunleth avatar jthacker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

elixir-fwup's Issues

Implement exit handshaking to avoid dropping final messages

There's a race condition between Erlang processing the exit code and it processing the messages that get sent to it. For example, fwup can fail and send an error message up. fwup will exit after it does this, but Erlang may handle the process exit first and lose the error message. That's not helpful.

The fix to this is to pass the --exit-handshake option to fwup. If this is done, then after fwup reports OK or ER, it will sent a CTRL+Z character (this part doesn't matter with framing), and then it will call read() and wait for Erlang to send something back to it. That's the handshake. All Erlang needs to do is send a byte (anything works) back to fwup after it gets an OK or ER. Then fwup will exit knowing that Erlang safely got the error or success message.

To summarize, the change is:

  1. Pass --exit-handshake when calling fwup
  2. Send a character to the port after receiving an OK or ER

After sending the character, it's ok to finish up completely. I don't think there's a need to wait for fwup to exit since you'll know that the exit code is 0 if the last message is OK or 1 if ER. Also, closing the port will also satisfy the handshake from fwup's point of view.

Another note is that it would be really bad for fwup to exit without sending an OK or ER. That would be a bad bug in fwup if that ever happens, so it's worth adding an ugly log message blaming fwup.

Support giving fwup a file and letting it use it directly

Since fwup can process a file path directly, it would be nice to use that rather than asking users to do something like:

{:ok, fwup} = Fwup.stream(self(), args)

new_firmwmare_path
|> File.stream!([:bytes], 4096)
|> Stream.map(fn chunk ->
   Fwup.send_chunk(fwup, chunk)
end)
|> Stream.run()

This should also be faster.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.