diff --git a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate index b653b6168a..b310c1ec89 100644 Binary files a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate and b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/main.cpp b/main.cpp index acb6e3ea94..bafb5383c1 100644 --- a/main.cpp +++ b/main.cpp @@ -198,6 +198,9 @@ void Timer(int extra) glutTimerFunc(1000,Timer,0); gettimeofday(&timer_start, NULL); + + // Send a message to the spaceserver telling it we are ALIVE + notify_spaceserver(UDP_socket, location[0], location[1], location[2]); } void display_stats(void) @@ -301,11 +304,6 @@ void terminate () { exit(EXIT_SUCCESS); } -const float SCALE_SENSORS = 0.3f; -const float SCALE_X = 2.f; -const float SCALE_Y = 1.f; - - void reset_sensors() { // @@ -512,6 +510,7 @@ void display(void) glPopMatrix(); + // Render 2D overlay: I/O level bar graphs and text glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -649,7 +648,10 @@ void read_network() timeval check; gettimeofday(&check, NULL); ping_msecs = (float)diffclock(ping_start, check); - + } else if (incoming_packet[0] == 'S') { + // Message from Spaceserver + std::cout << "Spaceserver: "; + outstring(incoming_packet, bytes_recvd); } } } diff --git a/network.cpp b/network.cpp index 7ff2361714..def6845057 100644 --- a/network.cpp +++ b/network.cpp @@ -11,9 +11,13 @@ #include "network.h" -const int UDP_PORT = 30000; +const int UDP_PORT = 30001; const char DESTINATION_IP[] = "127.0.0.1"; +// Location of the spaceserver to talk to +const char SPACESERVER_IP[] = "127.0.0.1"; +const int SPACESERVER_PORT = 40000; + // Implementation of optional delay behavior using a ring buffer const int MAX_DELAY_PACKETS = 300; char delay_buffer[MAX_PACKET_SIZE*MAX_DELAY_PACKETS]; @@ -22,7 +26,7 @@ int delay_size_received[MAX_DELAY_PACKETS]; int next_to_receive = 0; int next_to_send = 0; -sockaddr_in address, dest_address, from; +sockaddr_in address, dest_address, spaceserver_address, from; socklen_t fromLength = sizeof( from ); int network_init() @@ -67,7 +71,11 @@ int network_init() dest_address.sin_family = AF_INET; dest_address.sin_addr.s_addr = inet_addr(DESTINATION_IP); dest_address.sin_port = htons( (unsigned short) UDP_PORT ); - + + spaceserver_address.sin_family = AF_INET; + spaceserver_address.sin_addr.s_addr = inet_addr(SPACESERVER_IP); + spaceserver_address.sin_port = htons( (unsigned short) SPACESERVER_PORT ); + from.sin_family = AF_INET; //from.sin_addr.s_addr = htonl(ip_address); from.sin_port = htons( (unsigned short) UDP_PORT ); @@ -86,6 +94,22 @@ timeval network_send_ping(int handle) { return check; } +int notify_spaceserver(int handle, float x, float y, float z) { + char data[100]; + sprintf(data, "%f,%f,%f", x, y, z); + std::cout << "sending: " << data << "\n"; + int packet_size = strlen(data); + int sent_bytes = sendto( handle, (const char*)data, packet_size, + 0, (sockaddr*)&spaceserver_address, sizeof(sockaddr_in) ); + + if ( sent_bytes != packet_size ) + { + printf( "failed to send to spaceserver: return value = %d\n", sent_bytes ); + return false; + } + return sent_bytes; +} + int network_send(int handle, char * packet_data, int packet_size) { int sent_bytes = sendto( handle, (const char*)packet_data, packet_size, diff --git a/network.h b/network.h index 8f636f3cfc..751b8f0f87 100644 --- a/network.h +++ b/network.h @@ -22,5 +22,6 @@ int network_init(); int network_send(int handle, char * packet_data, int packet_size); int network_receive(int handle, char * packet_data, int delay /*msecs*/); timeval network_send_ping(int handle); +int notify_spaceserver(int handle, float x, float y, float z); #endif diff --git a/util.cpp b/util.cpp index c136e20e8e..1e3c786bf9 100644 --- a/util.cpp +++ b/util.cpp @@ -39,6 +39,11 @@ void render_world_box() glEnd(); } +void outstring(char * string, int length) { + char out[length]; + memcpy(out, string, length); + std::cout << out << "\n"; +} double diffclock(timeval clock1,timeval clock2) { diff --git a/util.h b/util.h index 46e1447581..2eac21117b 100644 --- a/util.h +++ b/util.h @@ -10,6 +10,7 @@ #define interface_util_h #include "glm/glm.hpp" +void outstring(char * string, int length); float randFloat(); void render_world_box(); void drawtext(int x, int y, float scale, float rotate, float thick, int mono, char *string,