Skip to content
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

Find a specific address in the .hex file #4

Open
ridi-mz opened this issue Apr 28, 2017 · 2 comments
Open

Find a specific address in the .hex file #4

ridi-mz opened this issue Apr 28, 2017 · 2 comments
Labels

Comments

@ridi-mz
Copy link

ridi-mz commented Apr 28, 2017

Hello,
I'm trying to parse some .a2l and .hex files to extract variables and their values. So far l don't know how to find the values of the variables in the .hex file. Here is a link (https://wiki.asam.net/display/STANDARDS/ASAM+CDF#ASAMCDF-Downloads) to download an example of these files. To be more specific : How can I read the value at the address 0x810600 in the .hex file ?

/begin CHARACTERISTIC ASAM.C.DEPENDENT.REF_1.SWORD
  "Dependent SWORD" 
  VALUE 
  0x810600                                             
  RL.FNC.SWORD.ROW_DIR                                 
  0 
  CM.IDENTICAL
  -32268 32267
  /begin DEPENDENT_CHARACTERISTIC 
     "X1 + 5" 
     ASAM.C.SCALAR.SBYTE.IDENTICAL                    
  /end DEPENDENT_CHARACTERISTIC
  DISPLAY_IDENTIFIER DI.ASAM.C.DEPENDENT.REF_1.SWORD
/end CHARACTERISTIC
@j123b567
Copy link
Owner

There are several strategies. If you need multiple (all) defined variables from .a2l file, you will prefere this method:

You can implement your own DataListener. It can create some binary representation of the .hex file in
the memory. It can compact sequential regions in larger blocks. Have a look at class MemoryRegions used in class RangeDetector. These clases just calculates address ranges, but can be easilly extended to store also data.

Later you can implement lookup function on that data, that will find correct region containing that address and return required number of bytes. After that, it is easy to fill your Java model with data from HEX.

Other way is, if you need just one variable from that file. This is already implemented in my second project in C# (https://github.com/j123b567/net-intelhex-parser), where class BinWriter has two more parameters - input and output memory region. If you compile the latest example C# program (I'm using MonoDevelop/XamarinStudio for this). It can be also easilly rewritten to Java. To extract 2 byte long variable at address 0x810600, you will call this from commandline

hex2bin.exe -i=0x810600:0x810601 -o=0x0000:0x0001 ASAP2_Demo_V161.hex variable.bin

Parsing .a2l file is out of the scope of this library.

@j123b567
Copy link
Owner

Here is precompiled latest version of the utility https://github.com/j123b567/net-intelhex-parser/releases/download/v2.0/hex2bin.exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants