~ubuntu-branches/debian/sid/linpsk/sid

« back to all changes in this revision

Viewing changes to src/textinput.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Hamish Moffatt
  • Date: 2005-04-10 18:17:27 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050410181727-3l9dnfg0sp7bhk13
Tags: 0.8.1-1
* New upstream release 0.8.1
  * Modified upstream configure.in to support FHS-compliant Qt
    installation! (ie /usr/include/qt3, not /usr/lib/qt3/include) :-(
  * Re-autotools with autoconf2.59 and automake-1.9
* linpsk is no longer a Debian-native package (dsc/tar.gz)
* Now maintained by the debian-hams group
* Switch to debhelper 4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          textinput.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Sat May 5 2001
 
5
    copyright            : (C) 2001 by Volker Schroer
 
6
    email                : DL1KSV@gmx.de
 
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
 ***************************************************************************/
 
16
 
 
17
#include "textinput.h"
 
18
#include <qobject.h>
 
19
#include <errno.h>
 
20
#include "parameter.h"
 
21
 
 
22
extern Parameter settings;
 
23
extern int errno;
 
24
 
 
25
TextInput::TextInput(int ptt = -1):Input(ptt)
 
26
{
 
27
}
 
28
TextInput::~TextInput()
 
29
{
 
30
}
 
31
 
 
32
/** Opens the Device for writting, for Textfiles this means write nothing ! */
 
33
bool TextInput::open_Device_write(QString *errorstring)
 
34
{
 
35
 
 
36
const char name[]="Demo.out";
 
37
fd=open(name,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU);
 
38
if (fd >= 0)
 
39
  return true;
 
40
else
 
41
 {
 
42
  *errorstring= QString(QObject::tr("Could not open Demo.out"));
 
43
   return false;
 
44
 }
 
45
}
 
46
 
 
47
/** gets the samples from the device */
 
48
int TextInput::getSamples(double *sample,int anzahl)
 
49
{
 
50
static char Buf[128];
 
51
int pos;
 
52
int i,j;
 
53
double x;
 
54
 
 
55
pos = 0;
 
56
j=0;
 
57
while (j<anzahl)
 
58
 {
 
59
  do
 
60
  i= read(fd,&Buf[pos],sizeof(Buf[0]));
 
61
  while ( (i == 1) && (Buf[pos++] != '\n') && (pos <128) );
 
62
  if ( i== 1 )
 
63
   {
 
64
        if ( pos >= 127)
 
65
                qWarning("Input file has strange lines\n");
 
66
    pos--;
 
67
          Buf[pos]=0;
 
68
    x = atof(Buf);
 
69
          *(sample++)=x;
 
70
    j++;
 
71
                pos=0;
 
72
    }
 
73
   else
 
74
 
 
75
                
 
76
    lseek(fd,0,SEEK_SET);
 
77
                
 
78
 } // End while
 
79
return j;
 
80
}
 
81
 
 
82
/** puts the Samples onto the Device, for a Textmode Device nothing happens */
 
83
int TextInput::putSamples(double *sample,int anzahl)
 
84
{
 
85
int i;
 
86
char c;
 
87
QString s;
 
88
for(i=0;i<anzahl;i++)
 
89
        {
 
90
         
 
91
                s.setNum(sample[i],'f',6);
 
92
                write(fd,s.latin1(),s.length());
 
93
                c='\n';
 
94
                write(fd,&c,1);
 
95
        }
 
96
return anzahl;
 
97
}
 
98
        
 
99
/** Dummy */
 
100
void TextInput::PTT(bool )
 
101
{
 
102
}
 
103
/** Dummy */
 
104
bool TextInput::open_Device_read(QString *errorstring)
 
105
{
 
106
*errorstring=QString("");
 
107
if (settings.inputFilename == "" )
 
108
 {
 
109
   *errorstring= QString(QObject::tr("Error, no Demofile selected")); 
 
110
    return false;
 
111
  }
 
112
fd = open(settings.inputFilename,O_RDONLY);
 
113
if (fd > 0)
 
114
        return true;
 
115
else
 
116
 {
 
117
    *errorstring= QString(QObject::tr("Error, Could not open Demofile "));
 
118
    return false;
 
119
  }
 
120
   
 
121
}
 
122
bool TextInput::close_Device()
 
123
{
 
124
if (fd >= 0)
 
125
        close(fd);
 
126
fd = -1;
 
127
return true;
 
128
}
 
129