This commit is contained in:
Hartmut Seichter 2025-06-30 22:10:49 +02:00
parent de9a4990e5
commit ec4728ed2a
2 changed files with 55 additions and 45 deletions

22
VRPN.gd
View file

@ -4,7 +4,6 @@ class_name VRPN
const magic_cookie_start : String = "vrpn: ver." const magic_cookie_start : String = "vrpn: ver."
static func marshall_block(data : PackedByteArray) -> void: static func marshall_block(data : PackedByteArray) -> void:
# need to fix that # need to fix that
@ -27,7 +26,7 @@ static func marshall_block(data : PackedByteArray) -> void:
var message_type := header.get_32() as int # type of message (payload) var message_type := header.get_32() as int # type of message (payload)
var sequence_num := header.get_32() as int # inofficial sequence number (padding) var sequence_num := header.get_32() as int # inofficial sequence number (padding)
if true: if false:
print("length '%d'" % length) print("length '%d'" % length)
print("time_sec '%d'" % time_sec) print("time_sec '%d'" % time_sec)
print("time_msec '%d'" % time_msec) print("time_msec '%d'" % time_msec)
@ -36,8 +35,10 @@ static func marshall_block(data : PackedByteArray) -> void:
print("sequence_num '%d'" % sequence_num) print("sequence_num '%d'" % sequence_num)
# print # print
print("block_offset:{0} header_size:{1} length:{2}".format([block_offset,header_size,length]))
print("sender_id:{0} message_type:{1} block_offset:{2} header_size:{3} length:{4}".format([sender_id, message_type, block_offset,header_size,length]))
# directly hand over marshalling for body
marshall_body(data.slice(block_offset+header_size,block_offset+length),message_type) marshall_body(data.slice(block_offset+header_size,block_offset+length),message_type)
# next datablock # next datablock
@ -49,13 +50,13 @@ static func marshall_body(data : PackedByteArray,message_type : int):
body.data_array = data body.data_array = data
body.big_endian = true body.big_endian = true
# sender description # sender description
match message_type: match message_type: # message_type_ids are supposedly dynamic
-1,-2: -1,-2:
# get length of string # get length of string
var body_length = body.get_32() var body_length = body.get_32()
# get string # get string
var sender_name = body.get_string(body_length) var sender_name = body.get_string(body_length)
print("sender name is %s:" % sender_name) print("sender name is '%s'" % sender_name)
#print(body.data_array) #print(body.data_array)
4: # quat pos 4: # quat pos
# get id # get id
@ -68,7 +69,16 @@ static func marshall_body(data : PackedByteArray,message_type : int):
var quat_y = body.get_double() var quat_y = body.get_double()
var quat_z = body.get_double() var quat_z = body.get_double()
var quat = Quaternion(quat_x,quat_y,quat_z,quat_w) var quat = Quaternion(quat_x,quat_y,quat_z,quat_w)
print("sensor id {0} {1} {2}".format([sensor_id,pos,quat])) #print("sensor id {0} {1} {2}".format([sensor_id,pos,quat]))
18:
var num_buttons = body.get_32()
var buttons = {}
for i in num_buttons:
var button_id = body.get_32()
var button_state = body.get_32()
buttons[button_id] = button_state
#print("sensor with {0} buttons".format([buttons]))
_: _:
print("unhandled message type {0}".format([message_type])) print("unhandled message type {0}".format([message_type]))

View file

@ -66,7 +66,7 @@ vrpn_Tracker_Spin Tracker0 1 200.0 0.0 1.0 0.0 0.1
# int number_of_buttons # int number_of_buttons
# float rate_at_which_the_buttons_toggle (transitions/second) # float rate_at_which_the_buttons_toggle (transitions/second)
#vrpn_Button_Example Button0 2 2.0 vrpn_Button_Example Button0 2 2.0
################################################################################ ################################################################################
# Example Dial server. This is a "device" that reports constant rotations for # Example Dial server. This is a "device" that reports constant rotations for