mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-25 19:29:55 +00:00
Extract TPMS packet stuff to separate files.
This commit is contained in:
@@ -175,6 +175,7 @@ CPPSRC = main.cpp \
|
||||
../commom/ais_packet.cpp \
|
||||
ais_app.cpp \
|
||||
tpms_app.cpp \
|
||||
../common/tpms_packet.cpp \
|
||||
ert_app.cpp \
|
||||
../common/ert_packet.cpp \
|
||||
sd_card.cpp \
|
||||
|
@@ -27,8 +27,6 @@
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "crc.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace tpms {
|
||||
@@ -53,87 +51,6 @@ std::string temperature(Temperature temperature) {
|
||||
|
||||
} /* namespace format */
|
||||
|
||||
Timestamp Packet::received_at() const {
|
||||
return packet_.timestamp();
|
||||
}
|
||||
|
||||
ManchesterFormatted Packet::symbols_formatted() const {
|
||||
return format_manchester(decoder_);
|
||||
}
|
||||
|
||||
Optional<Reading> Packet::reading() const {
|
||||
const auto length = crc_valid_length();
|
||||
|
||||
switch(length) {
|
||||
case 64:
|
||||
return Reading {
|
||||
Reading::Type::FLM_64,
|
||||
reader_.read(0, 32),
|
||||
Pressure { static_cast<int>(reader_.read(32, 8)) * 4 / 3 },
|
||||
Temperature { static_cast<int>(reader_.read(40, 8) & 0x7f) - 50 }
|
||||
};
|
||||
|
||||
case 72:
|
||||
return Reading {
|
||||
Reading::Type::FLM_72,
|
||||
reader_.read(0, 32),
|
||||
Pressure { static_cast<int>(reader_.read(40, 8)) * 4 / 3 },
|
||||
Temperature { static_cast<int>(reader_.read(48, 8)) - 50 }
|
||||
};
|
||||
|
||||
case 80:
|
||||
return Reading {
|
||||
Reading::Type::FLM_80,
|
||||
reader_.read(8, 32),
|
||||
Pressure { static_cast<int>(reader_.read(48, 8)) * 4 / 3 },
|
||||
Temperature { static_cast<int>(reader_.read(56, 8)) - 50 }
|
||||
};
|
||||
|
||||
default:
|
||||
return { };
|
||||
}
|
||||
}
|
||||
|
||||
size_t Packet::crc_valid_length() const {
|
||||
constexpr uint32_t checksum_bytes = 0b1111111;
|
||||
constexpr uint32_t crc_72_bytes = 0b111111111;
|
||||
constexpr uint32_t crc_80_bytes = 0b1111111110;
|
||||
|
||||
std::array<uint8_t, 10> bytes;
|
||||
for(size_t i=0; i<bytes.size(); i++) {
|
||||
bytes[i] = reader_.read(i * 8, 8);
|
||||
}
|
||||
|
||||
uint32_t checksum = 0;
|
||||
CRC<8> crc_72 { 0x01, 0x00 };
|
||||
CRC<8> crc_80 { 0x01, 0x00 };
|
||||
|
||||
for(size_t i=0; i<bytes.size(); i++) {
|
||||
const uint32_t byte_mask = 1 << i;
|
||||
const auto byte = bytes[i];
|
||||
|
||||
if( checksum_bytes & byte_mask ) {
|
||||
checksum += byte;
|
||||
}
|
||||
if( crc_72_bytes & byte_mask ) {
|
||||
crc_72.process_byte(byte);
|
||||
}
|
||||
if( crc_80_bytes & byte_mask ) {
|
||||
crc_80.process_byte(byte);
|
||||
}
|
||||
}
|
||||
|
||||
if( crc_80.checksum() == 0 ) {
|
||||
return 80;
|
||||
} else if( crc_72.checksum() == 0 ) {
|
||||
return 72;
|
||||
} else if( (checksum & 0xff) == bytes[7] ) {
|
||||
return 64;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace tpms */
|
||||
|
||||
TPMSLogger::TPMSLogger(
|
||||
|
@@ -25,127 +25,11 @@
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
#include "field_reader.hpp"
|
||||
#include "baseband_packet.hpp"
|
||||
#include "manchester.hpp"
|
||||
#include "log_file.hpp"
|
||||
|
||||
#include "recent_entries.hpp"
|
||||
|
||||
#include "optional.hpp"
|
||||
|
||||
#include "units.hpp"
|
||||
using units::Temperature;
|
||||
using units::Pressure;
|
||||
|
||||
namespace tpms {
|
||||
|
||||
class TransponderID {
|
||||
public:
|
||||
constexpr TransponderID(
|
||||
) : id_ { 0 }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr TransponderID(
|
||||
const uint32_t id
|
||||
) : id_ { id }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr uint32_t value() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t id_;
|
||||
};
|
||||
|
||||
class Reading {
|
||||
public:
|
||||
enum Type {
|
||||
None = 0,
|
||||
FLM_64 = 1,
|
||||
FLM_72 = 2,
|
||||
FLM_80 = 3,
|
||||
};
|
||||
|
||||
constexpr Reading(
|
||||
) : type_ { Type::None }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Reading(
|
||||
Type type,
|
||||
TransponderID id
|
||||
) : type_ { type },
|
||||
id_ { id }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Reading(
|
||||
Type type,
|
||||
TransponderID id,
|
||||
Optional<Pressure> pressure = { },
|
||||
Optional<Temperature> temperature = { }
|
||||
) : type_ { type },
|
||||
id_ { id },
|
||||
pressure_ { pressure },
|
||||
temperature_ { temperature }
|
||||
{
|
||||
}
|
||||
|
||||
Type type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
TransponderID id() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
Optional<Pressure> pressure() const {
|
||||
return pressure_;
|
||||
}
|
||||
|
||||
Optional<Temperature> temperature() const {
|
||||
return temperature_;
|
||||
}
|
||||
|
||||
private:
|
||||
Type type_ { Type::None };
|
||||
TransponderID id_ { 0 };
|
||||
Optional<Pressure> pressure_ { };
|
||||
Optional<Temperature> temperature_ { };
|
||||
};
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
constexpr Packet(
|
||||
const baseband::Packet& packet
|
||||
) : packet_ { packet },
|
||||
decoder_ { packet_, 0 },
|
||||
reader_ { decoder_ }
|
||||
{
|
||||
}
|
||||
|
||||
Timestamp received_at() const;
|
||||
|
||||
ManchesterFormatted symbols_formatted() const;
|
||||
|
||||
Optional<Reading> reading() const;
|
||||
|
||||
private:
|
||||
using Reader = FieldReader<ManchesterDecoder, BitRemapNone>;
|
||||
|
||||
const baseband::Packet packet_;
|
||||
const ManchesterDecoder decoder_;
|
||||
|
||||
const Reader reader_;
|
||||
|
||||
size_t crc_valid_length() const;
|
||||
};
|
||||
|
||||
} /* namespace tpms */
|
||||
#include "tpms_packet.hpp"
|
||||
|
||||
namespace std {
|
||||
|
||||
|
Reference in New Issue
Block a user