Class: Prremote::Commands::Undeploy

Inherits:
Object
  • Object
show all
Defined in:
lib/prremote/commands/undeploy.rb

Constant Summary collapse

ERASE_MAGIC =
'ERSE'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(port:, baud:) ⇒ Undeploy

Returns a new instance of Undeploy.



6
7
8
9
# File 'lib/prremote/commands/undeploy.rb', line 6

def initialize(port:, baud:)
  @port = port
  @baud = baud
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/prremote/commands/undeploy.rb', line 11

def call
  serial = Serial.new(@port, @baud)
  serial.write("\x03")

  # \x03 may trigger a watchdog reboot (if a script was running).
  # wait_for_ready returns the active serial (original or reopened).
  serial = wait_for_ready(serial)

  serial.write(ERASE_MAGIC)
  wait_for_erased(serial)
  warn 'Flash erased. Device will no longer auto-run a script on boot.'
ensure
  begin
    serial&.close
  rescue StandardError
    nil
  end
end