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

« back to all changes in this revision

Viewing changes to linpsk/textinput.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bruce Walker
  • Date: 2002-02-06 11:43:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020206114338-xqmjmhh01lpjm0g4
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

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
 *    based on the work of  Moe Wheatly, AE4JY                             *  
 
16
 ***************************************************************************/
 
17
 
 
18
#include "textinput.h"
 
19
#include <errno.h>
 
20
 
 
21
extern int errno;
 
22
 
 
23
TextInput::TextInput(int ptt = -1):Input(ptt)
 
24
{
 
25
}
 
26
TextInput::~TextInput()
 
27
{
 
28
}
 
29
 
 
30
/** Opens the Device for writting, for Textfiles this means write nothing ! */
 
31
bool TextInput::open_Device_write(QString Device)
 
32
{
 
33
int j;
 
34
const char name[]="RTTY.out";
 
35
                fd=open(name,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU);
 
36
                if (fd >= 0)
 
37
                        return true;
 
38
                        else
 
39
                        {
 
40
      j= errno;
 
41
                        return false;
 
42
                        }
 
43
}
 
44
 
 
45
/** gets the samples from the device */
 
46
int TextInput::getSamples(double *sample,int anzahl)
 
47
{
 
48
static char Buf[128];
 
49
int pos;
 
50
int i,j;
 
51
double x;
 
52
 
 
53
pos = 0;
 
54
j=0;
 
55
while (j<anzahl)
 
56
 {
 
57
  do
 
58
  i= read(fd,&Buf[pos],sizeof(Buf[0]));
 
59
  while ( (i == 1) && (Buf[pos++] != '\n') && (pos <128) );
 
60
  if ( i== 1 )
 
61
   {
 
62
        if ( pos >= 127)
 
63
                qWarning("Input file has strange lines\n");
 
64
    pos--;
 
65
          Buf[pos]=0;
 
66
    x = atof(Buf);
 
67
          *(sample++)=x/8.;
 
68
    j++;
 
69
                pos=0;
 
70
    }
 
71
   else
 
72
 
 
73
                
 
74
    lseek(fd,0,SEEK_SET);
 
75
                
 
76
 } // End while
 
77
return j;
 
78
}
 
79
 
 
80
/** puts the Samples onto the Device, for a Textmode Device nothing happens */
 
81
int TextInput::putSamples(double *sample,int anzahl)
 
82
{
 
83
int i;
 
84
char c;
 
85
QString s;
 
86
for(i=0;i<anzahl;i++)
 
87
        {
 
88
                s.setNum((int) sample[i]);
 
89
                                write(fd,s.latin1(),s.length());
 
90
                c='\n';
 
91
                write(fd,&c,1);
 
92
        }
 
93
return anzahl;
 
94
}
 
95
        
 
96
/** Dummy */
 
97
void TextInput::PTT(bool mode)
 
98
{
 
99
}
 
100
/** Dummy */
 
101
bool TextInput::setParams(QString *errorstring)
 
102
{
 
103
return true;
 
104
}