jlcout / epctagcoder

Java library for RFID EPC encode / decode

Home Page:https://jlcout.github.io/epctagcoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with certain chip formats

jnwilliamlee opened this issue · comments

Hi,

Thanks for a great framework. It saves us a lot of time.

It works great, but it seems that there are certain formats that are not supported when parsing a chipcode.

At least some of the chips that I have to scan fail to be understood. I'm not sure if it is the chips that have been coded wrong by the manufacturer or because epctagcoder currently supports 1.9 and the Tag Data standard is at 1.13? Maybe something third?

For example following RFID codes

3000E2009A9040060AF000000372
3000E2009A9040060AF000003060

When using https://www.gs1.org/services/epc-encoderdecoder seems to work.

3000E2009A9040060AF000000372 -> EPC Tag URI = urn:epc:tag:sgtin-96:0.242668184592.0.25953304576

But I am having problems when I use the following in my unit test

...
            ParseSGTIN parseSGTIN = ParseSGTIN.Builder().withRFIDTag(chipCode).build();
            if ("sgtin".equals(parseSGTIN.getSGTIN().getEpcScheme())) {
                StringBuilder sb = new StringBuilder("urn:epc:tag:sgtin-");
                sb.append(parseSGTIN.getSGTIN().getTagSize());
                sb.append(":");
                sb.append(parseSGTIN.getSGTIN().getExtensionDigit());
                sb.append(".");
                sb.append(parseSGTIN.getSGTIN().getCompanyPrefix());
                sb.append(".");
                sb.append(parseSGTIN.getSGTIN().getFilterValue());
                sb.append(".");
                sb.append(parseSGTIN.getSGTIN().getSerial());
                return sb.toString();
            }
...

The first issue is that the RFID code causes a NumberformatException as 242668184592 in too big for an Integer.

java.lang.NumberFormatException: For input string: "242668184592"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
NumberFormatException.java:65
	at java.base/java.lang.Integer.parseInt(Integer.java:652)

If I change the code and remove Integer.parseInt() in line 176 and use the String version of Converter.decToBin the code can continue. But the problem is that the serial is then incorrect? I get

EPC Tag URI: urn:epc:tag:sgtin-96:0.242668184592.0.1700875768693618

It seems that the serial is different than https://www.gs1.org/services/epc-encoderdecoder?

Thanks again for this project.

Hi,

I am happy that my project has helped you in some way.
I have in mind what causes the bug and a solution.
Next weekend I must fix it.

Cheers

The EPC is not correct, the hexadecimal converted to binary has 112 bits. The specification allows only 96 or 128 bits,
https://www.gs1.org/services/epc-encoderdecoder ignores the additional hexadecimal to calculate correctly, so I changed my implementation to ignore it too.

image

Another detail is that you build epcTagURI as follows:

            StringBuilder sb = new StringBuilder ("urn: epc: tag: sgtin-");
            sb.append (parseSGTIN.getSGTIN (). getTagSize ());
            sb.append (":");
            sb.append (parseSGTIN.getSGTIN (). getExtensionDigit ());
            sb.append (".");
            sb.append (parseSGTIN.getSGTIN (). getCompanyPrefix ());
            sb.append (".");
            sb.append (parseSGTIN.getSGTIN (). getFilterValue ());
            sb.append (".");
            sb.append (parseSGTIN.getSGTIN (). getSerial ());
            return sb.toString ();

could just execute the method: parseSGTIN.getSGTIN (). getEpcTagURI ()

Hello,

Thank you so much for your quick response and looking at the issue.

If the EPC is wrong, maybe your previous version was more correct when it did not ignore it?

I didn't realize before, but since the tags are invalid, the barcode generated using https://www.gs1.org/services/epc-encoderdecoder from the tags are not unique. With your fix, epctagcoder now also does that. Before the fix, the serial generated was unique.

I am using epctagcoder to generate a barcode (actually a QR code) from the RFID chipcode, so it also is possible to scan a chip using a QR code on the label of a RFID chip. This of course also means that when I scan the QR code, I cannot recreate what the original RFID code was, as the only unique part is the last 32 bits, which is thrown away. So when using the QR code to find the RFID code, they would now all generate 3000E2009A9040060AF00000 as the RFID chip. So it is not possible to calculate a unique RFID code using the QR code identifier since data is lost when creating the QR code identifier. The generated QR code for both 3000E2009A9040060AF000003060 and 3000E2009A9040060AF000000372 will be the same and thereby also the extracted RFID code.

Do you think there is a workaround so it is possible to generate a unique barcode identifier using the invalid EPC's? A barcode identifier that can be reversed into the same unique RFID tag again? Or is the proper solution to reprogram all the invalid EPC we got? I'm hoping for the workaround as there are thousands of tags.

Hi,

I also thought that my previous version would be the most correct, however it is not possible to perform the correct decoding of the serial number because it has a maximum number of characters, causing the error of value out of range. Understand that this approach is not foreseen by the specification.

Unfortunately, I don't see an alternative solution, I believe that it will be necessary to reprogram invalid EPCs.

Ok, thank you.

I will close this issue, as it was the tags that were invalid. I don't know if you wish to revert your changes or leave them.

Thanks again for this great project.