fulfilio / pyepc

Python GS1 EPC toolkit
MIT License
16 stars 3 forks source link

Filter Value #5

Open rG2ee opened 2 years ago

rG2ee commented 2 years ago

Hello, this is more like a question rather than an issue. I tried

SGTIN(company_prefix="0614141", indicator="8", item_ref="12345", serial_number="12345").encode(SGTIN.BinarySchemes.SGTIN_96, SGTIN.FilterValues.CASE)
>> '3054257BF7194E4000003039'

SGTIN(company_prefix="0614141", indicator="8", item_ref="12345", serial_number="12345").encode(SGTIN.BinarySchemes.SGTIN_96, SGTIN.FilterValues.RESERVED_2)
>> '30B4257BF7194E4000003039'

So the third bit is reserved for filtering. Is there a way to access the filter from an encoded epc like this:

SGTIN.decode('30B4257BF7194E4000003039').filter_value

Every other attribute is stored on the instance but I haven't found the filter.

Thanks in advance!

legomatrix commented 2 years ago

Maybe this helps: GS1 Tag Data Standard Line 2363 starts a whole chapter on filter values.

Maybe you can deduct filter values form binary values.

GS1_EPC_TDS_i1_13.pdf

rG2ee commented 2 years ago

You already provide the filter value in one of your functions.

In pyepc/epc.py: Patching SGTIN 96-bit (line 554-560) and SGTIN 198-bit (line 583-589):

return cls( 
    company_prefix,  
    indicator,
    item_ref,
    utils.decode_integer(serial),
    default_filter_value=str(int(filter_value, 2)) 
)

These two additional lines fix the issue. The question is if it breakes other things. (in this case one may use a different variable than default_filter_value).

If it's ok for you, I would create a PR and write some tests.

sharoonthomas commented 2 years ago

I think it's ok to set the default_filter_value with the filter_value that was decoded from an SGTIN.

Do you want to send a pull request for this? If yes, please include a test case.