Skip to content

Network api extended

Lucashsmello edited this page Apr 9, 2019 · 3 revisions

Everything should be in network byte order.

Request exit (E_NETWORK_PACKET_EXIT)

0x02 (a single byte)

No response

Set current configuration settings (E_NETWORK_PACKET_SETCONFIG)

byte value
0 0x03
1-4 sensibility (float)
5-6 dead zone X (signed int_16bits)
7-8 dead zone Y (signed int_16bits)

Some special values are used to signal for no modification for a specific setting:

  • Negative values for sensibility
  • 32767 (INT16_MAX) for dead zone

No response

Example code (python)

import socket
import struct
GIMX_PORT=51914
def SetConfigurationParameters(sensibility=-1,dzx=32767,dzy=32767):
	global GIMX_PORT
	if(sensibility==-1 and dzx==32767 and dzy==32767): return
	dest = ("127.0.0.1", GIMX_PORT)
	data = bytearray(struct.pack('>Bfhh',3,sensibility,dzx,dzy))
	sock = socket.socket(socket.AF_INET, # Internet
		                  socket.SOCK_DGRAM) # UDP
	sock.sendto(data, dest)
	sock.close()

Request current configuration settings (E_NETWORK_PACKET_GETCONFIG)

0x04

Response:

byte value
0 0x04
1-4 sensibility (float)
5-6 dead zone X (signed int_16bits)
7-8 dead zone Y (signed int_16bits)

Example code (python)

import socket
import struct
GIMX_PORT=51914
def GetConfigurationParameters():
	"""
	If successful, returns a dict with all settings.
	Current Valid settings are: 'sensibility', 'dzx' and 'dzy'.

	None is returned when failed.
	"""
	global GIMX_PORT
	dest=("127.0.0.1", GIMX_PORT)
	data = bytearray([4]) # E_NETWORK_PACKET_GETCONFIG
	sock = socket.socket(socket.AF_INET, # Internet
		                  socket.SOCK_DGRAM) # UDP
	sock.sendto(data, dest)
	sock.settimeout(0.8)
	try:
		data, _ = sock.recvfrom(128)
		data=bytearray(data)[1:] # first byte is always the packet code (4).
		#print ">%s<" % str(''.join('{:02x}'.format(x) for x in data))
		config={}
		config['sensibility'], config['dzx'], config['dzy']=struct.unpack('>fhh',data[0:8])
		sock.close()
		return config
	except socket.timeout:
		sock.close()
	return None

Save current settings/calibration (E_NETWORK_PACKET_SAVECALIBRATION)

0x05

No response