3 messages in net.java.dev.jna.usersMapping of a complex C++ Structure
FromSent OnAttachments
Freddie ScottMar 4, 2008 11:50 pm 
Freddie ScottMar 5, 2008 1:53 am 
Timothy WallMar 5, 2008 6:37 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Mapping of a complex C++ StructureActions...
From:Freddie Scott (fsc@solatix.com)
Date:Mar 4, 2008 11:50:52 pm
List:net.java.dev.jna.users

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,

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