Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Μ
µnit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teckids
Projekt Hack-n-Fun
Libs
µnit
Commits
2809a6b7
Verified
Commit
2809a6b7
authored
2 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[companion] Implement schema loading
parent
6ba88f84
No related branches found
No related tags found
No related merge requests found
Pipeline
#84224
failed
2 years ago
Stage: prepare
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
companion/device.py
+49
-4
49 additions, 4 deletions
companion/device.py
companion/device_list.py
+1
-1
1 addition, 1 deletion
companion/device_list.py
with
50 additions
and
5 deletions
companion/device.py
+
49
−
4
View file @
2809a6b7
import
asyncio
import
json
from
kivy.logger
import
Logger
from
kivy.uix.button
import
Button
from
kivy.uix.widget
import
Widget
from
bleak
import
BleakClient
...
...
@@ -16,6 +18,8 @@ class DeviceWidget(Widget):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_task_queue
=
set
()
self
.
_ready
=
False
self
.
_data
=
b
""
self
.
_client
=
BleakClient
(
address
)
Logger
.
info
(
f
"
Connecting to device:
{
address
}
"
)
...
...
@@ -35,16 +39,57 @@ class DeviceWidget(Widget):
def
_reading
(
self
,
task
):
Logger
.
debug
(
"
Reading UART data now
"
)
self
.
_task_queue
.
discard
(
task
)
self
.
send_line
(
'
print(
"
Hallo Welt
"
)
'
)
self
.
_send_data
(
b
"
\x01
"
)
def
_handle_rx
(
self
,
count
,
data
):
Logger
.
debug
(
f
"
Received:
{
data
}
"
)
if
not
self
.
_ready
:
if
b
"
raw REPL
"
in
data
:
self
.
_ready
=
True
self
.
_data
=
b
""
self
.
_raw_repl_entered
()
else
:
Logger
.
warn
(
"
Unexpected data before raw REPL
"
)
return
if
self
.
_data
==
b
""
:
if
not
data
.
startswith
(
b
"
OK
"
):
Logger
.
warn
(
"
Unexpected data, exepcted OK marker
"
)
return
data
=
data
[
2
:]
self
.
_data
+=
data
if
self
.
_data
.
endswith
(
b
"
\r\n\x04\x04
>
"
):
Logger
.
debug
(
"
Found end marker
"
)
self
.
_handle_result
(
self
.
_data
[:
-
5
])
self
.
_data
=
b
""
def
_handle_result
(
self
,
data
):
Logger
.
debug
(
f
"
Handling result:
{
data
}
"
)
if
data
.
startswith
(
b
"
_mynit_schemas=
"
):
Logger
.
info
(
"
Received schema update
"
)
schemas
=
json
.
loads
(
data
[
15
:].
decode
())
self
.
_handle_schemas
(
schemas
)
def
_handle_schemas
(
self
,
schemas
):
Logger
.
debug
(
"
Handling schema update
"
)
def
_raw_repl_entered
(
self
):
Logger
.
info
(
"
Raw REPL entereed
"
)
Logger
.
debug
(
"
Retrieving schema
"
)
self
.
send_command
(
"
import ujson; print(
'
_mynit_schemas=
'
+ ujson.dumps(mynit._schemas))
"
)
def
send_
line
(
self
,
data
):
if
not
data
.
endswith
(
"
\
r\n
"
):
data
+=
"
\
r\n
"
def
send_
command
(
self
,
data
):
if
not
data
.
endswith
(
"
\
x04
"
):
data
+=
"
\
x04
"
data
=
data
.
encode
()
self
.
_send_data
(
data
)
def
_send_data
(
self
,
data
):
Logger
.
debug
(
f
"
Sending:
{
data
}
"
)
task
=
asyncio
.
create_task
(
self
.
_client
.
write_gatt_char
(
UART_SERVICE_TX_UUID
,
data
))
self
.
_task_queue
.
add
(
task
)
...
...
This diff is collapsed.
Click to expand it.
companion/device_list.py
+
1
−
1
View file @
2809a6b7
...
...
@@ -30,7 +30,7 @@ class DeviceListWidget(Widget):
def
_scan_finished
(
self
,
task
):
self
.
_scan_task
=
None
Logger
.
info
(
"
Sc
n
a finished
"
)
Logger
.
info
(
"
Sca
n
finished
"
)
def
do_connect
(
self
,
address
):
Logger
.
info
(
f
"
Connecting to device:
{
address
}
"
)
...
...
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