Vala DataInputStream.read_int32 in accelerometer message

MicVM ssj2micvm at gmail.com
Sat Oct 10 22:08:56 CEST 2009


I am trying to build a vala library to access the accelerometers of the
freerunner. I am using vala just to give it a try but I am experiencing
strange problems and wanted to ask if some of you can give me some hints.
When i read from the input interface of an accelerometer i get the following
bytestream:

b 3 d1 4a 42 ea d 0 0 0 0 0 0 0 0 0
1b 3 d1 4a 79 f e 0 3 0 1 0 6c 0 0 0
1b 3 d1 4a d7 f e 0 3 0 2 0 26 4 0 0

that looks quite good to me. However, when I try to read the values in the
message as integers i have a problem when reding the "value" field, i.e. the
last 32 bit signed integer of the message. I get strange values around +300
instead of +1062 for the Z value as in the last line of the above example.
Also for X and Y the values are wrong. I read the stream with the following
code snippet in vala (using GIO libs):

var data_stream=new DataInputStream(file_stream);
data_stream.set_byte_order(DataStreamByteOrder.LITTLE_ENDIAN);

//Skip time field, 8 bytes
data_stream.skip(8,null);

//Read eventtype
eventtype=data_stream.read_uint16(null);
while(eventtype!=0)
{
	if((eventtype==3)||(eventtype==2))
	{
		code=data_stream.read_uint16(null);
		if(code==0)
		{
			x_value=data_stream.read_int32(null);
					
		}
		if(code==1)
		{
			y_value=data_stream.read_int32(null);
		}
		if(code==2)
		{	
			z_value=data_stream.read_int32(null);
		}
			
....

I think somewhere I am doing a major mistake because the decoding of the
int32 is a basic functionality that does not work in my case. The funny
thing is that decoding of uint16 is done correctly such that eventtype and
code are read correctly. Any help is appreciate :)
-- 
View this message in context: http://n2.nabble.com/Vala-DataInputStream-read-int32-in-accelerometer-message-tp3801000p3801000.html
Sent from the Openmoko Devel mailing list archive at Nabble.com.



More information about the devel mailing list