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

a bug with lengthleylarameter #375

Closed
cmydd opened this issue Dec 16, 2024 · 3 comments · Fixed by #376
Closed

a bug with lengthleylarameter #375

cmydd opened this issue Dec 16, 2024 · 3 comments · Fixed by #376

Comments

@cmydd
Copy link

cmydd commented Dec 16, 2024

hello
a odx like this

PARAM xsi:type="LENGTH-KEY" SEMANTIC="DATA" ID="Req_ReadMemorByAddre.Param_LengtFormaIdent">
        SHORT-NAME>Param_LengtFormaIdent</SHORT-NAME>
        LONG-NAME>Length Format Identifier</LONG-NAME>
        BYTE-POSITION>1</BYTE-POSITION>
        BIT-POSITION>4</BIT-POSITION>
        DOP-REF DOCREF="ES_DataLibra" DOCTYPE="LAYER" ID-REF="DOP_UINTDEC4Bits8x1F"/>
       /PARAM>
       PARAM xsi:type="LENGTH-KEY" SEMANTIC="DATA" ID="Req_ReadMemorByAddre.Param_AddreFormaIdent">
        SHORT-NAME>Param_AddreFormaIdent</SHORT-NAME>
        LONG-NAME>Address Format Identifier</LONG-NAME>
        BYTE-POSITION>1</BYTE-POSITION>
        DOP-REF DOCREF="ES_DataLibra" DOCTYPE="LAYER" ID-REF="DOP_UINTDEC4Bits8x1F"/>
       /PARAM>

 DATA-OBJECT-PROP ID="DOP_UINTDEC4Bits8x1F">
        DIAG-CODED-TYPE xsi:type="STANDARD-LENGTH-TYPE" BASE-DATA-TYPE="A_UINT32">
        BIT-LENGTH>4</BIT-LENGTH>
        BIT-MASK>0F</BIT-MASK>
       /DIAG-CODED-TYPE>

lengthkeyparameter.py
line 105

//emplace a value of zero into the encode state, but pretend the bits not to be used
        n = odxrequire(self.dop.get_static_bit_length()) + encode_state.cursor_bit_position
        tmp_val = b'\x00' * ((n + 7) // 8)
        encode_state.emplace_bytes(tmp_val, obj_used_mask=tmp_val)

the encode_state.cursor_bit_position is 4 and self.dop.get_static_bit_length() is 4

if encode_state.cursor_bit_position != 0:
     encode_state.cursor_bit_position = (odxrequire(self.dop.get_static_bit_length()) + encode_state.cursor_bit_position) % 8

if not like this.encodestate will throw exception
encodestate.py
line 191

        if self.cursor_bit_position != 0:
            odxraise("EncodeState.emplace_bytes can only be called "
                     "for a bit position of 0!", RuntimeError)
@andlaus
Copy link
Collaborator

andlaus commented Dec 16, 2024

thanks for the catch. (seems like nobody stumbled over non-byte aligned lentgh keys so far.) The fix is to add

        encode_state.cursor_bit_position = 0

before emplace_bytes() is called for the placeholder value. can you make a PR?

@cmydd
Copy link
Author

cmydd commented Dec 16, 2024

thanks for the catch. (seems like nobody stumbled over non-byte aligned lentgh keys so far.) The fix is to add

        encode_state.cursor_bit_position = 0

before emplace_bytes() is called for the placeholder value. can you make a PR?
sorry i dont knwo hao to make a pr.i can give you the odx file. search length-key or "Req_ReadMemorByAddre", you can find a lot of them.

@cmydd
Copy link
Author

cmydd commented Dec 16, 2024

odxfile.zip

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

Successfully merging a pull request may close this issue.

2 participants