def pq9_connection(): pq9client = PQ9Client.PQ9Client(testConfig['PQ9EGSE']['server'], testConfig['PQ9EGSE']['port'], int(testConfig['PQ9EGSE']['timeout'])) pq9client.connect() yield pq9client pq9client.close()
def __init__(self, startUptime, stopUptime): # does the addOne command 10x on one var, 10x on three vars. self.client = PQ9Client.PQ9Client("localhost","10000") # EGSE port self.client.connect() self.startUptime = startUptime self.stopUptime = stopUptime self.firstMsg = True self.fileCount = 0 self.lineCount = 0 self.lastUptime = 0 self.MaxLines = 24*3600 self.filename = "Telemetry_2_response_"+str(fileCount)+".csv" self.fo = open(filename, 'w+')
def __init__(self, *args, **kwargs): super(PQ9CommandHandler, self).__init__(*args, **kwargs) self.getTelemetry = False self.stopSignal = False self.commandQueue = Queue() self.busStates = [True, False, False, False] self.pq9client = PQ9Client.PQ9Client() self.pq9client.connect() self.MaxLines = 24 * 3600 self.fileCount = 0 filename = "Telemetry_2_response_" + str(self.fileCount) + ".csv" self.fo = open(filename, 'w+') self.lineCount = 0 self.firstMsg = True self.lastUptime = 0 self.autoToggleEnabled = [False, False, False, False] self.autoToggleOnTime = [10, 10, 10, 10] self.autoToggleOffTime = [10, 10, 10, 10] self.autoToggleStartTime = [0, 0, 0, 0]
def pq9_connection(): pq9client = PQ9Client.PQ9Client("localhost", "10000") pq9client.connect() yield pq9client pq9client.close()
import PQ9Client import json import sys import time import os if __name__ == "__main__": pq9client = PQ9Client.PQ9Client() pq9client.connect() comPortName = sys.argv[1] # "tty.usbserial-AH3YB5A0" # dest = sys.argv[2] # inputFileName = sys.argv[3] print("Connecting PC_EGSE to COMPORT: "+comPortName) command = {} command["command"] = "reloadSerialPorts" pq9client.sendFrame(command) command["command"] = "setSerialPort" command["data"] = comPortName pq9client.sendFrame(command) time.sleep(2) # print("Opening file: "+inputFileName) # fi = open(inputFileName, "r") # try: # os.remove("Telemetry_"+str(dest)+"_response.csv") # except: # pass filename = "Telemetry_"+str(dest)+"_response.csv"
import PQ9Client import sys import time if __name__ == "__main__": pq9client = PQ9Client.PQ9Client("localhost","10000") pq9client.connect() # comPortName = sys.argv[1] # dest = sys.argv[2] # inputFileName = sys.argv[3] # print("Connecting PC_EGSE to COMPORT: "+comPortName) # command = {} # command["command"] = "reloadSerialPorts" # pq9client.sendFrame(command) # command["command"] = "setSerialPort" # command["data"] = comPortName # pq9client.sendFrame(command) # time.sleep(3) inputFileName = sys.argv[2] dest = sys.argv[1] print("Opening file: "+inputFileName) fi = open(inputFileName, "r") fo = open(inputFileName+"_response", 'w') commandlines = fi.readlines() startTime= time.time() for i,commandline in enumerate(commandlines): command = {}
def detumblealgo(magx1, magy1, magz1, magx2, magy2, magz2): # important: set the correct address and port in PQ9Client.py # also important: comment out all print() statements in PQ9Client.py when performing HIL tests # used to connect to the satellite client = PQ9Client.PQ9Client() client.connect() # The spacecraft bus communicates using bytes. hence the magnetic sensor readings should be converted to a strig of bytes # convert input to array of bytes to send over the spacecraft bus bmagx1 = bytearray(struct.pack("d", magx1)) bmagy1 = bytearray(struct.pack("d", magy1)) bmagz1 = bytearray(struct.pack("d", magz1)) bmagx2 = bytearray(struct.pack("d", magx2)) bmagy2 = bytearray(struct.pack("d", magy2)) bmagz2 = bytearray(struct.pack("d", magz2)) # initialise strings strbmagx1 = "" strbmagy1 = "" strbmagz1 = "" strbmagx2 = "" strbmagy2 = "" strbmagz2 = "" # convert bytes to strings and append with spaces in between for i in range(0, len(bmagx1)): strbmagx1 = strbmagx1 + " " + str(bmagx1[i]) for i in range(0, len(bmagx2)): strbmagx2 = strbmagx2 + " " + str(bmagx2[i]) for i in range(0, len(bmagy1)): strbmagy1 = strbmagy1 + " " + str(bmagy1[i]) for i in range(0, len(bmagy2)): strbmagy2 = strbmagy2 + " " + str(bmagy2[i]) for i in range(0, len(bmagz1)): strbmagz1 = strbmagz1 + " " + str(bmagz1[i]) for i in range(0, len(bmagz2)): strbmagz2 = strbmagz2 + " " + str(bmagz2[i]) # generate detumble request # ADCS destination = 5 # source (does not really matter for no) = 8 # detumbleservicenumber = 25 # request = 1 # detumblepayload command = 0 # data is the string of bytes in order: x1 y1 z1 x2 y2 z2 command = {} command["_send_"] = "SendRaw" command["dest"] = "5" # EPS command["src"] = "8" command[ "data"] = "25 1 0" + strbmagx1 + strbmagy1 + strbmagz1 + strbmagx2 + strbmagy2 + strbmagz2 client.sendFrame(command) succes, msg = client.getFrame() # spacecraft bus returns string of bytes, need to be converted again to doubles # split string of bytes into individual integers PLbytes = [int(s) for s in msg["_raw_"][1:-1].split(',')] # obtain only the payload integers PLbytes = PLbytes[5:-2] #output are doubles, so 8 bytes. convert string to bytes and assign to variables PLbytesx = bytes(PLbytes[0:8]) PLbytesy = bytes(PLbytes[8:16]) PLbytesz = bytes(PLbytes[16:24]) tumblebytesx = bytes(PLbytes[24:32]) tumblebytesy = bytes(PLbytes[32:40]) tumblebytesz = bytes(PLbytes[40:48]) #convert bytes to doubles M_DESx = struct.unpack('d', PLbytesx)[0] M_DESy = struct.unpack('d', PLbytesy)[0] M_DESz = struct.unpack('d', PLbytesz)[0] tumblex = struct.unpack('d', tumblebytesx)[0] tumbley = struct.unpack('d', tumblebytesy)[0] tumblez = struct.unpack('d', tumblebytesz)[0] #return output return [M_DESx, M_DESy, M_DESz, tumblex, tumbley, tumblez]