|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 //////////////////////////////////////////////////////////////////////////////////////// |
|
22 // statserial.h |
|
23 // Serial transport class definition |
|
24 //////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
26 #ifndef STATSERIAL_H |
|
27 #define STATSERIAL_H |
|
28 |
|
29 #include "statcommon.h" |
|
30 #include "stattransport.h" |
|
31 |
|
32 // COM port settings |
|
33 // There is a problem with the use of ::ReadFile as this is a blocking |
|
34 // operation called in a critical section. If the call blocks for too |
|
35 // long and the user closes the thread then the section is lost for ever. |
|
36 // Reduce the timeouts to prevent the threads locking when there is |
|
37 // a link error. This is the wrong thing to do as we should really |
|
38 // update the reading to check the port first and query if data |
|
39 // is available. |
|
40 #define STAT_WRITETOTALTIMEOUTMULTIPLIER 0 |
|
41 #define STAT_WRITETOTALTIMEOUTCONSTANT 1000 |
|
42 #define STAT_READINTERVALTIMEOUT 0 |
|
43 #define STAT_READTOTALTIMEOUTMULTIPLIER 0 |
|
44 #if defined _DEBUG |
|
45 // In a release build wait a few seconds. |
|
46 // In a debug build wait for longer as we may be debugging and |
|
47 // pausing at break-points and generally slowing things up a bit. |
|
48 #define STAT_READTOTALTIMEOUTCONSTANT (10 * 1000) |
|
49 #else // defined _DEBUG |
|
50 #define STAT_READTOTALTIMEOUTCONSTANT 1000 |
|
51 #endif // defined _DEBUG |
|
52 |
|
53 #define STAT_BAUDRATE CBR_115200 |
|
54 #define STAT_BYTESIZE 8 |
|
55 #define STAT_PARITY NOPARITY |
|
56 #define STAT_STOPBITS ONESTOPBIT |
|
57 |
|
58 |
|
59 class CSTATSerial : public CSTATTransport |
|
60 { |
|
61 public: |
|
62 CSTATSerial(STATCONNECTTYPE eConnect); // Request that when this object |
|
63 // is created then it knows what |
|
64 // implementation of serial it is. |
|
65 // We could use sub-classes but there |
|
66 // is so little difference we handle |
|
67 // all serial transports as one case. |
|
68 // The only difference is in the packet |
|
69 // size which we store as an object |
|
70 // data field. |
|
71 ~CSTATSerial(); |
|
72 int Initialise(void); |
|
73 int Connect(const char *pAddress = NULL); |
|
74 int Send(const char cIdentifier, const char *pData = NULL, const unsigned long ulLength = 0); |
|
75 int Receive(char *cIdentifier, char **ppData = NULL, unsigned long *pLength = NULL); |
|
76 int Disconnect(void); |
|
77 int Release(void); |
|
78 unsigned int GetMaxPacketSize(void) const; // Override base class method |
|
79 // to specify that we have |
|
80 // a limit to the pakcet size |
|
81 // and the specific limit |
|
82 // depends upon the serial |
|
83 // transport we represent. |
|
84 |
|
85 private: |
|
86 bool OpenComPort(const char *pAddress); |
|
87 int ReceiveBytes( char *buff, unsigned long size ); |
|
88 |
|
89 HANDLE hComPort; // com port to work with |
|
90 unsigned long int iMaxPacketSize; |
|
91 // Holds the maximum size of the |
|
92 // packets we send. |
|
93 char *pBuffer; // Holds received data |
|
94 unsigned long int iBufferLength; |
|
95 // Holds the length of the receive data |
|
96 // buffer |
|
97 }; |
|
98 |
|
99 inline unsigned int CSTATSerial::GetMaxPacketSize(void) const |
|
100 { |
|
101 return (iMaxPacketSize); |
|
102 } |
|
103 |
|
104 #endif |