Class: OpenC3::LincHandshake

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/interfaces/linc_interface.rb

Overview

The LincHandshake class is used only by the LincInterface. It processes the handshake and helps with finding the information regarding the internal command.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handshake, interface_target_name) ⇒ LincHandshake

Returns a new instance of LincHandshake.



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/openc3/interfaces/linc_interface.rb', line 400

def initialize(handshake, interface_target_name)
  @handshake = handshake

  # Interpret the command field of the handshake packet
  # Where DATA is defined as:
  # 1 byte target name length
  # X byte target name
  # 1 byte packet name length
  # X byte packet name
  # 4 byte packet data length
  # X byte packet data
  # 4 byte error source length
  # X byte error source
  data = handshake.read('DATA')
  raise "Data field too short for target name length" if data.length == 0

  # Get target name length
  target_name_length = data[0..0].unpack('C')[0]
  raise "Invalid target name length" if target_name_length == 0

  data = data[1..-1]

  # get target name
  raise "Data field too short for target name" if data.length < target_name_length

  # target_name = data[0..(target_name_length - 1)] # Unused
  data = data[target_name_length..-1]

  # get packet name length
  raise "Data field too short for packet name length" if data.length == 0

  packet_name_length = data[0..0].unpack('C')[0]
  raise "Invalid packet name length" if packet_name_length == 0

  data = data[1..-1]

  # get packet name
  raise "Data field too short for packet name" if data.length < packet_name_length

  packet_name = data[0..(packet_name_length - 1)]
  data = data[packet_name_length..-1]

  # get packet data length
  raise "Data field too short for packet data length" if data.length < 4

  packet_data_length = data[0..3].unpack('N')[0]
  raise "Invalid data length" if packet_data_length == 0

  data = data[4..-1]

  # get packet data
  raise "Data field too short for packet data" if data.length < packet_data_length

  packet_data = data[0..(packet_data_length - 1)]
  data = data[packet_data_length..-1]

  # get error source length
  raise "Data field too short for error source length" if data.length < 4

  error_source_length = data[0..3].unpack('N')[0]
  # note it is OK to have a 0 source length
  data = data[4..-1]

  # get error source - store on object
  if error_source_length > 0
    @error_source = data[0..(error_source_length - 1)]
  else
    @error_source = ''
  end

  # make packet - store on object as a defined packet of type command that this handshakes
  @identified_command = System.commands.packet(interface_target_name, packet_name).clone
  @identified_command.buffer = packet_data
  @identified_command.received_time = Time.at(handshake.read('TIME_SECONDS'), handshake.read('TIME_MICROSECONDS')).sys
end

Instance Attribute Details

#error_sourceObject

Returns the value of attribute error_source.



398
399
400
# File 'lib/openc3/interfaces/linc_interface.rb', line 398

def error_source
  @error_source
end

#handshakeObject

Returns the value of attribute handshake.



396
397
398
# File 'lib/openc3/interfaces/linc_interface.rb', line 396

def handshake
  @handshake
end

#identified_commandObject

Returns the value of attribute identified_command.



397
398
399
# File 'lib/openc3/interfaces/linc_interface.rb', line 397

def identified_command
  @identified_command
end

Instance Method Details

#get_cmd_guid(fieldname_guid) ⇒ Object



476
477
478
# File 'lib/openc3/interfaces/linc_interface.rb', line 476

def get_cmd_guid(fieldname_guid)
  return @identified_command.read(fieldname_guid)
end