182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/openc3/interfaces/protocols/template_protocol.rb', line 182
def write_packet(packet)
if @initial_read_delay and @initial_read_delay_needed and @connect_complete_time and Time.now < @connect_complete_time
delay_needed = @connect_complete_time - Time.now
sleep(delay_needed) if delay_needed > 0
end
begin
@response_template = packet.read("RSP_TEMPLATE").strip
@response_packet = packet.read("RSP_PACKET").strip
@response_target_name = packet.target_name
if @response_template.empty? || @response_packet.empty?
@response_template = nil
@response_packet = nil
@response_target_name = nil
end
rescue
@response_template = nil
@response_packet = nil
@response_target_name = nil
end
@template = packet.read("CMD_TEMPLATE")
raw_packet = Packet.new(nil, nil)
raw_packet.buffer = @template
raw_packet = super(raw_packet)
return raw_packet if Symbol === raw_packet
data = raw_packet.buffer(false)
@template.scan(/<(.*?)>/).each do |variable|
value = packet.read(variable[0], :RAW).to_s
data.gsub!("<#{variable[0]}>", value)
@response_packet.gsub!("<#{variable[0]}>", value) if @response_packet
end
return raw_packet
end
|