Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

ObdiiDataMesg. Problem with pid data

Rank

Total Posts: 6

Joined 2016-05-29

PM

Hi, I would like to ask for help on using the ObdiiDataMesg class.

I'm coding in Java and would like to enter into a fit file the ENGINE RPM data. I already have this data in a vector. To do this I've tried the following code.
ObdiiDataMesg OB = new ObdiiDataMesg(); 
//

//
 
Float singlefloatdata=(float) float_vector[ii];

 
int num = (Integer.parseInt("0C"16)); // This for PID code that is in Hex
 
OB.setPid((bytenum);
    
   
Byte to_row_data_byte =singlefloatdata.byteValue(); //probably error is here...?

  
OB.setRawData(0to_row_data_byte);

  
encode.write(OB); 



the solution above work perfectly for pid data that return only 1 byte, but the PID "ENGINE RPM" return 2 bytes. Is this the problem? How I can use this PID? for example, the above solution work perfectly with the PID "vehicle speed" that has "0D" as PID number, but return 1 byte...

I'm becoming crazy...

Thank again
Bye      
RankRankRank

Total Posts: 68

Joined 0

PM

The Raw Data should encode the raw data using the same endianness as the rest of the file. Assuming that the data is encoded in little endian format. The following code shows how to encode data that is larger than 1 byte in an ObdiiDataMesg:

ObdiiDataMesg ob = new ObdiiDataMesg(); 

Float singleFloatData = (float)float_vector[ii];

int num = (Integer.parseInt("0C"16)); // This for PID code that is in Hex
ob.setPid((bytenum);

short rowData singleFloatData.shortValue();
// Encode bytes in Little Endian format
ob.setRawData(0rowData);
ob.setRawData(1rowData >> 8);

encode.write(ob); 
     
Rank

Total Posts: 6

Joined 2016-05-29

PM

hi, thanks for reply. I tried and tried several times in different ways to do what you suggest and follow your indication but i haven't obtained anything.

following the code used after the suggestion. I converted the "Short" type data values to be included as byte. (the PID field for ENGINE RPM request byte type). Now I can see the data but the values readed in VIRB are wrong. it is as if it lose a few bytes ...
ObdiiDataMesg OB = new ObdiiDataMesg(); 
  
OB.setSystemTime(0, (longi);  // This line was omitted... but now i don't know what think...
     
OB.setSystemTime(1, (longi);

     
int num = (Integer.parseInt("0C"16)); // This for PID Field
     
OB.setPid((bytenum);
    
Short rowData doublevectordata.shortValue(); 
//FIRST TRIAL
    
ByteBuffer buffer ByteBuffer.allocate(1000); 
     
buffer.order(ByteOrder.LITTLE_ENDIAN);       
     
buffer.putShort(rowData);
     
OB.setRawData(0,buffer.get(8));
     
OB.setRawData(1,buffer.get(0));

// SECOND TRIAL
    
OB.setRawData(0,(byte)(rowData>>8));
     
OB.setRawData(1,(byte) (rowData.byteValue() & 0xff));

// THIRD TRIAL
   
OB.setRawData(0,(byte) (rowData.byteValue() & 0xFF));
   
OB.setRawData(1, (byte)(rowData>>8)); 


I do not understand how fir sdk 20.0 encode this kind of data...

Sorry, but I'm frustrated ...

Thanks again for your answer!

regards      
RankRankRank

Total Posts: 68

Joined 0

PM

Are you trying to insert data into a FIT file generated by VIRB or are you attempting to read data that is already encoded? The code above is correct if you are attempting to generate a new FIT file

It is possible that VIRB does not support the PID you are trying to use. I suggest you use the Garmin VIRB Forums for questions regarding interfacing with that product.
https://forums.garmin.com/forumdisplay.php?482-VIRB

Cheers