Move ERT packet type to its rightful place.

No longer mixed up with Message types.
This commit is contained in:
Jared Boone 2015-12-08 16:19:27 -08:00
parent 7de187e267
commit eb1402764e
5 changed files with 23 additions and 23 deletions

View File

@ -81,14 +81,14 @@ void ERTView::on_hide() {
void ERTView::on_packet(const ert::Packet& packet) {
std::string msg;
switch(packet.type()) {
case ERTPacketMessage::Type::SCM:
case ert::Packet::Type::SCM:
msg += "SCM ";
msg += to_string_dec_uint(packet.id(), 10);
msg += " ";
msg += to_string_dec_uint(packet.consumption(), 10);
break;
case ERTPacketMessage::Type::IDM:
case ert::Packet::Type::IDM:
msg += "IDM ";
msg += to_string_dec_uint(packet.id(), 10);
msg += " ";

View File

@ -98,7 +98,7 @@ void ERTProcessor::scm_handler(
const baseband::Packet& packet
) {
ERTPacketMessage message;
message.type = ERTPacketMessage::Type::SCM;
message.type = ert::Packet::Type::SCM;
message.packet = packet;
shared_memory.application_queue.push(message);
}
@ -107,7 +107,7 @@ void ERTProcessor::idm_handler(
const baseband::Packet& packet
) {
ERTPacketMessage message;
message.type = ERTPacketMessage::Type::IDM;
message.type = ert::Packet::Type::IDM;
message.packet = packet;
shared_memory.application_queue.push(message);
}

View File

@ -37,27 +37,27 @@ rtc::RTC Packet::received_at() const {
return received_at_;
}
ERTPacketMessage::Type Packet::type() const {
Packet::Type Packet::type() const {
return type_;
}
ID Packet::id() const {
if( type() == ERTPacketMessage::Type::SCM ) {
if( type() == Type::SCM ) {
const auto msb = reader_.read(0, 2);
const auto lsb = reader_.read(35, 24);
return (msb << 24) | lsb;
}
if( type() == ERTPacketMessage::Type::IDM ) {
if( type() == Type::IDM ) {
return reader_.read(5 * 8, 32);
}
return invalid_id;
}
Consumption Packet::consumption() const {
if( type() == ERTPacketMessage::Type::SCM ) {
if( type() == Type::SCM ) {
return reader_.read(11, 24);
}
if( type() == ERTPacketMessage::Type::IDM ) {
if( type() == Type::IDM ) {
return reader_.read(25 * 8, 32);
}
return invalid_consumption;
@ -69,9 +69,9 @@ ManchesterFormatted Packet::symbols_formatted() const {
bool Packet::crc_ok() const {
switch(type()) {
case ERTPacketMessage::Type::SCM: return crc_ok_scm();
case ERTPacketMessage::Type::IDM: return crc_ok_idm();
default: return false;
case Type::SCM: return crc_ok_scm();
case Type::IDM: return crc_ok_idm();
default: return false;
}
}

View File

@ -28,7 +28,6 @@
#include "field_reader.hpp"
#include "baseband_packet.hpp"
#include "manchester.hpp"
#include "message.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
@ -40,9 +39,15 @@ using Consumption = uint32_t;
class Packet {
public:
enum class Type : uint32_t {
Unknown = 0,
IDM = 1,
SCM = 2,
};
Packet(
const rtc::RTC& received_at,
const ERTPacketMessage::Type type,
const Type type,
const baseband::Packet& packet
) : packet_ { packet },
received_at_ { received_at },
@ -58,7 +63,7 @@ public:
rtc::RTC received_at() const;
ERTPacketMessage::Type type() const;
Type type() const;
ID id() const;
Consumption consumption() const;
@ -73,7 +78,7 @@ private:
const rtc::RTC received_at_;
const ManchesterDecoder decoder_;
const Reader reader_;
const ERTPacketMessage::Type type_;
const Type type_;
const ID invalid_id = 0;
const Consumption invalid_consumption = 0;

View File

@ -28,6 +28,7 @@
#include <functional>
#include "baseband_packet.hpp"
#include "ert_packet.hpp"
#include "utility.hpp"
@ -238,13 +239,7 @@ public:
{
}
enum class Type : uint32_t {
Unknown = 0,
IDM = 1,
SCM = 2,
};
Type type { Type::Unknown };
ert::Packet::Type type { ert::Packet::Type::Unknown };
baseband::Packet packet;
};