47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
#recieves data from LabView and writes it in global variables TF.
|
|
import multiprocessing
|
|
import multiprocessing.managers
|
|
import socket
|
|
import struct
|
|
from timeit import default_timer as timer
|
|
|
|
#establish connection to global variables}
|
|
manager = multiprocessing.managers.BaseManager(address=('localhost',5001), authkey=b'')
|
|
manager.connect()
|
|
manager.register('sync_imc')
|
|
sync_imc = manager.sync_imc()
|
|
|
|
|
|
|
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
server_address = ('localhost', 8089)
|
|
client.connect(server_address)
|
|
|
|
try:
|
|
print('Press strg+c to close the programm')
|
|
while True:
|
|
start = timer()
|
|
size = struct.unpack('i', client.recv(4))[0] # Extract the msg size from four bytes - mind the encoding
|
|
str_data = client.recv(size)
|
|
str_data = str_data.decode()
|
|
str_data = str_data.replace(',','.')
|
|
data = [float(splits) for splits in str_data.split('\t')]
|
|
#order the revieved data in the different sensor types. There is one empty pin on the board (channel 88 on imc). Therefore, index 23 is missing in the AMR indixes and Fluxgates start from 46.
|
|
sync_imc.update({'T':data[-8:]})
|
|
|
|
#ATTENTION: MINUS SIGN FOR FG X AND Z FOR CRAFT APPARATUS
|
|
FG_data=[-data[46],data[47],-data[48]]
|
|
sync_imc.update({'FG':FG_data})
|
|
#USUAL CODE:
|
|
|
|
# sync_imc.update({'FG':data[46:49]})
|
|
sync_imc.update({'AMR_x':[data[i] for i in [0,3,4,9,12,13,18,21,22,28,31,32,37,40,41]]})
|
|
sync_imc.update({'AMR_y':[data[i] for i in [8,7,6,17,16,15,27,26,25,36,35,34,45,44,43]]})
|
|
sync_imc.update({'AMR_z':[data[i] for i in [1,2,5,10,11,14,19,20,24,29,30,33,38,39,42]]})
|
|
end = timer()
|
|
# print('Data size: %s Data value: %s' % (size, str_data.decode('ascii')))
|
|
print(end - start)
|
|
except KeyboardInterrupt:
|
|
print('shutting down')
|
|
client.sendall(b'Enough data :) Thanks') # Sending anything back closes the connection
|