A
A
antonyter2012-11-19 22:05:46
Android
antonyter, 2012-11-19 22:05:46

Bluegiga + Galaxy Note 10.1 problem?

There is a third-party board with a Bluegiga chip on board. The tablet connects via Bluetooth to the board and from time to time sends requests to it, to which it receives responses (the volume is 2-3 messages (about 100 bytes) per second). Everything works stably until the board starts sending commands more often (10 times). In this case, the tablet at some point (1-2 minutes after the connection was established) freezes, and then generates an exception (and you can see a fragment of a message that has not reached). What could be the reason? On the Huawei Sonic phone, everything works without such glitches. If you connect the phone to the tablet and emulate the board on the phone, everything is fine too.
I give the function of reading from the socket:

public void run()
{
    final int BufferSize = 0x400;
    byte[] buffer = new byte[BufferSize];
    int bufferCursor = 0;
    int bufferRemainder = 0;
    final int MessageBufferSize = 0x400;
    byte[] message = new byte[MessageBufferSize];
    int cursor = 0;
    int bytes = 0;

    while(true)
    {
        try 
        {                
            if(bufferRemainder == 0)
            {
                bufferCursor = 0;
                bufferRemainder = BufferSize;
            }
                		
            bytes = mmInStream.read(buffer, bufferCursor, bufferRemainder);                			               	
            if(bytes >= 0)
            {     
                bufferCursor += bytes;
                bufferRemainder -= bytes;
                for(int i = bufferCursor - bytes; i < bufferCursor; ++i)
                {
                	message[cursor] = buffer[i];
                	//35 #
                	//36 $
                	//13 \r
                	//10 \n
                	if(cursor == 0)
                	{
                		if(buffer[i] == 35 || buffer[i] == 36)
                			cursor++;                  				
                	}                			
                	else if(buffer[i] == 13)
                	{
                		mHandler.obtainMessage(MESSAGE_READ, cursor, -1, message.clone()).sendToTarget();
                		cursor = 0;  
                	}
                	else if(buffer[i] != 10)
                		cursor++;     
                	if(cursor == BufferSize)
                		cursor = 0;
                }
            }
        } 
    catch(IOException readException)
    {
            if(cursor > 0)
            {
              message[0] = 111;
              mHandler.obtainMessage(MESSAGE_READ, cursor, -1, message.clone()).sendToTarget();
      		cursor = 0;
            }
            Log.e(TAG, "Failed to read from input stream: " + readException.getMessage());
            connectionLost();
            break;
    }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question