All you need to do is assemble and link a program with the Doors CS SDK, and see what the checksum is, then try to do the same with your program and see if the checksums match. Smile If not, you'll know that you're doing something wrong. If so, you'll know you have it right.
KermMartian wrote:
All you need to do is assemble and link a program with the Doors CS SDK, and see what the checksum is, then try to do the same with your program and see if the checksums match. Smile If not, you'll know that you're doing something wrong. If so, you'll know you have it right.


wooooops, I forgot to put that in the last post. It is not returning the correct checksum.
Oh, ok. Remember when I told you the exact byte offsets between which you need to checksum; did you check that those are the offsets you're using? If so, I'll look a bit more closely at the Python code you posted.
According to this the checksum is the sum of all the bytes in the data section. According to the same page, the data section is:

Data section - consists of a number of variable entries (described below).

So, it's the program code (2101002323EF0745EF7249...).

However, I was not sure if 'BB6D' was part of this, so I decided to try my getCheckSum( function with both. However, neither returned the correct checksum.


Code:
>>> getCheckSum("EF4045210500EF0745EF7249C9")
'5213'
>>> getCheckSum("BB6DEF4045210500EF0745EF7249C9")
'4816'


My function also doesn't work for all strings:


Code:
>>> getCheckSum("210100C9")

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    getCheckSum("210100C9")
  File "<pyshell#1>", line 8, in getCheckSum
    checksum = str(sumo)[2]+str(sumo)[3]+str(sumo)[0]+str(sumo)[1]
IndexError: string index out of range


Here's my function:


Code:
def getCheckSum(dataSection):
   hexArray = [dataSection[x:x+2] for x in xrange(0,len(dataSection),2)]

   sumo=0   
   for i in range(0,len(hexArray)):         
      sumo += int(str(hexArray[i]),16)
           
   checksum = str(sumo)[2]+str(sumo)[3]+str(sumo)[0]+str(sumo)[1]
   return checksum
ScoutDavid wrote:
However, I was not sure if 'BB6D' was part of this, so I decided to try my getCheckSum( function with both. However, neither returned the correct checksum.
No offense, but I'm pretty sure we've answered that question two or three times previously. Sad

Here's your fixed function:

Code:
def getCheckSum(dataSection): 
   hexArray = int([dataSection[x:x+2],16) for x in xrange(0,len(dataSection),2)] 

   sumo=0   
   for i in range(0,len(hexArray)):         
      sumo = (sumo + hexArray[i])%65536

   myhex = "%04X" % (sumo)
   checksum = "%s%s" % (myhex[2:4], myhex[0:2])
   return checksum
Thanks Kerm! Now I'm using binpac8x though and I'd like to know how to do this:

I have some code in a string, as an example: ("BB6D210100EF0745C9").

I want to write that code in a file, a .bin file, a binary file.

I want to do it using bytearrays.

I can do this:


Code:

buf=bytearray()
buf.append(0xDE)
f.write(buf)


That works, but how can I do that to the string?


Code:
programData = self.inputText.GetValue()
if programData[0:4].upper() != 'BB6D':
   programData='BB6D'+programData
         
myByteArray = bytearray()
         
myByteArray.append(programData)


That would write it but I get a ValueError:


Code:

ValueError: string must be of size 1


How to do it, then?
Thanks.
Are you using Python 2.x or 3.x? Are you trying to make it cross-compatible, or do you only care about either 2.x or 3.x?
KermMartian wrote:
Are you using Python 2.x or 3.x? Are you trying to make it cross-compatible, or do you only care about either 2.x or 3.x?


I only care about 2.x.
ScoutDavid wrote:
KermMartian wrote:
Are you using Python 2.x or 3.x? Are you trying to make it cross-compatible, or do you only care about either 2.x or 3.x?


I only care about 2.x.
It is important that you keep in mind that a python array of bytes ("bytes") is basically like a string, while a "bytearray" variable is a mutable array of actual bytes. You can't append more than a single element to an array; consider either using a loop, or finding out if bytearray has a join() function.

Code:
>>> a = "210100EF0745"
>>> b = bytearray()
>>> c = [a[x:x+1] for x in xrange(0,len(a),1)]
>>> c
['2', '1', '0', '1', '0', '0', 'E', 'F', '0', '7', '4', '5']
>>> for i in range(0,len(c)):
   b.append(c[i])

   
>>> b
bytearray(b'210100EF0745')
>>> d = bytearray()
>>> for i in c:
   d.append(i)

   
>>> d
bytearray(b'210100EF0745')
>>> b
bytearray(b'210100EF0745')


OK, I am now using binpac8x to create files and I created a binary file with this:


Code:
BB6DEF4045210500
EF0745EF7249C9


It's a binary file, not ASCII, but with that encoded on it (I'm sure the problem isn't the binary file).

Then I do:


Code:
os.system("binpac8x.py "+binFileName)


binFileName is the name of my file.

And here's what I got as a 8xp file (in binary, not ASCII):


Code:
2A2A54493833462A
1A0A0042696E5061
6338782028632932
3031302043656D65
746563682E6E6574
264B65726D204D61
727469616E35000D
002400064D594C49
54544C4500002400
2200424236446566
343034350A323130
3130300A65663037
34350A6566373234
390A6339AB0A


My reaction was immediate: "What the ?".

I really have no idea of what's causing this.

Any idea?
I'm not seeing what the problem is; what's wrong with that...?
The problem with that is that my code (in the .bin) isn't in the 8xp file, as simple as that.
Sure it is. At the very end I see "6339", which is the number 63 followed by 39, or in other words "C" "9". The bin file you're passing to BinPac8x is letters like "C9" instead of bytes like ($c9).
KermMartian wrote:
Sure it is. At the very end I see "6339", which is the number 63 followed by 39, or in other words "C" "9". The bin file you're passing to BinPac8x is letters like "C9" instead of bytes like ($c9).


Then I'm writing a string, not bytes, I'll just use my old way of writing files, a bytearrays.
I just said that. Very Happy Can you post the code that you're using to write into the files?

Code:

programData = self.inputText.GetValue()
if programData[0:4].upper() != 'BB6D':
   programData='BB6D'+programData

programDataArray = [programData[x:x+1] for x in xrange(0,len(programData),1)]

myByteArray = bytearray()

for i in programDataArray:
   myByteArray.append(i)

self.filename=dlg.GetFilename()

binFileName = ""

if len(self.filename[:len(self.filename)-4])>8:
   binFileName = self.filename[0:8]+".bin"
else:
   binFileName = self.filename

filehandle=open(binFileName,'wb')
filehandle.write(myByteArray)
filehandle.close()

os.system("binpac8x.py "+binFileName)


Never mind the filename variables, it's just a hack to avoid >8 names.

But that's my code.
This line:
Code:
programDataArray = [programData[x:x+1] for x in xrange(0,len(programData),1)]
just splits your ASCII into a sequence of two-letter chunks. It doesn't turn them from two-letter chunks to actual numbers. You need an int(programData[xMad+1],16) in there.
I'm using a new method now, and I still have a problem.

I created the following file: http://davidgom.co.cc/mylittle.bin

I think it's ok, it's code is the following:

BB6DEF4045210500
EF0745EF7249C9

Please download the file and check the binary file is ok.

And then the 8xp file created is here.

It crashes and it's code is very similar to the one desired (the .bin one) but it has some differences:


Code:
2A2A54493833462A
1A0A0042696E5061
6338782028632932
3031302043656D65
746563682E6E6574
264B65726D204D61
727469616E24000D
001300064D594C49
54544C4500001300
1100BB6DEF404502
101000EF07450EF7
2409C9B208


The code is more or less right, however some zeros were added to the code in random positions:


Code:
BB6DEF4045[b]0[/b]2
101000EF0745[b]0[/b]EF7
24[/b]0[/b]9C9


Here's my code to create the file:


Code:
def ExporTo8xp(event):
def to_binary(hex_string):
   ints = [int(hex_string[i:i+2], 16) for i in range(0,len(hex_string),2)]
   return struct.pack('B' * len(ints), *ints)
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "Binary Files (*.bin)|*.bin", wx.SAVE | wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
   programData = self.inputText.GetValue()
   if programData[0:4].upper() != 'BB6D':
      programData='BB6D'+programData
   
   
   self.filename=dlg.GetFilename()
   
   binFileName = ""
   
   if len(self.filename[:len(self.filename)-4])>8:
      binFileName = self.filename[0:8]+".bin"
   else:
      binFileName = self.filename

   filehandle=open(os.path.join(self.dirname, binFileName),'wb')
   filehandle.write(to_binary(programData))
   filehandle.close()
   
   os.system("binpac8x.py "+binFileName)
   
   self.openfile = binFileName[:len(binFileName-4)]+".8xp"
   
   self.SetTitle('Assemblex IDE - '+self.filename)
dlg.Destroy()


Any idea of what I'm doing wrong?
In this function:
Code:
def to_binary(hex_string):
   ints = [int(hex_string[i:i+2], 16) for i in range(0,len(hex_string),2)]
   return struct.pack('B' * len(ints), *ints)
Can you add a print ints line right after the ints= line and tell us what it outputs?

Code:

[187,109,239,64,69,2,16,16,0,239,7,69,14,247,36,9,201]


Did you check the binary file? I just rechecked it and it also has weird 0s.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3, 4, 5, 6  Next
» View previous topic :: View next topic  
Page 5 of 6
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement