Class: Driver::Datecs::Dp35::Frame

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/extface/driver/datecs/dp35.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ Frame

Returns a new instance of Frame.



320
321
322
323
324
325
326
327
328
329
330
331
# File 'app/models/extface/driver/datecs/dp35.rb', line 320

def initialize(buffer)
  if match = buffer.match(/\x01(.{1})(.{1})(.{1})(.*)\x04(.{6})\x05(.{4})\x03/nm)
    @frame = match.to_a.first
    @len, @seq, @cmd, @data, @status, @bcc = match.captures
  else
    if buffer[/^\x16+$/] # only ACKs
      @ack = true
    elsif buffer.index("\x15")
      @nak = true
    end
  end
end

Instance Attribute Details

#bccObject (readonly)

Returns the value of attribute bcc.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def bcc
  @bcc
end

#cmdObject (readonly)

Returns the value of attribute cmd.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def cmd
  @cmd
end

#dataObject (readonly)

Returns the value of attribute data.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def data
  @data
end

#frameObject (readonly)

Returns the value of attribute frame.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def frame
  @frame
end

#lenObject (readonly)

Returns the value of attribute len.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def len
  @len
end

#seqObject (readonly)

Returns the value of attribute seq.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def seq
  @seq
end

#statusObject (readonly)

Returns the value of attribute status.



314
315
316
# File 'app/models/extface/driver/datecs/dp35.rb', line 314

def status
  @status
end

Class Method Details

.bcc(buffer) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
# File 'app/models/extface/driver/datecs/dp35.rb', line 357

def bcc(buffer)
  sum = 0
  buffer.each_byte do |byte|
    sum += byte
  end
  "".tap() do |bcc|
    4.times do |halfbyte|
      bcc.insert 0, (0x30 + ((sum >> (halfbyte*4)) & 0x0f)).chr
    end
  end
end

Instance Method Details

#ack?Boolean

should wait, response is yet to come

Returns:

  • (Boolean)


333
# File 'app/models/extface/driver/datecs/dp35.rb', line 333

def ack?; !!@ack; end

#nak?Boolean

should retry command with same seq

Returns:

  • (Boolean)


335
# File 'app/models/extface/driver/datecs/dp35.rb', line 335

def nak?; !!@nak; end