Oohh, got it working!
import struct, socket, os, math
is_isi = struct.Struct('BBBBHHBBH16s16s')
is_ver = struct.Struct('BBBB8s6sH')
is_cpp = struct.Struct('BBBB3lHHHBBfHH')
is_tiny = struct.Struct('BBBB')
is_small = struct.Struct('BBBBL')
outsimpack = struct.Struct('I3ffff3f3f3L')
config = open('camlevel_cfg.txt', 'r')
insimport = int(config.readline())
outsimport = int(config.readline())
pitch_multi = float(config.readline())
roll_multi = float(config.readline())
average_window = int(config.readline())
average_multi = float(config.readline())
camera_average = int(config.readline())
config.close()
pitch_list = [0]*average_window
roll_list = [0]*average_window
socket.setdefaulttimeout(10)
insim = socket.socket()
insim.connect(('127.0.0.1',insimport))
insim.send(is_isi.pack(44,1,0,0,outsimport,0,0,0,0,'','CamLevel'))
insim.send(is_small.pack(8,4,0,1,1))
outsim = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
outsim.bind(('127.0.0.1',outsimport))
while True:
try:
pitch, roll = (outsimpack.unpack(outsim.recv(64))[5:7])
pitch, roll = math.degrees(pitch),math.degrees(roll)
del pitch_list[0]
pitch_list.append(pitch)
del roll_list[0]
roll_list.append(roll)
pitch = pitch - (sum(pitch_list) / average_window)*average_multi
roll = roll - (sum(roll_list) / average_window)*average_multi
pitch, roll = pitch * pitch_multi, roll * roll_multi
pitch = int(pitch * 182.044444444444)
roll = int(roll * 182.0444444444)
if pitch < 0:
pitch = -pitch
else:
pitch = 65535 - pitch
if roll < 0:
roll = -roll
else:
roll = 65535 - roll
insim.send(is_cpp.pack(32,9,0,0,0,0,0,21,pitch,roll,
255,255,90.0,camera_average,8192))
except socket.timeout:
insim.send(is_small.pack(8,4,0,1,0))
insim.send(is_small.pack(8,4,0,1,1))
pitch_list = [0]*average_window
roll_list = [0]*average_window