Class: OpenC3::PreidentifiedProtocol
Overview
Delineates packets using the OpenC3 preidentification system
Constant Summary
collapse
- COSMOS4_STORED_FLAG_MASK =
0x80
0x40
Instance Attribute Summary
Attributes inherited from Protocol
#allow_empty_data, #interface
Instance Method Summary
collapse
#handle_sync_pattern, #log_discard, #read_data
Methods inherited from Protocol
#connect_reset, #disconnect_reset, #post_write_interface, #protocol_cmd, #read_data
Constructor Details
#initialize(sync_pattern = nil, max_length = nil, mode = 4, allow_empty_data = nil) ⇒ PreidentifiedProtocol
34
35
36
37
38
39
|
# File 'lib/openc3/interfaces/protocols/preidentified_protocol.rb', line 34
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
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/openc3/interfaces/protocols/preidentified_protocol.rb', line 46
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 packet.stored = @read_stored
packet. = @read_extra
end
return packet
end
|
41
42
43
44
|
# File 'lib/openc3/interfaces/protocols/preidentified_protocol.rb', line 41
def reset
super()
@reduction_state = :START
end
|
#write_data(data) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/openc3/interfaces/protocols/preidentified_protocol.rb', line 78
def write_data(data)
data_length = [data.length].pack('N') data_to_send = ''
data_to_send << @sync_pattern if @sync_pattern
if @mode == 4 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/openc3/interfaces/protocols/preidentified_protocol.rb', line 57
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') @write_time_microseconds = [received_time.tv_usec].pack('N') @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 @write_flags = 0
@write_flags |= COSMOS4_STORED_FLAG_MASK if packet.stored
@write_extra = nil
if packet.
@write_flags |= COSMOS4_EXTRA_FLAG_MASK
@write_extra = packet..as_json(:allow_nan => true).to_json(:allow_nan => true)
end
end
return packet
end
|