|
@@ -31,7 +31,7 @@
|
31
|
31
|
#include <netinet/in.h>
|
32
|
32
|
#include <arpa/inet.h>
|
33
|
33
|
int sock = 0;
|
34
|
|
-const char* host = "127.0.0.1";
|
|
34
|
+string host = "127.0.0.1";
|
35
|
35
|
#define PORT 6699
|
36
|
36
|
#endif
|
37
|
37
|
|
|
@@ -96,7 +96,7 @@ int ComRobot::Open(string usart) {
|
96
|
96
|
serv_addr.sin_port = htons(PORT);
|
97
|
97
|
|
98
|
98
|
// Convert IPv4 and IPv6 addresses from text to binary form
|
99
|
|
- if (inet_pton(AF_INET, host, &serv_addr.sin_addr) <= 0) {
|
|
99
|
+ if (inet_pton(AF_INET, host.c_str(), &serv_addr.sin_addr) <= 0) {
|
100
|
100
|
printf("\nInvalid address/ Address not supported \n");
|
101
|
101
|
return -1;
|
102
|
102
|
}
|
|
@@ -127,6 +127,36 @@ int ComRobot::Open(string usart) {
|
127
|
127
|
#endif
|
128
|
128
|
}
|
129
|
129
|
|
|
130
|
+int ComRobot::Open(string shost, int nport) {
|
|
131
|
+#ifdef __SIMULATION__
|
|
132
|
+
|
|
133
|
+ struct sockaddr_in serv_addr;
|
|
134
|
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
|
135
|
+ printf("\n Socket creation error \n");
|
|
136
|
+ return -1;
|
|
137
|
+ }
|
|
138
|
+ struct timeval tv;
|
|
139
|
+ tv.tv_sec = 0;
|
|
140
|
+ tv.tv_usec = 200000;
|
|
141
|
+ setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char*) &tv, sizeof tv);
|
|
142
|
+
|
|
143
|
+ serv_addr.sin_family = AF_INET;
|
|
144
|
+ serv_addr.sin_port = htons(nport);
|
|
145
|
+
|
|
146
|
+ if (inet_pton(AF_INET, shost.c_str(), &serv_addr.sin_addr) <= 0) {
|
|
147
|
+ cout << "Invalid address/ Address not supported" << endl;
|
|
148
|
+ return -1;
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+ if (connect(sock, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
|
|
152
|
+ return -2;
|
|
153
|
+ }
|
|
154
|
+ return 1;
|
|
155
|
+#else
|
|
156
|
+ return -1
|
|
157
|
+#endif
|
|
158
|
+}
|
|
159
|
+
|
130
|
160
|
/**
|
131
|
161
|
* Close serial link
|
132
|
162
|
* @return Success if above 0, failure if below 0
|