×
Namespaces

Variants
Actions
(Difference between revisions)

WISE Receive Number

From Nokia Developer Wiki
Jump to: navigation, search
ebra (Talk | contribs)
(Links)
ebra (Talk | contribs)
(Maemo Platform)
Line 9: Line 9:
  
 
== Maemo Platform ==
 
== Maemo Platform ==
 +
<code>
 +
#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;
 +
}
 +
</code>
  
 
== S60 Platform ==
 
== S60 Platform ==

Revision as of 13:12, 17 June 2008

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

Links

65 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.

×