-
Notifications
You must be signed in to change notification settings - Fork 1
/
FakeSerial.cpp
86 lines (73 loc) · 3.08 KB
/
FakeSerial.cpp
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
/***************************************************************************
* Copyright (C) 2010 Alexey Aksenov, Alexx Fomichew *
* Alexey Aksenov (ezh at ezh.msk.ru) software, firmware *
* Alexx Fomichew (axx at fomichi.ru) hardware *
* *
* This file is part of ENikiBENiki *
* *
* ENikiBENiki is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* ENikiBENiki is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with ENikiBENiki. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include "FakeSerial.h"
#define new PNEW
FakeSerial::FakeSerial() : fakequeue(1000) {
fakequeue.SetReadTimeout(0); // timeout 0 ms
fakequeue.SetWriteTimeout(0); // timeout 0 ms
PThread::Create(PCREATE_NOTIFIER(HeatBeat), 30000,
PThread::NoAutoDeleteThread,
PThread::NormalPriority);
}
PBoolean FakeSerial::Read(void * buf, PINDEX len) {
bool result = fakequeue.Read(buf, len);
if (result) {
lastReadCount = fakequeue.GetLastReadCount();
} else {
lastReadCount = 0;
};
return result;
}
PBoolean FakeSerial::Write(const void * buf, PINDEX len) {
bool result = PFalse;
const BYTE *pbuf = (BYTE*)buf;
if (len == 3) {
BYTE expect = pbuf[0] + pbuf[1] + pbuf[2];
if (expect == 0) {
expect = 1;
};
result = fakequeue.Write(&expect, 1);
} else {
PError << "unknown message" << endl;
};
return result;
}
PINDEX FakeSerial::GetLastReadCount() const {
return lastReadCount;
};
PBoolean FakeSerial::Open(const PString & port, DWORD speed, BYTE data, Parity parity, BYTE stop, FlowControl inputFlow, FlowControl outputFlow) {
return PTrue;
};
PBoolean FakeSerial::Close() {
return PTrue;
};
void FakeSerial::SetReadTimeout(const PTimeInterval & time) {
};
void FakeSerial::SetWriteTimeout(const PTimeInterval & time) {
};
void FakeSerial::HeatBeat(PThread &, INT) {
char buf[2] = {0, 0};
for (;;) {
fakequeue.Write(buf, 2);
PThread::Sleep(1000);
};
}