From 8a30003ab64b5fd75098668441f6e188c3808fd0 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 13 Jan 2016 22:27:30 -0800 Subject: [PATCH] Move entry update code into AISRecentEntry. --- firmware/application/ais_app.cpp | 75 +++++++++++++++++--------------- firmware/application/ais_app.hpp | 2 + 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index 0ae14318..28ef4b0d 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -99,6 +99,44 @@ void AISLogger::on_packet(const ais::Packet& packet) { } } +void AISRecentEntry::update(const ais::Packet& packet) { + received_count++; + + switch(packet.message_id()) { + case 1: + case 2: + case 3: + navigational_status = packet.read(38, 4); + last_position.timestamp = packet.received_at(); + last_position.latitude = packet.latitude(89); + last_position.longitude = packet.longitude(61); + break; + + case 4: + // packet.datetime(38) + last_position.timestamp = packet.received_at(); + last_position.latitude = packet.latitude(107); + last_position.longitude = packet.longitude(79); + break; + + case 5: + call_sign = packet.text(70, 7); + name = packet.text(112, 20); + destination = packet.text(302, 20); + break; + + case 21: + name = packet.text(43, 20); + last_position.timestamp = packet.received_at(); + last_position.latitude = packet.latitude(192); + last_position.longitude = packet.longitude(164); + break; + + default: + break; + } +} + void AISRecentEntries::on_packet(const ais::Packet& packet) { const auto source_id = packet.source_id(); auto matching_recent = find_by_mmsi(source_id); @@ -111,42 +149,7 @@ void AISRecentEntries::on_packet(const ais::Packet& packet) { truncate_entries(); } - auto& entry = entries.front(); - entry.received_count++; - - switch(packet.message_id()) { - case 1: - case 2: - case 3: - entry.navigational_status = packet.read(38, 4); - entry.last_position.timestamp = packet.received_at(); - entry.last_position.latitude = packet.latitude(89); - entry.last_position.longitude = packet.longitude(61); - break; - - case 4: - // packet.datetime(38) - entry.last_position.timestamp = packet.received_at(); - entry.last_position.latitude = packet.latitude(107); - entry.last_position.longitude = packet.longitude(79); - break; - - case 5: - entry.call_sign = packet.text(70, 7); - entry.name = packet.text(112, 20); - entry.destination = packet.text(302, 20); - break; - - case 21: - entry.name = packet.text(43, 20); - entry.last_position.timestamp = packet.received_at(); - entry.last_position.latitude = packet.latitude(192); - entry.last_position.longitude = packet.longitude(164); - break; - - default: - break; - } + entries.front().update(packet); } AISRecentEntries::ContainerType::const_iterator AISRecentEntries::find_by_mmsi(const ais::MMSI key) const { diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index 59af0e96..b80ca6bd 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -61,6 +61,8 @@ struct AISRecentEntry { navigational_status { -1 } { } + + void update(const ais::Packet& packet); }; class AISRecentEntries {