class MicroAethAE51::Message

Creates and parses messages to and from the MicroAeth. See MicroAeth::Com for specifications on the transmiting of messages.

Attributes

original_char_string[RW]

Public Class Methods

new(data) click to toggle source

@param data [String] conents between the `STX` “x02”

and the `ETX` "0x03"
# File lib/micro_aeth-ae51.rb, line 60
def initialize data
  raise "invalid data" unless data_valid? data
  @original_char_string = data
  parse_data( data[7..-1])
end

Private Instance Methods

data_valid?(d) click to toggle source
# File lib/micro_aeth-ae51.rb, line 67
def data_valid? d
  crc = d[-1]
  data = d[1..-2]
  len = d[0]
  (data ^ len).byte == crc.byte
end
parse_data(d) click to toggle source
# File lib/micro_aeth-ae51.rb, line 73
def parse_data d
  b = d.bytes
  @ref = d[0..2].unpack("v")[0]
  @sen1 = d[3..5].unpack("v")[0]
  @sen2 = d[6..8].unpack("v")[0]
  @flow = d[9..10].unpack("v")[0]
  @pcb_temp = b[11]
  @time = Time.new ('20' + b[12].to_s).to_i,
                   b[13],
                   b[14],
                   b[15],
                   b[16],
                   b[17]
  @status = b[18]
  @battery = d[19..20].unpack("v")[0]
end