mirror of
https://github.com/yoboujon/dumber.git
synced 2025-06-08 22:00:49 +02:00
add carriage return for robot communication with the simulator
This commit is contained in:
parent
1c73c39715
commit
de1629c147
1 changed files with 4 additions and 2 deletions
|
@ -31,6 +31,7 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
int sock = 0;
|
int sock = 0;
|
||||||
|
const char* host = "127.0.0.1";
|
||||||
#define PORT 6699
|
#define PORT 6699
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -88,14 +89,14 @@ int ComRobot::Open(string usart) {
|
||||||
}
|
}
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 80000;
|
tv.tv_usec = 200000;
|
||||||
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char*) &tv, sizeof tv);
|
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char*) &tv, sizeof tv);
|
||||||
|
|
||||||
serv_addr.sin_family = AF_INET;
|
serv_addr.sin_family = AF_INET;
|
||||||
serv_addr.sin_port = htons(PORT);
|
serv_addr.sin_port = htons(PORT);
|
||||||
|
|
||||||
// Convert IPv4 and IPv6 addresses from text to binary form
|
// Convert IPv4 and IPv6 addresses from text to binary form
|
||||||
if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr) <= 0) {
|
if (inet_pton(AF_INET, host, &serv_addr.sin_addr) <= 0) {
|
||||||
printf("\nInvalid address/ Address not supported \n");
|
printf("\nInvalid address/ Address not supported \n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -156,6 +157,7 @@ Message *ComRobot::Write(Message* msg) {
|
||||||
|
|
||||||
s = MessageToString(msg);
|
s = MessageToString(msg);
|
||||||
#ifdef __SIMULATION__
|
#ifdef __SIMULATION__
|
||||||
|
s += "\r";
|
||||||
|
|
||||||
char buffer[1024] = {0};
|
char buffer[1024] = {0};
|
||||||
cout << "[" << __PRETTY_FUNCTION__ << "] Send command: " << s << endl << flush;
|
cout << "[" << __PRETTY_FUNCTION__ << "] Send command: " << s << endl << flush;
|
||||||
|
|
Loading…
Add table
Reference in a new issue