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
|
/***************************************************************************
* Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "port_base.h"
#include "common/global/global.h"
#include "common/common/misc.h"
#include "common/common/number.h"
bool Port::Base::open()
{
close();
resetError();
_closing = false;
return internalOpen();
}
void Port::Base::close()
{
_closing = true;
internalClose();
}
bool Port::Base::send(const char *data, uint size, uint timeout)
{
log(Log::DebugLevel::LowLevel, TQString("Sending: \"%1\"").tqarg(toPrintable(data, size, PrintAlphaNum)));
return internalSend(data, size, timeout);
}
bool Port::Base::receive(uint size, TQString &s, uint timeout)
{
TQMemArray<uchar> a;
if ( !receive(size, a, timeout) ) return false;
s.fill(0, size);
for (uint i=0; i<size; i++) s[i] = a[i];
return true;
}
bool Port::Base::receive(uint size, TQMemArray<uchar> &a, uint timeout)
{
a.resize(size);
bool ok = internalReceive(size, (char *)a.data(), timeout);
if (ok) log(Log::DebugLevel::LowLevel, TQString("Received: \"%1\"").tqarg(toPrintable(a, PrintAlphaNum)));
return ok;
}
bool Port::Base::receiveChar(char &c, uint timeout)
{
if ( !internalReceive(1, &c, timeout) ) return false;
log(Log::DebugLevel::LowLevel, TQString("Received: \"%1\"").tqarg(toPrintable(c, PrintAlphaNum)));
return true;
}
bool Port::Base::setPinOn(uint, bool, LogicType)
{
qFatal("setPinOn not implemented");
return false;
}
bool Port::Base::readPin(uint, LogicType, bool &)
{
qFatal("readPin not implemented");
return 0;
}
TQValueVector<Port::PinData> Port::Base::pinData(IODir) const
{
qFatal("pinData not implemented");
return TQValueVector<PinData>();
}
bool Port::Base::isGroundPin(uint) const
{
qFatal("isGroundPin not implemented");
return false;
}
uint Port::Base::groundPin() const
{
qFatal("groundPin not implemented");
return 0;
}
Port::IODir Port::Base::ioDir(uint) const
{
qFatal("ioType not implemented");
return NoIO;
}
void Port::Base::log(Log::LineType lineType, const TQString &message)
{
if ( lineType==Log::LineType::Error && _closing ) return;
Log::Base::log(lineType, description().type.label() + ": " + message);
if ( lineType==Log::LineType::Error ) close();
}
void Port::Base::log(Log::DebugLevel level, const TQString &message)
{
Log::Base::log(level, description().type.label() + ": " + message);
}
void Port::Base::logData(const TQString &)
{
/*
TQString vs;
for (uint i=0; i<s.length(); i++) {
char c = s[i];
switch (c) {
case '\r': vs += "\\r"; break;
case '\n': vs += "\\n"; break;
case '<': vs += "<"; break;
case '>': vs += ">"; break;
default: {
if ( c>=32 && c<=126 ) vs += c;
else {
TQString tmp;
tmp.sprintf("\\x%02x", c);
vs += tmp;
}
break;
}
}
}
qDebug("%s", vs.latin1());
*/
//log(Log::Debug, vs);
}
|