1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38
44 #ifndef CCXX_SERIAL_H_
45 #define CCXX_SERIAL_H_
46
47 #ifndef CCXX_MISSING_H_
49 #endif
50
51 #ifndef CCXX_THREAD_H_
53 #endif
54
55 #ifndef CCXX_EXCEPTION_H_
57 #endif
58
59 #ifndef WIN32
61 #define INVALID_HANDLE_VALUE (-1)
62 #endif
63
64 #ifdef CCXX_NAMESPACES
65 namespace ost {
66 #endif
67
99 {
100 public:
116 };
118
124 };
126
131 };
133
138 };
140
141 private:
144
145 struct {
148 } flags;
149
152
156 void initSerial(void);
157
158 protected:
159
161
163
169 void open(const char *fname);
170
175 void close(void);
176
184 virtual int aRead(char * Data, const int Length);
185
192 virtual int aWrite(const char * Data, const int Length);
193
202
210 {
error(errExtended, err);};
211
212
220 {flags.thrown = !enable;};
221
232 int setPacketInput(int size, unsigned char btimer = 0);
233
243 int setLineInput(char newline = 13, char nl1 = 0);
244
248 void restore(void);
249
253 void flushInput(void);
254
258 void flushOutput(void);
259
263 void waitOutput(void);
264
269 void endSerial(void);
270
276 void initConfig(void);
277
283 {initSerial();};
284
292
293
294 public:
295
303
309
316 Error setSpeed(unsigned long speed);
317
324 Error setCharBits(int bits);
325
332 Error setParity(Parity parity);
333
340 Error setStopBits(int bits);
341
348 Error setFlowControl(Flow flow);
349
356
360 void sendBreak(void);
361
369 {return errid;};
370
378 {return errstr;};
379
388 {return bufsize;};
389
400 };
401
424 {
425 private:
426 int doallocate();
427
430
431 protected:
434
440
445 void allocate(void);
446
451 void endStream(void);
452
459 int underflow(void);
460
469 int uflow(void);
470
478 int overflow(int ch);
479
480 public:
488
493
500 {timeout = to;};
501
509 void interactive(bool flag);
510
517 int sync(void);
518
531 };
532
543 {
544 public:
549
558
564 void open(const char *name);
565
569 void close(void);
570
575 {return (dev < 0);};
576 };
577
589 {
590 public:
598 TTYSession(
const char *name,
int pri = 0,
int stack = 0);
599
601 };
602
603 #ifndef WIN32
604
605 // Not support this right now.......
606 //
609
632 {
633 private:
636 #ifdef USE_POLL
637 struct pollfd *ufd;
638 #endif
642
644
645 protected:
653
659
664 void setDetectPending( bool );
665
670 { return detect_pending; }
671
676 void setDetectOutput( bool );
677
682 { return detect_output; }
683
688 virtual void expired(void);
689
695 virtual void pending(void);
696
701 virtual void disconnect(void);
702
713 {return aWrite((char *)buf, len);};
714
718 virtual void output(void);
719
729 inline int input(
void *buf,
int len)
730 {return aRead((char *)buf, len);};
731 public:
740
747 };
748
772 {
773 private:
779
786
793
797 void run(void);
798
800
801 protected:
808 virtual void onUpdate(unsigned char flag);
809
814 virtual void onEvent(void);
815
823
824 public:
834 void update(unsigned char flag = 0xff);
835
844 SerialService(
int pri = 0,
size_t stack = 0,
const char *
id = NULL);
845
850
858 {return count;};
859 };
860
861 #endif
862
863
864
865 #ifdef COMMON_STD_EXCEPTION
866 class __EXPORT SerException :
public IOException
867 {
868 public:
869 SerException(
const String &str) : IOException(str) {};
870 };
871 #endif
872
873 #ifdef CCXX_NAMESPACES
874 }
875 #endif
876
877 #endif
878
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution co...
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
bool operator!()
Test to see if stream is opened.
int getCount(void)
Get current reference count.
Serial()
This allows later ttystream class to open and close a serial device.
substitute functions which may be missing in target platform libc.
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
int input(void *buf, int len)
Receive "input" for pending data from the serial port.
This is a generic and portable string class.
int output(void *buf, int len)
Transmit "send" data to the serial port.
GNU Common C++ exception model base classes.
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ st...
bool getDetectPending(void) const
Get the current state of the DetectPending flag.
Synchronization and threading services.
The SerialService is a thead service object that is meant to service attached serial ports...
Error getErrorNumber(void)
Often used by a "catch" to fetch the last error of a thrown serial.
char * getErrorString(void)
Often used by a "catch" to fetch the user set error string of a thrown serial.
class __EXPORT SerialService
bool getDetectOutput(void) const
Get the current state of the DetectOutput flag.
int getBufferSize(void)
Get the "buffer" size for buffered operations.
The Serial class is used as the base for all serial I/O services under APE.
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...
Every thread of execution in an application is created by instantiating an object of a class derived ...
void setError(bool enable)
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the...
Timer ports are used to provide synchronized timing events when managed under a "service thread" such...
A more natural C++ "ttystream" class for use by non-threaded applications.
void setTimeout(timeout_t to)
Set the timeout control.
The serial port is an internal class which is attached to and then serviced by a specified SerialServ...
class __EXPORT SerialPort