|
1 /* |
|
2 * Copyright (c) 2005-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 "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 * System Includes |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <assert.h> |
|
22 #include <string.h> |
|
23 |
|
24 /********************************************************************************************** |
|
25 * |
|
26 * Local Includes |
|
27 * |
|
28 *********************************************************************************************/ |
|
29 #include "CFrameBuffer.h" |
|
30 |
|
31 /********************************************************************************************** |
|
32 * |
|
33 * Defines |
|
34 * |
|
35 *********************************************************************************************/ |
|
36 |
|
37 /********************************************************************************************** |
|
38 * |
|
39 * Static Method |
|
40 * |
|
41 *********************************************************************************************/ |
|
42 TFBError CFrameBuffer::createSendBuffer(int aUID, TPCommand aSendCommand, int aDataLength, char* aData, char* aFrame, int* aFrameSize) |
|
43 { |
|
44 int totalFrameSize, i, data_base_index; |
|
45 TPHeader *header; |
|
46 |
|
47 // Check params |
|
48 assert ( aData != NULL); |
|
49 assert ( aFrame != NULL); |
|
50 assert ( aFrameSize != NULL); |
|
51 |
|
52 // Calculate the size of the resultant frame buffer |
|
53 totalFrameSize = ( sizeof(TPHeader) + aDataLength); |
|
54 |
|
55 // Check that the frame data will fit into the allocated frame size |
|
56 if ( totalFrameSize > *aFrameSize ) |
|
57 { |
|
58 return TFB_BUFFERTOOSMALL; |
|
59 } |
|
60 |
|
61 header = (TPHeader*)aFrame; |
|
62 |
|
63 // Now create the packet |
|
64 header->iUid = aUID; // Add the UID |
|
65 header->iCmdID = aSendCommand; // Add the command id |
|
66 header->iDataLen = aDataLength; // Add the length |
|
67 |
|
68 for( i = 0, data_base_index = sizeof(TPHeader); i < aDataLength; i++ ) |
|
69 { |
|
70 aFrame[data_base_index + i] = aData[i]; |
|
71 } |
|
72 |
|
73 // Set the final frame size to the actual size of the frame we have created. |
|
74 *aFrameSize = totalFrameSize; |
|
75 |
|
76 return TFB_SUCCESS; |
|
77 } |
|
78 |