My USB-RFID reader receives a 24 bit ID from the card. I can convert this ID into 8 bit/16bit format. But how can I convert it into 40 bit format?
Example for one tag:
24 bit decimal format (as I get from the reader): 0005966009
8,16 bit binary format (converted via Python): 01011011, 0000100010111001
8,16 bit decimal format (converted via Python): 91, 2233
40 bit decimal format (provided by the manufacturer): 455272499385
How can I get that 40 bit number from the 24 bit number?
Tag standard: unique, 125 kHz
Screenshot from manufacturer's system:
No, in general it's impossible to turn a 24 bit number into a 40 bit number. Such a conversion would imply that you add 16 bits of extra information to the 24 bit value. This extra information won't just magically appear out of nowhere.
In your case, the numbers are
24 bit format: 0005966009dec = 5B08B9hex
8+16 bit format: 091dec & 02233dec = 5Bhex & 08B9hex
40 bit format: 455272499385dec = 6A005B08B9hex
Thus, all three numbers contain 24 common bits (5B08B9hex). The 40 bit number has an additional prefix value of 6A00hex.
Since you did not reveal what RFID system and what tags you are using (other than that they are operating on 125 khz), it's impossible to tell if that prefix is some standard prefix that is the same for all tags or if that prefix changes for every tag (or every manufacturer, customer, etc.)
If the prefix is the same for all your tags, you could easily use the value 6A00hex as the upper 16 bits of each tag serial number. However, if the prefix may be different for different tags, then there is no other way than to get a reader that reads that full 40 bit serial number.
Nevertheless, if all your readers only read the 24 bit value, I don't see why you would even want to use the whole 40 bit value. Even if you already have a database that contains the whole 40 bit value, you could easily trim that value to a 24 bit value (as long as the lower 24 bits are (sufficiently) unique across all your tags).
Related
I was wondering if there was a easy way to grab the full file version of an exe in python (for instance if you right click into a file's properties and go to Details, you will find something like File Version 1.1.1.0).
I found something close by using win32api.GetFileVersionInfo, however when listing the file properties, under FileVersionLS it seems to have given only one digit, the far right digit of the file version (so in the case of the example above it gave the 0 in 1.1.1.0) when I needed the whole version number.
Hopefully this makes sense, please let me know if there is something I need to elaborate on.
Thanks for reading!
FileVersionLS and FileVersionMS act together to represent the complete version number as a 64-bit integer:
dwFileVersionMS
Type: DWORD
The most significant 32 bits of the file's binary version number. This member is used with dwFileVersionLS to form a 64-bit value used for numeric comparisons.
dwFileVersionLS
Type: DWORD
The least significant 32 bits of the file's binary version number. This member is used with dwFileVersionMS to form a 64-bit value used for numeric comparisons.
They are each bit-packed with two 16-bit numbers, so you have to bit-shift out the individual numbers. You can use win32api.LOWORD() and win32api.HIWORD() for that, eg:
def get_file_version(self, path):
info = win32api.GetFileVersionInfo(path, '\\')
ms = info['FileVersionMS']
ls = info['FileVersionLS']
return (win32api.HIWORD(ms), win32api.LOWORD(ms),
win32api.HIWORD(ls), win32api.LOWORD(ls))
I'm pulling data out from DA-14585 IoT device. I'm getting a report from the temperature sensor which is as follows:
a50f060203d10900000b020390290000
Reading the documentation (search for table 12) tells me that
a5 is preamble
0f is timestamp
06 is the sensor id (temperature)
02 is the sensor state (always 2)
03 is the sensor value (always 3)
d10900000b020390290000 is the actual sensor data, which is listed as "Val32".
Mainly I'm wondering, what format is this data in, and how would one go with turning this into a human readable form? Same goes for the timestamp, which is 0f.
I'm mainly working with Python.
Val32 is a 32-bit integer (little-endian by the look of things). In your example, d1090000. What follows thereafter is a subsequent message which will need to be decoded separately (it has the same format and is of type GAS_REPORT_ID).
Since 0x000009d1 = 2513, if I were to guess I'd say this is in hundredths of degrees C, i.e. 25.13C (assuming this is ambient temperature and not, say, a reading from an oven). Please don't rely on my guesswork though and read the relevant specs. :)
You could use the struct module to unpack the binary data in Python.
There is a need for storing and retrieving some data which can be string formatted in a known way. But the data needs to be 16 bit aligned as the storing device doesn't support it. In order to store the data efficiently, I am packing the data in a known format using struct pack. But how should I align the data to be 16 bit so that retrieving and storing doesn't screw up the data?
for eg.
data = [12,b'c', 100009, b"string", 3.45]
stringformat of data = "icl6sd"
packed data =b'\x0c\x00\x00\x00c\x00\x00\x00\xa9\x86\x01
\x00\x00\x00\x00\x00string\x00\x00\x9a\x99\x99\x99\x99\x99\x0b#'
How do I convert this data to be 16 bit aligned?
struct.pack knows all about C-compiler byte-alignment and will add packing bytes to your data without being asked. That is why your structure is 32 bytes long, even though your data calls for 4 + 1 + 4 + 6 + 8 (=23) bytes of of data. Look closely and you will see (for example) that string has been padded out on the right with an extra null byte so that the double will occupy the last 8 bytes of the structure. So I'm not sure I'm convinced that the alignment is wrong.
You can take charge of the padding yourself (format x) but I suggest that struct.pack knows exactly what it is doing.
If your packed data isn't being interpreted as you expect, it is much more likely that there is a problem with the struct specification or that the byte order is not what you expect.
I belong a garmin watch , to report statistic they have a sdk
in this SDK they have a timestamp in two format
one is a true timestamp on 32 bit
another is the lower part on 16 bit which must be combinate whith the first
I dont know to code this in Python Can somebody help me
here is their explanation and the formula
*timestamp_16 is a 16 bit version of the timestamp field (which is 32 bit) that represents the lower 16 bits of the timestamp.
This field is meant to be used in combination with an earlier timestamp field that is used as a reference for the upper 16 bits.
The proper way to deal with this field is summarized as follows:
mesgTimestamp += ( timestamp_16 - ( mesgTimestamp & 0xFFFF ) ) & 0xFFFF;*
my problem is not to obtain the two timestamp but to combinate the two in python
thanks
I'm not sure of the result but I took them literally explanation
I shifted 32-bit timestamps of bits left 16 positions
then I shifted 16 places to the right and I made one or bitwise with the 16-bit timestamp
Just as a preamble I am using python 3 and the bitstring library.
So Arinc429 words are 32 bit data words.
Bits 1-8 are used to store the label. Say for example I want the word to set the latitude, according to the label docs, set latitude is set to the octal
041
I can model this in python by doing:
label = BitArray(oct='041')
print(label.bin)
>> 000100001
The next two bits can be used to send a source, or extend the label by giving an equipment ID. Equipment IDs are given in hex, the one I wish to use is
002
So again, I add it to a new BitArray object and convert it to binary
>> 000000010
Next comes the data field which spans from bits 11-29. Say I want to set the latitude to the general area of London (51.5072). This is where I'm getting stuck as floats can only be 32/64 bits long.
There are 2 other parts of the word, but before I go there I am just wondering, if I am going along the right track, or way off how you would construct such a word?
Thanks.
I think you're on the right track, but you need to either know or decide the format for your data field.
If the 19 bits you want to represent a float are documented somewhere as being a float then look how that conversion is done (as that's not at all a standard number of bits for a floating point number). If those bits are free-form and you can choose both the encode and decode then just pick something appropriate.
There is a standard for 16-bit floats which is occasionally used, but if you only want to represent a latitude I'd go for something simpler. As it can only got from 0 to 360 just scale that to an integer from 0 to 2^19 and store the integer.
So 51.5072 becomes (51.5072/360*(2**19)) = 75012
Then store this as a unsigned integer
> latitude = BitArray(uint=75012, length=19)
This gives you a resolution of about 0.0007 degrees, which is the best you can hope for. To convert back:
> latitude.uint*360.0/2**19
51.50665283203125