chiark / gitweb /
path-setting
[trains.git] / hostside / hostside.c
1 /**/
2
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <errno.h>
6 #include <string.h>
7 #include <stdarg.h>
8
9 #include "../layout/dlist.h"
10 #include "hostside.h"
11
12 oop_source *events;
13 FILE *dump_stream= 0;
14
15 static void serial_error(OutBufferChain *ch, const char *e1, const char *e2) {
16   abort();
17 }
18
19 static OutBufferChain serial_ochain= { (char*)"serial", -1, serial_error };
20
21 static void *serial_exception(oop_source *evts, int fd,
22                               oop_event evt, void *cl_v) {
23   die("serial port - exception");
24 }
25
26 static void *serial_readable(oop_source *evts, int fd,
27                              oop_event evt, void *u0) {
28   events->cancel_fd(events, serial_fd, OOP_READ);
29   return OOP_CONTINUE;
30 }
31
32 const char *device;
33
34 int main(int argc, const char **argv) {
35   oop_source_sys *sys_events;
36   int r;
37
38   device= argv[1];
39   if (!device) device= "/dev/ttyS0";
40
41   sys_events= oop_sys_new();  if (!sys_events) diee("oop_sys_new");
42   events= oop_sys_source(sys_events);  assert(events);
43   
44   serial_open(device);
45   r= oop_fd_nonblock(serial_fd, 1);  if (r) diee("nonblock(serial_fd,1)");
46   serial_ochain.fd= serial_fd;
47
48   stdin_client();
49
50   events->on_fd(events, serial_fd, OOP_READ, serial_readable, 0);
51   events->on_fd(events, serial_fd, OOP_EXCEPTION, serial_exception, 0);
52   oop_sys_run(sys_events);
53   abort();
54 }