0

From ESP32 I am sending the data with the length 330. The code is like this:

    #define HS   2
    #define SIZE_BUFFER  (162 - HS)
    #define BS  2
    .
    .
    .
    int16_t buffer[BS][SIZE_BUFFER + HS];
    .
    .
    .
   loop()
   {
    .
    .
    .

    if (send_data){
            SerialBT.write((const uint8_t *)&buffer[3][0], (SIZE_BUFFER + HS) * 2);}
   }

If I use simple python code I can access the data

import serial
import numpy as np
.
.
.
data_bytes = ser.read(2 * size) 
res = int.from_bytes(data_bytes, byteorder='big')                   
data = (np.frombuffer(data_bytes, dtype=np.int16).reshape(-1,3))   

However, In Java(Android), there is no unsigned integer so what should I do

int data_size = mmInStream.read();

Log.d( "InputStream_5 : ", String.valueOf( data_size ) );
int x = data_size * 2; ///Till here its correct 

byte[] data = new byte[x];
bytes = mmInStream.read(data);
BigInteger newval = new BigInteger( data );
Log.d("Result:", String.valueOf( newval ) );  // what to do next

For the same data points: The result of res in python is:

1395743366482994016120367906701959328940313811521429321623203791215015610896120698403587716303123323476514487386210980511113296227293133748755999126249884966963269554083576932854957319499606672206946690637945927429737437418817759780358808406310496664214087463862251283806109649081292309625966098717557115363596511131444117377905344115257389940198017213691126712969278725996734797426950556703681996156550815363994288346716397799810175186126280896211756990954743286361863235039180008658191372695345728621290483384582238798126321929838346586289088895329092498166002359304466940370854681389408787668885082376341168271280835229419151701368026081320655044598932795793727396724356973250102964972276610698312747041473933394052929893095330364048475720783524627650816885438165149238434155527

And the result of java is

-705289714887329283616576107063612632214263054901576259029263759518967598460041390561029945242183295775579640697037904787066482681001486751488385940789863338128750191767553198984721206295994363333290717786312778357170079637438313893150451154698217437458678283897130004422089378581306960630773955403036570373092928857369602300991212986683878288316600295769339022148648726271444364481378851723842834602853319044566264026554782791463665524973556423928094852533391430794360486340043116168365368023604851236124514136956655865175322222980687697927349757704794907680665662432488204761405978577334579832224424529438822375092545726559924235187398126194160241854225068616466240004911911587629309225761498289035507017382826438559470863091164263910371280855712903773197381841797043719567050183
techno
  • 101
  • 1
  • 1
  • 8
  • Signed or unsigned doesn't matter. You just need to [convert 2 bytes to a short, right?](https://stackoverflow.com/questions/736815/2-bytes-to-short-java) – Sweeper Nov 20 '20 at 04:55
  • @Sweeper I am aware of those methods but that is not working in my case. I have updated the result as well. – techno Nov 20 '20 at 05:37
  • I'm not sure the numbers you showed in the edit are `short`s... What are you trying to do anyway? – Sweeper Nov 20 '20 at 05:38
  • @Sweeper First I want to check why my result from python and java are not the same. both java [`bytes = mmInStream.read(data);`] and python[`data_bytes = ser.read(2 * size)` ] receive same data of byte array (162*2). – techno Nov 20 '20 at 05:55

0 Answers0