7#include "transferflags.hh"
53 bool _autoEnableRoaming;
74 const unsigned int bit;
78 unsigned int tmp = 8 *
byte + (7-
bit) + bits;
79 return {tmp/8, (7 - (tmp % 8))};
84 unsigned int tmp = 8 *
byte + (7-
bit) - bits;
85 return {tmp/8, (7 - (tmp % 8))};
94 template <
class T>
struct Range {
100 inline T
limit(
const T &value)
const {
101 return std::min(
max, std::max(
min, value));
104 inline bool in(
const T &value)
const {
105 return (value <=
max) && (value >=
min);
134 virtual void clear();
137 bool fill(uint8_t value,
unsigned offset=0,
int size=-1);
140 bool getBit(
const Offset::Bit &offset)
const;
142 bool getBit(
unsigned offset,
unsigned bit)
const;
144 void setBit(
const Offset::Bit &offset,
bool value=
true);
146 void setBit(
unsigned offset,
unsigned bit,
bool value=
true);
148 void clearBit(
unsigned offset,
unsigned bit);
150 void clearBit(
const Offset::Bit &offset);
153 uint8_t
getUInt2(
const Offset::Bit &offset)
const;
155 uint8_t
getUInt2(
unsigned offset,
unsigned bit)
const;
157 void setUInt2(
const Offset::Bit &offset, uint8_t value);
159 void setUInt2(
unsigned offset,
unsigned bit, uint8_t value);
162 uint8_t
getUInt3(
const Offset::Bit &offset)
const;
164 uint8_t
getUInt3(
unsigned offset,
unsigned bit)
const;
166 void setUInt3(
const Offset::Bit &offset, uint8_t value);
168 void setUInt3(
unsigned offset,
unsigned bit, uint8_t value);
171 uint8_t
getUInt4(
const Offset::Bit &offset)
const;
173 uint8_t
getUInt4(
unsigned offset,
unsigned bit)
const;
175 void setUInt4(
const Offset::Bit &offset, uint8_t value);
177 void setUInt4(
unsigned offset,
unsigned bit, uint8_t value);
180 uint8_t
getUInt5(
const Offset::Bit &offset)
const;
182 uint8_t
getUInt5(
unsigned offset,
unsigned bit)
const;
184 void setUInt5(
const Offset::Bit &offset, uint8_t value);
186 void setUInt5(
unsigned offset,
unsigned bit, uint8_t value);
189 uint8_t
getUInt6(
const Offset::Bit &offset)
const;
191 uint8_t
getUInt6(
unsigned offset,
unsigned bit)
const;
193 void setUInt6(
const Offset::Bit &offset, uint8_t value);
195 void setUInt6(
unsigned offset,
unsigned bit, uint8_t value);
198 uint8_t
getUInt8(
unsigned offset)
const;
200 void setUInt8(
unsigned offset, uint8_t value);
202 int8_t
getInt8(
unsigned offset)
const;
204 void setInt8(
unsigned offset, int8_t value);
243 uint8_t
getBCD2(
unsigned offset)
const;
245 void setBCD2(
unsigned offset, uint8_t value);
250 void setBCD4_be(
unsigned offset, uint16_t value);
254 void setBCD4_le(
unsigned offset, uint16_t value);
259 void setBCD8_be(
unsigned offset, uint32_t value);
263 void setBCD8_le(
unsigned offset, uint32_t value);
266 QString
readASCII(
unsigned offset,
unsigned maxlen, uint8_t eos=0x00)
const;
269 void writeASCII(
unsigned offset,
const QString &txt,
unsigned maxlen, uint8_t eos=0x00);
272 QString
readUnicode(
unsigned offset,
unsigned maxlen, uint16_t eos=0x0000)
const;
275 void writeUnicode(
unsigned offset,
const QString &txt,
unsigned maxlen, uint16_t eos=0x0000);
304 ConfigItem *
obj(
const QMetaObject *elementType,
unsigned idx);
319 return this->
obj(&(T::staticMetaObject), idx)->template as<T>();
325 return nullptr != this->
obj(&(T::staticMetaObject), idx)->template as<T>();
359 explicit Codeplug(QObject *parent=
nullptr);
Internal used table type to associate objects and indices.
Definition codeplug.hh:336
QHash< unsigned, ConfigItem * > objects
The index->object map.
Definition codeplug.hh:339
QHash< ConfigItem *, unsigned > indices
The object->index map.
Definition codeplug.hh:341
Base class for all codeplug contexts.
Definition codeplug.hh:291
QHash< QString, Table > _tables
Table of tables.
Definition codeplug.hh:354
Context(Config *config)
Empty constructor.
Definition codeplug.cc:691
SatelliteDatabase * satellites() const
Returns a reference to the satellite database.
Definition codeplug.cc:718
int index(ConfigItem *obj)
Returns the index for the given object.
Definition codeplug.cc:755
Config * config() const
Returns the reference to the config object.
Definition codeplug.cc:713
Config * _config
A weak reference to the config object.
Definition codeplug.hh:350
ConfigItem * obj(const QMetaObject *elementType, unsigned idx)
Resolves the given index for the specifies element type.
Definition codeplug.cc:748
T * get(unsigned idx)
Returns the object associated by the given index and type.
Definition codeplug.hh:318
bool add(ConfigItem *obj, unsigned idx)
Associates the given object with the given index.
Definition codeplug.cc:764
unsigned int count()
Returns the number of elements for the specified type.
Definition codeplug.hh:330
SatelliteDatabase * _satellites
A weak reference to the satellite database.
Definition codeplug.hh:352
bool has(unsigned idx)
Returns true, if the given index is defined for the specified type.
Definition codeplug.hh:324
bool addTable(const QMetaObject *obj)
Adds a table for the given type.
Definition codeplug.cc:740
bool hasTable(const QMetaObject *obj) const
Returns true if a table is defined for the given type.
Definition codeplug.cc:723
Table & getTable(const QMetaObject *obj)
Returns a reference to the table for the given type.
Definition codeplug.cc:733
Represents the abstract base class of all codeplug elements.
Definition codeplug.hh:65
Element(uint8_t *ptr, size_t size)
Hidden constructor.
Definition codeplug.cc:56
uint16_t getUInt16_be(unsigned offset) const
Reads a 16bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:349
int8_t getInt8(unsigned offset) const
Reads a 8bit signed integer at the given byte- and bit-offset.
Definition codeplug.cc:331
void setBCD8_le(unsigned offset, uint32_t value)
Stores a 8-digit (4-byte/32bit) BDC value in little-endian at the given byte-offset.
Definition codeplug.cc:630
uint16_t getBCD4_le(unsigned offset) const
Reads a 4-digit (2-byte/16bit) BDC value in little-endian at the given byte-offset.
Definition codeplug.cc:565
void setUInt16_be(unsigned offset, uint16_t value)
Stores a 16bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:371
uint8_t * _data
Holds the pointer to the element.
Definition codeplug.hh:279
uint64_t getUInt64_le(unsigned offset) const
Reads a 64bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:489
uint32_t getUInt24_be(unsigned offset) const
Reads a 24bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:393
uint32_t getUInt24_le(unsigned offset) const
Reads a 24bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:403
void setUInt8(unsigned offset, uint8_t value)
Reads a 8bit unsigned integer at the given byte- and bit-offset.
Definition codeplug.cc:321
void setBCD2(unsigned offset, uint8_t value)
Stores a 2-digit (1-byte/8bit) BDC value in big-endian at the given byte-offset.
Definition codeplug.cc:530
void setBCD4_le(unsigned offset, uint16_t value)
Stores a 4-digit (1-byte/16bit) BDC value in little-endian at the given byte-offset.
Definition codeplug.cc:575
uint32_t getBCD8_be(unsigned offset) const
Reads a 8-digit (4-byte/32bit) BDC value in big-endian at the given byte-offset.
Definition codeplug.cc:589
void setUInt3(const Offset::Bit &offset, uint8_t value)
Stores a 3bit unsigned integer at the given bit-offset.
Definition codeplug.cc:191
void setUInt32_be(unsigned offset, uint32_t value)
Stores a 32bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:458
void setUInt4(const Offset::Bit &offset, uint8_t value)
Stores a 4bit unsigned integer at the given bit-offset.
Definition codeplug.cc:222
uint64_t getUInt64_be(unsigned offset) const
Reads a 64bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:479
void writeASCII(unsigned offset, const QString &txt, unsigned maxlen, uint8_t eos=0x00)
Stores up to maxlen ASCII chars at the given byte-offset using eos as the string termination char.
Definition codeplug.cc:657
void clearBit(unsigned offset, unsigned bit)
Clears a specific bit at the given byte-offset.
Definition codeplug.cc:143
uint8_t getUInt6(const Offset::Bit &offset) const
Reads a 6bit unsigned integer at the given byte- and bit-offset.
Definition codeplug.cc:281
void setUInt64_be(unsigned offset, uint64_t value)
Stores a 64bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:499
void setUInt16_le(unsigned offset, uint16_t value)
Stores a 16bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:382
uint8_t getUInt5(const Offset::Bit &offset) const
Reads a 5bit unsigned integer at the given byte- and bit-offset.
Definition codeplug.cc:250
QString readASCII(unsigned offset, unsigned maxlen, uint8_t eos=0x00) const
Reads up to maxlen ASCII chars at the given byte-offset using eos as the string termination char.
Definition codeplug.cc:648
uint8_t getUInt3(const Offset::Bit &offset) const
Reads a 3bit unsigned integer at the given bit-offset.
Definition codeplug.cc:187
void setUInt24_le(unsigned offset, uint32_t value)
Stores a 24bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:425
uint8_t getUInt8(unsigned offset) const
Reads a 8bit unsigned integer at the given byte- and bit-offset.
Definition codeplug.cc:312
void setInt8(unsigned offset, int8_t value)
Reads a 8bit signed integer at the given byte- and bit-offset.
Definition codeplug.cc:339
void setUInt32_le(unsigned offset, uint32_t value)
Stores a 32bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:468
void setUInt64_le(unsigned offset, uint64_t value)
Stores a 64bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:509
void setUInt6(const Offset::Bit &offset, uint8_t value)
Stores a 6bit unsigned integer at the given byte- and bit-offset.
Definition codeplug.cc:285
virtual ~Element()
Destructor.
Definition codeplug.cc:68
uint16_t getUInt16_le(unsigned offset) const
Reads a 16bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:360
QString readUnicode(unsigned offset, unsigned maxlen, uint16_t eos=0x0000) const
Reads up to maxlen unicode chars at the given byte-offset using eos as the string termination char.
Definition codeplug.cc:668
uint16_t getBCD4_be(unsigned offset) const
Reads a 4-digit (2-byte/16bit) BDC value in big-endian at the given byte-offset.
Definition codeplug.cc:542
virtual bool isValid() const
Returns true if the pointer is not null.
Definition codeplug.cc:80
void setUInt5(const Offset::Bit &offset, uint8_t value)
Stores a 5bit unsigned integer at the given byte- and bit-offset.
Definition codeplug.cc:254
uint32_t getUInt32_be(unsigned offset) const
Reads a 32bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:438
bool fill(uint8_t value, unsigned offset=0, int size=-1)
Fills the memsets the entire element to the given value.
Definition codeplug.cc:90
Element & operator=(const Element &other)
Copy assignment.
Definition codeplug.cc:73
void setBCD8_be(unsigned offset, uint32_t value)
Stores a 8-digit (4-byte/32bit) BDC value in big-endian at the given byte-offset.
Definition codeplug.cc:601
uint32_t getBCD8_le(unsigned offset) const
Reads a 8-digit (4-byte/32bit) BDC value in little-endian at the given byte-offset.
Definition codeplug.cc:618
uint8_t getBCD2(unsigned offset) const
Reads a 2-digit (1-byte/8bit) BDC value in big-endian at the given byte-offset.
Definition codeplug.cc:520
void setBCD4_be(unsigned offset, uint16_t value)
Stores a 4-digit (2-byte/16bit) BDC value in big-endian at the given byte-offset.
Definition codeplug.cc:552
void setUInt24_be(unsigned offset, uint32_t value)
Stores a 24bit big-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:413
void setBit(const Offset::Bit &offset, bool value=true)
Sets a specific bit at the given byte-offset.
Definition codeplug.cc:120
bool getBit(const Offset::Bit &offset) const
Reads a specific bit at the given byte-offset.
Definition codeplug.cc:103
uint8_t getUInt4(const Offset::Bit &offset) const
Reads a 4bit unsigned integer at the given bit-offset.
Definition codeplug.cc:218
uint8_t getUInt2(const Offset::Bit &offset) const
Reads a 2bit unsigned integer at the given bit-offset.
Definition codeplug.cc:156
uint32_t getUInt32_le(unsigned offset) const
Reads a 32bit little-endian unsigned integer at the given byte-offset.
Definition codeplug.cc:448
size_t _size
Holds the size of the element.
Definition codeplug.hh:281
virtual void clear()
Abstract method to reset the element within the codeplug.
Definition codeplug.cc:85
void writeUnicode(unsigned offset, const QString &txt, unsigned maxlen, uint16_t eos=0x0000)
Stores up to maxlen unicode chars at the given byte-offset using eos as the string termination char.
Definition codeplug.cc:677
void setUInt2(const Offset::Bit &offset, uint8_t value)
Stores a 2bit unsigned integer at the given bit-offset.
Definition codeplug.cc:160
Certain flags passed to CodePlug::encode to control the transfer and encoding of the codeplug.
Definition codeplug.hh:24
void setUpdateCodeplug(bool enable)
Sets if the codeplug gets updated.
Definition codeplug.cc:25
void setAutoEnableGPS(bool enable)
Sets if the GPS gets enabled automatically.
Definition codeplug.cc:36
bool autoEnableRoaming() const
If true enables automatic roaming when there is a roaming zone defined that is used by any channel.
Definition codeplug.cc:42
bool autoEnableGPS() const
If true enables GPS when there is a GPS or APRS system defined that is used by any channel.
Definition codeplug.cc:31
Flags()
Default constructor, enables code-plug update and disables automatic GPS/APRS and roaming.
Definition codeplug.cc:12
void setAutoEnableRoaming(bool enable)
Sets if roaming gets enabled automatically.
Definition codeplug.cc:47
bool updateCodeplug() const
If true, the codeplug will first be downloaded from the device, updated from the abstract config and ...
Definition codeplug.cc:20
Codeplug(QObject *parent=nullptr)
Hidden default constructor.
Definition codeplug.cc:778
virtual bool index(Config *config, Context &ctx, const ErrorStack &err=ErrorStack()) const =0
Indexes all elements of the codeplug.
virtual bool encode(Config *config, const Flags &flags=Flags(), const ErrorStack &err=ErrorStack())=0
Encodes a given abstract configuration (config) to the device specific binary code-plug.
virtual bool postprocess(Config *config, const ErrorStack &err=ErrorStack()) const
Returns a post-processed configuration of the decoded config.
Definition codeplug.cc:794
virtual ~Codeplug()
Destructor.
Definition codeplug.cc:784
virtual Config * preprocess(Config *config, const ErrorStack &err=ErrorStack()) const
Returns a prepared configuration for this particular radio.
Definition codeplug.cc:789
virtual bool decode(Config *config, const ErrorStack &err=ErrorStack())=0
Decodes a binary codeplug to the given abstract configuration config.
Base class for all configuration objects (channels, zones, contacts, etc).
Definition configobject.hh:35
The config class, representing the codeplug configuration.
Definition config.hh:70
DFUFile(QObject *parent=nullptr)
Constructs an empty DFU file object.
Definition dfufile.cc:45
uint32_t size() const
Returns the total size of the DFU file.
Definition dfufile.cc:52
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition errorstack.hh:43
A table holding all known satellites.
Definition satellitedatabase.hh:108
TransferFlags()
Default constructor.
Definition transferflags.cc:3
Holds a range of values [min, max].
Definition codeplug.hh:94
T limit(const T &value) const
Limits the value to the range.
Definition codeplug.hh:100
T mapTo(const Range< T > &other, const T &value) const
Maps a value from this range to the given range.
Definition codeplug.hh:108
bool in(const T &value) const
Checks if value is in range.
Definition codeplug.hh:104
const T max
Upper bound.
Definition codeplug.hh:98
const T min
Lower bound.
Definition codeplug.hh:96
Base class for Limits.
Definition codeplug.hh:92
Some type to specify a bit offset.
Definition codeplug.hh:70
const unsigned int byte
The byte offset.
Definition codeplug.hh:72
Bit operator+(unsigned int bits) const
Implements a simple increment.
Definition codeplug.hh:77
Bit operator-(unsigned int bits) const
Implements a simple increment.
Definition codeplug.hh:83
const unsigned int bit
The bit within the byte.
Definition codeplug.hh:74
Base class for Offsets.
Definition codeplug.hh:68