2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 BCU1DriverLowLevelDriver::BCU1DriverLowLevelDriver (const char *dev
,
29 TRACEPRINTF (t
, 1, this, "Open");
30 fd
= open (dev
, O_RDWR
);
32 throw Exception (DEV_OPEN_FAIL
);
34 pth_sem_init (&in_signal
);
35 pth_sem_init (&out_signal
);
36 pth_sem_init (&send_empty
);
37 pth_sem_set_value (&send_empty
, 1);
38 getwait
= pth_event (PTH_EVENT_SEM
, &out_signal
);
40 pth_event_t timeout
= pth_event (PTH_EVENT_TIME
, pth_timeout (0, 1));
41 send_done
= pth_event (PTH_EVENT_FD
| PTH_UNTIL_FD_EXCEPTION
, fd
);
42 pth_event_concat (send_done
, timeout
, NULL
);
46 pth_event_isolate (send_done
);
47 pth_event_free (timeout
, PTH_FREE_THIS
);
49 if (pth_event_status (send_done
) != PTH_STATUS_OCCURRED
)
51 TRACEPRINTF (t
, 1, this, "Driver select extension missing");
52 pth_event_free (send_done
, PTH_FREE_THIS
);
57 TRACEPRINTF (t
, 1, this, "Opened");
60 BCU1DriverLowLevelDriver::~BCU1DriverLowLevelDriver ()
62 TRACEPRINTF (t
, 1, this, "Close");
65 pth_event_free (send_done
, PTH_FREE_THIS
);
67 pth_event_free (getwait
, PTH_FREE_THIS
);
73 bool BCU1DriverLowLevelDriver::Connection_Lost ()
79 BCU1DriverLowLevelDriver::Send_Packet (CArray l
)
82 t
->TracePacket (1, this, "Send", l
);
84 pth_sem_set_value (&send_empty
, 0);
85 pth_sem_inc (&in_signal
, TRUE
);
89 BCU1DriverLowLevelDriver::SendReset ()
93 bool BCU1DriverLowLevelDriver::Send_Queue_Empty ()
95 return inqueue
.isempty ();
99 BCU1DriverLowLevelDriver::Send_Queue_Empty_Cond ()
105 BCU1DriverLowLevelDriver::Get_Packet (pth_event_t stop
)
108 pth_event_concat (getwait
, stop
, NULL
);
113 pth_event_isolate (getwait
);
115 if (pth_event_status (getwait
) == PTH_STATUS_OCCURRED
)
117 pth_sem_dec (&out_signal
);
118 CArray
*c
= outqueue
.get ();
119 t
->TracePacket (1, this, "Recv", *c
);
127 BCU1DriverLowLevelDriver::Run (pth_sem_t
* stop1
)
131 pth_event_t stop
= pth_event (PTH_EVENT_SEM
, stop1
);
132 pth_event_t input
= pth_event (PTH_EVENT_SEM
, &in_signal
);
133 while (pth_event_status (stop
) != PTH_STATUS_OCCURRED
)
135 pth_event_concat (stop
, input
, NULL
);
136 i
= pth_read_ev (fd
, buf
, sizeof (buf
), stop
);
139 t
->TracePacket (0, this, "Recv", i
, buf
);
140 outqueue
.put (new CArray (buf
, i
));
141 pth_sem_inc (&out_signal
, 1);
143 pth_event_isolate (stop
);
144 if (!inqueue
.isempty ())
146 const CArray
& c
= inqueue
.top ();
147 t
->TracePacket (0, this, "Send", c
);
148 i
= pth_write_ev (fd
, c
.array (), c (), stop
);
152 pth_wait (send_done
);
154 pth_sem_dec (&in_signal
);
156 if (inqueue
.isempty ())
157 pth_sem_set_value (&send_empty
, 1);
161 pth_event_free (stop
, PTH_FREE_THIS
);
162 pth_event_free (input
, PTH_FREE_THIS
);
165 LowLevelDriverInterface::EMIVer
BCU1DriverLowLevelDriver::getEMIVer ()