~ubuntu-branches/ubuntu/trusty/argyll/trusty-proposed

« back to all changes in this revision

Viewing changes to spectro/icoms.h

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-02-12 00:35:39 UTC
  • mfrom: (13.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20140212003539-24tautzlitsiz61w
Tags: 1.5.1-5ubuntu1
* Merge from Debian unstable. (LP: #1275572) Remaining changes:
  - debian/control:
    + Build-depend on libtiff-dev rather than libtiff4-dev.
  - debian/control, debian/patches/06_fix_udev_rule.patch:
    + Fix udev rules to actually work; ENV{ACL_MANAGE} has
      stopped working ages ago, and with logind it's now the
      "uaccess" tag. Dropping also consolekit from Recommends.
  - debian/patches/drop-usb-db.patch:
    + Use hwdb builtin, instead of the obsolete usb-db
      in the udev rules.
* debian/patches/05_ftbfs-underlinkage.diff:
  - Dropped change, no needed anymore.
* Refresh the patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * Author: Graeme W. Gill
10
10
 * Date:   2006/4/20
11
11
 *
12
 
 * Copyright 1996 - 2007 Graeme W. Gill
 
12
 * Copyright 1996 - 2013 Graeme W. Gill
13
13
 * All rights reserved.
14
14
 *
15
15
 * This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
28
28
        not necessarily robust to interrupt or terminate after a give
29
29
        USB transaction. The handling of user commands and aborts
30
30
        is not consistent either, possibly leaving some instruments
31
 
        suseptable to body results due to an unrecognised aborted
 
31
        suseptable to bodgy results due to an unrecognised aborted
32
32
        command. Really, the instrument driver should deterimine
33
33
        at what points an operation can be aborted, and how to recover.
34
34
 
38
38
        
39
39
*/
40
40
 
41
 
#ifdef ENABLE_USB
42
 
# ifdef USE_LIBUSB1
43
 
#  include "libusb.h"
44
 
# else
45
 
#  include "usb.h"
 
41
/* Some MSWin specific stuff is in icoms, and used by usbio & hidio */
 
42
#if defined (NT)
 
43
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0501
 
44
# if defined(_WIN32_WINNT) 
 
45
#  undef _WIN32_WINNT
46
46
# endif
47
 
#endif /* ENABLE_USB */
 
47
# define _WIN32_WINNT 0x0501
 
48
#endif
 
49
#define WIN32_LEAN_AND_MEAN
 
50
#include <windows.h>
 
51
#endif
 
52
 
 
53
#if defined(__APPLE__)
 
54
#include <IOKit/usb/IOUSBLib.h>
 
55
#endif
48
56
 
49
57
#ifdef __cplusplus
50
58
        extern "C" {
52
60
 
53
61
#undef QUIET_MEMCHECKERS                /* #define to memset coms read buffers before reading */
54
62
 
55
 
/* Provide some backwards compatibility to libusb0 */
56
 
#ifdef USE_LIBUSB1
57
 
# define USB_ENDPOINT_IN        LIBUSB_ENDPOINT_IN
58
 
# define USB_ENDPOINT_OUT       LIBUSB_ENDPOINT_OUT
59
 
# define USB_RECIP_DEVICE       LIBUSB_RECIPIENT_DEVICE
60
 
# define USB_RECIP_INTERFACE    LIBUSB_RECIPIENT_INTERFACE
61
 
# define USB_RECIP_ENDPOINT     LIBUSB_RECIPIENT_ENDPOINT
62
 
# define USB_TYPE_STANDARD      LIBUSB_REQUEST_TYPE_STANDARD
63
 
# define USB_TYPE_CLASS         LIBUSB_REQUEST_TYPE_CLASS
64
 
# define USB_TYPE_VENDOR        LIBUSB_REQUEST_TYPE_VENDOR
65
 
# define USB_ENDPOINT_TYPE_MASK LIBUSB_TRANSFER_TYPE_MASK
66
 
 
67
 
#define usb_device              libusb_device
68
 
#define usb_device_descriptor   libusb_device_descriptor
69
 
#define usb_dev_handle          libusb_device_handle
70
 
#define usb_config_descriptor   libusb_config_descriptor
71
 
#define usb_strerror         libusb_strerror
 
63
typedef struct _icompath icompath;
 
64
typedef struct _icompaths icompaths;
 
65
typedef struct _icoms icoms;
 
66
 
 
67
#ifdef ENABLE_USB
 
68
 
 
69
struct usb_idevice;             /* Forward declarations */
 
70
struct hid_idevice;
 
71
 
 
72
/* Information about each end point */
 
73
typedef struct {
 
74
        int valid;                      /* Flag, nz if this endpoint is valid */
 
75
        int addr;                       /* Address of end point */
 
76
        int packetsize;         /* The max packet size */
 
77
        int type;                       /* 2 = bulk, 3 = interrupt */   
 
78
        int interface;          /* interface number */
 
79
        int pipe;                       /* pipe number (1..N, OS X only) */
 
80
} usb_ep;
 
81
 
 
82
#define ICOM_EP_TYPE_BULK 2
 
83
#define ICOM_EP_TYPE_INTERRUPT 3
 
84
 
 
85
#include "usbio.h"
 
86
#include "hidio.h"
 
87
 
 
88
#endif /* ENABLE_USB */
 
89
 
 
90
/* - - - - - - - - - - - - - - - - - - - -  */
 
91
 
 
92
/* Store information about a possible instrument communication path */
 
93
/* (Note a path doesn't have a reference to icompaths or its' log) */
 
94
struct _icompath{
 
95
        char *name;                                     /* instance description */
 
96
#ifdef ENABLE_SERIAL
 
97
        char *spath;                            /* Serial device path */
72
98
#endif
 
99
#ifdef ENABLE_USB
 
100
        int nep;                                        /* Number of end points */
 
101
        unsigned int vid, pid;          /* USB vendor and product id's */
 
102
        struct usb_idevice *usbd;       /* USB port, NULL if not USB */
 
103
        struct hid_idevice *hidd;       /* HID port, NULL if not HID */
 
104
#endif /* ENABLE_USB */
 
105
        instType itype;                         /* Type of instrument if known */
 
106
};
 
107
 
 
108
extern icompath icomFakeDevice; /* Declare fake device */
 
109
 
 
110
/* The available instrument communication paths */
 
111
struct _icompaths {
 
112
        int npaths;                                     /* Number of paths */
 
113
        icompath **paths;                       /* Paths if any */
 
114
        a1log *log;                                     /* Verbose, debuge & error logging */
 
115
 
 
116
        /* Re-populate the available instrument list */
 
117
        /* return icom error */
 
118
        int (*refresh)(struct _icompaths *p);
 
119
 
 
120
#ifdef ENABLE_SERIAL
 
121
        /* Add a serial path. path is copied. Return icom error */
 
122
        int (*add_serial)(struct _icompaths *p, char *name, char *spath);
 
123
#endif /* ENABLE_SERIAL */
 
124
 
 
125
#ifdef ENABLE_USB
 
126
        /* Add a usb path. usbd is taken, others are copied. Return icom error */
 
127
        int (*add_usb)(struct _icompaths *p, char *name, unsigned int vid, unsigned int pid,
 
128
                        int nep, struct usb_idevice *usbd, instType itype);
 
129
 
 
130
        /* Add an hid path. hidd is taken, others are copied. Return icom error */
 
131
        int (*add_hid)(struct _icompaths *p, char *name, unsigned int vid, unsigned int pid,
 
132
                        int nep, struct hid_idevice *hidd, instType itype);
 
133
#endif /* ENABLE_USB */
 
134
 
 
135
        /* Return the path corresponding to the port number, or NULL if out of range */
 
136
        icompath *(*get_path)(
 
137
                struct _icompaths *p, 
 
138
                int            port);           /* Enumerated port number, 1..n */
 
139
 
 
140
        /* Clear all the paths */
 
141
        void (*clear)(struct _icompaths *p);
 
142
 
 
143
        /* We're done */
 
144
        void (*del)(struct _icompaths *p);
 
145
 
 
146
};
 
147
 
 
148
/* Allocate an icom paths and set it to the list of available devices */
 
149
/* Return NULL on error */
 
150
icompaths *new_icompaths(a1log *log);
 
151
 
73
152
 
74
153
/* - - - - - - - - - - - */
75
154
/* Serial related stuff */
140
219
} icom_type;
141
220
 
142
221
/* Status bits/return values */
143
 
#define ICOM_OK     0x00000             /* No error */
144
 
 
145
 
#define ICOM_USER       0x10000         /* User abort operation */
146
 
#define ICOM_TERM       0x20000         /* User terminated operation */
147
 
#define ICOM_TRIG       0x30000         /* User trigger */
148
 
#define ICOM_CMND       0x40000         /* User command */
149
 
#define ICOM_USERM      0xF0000         /* Mask of user interrupts */
150
 
 
151
 
#define ICOM_NOTS       0x01000         /* Not supported */
152
 
#define ICOM_TO         0x02000         /* Timed out */
153
 
#define ICOM_SHORT      0x04000         /* Number of bytes wasn't read/written */
154
 
 
155
 
#define ICOM_USBR       0x00100         /* Unspecified USB read error */
156
 
#define ICOM_USBW       0x00200         /* Unspecified USB write error */
157
 
#define ICOM_SERR       0x00400         /* Unspecified Serial read error */
158
 
#define ICOM_SERW       0x00800         /* Unspecified Serial write error */
159
 
 
160
 
#define ICOM_XRE        0x00040         /* Xmit shift reg empty */
161
 
#define ICOM_XHE        0x00020         /* Xmit hold reg empty */
162
 
#define ICOM_BRK        0x00010         /* Break detected */
163
 
#define ICOM_FER        0x00008         /* Framing error */
164
 
#define ICOM_PER        0x00004         /* Parity error */
165
 
#define ICOM_OER        0x00002         /* Overun error */
166
 
#define ICOM_DRY        0x00001         /* Recv data ready */
167
 
 
168
 
/* Store information about a possible instrument communication path */
169
 
typedef struct {
170
 
        char *path;                                     /* Serial port path, or USB/HID device description */
171
 
#ifdef ENABLE_USB
172
 
        unsigned int vid, pid;          /* USB vendor and product id's */
173
 
        struct usb_device *dev;         /* USB port, NULL if not USB */
174
 
        struct _hid_device *hev;        /* HID port, NULL if not HID */
175
 
        instType itype;                         /* Type of instrument on the USB or HID port */
176
 
#endif /* ENABLE_USB */
177
 
} icompath;
178
 
 
179
 
#ifdef ENABLE_USB
180
 
 
181
 
/* Information about each end point */
182
 
typedef struct {
183
 
        int valid;                      /* Flag, nz if this endpoint is valid */
184
 
        int addr;                       /* Address of end point */
185
 
        int packetsize;         /* The max packet size */
186
 
        int type;                       /* 2 = bulk, 3 = interrupt */   
187
 
} usb_ep;
188
 
 
189
 
#define ICOM_EP_TYPE_BULK 2
190
 
#define ICOM_EP_TYPE_INTERRUPT 3
191
 
 
192
 
#endif
193
 
 
194
 
#ifdef __cplusplus
195
 
        }
196
 
#endif
197
 
 
198
 
#if defined (NT)
199
 
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0501
200
 
# if defined(_WIN32_WINNT) 
201
 
#  undef _WIN32_WINNT
202
 
# endif
203
 
# define _WIN32_WINNT 0x0501
204
 
#endif
205
 
#define WIN32_LEAN_AND_MEAN
206
 
#include <windows.h>
207
 
#endif
208
 
 
209
 
#ifdef __cplusplus
210
 
        extern "C" {
 
222
#define ICOM_OK     0x000000            /* No error */
 
223
 
 
224
#define ICOM_NOTS       0x001000                /* Not supported */
 
225
#define ICOM_SIZE       0x002000                /* Request/response size exceeded limits */
 
226
#define ICOM_TO         0x004000                /* Timed out */
 
227
#define ICOM_SHORT      0x008000                /* Number of bytes wasn't read/written */
 
228
#define ICOM_CANC       0x010000                /* Was cancelled */
 
229
#define ICOM_SYS        0x020000                /* System error (ie. malloc, system call fail) */
 
230
#define ICOM_VER        0x040000                /* Version error - need up to date kernel driver */
 
231
 
 
232
#define ICOM_USBR       0x000100                /* Unspecified USB read error */
 
233
#define ICOM_USBW       0x000200                /* Unspecified USB write error */
 
234
#define ICOM_SERR       0x000400                /* Unspecified Serial read error */
 
235
#define ICOM_SERW       0x000800                /* Unspecified Serial write error */
 
236
 
 
237
#define ICOM_XRE        0x000040                /* Xmit shift reg empty */
 
238
#define ICOM_XHE        0x000020                /* Xmit hold reg empty */
 
239
#define ICOM_BRK        0x000010                /* Break detected */
 
240
#define ICOM_FER        0x000008                /* Framing error */
 
241
#define ICOM_PER        0x000004                /* Parity error */
 
242
#define ICOM_OER        0x000002                /* Overun error */
 
243
#define ICOM_DRY        0x000001                /* Recv data ready */
 
244
 
 
245
 
 
246
 
 
247
/* Cancelation token. */
 
248
typedef struct _usb_cancelt usb_cancelt;
 
249
 
 
250
#ifdef ENABLE_USB
 
251
void usb_init_cancel(usb_cancelt *p);
 
252
void usb_uninit_cancel(usb_cancelt *p);
 
253
 
211
254
#endif
212
255
 
213
256
struct _icoms {
214
257
  /* Private: */
215
 
        icompath *ppath;                        /* path to selected port */
 
258
 
 
259
        /* Copy of some of icompath contents: */
 
260
        char *name;                                     /* Device description */
 
261
        instType itype;                         /* Type of instrument if known */
216
262
        
217
 
        int port;                                       /* io port number: 1, 2, 3, 4 .. n */
218
263
        int is_open;                            /* Flag, NZ if this port is open */
219
 
        int is_usb;                                     /* Flag, NZ if this is a USB port */
220
 
        int is_hid;                                     /* Flag, NZ if this is an HID port */
 
264
 
 
265
#ifdef ENABLE_SERIAL
221
266
 
222
267
        /* Serial port parameters */
 
268
        char *spath;                            /* Serial port path */
223
269
#if defined (MSDOS)
224
270
        unsigned short porta;           /* Hardware port address */
225
271
#endif
235
281
        stop_bits       sb;
236
282
        word_length     wl;
237
283
 
 
284
#endif  /* ENABLE_SERIAL */
 
285
 
238
286
#ifdef ENABLE_USB
 
287
 
239
288
        /* USB port parameters */
240
 
#ifdef USE_LIBUSB1
241
 
        libusb_context *ctx; 
242
 
#endif
243
 
        unsigned int vid, pid;          /* USB vendor and product id's */
244
 
        struct usb_device *usbd;
 
289
        struct usb_idevice *usbd;       /* USB port - copy of ppath->usbd */
 
290
#ifndef NATIVE_USB                              /* Hmm. could put all this within usb_idevice if not #defined ? */
 
291
# ifdef USE_LIBUSB1
 
292
        libusb_device_handle *usbh;
 
293
# else
245
294
        struct usb_dev_handle *usbh;
246
 
        int cnfg;                               /* Configuration */
 
295
# endif
 
296
#endif
 
297
        icomuflags uflags;              /* Bug workaround flags */
 
298
 
 
299
        unsigned int vid, pid;  /* USB vendor and product id's, used to distiguish instruments */
 
300
        int nconfig;                    /* Number of configurations */
 
301
        int config;                             /* Config this info applies to (always 1 ?) */
 
302
        int cconfig;                    /* Current configuration (0 or 1 ?) */
247
303
        int nifce;                              /* Number of interfaces */
 
304
        int nep;                                /* Number of end points */
248
305
        int wr_ep, rd_ep;               /* Default end points to use for "serial" read/write */
249
306
        int rd_qa;                              /* Read quanta size */
250
307
 
251
308
        usb_ep ep[32];                  /* Information about each end point for general usb i/o */
252
 
        icomuflags uflags;              /* Bug workaround flags */
253
309
 
254
310
/* Macro to access end point information */
255
311
#define EPINFO(addr) ep[((addr >> 3) & 0x10) + (addr & 0x0f)]
256
312
 
257
313
        /* HID port parameters */
258
 
        struct _hid_device *hidd;       /* HID port, NULL if not HID */
 
314
        struct hid_idevice *hidd;       /* HID port - copy of ppath->hidd */
259
315
 
260
316
#endif /* ENABLE_USB */
261
317
 
262
318
        /* General parameters */
263
 
        int lerr;                                       /* Last error code */
 
319
        int lserr;                                      /* Last serial communication error code */
264
320
        int tc;                                         /* Current serial parser termination character (-1 if not set) */
265
 
        int npaths;                                     /* Number of paths */
266
 
        icompath **paths;                       /* Paths if any */
267
 
        int debug;                                      /* Flag, nz to print instrument io info to stderr */
268
 
 
269
 
        int uih[256];                           /* User interrupt handling key table. Value can be: */
270
 
                                                                /* ICOM_OK, ICOM_USER, ICOM_TERM, ICOM_TRIG, ICOM_CMND */
271
 
        int cut;                                        /* The character that caused the termination */
 
321
        a1log *log;                                     /* Debug & Error log */
 
322
        int debug;                                      /* legacy - Flag, nz to print instrument io info to stderr */
272
323
 
273
324
        /* Linked list to automate SIGKILL cleanup */
274
325
        struct _icoms *next;
275
326
        
276
327
  /* Public: */
277
328
 
278
 
        /* Return a list of instrument io communication paths */
279
 
        /* Return NULL on failure. */
280
 
        icompath ** (*get_paths)(               /* Return pointer to list of icompath */
281
 
                struct _icoms *p                        /* End is marked with NULL pointer, */
282
 
        );                                                              /* Storage will be freed with icoms object */
283
 
 
284
329
        /* Return the port type */
285
330
        icom_type (*port_type)(struct _icoms *p);
286
331
 
287
 
        /* Return the instrument type if the port number is USB, instUnknown if not */
288
 
        instType (*is_usb_portno)(
289
 
                struct _icoms *p, 
290
 
                int              port);         /* Enumerated port number, 1..n */
291
 
 
292
 
        /* Return the instrument type if the port number is HID, */
293
 
        /* and instUnknown if it is not. */
294
 
        instType (*is_hid_portno)(
295
 
                struct _icoms *p, 
296
 
                int port);              /* Enumerated port number, 1..n */
297
 
 
 
332
#ifdef ENABLE_SERIAL
298
333
        /* Select the serial communications port and characteristics */
299
 
        void (*set_ser_port)(
 
334
        /* return icom error */
 
335
        int (*set_ser_port)(
300
336
                struct _icoms *p, 
301
 
                int              port,          /* Enumerated port number, 1..n */
302
337
                flow_control fc,                /* Flow control */
303
338
                baud_rate        baud,
304
339
                parity           parity,
305
340
                stop_bits        stop_bits,
306
341
                word_length      word_length);
 
342
#endif  /* ENABLE_SERIAL */
307
343
 
 
344
#ifdef ENABLE_USB
308
345
        /* Select the USB communications port and characteristics */
309
 
        void (*set_usb_port)(
 
346
        /* return icom error */
 
347
        int (*set_usb_port)(
310
348
                struct _icoms *p, 
311
 
                int            port,            /* Enumerated port number, 1..n */
312
349
            int            config,              /* Configuration */
313
350
            int            wr_ep,               /* "serial" write end point */
314
351
            int            rd_ep,               /* "serial" read end point */
318
355
        );
319
356
 
320
357
        /* Select the HID communications port and characteristics */
321
 
        void (*set_hid_port)(
 
358
        /* return icom error */
 
359
        int (*set_hid_port)(
322
360
                struct _icoms *p, 
323
 
                int            port,            /* Enumerated port number, 1..n */
324
361
                icomuflags usbflags,            /* Any special handling flags */
325
362
                int retries,                            /* > 0 if we should retry set_configuration (100msec) */
326
363
                char **pnames                           /* List of process names to try and kill before opening */
327
364
        );
 
365
#endif /* ENABLE_USB */
328
366
 
329
367
        /* Close the port */
330
368
        void (*close_port)(struct _icoms *p);
331
369
 
332
 
        /* Reset user interrupt handling to default (Esc, ^C, q or 'Q' = Abort) */
333
 
        void (*reset_uih)(struct _icoms *p);
334
 
 
335
 
        /* Set a key range to the given handling type */
336
 
        /* min & max are between 0 and 255, status is one of */
337
 
        /* ICOM_OK, ICOM_USER, ICOM_TERM, ICOM_TRIG, ICOM_CMND */
338
 
        void (*set_uih)(struct _icoms *p, int min, int max, int status);
339
 
 
340
 
        /* Get the character that caused the user interrupt */
341
 
        /* Clear it to 0x00 after reading it. */
342
 
        int (*get_uih_char)(struct _icoms *p);
343
 
 
344
370
        /* "Serial" write the characters in the buffer out */
345
371
        /* Data will be written up to the terminating nul. */
346
 
        /* Return error code & set error state. */
 
372
        /* return icom error */
347
373
        int (*write)(
348
374
                struct _icoms *p,
349
375
                char *buf,
350
376
                double tout);           /* Timeout in seconds */
351
377
 
352
378
        /* "Serial" read characters into the buffer */
353
 
        /* Return error code & set error state. */
354
379
        /* The returned data will be terminated by a nul. */
 
380
        /* return icom error */
355
381
        int (*read)(
356
382
                struct _icoms *p,
357
383
                char *buf,                      /* Buffer to store characters read */
361
387
                double tout);           /* Timeout in seconds */
362
388
 
363
389
        /* "Serial" write and read */
364
 
        /* Return error code & set error state. */
 
390
        /* return icom error */
365
391
        int (*write_read)(
366
392
                struct _icoms *p,
367
393
                char *wbuf,                     /* Write puffer */
372
398
                double tout);           /* Timeout in seconds */
373
399
 
374
400
        /* For a USB device, do a control message */
375
 
        /* Return error code (don't set error state). */
376
 
        int (*usb_control_th)(struct _icoms *p,
377
 
                int requesttype,                /* 8 bit request type (USB bmRequestType) */
378
 
                int request,                    /* 8 bit request code (USB bRequest) */
379
 
                int value,                              /* 16 bit value (USB wValue, sent little endian) */
380
 
                int index,                              /* 16 bit index (USB wIndex, sent little endian) */
381
 
                unsigned char *rwbuf,   /* Read or write buffer */
382
 
                int rwsize,                             /* Bytes to read or write */
383
 
                double tout,                    /* Timeout in seconds */
384
 
                int debug,                              /* debug flag value */
385
 
                int *cut,                               /* Character that caused termination */
386
 
                int checkabort);                /* check for user abort */
387
 
 
388
 
        /* Same as above, but set error state */
 
401
        /* return icom error */
389
402
        int (*usb_control)(struct _icoms *p,
390
403
                int requesttype,                /* 8 bit request type (USB bmRequestType) */
391
404
                int request,                    /* 8 bit request code (USB bRequest) */
396
409
                double tout);                   /* Timeout in seconds */
397
410
 
398
411
        /* For a USB device, do a bulk or interrupt read from an end point */
399
 
        /* Return error code (don't set error state). */
400
 
        int (*usb_read_th)(struct _icoms *p,
401
 
                void **hcancel,                 /* Optionaly return handle to allow cancel */
402
 
                int ep,                                 /* End point address */
403
 
                unsigned char *buf,             /* Read buffer */
404
 
                int bsize,                              /* Bytes to read or write */
405
 
                int *bread,                             /* Bytes read */
406
 
                double tout,                    /* Timeout in seconds */
407
 
                int debug,                              /* debug flag value */
408
 
                int *cut,                               /* Character that caused termination */
409
 
                int checkabort);                /* check for user abort */
410
 
 
411
 
        /* Same as above, but set error state */
 
412
        /* return icom error */
412
413
        int (*usb_read)(struct _icoms *p,
 
414
                usb_cancelt *cancelt,   /* Optionaly tokem that can be used to cancel */
413
415
                int ep,                                 /* End point address */
414
416
                unsigned char *buf,             /* Read buffer */
415
417
                int bsize,                              /* Bytes to read or write */
417
419
                double tout);                   /* Timeout in seconds */
418
420
 
419
421
        /* For a USB device, do a bulk or interrupt write to an end point */
420
 
        /* Return error code (don't set error state). */
421
 
        int (*usb_write_th)(struct _icoms *p,
422
 
                void **hcancel,                 /* Optionaly return handle to allow cancel */
423
 
                int ep,                                 /* End point address */
424
 
                unsigned char *wbuf,    /* Write buffer */
425
 
                int wsize,                              /* Bytes to or write */
426
 
                int *bwritten,                  /* Bytes written */
427
 
                double tout,                    /* Timeout in seconds */
428
 
                int debug,                              /* debug flag value */
429
 
                int *cut,                               /* Character that caused termination */
430
 
                int checkabort);                /* check for user abort */
431
 
 
432
 
        /* Same as above, but set error state */
 
422
        /* return icom error */
433
423
        int (*usb_write)(struct _icoms *p,
 
424
                usb_cancelt *cancelt,   /* Optionaly tokem that can be used to cancel */
434
425
                int ep,                                 /* End point address */
435
426
                unsigned char *wbuf,    /* Write buffer */
436
427
                int wsize,                              /* Bytes to or write */
438
429
                double tout);                   /* Timeout in seconds */
439
430
 
440
431
        /* Cancel a read/write in another thread */
 
432
        /* return icom error */
441
433
        int (*usb_cancel_io)(struct _icoms *p,
442
 
                void *hcancel);                 /* Cancel handle */
 
434
                usb_cancelt *cantelt);                  /* Cancel handle */
443
435
 
444
436
        /* Reset and end point toggle state to 0 */
 
437
        /* return icom error */
445
438
        int (*usb_resetep)(struct _icoms *p,
446
439
                int ep);                                /* End point address */
447
440
 
448
441
        /* Clear an end point halt */
 
442
        /* return icom error */
449
443
        int (*usb_clearhalt)(struct _icoms *p,
450
444
                int ep);                                /* End point address */
451
445
 
452
 
        /* For an HID device, read a message from the device - thread friendly. */
453
 
        /* Set error state on error */
454
 
        int (*hid_read_th)(struct _icoms *p,
455
 
                unsigned char *buf,             /* Read buffer */
456
 
                int bsize,                              /* Bytes to read or write */
457
 
                int *bread,                             /* Bytes read */
458
 
                double tout,                    /* Timeout in seconds */
459
 
                int debug,                              /* debug flag value */
460
 
                int *cut,                               /* Character that caused termination */
461
 
                int checkabort);                /* Check for abort from keyboard */
462
 
 
463
446
        /* For an HID device, read a message from the device. */
464
 
        /* Set error state on error */
 
447
        /* return icom error */
465
448
        int (*hid_read)(struct _icoms *p,
466
449
                unsigned char *buf,             /* Read buffer */
467
450
                int bsize,                              /* Bytes to read or write */
468
451
                int *bread,                             /* Bytes read */
469
452
                double tout);                   /* Timeout in seconds */
470
453
 
471
 
        /* For an HID device, write a message to the device - thread friendly. */
472
 
        /* Set error state on error */
473
 
        int (*hid_write_th)(struct _icoms *p,
474
 
                unsigned char *wbuf,    /* Write buffer */
475
 
                int wsize,                              /* Bytes to or write */
476
 
                int *bwritten,                  /* Bytes written */
477
 
                double tout,                    /* Timeout in seconds */
478
 
                int debug,                              /* debug flag value */
479
 
                int *cut,                               /* Character that caused termination */
480
 
                int checkabort);                /* Check for abort from keyboard */
481
 
 
482
454
        /* For an HID device, write a message to the device */
483
 
        /* Set error state on error */
 
455
        /* return icom error */
484
456
        int (*hid_write)(struct _icoms *p,
485
457
                unsigned char *wbuf,    /* Write buffer */
486
458
                int wsize,                              /* Bytes to or write */
490
462
        /* Destroy ourselves */
491
463
        void (*del)(struct _icoms *p);
492
464
 
493
 
}; typedef struct _icoms icoms;
 
465
};
494
466
 
495
467
/* Constructor */
496
 
extern icoms *new_icoms(void);
497
 
 
498
 
/* - - - - - - - - */
499
 
/* Other functions */
500
 
 
501
 
/* Poll for a user abort, terminate, trigger or command. */
502
 
/* Wait for a key rather than polling, if wait != 0 */
503
 
/* Return: */
504
 
/* ICOM_OK if no key has been hit, */
505
 
/* ICOM_USER if User abort has been hit, */
506
 
/* ICOM_TERM if User terminate has been hit. */
507
 
/* ICOM_TRIG if User trigger has been hit */
508
 
/* ICOM_CMND if User command has been hit */
509
 
int icoms_poll_user(icoms *p, int wait);
 
468
extern icoms *new_icoms(icompath *ipath, a1log *log);
510
469
 
511
470
/* - - - - - - - - - - - - - - - - - - -- */
512
471
/* Utilities */