Sha256: 49a5c9612fde988b00b4c4615268f246bbd7ff34581674548fecff84ad5d5506

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module MaxCube
  module Messages
    module TCP
      class Parser
        module MessageN
          private

          KEYS = %i[device_type rf_address serial_number unknown].freeze

          # New device (pairing) message
          def parse_tcp_n(body)
            @io = StringIO.new(decode(body), 'rb')

            {
              device_type: device_type(read(1, true)),
              rf_address: read(3, true),
              serial_number: read(10),
              unknown: read(1),
            }
          rescue IOError
            raise InvalidMessageBody
              .new(@msg_type, 'unexpected EOF reached')
          end
        end
      end

      class Serializer
        module MessageN
          private

          OPT_KEYS = %i[timeout].freeze

          # Command to set the Cube into pairing mode
          # with optional +timeout+ in seconds
          def serialize_tcp_n(hash)
            return '' unless hash.key?(:timeout)
            format('%04x', to_int(0, 'timeout', hash[:timeout]))
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maxcube-client-0.4.1 lib/maxcube/messages/tcp/type/n.rb
maxcube-client-0.4.0 lib/maxcube/messages/tcp/type/n.rb