connectivity/com.nokia.tcf/native/TCFNative/TCFProtOST/OSTProtocol.cpp
changeset 60 9d2210c8eed2
child 458 70467d598794
equal deleted inserted replaced
59:c892c53c664e 60:9d2210c8eed2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 // OSTProtocol.cpp: implementation of the COSTProtocol class.
       
    18 //
       
    19 //////////////////////////////////////////////////////////////////////
       
    20 
       
    21 #include "stdafx.h"
       
    22 #include "OSTProtocol.h"
       
    23 
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 // Construction/Destruction
       
    26 //////////////////////////////////////////////////////////////////////
       
    27 
       
    28 COSTProtocol::COSTProtocol()
       
    29 {
       
    30 
       
    31 }
       
    32 
       
    33 COSTProtocol::~COSTProtocol()
       
    34 {
       
    35 
       
    36 }
       
    37 BOOL COSTProtocol::DecodeMessage(BYTE* fullMessage, DWORD& fullMessageLength, BYTE& msgId, BYTE*& rawMessage, DWORD& rawLength)
       
    38 {
       
    39 	BOOL found = FALSE;
       
    40 
       
    41 	WORD msgLen = MAKEWORD(fullMessage[OST_LEN_BYTE_1+1], fullMessage[OST_LEN_BYTE_1]);
       
    42 	if (fullMessageLength >= (WORD)(msgLen + OST_HDR_LEN_1))
       
    43 	{
       
    44 		msgId = fullMessage[OST_PROT_BYTE_1];
       
    45 		rawMessage = &fullMessage[OST_MSG_BYTE_1];
       
    46 		rawLength = msgLen;
       
    47 		fullMessageLength = msgLen+OST_HDR_LEN_1;
       
    48 		found = TRUE;
       
    49 	}
       
    50 
       
    51 	return found;
       
    52 }
       
    53 
       
    54 DWORD COSTProtocol::EncodeMessage(BYTE* rawMessage, DWORD rawLength, BYTE protocolVersion, BYTE msgId, BYTE* fullMessage, DWORD maxFullLength)
       
    55 {
       
    56 	DWORD outLength = 0;
       
    57 
       
    58 	fullMessage[OST_VER_BYTE_1] = protocolVersion;
       
    59 	fullMessage[OST_PROT_BYTE_1] = msgId;
       
    60 	fullMessage[OST_LEN_BYTE_1] = (BYTE)((rawLength >> 8) & 0xff);
       
    61 	fullMessage[OST_LEN_BYTE_1+1] = (BYTE)(rawLength & 0xff);
       
    62 	if (rawLength > 0)
       
    63 	{
       
    64 		memcpy(&fullMessage[OST_MSG_BYTE_1], rawMessage, rawLength);
       
    65 	}
       
    66 	outLength = rawLength + OST_HDR_LEN_1;
       
    67 
       
    68 	return outLength;
       
    69 
       
    70 }