-
Notifications
You must be signed in to change notification settings - Fork 0
/
dll-src.diff
166 lines (161 loc) · 3.99 KB
/
dll-src.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
--- util/dll-src/loader.c.orig 2004-11-18 05:28:19.000000000 +0100
+++ util/dll-src/loader.c 2005-02-01 20:05:58.909999406 +0100
@@ -211,7 +211,7 @@
FD_ZERO(&fds);
FD_SET(rcxFD(), &fds);
- tv.tv_sec = (total - elapsed) / 1000000;
+ tv.tv_sec = (total - elapsed) / 1000000 + 2;
tv.tv_usec = (total - elapsed) % 1000000;
select(rcxFD() + 1, &fds, NULL, NULL, &tv);
if (FD_ISSET(rcxFD(), &fds))
--- util/dll-src/rcxtty.c.orig 2004-11-18 05:28:19.000000000 +0100
+++ util/dll-src/rcxtty.c 2005-02-01 20:08:27.278469205 +0100
@@ -50,6 +50,11 @@
#include <errno.h>
#endif
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
#include "rcxtty.h"
extern int tty_usb;
@@ -106,6 +111,121 @@
#endif
}
+//! initialize RCX communications port of a NCD
+int ncdttyInit(const char *tty, int highspeed)
+{
+ FILEDESCR fd;
+ char *portStr;
+ int port = 87;
+ struct hostent *h;
+ struct sockaddr_in localAddr, ttyAddr;
+#ifdef NCD_SETUP_SUPPORT
+ char buffer[400];
+ int len;
+#endif
+
+ portStr = strchr(tty, ':');
+ if (portStr) {
+ *portStr = 0;
+ port = atoi(portStr+1);
+ }
+
+ h = gethostbyname(tty);
+
+ if (portStr)
+ *portStr = ':';
+
+ if (!h) {
+ fprintf(stderr, "Unknown host: %s\n", tty);
+ return -1;
+ }
+
+#ifdef NCD_SETUP_SUPPORT
+ /* create setup socket */
+
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if(fd<0) {
+ perror("cannot open socket ");
+ return -1;
+ }
+
+ /* bind any port number */
+ localAddr.sin_family = AF_INET;
+ localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ localAddr.sin_port = htons(0);
+
+ if (bind(fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0) {
+ perror("cannot bind");
+ return -1;
+ }
+
+ ttyAddr.sin_family = h->h_addrtype;
+ memcpy((char *) &ttyAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
+ ttyAddr.sin_port = htons(5979);
+
+ if (connect(fd, (struct sockaddr *) &ttyAddr, sizeof(ttyAddr)) < 0) {
+ perror("cannot connect to config");
+ return -1;
+ }
+
+ /* Read in password prompt */
+ read(fd, buffer, sizeof(buffer));
+ /* write password */
+ write (fd, "<insert password here>\n", 8);
+
+ /* Read in prompt */
+ read(fd, buffer, sizeof(buffer));
+
+ /* write commands */
+ len = sprintf(buffer,
+ "set serial-interfaces-table = { "
+ "{ 1 printer printer %d 8 1 %s none none } }\n"
+ "apply\n",
+ highspeed ? 4800 : 2400,
+ highspeed ? "none" : "odd");
+ write(fd, buffer, len);
+
+ /* Read in prompts */
+ read(fd, buffer, sizeof(buffer));
+
+ /* Quit */
+ write(fd, "quit\n", 5);
+ close(fd);
+#endif
+
+ /* create socket */
+
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if(fd<0) {
+ perror("cannot open socket ");
+ return -1;
+ }
+
+ /* bind any port number */
+ localAddr.sin_family = AF_INET;
+ localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ localAddr.sin_port = htons(0);
+
+ if (bind(fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0) {
+ perror("cannot bind");
+ return -1;
+ }
+
+ ttyAddr.sin_family = h->h_addrtype;
+ memcpy((char *) &ttyAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
+ ttyAddr.sin_port = htons(port);
+
+ if (connect(fd, (struct sockaddr *) &ttyAddr, sizeof(ttyAddr)) < 0) {
+ perror("cannot connect");
+ return -1;
+ }
+
+ rcxFd=fd;
+
+ return 0;
+}
+
+
//! initialize RCX communications port
int rcxInit(const char *tty, int highspeed)
{
@@ -141,13 +261,17 @@
0, NULL, OPEN_EXISTING,
0, NULL)) == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Error %lu: Opening %s\n", (unsigned long) GetLastError(), tty);
+ return -1;
+ }
#else
+ else if (memcmp(tty, "ncd:", 4) == 0 || memcmp(tty, "tcp:", 4) == 0)
+ return ncdttyInit(tty+4, highspeed);
else if ((fd = open(tty, O_RDWR | O_EXCL)) < 0) {
fprintf(stderr,"Error opening tty=%s, ",tty);
perror("open");
-#endif
return -1;
}
+#endif
#if !defined(_WIN32)
if (tty_usb == 0 && !isatty(fd)) {