-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Extended Address record type mode saving in 'write_hex_file' function #41
base: master
Are you sure you want to change the base?
New Extended Address record type mode saving in 'write_hex_file' function #41
Conversation
Hmm, I didn't see that before, but there is a pull-up request (old one though), which is strongly related with this topic: #5
Right now I'm confused :) |
OK, my bad. It was 4 years ago. A long time ago in far far galaxy... |
I see no problem in "merging" both solutions. The only thing here is what You consider as common part and what is need to be changed. This can be done in several variants.
And I think that is all. Tell me what You think and I'll start to work on this :) |
OK. Let's do what is minimal accepted for you. I don't want to ask you for something you don't sign in. Converting start address is overkill for me. It's nice to have, but maybe as a separate method, if any? Your and older patches are both trying to fix the same problem. Let's name it in scrum terms )) "I want to have control over the type of extended address record when writing the hex file." What we need, the core part:
The second, bonus part:
So, about "auto" type of extended address record. It looks for me that we must check the maximum address of the data first, then if still segment is possible - check starting address record type, if no starting address record here - use linear. As we say before - linear was default behaviour in all previous releases. Does it make sense for you? I'd like to summarize, for every change (core and bonus parts) I'd like to have from your patch:
|
I agree about exception. |
Umm, and another option for auto. I think we can save the extended address type we read from source hex file. If there is only one type, you can save it for later use as another sign before inspecting starting addr type. This would make round trip better. Again - it's up to you. |
Hi,
this is already done in my solution, but:
I can agree to preserve old the behavior, when possible. Nevertheless 'auto' mode is something new, which will be used only by people who will no something about it. Default option is 'linear', just like did with my current change.
'linear' option would be actually what we have in IntelHex right now. 'segment' would throw exception whenever Starting Linear Address is detected or data >=1MB. Both would not add any Extended Address records when when data <64KB.
I was thinking about this. But first of all the IntelHex internal structure data need to support this. And we need to always remember about this if we want to rely on that parameter. I would like add additionally, that besides 'bin2hex' we need to take care of 'hexmerge' as well - it uses 'write_to_hex' directly. I checked it today ;) |
intelhex/__init__.py
Outdated
@@ -630,26 +659,48 @@ def write_hex_file(self, f, write_start_addr=True, eolstyle='native', byte_count | |||
minaddr = addresses[0] | |||
maxaddr = addresses[-1] | |||
|
|||
if extaddr_rectyp == -1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should check maxaddr before checking start addr record type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason why this is here, is because whole data are manged here. We have all necessary variables here. If we want to make checks for 'maxaddr' before Starting Address then I'm understanding this that You want to make this more important criteria than Start Address type for Extended Address resolving. If this was Your intention, then no problem - I will do a little change and refactor. If not then I suggest this would stay as it is now.
intelhex/__init__.py
Outdated
cur_addr = minaddr | ||
cur_ix = 0 | ||
|
||
while cur_addr <= maxaddr: | ||
if need_offset_record: | ||
if cur_addr > 0x0FFFFF and extaddr_rectyp == 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should check this condition at the start of the operation. checking it here every time is waste of time.
if maxaddr > 0x0FFFFF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, agree. Need to find different suitable exception type :)
intelhex/__init__.py
Outdated
bin[4] = b[0] # msb of high_ofs | ||
bin[5] = b[1] # lsb of high_ofs | ||
bin[5] = b[1] # lsb of high_ofs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add extra white spaces please
Sorry, I haven't. Done now, for core part, except tests. |
I've added a new option for 'ext_addr_mode' - 'none'. When selected it only checks if last address fits into 64KB. It's just to have consistent solution for all options ('segment', 'linear'). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add something to NEWS and AUTHORS
docs/manual/part2-5.txt
Outdated
BLOCK_SIZE = 128 # 128 bytes | ||
for addr in range(0, EEPROM_SIZE, BLOCK_SIZE): | ||
eeprom.i2c_write(addr, ih.tobinarray(start=addr, size=BLOCK_SIZE)) | ||
Writing out data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spot different line-endings here. Can you double check please? I'd like to see actual changes in document, but diff shows me that all document was changed. Not good. I believe all my files are using LF line-endings. You can set git attributes for those text files if you wish. But please, don't blindly change line endings. It's bad practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will recheck this. I checked few files and I thought they are OK.
Maybe the problem is that I'm using Windows and it does some "magically" things with the files :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on Windows too. You can use smart text editor though, Visual Studio Code is very good and should preserve original line-endings IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use VS Code as well. It looks like something went wrong.
|
||
eol = IntelHex._get_eol_textfile(eolstyle, sys.platform) | ||
|
||
addresses = dict_keys(self._buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I can't see unit tests for new feature. Can you add some? |
Test for new 'none' option are there. I didn't do special test suite for it. Just added/changed to which I created before. |
I haven't noticed changes to tests - because it says diff too large. Again line edings. Please fix it. |
You mean to squash all the commits in this pull request? Is this even possible after everything is pushed on repo? |
I think you will need to use |
New 'ext_addr_mode' parameter responsible for Extended Address records.
88a2e42
to
1d8f5c8
Compare
I left 'X' in 'NEWS' on purpose, as I can't predict the future ;) |
@bialix I don't know if You get the notifications I had corrected everything that you requested. It's waiting for You to review :) |
Sorry for delay! I can't review it right now. I'll try my best soon. |
Hello,
I've finally pushed my changes, which will solve the problem described by me here: #40
There is new parameter 'ext_addr_mode' for 'write_hex_file', which will handle the issue in following way.
I did the implementation in few days, but I had problem to manage UnitTest for this change. I hope everything is OK there.