×
Namespaces

Variants
Actions
Revision as of 09:28, 26 July 2012 by hamishwillee (Talk | contribs)

WISE Receive Number

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: ebra (17 Jun 2008)
Last edited: hamishwillee (26 Jul 2012)

Contents

Description

The communication between two WISE devices is devided into two possibilities

When number is send or received the data size is always 5 bytes - the first byte is a control byte (always 'L') and the remaining 4 bytes represents a 32 bit integer is a little endian format.

Maemo Platform

#define LITTLE_ENDIAN 'L'
#define BIG_ENDIAN 'R'
 
int buffer_to_int(const char* buffer,int* error)
{
int index,result=0;
*error=WISE_OK;
if ( buffer==NULL ) return 0;
if ( buffer[0]==LITTLE_ENDIAN )
{
for ( index=sizeof(int); index>1; index-- )
result=(result+(int)buffer[index])<<8;
result+=(int)buffer[1];
}
else if ( buffer[0]==BIG_ENDIAN )
{
for ( index=1; index < sizeof(int); index++ )
result=(result+(int)buffer[index])<<8;
result+=(int)buffer[sizeof(int)];
}
else *error=WISE_ERROR;
return result;
}
 
int wise_recv_int(int socket,int* nbr)
{
int bytes_read=0,error;
char number[sizeof(int)+1];
 
/* receive number */
bytes_read = read(socket,number,sizeof(int)+1);
if ( bytes_read < sizeof(int)+1 )
{
return WISE_CONNECTION_ERROR;
}
*nbr = buffer_to_int(number,&error);
return error;
}

S60 Platform

TInt CWISEBase::ReceiveIntL(RSocket& aSocket)
{
TRequestStatus status;
TBuf8<5> buffer;
TSockXfrLength len;
 
aSocket.RecvOneOrMore(buffer, 0, status, len);
User::WaitForRequest(status);
User::LeaveIfError(status.Int());
 
const TUint8* ptr = buffer.Ptr();
return LittleEndian::Get32(++ptr);
}

Links

54 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×