00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #ifndef INC_MI32_PORTS_H
00063 #define INC_MI32_PORTS_H
00064
00065 #ifndef INC_STDIO_H
00066 #include <stdio.h>
00067 #define INC_STDIO_H
00068 #endif
00069
00070 #ifndef INC_MI32_FIXEDSTR_H
00071 #include <mi32/fixedstr.h>
00072 #endif
00073
00074 #ifndef INC_MI32_GENERICRW_H
00075 #include <mi32/genericrw.h>
00076 #endif
00077
00078
00079 #ifndef GENERATING_DOXYGEN_OUTPUT
00080 struct _PortSpecific {
00081 FIXEDSTRING<80> name;
00082 int num;
00083 };
00084
00085 struct _PortOption {
00086 char *name;
00087 int value;
00088 };
00089
00090 struct _PortOptionType {
00091 char *name;
00092 short num;
00093 short radio;
00094 char *dft;
00095 _PortOption *list;
00096 };
00097 #endif
00098
00099 struct MPORT;
00100
00101 struct MPORTTYPE {
00102 char name[20];
00103 int type_num;
00104 int (*init)(MPORT *, MPORTTYPE *, char *);
00105 int (*get_status)(MPORT *, char **);
00106 int (*read_data)(MPORT *, UINT8 *, int);
00107 int (*write_data)(MPORT *, const UINT8 *, int);
00108 int (*xxinterface_cmd)(MPORT *, const UINT8 *, int);
00109 int (*xxset_mode)(MPORT *, short);
00110 int (*set_parms)(MPORT *, char **);
00111 int (*xxreset)(MPORT *);
00112 int (*xxabort)(MPORT *);
00113 int (*close)(MPORT *);
00114 int (*scan)(MPORTTYPE *);
00115 int (*flush)(MPORT *);
00116
00117 short NumPorts;
00118 short NumOptionTypes;
00119 _PortSpecific *specific;
00120 _PortOptionType *options;
00121 };
00122
00123 struct PortChannel {
00124 char *buf;
00125 unsigned short len;
00126 unsigned short received;
00127 int allocsize;
00128 int spare;
00129 };
00130
00131 #define MAXPORTCHANNEL 2
00132
00133 struct MPORT {
00134 MIUNICODE *name;
00135 const MPORTTYPE *type;
00136 int unit_num;
00137 unsigned short mode;
00138 short bogus1;
00139 void *data;
00140 int addr;
00141 short word_dma;
00142 unsigned char intnum;
00143 unsigned char dmanum;
00144 PTRINT out_port;
00145 PTRINT in_port;
00146 PTRINT secondary_out;
00147 PTRINT secondary_in;
00148 FILE *stream;
00149 unsigned short status;
00150 UINT8 channel_num;
00151 UINT8 state;
00152 PortChannel channels[MAXPORTCHANNEL + 1];
00153 PortChannel *cp;
00154 void (*oldintfunc)();
00155 unsigned char *buf[2], *bufp;
00156 const unsigned char *busy_data;
00157 int busy_len;
00158 int buflen;
00159 int bufleft;
00160 int curpos;
00161 int curbuf;
00162 int lasterr;
00163 unsigned char out_mask;
00164 unsigned char in_mask;
00165 int InputQueueSize;
00166 int OutputQueueSize;
00167 MIUNICODE *message;
00168 int NoWait;
00169 };
00170
00171
00172
00173
00174
00175
00176 #define PORTTYPE_LPT 0x0001
00177 #define PORTTYPE_COM 0x0002
00178 #define PORTTYPE_FILE 0x0008
00179 #define PORTTYPE_PIPE 0x0080
00180 #define PORTTYPE_SPOOLER 0x0100
00181 #define PORTTYPE_WINPRINT 0x0400
00182 #define PORTTYPE_MACBACK 0x0800
00183
00184
00185 #define PORTSTAT_Error 0x0008
00186 #define PORTSTAT_OffLine 0x0010
00187 #define PORTSTAT_OutOfPaper 0x0020
00188 #define PORTSTAT_NotReady 0x0080
00189 #define PORTSTAT_TimeOut 0x0001
00190 #define PORTSTAT_Abort 0x8000
00191 #define PORTSTAT_DiskFull 0x0100
00192
00193
00194
00195
00196
00197
00198
00199 #define PORTMODE_UnicodeName 0x0100
00200 #define PORTMODE_NonBlocking 0x0200
00201 #define PORTMODE_NOT 0x8000
00202
00203
00204 #define MSERIALFLOW_Hardware 0
00205 #define MSERIALFLOW_XonXoff 1
00206 #define MSERIALFLOW_None 2
00207 #define MSERIALFLOW_NoCTSDSR 3
00208
00209 #define MSERIALPARITY_None 0
00210 #define MSERIALPARITY_Odd 1
00211 #define MSERIALPARITY_Even 2
00212
00213 #define MSERIALBAUD_300 300
00214 #define MSERIALBAUD_600 600
00215 #define MSERIALBAUD_1200 1200
00216 #define MSERIALBAUD_2400 2400
00217 #define MSERIALBAUD_4800 4800
00218 #define MSERIALBAUD_9600 9600
00219 #define MSERIALBAUD_19_2K 19200
00220 #define MSERIALBAUD_38_4K 28400
00221 #define MSERIALBAUD_57_6K 57600
00222
00223 #define MSERIALDATABITS_7 7
00224 #define MSERIALDATABITS_8 8
00225
00226 #define MSERIALSTOPBITS_1 1
00227 #define MSERIALSTOPBITS_2 2
00228 #define MSERIALSTOPBITS_1_5 3
00229
00230
00231 class PORT : public GENERICRW {
00232 public:
00233
00234 enum STATUS {
00235 STATUS_OK = 0,
00236 STATUS_Error = 0x0008,
00237 STATUS_OffLine = 0x0010,
00238 STATUS_OutOfPaper = 0x0020,
00239 STATUS_NotReady = 0x0080,
00240 STATUS_TimeOut = 0x0001,
00241 STATUS_Abort = 0x8000,
00242 STATUS_DiskFull = 0x0100
00243 };
00244
00245 enum TYPE {
00246 TYPE_Automatic = 0,
00247 TYPE_Parallel = 0x0001,
00248 TYPE_Serial = 0x0002,
00249 TYPE_File = 0x0008,
00250 TYPE_Pipe = 0x0080,
00251 TYPE_WindowPrinter = 0x0400,
00252 };
00253
00255 PORT (
00256 TYPE type = TYPE_Automatic
00257 );
00258
00263 PORT(const char* PortType);
00264
00268 PORT(const MPORTTYPE* PortType);
00269
00270 virtual ~PORT();
00271
00272 ERRVALUE Flush (
00273 );
00274
00275 STATUS GetStatus (
00276 ) const;
00277
00280 bool HasDataAvailable (
00281 ) const;
00282
00283 ERRVALUE Open (
00284 const MISTRING& portname,
00285 const char* parameters = 0,
00286 bool bNonBlocking = false
00287 );
00288
00289 void SetParms (
00290 const char*
00291 );
00292
00293 public:
00294 const MPORTTYPE* m_PortType;
00295 MPORT* m_priv;
00296
00297 virtual CAPABILITIES v_GetCapabilities () const;
00298 virtual INT64 v_GetSize () const;
00299 virtual INT64 v_GetSizeLimit () const;
00300 virtual INT32 v_Read (void* buffer, INT32 numbytes, bool AllowPartial);
00301 virtual ERRVALUE v_Resize (INT64 newsize);
00302 virtual INT64 v_Seek (INT64 offset, SEEKFROM from);
00303 virtual INT64 v_Tell () const;
00304 virtual ERRVALUE v_Write (const void* buffer, INT32 numbytes);
00305 };
00306
00307
00308
00309
00310
00311
00316 int MpClose (
00317 MPORT *port
00318 );
00319
00323 int MpComHasDataAvail (
00324 MPORT *port
00325 );
00326
00328 void MpComSetQueueSize (
00329 int InputSize,
00330 int OutputSize
00331 );
00332
00340 int MpFlush (
00341 MPORT *port
00342 );
00343
00345 int MpGetLastError (
00346 MPORT *port
00347 );
00348
00355 MPORTTYPE * MpGetPortTypeByName (
00356 const char *name
00357 );
00358
00364 MPORTTYPE * MpGetPortTypeByNumber (
00365 int num
00366 );
00367
00371 int MpInit (void);
00372
00376 int MpIsFile (
00377 const char *type,
00378 const char *name
00379 );
00380
00384 int MpIsFileUC (
00385 const char *type,
00386 const MIUNICODE *name
00387 );
00388
00392 int MpLastStatus (
00393 MPORT *port
00394 );
00395
00402 DEPRECATED_MSG("There's a version that takes MISTRING for the name now") MPORT * MpOpen (
00403 const char *name,
00404 const MPORTTYPE *type,
00405 const char *parms = 0,
00406 UINT32 mode = 0
00407 );
00408
00415 MPORT * MpOpen (
00416 const MISTRING& name,
00417 const MPORTTYPE *type,
00418 const char *parms = 0,
00419 UINT32 mode = 0
00420 );
00421
00434 int MpRead (
00435 MPORT *port,
00436 void *buf,
00437 int maxlen,
00438 char *term = 0
00439 );
00440
00441
00442 #ifndef GENERATING_DOXYGEN_OUTPUT
00443 int MpScan (
00444 MPORTTYPE *porttype
00445 );
00446 #endif
00447
00448
00463 int MpSetParms (
00464 MPORT *port,
00465 const char *parms
00466 );
00467
00484 int MpStatus (
00485 MPORT *port,
00486 char **status
00487 );
00488
00514 int MpWrite (
00515 MPORT *port,
00516 const void *buf,
00517 int len
00518 );
00519
00522 int MpWriteExt (
00523 MPORT *port,
00524 const void *buffer,
00525 int len,
00526 UINT32 flags = 0
00527 );
00528
00537 int MxpWrite (
00538 MPORT *port,
00539 const void *buf,
00540 int numbytes,
00541 void *status,
00542 int line
00543 );
00544
00545 #ifndef PORTS_C
00546 extern MPORTTYPE *MpPortTypeList[];
00547 #endif
00548
00550 int MxPortGetSettings (
00551 Widget pwidget,
00552 MPORTTYPE *porttype,
00553 char *portoptions
00554 );
00555
00556
00557 #endif