mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Merge pull request #907 from NotherNgineer/next
Support for ERT SCM+ meter protocol
This commit is contained in:
commit
b1aa607a7c
@ -41,6 +41,7 @@ std::string type(Packet::Type value) {
|
||||
case Packet::Type::Unknown: return "???";
|
||||
case Packet::Type::IDM: return "IDM";
|
||||
case Packet::Type::SCM: return "SCM";
|
||||
case Packet::Type::SCMPLUS: return "SCM+";
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +63,8 @@ std::string commodity_type(CommodityType value) {
|
||||
|
||||
void ERTLogger::on_packet(const ert::Packet& packet) {
|
||||
const auto formatted = packet.symbols_formatted();
|
||||
log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors);
|
||||
std::string entry = ert::format::type(packet.type()) + " " + formatted.data + "/" + formatted.errors;
|
||||
log_file.write_entry(packet.received_at(), entry);
|
||||
}
|
||||
|
||||
const ERTRecentEntry::Key ERTRecentEntry::invalid_key { };
|
||||
|
@ -87,6 +87,7 @@ void ERTProcessor::consume_symbol(
|
||||
) {
|
||||
const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0;
|
||||
scm_builder.execute(sliced_symbol);
|
||||
scmplus_builder.execute(sliced_symbol);
|
||||
idm_builder.execute(sliced_symbol);
|
||||
}
|
||||
|
||||
@ -97,6 +98,13 @@ void ERTProcessor::scm_handler(
|
||||
shared_memory.application_queue.push(message);
|
||||
}
|
||||
|
||||
void ERTProcessor::scmplus_handler(
|
||||
const baseband::Packet& packet
|
||||
) {
|
||||
const ERTPacketMessage message { ert::Packet::Type::SCMPLUS, packet };
|
||||
shared_memory.application_queue.push(message);
|
||||
}
|
||||
|
||||
void ERTProcessor::idm_handler(
|
||||
const baseband::Packet& packet
|
||||
) {
|
||||
|
@ -44,10 +44,14 @@ constexpr uint64_t scm_preamble_and_sync_manchester { 0b101010101001011001100110
|
||||
constexpr size_t scm_preamble_and_sync_length { 42 - 10 };
|
||||
constexpr size_t scm_payload_length_max { 150 };
|
||||
|
||||
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x16a3)[2:].zfill(16))])
|
||||
constexpr uint64_t scmplus_preamble_and_sync_manchester { 0b01010110011010011001100101011010 };
|
||||
constexpr size_t scmplus_preamble_and_sync_length { 32 - 0 };
|
||||
constexpr size_t scmplus_payload_length_max { 224 };
|
||||
|
||||
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x555516a3)[2:].zfill(32))])
|
||||
constexpr uint64_t idm_preamble_and_sync_manchester { 0b0110011001100110011001100110011001010110011010011001100101011010 };
|
||||
constexpr size_t idm_preamble_and_sync_length { 64 - 16 };
|
||||
|
||||
constexpr size_t idm_payload_length_max { 1408 };
|
||||
|
||||
class ERTProcessor : public BasebandProcessor {
|
||||
@ -80,6 +84,15 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
PacketBuilder<BitPattern, NeverMatch, FixedLength> scmplus_builder {
|
||||
{ scmplus_preamble_and_sync_manchester, scmplus_preamble_and_sync_length, 1 },
|
||||
{ },
|
||||
{ scmplus_payload_length_max },
|
||||
[this](const baseband::Packet& packet) {
|
||||
this->scmplus_handler(packet);
|
||||
}
|
||||
};
|
||||
|
||||
PacketBuilder<BitPattern, NeverMatch, FixedLength> idm_builder {
|
||||
{ idm_preamble_and_sync_manchester, idm_preamble_and_sync_length, 1 },
|
||||
{ },
|
||||
@ -91,6 +104,7 @@ private:
|
||||
|
||||
void consume_symbol(const float symbol);
|
||||
void scm_handler(const baseband::Packet& packet);
|
||||
void scmplus_handler(const baseband::Packet& packet);
|
||||
void idm_handler(const baseband::Packet& packet);
|
||||
|
||||
float sum_half_period[2];
|
||||
|
@ -47,6 +47,9 @@ ID Packet::id() const {
|
||||
const auto lsb = reader_.read(35, 24);
|
||||
return (msb << 24) | lsb;
|
||||
}
|
||||
if( type() == Type::SCMPLUS ) {
|
||||
return reader_.read(2 * 8, 32);
|
||||
}
|
||||
if( type() == Type::IDM ) {
|
||||
return reader_.read(5 * 8, 32);
|
||||
}
|
||||
@ -57,6 +60,9 @@ Consumption Packet::consumption() const {
|
||||
if( type() == Type::SCM ) {
|
||||
return reader_.read(11, 24);
|
||||
}
|
||||
if( type() == Type::SCMPLUS ) {
|
||||
return reader_.read(6 * 8, 32);
|
||||
}
|
||||
if( type() == Type::IDM ) {
|
||||
return reader_.read(25 * 8, 32);
|
||||
}
|
||||
@ -67,6 +73,9 @@ CommodityType Packet::commodity_type() const {
|
||||
if( type() == Type::SCM ) {
|
||||
return reader_.read(5, 4);
|
||||
}
|
||||
if( type() == Type::SCMPLUS ) {
|
||||
return reader_.read(1 * 8 + 4, 4);
|
||||
}
|
||||
if( type() == Type::IDM ) {
|
||||
return reader_.read(4 * 8 + 4, 4);
|
||||
}
|
||||
@ -80,7 +89,8 @@ FormattedSymbols Packet::symbols_formatted() const {
|
||||
bool Packet::crc_ok() const {
|
||||
switch(type()) {
|
||||
case Type::SCM: return crc_ok_scm();
|
||||
case Type::IDM: return crc_ok_idm();
|
||||
case Type::SCMPLUS:
|
||||
case Type::IDM: return crc_ok_ccitt();
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@ -95,7 +105,7 @@ bool Packet::crc_ok_scm() const {
|
||||
return ert_bch.checksum() == 0x0000;
|
||||
}
|
||||
|
||||
bool Packet::crc_ok_idm() const {
|
||||
bool Packet::crc_ok_ccitt() const {
|
||||
CRC<16> ert_crc_ccitt { 0x1021, 0xffff, 0x1d0f };
|
||||
for(size_t i=0; i<length(); i+=8) {
|
||||
ert_crc_ccitt.process_byte(reader_.read(i, 8));
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
Unknown = 0,
|
||||
IDM = 1,
|
||||
SCM = 2,
|
||||
SCMPLUS = 3,
|
||||
};
|
||||
|
||||
Packet(
|
||||
@ -80,7 +81,7 @@ private:
|
||||
const Reader reader_;
|
||||
const Type type_;
|
||||
|
||||
bool crc_ok_idm() const;
|
||||
bool crc_ok_ccitt() const;
|
||||
bool crc_ok_scm() const;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user