Dependencies:   ros_lib_kinetic

Revision:
17:bbaf3e8440ad
Parent:
14:54c3759e76ed
Child:
19:e5acb2183d4e
--- a/HLComms.cpp	Tue Sep 11 10:10:26 2018 +0000
+++ b/HLComms.cpp	Thu Oct 04 15:27:15 2018 +0000
@@ -13,9 +13,9 @@
     int error_code;
     if(IS_PRINT_OUTPUT) printf("Starting TCP server...\n\r");
     if( !IS_DHCP ) {
-        const char* ip = "192.168.1.125"; //"10.101.81.135"; //"10.101.79.125"; // Get first 3 parts from "ifconfig" on PC
+        const char* ip = "192.168.1.5"; //"192.168.1.2"; //"10.101.81.135"; //"10.101.79.125"; // Get first 3 parts from "ifconfig" on PC
         const char* mask = "255.255.255.0"; // Get from "ifconfig" on PC
-        const char* gateway =  "10.101.81.1"; //"10.101.79.1"; // Get from "route -n" on PC
+        const char* gateway =  "192.168.1.1"; //"10.101.81.1"; //"10.101.79.1"; // Get from "route -n" on PC
         error_code = interfaces.eth.set_network(ip, mask, gateway); // Dont use DHCP
         if( error_code < 0 ) {
             if(IS_PRINT_OUTPUT) printf("Error %i. Could not network interface to use a static IP address. "
@@ -79,7 +79,7 @@
 
 int HLComms::receive_message(void) {
     memset(recv_buffer, 0, sizeof(recv_buffer));
-    int error_code = interfaces.clt_sock.recv(recv_buffer, 1024); // Blocks until data is received
+    int error_code = interfaces.clt_sock.recv(recv_buffer, sizeof(recv_buffer)-1); // Blocks until data is received
     if(IS_PRINT_OUTPUT) printf("Message received.\r\n");
     return error_code;
 }
@@ -127,9 +127,24 @@
     return input;
 } // End of consume_message()
 
-void HLComms::make_message(double *dblTime) {
+int HLComms::send_duration_message(double *dblTime) {
+    send_mutex.lock();
     memset(send_buffer, 0, sizeof(send_buffer));
-    _snprintf(send_buffer,64,"%f",*dblTime);
+    _snprintf(send_buffer,sizeof(send_buffer),"0,%f",*dblTime);
+    int error_code = send_message();
+    send_mutex.unlock();
+    return error_code;
+}
+
+int HLComms::send_sensor_message(double positions[], double pressures[]) {
+    send_mutex.lock();
+    memset(send_buffer, 0, sizeof(send_buffer));
+    _snprintf(send_buffer,sizeof(send_buffer),"1,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f,%0.5f",
+        positions[0],positions[1],positions[2],positions[3],positions[4],positions[5],positions[6],positions[7],
+        pressures[0],pressures[1],pressures[2],pressures[3],pressures[4],pressures[5],pressures[6],pressures[7]);
+    int error_code = send_message();
+    send_mutex.unlock();
+    return error_code;
 }
 
 int HLComms::send_message(void) {