Radiosonde RX now understands Meteomodem's M10 correctly

Updated binary
This commit is contained in:
furrtek 2017-10-27 18:54:50 +02:00
parent 6e7b2c751f
commit d47f292d3a
11 changed files with 157 additions and 47 deletions

View file

@ -23,6 +23,10 @@
#include "string_format.hpp"
size_t ManchesterBase::symbols_count() const {
return packet.size() / 2;
}
DecodedSymbol ManchesterDecoder::operator[](const size_t index) const {
const size_t encoded_index = index * 2;
if( (encoded_index + 1) < packet.size() ) {
@ -34,12 +38,19 @@ DecodedSymbol ManchesterDecoder::operator[](const size_t index) const {
}
}
size_t ManchesterDecoder::symbols_count() const {
return packet.size() / 2;
DecodedSymbol BiphaseMDecoder::operator[](const size_t index) const {
const size_t encoded_index = index * 2;
if( (encoded_index + 1) < packet.size() ) {
const auto value = packet[encoded_index + 0] != packet[encoded_index + 1];
const uint_fast8_t error = encoded_index ? (packet[encoded_index - 1] == packet[encoded_index + 0]) : 0;
return { value, error };
} else {
return { 0, 1 };
}
}
FormattedSymbols format_symbols(
const ManchesterDecoder& decoder
const ManchesterBase& decoder
) {
const size_t payload_length_decoded = decoder.symbols_count();
const size_t payload_length_hex_characters = (payload_length_decoded + 3) / 4;

View file

@ -34,25 +34,39 @@ struct DecodedSymbol {
uint_fast8_t error;
};
class ManchesterDecoder {
class ManchesterBase {
public:
constexpr ManchesterDecoder(
constexpr ManchesterBase(
const baseband::Packet& packet,
const size_t sense = 0
) : packet { packet },
sense { sense }
{
}
virtual DecodedSymbol operator[](const size_t index) const = 0;
DecodedSymbol operator[](const size_t index) const;
size_t symbols_count() const;
private:
virtual size_t symbols_count() const;
virtual ~ManchesterBase() { };
protected:
const baseband::Packet& packet;
const size_t sense;
};
class ManchesterDecoder : public ManchesterBase {
public:
using ManchesterBase::ManchesterBase;
DecodedSymbol operator[](const size_t index) const;
};
class BiphaseMDecoder : public ManchesterBase {
public:
using ManchesterBase::ManchesterBase;
DecodedSymbol operator[](const size_t index) const;
};
template<typename T>
T operator|(const T& l, const DecodedSymbol& r) {
return l | r.value;
@ -64,7 +78,7 @@ struct FormattedSymbols {
};
FormattedSymbols format_symbols(
const ManchesterDecoder& decoder
const ManchesterBase& decoder
);
void manchester_encode(uint8_t * dest, uint8_t * src, const size_t length, const size_t sense = 0);

View file

@ -42,6 +42,33 @@ Packet::Type Packet::type() const {
return type_;
}
uint32_t Packet::visible_sats() const {
return reader_.read(30 * 8, 8);
}
uint32_t Packet::GPS_altitude() const {
return reader_.read(22 * 8, 32) / 1000;
}
float Packet::GPS_latitude() const {
return reader_.read(14 * 8, 32) / ((1ULL << 32) / 360.0);
}
float Packet::GPS_longitude() const {
return reader_.read(18 * 8, 32) / ((1ULL << 32) / 360.0);
}
std::string Packet::signature() const {
const auto header = reader_.read(0, 24);
if (header == 0x649F20)
return "M10";
else if (header == 0x648F20)
return "M2K2";
else
return symbols_formatted().data.substr(0, 6);
}
SN Packet::serial_number() const {
if (type() == Type::M10) {
// See https://github.com/rs1729/RS/blob/master/m10/m10x.c line 606

View file

@ -42,8 +42,8 @@ public:
};
Packet(
const Type type,
const baseband::Packet& packet
const baseband::Packet& packet,
const Type type
) : packet_ { packet },
decoder_ { packet_ },
reader_ { decoder_ },
@ -59,16 +59,21 @@ public:
Type type() const;
SN serial_number() const;
uint32_t visible_sats() const;
uint32_t GPS_altitude() const;
float GPS_latitude() const;
float GPS_longitude() const;
std::string signature() const;
FormattedSymbols symbols_formatted() const;
bool crc_ok() const;
private:
using Reader = FieldReader<ManchesterDecoder, BitRemapNone>;
using Reader = FieldReader<BiphaseMDecoder, BitRemapNone>;
const baseband::Packet packet_;
const ManchesterDecoder decoder_;
const BiphaseMDecoder decoder_;
const Reader reader_;
const Type type_;