class CresIP::SerialData

Constants

Encodings

Attributes

header[R]
payload[R]

Public Class Methods

new(header, payload) click to toggle source
# File lib/cresip/serial.rb, line 7
def initialize(header, payload)
    @header = header
    @payload = payload

    @value = parse_serial_data(payload.bytes)
end

Public Instance Methods

type() click to toggle source
# File lib/cresip/serial.rb, line 16
def type
    @header.type
end

Protected Instance Methods

parse_serial_data(bytes) click to toggle source
# File lib/cresip/serial.rb, line 28
def parse_serial_data(bytes)
    len = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3]
    join = 1 + (bytes[5] << 8) + bytes[6]
    encoding = bytes[7]
    string = bytes[8...(len + 4)].pack('c*')
    enc = Encodings[encoding]

    # Not sure if this will work as don't have any sample data.
    # Reference: https://github.com/ironiridis/control4go/blob/master/crestron/packets.go#L149
    string.force_encoding(enc) if enc
end