NTAG Version Info hardcoded for NTAG215
Closed this issue · 1 comments
In nxp_ntag21x_emulator.h
:
Payload versionPayload{version::Ntag215.Data, version::ResponseLength};
Also the emulator sets the versionPayload data before a payload is loaded.
My temporary fix is a little hacky. I added const Descriptor for Ntag213 and Ntag216. Then I made an array of their names in nxp_ntag21x.h
static Descriptor descriptors[] = { Ntag213, Ntag215, Ntag216 };
In Ntag21xEmulator::SetPayload
select the version::Descriptor based on payload data size and overwrite the default versionPayload in nxp_ntag21x_emulator.cpp
Payload newPayload(version::descriptors[payload->GetDataLength() / 450].Data, version::ResponseLength); //450 arbitrary number to make array index work
memcpy(&versionPayload, &newPayload, version::ResponseLength);
I'm sure there's a better way to do this but it's working for me for now.
Very clever with the 450 to index your array 😂
Yeah you've touched on something that I never quite came up with a very good solution to for sure, which is a one reason I had left it just hardcoded as NTAG215 for the time being. I'm pretty fine with how you've done it there for the other NTAG variants, I had just stopped short as I started thinking how to best implement metadata like that for other tag types further from the NTAG family.
Also the emulator sets the versionPayload data before a payload is loaded.
So, I had done it before setting payload, because through the majority of initially writing all of this I was building payloads by hand mostly, and had been mimicking exclusively NTAG215s, as it was what I had the majority of on my desk. I do have a couple 213s and 216s, but just hadn't got to them til I hit that "is this really how I want to do metadata" wall I mentioned above (thus assigning it right in the initializer.)
All of this is to say: You're probably pretty close to the "right" solution. Especially since the version metadata doesn't seem to change, at least it hasn't in the years prior according to the datasheets!
If you'd like to make a PR with what you've got, and mark it "allow edits from maintainers" I'll bump it around a bit and merge it in so you can have that functionality mainline!