#!/usr/bin/env python # Send PARAM_STORED_VALS message # # The request is the message ID only # The response is a complex structure (not handled here) ##import datetime import socket import struct import sys import pprint # must match flightcode/stm32 PARAM_STORED_VALS_PORT = 5011 def send(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.sendto("", ("127.0.0.1", PARAM_STORED_VALS_PORT)) s.close() ##max_delay = 0.0 # send request, wait for response def fetch(): ##global max_delay s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Most of the time we get a response in <17 msec. # In one run of 10,000 fetches, the longest delay was <82 msec. s.settimeout(0.2) # send request ##start_time = datetime.datetime.now() s.sendto("", ("127.0.0.1", PARAM_STORED_VALS_PORT)) # wait for response try: msg = s.recv(256) except: msg = "" ##else: ## delta_time = datetime.datetime.now() - start_time ## delta_time = delta_time.total_seconds() ## if max_delay < delta_time: ## max_delay = delta_time ## print "response in %f sec" % (delta_time, ) s.close() return msg # parse string msg to dictionary # # { # 'stickCals' : [ stickCal0, ... stickCal5 ], # 'presets' : [ preset0, preset1 ], # 'rcSticks' : [ rcStick0, ... rcStick5 ], # 'buttonConfigs' : [ buttonConfig0, ... buttonConfig2 ], # 'sweepConfig' : [ sweepConfig0 ] # } # # stickCalN = # ( # , # minVal # , # trim # # maxVal # ) # presetN = # ( # # ) # rcStickN = # ( # , # input # , # direction # # expo # ) # buttonConfigN = # ( # , # buttonID # , # buttonEvt # , # shotID # , # state # # descriptor # ) # sweepConfigN = # ( # , # minSweepSec # # maxSweepSec # ) def unpack(msg): x = 0 stickCals = [] for i in range(6): stickCal = struct.unpack("