60
|
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 |
}
|
458
|
37 |
int COSTProtocol::DecodeMessage(BYTE* fullMessage, DWORD& fullMessageLength, BYTE& msgId, BYTE*& rawMessage, DWORD& rawLength)
|
60
|
38 |
{
|
458
|
39 |
int result = DECODE_MESSAGE_NOT_FOUND;
|
60
|
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;
|
458
|
48 |
result = DECODE_MESSAGE_FOUND;
|
|
49 |
}
|
|
50 |
else
|
|
51 |
{
|
|
52 |
result = DECODE_NOT_ENOUGH_BYTES_TO_SEARCH;
|
60
|
53 |
}
|
|
54 |
|
458
|
55 |
return result;
|
60
|
56 |
}
|
|
57 |
|
|
58 |
DWORD COSTProtocol::EncodeMessage(BYTE* rawMessage, DWORD rawLength, BYTE protocolVersion, BYTE msgId, BYTE* fullMessage, DWORD maxFullLength)
|
|
59 |
{
|
|
60 |
DWORD outLength = 0;
|
|
61 |
|
|
62 |
fullMessage[OST_VER_BYTE_1] = protocolVersion;
|
|
63 |
fullMessage[OST_PROT_BYTE_1] = msgId;
|
|
64 |
fullMessage[OST_LEN_BYTE_1] = (BYTE)((rawLength >> 8) & 0xff);
|
|
65 |
fullMessage[OST_LEN_BYTE_1+1] = (BYTE)(rawLength & 0xff);
|
|
66 |
if (rawLength > 0)
|
|
67 |
{
|
|
68 |
memcpy(&fullMessage[OST_MSG_BYTE_1], rawMessage, rawLength);
|
|
69 |
}
|
|
70 |
outLength = rawLength + OST_HDR_LEN_1;
|
|
71 |
|
|
72 |
return outLength;
|
|
73 |
|
|
74 |
}
|