2 * Copyright (C) 2006 Paul Davis
3 * Copyright (C) 2007 Michael Taht
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #if HAVE_TRANZPORT_KERNEL_DRIVER
25 #include "tranzport_control_protocol.h"
27 // Something like open(/dev/surface/tranzport/event) for reading and raw for writing) would be better in the long run
28 // Also support for multiple tranzports needs to be figured out
29 // And bulk reads/writes in general
32 TranzportControlProtocol::probe ()
34 if((udev
= ::open(TRANZPORT_DEVICE
,O_RDWR
))> 0) {
38 error
<< _("Tranzport: Can't open device for Read/Write: ") << endmsg
;
43 TranzportControlProtocol::open ()
45 if((udev
=::open(TRANZPORT_DEVICE
,O_RDWR
))> 0) {
48 error
<< _("Tranzport: no device detected") << endmsg
;
53 TranzportControlProtocol::close ()
61 if ((ret
= ::close (udev
)) != 0) {
62 error
<< _("Tranzport: cannot close device") << endmsg
;
68 // someday do buffered reads, presently this does blocking reads, which is bad...
70 int TranzportControlProtocol::read(uint8_t *buf
, uint32_t timeout_override
)
72 last_read_error
= ::read (udev
, (char *) buf
, 8);
79 cerr
<< "Tranzport disconnected, errno: " << last_read_error
;
82 case -ETIMEDOUT
: // This is not normal, but lets see what happened
83 cerr
<< "Tranzport read timed out, errno: " << last_read_error
;
87 cerr
<< "Got an unknown error on read:" << last_read_error
"\n";
92 return last_read_error
;
97 TranzportControlProtocol::write_noretry (uint8_t* cmd
, uint32_t timeout_override
)
99 // inflight is now taken care of by the driver, but...
100 if(inflight
> MAX_TRANZPORT_INFLIGHT
) { return (-1); }
101 int val
= ::write (udev
, (char*) cmd
, 8);
103 if (val
< 0 && val
!=8) {
105 printf("write failed: %d\n", val
);
107 last_write_error
= errno
;
108 switch(last_write_error
) {
114 cerr
<< "Tranzport disconnected, errno: " << last_write_error
;
117 case -ETIMEDOUT
: // This is not normal but
118 cerr
<< "Tranzport disconnected, errno: " << last_write_error
;
122 cerr
<< "Got an unknown error on read:" << last_write_error
"\n";
126 return last_write_error
;
129 last_write_error
= 0;
137 TranzportControlProtocol::write (uint8_t* cmd
, uint32_t timeout_override
)
139 return (write_noretry(cmd
,timeout_override
));
142 // FIXME - install poll semantics
143 #endif /* HAVE_TRANZPORT_KERNEL_DRIVER */