~hmatuschek/+junk/qdmr-package

« back to all changes in this revision

Viewing changes to lib/uv390.cc

  • Committer: Hannes Matuschek
  • Date: 2020-07-07 14:34:22 UTC
  • mto: (17.1.1 qdmr-package)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: hmatuschek@gmail.com-20200707143422-1djcxrjkem3k5kb1
Tags: upstream-0.3.0
ImportĀ upstreamĀ versionĀ 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
UV390::UV390(QObject *parent)
39
 
  : Radio(parent), _name("TYT MD-UV390"), _dev(nullptr), _config(nullptr)
 
39
  : Radio(parent), _name("TYT MD-UV390"), _dev(nullptr), _codeplugUpdate(true), _config(nullptr)
40
40
{
41
41
  // pass...
42
42
}
89
89
}
90
90
 
91
91
bool
92
 
UV390::startUpload(Config *config, bool blocking) {
 
92
UV390::startUpload(Config *config, bool blocking, bool update) {
93
93
  if (StatusIdle != _task)
94
94
    return false;
95
95
 
104
104
  }
105
105
 
106
106
  _task = StatusUpload;
 
107
  _codeplugUpdate = update;
107
108
  if (blocking) {
108
109
    this->run();
109
110
    return (StatusIdle == _task);
195
196
      totb += _codeplug.image(0).element(n).data().size()/BSIZE;
196
197
    }
197
198
 
198
 
    // First download codeplug from device:
199
199
    size_t bcount = 0;
200
 
    for (int n=0; n<_codeplug.image(0).numElements(); n++) {
201
 
      uint addr = _codeplug.image(0).element(n).address();
202
 
      uint size = _codeplug.image(0).element(n).data().size();
203
 
      uint b0 = addr/BSIZE, nb = size/BSIZE;
204
 
      for (uint b=0; b<nb; b++, bcount++) {
205
 
        if (! _dev->read_block(b0+b, _codeplug.data((b0+b)*BSIZE), BSIZE)) {
206
 
          _errorMessage = QString("%1 Cannot upload codeplug: %2").arg(__func__)
207
 
              .arg(_dev->errorMessage());
208
 
          logError() << _errorMessage;
209
 
          _task = StatusError;
210
 
          _dev->reboot();
211
 
          _dev->close();
212
 
          _dev->deleteLater();
213
 
          emit downloadError(this);
214
 
          return;
 
200
 
 
201
    // If codeplug gets updated, download codeplug from device first:
 
202
    if (_codeplugUpdate) {
 
203
      for (int n=0; n<_codeplug.image(0).numElements(); n++) {
 
204
        uint addr = _codeplug.image(0).element(n).address();
 
205
        uint size = _codeplug.image(0).element(n).data().size();
 
206
        uint b0 = addr/BSIZE, nb = size/BSIZE;
 
207
        for (uint b=0; b<nb; b++, bcount++) {
 
208
          if (! _dev->read_block(b0+b, _codeplug.data((b0+b)*BSIZE), BSIZE)) {
 
209
            _errorMessage = QString("%1 Cannot upload codeplug: %2").arg(__func__)
 
210
                .arg(_dev->errorMessage());
 
211
            logError() << _errorMessage;
 
212
            _task = StatusError;
 
213
            _dev->reboot();
 
214
            _dev->close();
 
215
            _dev->deleteLater();
 
216
            emit downloadError(this);
 
217
            return;
 
218
          }
 
219
          emit uploadProgress(float(bcount*50)/totb);
215
220
        }
216
 
        emit uploadProgress(float(bcount*50)/totb);
217
221
      }
218
222
    }
219
223
 
220
 
    // Send encode config into codeplug
 
224
    // Encode config into codeplug
221
225
    _codeplug.encode(_config);
222
226
 
223
227
    // then erase memory