From: Soeren Apel Date: Sat, 27 May 2017 14:54:53 +0000 (+0200) Subject: Bindings: Flesh out the analog payload bindings X-Git-Tag: libsigrok-0.5.0~28 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=0cee3a3ea5d9808c000def569887e5f18b82df71;hp=845060fa9ddbfae9441aa67fab4934f46f4baa05;p=libsigrok.git Bindings: Flesh out the analog payload bindings --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 5e07c2c6..5c0ae3d0 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -1227,6 +1227,58 @@ vector> Analog::channels() return result; } +unsigned int Analog::unitsize() const +{ + return _structure->encoding->unitsize; +} + +bool Analog::is_signed() const +{ + return _structure->encoding->is_signed; +} + +bool Analog::is_float() const +{ + return _structure->encoding->is_float; +} + +bool Analog::is_bigendian() const +{ + return _structure->encoding->is_bigendian; +} + +int Analog::digits() const +{ + return _structure->encoding->digits; +} + +bool Analog::is_digits_decimal() const +{ + return _structure->encoding->is_digits_decimal; +} + +shared_ptr Analog::scale() +{ + unique_ptr scale; + scale.reset(new Rational(&(_structure->encoding->scale))); + + if (scale) + return scale->share_owned_by(shared_from_this()); + else + throw Error(SR_ERR_NA); +} + +shared_ptr Analog::offset() +{ + unique_ptr offset; + offset.reset(new Rational(&(_structure->encoding->offset))); + + if (offset) + return offset->share_owned_by(shared_from_this()); + else + throw Error(SR_ERR_NA); +} + const Quantity *Analog::mq() const { return Quantity::get(_structure->meaning->mq); @@ -1242,6 +1294,36 @@ vector Analog::mq_flags() const return QuantityFlag::flags_from_mask(_structure->meaning->mqflags); } +Rational::Rational(const struct sr_rational *structure) : + _structure(structure) +{ +} + +Rational::~Rational() +{ +} + +shared_ptr Rational::share_owned_by(shared_ptr _parent) +{ + return static_pointer_cast( + ParentOwned::share_owned_by(_parent)); +} + +int64_t Rational::numerator() const +{ + return _structure->p; +} + +uint64_t Rational::denominator() const +{ + return _structure->q; +} + +float Rational::value() const +{ + return (float)(_structure->p) / (float)(_structure->q); +} + InputFormat::InputFormat(const struct sr_input_module *structure) : _structure(structure) { diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index ad59f5b9..b82679ab 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -115,6 +115,7 @@ class SR_API PacketType; class SR_API Quantity; class SR_API Unit; class SR_API QuantityFlag; +class SR_API Rational; class SR_API Input; class SR_API InputDevice; class SR_API Output; @@ -771,6 +772,26 @@ public: unsigned int num_samples() const; /** Channels for which this packet contains data. */ vector > channels(); + /** Size of a single sample in bytes. */ + unsigned int unitsize() const; + /** Samples use a signed data type. */ + bool is_signed() const; + /** Samples use float. */ + bool is_float() const; + /** Samples are stored in big-endian order. */ + bool is_bigendian() const; + /** + * Number of significant digits after the decimal point if positive, + * or number of non-significant digits before the decimal point if negative + * (refers to the value we actually read on the wire). + */ + int digits() const; + /** TBD */ + bool is_digits_decimal() const; + /** TBD */ + shared_ptr scale(); + /** TBD */ + shared_ptr offset(); /** Measured quantity of the samples in this packet. */ const Quantity *mq() const; /** Unit of the samples in this packet. */ @@ -787,6 +808,28 @@ private: friend class Packet; }; +/** Number represented by a numerator/denominator integer pair */ +class SR_API Rational : + public ParentOwned +{ +public: + /** Numerator, i.e. the dividend. */ + int64_t numerator() const; + /** Denominator, i.e. the divider. */ + uint64_t denominator() const; + /** Actual (lossy) value. */ + float value() const; +private: + explicit Rational(const struct sr_rational *structure); + ~Rational(); + shared_ptr share_owned_by(shared_ptr parent); + + const struct sr_rational *_structure; + + friend class Analog; + friend struct std::default_delete; +}; + /** An input format supported by the library */ class SR_API InputFormat : public ParentOwned