Problem with 8 bit CheckSum

bitstra

Member
Licensed User
Longtime User
Hello,

I have a problem woth calculating the accurate oh an 8 bit CheckSum for an
A-GPS data fie by skytraq...

in Linux/posix the right checksum is calculated for the array of bytes like this:

//for bytearray ephdata[]

csum is the checksum over all bytes of file
csumb is the checksum over the first 10000 bytes of the file

// checksum
unsigned char csuma, csumb = 0;
for (i = 0; i < 0x10000; i++)
csumb += ephdata;
csuma = csumb;
for (; i < ephbytes; i++)
csuma += ephdata;

I've try'd to make that way in b4a - but with all variants I could not get the accurate checksum value.

Here is one of my b4a-examples:

Dim bc, bcB As Byte
Dim c, cB As Int
'c=0:cB=0
For i=0 To buffer.Length-1
'c=c+(Bit.ParseInt(buffer(i),16)+255)
bc=Bit.xor(bc,buffer(i)+255)
If i<=9999 Then bcB=Bit.Xor(bcB,buffer(i)+255)
'cB=cB+(Bit.ParseInt(buffer(i),16)+255)
Next

c=bc Mod 256
cB=bcB Mod 256

The hardware manufacturer of the device, for that I want to use the checksum says:

'The checksums are the 8-bit exclusive OR of the data, to be transmitted'...

Any Idea???


regards

bitstra
 

bitstra

Member
Licensed User
Longtime User
Hi Erel,

thank you for your reply. As you can see, the bit strange lines are remarked - not used... :)

The buffer type is byte() from a binary file read:

B4X:
Dim in As File
If File.Exists(File.DirRootExternal,"Eph.dat")=True Then 
    If File.size(File.DirRootExternal,"Eph.dat")>0 Then 
     Dim buffer(File.size(File.DirRootExternal,"Eph.dat")) As Byte
     in = File.OpenInput(File.DirRootExternal,"Eph.dat")
     count = in.ReadBytes(buffer, 0, buffer.length)
     byteCnt=count
     
     Dim bc, bcB As Byte
     Dim c, cB As Int
     'c=0:cB=0
     For i=0 To buffer.Length-1
       'c=c+(Bit.ParseInt(buffer(i),16)+255)
      bc=Bit.xor(bc,buffer(i)+255)
      If i<=9999 Then bcB=Bit.Xor(bcB,buffer(i)+255) 
      'cB=cB+(Bit.ParseInt(buffer(i),16)+255)
     Next
     
     c=bc Mod 256
     cB=bcB Mod 256
     'c=  c-(Round(c /256)*256)
     'cB= cB-(Round(cB/256)*256)
     
     
     
     'cB=cB Mod 256
     
     Log("csum: " & c & "/ csumB: " & cB)

          in.Close
         End If
End If

???

regards


bitstra
 
Last edited:
Upvote 0

Similar Threads

Top