I have a text string from a HEX file (Intel format) with the following content: "02000C00189545" (txt file).
These are information about HEX values: 0x02 0x00 0x0C 0x18 0x95 0x45 and these are data intended for operations in the AVR microcontroller.
I divided the text string by 2 characters: 02 00 0C 00 18 95 45
Then I convert each of these parts to a DEC value
and in the next step I send each DEC value separately via BLE.
I do it in the following loop
The above solution works 100% but is very slow: A 2KB HEX file is sent to the CPU for about 5 minutes
I am still learning but I am convinced that sending the whole record will be much faster, but I do not know how to do it.
Principal question:
how to build such an array of DEC values
02 00 0C 00 18 95 45 ----> 2 0 12 0 24 -107 69
string -----> DEC
so that it can be sent with the SendArray function via BLE (also for B4i) to the processor ?
Perhaps I'm taking the wrong approach from the beginning, but I have failed with ByteBuilder and ByteConverter to solve it. I do not understand enough about the operation of these libraries.
Does anybody have an idea?
thanks for reading
These are information about HEX values: 0x02 0x00 0x0C 0x18 0x95 0x45 and these are data intended for operations in the AVR microcontroller.
I divided the text string by 2 characters: 02 00 0C 00 18 95 45
Then I convert each of these parts to a DEC value
and in the next step I send each DEC value separately via BLE.
I do it in the following loop
B4X:
Dim record As String
Dim Len_record As Int
Public sf As StringFunctions
Dim b As Byte
Dim a As String
record = "02000C00189545"
Len_record = record.Length
For z = 1 To Len_record - 1 Step 2
a = sf.Mid(record, z, 2) 'separated to: 02 00 0C... in each step
b = ( Bit.ParseInt(a,16) ) 'converted to DEC value: 02-->2 00-->0 0C-->12... in each step
SendArray(b) 'each DEC value is sent separately 'send each DEC value
Next
Public Sub SendArray (msg As Byte)
manager.WriteData(ServiceId, WriteChar, Array As Byte(msg))
End Sub
The above solution works 100% but is very slow: A 2KB HEX file is sent to the CPU for about 5 minutes
I am still learning but I am convinced that sending the whole record will be much faster, but I do not know how to do it.
Principal question:
how to build such an array of DEC values
02 00 0C 00 18 95 45 ----> 2 0 12 0 24 -107 69
string -----> DEC
so that it can be sent with the SendArray function via BLE (also for B4i) to the processor ?
Perhaps I'm taking the wrong approach from the beginning, but I have failed with ByteBuilder and ByteConverter to solve it. I do not understand enough about the operation of these libraries.
Does anybody have an idea?
thanks for reading