Class: Cosmos::PreidentifiedProtocol
- Inherits:
-
BurstProtocol
- Object
- Protocol
- BurstProtocol
- Cosmos::PreidentifiedProtocol
- Defined in:
- lib/cosmos/interfaces/protocols/preidentified_protocol.rb
Overview
Delineates packets using the COSMOS preidentification system
Constant Summary collapse
- COSMOS4_STORED_FLAG_MASK =
0x80
- COSMOS4_EXTRA_FLAG_MASK =
0x40
Instance Attribute Summary
Attributes inherited from Protocol
Instance Method Summary collapse
-
#initialize(sync_pattern = nil, max_length = nil, mode = 4, allow_empty_data = nil) ⇒ PreidentifiedProtocol
constructor
A new instance of PreidentifiedProtocol.
- #read_packet(packet) ⇒ Object
- #reset ⇒ Object
- #write_data(data) ⇒ Object
- #write_packet(packet) ⇒ Object
Methods inherited from BurstProtocol
#handle_sync_pattern, #log_discard, #read_data
Methods inherited from Protocol
#connect_reset, #disconnect_reset, #post_write_interface, #read_data
Constructor Details
#initialize(sync_pattern = nil, max_length = nil, mode = 4, allow_empty_data = nil) ⇒ PreidentifiedProtocol
Returns a new instance of PreidentifiedProtocol.
31 32 33 34 35 36 |
# File 'lib/cosmos/interfaces/protocols/preidentified_protocol.rb', line 31 def initialize(sync_pattern = nil, max_length = nil, mode = 4, allow_empty_data = nil) super(0, sync_pattern, false, allow_empty_data) @max_length = ConfigParser.handle_nil(max_length) @max_length = Integer(@max_length) if @max_length @mode = Integer(mode) end |
Instance Method Details
#read_packet(packet) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cosmos/interfaces/protocols/preidentified_protocol.rb', line 43 def read_packet(packet) packet.received_time = @read_received_time packet.target_name = @read_target_name packet.packet_name = @read_packet_name if @mode == 4 # COSMOS4.3+ Protocol packet.stored = @read_stored packet.extra = @read_extra end return packet end |
#reset ⇒ Object
38 39 40 41 |
# File 'lib/cosmos/interfaces/protocols/preidentified_protocol.rb', line 38 def reset super() @reduction_state = :START end |
#write_data(data) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cosmos/interfaces/protocols/preidentified_protocol.rb', line 75 def write_data(data) data_length = [data.length].pack('N') # UINT32 data_to_send = '' data_to_send << @sync_pattern if @sync_pattern if @mode == 4 # COSMOS4.3+ Protocol data_to_send << @write_flags if @write_extra data_to_send << [@write_extra.length].pack('N') data_to_send << @write_extra end end data_to_send << @write_time_seconds data_to_send << @write_time_microseconds data_to_send << @write_target_name.length data_to_send << @write_target_name data_to_send << @write_packet_name.length data_to_send << @write_packet_name data_to_send << data_length data_to_send << data return data_to_send end |
#write_packet(packet) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cosmos/interfaces/protocols/preidentified_protocol.rb', line 54 def write_packet(packet) received_time = packet.received_time received_time = Time.now unless received_time @write_time_seconds = [received_time.tv_sec].pack('N') # UINT32 @write_time_microseconds = [received_time.tv_usec].pack('N') # UINT32 @write_target_name = packet.target_name @write_target_name = 'UNKNOWN' unless @write_target_name @write_packet_name = packet.packet_name @write_packet_name = 'UNKNOWN' unless @write_packet_name if @mode == 4 # COSMOS4.3+ Protocol @write_flags = 0 @write_flags |= COSMOS4_STORED_FLAG_MASK if packet.stored @write_extra = nil if packet.extra @write_flags |= COSMOS4_EXTRA_FLAG_MASK @write_extra = packet.extra.to_json end end return packet end |