#!/usr/bin/python # @file tricksim.py # @brief TRICK simulator # @author David Hale # @date 2013-02-19 # @modified 2013-02-26, DH # # This python script simulates the sequence of ROIs expected from TRICK # as a function of number of ROIs and their periodicities. You can edit # the ROI periodicities, cycles per reset (CPRS), and the max number of # cycles to display. # # The frames marked with (R) indicate that these are the reset frames. import sys import getopt import numpy as np # --- USER-EDITABLE VARIABLES -------------------------------------------------- CPRS=3 # CYCLES PER RESET MAX_CYCLES=9 # number of cycles to display (so it's not an infinite loop) # This "mini ROI Table" contains periodicity only. Element 0 is left unused # so that I can use direct indexing. Edit the contents and not the length -- # change the 0s as needed but define all values, 0 or not. periodicity= [0, 1, 3, 2, 0, 0, 0, 0, 0] # ^ ^ ^ ^ ^ ^ ^ ^ ^ # not used ___| | | | | | | | | # ROI1 ______| | | | | | | |___ ROI8 # ROI2 _________| | | | | |______ ROI7 # ROI3 ____________| | | |_________ ROI6 # ROI4 _______________| |____________ ROI5 # --- END USER-EDITABLE VARIABLES ---------------------------------------------- ROI = ['','A','B','C','D','E','F','G','H'] # names for the ROIs to print frame_count=1 # counter for dispay purposes, not part of the firmware cycle_count=1 # counter to limit the number of cycles displayed here ROI_MASK = np.zeros(len(periodicity), dtype='int') # --- TRANSMIT_VOF ------------------------------------------------------------- def TRANSMIT_VOF(): print "transmit VOF $0A 0056 004F 0046" print "------------------------------------------" print "" # --- ROI_TABLE_RESET ---------------------------------------------------------- def ROI_TABLE_RESET(): global periodicity global ROI global NUM_ROIS global ROI_MASK global frame_count global cycle_count print "transmit config packet $0A 00 00 CC NR ... " print "transmit reset header $0A 00 52" # instead of bit masks use arrays ROI_PATTERN = np.zeros(len(periodicity), dtype='int') # JSR NUM_ROIS): ROI_SEL = 1 # --- end of ROI loop --- FS_I += 1 # JSR MAX_CYCLES): exit # --- MAIN --------------------------------------------------------------------- def main(): global frame_count # just a counter for display purposes only global cycle_count # to limit the number of cycles displayed global NUM_ROIS global ROI_MASK print "start tricksim" print "periodicities =", periodicity[1:len(periodicity)-1] print "cycles per reset =", CPRS print "max cycles to display =", MAX_CYCLES print "" print "------------------------------------------" # --- start firmware simulation ------------- # Count number of ROIs (must set a 0 after last active ROI in table) # and create the ROI_MASK (which is normally a bit mask to indicate if # an ROI is present. # This is normally done in ROI command, before main video loop NUM_ROIS = 0 ROI_MASK = np.zeros(len(periodicity), dtype='int') for i, r in enumerate(periodicity): if (r > 0): NUM_ROIS += 1 ROI_MASK[i] = 1 # --- start exposure ------------------------ # RD_ARRAY CPR_I = CPRS # cycles per reset counter, CPR_I counts down from CPRS to 0. print "transmit VON $0A 0056 004F 004E" ROI_TABLE_RESET() # transmits the first of CPRS cycles # --- main video loop ----------------------- # DO FOREVER,VIDEO_LOOP (normally an infinite loop terminated by command, here limited by MAX_FRAMES) while True: ROI_PATTERN = np.zeros(len(periodicity), dtype='int') # JSR 1 and CPR_I == 0): CPR_I = CPRS ROI_TABLE_RESET() continue # DO FOREVER,FSM_LOOP (the minimum length of this loop is one cycle) while True: ROI_SEL=1 # INIT_ROI_SEL # --- loop through ROIs in table ------------ # DO Y:NUM_ROIS,ROI_LOOP for k in range(0, NUM_ROIS): decimate = periodicity[ROI_SEL] # JSR NUM_ROIS): ROI_SEL = 1 # --- end of ROI loop --- FS_I += 1 # JSR MAX_CYCLES): break TRANSMIT_VOF() exit if __name__ == "__main__": main()