WISE Receive Number
hamishwillee
(Talk | contribs) m (Hamishwillee - Fix categories) |
|||
| Line 1: | Line 1: | ||
| + | [[Category:Bluetooth]][[Category:Maemo]][[Category:Symbian]][[Category:Symbian C++]][[Category:Porting]] | ||
== Description == | == Description == | ||
| Line 70: | Line 71: | ||
* [[Wireless Information Sharing Engine]] | * [[Wireless Information Sharing Engine]] | ||
* [[WISE Protocol]] | * [[WISE Protocol]] | ||
| − | |||
| − | |||
Revision as of 06:04, 2 May 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);
}

