Android Question Weird Astream crash issue

techknight

Well-Known Member
Licensed User
Longtime User
I have a weird issue that I am having a difficult time narrowing down. It doesnt do this all the time, only once in awhile. Otherwise it works fine.

Occasionally, my bluetooth adapter will sometimes repeat back to the droid device of what I sent out if the BT connection drops or caches the sent data. Why I dunno, but it does.

When this happens, it causes a crash of this:

B4X:
Sub AStream_NewData (Buffer() As Byte) 'Serial Receive interrupt routine
If RxEnabled = False Then
    Return
End If
RxPacket = RxPacket & BytesToString(Buffer, 0, Buffer.Length, "UTF8")
'Since we arnt using Prefix mode, The entire packet may not have arrived when this event is triggered.
'Since we are doing length and checksummed packets, We test for a valid packet and length before releasing the packet.
If Len(RxPacket) > 4 Then
    PacketLength = Len(RxPacket) / 2    'Length of packet

    '***************************************************************
    > TestLength = HexString(Mid(RxPacket, 3, 2)) 'Send Length byte  <error location
   '**************************************************************


    TestLength = TestLength + 4        'Include header byte, Length byte, checksum byte, and character return (AVR Print) as part of the length. Ensure full data packet recpetion.
    If TestLength = PacketLength Then
        RxHandler
        RxPacket = ""
    End If
End If
'if the start of the packet doesnt have the correct header, just throw it away until we do.
If Left(RxPacket, 1) <> "1" Then
    RxPacket = ""
End If
Return
End Sub

That is were debug hangs up at.

Here is what I have during the crash: ( i have to type manually, IDE doenst give me an option to copy out of these boxes which sucks)
under local variables, I have:

Buffer [0=33, 1=3, 2=1, 3=-1, 4=7, 5=-37, 6=0, 7=0
LastException: java.lang.NumberFormatException: Invalid double: "�"

Gives me some funny diamond character on the exception, Well, if you look at buffer, its actually "21 03 01 FF 07 DB" in HEX which is the previous command I had sent during a last session. It got bounced back at me by the BT adapter, or some type of caching.

Every time it does, it craps out the app with the above exception.

any ideas?
 

Attachments

  • crash.jpg
    crash.jpg
    455.5 KB · Views: 196

KitCarlson

Active Member
Licensed User
Longtime User
Here is an idea, but it involves hardware not software. An intermittent short of rx, to tx can cause the undesired loop back.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Erel: I did use rapid debugger the first time around, but it gave me alot less information on the crash than the old legacy debugging. But I dont think I am running V3.5 yet, just V3

Kit: Its not hardware related, I checked that long ago. There is no intermittent short that could occur, strictly by design. it doesnt cross anywhere, and it isnt muxed. it goes straight from the BT dongle into a MAX232 and directly into the MCU.
 
Upvote 0

KitCarlson

Active Member
Licensed User
Longtime User
I find monitoring rx, tx with a logic analyzer in development, gives insite not possible with just software and debugger.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I have to get it to crash again, but ill find out.

Edit: The Return response from my board via bluetooth, in my case its 04.

The full packet is:
12040181810017

the breakdown of my packet structure is as follows:
12 is the slave address
04 is the length
01818100 is response specific data.
17 is the LRC

Master commands (commands sent to the board) begin with 21 instead of 12. packet structure is the same. Problem is never sending to the device, it tends to crash on the slave returns.

the crash is random, and few and far between. I havent gotten a log on a crash just yet.
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I wrote the routine using strings as it was easier for me to "see" and work with, but maybe not the most elegant solution. As the old saying goes, everyone does things a different way. Ill take your idea into consideration, as i think it would work better.

I use strings becuase I have big IF/Select case statements that check the packets for what they are.

Edit: BTW, How would I put the Astream bytes into a list.addall? I still dont understand the "new" style basic as much as I do the old VB6 stuff.
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Ok. Pardon my asking, but isnt that the same thing as just throwing the buffer into an Array variable?
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Ok, well that makes sense, so basically if the buffer isnt all there, the next time the event is raised, it just appends at the bottom of the list behind the data that is already there from the first time, correct? Is there any subscript/indexing issues if I test for a full packet, and it all isnt there or missing, is there? or is there a way to test a length of a list.

Also, how do I convert the list back into a HexString that way I dont have to go back and modify all my conditional command handler routines and statements.
 
Last edited:
Upvote 0
Top