コード例 #1
0
sys.path.append('/root/fpga/')
import ipc_helper
import fpga_map as mmap
import time
import file_manager
import traceback
import options
import dac
import math
import hashlib
import datetime

#For basic testing of calibration laser and seed laser aliveness. Can be upgraded as necessary (e.g. expected parameter values)

# define fpga interface
fpga = ipc_helper.FPGAClientInterface()
power = mmap.Power(fpga)  # power sub-interface

len_pass_string = 100


def print_test(fo, name):
    print(name + ' ' + '.' * (len_pass_string - len(name)) + ' ', end='')
    fo.write('--- %s Starting %s ---\n' %
             ("(" + str(datetime.datetime.now())[0:23] + ")", name))


def pass_test(fo):
    print('Pass')
    fo.write('--- %s Pass ---\n' %
             ("(" + str(datetime.datetime.now())[0:23] + ")"))
コード例 #2
0
    def __init__(self):
        self.pid = os.getpid()

        # Initialize enables
        self.all_pkts_send_enable = HK_ALLPKTS_SEND_ENABLE
        self.fpga_req_enable = HK_FPGA_REQ_ENABLE
        self.sys_hk_send_enable  = HK_SYS_HK_SEND_ENABLE
        self.pat_hk_send_enable = HK_PAT_HK_SEND_ENABLE
        self.ch_hk_send_enable = HK_CH_HK_SEND_ENABLE
        self.ch_restart_enable = HK_CH_RESTART_ENABLE
        self.pat_restart_enable = HK_PAT_RESTART_ENABLE
        self.fpga_restart_enable = HK_FPGA_RESTART_ENABLE
        self.lb_restart_enable = HK_LB_RESTART_ENABLE

        # Initialize timing/check-related variables
        self.fpga_check_period = HK_FPGA_CHECK_PD
        self.sys_check_period = HK_SYS_CHECK_PD
        self.ch_heartbeat_period = HK_CH_CHECK_PD
        self.pat_health_period = HK_PAT_CHECK_PD
        self.lb_heartbeat_period = HK_LB_CHECK_PD

        # Initialize zmq-related objects and sockets
        # TODO: Update zmq connections, use library
        self.context = zmq.Context()
        self.pat_health_socket = self.context.socket(zmq.SUB)
        self.tx_socket = self.context.socket(zmq.PUB)
        self.hk_control_socket = self.context.socket(zmq.SUB)
        self.ch_heartbeat_socket = self.context.socket(zmq.SUB)
        self.lb_heartbeat_socket = self.context.socket(zmq.SUB)

        self.pat_health_socket.connect("tcp://127.0.0.1:%s" % PAT_HEALTH_PORT) #pat process is not already running
        self.tx_socket.connect("tcp://127.0.0.1:%s" % TX_PACKETS_PORT)
        self.hk_control_socket.bind("tcp://127.0.0.1:%s" % HK_CONTROL_PORT)
        self.ch_heartbeat_socket.bind("tcp://127.0.0.1:%s" % CH_HEARTBEAT_PORT)
        self.lb_heartbeat_socket.connect("tcp://127.0.0.1:%s" % LB_HEARTBEAT_PORT)

        self.pat_health_socket.setsockopt(zmq.SUBSCRIBE, b'')
        self.ch_heartbeat_socket.setsockopt(zmq.SUBSCRIBE, b'')
        self.hk_control_socket.setsockopt(zmq.SUBSCRIBE, b'')
        self.lb_heartbeat_socket.setsockopt(zmq.SUBSCRIBE, b'')

        self.poller = zmq.Poller()
        self.poller.register(self.ch_heartbeat_socket, zmq.POLLIN)
        self.poller.register(self.hk_control_socket, zmq.POLLIN)
        self.poller.register(self.pat_health_socket, zmq.POLLIN)
        self.poller.register(self.lb_heartbeat_socket, zmq.POLLIN)

        # Initialize FPGA client
        self.fpga_interface = ipc_helper.FPGAClientInterface(self.context)

        # Initialize structures to keep track of command handlers and their watchdogs
        self.ch_pids = range(COMMAND_HANDLERS_COUNT)
        self.ch_heartbeat_wds = {}

        for i in range(COMMAND_HANDLERS_COUNT):
            # TODO: switch this for multiple commandhandlers
            ch_pid = self.get_service_pid('commandhandler@%d' % i)
            # ch_pid = self.get_service_pid('commandhandler')

            self.ch_pids[i] = ch_pid
            self.ch_heartbeat_wds[ch_pid] = WatchdogTimer(self.ch_heartbeat_period, self.alert_missing_ch, i)

        # Initailize other watchdogs and timers
        self.pat_health_wd = WatchdogTimer(self.pat_health_period, self.alert_missing_pat)
        self.fpga_check_timer = ResetTimer(self.fpga_check_period, self.alert_fpga_check)
        self.sys_check_timer = ResetTimer(self.sys_check_period, self.alert_sys_check)
        self.lb_heartbeat_wd = WatchdogTimer(self.lb_heartbeat_period, self.alert_missing_lb)

        # Initialize objects for multithreading
        self.fpga_check_flag = threading.Event()
        self.sys_check_flag = threading.Event()
        self.missing_pat_flag = threading.Event()
        self.missing_fpga_flag = threading.Event()
        self.missing_lb_flag = threading.Event()

        self.fpga_check_flag.clear()
        self.sys_check_flag.clear()
        self.missing_pat_flag.clear()
        self.missing_fpga_flag.clear()
        self.missing_lb_flag.clear()

        self.missing_ch_queue = Queue.Queue()
        self.fpga_queue = Queue.Queue()

        # Initialize packet buffer
        self.packet_buf = []

        # Initialize counters
        self.sys_hk_count = 0
        self.fpga_hk_count = 0
        self.ack_cmd_count = 0
        self.err_cmd_count = 0

        # Initialize command tracking
        self.last_ack_cmd_id = 0
        self.last_err_cmd_id = 0