kandy

modem.h
1 /*
2  KMLOCfg
3 
4  A utility to configure the ELSA MicroLink(tm) Office modem.
5 
6  Copyright (C) 2000 Oliver Gantz <Oliver.Gantz@epost.de>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  ------
23  ELSA and MicroLink are trademarks of ELSA AG, Aachen.
24 */
25 
26 #ifndef MODEM_H
27 #define MODEM_H
28 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include <termios.h>
34 
35 #include <tqobject.h>
36 #include <tqstring.h>
37 #include <tqtimer.h>
38 #include <tqsocketnotifier.h>
39 #include <tqfile.h>
40 
41 #include "kandyprefs.h"
42 
43 
44 
45 
46 class Modem : public TQObject
47 {
48  TQ_OBJECT
49 
50 public:
51  Modem(KandyPrefs *kprefs, TQObject *parent = 0, const char *name = 0);
52  virtual ~Modem();
53 
54  void setSpeed(int speed);
55  void setData(int data);
56  void setParity(char parity);
57  void setStop(int stop);
58 
59  bool open();
60  void close();
61 
62  bool isOpen() { return mOpen; }
63 
64  void flush();
65 
66  bool lockDevice();
67  void unlockDevice();
68 
69  bool dsrOn();
70  bool ctsOn();
71 
72  void writeChar(const char c);
73  void writeLine(const char *line);
74 
75  void timerStart(int msec);
76 
77  void receiveXModem(bool crc);
78  void abortXModem();
79 
80 private slots:
81  void timerDone();
82 
83  void readChar(int);
84  void readXChar(int);
85 
86 private:
87  bool mOpen;
88 
89  void init();
90  void xreset();
91 
92  uchar calcChecksum();
93  ushort calcCRC();
94 
95  bool is_locked;
96  struct termios init_tty;
97 
98  speed_t cspeed;
99  tcflag_t cflag;
100 
101  int fd;
102  TQTimer *timer;
103  TQSocketNotifier *sn;
104 
105  uchar buffer[1024];
106  int bufpos;
107 
108  int xstate;
109  bool xcrc;
110  uchar xblock;
111  int xsize;
112 
113  KandyPrefs *prefs;
114 
115 signals:
116  void gotLine(const char *);
117  void gotXBlock(const uchar *, int);
118  void xmodemDone(bool);
119  void timeout();
120 
121  void errorMessage( const TQString & );
122 };
123 
124 
125 #endif // MODEM_H