Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
web-ros3rag
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
web-ros3rag
Commits
92976ad5
Commit
92976ad5
authored
4 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
New buttons for demo mode.
parent
0a582068
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+39
-23
39 additions, 23 deletions
main.py
utils.py
+1
-1
1 addition, 1 deletion
utils.py
with
40 additions
and
24 deletions
main.py
+
39
−
23
View file @
92976ad5
...
...
@@ -29,11 +29,19 @@ message_queue = queue.Queue()
# button-id: (topic, payload)
commands
=
{
'
send-place-a-model
'
:
(
'
place-a/model
'
,
'
1
'
),
'
send-place-a-model-details
'
:
(
'
place-a/model
'
,
'
details
'
),
'
send-place-a-exit
'
:
(
'
place-a/exit
'
,
'
1
'
),
'
send-place-b-model
'
:
(
'
place-b/model
'
,
'
1
'
),
'
send-place-b-model-details
'
:
(
'
place-b/model
'
,
'
details
'
),
'
send-place-b-exit
'
:
(
'
place-b/exit
'
,
'
1
'
),
'
send-place-a-demo-objRed-blue
'
:
(
'
place-a/demo/move/objectRed1/blue
'
,
'
1
'
),
'
send-place-a-demo-objRed-red
'
:
(
'
place-a/demo/move/objectRed1/red
'
,
'
1
'
),
'
send-place-b-demo-objRed-red
'
:
(
'
place-b/demo/move/objectRed1/red
'
,
'
1
'
),
}
button_style_normal
=
{
"
marginRight
"
:
"
15px
"
}
button_style_exit
=
{
**
button_style_normal
,
"
backgroundColor
"
:
"
red
"
,
"
color
"
:
"
white
"
}
app
=
dash
.
Dash
(
__name__
,
external_stylesheets
=
external_stylesheets
)
app
.
layout
=
html
.
Div
([
html
.
Div
([
...
...
@@ -44,7 +52,7 @@ app.layout = html.Div([
value
=
'
{}
'
,
style
=
{
'
width
'
:
'
100%
'
}
),
html
.
Button
(
'
Send to place-a/scene/update
'
,
id
=
'
send-place-a-update
'
),
html
.
Button
(
'
Send to place-a/scene/update
'
,
id
=
'
send-place-a-update
'
,
disabled
=
True
),
],
className
=
"
six columns
"
),
html
.
Div
([
dcc
.
Textarea
(
...
...
@@ -53,28 +61,34 @@ app.layout = html.Div([
value
=
'
{}
'
,
style
=
{
'
width
'
:
'
100%
'
}
),
html
.
Button
(
'
Send to place-b/scene/update
'
,
id
=
'
send-place-b-update
'
),
html
.
Button
(
'
Send to place-b/scene/update
'
,
id
=
'
send-place-b-update
'
,
disabled
=
True
),
],
className
=
"
six columns
"
),
],
className
=
'
row
'
),
dcc
.
Markdown
(
"
---
"
),
html
.
H3
(
"
Commands
"
),
html
.
Div
([
html
.
Div
([
html
.
Button
(
'
Place A: Model
'
,
id
=
'
send-place-a-model
'
,
style
=
{
"
margin-right
"
:
"
15px
"
}),
html
.
Button
(
'
Place A: Exit
'
,
id
=
'
send-place-a-exit
'
,
style
=
{
"
margin-right
"
:
"
15px
"
}),
html
.
H3
(
"
Commands Place A
"
),
html
.
Button
(
'
Model
'
,
id
=
'
send-place-a-model
'
,
style
=
button_style_normal
),
html
.
Button
(
'
Model (Details)
'
,
id
=
'
send-place-a-model-details
'
,
style
=
button_style_normal
),
html
.
Button
(
'
Exit
'
,
id
=
'
send-place-a-exit
'
,
style
=
button_style_exit
),
html
.
Button
(
'
obj-Red -> Red
'
,
id
=
'
send-place-a-demo-objRed-red
'
,
style
=
button_style_normal
),
html
.
Button
(
'
obj-Red -> Blue
'
,
id
=
'
send-place-a-demo-objRed-blue
'
,
style
=
button_style_normal
),
],
className
=
"
six columns
"
),
html
.
Div
([
html
.
Button
(
'
Place B: Model
'
,
id
=
'
send-place-b-model
'
,
style
=
{
"
margin-right
"
:
"
15px
"
}),
html
.
Button
(
'
Place B: Exit
'
,
id
=
'
send-place-b-exit
'
,
style
=
{
"
margin-right
"
:
"
15px
"
}),
html
.
H3
(
"
Commands Place B
"
),
html
.
Button
(
'
Model
'
,
id
=
'
send-place-b-model
'
,
style
=
button_style_normal
),
html
.
Button
(
'
Model (Details)
'
,
id
=
'
send-place-b-model-details
'
,
style
=
button_style_normal
),
html
.
Button
(
'
Exit
'
,
id
=
'
send-place-b-exit
'
,
style
=
button_style_exit
),
html
.
Button
(
'
obj-Red -> Red
'
,
id
=
'
send-place-b-demo-objRed-red
'
,
style
=
button_style_normal
),
],
className
=
"
six columns
"
),
],
className
=
'
row
'
),
dcc
.
Markdown
(
"
---
"
),
html
.
H3
(
"
MQTT Log
"
),
dcc
.
Textarea
(
id
=
'
mqtt-log
'
,
value
=
""
,
readOnly
=
True
,
rows
=
50
,
style
=
{
'
width
'
:
'
100%
'
,
'
height
'
:
'
200px
'
,
'
font-family
'
:
'
Consolas, monospace
'
}
style
=
{
'
width
'
:
'
100%
'
,
'
height
'
:
'
200px
'
,
'
fontFamily
'
:
'
Consolas, monospace
'
}
),
dcc
.
Markdown
(
"
---
"
),
html
.
Div
([
...
...
@@ -113,24 +127,21 @@ def append_to_mqtt_log(_, value):
else
:
value
=
""
value
+=
'
\n
'
.
join
(
local_messages
)
if
max_topic
.
get_and_clear
():
lines
=
value
.
split
(
'
\n
'
)
reformatted_lines
=
[]
for
line
in
lines
:
timestamp
,
topic
,
message
=
utils
.
parse_log_msg
(
line
)
print
(
f
'
{
timestamp
,
topic
,
message
}
'
)
reformatted_lines
.
append
(
utils
.
format_log_msg
(
topic
,
max_topic
.
max_mqtt_topic_length
,
message
,
timestamp
=
timestamp
))
value
=
'
\n
'
.
join
(
reformatted_lines
)
#
if max_topic.get_and_clear():
#
lines = value.split('\n')
#
reformatted_lines = []
#
for line in lines:
#
timestamp, topic, message = utils.parse_log_msg(line)
#
print(f'{timestamp, topic, message}')
#
reformatted_lines.append(utils.format_log_msg(topic, max_topic.max_mqtt_topic_length,
#
message, timestamp=timestamp))
#
value = '\n'.join(reformatted_lines)
return
value
@app.callback
(
Output
(
'
hidden-div
'
,
'
children
'
),
Input
(
'
send-place-a-model
'
,
'
n_clicks
'
),
Input
(
'
send-place-a-exit
'
,
'
n_clicks
'
),
Input
(
'
send-place-b-model
'
,
'
n_clicks
'
),
Input
(
'
send-place-b-exit
'
,
'
n_clicks
'
),
[
Input
(
button_id
,
'
n_clicks
'
)
for
button_id
in
commands
]
)
def
button_clicked_to_add_to_mqtt_log
(
*
_
):
ctx
=
dash
.
callback_context
...
...
@@ -154,6 +165,7 @@ def button_clicked_to_add_to_mqtt_log(*_):
def
send_manual
(
n_clicks
,
topic
,
message
):
if
n_clicks
:
mqttc
.
publish
(
topic
=
topic
,
payload
=
message
)
return
dash
.
no_update
def
on_mqtt_connect
(
_client
,
_userdata
,
_flags
,
_rc
,
_properties
=
None
):
...
...
@@ -163,9 +175,13 @@ def on_mqtt_connect(_client, _userdata, _flags, _rc, _properties=None):
def
on_mqtt_message
(
_client
,
_userdata
,
message
):
max_mqtt_topic_length
=
max_topic
.
process_topic
(
message
.
topic
)
try
:
payload
=
message
.
payload
.
decode
(
"
utf-8
"
)
except
UnicodeDecodeError
:
payload
=
"
(unreadable bytes)
"
message_queue
.
put_nowait
(
utils
.
format_log_msg
(
message
.
topic
,
max_mqtt_topic_length
,
message
.
payload
.
decode
(
"
utf-8
"
))
.
replace
(
"
\n
"
,
"
~
"
))
payload
))
#
.replace("\n", " ~ "))
def
publish_test_message
():
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
1
−
1
View file @
92976ad5
...
...
@@ -4,7 +4,7 @@ from datetime import datetime
class
MaxTopicLength
:
def
__init__
(
self
):
self
.
max_mqtt_topic_length
=
1
self
.
max_mqtt_topic_length
=
22
self
.
mqtt_log_reformat_event
=
threading
.
Event
()
def
process_topic
(
self
,
topic
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment