Refactorig and initial documentation (e.g. ParticipantMsg.py)

This commit is contained in:
Pascal Serrarens 2025-02-23 14:07:57 +01:00
parent d9108a418b
commit db16f95a45
29 changed files with 109 additions and 88 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -1,39 +1,51 @@
warning: source 'images' is not a readable file or directory... skipping. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:31: warning: documented symbol 'controlcore.Participant.Participant::bool' was not declared or defined.
d:/Python/Control.Core/ClientMsg.py:16: warning: Member network_id (variable) of class Control.Core.ClientMsg.ClientMsg is not documented. error: Project logo '//intranet/home/Afbeeldingen/PasserVR/Logos/Logo3NameRight100.png' specified by PROJECT_LOGO does not exist!
d:/Python/Control.Core/ClientMsg.py:8: warning: Member id (variable) of class Control.Core.ClientMsg.ClientMsg is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:26: warning: Member __init__(self, ipAddress="0.0.0.0", port=7681, remote=False, udp_socket=None) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/ClientMsg.py:9: warning: Member length (variable) of class Control.Core.ClientMsg.ClientMsg is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:47: warning: Member GetParticipant(self, ip_address, port) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:9: warning: Member __init__(self, ipAddress="0.0.0.0", port=7168) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:57: warning: Member AddParticipant(self, ip_address, port) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:48: warning: Member Publish(self, msg) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:64: warning: Member Update(self, currentTimeMs) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:56: warning: Member Update(self, currentTime) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:76: warning: Member SendThingInfo(self, thing) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:64: warning: Member ProcessClientMsg(self, bytearray data) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:81: warning: Member Send(self, msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:66: warning: Member ProcessNetworkIdMsg(self, bytearray data) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:90: warning: Member Publish(self, msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:68: warning: Member ProcessInvestigateMsg(self, bytearray data) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:103: warning: Member Receiver(self) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:71: warning: Member ReceiveData(self, data) (function) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:115: warning: Member ReceiveData(self, data, remote_participant) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:10: warning: Member buffer (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:135: warning: Member ProcessClientMsg(self, sender, ParticipantMsg msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:11: warning: Member ipAddress (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:138: warning: Member ProcessNetworkIdMsg(self, sender, NetworkIdMsg msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:12: warning: Member port (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:147: warning: Member ProcessInvestigateMsg(self, bytearray data) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:13: warning: Member udp_socket (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:150: warning: Member ProcessThingMsg(self, ThingMsg msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:18: warning: Member network_id (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:153: warning: Member ProcessNameMsg(self, NameMsg msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:19: warning: Member nextPublishMe (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:156: warning: Member ProcessModelUrlMsg(self, ModelUrlMsg msg) (function) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Participant.py:8: warning: Member publishInterval (variable) of class Control.Core.Participant.Participant is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:27: warning: Member ip_address (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:20: warning: Member __init__(self, type=Type.Undetermined, parent=None, name=None) (function) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:28: warning: Member port (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:41: warning: Member update(self, currentTime) (function) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:34: warning: Member udp_socket (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:44: warning: Member ProcessBinary(self, data) (function) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:16: warning: Member publishInterval (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:50: warning: Member Add(thing) (function) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:18: warning: Member buffer (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:55: warning: Member Get(networkId, thingId) (function) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:21: warning: Member nextPublishMe (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:21: warning: Member networkId (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:22: warning: Member others (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:22: warning: Member id (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:23: warning: Member thread (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:23: warning: Member type (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Participant.py:24: warning: Member name (variable) of class controlcore.Participant.Participant is not documented.
d:/Python/Control.Core/Thing.py:25: warning: Member parent_id (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:21: warning: Member __init__(self, type=Type.Undetermined, parent=None, name=None) (function) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:29: warning: Member name (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:42: warning: Member update(self, currentTime) (function) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:30: warning: Member model_url (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:45: warning: Member ProcessBinary(self, data) (function) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:32: warning: Member position (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:51: warning: Member Add(thing) (function) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:33: warning: Member orientation (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:56: warning: Member Get(networkId, thingId) (function) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:34: warning: Member linearVelocity (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:22: warning: Member networkId (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:35: warning: Member angularVelocity (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:23: warning: Member id (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:37: warning: Member pose_updated (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:24: warning: Member type (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:15: warning: Member Position (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:26: warning: Member parent_id (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:16: warning: Member Orientation (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:30: warning: Member name (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:17: warning: Member LinearVelocity (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:31: warning: Member model_url (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:18: warning: Member AngularVelocity (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:33: warning: Member position (variable) of class controlcore.Thing.Thing is not documented.
d:/Python/Control.Core/Thing.py:47: warning: Member allThings (variable) of class Control.Core.Thing.Thing is not documented. /Users/pascal/Documents/Dev/Python/controlcore/Thing.py:34: warning: Member orientation (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:35: warning: Member linearVelocity (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:36: warning: Member angularVelocity (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:38: warning: Member pose_updated (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:16: warning: Member Position (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:17: warning: Member Orientation (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:18: warning: Member LinearVelocity (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:19: warning: Member AngularVelocity (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Thing.py:48: warning: Member allThings (variable) of class controlcore.Thing.Thing is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Messages/NetworkIdMsg.py:7: warning: Member id (variable) of class NetworkIdMsg.NetworkIdMsg is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Messages/NetworkIdMsg.py:8: warning: Member length (variable) of class NetworkIdMsg.NetworkIdMsg is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/Messages/NetworkIdMsg.py:10: warning: Member network_id (variable) of class NetworkIdMsg.NetworkIdMsg is not documented.
/Users/pascal/Documents/Dev/Python/controlcore/LinearAlgebra/SwingTwist.py:6: warning: Member __init__(self, Direction swing, float twist) (function) of class SwingTwist.SwingTwist is not documented.

View File

@ -1,5 +1,5 @@
import math import math
from Direction import Direction from LinearAlgebra.Direction import Direction
class Spherical: class Spherical:
def __init__(self, distance, direction): def __init__(self, distance, direction):

View File

@ -1,17 +1,21 @@
from Direction import Direction from LinearAlgebra.Direction import Direction
from Quaternion import Quaternion from LinearAlgebra.Quaternion import Quaternion
class SwingTwist: class SwingTwist:
"""A rotation using swing and twist angle components"""
def __init__(self, swing: Direction, twist: float): def __init__(self, swing: Direction, twist: float):
if swing.vertical > 90 or swing.vertical < -90: if swing.vertical > 90 or swing.vertical < -90:
swing.horizontal += 180 swing.horizontal += 180
swing.vertical = 180 - swing.vertical swing.vertical = 180 - swing.vertical
twist += 180 twist += 180
## Swing component of the rotation
self.swing = swing self.swing = swing
## The twist component of the rotation
self.twist = twist self.twist = twist
def ToQuaternion(self) -> Quaternion: def ToQuaternion(self) -> Quaternion:
"""Convert the SwingTwist rotation to a Quaternion"""
q = Quaternion.Euler(-self.swing.vertical, q = Quaternion.Euler(-self.swing.vertical,
self.swing.horizontal, self.swing.horizontal,
self.twist) self.twist)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
import numpy as np import numpy as np
from SwingTwist import SwingTwist from LinearAlgebra.SwingTwist import SwingTwist
def SendAngle8(buffer, ix_ref, angle): def SendAngle8(buffer, ix_ref, angle):
# Normalize angle # Normalize angle

View File

@ -1,4 +1,4 @@
import LowLevelMessages import Messages.LowLevelMessages as LowLevelMessages
from Thing import Thing from Thing import Thing
class IMessage: class IMessage:

View File

@ -1,4 +1,4 @@
from Messages import IMessage from Messages.Messages import IMessage
class ModelUrlMsg(IMessage): class ModelUrlMsg(IMessage):
id = 0x90 id = 0x90

View File

@ -1,4 +1,4 @@
from Messages import IMessage from Messages.Messages import IMessage
class NameMsg(IMessage): class NameMsg(IMessage):
id = 0x91 id = 0x91

View File

@ -1,4 +1,4 @@
from Messages import IMessage from Messages.Messages import IMessage
## A network id message invites another participant to a site ## A network id message invites another participant to a site
# #

View File

@ -1,39 +1,41 @@
from Messages import IMessage from Messages.Messages import IMessage
## A client message announces the presence of a participant class ParticipantMsg(IMessage):
# """! A participant messages notifies other participants of its presence.
## When received by another participant, it can be followed by a NetworkIdMsg
## to announce that participant to this client such that it can join privately
class ClientMsg(IMessage):
id = 0xA0
length = 2
network_id = None When received by another participant, it can be followed by a NetworkIdMsg
to announce that participant to this client such that it can join privately
"""
## The message ID
id: int = 0xA0
## The length of the message
length: int = 2
## The network ID known by the participant.
network_id: int = None
## Create a Client message def __init__(self, network_id: int):
# """! Create a new message for sending
# @param network_id The network id of the local participant. Use 0 if it is unknown @param network_id The network ID known by the participant. Use 0 if it is unknown
def __init__(self, network_id): """
if isinstance(network_id, int): if isinstance(network_id, int):
self.network_id = network_id self.network_id = network_id
elif isinstance(network_id, bytes): elif isinstance(network_id, bytes):
self.network_id = network_id[1] self.network_id = network_id[1]
## Serialize the message into the given buffer
#
## @param buffer_ref A reference to the buffer to use. This should be a list with the buffer as its first and only element
## @returns the length of the message
def Serialize(self, buffer_ref): def Serialize(self, buffer_ref):
"""! Serialize the message into a byte array.
@param buffer_ref The buffer to serialize into
@return The length of the message in the buffer
"""
if buffer_ref is None or self.network_id is None: if buffer_ref is None or self.network_id is None:
return 0 return 0
buffer: bytearray = buffer_ref[0] buffer: bytearray = buffer_ref[0]
buffer[0:ClientMsg.length] = [ buffer[0:ParticipantMsg.length] = [
ClientMsg.id, ParticipantMsg.id,
self.network_id self.network_id
] ]
return ClientMsg.length return ParticipantMsg.length
# @staticmethod # @staticmethod
# def Serialized(buffer_ref, network_id): # def Serialized(buffer_ref, network_id):

View File

@ -1,4 +1,4 @@
from Messages import IMessage from Messages.Messages import IMessage
class ThingMsg(IMessage): class ThingMsg(IMessage):
id = 0x80 id = 0x80

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,20 +1,22 @@
import socket import socket
import threading import threading
from ClientMsg import ClientMsg from Messages.ParticipantMsg import ParticipantMsg
from NetworkIdMsg import NetworkIdMsg from Messages.NetworkIdMsg import NetworkIdMsg
from ThingMsg import ThingMsg from Messages.ThingMsg import ThingMsg
from NameMsg import NameMsg from Messages.NameMsg import NameMsg
from ModelUrlMsg import ModelUrlMsg from Messages.ModelUrlMsg import ModelUrlMsg
from Thing import Thing from Thing import Thing
## A participant is device which can communicate with other participants
#
## Currently only UDP communication is supported
class Participant: class Participant:
"""! A participant is used for communcation between things.
Currently, only UDP communication is supported
"""
publishInterval = 3000 # 3 seconds publishInterval = 3000 # 3 seconds
buffer = None buffer = None
## The network ID of the participant
network_id = None network_id = None
nextPublishMe = 0 nextPublishMe = 0
others = None others = None
@ -61,7 +63,7 @@ class Participant:
def Update(self, currentTimeMs): def Update(self, currentTimeMs):
if self.publishInterval > 0 and currentTimeMs > self.nextPublishMe: if self.publishInterval > 0 and currentTimeMs > self.nextPublishMe:
self.Publish(ClientMsg(self.network_id)) self.Publish(ParticipantMsg(self.network_id))
print(f'Publish ClientMsg {self.network_id}') print(f'Publish ClientMsg {self.network_id}')
self.nextPublishMe = currentTimeMs + self.publishInterval self.nextPublishMe = currentTimeMs + self.publishInterval
@ -114,8 +116,8 @@ class Participant:
msgId = data[0] msgId = data[0]
# print(f'msg {msgId} ') # print(f'msg {msgId} ')
match msgId: match msgId:
case ClientMsg.id: case ParticipantMsg.id:
self.ProcessClientMsg(remote_participant, ClientMsg(data)) self.ProcessClientMsg(remote_participant, ParticipantMsg(data))
case NetworkIdMsg.id: case NetworkIdMsg.id:
self.ProcessNetworkIdMsg(remote_participant, NetworkIdMsg(data)) self.ProcessNetworkIdMsg(remote_participant, NetworkIdMsg(data))
# case InvestigateMsg.id: # case InvestigateMsg.id:
@ -130,7 +132,7 @@ class Participant:
# msg = Messages.BinaryMsg(data) # msg = Messages.BinaryMsg(data)
# msg.thing.ProcessBinary(msg.data) # msg.thing.ProcessBinary(msg.data)
def ProcessClientMsg(self, sender, msg: ClientMsg): def ProcessClientMsg(self, sender, msg: ParticipantMsg):
pass pass
def ProcessNetworkIdMsg(self, sender, msg: NetworkIdMsg): def ProcessNetworkIdMsg(self, sender, msg: NetworkIdMsg):

View File

@ -1,6 +1,6 @@
from Participant import Participant from Participant import Participant
from ClientMsg import ClientMsg from Messages.ParticipantMsg import ParticipantMsg
from NetworkIdMsg import NetworkIdMsg from Messages.NetworkIdMsg import NetworkIdMsg
import socket import socket
import threading import threading

View File

@ -1,10 +1,11 @@
from Spherical import Spherical from LinearAlgebra.Spherical import Spherical
from Quaternion import Quaternion from LinearAlgebra.Quaternion import Quaternion
## A thing is the basic building block ## A thing is the basic building block
# #
## A thing is the basic building block ## A thing is the basic building block
class Thing: class Thing:
""" A thing is the basic building block"""
class Type: class Type:
Undetermined = 0x00 Undetermined = 0x00
Switch = 0x01 Switch = 0x01

View File

@ -6,9 +6,9 @@ __all__ = ['Direction',
'SiteServer', 'SiteServer',
'SwingTwist'] 'SwingTwist']
from .Direction import Direction from .LinearAlgebra.Direction import Direction
from .Participant import Participant from .Participant import Participant
from .Thing import Thing from .Thing import Thing
from .Spherical import Spherical from .LinearAlgebra.Spherical import Spherical
from .SwingTwist import SwingTwist from .LinearAlgebra.SwingTwist import SwingTwist
from .SiteServer import SiteServer from .SiteServer import SiteServer