author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 2 |
// All rights reserved. |
sl@0 | 3 |
// This component and the accompanying materials are made available |
sl@0 | 4 |
// under the terms of "Eclipse Public License v1.0" |
sl@0 | 5 |
// which accompanies this distribution, and is available |
sl@0 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 7 |
// |
sl@0 | 8 |
// Initial Contributors: |
sl@0 | 9 |
// Nokia Corporation - initial contribution. |
sl@0 | 10 |
// |
sl@0 | 11 |
// Contributors: |
sl@0 | 12 |
// |
sl@0 | 13 |
// Description: |
sl@0 | 14 |
// |
sl@0 | 15 |
|
sl@0 | 16 |
#include <e32std.h> |
sl@0 | 17 |
#include <ecom/implementationproxy.h> |
sl@0 | 18 |
|
sl@0 | 19 |
#include "uloggerserialplugin.h" |
sl@0 | 20 |
|
sl@0 | 21 |
#if defined(__LIGHTLOGGER_ENABLED) |
sl@0 | 22 |
#include "lightlogger.h" |
sl@0 | 23 |
#endif |
sl@0 | 24 |
|
sl@0 | 25 |
namespace Ulogger |
sl@0 | 26 |
{ |
sl@0 | 27 |
|
sl@0 | 28 |
#if defined (__WINS__) |
sl@0 | 29 |
_LIT(KPddDev, "ECDRV.PDD"); |
sl@0 | 30 |
#else |
sl@0 | 31 |
_LIT(KPddDev, "EUART1"); |
sl@0 | 32 |
#endif |
sl@0 | 33 |
|
sl@0 | 34 |
#if defined (__WINS__) |
sl@0 | 35 |
_LIT(KLddDev, "ECOMM.LDD"); |
sl@0 | 36 |
#else |
sl@0 | 37 |
_LIT(KLddDev, "ECOMM"); |
sl@0 | 38 |
#endif |
sl@0 | 39 |
|
sl@0 | 40 |
//settings for serial output plugin |
sl@0 | 41 |
_LIT(KPortNumber, "output_port"); |
sl@0 | 42 |
|
sl@0 | 43 |
/** |
sl@0 | 44 |
Creates an instance of CSerialWriter object |
sl@0 | 45 |
@return a pointer to the new created CSerialWriter Object |
sl@0 | 46 |
@leave KErrNoMemory if no memory |
sl@0 | 47 |
*/ |
sl@0 | 48 |
CSerialWriter* CSerialWriter::NewL() |
sl@0 | 49 |
{ |
sl@0 | 50 |
CSerialWriter *me = new (ELeave) CSerialWriter; |
sl@0 | 51 |
CleanupStack::PushL(me); |
sl@0 | 52 |
me->ConstructL(); |
sl@0 | 53 |
CleanupStack::Pop(); |
sl@0 | 54 |
return me; |
sl@0 | 55 |
} |
sl@0 | 56 |
|
sl@0 | 57 |
/** |
sl@0 | 58 |
Public Destructor |
sl@0 | 59 |
*/ |
sl@0 | 60 |
CSerialWriter::~CSerialWriter() |
sl@0 | 61 |
{ |
sl@0 | 62 |
Disconnect(); |
sl@0 | 63 |
} |
sl@0 | 64 |
|
sl@0 | 65 |
//default constructor |
sl@0 | 66 |
CSerialWriter::CSerialWriter() |
sl@0 | 67 |
{ |
sl@0 | 68 |
} |
sl@0 | 69 |
|
sl@0 | 70 |
void CSerialWriter::ConstructL() |
sl@0 | 71 |
{ |
sl@0 | 72 |
iReady = EFalse; |
sl@0 | 73 |
|
sl@0 | 74 |
TInt err = User::LoadPhysicalDevice(KPddDev); |
sl@0 | 75 |
if(err!=KErrNone && err!=KErrAlreadyExists) |
sl@0 | 76 |
User::Leave(err); |
sl@0 | 77 |
|
sl@0 | 78 |
err = User::LoadLogicalDevice(KLddDev); |
sl@0 | 79 |
if(err!=KErrNone && err!=KErrAlreadyExists) |
sl@0 | 80 |
User::Leave(err); |
sl@0 | 81 |
} |
sl@0 | 82 |
|
sl@0 | 83 |
void CSerialWriter::CloseOutputPlugin() |
sl@0 | 84 |
{ |
sl@0 | 85 |
Disconnect(); |
sl@0 | 86 |
} |
sl@0 | 87 |
|
sl@0 | 88 |
TInt CSerialWriter::ConfigureOutputPlugin(const RPointerArray<TPluginConfiguration>& aSettings) |
sl@0 | 89 |
{ |
sl@0 | 90 |
TInt i = aSettings.Count(); |
sl@0 | 91 |
while(i-->0) |
sl@0 | 92 |
{ |
sl@0 | 93 |
TPluginConfiguration* key = aSettings[i]; |
sl@0 | 94 |
|
sl@0 | 95 |
if(key->Key().Compare(KPortNumber) == 0) |
sl@0 | 96 |
{ |
sl@0 | 97 |
TLex lex(key->Value()); |
sl@0 | 98 |
lex.Val(iPortNum); |
sl@0 | 99 |
} |
sl@0 | 100 |
} |
sl@0 | 101 |
|
sl@0 | 102 |
Disconnect(); |
sl@0 | 103 |
TInt err = Connect(); |
sl@0 | 104 |
if(err != KErrNone) |
sl@0 | 105 |
return err; |
sl@0 | 106 |
err = Config(); |
sl@0 | 107 |
|
sl@0 | 108 |
return KErrNone; |
sl@0 | 109 |
} |
sl@0 | 110 |
|
sl@0 | 111 |
TInt CSerialWriter::Connect() |
sl@0 | 112 |
{ |
sl@0 | 113 |
if(!iReady) |
sl@0 | 114 |
{ |
sl@0 | 115 |
TInt err = KErrNone; |
sl@0 | 116 |
err = iComm.Open(iPortNum); |
sl@0 | 117 |
if(err!=KErrNone) |
sl@0 | 118 |
{ |
sl@0 | 119 |
iReady = EFalse; |
sl@0 | 120 |
return err; |
sl@0 | 121 |
} |
sl@0 | 122 |
else |
sl@0 | 123 |
iReady = ETrue; |
sl@0 | 124 |
} |
sl@0 | 125 |
return KErrNone; |
sl@0 | 126 |
} |
sl@0 | 127 |
|
sl@0 | 128 |
TInt CSerialWriter::Config() |
sl@0 | 129 |
{ |
sl@0 | 130 |
TInt err = KErrNone; |
sl@0 | 131 |
if(iReady) |
sl@0 | 132 |
{ |
sl@0 | 133 |
TCommConfig2 cfgBuf; |
sl@0 | 134 |
TCommConfigV02& cfg = cfgBuf(); |
sl@0 | 135 |
iComm.Config(cfgBuf); |
sl@0 | 136 |
cfg.iRate = EBps115200;// default EBps9600; |
sl@0 | 137 |
cfg.iDataBits = EData8;// default EData8; |
sl@0 | 138 |
cfg.iStopBits = EStop1;// default EStop1; |
sl@0 | 139 |
cfg.iParity = EParityNone;// default EParityNone; |
sl@0 | 140 |
cfg.iHandshake = 0;// default KConfigObeyCTS; |
sl@0 | 141 |
cfg.iParityError = KConfigParityErrorFail; |
sl@0 | 142 |
cfg.iFifo = EFifoEnable;// default EFifoEnable; |
sl@0 | 143 |
cfg.iSpecialRate = 0;// default 0; |
sl@0 | 144 |
cfg.iTerminatorCount = 0;// default 0; |
sl@0 | 145 |
cfg.iXonChar = 0x11;// default 0x11; // XON |
sl@0 | 146 |
cfg.iXoffChar = 0x13;// default 0x13; // XOFF |
sl@0 | 147 |
cfg.iParityErrorChar = 0;// default 0; |
sl@0 | 148 |
cfg.iSIREnable = ESIRDisable;// default ESIRDisable; |
sl@0 | 149 |
cfg.iSIRSettings = 0;// no default |
sl@0 | 150 |
|
sl@0 | 151 |
err = iComm.SetConfig(cfgBuf); |
sl@0 | 152 |
if(err!=KErrNone && err!=KErrInUse) |
sl@0 | 153 |
{ |
sl@0 | 154 |
iReady = EFalse; |
sl@0 | 155 |
return(err); |
sl@0 | 156 |
} |
sl@0 | 157 |
} |
sl@0 | 158 |
|
sl@0 | 159 |
return err; |
sl@0 | 160 |
} |
sl@0 | 161 |
|
sl@0 | 162 |
TInt CSerialWriter::Disconnect() |
sl@0 | 163 |
{ |
sl@0 | 164 |
if(iReady) |
sl@0 | 165 |
{ |
sl@0 | 166 |
iReady = EFalse; |
sl@0 | 167 |
iComm.Close(); |
sl@0 | 168 |
} |
sl@0 | 169 |
return KErrNone; |
sl@0 | 170 |
} |
sl@0 | 171 |
|
sl@0 | 172 |
TInt CSerialWriter::Write(const TDesC8& aData) |
sl@0 | 173 |
{ |
sl@0 | 174 |
TInt err = KErrNone; |
sl@0 | 175 |
|
sl@0 | 176 |
if(iReady) |
sl@0 | 177 |
{ |
sl@0 | 178 |
TRequestStatus writeStatus; |
sl@0 | 179 |
iComm.Write(writeStatus, aData); |
sl@0 | 180 |
User::WaitForRequest(writeStatus); |
sl@0 | 181 |
err = writeStatus.Int(); |
sl@0 | 182 |
} |
sl@0 | 183 |
|
sl@0 | 184 |
return err; |
sl@0 | 185 |
} |
sl@0 | 186 |
|
sl@0 | 187 |
|
sl@0 | 188 |
TAny* CSerialWriter::GetInterfaceL(TPluginInterface aInterfaceId) |
sl@0 | 189 |
{ |
sl@0 | 190 |
if(aInterfaceId == MOutputPlugin::iInterfaceId) |
sl@0 | 191 |
return static_cast<MOutputPlugin*>(this); |
sl@0 | 192 |
else |
sl@0 | 193 |
return NULL; |
sl@0 | 194 |
} |
sl@0 | 195 |
|
sl@0 | 196 |
} // namespace |
sl@0 | 197 |
|
sl@0 | 198 |
|
sl@0 | 199 |
//Ecom Implementations |
sl@0 | 200 |
// Map the interface implementation UIDs to implementation factory functions |
sl@0 | 201 |
const TImplementationProxy ImplementationTable[] = |
sl@0 | 202 |
{ |
sl@0 | 203 |
IMPLEMENTATION_PROXY_ENTRY(0x102836CB, Ulogger::CSerialWriter::NewL) |
sl@0 | 204 |
}; |
sl@0 | 205 |
|
sl@0 | 206 |
|
sl@0 | 207 |
// Exported proxy for instantiation method resolution. |
sl@0 | 208 |
EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
sl@0 | 209 |
TInt& aTableCount) |
sl@0 | 210 |
{ |
sl@0 | 211 |
aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
sl@0 | 212 |
return ImplementationTable; |
sl@0 | 213 |
} |
sl@0 | 214 |