~ubuntu-branches/ubuntu/quantal/linpsk/quantal

« back to all changes in this revision

Viewing changes to .pc/gcc-4.6.patch/src/linpsk.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-09-19 21:34:50 UTC
  • Revision ID: package-import@ubuntu.com-20110919213450-w4ezw2kh1w0ttmob
Tags: 1.1-1ubuntu1
Fix FTBFS with g++-4.6. Closes: #624967, LP: #770983.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          |FILENAME|  -  description
 
3
                             -------------------
 
4
    begin                : |DATE|
 
5
    copyright            : (C) |YEAR| by |AUTHOR|
 
6
    email                : |EMAIL|
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *   The PSK part is based on WinPSK 1.0 by Moe Wheatly, AE4JY             *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "linpsk.h"
 
19
 
 
20
 
 
21
#include "controlpanel.h"
 
22
#include "crxdisplay.h"
 
23
#include "ctxdisplay.h"
 
24
 
 
25
#include "parameter.h"
 
26
#include "addrxwindow.h"
 
27
#include "spectrumdisplay.h"
 
28
#include "frequencyselect.h"
 
29
#include "cledbutton.h"
 
30
#include "rttymodulator.h"
 
31
#include "pskmodulator.h"
 
32
#include "bpskmodulator.h"
 
33
#include "qpskmodulator.h"
 
34
#include "mfskmodulator.h"
 
35
#include "ctxbuffer.h"
 
36
#include "crxchannel.h"
 
37
#include "input.h"
 
38
#include "textinput.h"
 
39
#include "waveinput.h"
 
40
#include "csound.h"
 
41
#include "generalsettings.h"
 
42
#include "modemenu.h"
 
43
#include "macrowindow.h"
 
44
#include "addmacro.h"
 
45
#include "deletemacro.h"
 
46
#include "macros.h"
 
47
#include "qsodata.h"
 
48
#include "editmacro.h"
 
49
#include "deletemacro.h"
 
50
#include "renamemacro.h"
 
51
#include "color.h"
 
52
#include "crecording.h"
 
53
 
 
54
 
 
55
#include <QtGui>
 
56
#include <QEventLoop>
 
57
 
 
58
#ifdef HAVE_CONFIG
 
59
#include "config.h"
 
60
#else
 
61
#define VERSION "1.1"
 
62
#endif
 
63
 
 
64
 
 
65
#define ProgramName "LinPSK "
 
66
 
 
67
extern Parameter settings;
 
68
/*
 
69
 *  Constructs a LinPSK as a child of 'parent', with the
 
70
 *  name 'name' and widget flags set to 'f'.
 
71
 *
 
72
 */
 
73
LinPSK::LinPSK ( QWidget* parent, Qt::WFlags fl )
 
74
    : QMainWindow ( parent, fl )
 
75
{
 
76
  RxDisplay = 0;
 
77
  TxDisplay = 0;
 
78
  Control = 0;
 
79
  Sound = 0;
 
80
  SaveParameters = new Parameter();
 
81
 
 
82
  Macro = new Macros(); // Macros will be used in read_config
 
83
  read_config();
 
84
 
 
85
  if ( settings.ApplicationFont == 0 )
 
86
  {
 
87
    settings.ApplicationFont = new QFont ( qApp->font().family() );
 
88
    settings.ApplicationFont->setPixelSize ( 10 );
 
89
    qApp->setFont ( *settings.ApplicationFont );
 
90
  }
 
91
  else
 
92
    qApp->setFont ( *settings.ApplicationFont );
 
93
 
 
94
// Save Settings to be able to make local modifications
 
95
  *SaveParameters = settings;
 
96
 
 
97
  if ( WindowColors.size() == 0 )
 
98
    WindowColors << color[0] ;
 
99
  Modulator = 0;
 
100
  setCentralWidget ( new QWidget ( this ) );
 
101
  centralWidget()->setMinimumSize ( settings.MinimumWindowWidth, settings.MinimumWindowHeight );
 
102
  setWindowTitle ( QString ( ProgramName ) + QString ( VERSION ) );
 
103
  setWindowIcon ( QIcon ( ":/images/linpsk.png" ) );
 
104
// Create Statusbar
 
105
  QStatusBar *StatusBar = this->statusBar();
 
106
  StatusBar->setSizeGripEnabled ( true );
 
107
 
 
108
 
 
109
//Messages
 
110
  msg = new QLabel ( StatusBar );
 
111
  StatusBar->addPermanentWidget ( msg, 2 );
 
112
  msg->setText ( tr ( "Ready" ) );
 
113
 
 
114
// IMD
 
115
  IMD = new QLabel ( StatusBar );
 
116
  StatusBar -> addPermanentWidget ( IMD, 1 );
 
117
 
 
118
 
 
119
// Time
 
120
  zeit = new QLabel ( StatusBar );
 
121
  StatusBar->addPermanentWidget ( zeit, 1 );
 
122
 
 
123
// date
 
124
  datum = new QLabel ( StatusBar );
 
125
  StatusBar ->addPermanentWidget ( datum, 1 );
 
126
  setclock();
 
127
 
 
128
// Let the time pass
 
129
  QTimer *clock = new QTimer ( this );
 
130
  connect ( clock, SIGNAL ( timeout() ), SLOT ( setclock() ) );
 
131
  clock->start ( 60000 );
 
132
 
 
133
  RxDisplay = new CRxDisplay ( centralWidget() );
 
134
  TxDisplay = new CTxDisplay ( centralWidget() );
 
135
 
 
136
  Control = new ControlPanel ( Macro, centralWidget() );
 
137
  RxDisplay->RxFreq->setAfcDisplayMode ( settings.ActChannel->AfcProperties() );
 
138
  RxDisplay->RxFreq->setAfcMode ( settings.ActChannel->getAfcMode() );
 
139
  RxDisplay->setColorList ( &WindowColors );
 
140
  connect ( RxDisplay, SIGNAL ( copyCallSign ( QString ) ), Control->QSO, SLOT ( copyCallSign ( QString ) ) );
 
141
  connect ( RxDisplay, SIGNAL ( copyQTH ( QString ) ), Control->QSO, SLOT ( copyQTH ( QString ) ) );
 
142
  connect ( RxDisplay, SIGNAL ( copyName ( QString ) ), Control->QSO, SLOT ( copyName ( QString ) ) );
 
143
  connect ( RxDisplay, SIGNAL ( copyLocator ( QString ) ), Control->QSO, SLOT ( copyLocator ( QString ) ) );
 
144
  connect ( RxDisplay, SIGNAL ( copyRST ( QString ) ), Control->QSO, SLOT ( copyRST ( QString ) ) );
 
145
 
 
146
  settings.QslData = settings.ActChannel->getQsoData();
 
147
  Control->Display->setPhasePointer ( settings.ActChannel->getPhasePointer() );
 
148
 
 
149
  Control->Display->setColorList ( &WindowColors );
 
150
  //Control->MacroBox->updateMacroWindow ( Macro );
 
151
  // menubar
 
152
  menubar = menuBar();
 
153
// File Menu
 
154
  fileMenu =  menubar->addMenu ( tr ( "File" ) );
 
155
  // Settings Menu
 
156
 
 
157
  editMenu =  menubar->addMenu ( tr ( "Settings" ) );
 
158
 
 
159
  menubar->addSeparator();
 
160
//=======
 
161
  changeRxParams =  menubar->addMenu ( tr ( "RxParams" ) );
 
162
  helpMenu =  menubar->addMenu ( tr ( "Help" ) );
 
163
  QAction *A;
 
164
  // File Menu
 
165
  // ================= File Actions ========
 
166
  A = fileMenu->addAction ( tr ( "Open Demo File" ) );
 
167
  connect ( A, SIGNAL ( activated() ), this, SLOT ( fileOpen() ) );
 
168
  A = fileMenu->addAction ( tr ( "add RxWindow" ) );
 
169
  connect ( A, SIGNAL ( activated() ), this, SLOT ( addRxWindow() ) );
 
170
 
 
171
  fileMenu->addSeparator();
 
172
  fileMenu->addSeparator();
 
173
 
 
174
  A = fileMenu->addAction ( tr ( "Exit" ) );
 
175
  connect ( A, SIGNAL ( activated() ), this, SLOT ( Exit() ) );
 
176
 
 
177
// Settings Menu
 
178
  // ================= Settings Actions=================
 
179
  A = editMenu->addAction ( tr ( "General_Settings" ) );
 
180
  connect ( A, SIGNAL ( activated() ), this, SLOT ( generalSettings() ) );
 
181
  editMenu->addSeparator();
 
182
  A = editMenu->addAction ( tr ( "Add Macros" ) );
 
183
  connect ( A, SIGNAL ( activated() ), this, SLOT ( addMacro() ) );
 
184
  A = editMenu->addAction ( tr ( "Edit Macros" ) );
 
185
  connect ( A , SIGNAL ( activated() ), this, SLOT ( editMacro() ) );
 
186
  A = editMenu->addAction ( tr ( "Delete Macros" ) );
 
187
  connect ( A  , SIGNAL ( activated() ), this, SLOT ( deleteMacro() ) );
 
188
  A = editMenu->addAction ( tr ( "Rename Macros" ) );
 
189
  connect ( A  , SIGNAL ( activated() ), this, SLOT ( renameMacro() ) );
 
190
//===============================================================================
 
191
  A = editMenu->addSeparator();
 
192
 
 
193
  A = editMenu->addAction ( tr ( "Font Settings" ) );
 
194
  connect ( A   , SIGNAL ( activated() ), this, SLOT ( FontSetup() ) );
 
195
  A = editMenu->addAction ( tr ( "ColorSettings" ) );
 
196
  connect ( A , SIGNAL ( activated() ), this, SLOT ( chooseColor() ) );
 
197
  editMenu->addSeparator();
 
198
 
 
199
  A = editMenu->addAction ( tr ( "Save Settings" ) );
 
200
  connect ( A  , SIGNAL ( activated() ), this, SLOT ( saveSettings() ) );
 
201
  // Menu Rx Settings
 
202
  //================Actions for RX Window ===========
 
203
  A = changeRxParams->addAction ( tr ( "Change Rx Mode" ) );
 
204
  connect ( A , SIGNAL ( activated() ), this, SLOT ( setRxMode() ) );
 
205
// A= changeRxParams->addAction(tr( " ???") );
 
206
// connect ( A , SIGNAL ( activated() ), settings.ActChannel, SLOT ( clearRxWindow() ) );
 
207
//Help Menu
 
208
  // ================= Help Actions =========
 
209
  A = helpMenu->addAction ( tr ( "helpContentsAction" ) );
 
210
  connect ( A, SIGNAL ( activated() ), this, SLOT ( helpIndex() ) );
 
211
  A = helpMenu->addAction ( tr ( "helpIndexAction" ) );
 
212
  connect ( A, SIGNAL ( activated() ), this, SLOT ( helpContents() ) );
 
213
  A = helpMenu->addAction ( tr ( "helpAboutAction" ) );
 
214
  connect ( A, SIGNAL ( activated() ), this, SLOT ( helpAbout() ) );
 
215
 
 
216
 
 
217
  languageChange();
 
218
 
 
219
  // signals and slots connections
 
220
 
 
221
//================================= Rx Parames ===================
 
222
//================================================================
 
223
  connect ( TxDisplay, SIGNAL ( startRx() ), this, SLOT ( startRx() ) );
 
224
  connect ( TxDisplay, SIGNAL ( startTx() ), this, SLOT ( startTx() ) );
 
225
  connect ( Macro, SIGNAL ( StartRx() ), this, SLOT ( startRx() ) );
 
226
  connect ( Macro, SIGNAL ( StartTx() ), this, SLOT ( startTx() ) );
 
227
 
 
228
  connect ( RxDisplay, SIGNAL ( startPlotting ( double *, bool ) ), Control->Display, SLOT ( startPlot ( double *, bool ) ) );
 
229
  connect ( Control->Display, SIGNAL ( FrequencyChanged ( double ) ), RxDisplay->RxFreq, SLOT ( setFrequency ( double ) ) );
 
230
  connect ( RxDisplay, SIGNAL ( new_IMD ( float ) ), this, SLOT ( setIMD ( float ) ) );
 
231
  connect ( Control->MacroBox, SIGNAL ( callMacro ( int ) ), this, SLOT ( executeMacro ( int ) ) );
 
232
  connect ( RxDisplay, SIGNAL ( newActiveChannel() ), this, SLOT ( setChannelParams() ) );
 
233
  connect ( RxDisplay->Recording->Record, SIGNAL ( toggled ( bool ) ), this, SLOT ( recording ( bool ) ) );
 
234
//===================================================================
 
235
 
 
236
  TxBuffer = new CTxBuffer();
 
237
  TxDisplay->TxWindow->setTxBuffer ( TxBuffer );
 
238
  apply_settings();
 
239
 
 
240
}
 
241
 
 
242
/*
 
243
 *  Destroys the object and frees any allocated resources
 
244
 */
 
245
LinPSK::~LinPSK()
 
246
{
 
247
 
 
248
  // no need to delete child widgets, Qt does it all for us
 
249
}
 
250
 
 
251
/*
 
252
 *  Sets the strings of the subwidgets using the current
 
253
 *  language.
 
254
 */
 
255
void LinPSK::languageChange()
 
256
{
 
257
  /**
 
258
  // File
 
259
      Open_Demo_File->setText( tr( "Open Demo File" ) );
 
260
      Open_Demo_File->setMenuText( tr( "&Open Demo File" ) );
 
261
      Open_Demo_File->setAccel( tr( "Ctrl+O" ) );
 
262
      fileExitAction->setText( tr( "Exit" ) );
 
263
      fileExitAction->setMenuText( tr( "E&xit" ) );
 
264
      fileExitAction->setAccel( QString::null );
 
265
  // Help
 
266
      helpContentsAction->setText( tr( "Contents" ) );
 
267
      helpContentsAction->setMenuText( tr( "&Contents..." ) );
 
268
      helpContentsAction->setAccel( QString::null );
 
269
      helpIndexAction->setText( tr( "Index" ) );
 
270
      helpIndexAction->setMenuText( tr( "&Index..." ) );
 
271
      helpIndexAction->setAccel( QString::null );
 
272
      helpAboutAction->setText( tr( "About" ) );
 
273
      helpAboutAction->setMenuText( tr( "&About" ) );
 
274
      helpAboutAction->setAccel( QString::null );
 
275
      add_Rx_Window->setText( tr( "add Rx Window" ) );
 
276
      add_Rx_Window->setMenuText( tr( "&Add another RxWindow" ) );
 
277
  // Settings
 
278
      General_Settings->setText( tr( "General Settings" ) );
 
279
      AddMacros->setText( tr( "Add Macro" ) );
 
280
      FontSettings->setText( tr( "Font Settings" ) );
 
281
      ColorSettings->setText( tr( "Color Settings" ) );
 
282
      EditMacros->setText( tr( "Edit Macro" ) );
 
283
      DeleteMacros->setText( tr("Delete Macro") );
 
284
      RenameMacros->setText( tr("Rename Macro") );
 
285
  //    EditFiles->setText( tr( "Edit Files" ) );
 
286
      SaveSettings->setText( tr( "Save Settings" ) );
 
287
  // Rx Params
 
288
      Clear_RxWindow->setMenuText( tr ("Clear active RX Channel") );
 
289
      ChangeRxMode->setMenuText( tr ("Change Mode of active Rx Channel") );
 
290
 
 
291
      menubar->findItem( 0 )->setText( tr( "&File" ) );
 
292
      menubar->findItem( 1 )->setText( tr( "&Settings" ) );
 
293
      menubar->findItem( 2 )->setText( tr( "&RxParams" ) );
 
294
      menubar->findItem( 4 )->setText( tr( "&Help" ) );
 
295
  **/
 
296
}
 
297
 
 
298
void LinPSK::fileOpen()
 
299
{
 
300
  QString fileName;
 
301
 
 
302
  fileName = QFileDialog::getOpenFileName ( 0, tr ( "Open Demofile" ), "", settings.DemoModeFileType[settings.DemoTypeNumber] );
 
303
  if ( !fileName.isEmpty() )
 
304
    settings.inputFilename = fileName;
 
305
}
 
306
 
 
307
void LinPSK::Exit()
 
308
{
 
309
  if ( settings.Status == ON ) // We arejust transmitting
 
310
  {
 
311
    QMessageBox::information ( 0, ProgramName,
 
312
                               "You should stop transmitting before closing this window!" );
 
313
    return;
 
314
  }
 
315
  else
 
316
  {
 
317
    if ( RxDisplay != 0 )
 
318
      RxDisplay->stop_process_loop();
 
319
    settings = *SaveParameters;
 
320
    save_config();
 
321
    qApp->quit();
 
322
    return;
 
323
  }
 
324
}
 
325
 
 
326
void LinPSK::helpIndex()
 
327
{}
 
328
 
 
329
void LinPSK::helpContents()
 
330
{}
 
331
 
 
332
void LinPSK::helpAbout()
 
333
{}
 
334
 
 
335
 
 
336
void LinPSK::addRxWindow()
 
337
{
 
338
  AddRxWindow *Channel = new AddRxWindow();
 
339
  if ( Channel->exec() != 0 )
 
340
  {
 
341
    AfcMode modus;
 
342
    modus = RxDisplay->RxFreq->getAfcMode();
 
343
    settings.ActChannel->setAfcMode ( modus );
 
344
    Mode rxmode = ( Mode ) Channel->selectedMode();
 
345
    if ( WindowColors.size() <= settings.RxChannels )
 
346
      WindowColors << color[ ( settings.RxChannels*51 ) % 256];
 
347
 
 
348
    RxDisplay->addRxWindow ( Channel->frequency(), rxmode, Channel->titleText() );
 
349
 
 
350
    settings.ActChannel->setWindowColor ( WindowColors.at ( settings.RxChannels ) );
 
351
    settings.RxChannels++;
 
352
    RxDisplay->RxFreq->setAfcDisplayMode ( settings.ActChannel->AfcProperties() );
 
353
  }
 
354
 
 
355
}
 
356
 
 
357
 
 
358
 
 
359
void LinPSK::calculateSizeofComponents()
 
360
{
 
361
  /** Anteile in percent of mainwindow **/
 
362
  /** RXDisplay **/
 
363
#define RXPART 36
 
364
  /** TXDisplay **/
 
365
#define TXPART 20
 
366
  /** Controlpanel **/
 
367
#ifndef LINPSK_FOR_MAC
 
368
#define CONTROLPART 37
 
369
#else
 
370
#define CONTROLPART 40
 
371
#endif
 
372
  
 
373
  int width, height;
 
374
  int xpos, ypos;
 
375
  int windowsheight;
 
376
 
 
377
  width = this->width();
 
378
  height = this->height();
 
379
 
 
380
  xpos = 0;
 
381
  ypos = 0;;
 
382
  windowsheight = height * RXPART / 100;
 
383
  if ( RxDisplay != 0 )
 
384
    RxDisplay->setGeometry ( xpos, ypos, width, windowsheight );
 
385
 
 
386
  ypos = ypos + windowsheight;
 
387
  windowsheight = height * TXPART / 100;
 
388
  if ( TxDisplay != 0 )
 
389
    TxDisplay->setGeometry ( xpos, ypos, width, windowsheight );
 
390
  ypos = ypos + windowsheight;
 
391
 
 
392
  windowsheight = height * CONTROLPART / 100;
 
393
  if ( Control != 0 )
 
394
    Control->setGeometry ( xpos, ypos, width, windowsheight );
 
395
}
 
396
 
 
397
 
 
398
 
 
399
void LinPSK::resizeEvent ( QResizeEvent * )
 
400
{
 
401
  calculateSizeofComponents();
 
402
}
 
403
 
 
404
 
 
405
void LinPSK::setclock()
 
406
{
 
407
  QString s;
 
408
  QDateTime t;
 
409
  t = QDateTime::currentDateTime();
 
410
  t = t.addSecs ( settings.timeoffset * 3600 );
 
411
  s.sprintf ( " %2d:%2d UTC", t.time().hour(), t.time().minute() );
 
412
  s.replace ( QRegExp ( ": " ), ":0" );
 
413
  zeit->setText ( s );
 
414
  zeit->update();
 
415
  s = t.toString ( "dd.MM.yyyy" );
 
416
  datum->setText ( s );
 
417
}
 
418
 
 
419
void LinPSK::setIMD ( float IMDvalue )
 
420
{
 
421
  QString s;
 
422
  if ( IMDvalue != 0.0 )
 
423
    s.sprintf ( " IMD = %6.2f dB", IMDvalue );
 
424
  else
 
425
    s.sprintf ( " IMD " );
 
426
  IMD->setText ( s );
 
427
}
 
428
void LinPSK::startRx()
 
429
{
 
430
  if ( Modulator != 0 )
 
431
  {
 
432
    TxBuffer->insert ( TXOFF_CODE );
 
433
    if ( Sound > 0 )  // Switch Trx to rx
 
434
      while ( Sound->isRunning() ) // Wait for buffer to be cleared
 
435
        qApp->processEvents ( QEventLoop::AllEvents, 100 );
 
436
  }
 
437
  if ( RxDisplay->start_process_loop() )
 
438
  {
 
439
    QString Info;
 
440
    TxDisplay->TxFunctions->setStatus ( OFF );
 
441
    if ( settings.ActChannel != 0 )
 
442
      switch ( settings.ActChannel->getModulationType() )
 
443
      {
 
444
        case QPSK:
 
445
          Info = "QPSK";
 
446
          break;
 
447
 
 
448
        case BPSK:
 
449
          Info = "BPSK";
 
450
          break;
 
451
 
 
452
        case RTTY:
 
453
          Info = "RTTY";
 
454
          break;
 
455
 
 
456
        case MFSK16:
 
457
          Info = "MFSK16";
 
458
          break;
 
459
 
 
460
 
 
461
        default:
 
462
          Info = "undefined";
 
463
      }
 
464
 
 
465
    msg->setText ( tr ( "Receiving " ) + Info );
 
466
  }
 
467
  else
 
468
    TxDisplay->TxFunctions->setStatus ( UNDEF );
 
469
  Control->Display->show();
 
470
  settings.Status = TxDisplay->TxFunctions->getstatus();
 
471
TxDisplay->TxWindow->setFocus();
 
472
}
 
473
 
 
474
void LinPSK::startTx()
 
475
{
 
476
  Mode ModulationType;
 
477
  QString errorstring;
 
478
  QString Info;
 
479
  double Frequency;
 
480
 
 
481
 
 
482
  RxDisplay->stop_process_loop();
 
483
  if ( settings.ActChannel == 0 )
 
484
  {
 
485
    QMessageBox::critical ( 0, " Program Error! LinPsk", "No active Channel available" );
 
486
    TxDisplay->TxFunctions->setStatus ( UNDEF );
 
487
    return;
 
488
  }
 
489
  ModulationType = settings.ActChannel->getModulationType();
 
490
  if ( TxDisplay->TxFreq->getAfcMode() != Off ) // net ?
 
491
    TxDisplay->TxFreq->setFrequency ( settings.ActChannel->getRxFrequency() );
 
492
  Frequency = TxDisplay->TxFreq->getFrequency();
 
493
  switch ( ModulationType )
 
494
  {
 
495
    case QPSK:
 
496
      Modulator = new QPskModulator ( 11025, Frequency, TxBuffer );
 
497
      Info = "QPSK";
 
498
      break;
 
499
    case BPSK:
 
500
      Modulator = new BPSKModulator ( 11025, Frequency, TxBuffer );
 
501
      Info = "BPSK";
 
502
      break;
 
503
 
 
504
    case RTTY:
 
505
      Modulator = new RTTYModulator ( 11025, Frequency, TxBuffer );
 
506
      if ( settings.ActChannel->getParameter ( Extra ) != 0 )
 
507
        Modulator->setParameter ( Extra, settings.ActChannel->getParameter ( Extra ) );
 
508
      Info = "RTTY";
 
509
      break;
 
510
    case MFSK16:
 
511
      Modulator = new MFSKModulator ( 11025, Frequency, TxBuffer );
 
512
      Info = "MFSK16";
 
513
      break;
 
514
 
 
515
    default:
 
516
      Modulator = new BPSKModulator ( 11025, Frequency, TxBuffer );
 
517
      Info = "BPSK";
 
518
      break;
 
519
  }
 
520
  if ( Sound <= 0 ) // Only create Sound Device once for output
 
521
  {
 
522
    if ( settings.DemoMode )
 
523
    {
 
524
      if ( settings.DemoTypeNumber == 0 )
 
525
        Sound = new WaveInput ( -1 );
 
526
      else
 
527
        Sound = new TextInput ( -1 );
 
528
      msg->setText ( tr ( "Transmitting (Demo)" ) );
 
529
    }
 
530
    else
 
531
      Sound = new CSound ( settings.serial );
 
532
    connect ( Sound, SIGNAL ( samplesAvailable() ), this, SLOT ( process_txdata() ) );
 
533
  }
 
534
  if ( Sound <= 0 )
 
535
  {
 
536
    QMessageBox::critical ( 0, " Program Error! LinPsk", "Could not create Sound Device for Output" );
 
537
    TxDisplay->TxFunctions->setStatus ( ON );
 
538
    return;
 
539
  }
 
540
 
 
541
  if ( Sound->open_Device_write ( &errorstring ) < 0 )
 
542
  {
 
543
    QMessageBox::information ( 0, ProgramName, errorstring );
 
544
    stopTx();
 
545
    return;
 
546
  }
 
547
 
 
548
  connect ( Modulator, SIGNAL ( charSend ( char ) ), settings.ActChannel, SLOT ( updateRx ( char ) ) );
 
549
  TxDisplay->TxFunctions->setStatus ( ON );
 
550
  msg->setText ( tr ( "Transmitting " ) + Info );
 
551
  TxDisplay->TxWindow->setFocus();
 
552
  settings.Status = TxDisplay->TxFunctions->getstatus();
 
553
  Control->Display->hide();
 
554
 
 
555
  Txcount = BUF_SIZE;
 
556
//  process_txdata(); // Generate first Sample
 
557
  Sound->PTT ( true );
 
558
  Sound->start();
 
559
}
 
560
 
 
561
void LinPSK::process_txdata()
 
562
{
 
563
  int length;
 
564
// To avoid pending calls to process_txdata() after stopping tx
 
565
//  when Modulator is alredy deleted
 
566
  if (Modulator == 0)
 
567
    return;
 
568
  if ( Txcount > 0 )
 
569
  {
 
570
    length = Modulator->CalcSignal ( Output, BUF_SIZE );
 
571
    if ( length <= 0 )
 
572
    {
 
573
 
 
574
      length = -length;
 
575
      while ( length < BUF_SIZE )
 
576
        Output[length++] = 0.0;
 
577
      length = BUF_SIZE;
 
578
      Txcount = Sound->putSamples ( Output, length );
 
579
      stopTx();
 
580
      return;
 
581
    }
 
582
  }
 
583
  else
 
584
    length = BUF_SIZE;
 
585
 
 
586
  Txcount = Sound->putSamples ( Output, length ); // If Txcount >= 0 and length < BUF_SIZE
 
587
  // we've reached end of Transmiision
 
588
 
 
589
}
 
590
 
 
591
void LinPSK::generalSettings()
 
592
{
 
593
  GeneralSettings *LocalSettings = new GeneralSettings ( this );
 
594
  if ( LocalSettings->exec() != 0 )
 
595
    settings = LocalSettings->getSettings();
 
596
  apply_settings();
 
597
}
 
598
void LinPSK::chooseColor()
 
599
{
 
600
  int ID = settings.ActChannel->getID();
 
601
  QColor color = QColorDialog::getColor ( WindowColors[ID], this );
 
602
  if ( color.isValid() )
 
603
  {
 
604
    settings.ActChannel->setWindowColor ( color );
 
605
    WindowColors[ID] = color;
 
606
    RxDisplay->repaint();
 
607
    RxDisplay->newColor();
 
608
  }
 
609
 
 
610
}
 
611
void LinPSK::FontSetup()
 
612
{
 
613
  bool ok;
 
614
  QFont f = QFontDialog::getFont ( &ok, font(), this );
 
615
  if ( ok )
 
616
  {
 
617
    settings.ApplicationFont->setFamily ( f.family() );
 
618
    int ii = f.pixelSize();
 
619
    if ( ii <= 0 )
 
620
    {
 
621
      ii = f.pointSize();
 
622
      settings.ApplicationFont->setPointSize ( ii );
 
623
    }
 
624
    else
 
625
      settings.ApplicationFont->setPixelSize ( ii );
 
626
 
 
627
    qApp->setFont ( f );
 
628
  }
 
629
}
 
630
void LinPSK::stopTx()
 
631
{
 
632
  Modulator->disconnect();
 
633
  if ( Sound != 0 )
 
634
  {
 
635
    Sound->PTT ( false );
 
636
    Sound->close_Device();
 
637
  }
 
638
  delete Modulator;
 
639
  Modulator = 0;
 
640
}
 
641
 
 
642
void LinPSK::apply_settings()
 
643
{
 
644
  selectPTTDevice();
 
645
}
 
646
void LinPSK::setChannelParams()
 
647
{
 
648
  Control->Display->setPhasePointer ( settings.ActChannel->getPhasePointer() );
 
649
  Control->QSO->newChannel();
 
650
  if ( settings.ActChannel != 0 )
 
651
  {
 
652
    QString Info;
 
653
    switch ( settings.ActChannel->getModulationType() )
 
654
    {
 
655
 
 
656
      case QPSK:
 
657
        Info = "QPSK";
 
658
        break;
 
659
 
 
660
      case BPSK:
 
661
        Info = "BPSK";
 
662
        break;
 
663
 
 
664
      case RTTY:
 
665
        Info = "RTTY";
 
666
        break;
 
667
 
 
668
      case MFSK16:
 
669
        Info = "MFSK16";
 
670
        break;
 
671
      default:
 
672
        Info = "undefined";
 
673
    }
 
674
    RxDisplay->RxFreq->setAfcDisplayMode ( settings.ActChannel->AfcProperties() );
 
675
    msg->setText ( tr ( "Receiving " ) + Info );
 
676
  }
 
677
}
 
678
void LinPSK::setRxMode()
 
679
{
 
680
  QString Info;
 
681
  ModeMenu Menu ;
 
682
  ExtraParameter *Param;
 
683
  Param = ( ExtraParameter * ) settings.ActChannel->getParameter ( Extra );
 
684
  if ( Param != 0 )
 
685
    Menu.setParameter ( *Param );
 
686
  if ( Menu.exec() != 0 )
 
687
  {
 
688
    Mode rxmode = ( Mode ) Menu.selectedMode();
 
689
    settings.ActChannel->setMode ( rxmode );
 
690
    RxDisplay->RxFreq->setAfcDisplayMode ( settings.ActChannel->AfcProperties() );
 
691
    RxDisplay->RxFreq->setAfcMode ( settings.ActChannel->getAfcMode() );
 
692
    Control->Display->setPhasePointer ( settings.ActChannel->getPhasePointer() );
 
693
    settings.ActChannel->setParameter ( Extra, &Menu.getParameter() );
 
694
  }
 
695
  if ( settings.ActChannel != 0 )
 
696
    switch ( settings.ActChannel->getModulationType() )
 
697
    {
 
698
      case QPSK:
 
699
        Info = "QPSK";
 
700
        break;
 
701
 
 
702
      case BPSK:
 
703
        Info = "BPSK";
 
704
        break;
 
705
 
 
706
      case RTTY:
 
707
        Info = "RTTY";
 
708
        break;
 
709
 
 
710
      case MFSK16:
 
711
        Info = "MFSK16";
 
712
        break;
 
713
 
 
714
      default:
 
715
        Info = "undefined";
 
716
    }
 
717
 
 
718
  msg->setText ( tr ( "Receiving " ) + Info );
 
719
}
 
720
 
 
721
void LinPSK::save_config()
 
722
{
 
723
  int i;
 
724
  QSettings config ( "DL1KSV", "LinPSK" );
 
725
  /** Windows Parameter **/
 
726
  config.beginGroup ( "WindowsParameter" );
 
727
// config.setValue ( "MinimumWindowWidth", settings.MinimumWindowWidth );
 
728
  config.setValue ( "WindowWidth", width() );
 
729
// config.setValue ( "MinimumWindowHeight", settings.MinimumWindowHeight );
 
730
  config.setValue ( "Xpos", this->x() );
 
731
  config.setValue ( "Ypos", this->y() );
 
732
  config.setValue ( "WindowHeight", height() );
 
733
  config.setValue ( "FontName", qApp->font().family() );
 
734
  config.setValue ( "FontSize",  qApp->font().pointSize() );
 
735
  config.endGroup();
 
736
  /** DemoMode **/
 
737
  config.setValue ( "DemoMode", settings.DemoMode );
 
738
  config.setValue ( "DemoTypeNumber", settings.DemoTypeNumber );
 
739
//Operating
 
740
  config.setValue ( "Callsign", settings.callsign );
 
741
  config.setValue ( "MyLocator", settings.myLocator );
 
742
 
 
743
  config.setValue ( "PTTDevice", settings.SerialDevice );
 
744
//Logging
 
745
  config.setValue ( "Directory", settings.Directory );
 
746
  config.setValue ( "QSoFileName", settings.QSOFileName );
 
747
  config.setValue ( "FileLog", settings.fileLog );
 
748
  config.setValue ( "LinLog", settings.LinLog );
 
749
  if ( settings.LinLog )
 
750
  {
 
751
    config.setValue ( "Host", settings.Host );
 
752
    config.setValue ( "Port", settings.Port );
 
753
  }
 
754
 
 
755
  config.setValue ( "TimeOffset", settings.timeoffset );
 
756
  config.setValue ( "dateFormat", settings.dateFormat );
 
757
  config.setValue ( "Slashed0", settings.slashed0 );
 
758
  config.setValue ("autoCrLf",settings.autoCrLf);
 
759
  /** Colors **/
 
760
  if ( WindowColors.size() > 0 )
 
761
  {
 
762
    config.beginWriteArray ( "Colors" );
 
763
    for ( i = 0; i < WindowColors.size();i++ )
 
764
    {
 
765
      config.setArrayIndex ( i );
 
766
      config.setValue ( "r", WindowColors[i].red() );
 
767
      config.setValue ( "g", WindowColors[i].green() );
 
768
      config.setValue ( "b", WindowColors[i].blue() );
 
769
    }
 
770
    config.endArray();
 
771
  }
 
772
// Macros
 
773
  if ( ( Macro->count() > 0 ) )
 
774
  {
 
775
    config.beginWriteArray ( "Macros" );
 
776
    for ( i = 0; i < Macro->count();i++ )
 
777
    {
 
778
      config.setArrayIndex ( i );
 
779
      config.setValue ( "Name", Macro->getMacroName ( i ) );
 
780
      QString s = Macro->getDefinition ( i );
 
781
      config.setValue ( "Definition", s );
 
782
      config.setValue ( "Accelerator", Macro->getAccelerator ( i ) );
 
783
    }
 
784
    config.endArray();
 
785
  }
 
786
 
 
787
}
 
788
 
 
789
void LinPSK::executeMacro ( int MacroNumber )
 
790
{
 
791
  Macro->executeMacro ( MacroNumber, TxBuffer );
 
792
}
 
793
 
 
794
void LinPSK::addMacro()
 
795
{
 
796
 
 
797
  AddMacro *NewMacro = new AddMacro ( Macro );
 
798
// NewMacro->setKeywords ( Macro );
 
799
  if ( NewMacro->exec() != 0 )
 
800
  {
 
801
    Macro->insert ( NewMacro->macroName(),
 
802
                    NewMacro->macroDefinition(), NewMacro->accelerator(), NewMacro->position() );
 
803
    Control->MacroBox->updateMacroWindow ( Macro );
 
804
  }
 
805
}
 
806
void LinPSK::editMacro()
 
807
{
 
808
  if ( Macro->count() > 0 )
 
809
  {
 
810
    EditMacro *Edit = new EditMacro ( Macro );
 
811
 
 
812
    if ( Edit->exec() != 0 )
 
813
//   Control->MacroBox->updateMacroWindow ( Macro );
 
814
      Control->MacroBox->setMacroWindow ( Macro );
 
815
  }
 
816
}
 
817
void LinPSK::deleteMacro()
 
818
{
 
819
  if ( Macro->count() > 0 )
 
820
  {
 
821
    DeleteMacro *Del = new DeleteMacro ( Macro );
 
822
 
 
823
    if ( Del->exec() != 0 )
 
824
      Control->MacroBox->setMacroWindow ( Macro );
 
825
  }
 
826
}
 
827
void LinPSK::renameMacro()
 
828
{
 
829
  if ( Macro->count() > 0 )
 
830
  {
 
831
    RenameMacro *Ren = new RenameMacro ( Macro );
 
832
 
 
833
    if ( Ren->exec() != 0 )
 
834
      Control->MacroBox->setMacroWindow ( Macro );
 
835
  }
 
836
}
 
837
 
 
838
void LinPSK::read_config()
 
839
{
 
840
  QSettings config ( "DL1KSV", "LinPSK" );
 
841
 
 
842
  int HeighttoSet = 0;
 
843
  int WidthtoSet = 0;
 
844
  int X = -1;
 
845
  int Y = -1;
 
846
  int i, size;
 
847
// Try to read settings from Configfile
 
848
  /** Windows Parameter **/
 
849
  config.beginGroup ( "WindowsParameter" );
 
850
// settings.MinimumWindowWidth = config.value ( "MinimumWindowWidth" , 600 ).toInt();
 
851
  WidthtoSet = config.value ( "WindowWidth" ).toInt();
 
852
// settings.MinimumWindowHeight = config.value ( "MinimumWindowHeight", 400 ).toInt();
 
853
  X = config.value ( "Xpos" ).toInt();
 
854
  Y = config.value ( "Ypos" ).toInt();
 
855
  HeighttoSet = config.value ( "WindowHeight" ).toInt();
 
856
  if ( config.contains ( "FontName" ) )
 
857
  {
 
858
    settings.ApplicationFont = new QFont ( config.value ( "FontName" ).toString() );
 
859
    size = config.value ( "FontSize" ).toInt();
 
860
    if ( size < 10 )
 
861
      size = 10;
 
862
    settings.ApplicationFont->setPointSize ( size );
 
863
 
 
864
  }
 
865
  config.endGroup();
 
866
  /** DemoMode **/
 
867
  settings.DemoMode = config.value ( "DemoMode" ).toBool();
 
868
  settings.DemoTypeNumber = config.value ( "DemoTypeNumber" ).toInt();
 
869
//Operating
 
870
  settings.callsign = config.value ( "Callsign" ).toString();
 
871
  settings.myLocator = config.value ( "MyLocator" ).toString();
 
872
 
 
873
  settings.SerialDevice = config.value ( "PTTDevice" ).toString();
 
874
//Logging
 
875
  settings.Directory = config.value ( "Directory", QDir::homePath() ).toString();
 
876
 
 
877
  settings.QSOFileName = config.value ( "QSoFileName" ).toString();
 
878
  settings.fileLog = config.value ( "FileLog", true ).toBool();
 
879
  settings.LinLog = config.value ( "LinLog", false ).toBool();
 
880
  if ( settings.LinLog )
 
881
  {
 
882
    settings.Host = config.value ( "Host", "localhost" ).toString();
 
883
    settings.Port = config.value ( "Port", 8080 ).toInt();
 
884
  }
 
885
  settings.timeoffset = config.value ( "TimeOffset" ).toInt();
 
886
  settings.dateFormat = config.value ( "dateFormat", "dd.MM.yyyy" ).toString();
 
887
  settings.slashed0 = config.value ( "Slashed0" ).toBool();
 
888
  settings.autoCrLf = config.value("autoCrLf").toBool();
 
889
  /** Colors **/
 
890
  if ( config.contains ( "Colors" ) )
 
891
  {
 
892
    size = config.beginReadArray ( "Colors" );
 
893
    for ( i = 0; i < size;i++ )
 
894
    {
 
895
      config.setArrayIndex ( i );
 
896
      int r = config.value ( "r" ).toInt();
 
897
      int g = config.value ( "g" ).toInt();
 
898
      int b = config.value ( "b" ).toInt();
 
899
      WindowColors.push_back ( QColor ( r, g, b ) );
 
900
 
 
901
    }
 
902
    config.endArray();
 
903
  }
 
904
// Macros
 
905
  size = config.beginReadArray ( "Macros" );
 
906
  if ( size > 0 )
 
907
  {
 
908
    QString name, def, acc;
 
909
 
 
910
    for ( i = 0; i < size;i++ )
 
911
    {
 
912
      config.setArrayIndex ( i );
 
913
      name = config.value ( "Name" ).toString();
 
914
      def = config.value ( "Definition" ).toString();
 
915
      acc = config.value ( "Accelerator" ).toString();
 
916
      Macro->insert ( name, def, acc, i + 1 );
 
917
    }
 
918
    config.endArray();
 
919
  }
 
920
 
 
921
  if ( ( HeighttoSet > 0 ) && ( WidthtoSet > 0 ) )
 
922
    resize ( WidthtoSet, HeighttoSet );
 
923
  if ( ( X >= 0 ) && ( Y >= 0 ) )
 
924
    move ( X, Y );
 
925
 
 
926
}
 
927
void LinPSK::selectPTTDevice()
 
928
{
 
929
 
 
930
//if (settings.serial >0 )
 
931
//  close(settings.serial);
 
932
  settings.serial = -1;
 
933
  if ( settings.SerialDevice != "None" )
 
934
//{
 
935
// QMessageBox::information(0,"LinPsk","Trying to open Device " + settings.SerialDevice);
 
936
    settings.serial = open ( settings.SerialDevice.toAscii().data(), O_EXCL | O_WRONLY );
 
937
// if (settings.serial > 0 )
 
938
//  QMessageBox::information(0,"LinPsk","Opening successfull");
 
939
// else
 
940
//  QMessageBox::information(0,"LinPsk","Opening unsuccessfull");
 
941
//}
 
942
  int flags = TIOCM_RTS | TIOCM_DTR;
 
943
  if ( settings.serial > 0 )
 
944
    ioctl ( settings.serial, TIOCMBIC, &flags );
 
945
  else
 
946
    settings.SerialDevice = "None"; //Their seems to be a wrong Value in the ConfigFile
 
947
}
 
948
void LinPSK::recording ( bool on )
 
949
{
 
950
  settings.ActChannel->record ( on );
 
951
}
 
952
void LinPSK::HelpAbout()
 
953
{
 
954
  QMessageBox::about ( this, tr ( "About..." ),
 
955
                       ProgramName + QString ( VERSION ) + "\n written by Volker Schroer, DL1KSV\n" );
 
956
//  setActiveWindow();
 
957
}
 
958
 
 
959
void LinPSK::saveSettings()
 
960
{
 
961
  *SaveParameters = settings;
 
962
  save_config();
 
963
}
 
964
 
 
965
void LinPSK::closeEvent ( QCloseEvent *e )
 
966
{
 
967
  if ( settings.Status != ON ) // We are not just transmitting
 
968
  {
 
969
    if ( RxDisplay != 0 )
 
970
      RxDisplay->stop_process_loop();
 
971
    e->accept();
 
972
    save_config();
 
973
  }
 
974
  else
 
975
  {
 
976
    QMessageBox::information ( 0, ProgramName,
 
977
      "You should stop transmitting before closing this window!" );
 
978
    e->ignore();
 
979
  }
 
980
  return;
 
981
}
 
982