testexecmgmt/ucc/Source/MobileTermination/CDatalinkPacketise.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     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 <stdio.h>
       
    22 #include <assert.h>
       
    23 
       
    24 
       
    25 /*******************************************************************************
       
    26  *
       
    27  * Local Includes
       
    28  *
       
    29  ******************************************************************************/
       
    30 #include "CDatalinkPacketise.h"
       
    31 
       
    32 
       
    33 /*******************************************************************************
       
    34  *
       
    35  * Definitions
       
    36  *
       
    37  ******************************************************************************/
       
    38 
       
    39 
       
    40 /*******************************************************************************
       
    41  *
       
    42  * Constructor - init state vars
       
    43  *
       
    44  ******************************************************************************/
       
    45 CDatalinkPacketise::CDatalinkPacketise( TPhoneData *aPhoneData, CLog *aLog ) : iIncomingFrame("CDatalinkPacketise::IncomingFrame"), iOutgoingFrame("CDatalinkPacketise::OutgoingFrame")
       
    46 {
       
    47 	// check params
       
    48 	assert( aPhoneData != NULL );
       
    49 	assert( aLog != NULL );
       
    50 
       
    51 	// set state
       
    52 	iAirInterface = NULL;
       
    53 	iTEChannel = NULL;
       
    54 	iPhoneData = aPhoneData;
       
    55 	iLog = aLog;
       
    56 }
       
    57 
       
    58 
       
    59 CDatalinkPacketise::~CDatalinkPacketise()
       
    60 {
       
    61 }
       
    62 
       
    63 
       
    64 /*******************************************************************************
       
    65  *
       
    66  * Access methods
       
    67  *
       
    68  ******************************************************************************/
       
    69 void CDatalinkPacketise::SetAirInterface( IAirInterface *aAirInterface )
       
    70 {
       
    71 	iAirInterface = aAirInterface;
       
    72 }
       
    73 
       
    74 void CDatalinkPacketise::SetTEChannel( ITEChannel *aTEChannel )
       
    75 {
       
    76 	iTEChannel = aTEChannel;
       
    77 }
       
    78 
       
    79 
       
    80 /*******************************************************************************
       
    81  *
       
    82  * Process data from the TEChannel
       
    83  *
       
    84  ******************************************************************************/
       
    85 TDataPathError CDatalinkPacketise::ProcessTEData( char *data, int len, int *aErrCode )
       
    86 {
       
    87 //	int i;
       
    88 	int errcode;
       
    89 //	int frame_size;
       
    90 //	char *frame_pointer;
       
    91 //	TFrameError ferr;
       
    92 //	TFrameStatus fstatus;
       
    93 	TDataPathError derr = DPE_NONE;
       
    94 
       
    95 	// check the params
       
    96 	assert( aErrCode != NULL );
       
    97 	*aErrCode = 0;
       
    98 		
       
    99 	// check that there is an air interface - not an error if not
       
   100 	if( iAirInterface == NULL ) {
       
   101 		return DPE_NONE;
       
   102 	}
       
   103 
       
   104 	// do not packetise the incoming interface
       
   105 	derr = iAirInterface->SendPacket( data, len, &errcode );
       
   106 	if( derr != DPE_NONE ) {
       
   107 		iLog->WriteLogEntry( SV_WARNING, "CDatalinkPacketise::ProcessTEData", "SendPacket returned error", derr, errcode );
       
   108 	}
       
   109 	return DPE_NONE;
       
   110 
       
   111 #if 0
       
   112 	// process each byte
       
   113 	for( i = 0; i < len; i++ ) {
       
   114 
       
   115 		// add the byte to the frame
       
   116 		ferr = iOutgoingFrame.AddByteToFrame( data[i] );
       
   117 
       
   118 		// if this overflows the buffer then we send whatever is in the frame and then add it again
       
   119 		if( ferr == FE_OVERFLOW ) {
       
   120 			frame_pointer = iOutgoingFrame.GetFrameBuffer( &frame_size );
       
   121 			derr = iAirInterface->SendPacket( frame_pointer, frame_size, &errcode );
       
   122 			if( derr != DPE_NONE ) {
       
   123 				iLog->WriteLogEntry( SV_WARNING, "CDatalinkPacketise::ProcessTEData", "SendPacket returned error", derr, errcode );
       
   124 			}
       
   125 			ferr = iOutgoingFrame.ClearFrameMemoryButNotState();
       
   126 			assert( ferr == FE_NONE );
       
   127 			ferr = iOutgoingFrame.AddByteToFrame( data[i] );
       
   128 			assert( ferr == FE_NONE );
       
   129 			continue;
       
   130 		}
       
   131 
       
   132 		// if the add was successful then check to see if the frame is complete and send it if it is
       
   133 		fstatus = iOutgoingFrame.GetFrameStatus();
       
   134 		if( fstatus == FS_COMPLETE ) {
       
   135 			frame_pointer = iOutgoingFrame.GetFrameBuffer( &frame_size );
       
   136 			derr = iAirInterface->SendPacket( frame_pointer, frame_size, &errcode );
       
   137 			if( derr != DPE_NONE ) {
       
   138 				iLog->WriteLogEntry( SV_WARNING, "CDatalinkPacketise::ProcessTEData", "SendPacket returned error", derr, errcode );
       
   139 			}
       
   140 			iOutgoingFrame.ClearFrame();
       
   141 		}
       
   142 	}
       
   143 #endif 
       
   144 	// done
       
   145 	return DPE_NONE;
       
   146 }
       
   147 
       
   148 
       
   149 /*******************************************************************************
       
   150  *
       
   151  * Process data from the UU interface
       
   152  *
       
   153  ******************************************************************************/
       
   154 TDataPathError CDatalinkPacketise::ProcessUUData( char *data, int len, int *aErrCode )
       
   155 {
       
   156 	int i, errcode;
       
   157 	int frame_size;
       
   158 	char *frame_pointer;
       
   159 	TFrameError ferr;
       
   160 	TFrameStatus fstatus;
       
   161 	TDataPathError derr = DPE_NONE;
       
   162 
       
   163 	// check the params
       
   164 	assert( aErrCode != NULL );
       
   165 	*aErrCode = 0;
       
   166 		
       
   167 	// check that there is an air interface - it is not unexpected or problematic if the
       
   168 	// channel is not defined so this is not an error.
       
   169 	if( iTEChannel == NULL ) {
       
   170 		return DPE_NONE;
       
   171 	}
       
   172 
       
   173 	// process each byte 
       
   174 	for( i = 0; i < len; i++ ) {
       
   175 
       
   176 		// add the byte to the frame
       
   177 		ferr = iIncomingFrame.AddByteToFrame( data[i] );
       
   178 
       
   179 		// if this overflows the buffer then we send whatever is in the frame and then add it again
       
   180 		if( ferr == FE_OVERFLOW ) {
       
   181 			frame_pointer = iIncomingFrame.GetFrameBuffer( &frame_size );
       
   182 			derr = iTEChannel->SendPacket( frame_pointer, frame_size, &errcode );
       
   183 			if( derr != DPE_NONE ) {
       
   184 				iLog->WriteLogEntry( SV_WARNING, "CDatalinkPacketise::ProcessTEData", "SendPacket returned error", derr, errcode );
       
   185 			}
       
   186 			ferr = iIncomingFrame.ClearFrameMemoryButNotState();
       
   187 			assert( ferr == FE_NONE );
       
   188 			ferr = iIncomingFrame.AddByteToFrame( data[i] );
       
   189 			assert( ferr == FE_NONE );
       
   190 			continue;
       
   191 		}
       
   192 
       
   193 		// get the frame status -- if the frame is complete then send it
       
   194 		fstatus = iIncomingFrame.GetFrameStatus();
       
   195 		if( fstatus == FS_COMPLETE ) {
       
   196 			frame_pointer = iIncomingFrame.GetFrameBuffer( &frame_size );
       
   197 			derr = iTEChannel->SendPacket( frame_pointer, frame_size, &errcode );
       
   198 			if( derr != DPE_NONE ) {
       
   199 				iLog->WriteLogEntry( SV_WARNING, "CDatalinkPacketise::ProcessUUData", "SendPacket returned an error", derr, errcode );
       
   200 			}
       
   201 			iIncomingFrame.ClearFrame();
       
   202 		}
       
   203 	}
       
   204 
       
   205 	// done
       
   206 	return DPE_NONE;
       
   207 }