Class: Cosmos::LincHandshake
- Defined in:
- lib/cosmos/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
-
#error_source ⇒ Object
Returns the value of attribute error_source.
-
#handshake ⇒ Object
Returns the value of attribute handshake.
-
#identified_command ⇒ Object
Returns the value of attribute identified_command.
Instance Method Summary collapse
- #get_cmd_guid(fieldname_guid) ⇒ Object
-
#initialize(handshake, interface_target_name) ⇒ LincHandshake
constructor
A new instance of LincHandshake.
Constructor Details
#initialize(handshake, interface_target_name) ⇒ LincHandshake
Returns a new instance of LincHandshake.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/cosmos/interfaces/linc_interface.rb', line 348 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')) end |
Instance Attribute Details
#error_source ⇒ Object
Returns the value of attribute error_source.
346 347 348 |
# File 'lib/cosmos/interfaces/linc_interface.rb', line 346 def error_source @error_source end |
#handshake ⇒ Object
Returns the value of attribute handshake.
344 345 346 |
# File 'lib/cosmos/interfaces/linc_interface.rb', line 344 def handshake @handshake end |
#identified_command ⇒ Object
Returns the value of attribute identified_command.
345 346 347 |
# File 'lib/cosmos/interfaces/linc_interface.rb', line 345 def identified_command @identified_command end |
Instance Method Details
#get_cmd_guid(fieldname_guid) ⇒ Object
415 416 417 |
# File 'lib/cosmos/interfaces/linc_interface.rb', line 415 def get_cmd_guid(fieldname_guid) return @identified_command.read(fieldname_guid) end |