|
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 // VirtualSerialComm1.cpp: implementation of the VirtualSerialComm class. |
|
18 // |
|
19 ////////////////////////////////////////////////////////////////////// |
|
20 |
|
21 #include "stdafx.h" |
|
22 #include "VirtualSerialComm.h" |
|
23 |
|
24 ////////////////////////////////////////////////////////////////////// |
|
25 // Construction/Destruction |
|
26 ////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 VirtualSerialComm::VirtualSerialComm() |
|
29 { |
|
30 #ifdef _DEBUG |
|
31 if (gDoLogging) |
|
32 { |
|
33 FILE* f = fopen("c:\\tcf\\vscommlog.txt", "at"); |
|
34 fprintf(f, "VirtualSerialComm::VirtualSerialComm() (default constructor)\n"); |
|
35 fclose(f); |
|
36 } |
|
37 #endif |
|
38 } |
|
39 VirtualSerialComm::VirtualSerialComm(ConnectData* connectSettings, DWORD connectionId, CBaseProtocol* protocol) |
|
40 { |
|
41 #ifdef _DEBUG |
|
42 if (gDoLogging) |
|
43 { |
|
44 FILE* f = fopen("c:\\tcf\\vscommlog.txt", "at"); |
|
45 fprintf(f, "connectSettings=%x connectionId=%d, protocol=%x\n", connectSettings, connectionId, protocol); |
|
46 fprintf(f, "connectSettings->comPort=%s\n", connectSettings->virtualSerialSettings.comPort); |
|
47 fclose(f); |
|
48 } |
|
49 #endif |
|
50 m_connId = connectionId; |
|
51 m_Protocol = protocol; |
|
52 |
|
53 m_ConnectSettings = new ConnectData(); |
|
54 memcpy(m_ConnectSettings, connectSettings, sizeof(ConnectData)); |
|
55 |
|
56 #if (defined(LOG_COMM) || defined(LOG_PROCCOMM)) && defined(_DEBUG) |
|
57 if (gDoLogging) |
|
58 { |
|
59 m_CommDebugLog = new TCDebugLog("TCF_Comm", connectionId, 2000L); |
|
60 m_ProcDebugLog = new TCDebugLog("TCF_CommP", connectionId, 2000L); |
|
61 } |
|
62 #endif |
|
63 pRealSerialConnectData pR = &m_ConnectSettings->realSerialSettings; |
|
64 pVirtualSerialConnectData pV = &m_ConnectSettings->virtualSerialSettings; |
|
65 |
|
66 // copy com port to real settings |
|
67 strcpy(pR->comPort, pV->comPort); |
|
68 |
|
69 // fill in real setting defaults |
|
70 pR->baudRate = 115200; |
|
71 pR->dataBits = 8; |
|
72 pR->flowControl = eFlowControlNone; |
|
73 pR->parity = eParityNone; |
|
74 pR->stopBits = eStopBits1; |
|
75 } |
|
76 |
|
77 VirtualSerialComm::~VirtualSerialComm() |
|
78 { |
|
79 #ifdef _DEBUG |
|
80 if (gDoLogging) |
|
81 { |
|
82 FILE* f = fopen("c:\\tcf\\vscommlog.txt", "at"); |
|
83 fprintf(f, "VirtualSerialComm::~VirtualSerialComm()\n"); |
|
84 fclose(f); |
|
85 } |
|
86 #endif |
|
87 } |
|
88 bool VirtualSerialComm::IsConnectionEqual(ConnectData* pConn) |
|
89 { |
|
90 bool equal = false; |
|
91 |
|
92 // forms accepted: |
|
93 // "comNN", "NN" |
|
94 char* ptr1 = m_ConnectSettings->virtualSerialSettings.comPort; |
|
95 char* ptr2 = pConn->virtualSerialSettings.comPort; |
|
96 bool digit1found = false; |
|
97 while(!digit1found && *ptr1 != NULL) |
|
98 { |
|
99 if (*ptr1 >= '0' && *ptr1 <= '9') |
|
100 { |
|
101 digit1found = true; |
|
102 break; |
|
103 } |
|
104 ptr1++; |
|
105 } |
|
106 bool digit2found = false; |
|
107 while(!digit2found && *ptr2 != NULL) |
|
108 { |
|
109 if (*ptr2 >= '0' && *ptr2 <= '9') |
|
110 { |
|
111 digit2found = true; |
|
112 break; |
|
113 } |
|
114 ptr2++; |
|
115 } |
|
116 if (digit1found && digit2found) |
|
117 { |
|
118 if (strcmp(ptr1, ptr2) == 0) |
|
119 equal = true; |
|
120 } |
|
121 return equal; |
|
122 } |
|
123 |