Commit 092e3280 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

Added check to ensure only valid frames can be written, all unit tests now pass.

parent 095266eb
......@@ -33,7 +33,28 @@ module Aprs
end
end
end
frame
return nil
end
private
def self.valid_frame(raw_frame)
frame_len = raw_frame.length
if frame_len > 16
(0...frame_len - 2).each do |raw_slice|
# Is address field length correct?
if raw_frame[raw_slice] & 0x01 != 0 and ((raw_slice + 1) % 7) == 0
i = (raw_slice.to_f + 1.0) / 7.0
# Less than 2 callsigns?
if 1.0 < i and i < 11.0
if raw_frame[raw_slice + 1] & 0x03 == 0x03 and [0xf0, 0xcf].include? raw_frame[raw_slice + 2]
return true
end
end
end
end
end
return false
end
private
......@@ -143,7 +164,9 @@ module Aprs
def write(frame, *args, **kwargs)
@lock.synchronize do
encoded_frame = AprsKiss.encode_frame(frame)
@data_stream.write(encoded_frame, *args, **kwargs)
if AprsKiss.valid_frame(encoded_frame)
@data_stream.write(encoded_frame, *args, **kwargs)
end
end
end
end
......
......@@ -78,6 +78,7 @@ module Aprs
all_raw_frames = kiss_mock.get_sent_to_interface
p all_raw_frames
assert_equal 0, all_raw_frames.length
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment