Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

GPS Java Problem

  • 22-03-2006 11:54am
    #1
    Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭


    hey i have posted in this problem before and i have meet another problem, basically i am trying to read in via bluetooth from a gps device but the data i am getting doesnt seem to be right.

    this is the output am getting from the code:
    avetanaBluetooth version 1.3.6
    2006-03-20 16:35:18.972 java[2591] *** _NSAutoreleaseNoPool(): Object 0x3195c0 of class NSCFString autoreleased with no pool in place - just leaking
    [52, 44, 87, 44, 48, 46, 48, 48, 44, 44, 50, 48, 48, 51, 48, 54, 44, 44, 42, 49, 50, 13, 10, 36, 71, 80, 86, 84, 71, 44, 44, 84, 44, 44, 77, 44, 44, 78, 44, 44, 75, 42, 52, 69, 13, 10, 36, 71, 80, 71, 71, 65, 44, 49, 54, 51, 53, 49, 50, 46, 53, 52, 51, 44, 53, 51, 50, 50, 46, 53, 48, 53, 50, 44, 78, 44, 48, 48, 54, 50, 50, 46, 57, 49, 48, 52, 44, 87, 44, 48, 44, 48, 48, 44, 53, 48, 46, 48, 44, 48, 46, 48, 44, 77, 44, 44, 44, 49, 46, 50, 44, 48, 48, 48, 48, 42, 48, 65, 13, 10, 36, 71, 80, 71, 83, 65, 44, 65, 44, 49, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 53, 48, 46, 48, 44, 53, 48, 46, 48, 44, 53, 48, 46, 48, 42, 48, 53, 13, 10, 36, 71, 80, 71, 83, 86, 44, 51, 44, 49, 44, 48, 57, 44, 49, 51, 44, 55, 53, 44, 49, 54, 56, 44, 50, 54, 44, 48, 52, 44, 54, 55, 44, 50, 54, 51, 44, 44, 50, 55, 44, 54, 51, 44, 49, 48, 55, 44, 44, 48, 56, 44, 53, 57, 44, 49, 51, 50, 44, 42, 55, 57, 13, 10, 36, 71, 80, 71, 83, 86, 44, 51, 44, 50, 44, 48, 57, 44, 50, 52, 44, 53, 51, 44, 49, 54, 51, 44, 44, 49, 48, 44, 51, 52, 44, 49, 50, 54, 44, 44, 48, 50, 44, 50, 57, 44, 50, 48, 49, 44, 44, 50, 48, 44, 50, 51, 44, 48, 57, 51, 44, 51, 57, 42, 55, 70, 13, 10, 36, 71, 80, 71, 83, 86, 44, 51, 44, 51, 44, 48, 57, 44, 50, 54, 44, 48, 54, 44, 50, 53, 50, 44, 42, 52, 55, 13, 10, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    .
    .
    .
    .
    
    Local name The Prince
    Local address 00-0d-93-11-a6-b2
    Device class 0
    Possibilities array 3F
    License-ID 2279
    

    when i should be getting output like this:
    $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
    

    which when i hooked up to a proper programme i got, anyone know why? i can post the code if it helps but here is where i read an convert the data:
    while(position<info.length){
    			try {
    				byte buffer[] = new byte[500];
    				InputStream is = connection.openInputStream();
    				// read data from the device
    				is.read(buffer);	
    				System.out.println(java.util.Arrays.toString(buffer));
    				info[position] = java.util.Arrays.toString(buffer);
    				position++;
    			} catch(IOException e) {
    				e.printStackTrace();
    				// conn=false;
    			}
    		}
    

    any help would be great guys thanks again!!


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Javadoc for java.util.Arrays.toString(byte[])
    Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(byte). Returns "null" if a is null.

    You're writing the object, not the string.

    Also, unless you have a specific reason to, creating a new stream in every loop iteration is a good way to kill the stack when you have a large amount of information coming in like this.


  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    so the inputstream should be created outside the while loop. so it all should look like this:
    
    byte buffer[] = new byte[500];
    InputStream is = connection.openInputStream();
    while(position<info.length){
    			try {
    				
    				// read data from the device
    				// write to new array
    			} catch(IOException e) {
    				e.printStackTrace();
    				// conn=false;
    			}
    		}
    

    also how do i write get the individual elements into their correct format? i kinda lost of the whole toString part...

    thanks


  • Registered Users, Registered Users 2 Posts: 919 ✭✭✭timeout


    output your buffer to see what is being captured. Use a for loop
    for(i =0; i<500;i++){
    System.out.print(buffer);
    }


  • Registered Users, Registered Users 2 Posts: 9,225 ✭✭✭Chardee MacDennis


    when i do that or even when i use String.valueOf(byte) i just get the same numbers, just without the brackets and commas..


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    ???

    There is no String.valueOf(byte b) in either 1.4 or 5.0...

    Have you really not tried String s = new String(buffer) to see what that produces?


  • Advertisement
Advertisement