

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
3 messages in net.java.dev.jna.usersRe: [jna-users] FW: Mapping of a comp...| From | Sent On | Attachments |
|---|---|---|
| Freddie Scott | Mar 4, 2008 11:50 pm | |
| Freddie Scott | Mar 5, 2008 1:53 am | |
| Timothy Wall | Mar 5, 2008 6:37 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] FW: Mapping of a complex C++ Structure | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Mar 5, 2008 6:37:48 am | |
| List: | net.java.dev.jna.users | |
When I have to debug a sufficiently complex structure, I first verify the calculated Java structure size and compare against what the C compiler generates. If there's a discrepancy, I know I've likely made a transcription error.
You can then do a binary search of the fields, checking the offset calculated by the C compiler against what JNA calculates. If the offsets match, pick the midpoint of later fields; if they don't pick the midpoint of prior fields.
For example:
struct my_struct { int field0; int field1; int field2; };
struct my_struct* s = (struct my_struct*)0; printf("size of my_struct=%d\n", sizeof(struct my_struct)); printf("offset of field1=%d\n", (int)((char*)&s->field1 - (char*)&s);
On Mar 5, 2008, at 4:53 AM, Freddie Scott wrote:
Hi,
I forgot to add how this structure is used in the C source. This is how : void ReadOnDemandEx(HANDLE hReader, TAG_LIST_EX *pTagList)
Freddie Scott
From: Freddie Scott [mailto:fsc...@solatix.com] Sent: 05 March 2008 09:51 To: 'use...@jna.dev.java.net' Subject: Mapping of a complex C++ Structure
Hi,
I would like to know if I made a mistake with mapping a structure in my Java code. The reason I ask is because the C API is telling me that I am passing a bad parameter to it. The parameter in question is the TAG_LIST_EX structure below. I have read the jna:Marshalling page over and over and can’t seem to find any fault with my implementation. As you can see, the structure is quite complex :
= = ====================================================================== typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
typedef struct { int nInit; // This will be initialized by macro int nTagListStructureFormat; int nTagListStructureSize; } TAG_LIST_STRUCTURE_HEADER;
typedef struct { int nInit; // This will be initialized by macro int nTypeTagStructureFormat; int nTypeTagStructureSize; } TYPE_TAG_STRUCTURE_HEADER;
typedef struct { TYPE_TAG_STRUCTURE_HEADER Header; unsigned char status; //Status of entry - discovered, ... unsigned char antennaNum; //Last antenna this tag has been read DWORD dataLength; //number if bytes in the tagID field. Includes the EPC number, and the memory page data length. Memory page length is stored in dwMemoryPageLength SYSTEMTIME firstSeen; //Timestamp of first time tag was seen SYSTEMTIME lastSeen; //Timestamp of last time tag was seen unsigned long readCount; //Number of reads of this tag DWORD dwType; //Type of Tag DWORD dwFormat; //Tag Data Format int nMemoryPageNumber; //For class 0 tags, memory page 2 is EPC. Memory page 2 information is not stored in this and the following memory page variables DWORD dwMemoryPageOffset; //starting bit Offset into tag's memory page where data was read. DWORD dwMemoryPageLength; //length of memory page in bytes. DWORD dwOperationStatus; // WORD wStatusDetail; // WORD wCRC; // WORD wPC; // WORD wRSSI; // DWORD dwMillisecond; // DWORD dwReserved5; // Reserve DWORDS unsigned char tagID[RFID_MAX_TAG_ID_LENGTH_EX]; //ID code of tag }TYPE_TAG_EX;
typedef struct { TAG_LIST_STRUCTURE_HEADER Header; DWORD dwTotalTags; // DWORD dwTotalReads; // DWORD dwNewTags; // DWORD dwReadTimeMS; // DWORD dwSeqNum; // DWORD dwMaxTags; // Max tags supported. 0 means 200 DWORD dwErrorTags; // total of error tag packets appended to end of valid tags.. DWORD dwReserved[19]; // Resrve a total of 19 DWORDS TYPE_TAG_EX Tags[RFID_MAX_TAGS]; } TAG_LIST_EX;
===================================================================== Here is my Java implementation of the above structures :
public static class TAG_LIST_STRUCTURE_HEADER extends Structure {
public int nInit; // This will be initialized by macro public int nTagListStructureFormat; public int nTagListStructureSize;
}
public static class TYPE_TAG_STRUCTURE_HEADER extends Structure {
public int nInit; // This will be initialized by macro public int nTypeTagStructureFormat; public int nTypeTagStructureSize;
}
public static class SYSTEMTIME extends Structure {
public short wYear; public short wMonth; public short wDayOfWeek; public short wDay; public short wHour; public short wMinute; public short wSecond; public short wMilliseconds;
}
public static class TYPE_TAG_EX extends Structure {
public TYPE_TAG_STRUCTURE_HEADER Header; public byte status; //Status of entry - discovered, ... public byte antennaNum; //Last antenna this tag has been read public int dataLength; //number if bytes in the tagID field. Includes the EPC number, and the memory page data length. Memory page length is stored in dwMemoryPageLength public SYSTEMTIME firstSeen; //Timestamp of first time tag was seen public SYSTEMTIME lastSeen; //Timestamp of last time tag was seen public NativeLong readCount; //Number of reads of this tag public int dwType; //Type of Tag public int dwFormat; //Tag Data Format public int nMemoryPageNumber; //For class 0 tags, memory page 2 is EPC. Memory page 2 information is not stored in this and the following memory page variables public int dwMemoryPageOffset; //starting bit Offset into tag's memory page where data was read. public int dwMemoryPageLength; //length of memory page in bytes. public int dwOperationStatus; // public short wStatusDetail; // public short wCRC; // public short wPC; // public short wRSSI; // public int dwMillisecond; // public int dwReserved5; // Reserve DWORDS public byte[] tagID = new byte[64]; //ID code of tag
}
public static class TAG_LIST_EX extends Structure {
public TAG_LIST_STRUCTURE_HEADER Header; public int dwTotalTags; // public int dwTotalReads; // public int dwNewTags; // public int dwReadTimeMS; // public int dwSeqNum; // public int dwMaxTags; // Max tags supported. 0 means 200 public int dwErrorTags; // total of error tag packets appended to end of valid tags.. public int[] dwReserved = new int[19]; // Resrve a total of 19 DWORDS public TYPE_TAG_EX[] Tags = new TYPE_TAG_EX[200];
}
And lastly, here is the output of TAG_LIST_EX.toString() method :
JXR480$TAG_LIST_EX(allocated@0x2df6660 (32116 bytes)) { JXR480$TAG_LIST_STRUCTURE_HEADER Header@0=JXR480$TAG_LIST_STRUCTURE_HEADER(allocated@0x2df6660 (32116 bytes) (shared from allocated@0x2df6660 (32116 bytes))) { int nInit@0=0 int nTagListStructureFormat@4=0 int nTagListStructureSize@8=0 } int dwTotalTags@c=0 int dwTotalReads@10=0 int dwNewTags@14=0 int dwReadTimeMS@18=0 int dwSeqNum@1c=0 int dwMaxTags@20=0 int dwErrorTags@24=0 int dwReserved[19]@28=[I@e24e2a JXR480$TYPE_TAG_EX Tags[200]@74=[LJXR480$TYPE_TAG_EX;@179c285 }
For some reason I cannot get the "-Djna.dump_memory=true" vm argument to work, it hangs my system/application execution. I hope this is enough information !
Best Regards, Freddie Scott
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.21.4/1312 - Release Date: 2008/03/04 21:46
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.21.4/1312 - Release Date: 2008/03/04 21:46







