server.py 1 KB
#!/usr/bin/env python

import socket
from thread import start_new_thread
import liboscimp_fpga

def clientThread(conn, addr):
    print('Open connection from ' + addr[0] + ':' + str(addr[1]) + '\n')
    while True:
        data = ''
        while '\n' not in data:
            data += conn.recv(8)
        recv = data.split(';')
        if recv[0] == "add_const_set_offset":
            try:
                liboscimp_fpga.add_const_set_offset(recv[1], int(recv[2]))
            except:
                pass
        if recv[0] == "nco_counter_send_conf":
            try:
                liboscimp_fpga.nco_counter_send_conf(recv[1], int(recv[2]), int(recv[3]), int(recv[4]), int(recv[5]))
            except:
                pass
        conn.close()

ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ctrl_sock.bind(('', 1001))
ctrl_sock.listen(10)

try:
    while True:
        conn, addr = ctrl_sock.accept()
        start_new_thread(clientThread ,(conn, addr,))
except KeyboardInterrupt:
    ctrl_sock.close()