Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
934c8a7d
Commit
934c8a7d
authored
Jan 25, 2011
by
lm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed support for CRLF and other special symbol handling
parent
5dcdc1ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
32 deletions
+109
-32
DebugConsole.cc
src/ui/DebugConsole.cc
+105
-26
DebugConsole.h
src/ui/DebugConsole.h
+3
-0
DebugConsole.ui
src/ui/DebugConsole.ui
+1
-6
No files found.
src/ui/DebugConsole.cc
View file @
934c8a7d
...
...
@@ -113,6 +113,8 @@ DebugConsole::DebugConsole(QWidget *parent) :
connect
(
m_ui
->
addSymbolButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
appendSpecialSymbol
()));
// Connect Checkbox
connect
(
m_ui
->
specialComboBox
,
SIGNAL
(
highlighted
(
QString
)),
this
,
SLOT
(
specialSymbolSelected
(
QString
)));
// Set add button invisible if auto add checkbox is checked
connect
(
m_ui
->
specialCheckBox
,
SIGNAL
(
clicked
(
bool
)),
m_ui
->
addSymbolButton
,
SLOT
(
setHidden
(
bool
)));
hold
(
false
);
...
...
@@ -341,46 +343,92 @@ void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes)
QByteArray
DebugConsole
::
symbolNameToBytes
(
const
QString
&
text
)
{
QByteArray
b
;
if
(
text
==
"LF"
)
if
(
text
.
contains
(
"CR+LF"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x0D
));
b
.
append
(
static_cast
<
char
>
(
0x0A
));
}
else
if
(
text
==
"FF"
)
else
if
(
text
.
contains
(
"LF"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x0
C
));
b
.
append
(
static_cast
<
char
>
(
0x0
A
));
}
else
if
(
text
==
"CR"
)
else
if
(
text
.
contains
(
"FF"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x0
D
));
b
.
append
(
static_cast
<
char
>
(
0x0
C
));
}
else
if
(
text
==
"CR+LF"
)
else
if
(
text
.
contains
(
"CR"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x0D
));
b
.
append
(
static_cast
<
char
>
(
0x0A
));
}
else
if
(
text
==
"TAB"
)
else
if
(
text
.
contains
(
"TAB"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x09
));
}
else
if
(
text
==
"NUL"
)
else
if
(
text
.
contains
(
"NUL"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x00
));
}
else
if
(
text
==
"ESC"
)
else
if
(
text
.
contains
(
"ESC"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x1B
));
}
else
if
(
text
==
"~"
)
else
if
(
text
.
contains
(
"~"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x7E
));
}
else
if
(
text
==
"<Space>"
)
else
if
(
text
.
contains
(
"<Space>"
)
)
{
b
.
append
(
static_cast
<
char
>
(
0x20
));
}
return
b
;
}
QString
DebugConsole
::
bytesToSymbolNames
(
const
QByteArray
&
b
)
{
QString
text
;
if
(
b
.
size
()
>
1
&&
b
.
contains
(
0x0D
)
&&
b
.
contains
(
0x0A
))
{
text
=
"<CR+LF>"
;
}
else
if
(
b
.
contains
(
0x0A
))
{
text
=
"<LF>"
;
}
else
if
(
b
.
contains
(
0x0C
))
{
text
=
"<FF>"
;
}
else
if
(
b
.
contains
(
0x0D
))
{
text
=
"<CR>"
;
}
else
if
(
b
.
contains
(
0x09
))
{
text
=
"<TAB>"
;
}
else
if
(
b
.
contains
((
char
)
0x00
))
{
text
==
"<NUL>"
;
}
else
if
(
b
.
contains
(
0x1B
))
{
text
=
"<ESC>"
;
}
else
if
(
b
.
contains
(
0x7E
))
{
text
=
"<~>"
;
}
else
if
(
b
.
contains
(
0x20
))
{
text
=
"<Space>"
;
}
else
{
text
.
append
(
b
);
}
return
text
;
}
void
DebugConsole
::
specialSymbolSelected
(
const
QString
&
text
)
{
Q_UNUSED
(
text
);
...
...
@@ -426,10 +474,27 @@ void DebugConsole::sendBytes()
return
;
}
QString
transmitUnconverted
=
m_ui
->
sendText
->
text
();
QByteArray
specialSymbol
;
// Append special symbol if checkbox is checked
if
(
m_ui
->
specialCheckBox
->
isChecked
())
{
appendSpecialSymbol
(
m_ui
->
specialComboBox
->
currentText
());
// Get auto-add special symbols
specialSymbol
=
symbolNameToBytes
(
m_ui
->
specialComboBox
->
currentText
());
// Convert them if needed
if
(
!
convertToAscii
)
{
QString
specialSymbolConverted
;
for
(
int
i
=
0
;
i
<
specialSymbol
.
length
();
i
++
)
{
QString
add
(
" 0x%1"
);
specialSymbolConverted
.
append
(
add
.
arg
(
static_cast
<
char
>
(
specialSymbol
.
at
(
i
)),
2
,
16
,
QChar
(
'0'
)));
}
specialSymbol
.
clear
();
specialSymbol
.
append
(
specialSymbolConverted
);
}
}
QByteArray
transmit
;
...
...
@@ -438,13 +503,27 @@ void DebugConsole::sendBytes()
if
(
convertToAscii
)
{
// ASCII text is not converted
transmit
=
m_ui
->
sendText
->
text
().
toLatin1
();
feedback
=
transmit
;
transmit
=
transmitUnconverted
.
toLatin1
();
// Auto-add special symbol handling
transmit
.
append
(
specialSymbol
);
QString
translated
;
// Replace every occurence of a special symbol with its text name
for
(
int
i
=
0
;
i
<
transmit
.
size
();
++
i
)
{
QByteArray
specialChar
;
specialChar
.
append
(
transmit
.
at
(
i
));
translated
.
append
(
bytesToSymbolNames
(
specialChar
));
}
feedback
.
append
(
translated
);
}
else
{
// HEX symbols are converted to bytes
QString
str
=
m_ui
->
sendText
->
text
().
toLatin1
();
QString
str
=
transmitUnconverted
.
toLatin1
();
str
.
append
(
specialSymbol
);
str
.
remove
(
' '
);
str
.
remove
(
"0x"
);
str
.
simplified
();
...
...
@@ -485,16 +564,16 @@ void DebugConsole::sendBytes()
if
(
ok
&&
m_ui
->
sendText
->
text
().
toLatin1
().
size
()
>
0
)
{
// Transmit only if conversion succeeded
// int transmitted =
currLink
->
writeBytes
(
transmit
,
transmit
.
size
());
// if (transmit.size() == transmitted)
// {
m_ui
->
sentText
->
setText
(
tr
(
"Sent: "
)
+
feedback
);
// }
// else
// {
// m_ui->sentText->setText(tr("Error during sending: Transmitted only %1 bytes instead of %2.").arg(transmitted, transmit.size()));
// }
// int transmitted =
currLink
->
writeBytes
(
transmit
,
transmit
.
size
());
// if (transmit.size() == transmitted)
// {
m_ui
->
sentText
->
setText
(
tr
(
"Sent: "
)
+
feedback
);
// }
// else
// {
// m_ui->sentText->setText(tr("Error during sending: Transmitted only %1 bytes instead of %2.").arg(transmitted, transmit.size()));
// }
}
else
if
(
m_ui
->
sendText
->
text
().
toLatin1
().
size
()
>
0
)
{
...
...
src/ui/DebugConsole.h
View file @
934c8a7d
...
...
@@ -98,7 +98,10 @@ public slots:
protected:
void
changeEvent
(
QEvent
*
e
);
/** @brief Convert a symbol name to the byte representation */
QByteArray
symbolNameToBytes
(
const
QString
&
symbol
);
/** @brief Convert a symbol byte to the name */
QString
bytesToSymbolNames
(
const
QByteArray
&
b
);
QList
<
LinkInterface
*>
links
;
LinkInterface
*
currLink
;
...
...
src/ui/DebugConsole.ui
View file @
934c8a7d
...
...
@@ -6,7 +6,7 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
4
66
</width>
<width>
5
66
</width>
<height>
190
</height>
</rect>
</property>
...
...
@@ -171,11 +171,6 @@
<string>
TAB
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
NUL
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
ESC
</string>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment