libdrmconf  0.12.0
A library to program DMR radios.
rd5r_codeplug.hh
1 #ifndef RD5R_CODEPLUG_HH
2 #define RD5R_CODEPLUG_HH
3 
4 #include <QObject>
5 #include "radioddity_codeplug.hh"
6 #include "signaling.hh"
7 
8 class Channel;
9 
78 {
79  Q_OBJECT
80 
81 public:
87  {
88  protected:
90  ChannelElement(uint8_t *ptr, size_t size);
91 
92  public:
94  explicit ChannelElement(uint8_t *ptr);
95 
96  void clear();
97 
99  virtual unsigned squelch() const;
101  virtual void setSquelch(unsigned level);
102 
103  bool fromChannelObj(const Channel *c, Context &ctx);
104  Channel *toChannelObj(Context &ctx) const;
105  bool linkChannelObj(Channel *c, Context &ctx) const;
106  };
107 
112  class TimestampElement: Element
113  {
114  protected:
116  TimestampElement(uint8_t *ptr, unsigned size);
117 
118  public:
120  explicit TimestampElement(uint8_t *ptr);
122  virtual ~TimestampElement();
123 
125  void clear();
126 
128  virtual QDateTime get() const;
130  virtual void set(const QDateTime &ts=QDateTime::currentDateTime());
131  };
132 
139  {
140  public:
142  EncryptionElement(uint8_t *ptr);
143 
144  bool isBasicKeySet(unsigned n) const;
145  QByteArray basicKey(unsigned n) const;
146  void setBasicKey(unsigned n, const QByteArray &key);
147  };
148 
149 public:
151  RD5RCodeplug(QObject *parent=0);
152 
153  void clear();
154 
155 public:
156  bool encodeElements(const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
157  bool decodeElements(Context &ctx, const ErrorStack &err=ErrorStack());
158 
160  virtual void clearTimestamp();
162  virtual bool encodeTimestamp(const ErrorStack &err=ErrorStack());
163 
164  void clearGeneralSettings();
165  bool encodeGeneralSettings(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
166  bool decodeGeneralSettings(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
167 
168  void clearButtonSettings();
169  bool encodeButtonSettings(Context &ctx, const Flags &flags, const ErrorStack &err=ErrorStack());
170  bool decodeButtonSettings(Context &ctx, const ErrorStack &err=ErrorStack());
171 
172  void clearMessages();
173  bool encodeMessages(Context &ctx, const Flags &flags, const ErrorStack &err=ErrorStack());
174  bool decodeMessages(Context &ctx, const ErrorStack &err=ErrorStack());
175 
176  void clearContacts();
177  bool encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
178  bool createContacts(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
179 
180  void clearDTMFContacts();
181  bool encodeDTMFContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
182  bool createDTMFContacts(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
183 
184  void clearChannels();
185  bool encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
186  bool createChannels(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
187  bool linkChannels(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
188 
189  void clearBootSettings();
190  void clearMenuSettings();
191 
192  void clearBootText();
193  bool encodeBootText(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
194  bool decodeBootText(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
195 
196  void clearVFOSettings();
197 
198  void clearZones();
199  bool encodeZones(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
200  bool createZones(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
201  bool linkZones(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
202 
203  void clearScanLists();
204  bool encodeScanLists(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
205  bool createScanLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
206  bool linkScanLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
207 
208  void clearGroupLists();
209  bool encodeGroupLists(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack());
210  bool createGroupLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
211  bool linkGroupLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack());
212 
213  void clearEncryption();
214  bool encodeEncryption(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err);
215  bool createEncryption(Config *config, Context &ctx, const ErrorStack &err);
216  bool linkEncryption(Config *config, Context &ctx, const ErrorStack &err);
217 
218 protected:
220  struct Offset {
222  static constexpr unsigned int timestamp() { return 0x000088; }
223  static constexpr unsigned int settings() { return 0x0000e0; }
224  static constexpr unsigned int buttons() { return 0x000108; }
225  static constexpr unsigned int messages() { return 0x000128; }
226  static constexpr unsigned int encryption() { return 0x001370; }
228  };
229 };
230 
231 #endif // RD5R_CODEPLUG_HH
The base class of all channels (analog and digital) of a codeplug configuration.
Definition: channel.hh:34
Base class for all codeplug contexts.
Definition: codeplug.hh:238
Certain flags passed to CodePlug::encode to control the transfer and encoding of the codeplug.
Definition: codeplug.hh:25
The config class, representing the codeplug configuration.
Definition: config.hh:70
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:41
Implements the specialization of the Radioddity channel for the RD5R radio.
Definition: rd5r_codeplug.hh:87
bool linkChannelObj(Channel *c, Context &ctx) const
Links a previously constructed channel to the rest of the configuration.
Definition: rd5r_codeplug.cc:111
virtual void setSquelch(unsigned level)
Sets the squelch level.
Definition: rd5r_codeplug.cc:70
virtual unsigned squelch() const
Returns the squelch level.
Definition: rd5r_codeplug.cc:66
bool fromChannelObj(const Channel *c, Context &ctx)
Initializes this codeplug channel from the given generic configuration.
Definition: rd5r_codeplug.cc:76
Channel * toChannelObj(Context &ctx) const
Constructs a generic Channel object from the codeplug channel.
Definition: rd5r_codeplug.cc:97
ChannelElement(uint8_t *ptr, size_t size)
Hidden constructor.
Definition: rd5r_codeplug.cc:47
void clear()
Resets the channel.
Definition: rd5r_codeplug.cc:60
Implements the encoding/decoding of encryption keys for the RD-5R radio.
Definition: rd5r_codeplug.hh:139
void setBasicKey(unsigned n, const QByteArray &key)
Sets the n-th "basic" key (32bit).
Definition: rd5r_codeplug.cc:188
EncryptionElement(uint8_t *ptr)
Constructor.
Definition: rd5r_codeplug.cc:167
bool isBasicKeySet(unsigned n) const
Returns true if the n-th "basic" key (32bit) is set.
Definition: rd5r_codeplug.cc:174
QByteArray basicKey(unsigned n) const
Returns the n-th "basic" key (32bit).
Definition: rd5r_codeplug.cc:181
Implements the timestamp for RD-5R codeplugs.
Definition: rd5r_codeplug.hh:113
TimestampElement(uint8_t *ptr, unsigned size)
Hidden constructor.
Definition: rd5r_codeplug.cc:128
void clear()
Resets the timestamp.
Definition: rd5r_codeplug.cc:145
virtual void set(const QDateTime &ts=QDateTime::currentDateTime())
Sets the time stamp.
Definition: rd5r_codeplug.cc:155
virtual ~TimestampElement()
Destructor.
Definition: rd5r_codeplug.cc:140
virtual QDateTime get() const
Returns the time stamp.
Definition: rd5r_codeplug.cc:150
Represents, encodes and decodes the device specific codeplug for a Baofeng/Radioddity RD-5R.
Definition: rd5r_codeplug.hh:78
bool decodeGeneralSettings(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Updates the given configuration from the general settings.
Definition: rd5r_codeplug.cc:262
void clearContacts()
Clears all contacts in the codeplug.
Definition: rd5r_codeplug.cc:304
void clear()
Clears and resets the complete codeplug to some default values.
Definition: rd5r_codeplug.cc:209
bool decodeElements(Context &ctx, const ErrorStack &err=ErrorStack())
Decodes the binary codeplug and stores its content in the given generic configuration using the given...
Definition: rd5r_codeplug.cc:229
RD5RCodeplug(QObject *parent=0)
Empty constructor.
Definition: rd5r_codeplug.cc:200
bool linkEncryption(Config *config, Context &ctx, const ErrorStack &err)
Links all encryption keys.
Definition: rd5r_codeplug.cc:681
bool encodeGeneralSettings(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Updates the general settings from the given configuration.
Definition: rd5r_codeplug.cc:253
void clearScanLists()
Clears all scan lists.
Definition: rd5r_codeplug.cc:545
bool encodeElements(const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes the given generic configuration as a binary codeplug using the given context.
Definition: rd5r_codeplug.cc:215
void clearVFOSettings()
Clears the VFO settings.
Definition: rd5r_codeplug.cc:473
void clearChannels()
Clear all channels.
Definition: rd5r_codeplug.cc:371
void clearGeneralSettings()
Clears the general settings in the codeplug.
Definition: rd5r_codeplug.cc:248
bool encodeMessages(Context &ctx, const Flags &flags, const ErrorStack &err=ErrorStack())
Encodes preset messages.
Definition: rd5r_codeplug.cc:286
void clearEncryption()
Clears all encryption keys.
Definition: rd5r_codeplug.cc:658
bool encodeGroupLists(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes all group lists.
Definition: rd5r_codeplug.cc:603
bool decodeButtonSettings(Context &ctx, const ErrorStack &err=ErrorStack())
Decodes the button settings.
Definition: rd5r_codeplug.cc:277
bool encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encode all channels.
Definition: rd5r_codeplug.cc:383
bool createGroupLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Creates all group lists.
Definition: rd5r_codeplug.cc:623
bool createZones(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Adds zones to the configuration.
Definition: rd5r_codeplug.cc:509
bool createEncryption(Config *config, Context &ctx, const ErrorStack &err)
Creates all encryption keys.
Definition: rd5r_codeplug.cc:672
bool encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes all digital contacts in the configuration into the codeplug.
Definition: rd5r_codeplug.cc:310
bool encodeZones(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes zones.
Definition: rd5r_codeplug.cc:487
bool encodeDTMFContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes all DTMF contacts.
Definition: rd5r_codeplug.cc:344
void clearBootSettings()
Clear boot settings.
Definition: rd5r_codeplug.cc:444
void clearGroupLists()
Clears all group lists.
Definition: rd5r_codeplug.cc:596
bool encodeBootText(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes boot text.
Definition: rd5r_codeplug.cc:459
bool linkScanLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Links all scan lists.
Definition: rd5r_codeplug.cc:582
void clearBootText()
Clears boot text.
Definition: rd5r_codeplug.cc:454
void clearDTMFContacts()
Clears all DTMF contacts in the codeplug.
Definition: rd5r_codeplug.cc:338
bool encodeButtonSettings(Context &ctx, const Flags &flags, const ErrorStack &err=ErrorStack())
Encodes button settings.
Definition: rd5r_codeplug.cc:272
bool linkChannels(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Links all channels.
Definition: rd5r_codeplug.cc:426
bool decodeBootText(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Updates the given configuration from the boot text settings.
Definition: rd5r_codeplug.cc:466
bool linkGroupLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Links all group lists.
Definition: rd5r_codeplug.cc:638
void clearZones()
Clears all zones.
Definition: rd5r_codeplug.cc:479
bool createContacts(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Adds a digital contact to the configuration for each one in the codeplug.
Definition: rd5r_codeplug.cc:323
bool createChannels(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Adds all defined channels to the configuration.
Definition: rd5r_codeplug.cc:408
void clearMenuSettings()
Clears menu settings.
Definition: rd5r_codeplug.cc:449
bool linkZones(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Links all zones within the configuration.
Definition: rd5r_codeplug.cc:526
virtual bool encodeTimestamp(const ErrorStack &err=ErrorStack())
Sets the time-stamp.
Definition: rd5r_codeplug.cc:241
bool encodeScanLists(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err=ErrorStack())
Encodes all scan lists.
Definition: rd5r_codeplug.cc:552
bool decodeMessages(Context &ctx, const ErrorStack &err=ErrorStack())
Decodes preset messages.
Definition: rd5r_codeplug.cc:294
void clearButtonSettings()
Clears the button settings.
Definition: rd5r_codeplug.cc:268
void clearMessages()
Clears the messages.
Definition: rd5r_codeplug.cc:282
bool createScanLists(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Creates all scan lists.
Definition: rd5r_codeplug.cc:567
virtual void clearTimestamp()
Clears the time-stamp in the codeplug.
Definition: rd5r_codeplug.cc:236
bool encodeEncryption(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err)
Encodes all encryption keys defined.
Definition: rd5r_codeplug.cc:664
bool createDTMFContacts(Config *config, Context &ctx, const ErrorStack &err=ErrorStack())
Adds all DTMF contacts to the configuration.
Definition: rd5r_codeplug.cc:357
Implements the base for all Radioddity channel encodings.
Definition: radioddity_codeplug.hh:33
Represents all encryption keys and settings within the codeplug on the device.
Definition: radioddity_codeplug.hh:1366
Base class of all Radioddity codeplugs.
Definition: radioddity_codeplug.hh:24
Internal offsets between codeplug elements.
Definition: rd5r_codeplug.hh:220