Class: MideaAirCondition::PacketBuilder
- Inherits:
-
Object
- Object
- MideaAirCondition::PacketBuilder
- Defined in:
- lib/packet_builder.rb
Overview
This is where we build our packets
Instance Method Summary collapse
- #add_command(command) ⇒ Object
- #add_unknown_section ⇒ Object
- #finalize ⇒ Object
-
#initialize(security) ⇒ PacketBuilder
constructor
A new instance of PacketBuilder.
- #populate_header_data ⇒ Object
Constructor Details
#initialize(security) ⇒ PacketBuilder
Returns a new instance of PacketBuilder.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/packet_builder.rb', line 6 def initialize(security) @security = security @command = [] populate_header_data # Maybe this one is the client id # In a response it's the device id # and the first six bytes are the same @packet += [0xc6, 0x79, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00] add_unknown_section end |
Instance Method Details
#add_command(command) ⇒ Object
20 21 22 23 |
# File 'lib/packet_builder.rb', line 20 def add_command(command) raise Exception, 'Invalid argument' if command.is_a?(Command) @command += command.finalize(@security) end |
#add_unknown_section ⇒ Object
56 57 58 59 60 61 |
# File 'lib/packet_builder.rb', line 56 def add_unknown_section @packet += [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 ] end |
#finalize ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/packet_builder.rb', line 25 def finalize @packet += @command @packet << @security.checksum(@command[1..(@command.length - 1)]) @packet << 0x00 # Add padding + update packet length @packet += [0] * (44 - @command.length) @packet += [0] @packet[0x04] = @packet.length @packet end |
#populate_header_data ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/packet_builder.rb', line 38 def populate_header_data # was always fix for me except the length byte @packet = [0x5a, 0x5a, 0x01, 0x11, 0x5c, 0x00, 0x20, 0x00] # was different for status and power # Set Temp # @packet += [0x12, 0x00, 0x00, 0x00, 0x6f, 0x33, 0x0c, 0x00] # Status # @packet += [0x01, 0x00, 0x00, 0x00, 0x8d, 0x0f, 0x17, 0x02] # Power # @packet += [0x12, 0x00, 0x00, 0x00, 0x6f, 0x33, 0x0c, 0x00] # now just use 0x00 * 8 @packet += [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # was always fix for me @packet += [0x0e, 0x03, 0x12, 0x14] end |