]> rtime.felk.cvut.cz Git - orte/eurobot.git/commitdiff
JORTE: fix endianness the proper way
authorMartin Vajnar <martin.vajnar@gmail.com>
Sun, 14 Jul 2013 12:57:21 +0000 (14:57 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Mon, 23 Sep 2013 09:06:25 +0000 (11:06 +0200)
Use the GNU C compiler macro __BYTE_ORDER__ to set data_endian on the C
side and ByteOrder.nativeOrder() function to set ByteBuffer's order
in the MessageData class on the Java side.

orte/java/src/org/ocera/orte/examples/hello/HelloMsg.java
orte/java/src/org/ocera/orte/types/MessageData.java
orte/libjorte/JORTEPublicationSend.c

index acaf8b2e03f5cbde7a946bbd21345fd39bd6ec7b..b87bf5d8066d91d6db906cb4537df776a1b00b8a 100644 (file)
@@ -8,8 +8,6 @@
 
 import org.ocera.orte.*;
 import org.ocera.orte.types.*;
-import java.nio.ByteOrder;
-
 
 public class HelloMsg extends org.ocera.orte.types.MessageData
 {
@@ -30,7 +28,6 @@ public class HelloMsg extends org.ocera.orte.types.MessageData
   public HelloMsg(DomainApp domainApp, String newTopic)
   {
     super();
-    buffer.order(ByteOrder.LITTLE_ENDIAN);
  
     // typeName registration
        if(counter == 0)
@@ -108,4 +105,4 @@ public class HelloMsg extends org.ocera.orte.types.MessageData
        return data;      
   }
   
-}  
\ No newline at end of file
+}  
index a45695a7f0af6421fc2c320748310a1ccc439578..2f1a92735f436f4ab2bb2a2749b4ba2f62404b14 100644 (file)
@@ -24,7 +24,7 @@
 
 package org.ocera.orte.types;
 import java.nio.ByteBuffer;
-
+import java.nio.ByteOrder;
 
 public class MessageData
 {
@@ -39,6 +39,7 @@ public class MessageData
    public MessageData() 
    {
      this.buffer = ByteBuffer.allocate(getMaxDataLength());
+     this.buffer.order(ByteOrder.nativeOrder());
      //System.out.println(":j: instance MessageData created..");       
    }           
 
index 3737f09c8426e0acdc977ba5e32a9478fb968858..22f47ad16824d1f3d494c277df6f35c39263b06c 100644 (file)
@@ -147,7 +147,15 @@ Java_org_ocera_orte_Publication_jORTEPublicationSend
     }
     /////////////////////////////////////////////////
     psp.instance = (void *) orte_instance;
-    psp.data_endian = 1; /* BIG -pak tahat z headeru !!*/
+    #ifdef __BYTE_ORDER__
+      #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+        psp.data_endian = BigEndian;
+      #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+        psp.data_endian = LittleEndian;
+      #else
+        #error "Unknown endianness"
+      #endif
+    #endif
     #ifdef TEST_STAGE
       printf(":c: endian? \n");
     #endif