39 recvBufSize = 0x1000000
42 def median_blur(input_array, total_size, fpga_ip, fpga_port, debug_level):
43 logging.basicConfig(level=debug_level)
44 bytesToSend = input_array.tostring()
46 UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
47 previous_buffer_size = UDPClientSocket.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)
48 UDPClientSocket.setsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF, recvBufSize)
49 real_buffer_size = UDPClientSocket.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF)
50 if(real_buffer_size/2 != recvBufSize):
51 logging.warning(
"set SO_RCVBUF failed! got only: " +
str(real_buffer_size/2) +
"; trying to continue...")
53 serverAddressPort = (fpga_ip, fpga_port)
56 logging.debug(
"Sending bytes: " +
str(cnt*BUFF_SIZE) +
" : " +
str((cnt+1)*BUFF_SIZE-1))
57 UDPClientSocket.sendto(bytesToSend[cnt*BUFF_SIZE:(cnt+1)*BUFF_SIZE], serverAddressPort)
58 if ((cnt+1)*BUFF_SIZE >= total_size):
59 logging.debug(
"INFO: Reached size to sent")
64 output_array = np.zeros((total_size,))
66 logging.debug(
"Receiving bytes: " +
str(cnt*BUFF_SIZE) +
" : " +
str((cnt+1)*BUFF_SIZE-1))
67 msgFromServer = UDPClientSocket.recvfrom(BUFF_SIZE)
68 y = np.frombuffer(msgFromServer[0], dtype=input_array.dtype)
69 logging.debug(output_array[cnt*BUFF_SIZE:(cnt+1)*BUFF_SIZE-1].size)
70 output_array[cnt*BUFF_SIZE:(cnt+1)*BUFF_SIZE] = y
71 if ((cnt+1)*BUFF_SIZE >= total_size):
72 logging.debug(
"Reached size to receive")
78 if __name__ ==
'__main__':
def median_blur(input_array, total_size, fpga_ip, fpga_port, debug_level)