From 0c1c0da8a574dffc73ff850ecd78bf65ad95a7d7 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 8 Dec 2015 13:38:40 -0800 Subject: [PATCH] AIS: More simplifying of packet length/validation code. --- firmware/application/app_ais.cpp | 30 +++++++++++++++--------------- firmware/application/app_ais.hpp | 2 ++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index b222e611..b71463b2 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -183,21 +183,7 @@ size_t Packet::length() const { } bool Packet::is_valid() const { - if( data_and_fcs_length() < 38 ) { - return false; - } - - const size_t extra_bits = data_and_fcs_length() & 7; - if( extra_bits != 0 ) { - return false; - } - - PacketLengthValidator packet_length_valid; - if( !packet_length_valid(message_id(), data_length()) ) { - return false; - } - - return crc_ok(); + return length_valid() && crc_ok(); } rtc::RTC Packet::received_at() const { @@ -279,6 +265,20 @@ size_t Packet::data_length() const { return data_and_fcs_length() - fcs_length; } +bool Packet::length_valid() const { + const size_t extra_bits = data_and_fcs_length() & 7; + if( extra_bits != 0 ) { + return false; + } + + const PacketLengthValidator packet_length_valid; + if( !packet_length_valid(message_id(), data_length()) ) { + return false; + } + + return true; +} + } /* namespace ais */ } /* namespace baseband */ diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index 12e5d60f..74284f6f 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -106,6 +106,8 @@ private: size_t data_and_fcs_length() const; size_t data_length() const; + + bool length_valid() const; }; } /* namespace ais */