Class: FirmwareHomie
- Inherits:
-
File
- Object
- File
- FirmwareHomie
- Defined in:
- lib/hodmin/hodmin_tools.rb
Overview
Defines a class for storing all attributes of a Homie-firmware. Check kind of esp8266-firmware: Homie (>= V.2.0 because of magic bytes) Homie: see github.com/marvinroger/homie-esp8266 Returns hash with fw-details if <filename> includes magic bytes, returns empty hash if doesn’t
Instance Attribute Summary collapse
-
#checksum ⇒ Object
readonly
Returns the value of attribute checksum.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#fw_brand ⇒ Object
readonly
Returns the value of attribute fw_brand.
-
#fw_name ⇒ Object
readonly
Returns the value of attribute fw_name.
-
#fw_version ⇒ Object
readonly
Returns the value of attribute fw_version.
Instance Method Summary collapse
- #homie? ⇒ Boolean
-
#initialize(filename) ⇒ FirmwareHomie
constructor
Initialize a firmware-file for Homie-device.
Constructor Details
#initialize(filename) ⇒ FirmwareHomie
Initialize a firmware-file for Homie-device. File is recognized by so called Homie-patterns (strings in binary file) that can be injected through sourcecode. Possible patterns are firmware-name, firmware-version and firmware-brand.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hodmin/hodmin_tools.rb', line 29 def initialize(filename) @firmware_homie = false return unless homie_firmware?(filename) @file_path = filename @firmware_homie = true binfile = IO.binread(filename) @checksum = Digest::MD5.hexdigest(binfile) binfile = binfile.unpack('H*').first fw_name_pattern = ["\xbf\x84\xe4\x13\x54".unpack('H*').first, "\x93\x44\x6b\xa7\x75".unpack('H*').first] fw_version_pattern = ["\x6a\x3f\x3e\x0e\xe1".unpack('H*').first, "\xb0\x30\x48\xd4\x1a".unpack('H*').first] fw_brand_pattern = ["\xfb\x2a\xf5\x68\xc0".unpack('H*').first, "\x6e\x2f\x0f\xeb\x2d".unpack('H*').first] @fw_brand = @fw_name = @fw_version = '<none>' # find Firmware-Branding @fw_brand = fw_brand_pattern.find_pattern(binfile) # find Firmware-Name: @fw_name = fw_name_pattern.find_pattern(binfile) # find Firmware-Version: @fw_version = fw_version_pattern.find_pattern(binfile) Log.log.info "FW found: #{@fw_name}, #{@fw_version}, #{@checksum}" end |
Instance Attribute Details
#checksum ⇒ Object (readonly)
Returns the value of attribute checksum.
24 25 26 |
# File 'lib/hodmin/hodmin_tools.rb', line 24 def checksum @checksum end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
24 25 26 |
# File 'lib/hodmin/hodmin_tools.rb', line 24 def file_path @file_path end |
#fw_brand ⇒ Object (readonly)
Returns the value of attribute fw_brand.
24 25 26 |
# File 'lib/hodmin/hodmin_tools.rb', line 24 def fw_brand @fw_brand end |
#fw_name ⇒ Object (readonly)
Returns the value of attribute fw_name.
24 25 26 |
# File 'lib/hodmin/hodmin_tools.rb', line 24 def fw_name @fw_name end |
#fw_version ⇒ Object (readonly)
Returns the value of attribute fw_version.
24 25 26 |
# File 'lib/hodmin/hodmin_tools.rb', line 24 def fw_version @fw_version end |
Instance Method Details
#homie? ⇒ Boolean
52 53 54 |
# File 'lib/hodmin/hodmin_tools.rb', line 52 def homie? @firmware_homie end |