Page 1 of 1

Converting a structs to a unsigned short-pointer ??

Posted: Mon May 11, 2009 6:30 pm
by DarkShadow44
Hello!
Is it possible to convert a struct to a pointer like this:

Code: Select all

typedef struct
{
     int value_1;
     int value_2;
}test_struct;

test_struct test;

int main()
{
     test_struct* pointer = &test;

     unsigned short* shortPtr=(unsigned short*) pointer;
}
I want to use it for wifi:

Code: Select all

Wifi_RawTxFrame(sizeof(test_struct)+1, 0x0014, shortPtr) ;
Afer sending the clients must decode it like

Code: Select all

void Handler(int packetID, int readlength) 
{ 
     test_struct test2; 
     static int bytesRead; 

     bytesRead = Wifi_RxRawReadPacket(packetID, readlength, (unsigned short*)test2); 
}

Please Help!!!

Re: Converting a structs to a unsigned short-pointer ??

Posted: Mon May 11, 2009 9:49 pm
by Sylus101
I'm not 100% sure, but I believe you should be able to just cast directly in the function without the need to create shortPtr (same as you did in the Handler function):

Code: Select all

Wifi_RawTxFrame(sizeof(test_struct)+1, 0x0014, (unsigned short*)pointer);

Re: Converting a structs to a unsigned short-pointer ??

Posted: Tue May 12, 2009 8:34 pm
by Al_Bro
Never used those functions myself, but you'd probably need to change the line to something like:

Code: Select all

bytesRead = Wifi_RxRawReadPacket(packetID, readlength, (unsigned short*)&test2);
(i.e. take the reference to variable test2).