Class: Driver::Datecs::Dp25::Frame

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ Frame

Returns a new instance of Frame.



300
301
302
303
304
305
306
307
308
309
310
311
# File 'app/models/extface/driver/datecs/dp25.rb', line 300

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.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def bcc
  @bcc
end

#cmdObject (readonly)

Returns the value of attribute cmd.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def cmd
  @cmd
end

#dataObject (readonly)

Returns the value of attribute data.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def data
  @data
end

#frameObject (readonly)

Returns the value of attribute frame.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def frame
  @frame
end

#lenObject (readonly)

Returns the value of attribute len.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def len
  @len
end

#seqObject (readonly)

Returns the value of attribute seq.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def seq
  @seq
end

#statusObject (readonly)

Returns the value of attribute status.



294
295
296
# File 'app/models/extface/driver/datecs/dp25.rb', line 294

def status
  @status
end

Class Method Details

.bcc(buffer) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
# File 'app/models/extface/driver/datecs/dp25.rb', line 337

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)


313
# File 'app/models/extface/driver/datecs/dp25.rb', line 313

def ack?; !!@ack; end

#nak?Boolean

should retry command with same seq

Returns:

  • (Boolean)


315
# File 'app/models/extface/driver/datecs/dp25.rb', line 315

def nak?; !!@nak; end