WISE Receive Number
(→Description) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot update - Add ArticleMetaData) |
||
| (6 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| + | {{ArticleMetaData <!-- v1.2 --> | ||
| + | |sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) --> | ||
| + | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
| + | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20080617 | ||
| + | |author= [[User:Ebra]] | ||
| + | }} | ||
| + | [[Category:Bluetooth]][[Category:Maemo]][[Category:Symbian]][[Category:Symbian C++]][[Category:Porting]] | ||
== Description == | == Description == | ||
| Line 9: | Line 32: | ||
== 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 == | ||
| + | <code> | ||
| + | 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); | ||
| + | } | ||
| + | </code> | ||
== Links == | == Links == | ||
| + | * [[Archived:Wireless Information Sharing Engine]] | ||
| + | * [[WISE Protocol]] | ||
Latest revision as of 09:28, 26 July 2012
Article Metadata
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);
}

