-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBMPlatform.h
More file actions
406 lines (372 loc) · 14.5 KB
/
BMPlatform.h
File metadata and controls
406 lines (372 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#pragma once
#include <Windows.h>
#include <tchar.h>
#define INVALID_VALUE ((DWORD)-1)
#define INFINITE_LOGFILE_SIZE ( 0 )
typedef enum
{
SPLOGLV_NONE = 0,
SPLOGLV_ERROR = 1,
SPLOGLV_WARN = 2,
SPLOGLV_INFO = 3,
SPLOGLV_DATA = 4, //exclusive, only output data
SPLOGLV_VERBOSE = 5
}SPLOG_LEVEL;
enum
{
LOG_READ = 0,
LOG_WRITE = 1,
LOG_ASYNC_READ = 2
};
class ISpLog
{
public:
enum OpenFlags
{
modeTimeSuffix = 0x0001, // Append time suffix to a file, like: xxx_2009_06_01_12_39_50.log
modeDateSuffix = 0x0002, // Append date suffix to a file, like: xxx_2009_06_12.log
modeCreate = 0x1000, // Directs the constructor to create a new file.
// If the file exists already, it is truncated to 0 length.
modeNoTruncate = 0x2000, // Combine this value with modeCreate.
// If the file being created already exists, it is not truncated to 0 length.
typeText = 0x4000, // Sets text mode. Default file extension is *.log
typeBinary = (int)0x8000, // Sets binary mode. Default file extension is *.bin
// typeBinary only --------- [
modeBinNone = 0x0000, // Log none bin data
modeBinRead = 0x0100, // Log read bin data
modeBinWrite = 0x0200, // Log write bin data
modeBinReadWrite = 0x0300, // Log read & Write bin data
// ------------------------]
defaultTextFlag = modeCreate | modeDateSuffix | typeText,
defaultBinaryFlag = modeCreate | modeDateSuffix | typeBinary | modeBinRead,
defaultDualFlag = modeCreate | modeDateSuffix | typeText | typeBinary | modeBinRead
};
virtual ~ISpLog(void) { };
// ----------------------------------------------------------------------------
// Open
// Open log file
//
// Parameter
// lpszLogPath : A string that is the path to the desired file. The path can be relative or absolute.
// There is a default string size limit of _MAX_PATH characters
// uFlags : Specifies the action to take when opening the file.
// You can combine options listed below by using the bitwise-OR (|) operator.
// See the ILog::OpenFlags enum for a list of mode options.
// uLogLevel : Specifies the log level. Only available for 'typeText'. see SPLOG_LEVEL.
// uMaxFileSizeInMB : Max. log file size in unit of MB. Note: 0, infinite file size.
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL Open(LPCTSTR lpszLogPath,
UINT uFlags = ISpLog::defaultTextFlag,
UINT uLogLevel = SPLOGLV_INFO,
UINT uMaxFileSizeInMB = INFINITE_LOGFILE_SIZE
) = 0;
// ----------------------------------------------------------------------------
// Close
// Close log file
//
// Parameter
// None.
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL Close(void) = 0;
// ----------------------------------------------------------------------------
// Release
// Delete object
//
// Parameter
// None.
//
// Return
// None.
//
// Remarks
// None
virtual void Release(void) = 0;
// ----------------------------------------------------------------------------
// LogHexData
// Log binary data.
// Example : 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00
// B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00
// uFlag : LOG_READ , specifies that the 'pHexData' is 'read data'.
// LOG_WRITE, specifies that the 'pHexData' is 'write data'.
//
// Parameter
// pHexData : Binary data.
// dwHexSize : The number of bytes to write to the log file.
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL LogHexData(const BYTE* pHexData, DWORD dwHexSize, UINT uFlag = LOG_READ) = 0;
// ----------------------------------------------------------------------------
// LogRawStrA (ANSI)
// LogRawStrW (UNICODE)
// Log a string.
// Example: [2009-06-04 16:54:47:500] This is a test.
//
// Parameter
// uLogLevel : Specifies the level of the 'lpszString'.
// lpszString : A string to write to log file.
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL LogRawStrA(UINT uLogLevel, LPCSTR lpszString) = 0;
virtual BOOL LogRawStrW(UINT uLogLevel, LPCWSTR lpszString) = 0;
// ----------------------------------------------------------------------------
// LogFmtStrA (ANSI)
// LogFmtStrW (UNICODE)
// Log a formatted string.
//
// Parameter
// uLogLevel : Specifies the level of the 'lpszString'.
// lpszFmt : Format control.
// argument: Optional arguments.
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL LogFmtStrA(UINT uLogLevel, LPCSTR lpszFmt, ...) = 0;
virtual BOOL LogFmtStrW(UINT uLogLevel, LPCWSTR lpszFmt, ...) = 0;
// ----------------------------------------------------------------------------
// LogBufData
// Log a buffer. Example :
// [2009-06-04 16:54:47:500] --> 114756(0x0001c044) Bytes
// 00000000h: 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 ; MZ..............
// 00000010h: B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ; ........@.......
// 00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
//
// Parameter
// uLogLevel: Specifies the level of the 'pBufData'
// pBufData : A buffer to write to log file.
// dwBufSize: The number of bytes of the buffer.
// uFlag : LOG_WRITE specifies '-->'
// LOG_READ specifies '<--'
// LOG_ASYNC_READ specifies '<<-'
// pUserNeedSize: this size is that user want to Read/Write buffer size
// use this parameter user can see the different between real Read/Write size (dwBufSize)
// and expired size (*pUserNeedSize)
// if this point is not null,log will like bellow
// [2009-06-04 16:54:47:0500] --> 114756(0x0001c044)/114757(0x0001c045) Bytes
//
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL LogBufData(UINT uLogLevel, const BYTE* pBufData, DWORD dwBufSize, UINT uFlag = LOG_WRITE, const DWORD* pUserNeedSize = NULL) = 0;
// ----------------------------------------------------------------------------
// SetProperty/GetProperty
// Set/Get property
// Parameter
// lAttr : Attributes, see enum LOG_ATTRIBUTE.
// lFlags :
// lpValue : Values to be set/get.
//
// Return
// If the function succeeds, the return value is nonzero.
// If the function fails, the return value is zero.
//
// Remarks
// None
virtual BOOL SetProperty(LONG lAttr, LONG lFlags, LPCVOID lpValue) = 0;
virtual BOOL GetProperty(LONG lAttr, LONG lFlags, LPVOID lpValue) = 0;
};
enum CHANNEL_TYPE
{
CHANNEL_TYPE_COM = 0,
CHANNEL_TYPE_SOCKET = 1,
CHANNEL_TYPE_FILE = 2,
CHANNEL_TYPE_USBMON = 3 // USB monitor
};
typedef struct _CHANNEL_ATTRIBUTE
{
CHANNEL_TYPE ChannelType;
union {
// ComPort
struct {
DWORD dwPortNum;
DWORD dwBaudRate;
} Com;
// Socket
struct {
DWORD dwPort;
DWORD dwIP;
DWORD dwFlag; //[in]: 0, Server; 1, Client; [out]: client ID.
} Socket;
// File
struct {
DWORD dwPackSize;
DWORD dwPackFreq;
WCHAR* pFilePath;
} File;
};
} CHANNEL_ATTRIBUTE, * PCHANNEL_ATTRIBUTE;
typedef const PCHANNEL_ATTRIBUTE PCCHANNEL_ATTRIBUTE;
class ICommChannel
{
public:
virtual~ICommChannel() = 0;
/**
* InitLog
* @param [in] pszLogName: log file name, if it is NULL or _T(""), program will set default
* @param [in] uiLogType : log format type
* @param [in] uiLogLevel: see LOG_LEVEL enum
* @param [in] pLogUtil : set the sub-class pointer of CLogUtil, to do special log content
* @param [in] pszBinLogFileExt: binary log file extension, if you set uiLogType both text
* and binary,and want to change the binary log file extension,you must
* set this param, otherwise ".bin" extension is set default.
*
* @return: TRUE if init success, FALSE otherwise
*
* @remarks: this method need not be called before Open always, because program will auto to
* log information by configure file settings. "ChannelConfig.ini"
*/
virtual BOOL InitLog(LPCWSTR pszLogName, UINT uiLogType,
UINT uiLogLevel = INVALID_VALUE, ISpLog* pLogUtil = NULL,
LPCWSTR pszBinLogFileExt = NULL) = 0;
/**
* Set receiver for reading data with async way
* @param [in] ulMsgId : message ID
* @param [in] bRcvThread : TRUE, received by thread, FALSE, by window
* @param [in] pReceiver : receiver based on bRcvThread
*
* @return TRUE if set success, FALSE otherwise
*
* @remarks: if you call this method after Open, and you set pReceiver to NULL,it will stop
* auto-read thread. if set pReceiver to not NULL, and not call this method before
* Open, this will start auto-read thread.
*/
virtual BOOL SetReceiver(ULONG ulMsgId,
BOOL bRcvThread,
LPCVOID pReceiver) = 0;
/**
* Get receiver
* @param [out] ulMsgId : message ID
* @param [out] bRcvThread : TRUE, received by thread, FALSE, by window
* @param [out] pReceiver : receiver based on bRcvThread
*
* @return void
*/
virtual void GetReceiver(ULONG& ulMsgId,
BOOL& bRcvThread,
LPVOID& pReceiver) = 0;
/**
* Open channel
* @param [in] pOpenArgument : channel parameters
*
* @return TRUE if open success, FALSE otherwise
*/
virtual BOOL Open(PCCHANNEL_ATTRIBUTE pOpenArgument) = 0;
/**
* Close channel
*
* @return void
*/
virtual void Close() = 0;
/**
* clear channel in&out data buffer
*
* @return TRUE if clear success, FALSE otherwise
*/
virtual BOOL Clear() = 0;
/**
* Read data from channel with sync way
* @param [out] lpData : store read data
* @param [in] dwDataSize : lpData allocated size by outside
* @param [in] dwTimeOut : time out
* @param [in] dwReserved : reserved, for UART;
* low word is client ID, high word is reserved for server socket
*
* @return real read data size
*/
virtual DWORD Read(LPVOID lpData, DWORD dwDataSize,
DWORD dwTimeOut, DWORD dwReserved = 0) = 0;
/**
* Write data to channel
* @param [in] lpData : store writing data
* @param [in] dwDataSize : lpData allocated size by outside
* @param [in] dwReserved : reserved, for UART;
* low word is client ID, high word is reserved for server socket
*
* @return real written data size
*/
virtual DWORD Write(LPVOID lpData, DWORD dwDataSize, DWORD dwReserved = 0) = 0;
/**
* Free memory allocated by program, only used after async read data
* @param [in] pMemBlock : memory pointer
*
* @return void
*/
virtual void FreeMem(LPVOID pMemBlock) = 0;
/**
* Get property of this program
* @param [in] lFlags : reserved
* @param [in] dwPropertyID: property name
* @param [out] pValue : property value pointer
*
* @return TRUE if get success, FALSE otherwise
*/
virtual BOOL GetProperty(LONG lFlags, DWORD dwPropertyID,
LPVOID pValue) = 0;
/**
* Get property of this program
* @param [in] lFlags : reserved
* @param [in] dwPropertyID: property name
* @param [in] pValue : property value pointer
*
* @return TRUE if set success, FALSE otherwise
*/
virtual BOOL SetProperty(LONG lFlags, DWORD dwPropertyID,
LPCVOID pValue) = 0;
};
typedef BOOL (*pfCreateChannel)( ICommChannel ** , CHANNEL_TYPE);
typedef void (*pfReleaseChannel)( ICommChannel *);
class CBMPlatformApp
{
public:
CBMPlatformApp();
pfCreateChannel m_pfCreateChannel;
pfReleaseChannel m_pfReleaseChannel;
HMODULE m_hChannelLib;
BOOL InitInstance();
int ExitInstance();
};
class CBootModeOpr
{
public:
CBootModeOpr();
~CBootModeOpr();
BOOL Initialize();
void Uninitialize();
int Read(UCHAR* m_RecvData, int max_len, int dwTimeout);
int Write(UCHAR* lpData, int iDataSize);
BOOL ConnectChannel(DWORD dwPort);
BOOL DisconnectChannel();
BOOL GetProperty(LONG lFlags, DWORD dwPropertyID, LPVOID pValue);
BOOL SetProperty(LONG lFlags, DWORD dwPropertyID, LPCVOID pValue);
private:
ICommChannel* m_pChannel;
};