Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
28f1f018
Commit
28f1f018
authored
8 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Formating, fix ruff errors
parent
4a6b76c2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
libs/lib/xaal/lib/aionetwork.py
+22
-19
22 additions, 19 deletions
libs/lib/xaal/lib/aionetwork.py
libs/lib/xaal/lib/bindings.py
+22
-24
22 additions, 24 deletions
libs/lib/xaal/lib/bindings.py
libs/lib/xaal/lib/devices.py
+35
-24
35 additions, 24 deletions
libs/lib/xaal/lib/devices.py
with
79 additions
and
67 deletions
libs/lib/xaal/lib/aionetwork.py
+
22
−
19
View file @
28f1f018
...
...
@@ -6,9 +6,9 @@ import logging
logger
=
logging
.
getLogger
(
__name__
)
class
AsyncNetworkConnector
(
object
):
def
__init__
(
self
,
addr
,
port
,
hops
,
bind_addr
=
'
0.0.0.0
'
):
class
AsyncNetworkConnector
(
object
):
def
__init__
(
self
,
addr
,
port
,
hops
,
bind_addr
=
"
0.0.0.0
"
):
self
.
addr
=
addr
self
.
port
=
port
self
.
hops
=
hops
...
...
@@ -19,7 +19,8 @@ class AsyncNetworkConnector(object):
loop
=
asyncio
.
get_running_loop
()
on_con_lost
=
loop
.
create_future
()
self
.
transport
,
self
.
protocol
=
await
loop
.
create_datagram_endpoint
(
lambda
:
XAALServerProtocol
(
on_con_lost
,
self
.
receive
),
sock
=
self
.
new_sock
())
lambda
:
XAALServerProtocol
(
on_con_lost
,
self
.
receive
),
sock
=
self
.
new_sock
()
)
# In some conditions (containers), transport is connected but IGMP is delayed (up to 10ms)
# so we need to wait for IGMP to be really sent.
await
asyncio
.
sleep
(
0.05
)
...
...
@@ -33,7 +34,9 @@ class AsyncNetworkConnector(object):
# Windows
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
bind
((
self
.
bind_addr
,
self
.
port
))
mreq
=
struct
.
pack
(
"
=4s4s
"
,
socket
.
inet_aton
(
self
.
addr
),
socket
.
inet_aton
(
self
.
bind_addr
))
mreq
=
struct
.
pack
(
"
=4s4s
"
,
socket
.
inet_aton
(
self
.
addr
),
socket
.
inet_aton
(
self
.
bind_addr
)
)
sock
.
setsockopt
(
socket
.
IPPROTO_IP
,
socket
.
IP_ADD_MEMBERSHIP
,
mreq
)
sock
.
setsockopt
(
socket
.
IPPROTO_IP
,
socket
.
IP_MULTICAST_TTL
,
10
)
sock
.
setblocking
(
False
)
...
...
@@ -48,6 +51,7 @@ class AsyncNetworkConnector(object):
async
def
get_data
(
self
):
return
await
self
.
_rx_queue
.
get
()
class
XAALServerProtocol
(
asyncio
.
Protocol
):
def
__init__
(
self
,
on_con_lost
,
on_dtg_recv
):
self
.
on_con_lost
=
on_con_lost
...
...
@@ -58,7 +62,7 @@ class XAALServerProtocol(asyncio.Protocol):
self
.
transport
=
transport
def
error_received
(
self
,
exc
):
print
(
'
Error received:
'
,
exc
)
print
(
"
Error received:
"
,
exc
)
logger
.
warning
(
f
"
Error received:
{
exc
}
"
)
def
connection_lost
(
self
,
exc
):
...
...
@@ -71,4 +75,3 @@ class XAALServerProtocol(asyncio.Protocol):
def
datagram_received
(
self
,
data
,
addr
):
# print(f"pkt from {addr}")
self
.
on_dtg_recv
(
data
)
This diff is collapsed.
Click to expand it.
libs/lib/xaal/lib/bindings.py
+
22
−
24
View file @
28f1f018
...
...
@@ -2,6 +2,7 @@ import uuid
from
.exceptions
import
UUIDError
class
UUID
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
__uuid
=
uuid
.
UUID
(
*
args
,
**
kwargs
)
...
...
@@ -13,7 +14,7 @@ class UUID:
"""
if
(
digit
>
0
)
and
(
digit
<
13
):
tmp
=
str
(
uuid
.
uuid1
())
st
=
"
%s%s
"
%
(
tmp
[:
-
digit
],
'
0
'
*
digit
)
st
=
"
%s%s
"
%
(
tmp
[:
-
digit
],
"
0
"
*
digit
)
return
UUID
(
st
)
else
:
raise
UUIDError
...
...
@@ -64,7 +65,6 @@ class UUID:
return
self
.
__uuid
.
bytes
class
URL
:
def
__init__
(
self
,
value
):
self
.
__url
=
value
...
...
@@ -93,6 +93,4 @@ class URL:
return
self
.
__url
classes
=
[
UUID
,
URL
]
This diff is collapsed.
Click to expand it.
libs/lib/xaal/lib/devices.py
+
35
−
24
View file @
28f1f018
...
...
@@ -18,6 +18,7 @@
# along with xAAL. If not, see <http://www.gnu.org/licenses/>.
#
import
time
from
.
import
config
from
.
import
tools
...
...
@@ -28,7 +29,6 @@ from tabulate import tabulate
import
logging
logger
=
logging
.
getLogger
(
__name__
)
import
time
class
Attribute
(
object
):
...
...
@@ -138,7 +138,7 @@ class Device(object):
@address.setter
def
address
(
self
,
value
):
if
value
==
None
:
if
value
is
None
:
self
.
__address
=
None
return
if
not
tools
.
is_valid_address
(
value
):
...
...
@@ -151,7 +151,7 @@ class Device(object):
@url.setter
def
url
(
self
,
value
):
if
value
==
None
:
if
value
is
None
:
self
.
__url
=
None
else
:
self
.
__url
=
bindings
.
URL
(
value
)
...
...
@@ -239,17 +239,28 @@ class Device(object):
#####################################################
def
_get_description
(
self
):
result
=
{}
if
self
.
vendor_id
:
result
[
'
vendor_id
'
]
=
self
.
vendor_id
if
self
.
product_id
:
result
[
'
product_id
'
]
=
self
.
product_id
if
self
.
version
:
result
[
'
version
'
]
=
self
.
version
if
self
.
url
:
result
[
'
url
'
]
=
self
.
url
if
self
.
schema
:
result
[
'
schema
'
]
=
self
.
schema
if
self
.
info
:
result
[
'
info
'
]
=
self
.
info
if
self
.
hw_id
:
result
[
'
hw_id
'
]
=
self
.
hw_id
if
self
.
group_id
:
result
[
'
group_id
'
]
=
self
.
group_id
if
self
.
unsupported_methods
:
result
[
'
unsupported_methods
'
]
=
self
.
unsupported_methods
if
self
.
unsupported_notifications
:
result
[
'
unsupported_notifications
'
]
=
self
.
unsupported_notifications
if
self
.
unsupported_attributes
:
result
[
'
unsupported_attributes
'
]
=
self
.
unsupported_attributes
if
self
.
vendor_id
:
result
[
'
vendor_id
'
]
=
self
.
vendor_id
if
self
.
product_id
:
result
[
'
product_id
'
]
=
self
.
product_id
if
self
.
version
:
result
[
'
version
'
]
=
self
.
version
if
self
.
url
:
result
[
'
url
'
]
=
self
.
url
if
self
.
schema
:
result
[
'
schema
'
]
=
self
.
schema
if
self
.
info
:
result
[
'
info
'
]
=
self
.
info
if
self
.
hw_id
:
result
[
'
hw_id
'
]
=
self
.
hw_id
if
self
.
group_id
:
result
[
'
group_id
'
]
=
self
.
group_id
if
self
.
unsupported_methods
:
result
[
'
unsupported_methods
'
]
=
self
.
unsupported_methods
if
self
.
unsupported_notifications
:
result
[
'
unsupported_notifications
'
]
=
self
.
unsupported_notifications
if
self
.
unsupported_attributes
:
result
[
'
unsupported_attributes
'
]
=
self
.
unsupported_attributes
return
result
def
_get_attributes
(
self
,
_attributes
=
None
):
...
...
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