NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

# -*- coding: utf-8 -*-
"""
Created on Fri Jan 22 12:28:39 2021

@author: Patrick.Wallrath
"""


import socket
import numpy as np
import time
import datetime as dt
import sys



file_Path = 'C:\UsersMessungDesktopTI RadarMeasurementTest\'
#file_Path = 'C:\Userspatrick.wallrathDesktopTI Meas\'

T_meas = 1 # measuremt time in sec


UDP_IP = "192.168.33.30"
UDP_PORT = 4098
RECV_BUF_LEN = 14660
UDP_HEADER_LEN = 10 # 26
MAX_LEN = 1456

def recvTelegram(sock, data_Telegram, data_Telegram_passed, frame_Id_Pre, n_Bytes_per_Telegram, start_Flag):

if start_Flag:
data_Frame, addr = sock.recvfrom(RECV_BUF_LEN)
n_Bytes_Passed = data_Frame[4] | data_Frame[5]<<8 | data_Frame[6]<<16 | data_Frame[7]<<24 | data_Frame[8]<<32 | data_Frame[9]<<40
n_Bytes_Recv = len(data_Frame[UDP_HEADER_LEN:])
#print("1 ", n_Bytes_Recv, " ")

#print("Searching Startn")
if n_Bytes_Passed%n_Bytes_per_Telegram == 0:
n_Bytes_Recv_Telegram = n_Bytes_Recv
data_Telegram[:int(n_Bytes_Recv_Telegram/2)] = np.frombuffer(data_Frame[UDP_HEADER_LEN:],dtype=np.int16)

else:
while ((n_Bytes_Passed+n_Bytes_Recv)%n_Bytes_per_Telegram) > (n_Bytes_Passed%n_Bytes_per_Telegram):
data_Frame, addr = sock.recvfrom(RECV_BUF_LEN)
n_Bytes_Passed = data_Frame[4] | data_Frame[5]<<8 | data_Frame[6]<<16 | data_Frame[7]<<24 | data_Frame[8]<<32 | data_Frame[9]<<40
n_Bytes_Recv = len(data_Frame[UDP_HEADER_LEN:])
n_Step = n_Bytes_Recv-(n_Bytes_Passed+n_Bytes_Recv)%n_Bytes_per_Telegram
n_Bytes_Recv_Telegram = len(data_Frame[n_Step:])
print()
data_Telegram[:int(n_Bytes_Recv_Telegram/2)] = np.frombuffer(data_Frame[n_Step:],dtype=np.int16)

frame_Id_Pre = data_Frame[0] | data_Frame[1]<<8 | data_Frame[2]<<16 | data_Frame[3]<<24

#print("Start foundn")
else:
n_Bytes_Recv_Telegram = len(data_Telegram_passed)
data_Telegram[:int(n_Bytes_Recv_Telegram/2)] = np.frombuffer(data_Telegram_passed,dtype=np.int16)


while n_Bytes_Recv_Telegram < n_Bytes_per_Telegram:

data_Frame, addr = sock.recvfrom(RECV_BUF_LEN)
frame_Id = data_Frame[0] | data_Frame[1]<<8 | data_Frame[2]<<16 | data_Frame[3]<<24
if frame_Id != frame_Id_Pre+1:
print('Error: False Frame IDn')
return 0, "", 0, 1

n_Bytes_Recv = len(data_Frame[UDP_HEADER_LEN:])
#print("recv: ", n_Bytes_Recv, " ")
n_Bytes_Passed = data_Frame[4] | data_Frame[5]<<8 | data_Frame[6]<<16 | data_Frame[7]<<24 | data_Frame[8]<<32 | data_Frame[9]<<40

if (n_Bytes_Recv_Telegram+n_Bytes_Recv) > n_Bytes_per_Telegram:
n_End = n_Bytes_per_Telegram - n_Bytes_Recv_Telegram + UDP_HEADER_LEN
n_Bytes_Recv = len(data_Frame[UDP_HEADER_LEN:n_End])
data_Telegram[int(n_Bytes_Recv_Telegram/2):int((n_Bytes_Recv_Telegram+n_Bytes_Recv)/2)] = np.frombuffer(data_Frame[UDP_HEADER_LEN:n_End],dtype=np.int16)
n_Bytes_Recv_Telegram += n_Bytes_Recv
data_Telegram_new = data_Frame[n_End:]#np.frombuffer(data_Frame[n_End:],dtype=np.int8)

else:
data_Telegram[int(n_Bytes_Recv_Telegram/2):int((n_Bytes_Recv_Telegram+n_Bytes_Recv)/2)] = np.frombuffer(data_Frame[UDP_HEADER_LEN:],dtype=np.int16)
n_Bytes_Recv_Telegram += n_Bytes_Recv

frame_Id_Pre = frame_Id


return data_Telegram, data_Telegram_new, frame_Id, 0





def recvMeas(file1, sock, n_Bytes_per_Telegram, n_Meas, n_Meas_p_Loop):

i = 0

data_Telegram = np.zeros(int(n_Bytes_per_Telegram/2), dtype=np.int16)
data_Loop = np.zeros(int(n_Bytes_per_Telegram/2)*n_Meas_p_Loop, dtype=np.int16)
data_Telegram_passed = ""
frame_Id = 0
control = np.ones(n_Meas,dtype=np.int8)
start_Flag = 1

d = dt.datetime.isoformat(dt.datetime.now())
file1.write(str.encode(d))
while i < int(n_Meas/n_Meas_p_Loop):
j = 0
while j < n_Meas_p_Loop:
data_Telegram, data_Telegram_passed, frame_Id, error = recvTelegram(sock, data_Telegram, data_Telegram_passed, frame_Id, n_Bytes_per_Telegram, start_Flag)

if error:
control[i*n_Meas_p_Loop+j] = 0
data_Loop[(i*n_Meas_p_Loop+j)*int(n_Bytes_per_Telegram/2):(i*n_Meas_p_Loop+j+1)*int(n_Bytes_per_Telegram/2)] = np.zeros(n_Bytes_per_Telegram)
file1.write(np.zeros(n_Bytes_per_Telegram))
start_Flag = 1

else:
data_Loop[(i*n_Meas_p_Loop+j)*int(n_Bytes_per_Telegram/2):(i*n_Meas_p_Loop+j+1)*int(n_Bytes_per_Telegram/2)] = data_Telegram
file1.write(data_Telegram)
start_Flag = 0
j += 1


i += 1


return control

if __name__ == '__main__':

try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

try:
sock.bind((UDP_IP, UDP_PORT))

except IOError:
print("Error: No Radar foundn")
sock.close()
raise sys.exit()


n_Tx = 2 # Number of used transmitting antennas
n_Rx = 4 # Number of used receiving antennas
n_samples = 256 # Number of samples in IF Signal
n_ADC_Byts = 2 # Number of used ADCbits
format_Complex = 1 # 1 Real Data 2 Complex Data

# BW = 1798.92*1e6
# c = 299792458
# dR = c / (2*BW) * (n_samples - 1) / n_samples
# IntRange = np.arange(n_samples) * dR

f_meas =1/(5e-4) # Measurment Rate in Hz
n_Meas = int(T_meas*f_meas) # Number of Measurments
T_Est = n_Meas/f_meas # estimated Measurment time in sec

n_Bytes_per_Ramp = n_Rx*n_samples*n_ADC_Byts*format_Complex
n_Bytes_per_Telegram = n_Tx*n_Bytes_per_Ramp
n_Bytes_per_Meas = n_Bytes_per_Telegram*n_Meas

# Creating File
date = dt.datetime.isoformat(dt.datetime.now())
date = date[:19].replace(':','_')
file_Name = file_Path + date + '.bin'

try:
file1 = open(file_Name, "wb")

except IOError:
print("Error: File not foundn")
sock.close()
raise sys.exit()


print("Measurement started! Estimated Measurement Time", T_Est, "secn")
start = time.time()
control = recvMeas(file1, sock, n_Bytes_per_Telegram, n_Meas)
stop = time.time()
sock.close()
file1.close()
print("Data saved in:" + file_Name + "n")
print("Measurement finished!n")
print("Time:", stop-start)

except KeyboardInterrupt:
sock.close()
file1.close()

# while(1):
# data = recvFrame()
# if data == -1:
# check_data[i] = 0
# a[i*n_Bytes_Frame:(i+1)*n_Bytes_Frame] =
# if i % n_loop ==0:
# queue = a
# i += 1
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.