def __init__(self): super(AudioHandler, self).__init__() self.header_base = construct.BitStruct( 'ASTRMBaseHeader', construct.BitField('fmt', 3), construct.Bit('channel'), construct.Flag('vibrate'), construct.Bit('packet_type'), construct.BitField('seq_id', 10), construct.BitField('payload_size', 16)) self.header_aud = construct.Struct('ASTRMAudioHeader', construct.ULInt32('timestamp')) self.header_msg = construct.Struct( 'ASTRMMsgHeader', # This is kind of a hack, (there are two timestamp fields, which one is used # depends on packet_type construct.ULInt32('timestamp_audio'), construct.ULInt32('timestamp'), construct.Array(2, construct.ULInt32('freq_0')), # -> mc_video construct.Array(2, construct.ULInt32('freq_1')), # -> mc_sync construct.ULInt8('vid_format'), construct.Padding(3)) self.header = construct.Struct( 'ASTRMHeader', construct.Embed(self.header_base), construct.Switch('format_hdr', lambda ctx: ctx.packet_type, { 0: construct.Embed(self.header_aud), 1: construct.Embed(self.header_msg), }, default=construct.Pass))
def __init__(self): super(VideoHandler, self).__init__() self.last_sent_time = 0 self.decoder = H264Decoder() self.header = construct.BitStruct( 'VSTRMHeader', construct.Nibble('magic'), construct.BitField('packet_type', 2), construct.BitField('seq_id', 10), construct.Flag('init'), construct.Flag('frame_begin'), construct.Flag('chunk_end'), construct.Flag('frame_end'), construct.Flag('has_timestamp'), construct.BitField('payload_size', 11), construct.BitField('timestamp', 32)) self.frame = array.array('B') self.is_streaming = False self.frame_decode_num = 0
def __init__(s): super(ServiceVSTRM, s).__init__() s.decoder = H264Decoder(s.dimensions['gamepad'], pygame.display.get_surface().get_size()) s.header = construct.BitStruct('VSTRMHeader', construct.Nibble('magic'), construct.BitField('packet_type', 2), construct.BitField('seq_id', 10), construct.Flag('init'), construct.Flag('frame_begin'), construct.Flag('chunk_end'), construct.Flag('frame_end'), construct.Flag('has_timestamp'), construct.BitField('payload_size', 11), construct.BitField('timestamp', 32)) s.frame = array.array('B') s.is_streaming = False s.frame_decode_num = 0
def __init__(s, decoder): super(ServiceVSTRM, s).__init__() s.decoder = decoder s.header = construct.BitStruct('VSTRMHeader', construct.Nibble('magic'), construct.BitField('packet_type', 2), construct.BitField('seq_id', 10), construct.Flag('init'), construct.Flag('frame_begin'), construct.Flag('chunk_end'), construct.Flag('frame_end'), construct.Flag('has_timestamp'), construct.BitField('payload_size', 11), construct.BitField('timestamp', 32)) s.frame = array.array('B') s._is_streaming = False s.is_streaming = False s.frame_decode_num = 0
def __init__(s): super(ServiceASTRM, s).__init__() s.header_base = construct.BitStruct('ASTRMBaseHeader', construct.BitField('fmt', 3), construct.Bit('channel'), construct.Flag('vibrate'), construct.Bit('packet_type'), construct.BitField('seq_id', 10), construct.BitField('payload_size', 16) ) s.header_aud = construct.Struct('ASTRMAudioHeader', construct.ULInt32('timestamp'), # construct.Array(lambda ctx: ctx.payload_size, construct.UBInt8("data")) ) s.header_msg = construct.Struct('ASTRMMsgHeader', # This is kind of a hack, (there are two timestamp fields, which one is used depends on packet_type construct.ULInt32('timestamp_audio'), construct.ULInt32('timestamp'), construct.Array(2, construct.ULInt32('freq_0')), # -> mc_video construct.Array(2, construct.ULInt32('freq_1')), # -> mc_sync construct.ULInt8('vid_format'), construct.Padding(3) ) s.header = construct.Struct('ASTRMHeader', construct.Embed(s.header_base), construct.Switch('format_hdr', lambda ctx: ctx.packet_type, { 0 : construct.Embed(s.header_aud), 1 : construct.Embed(s.header_msg), }, default = construct.Pass ) ) s.is_streaming = False s.p = pyaudio.PyAudio() s.stream = None s.pa_num_bufs = 15 s.pa_ring = [array.array('H', '\0' * 416 * 2)] * s.pa_num_bufs s.pa_wpos = s.pa_rpos = 0
brams=['bram_msb','bram_lsb','bram_oob'] tx_snap = 'snap_gbe0_tx' rx_snap = 'snap_gbe3_rx' tx_core_name = 'gbe0' test_core_bram = 'qdrBram' test_QDRReg = 'testQDR' test_fineFFT= 'vals_testQDR' fpga=[] snap_debug='snap_debug' snap_fengine_debug_coarse_fft = construct.BitStruct(snap_debug, construct.Padding(128 - (4*18)), construct.BitField("d0_r", 18), construct.BitField("d0_i", 18), construct.BitField("d1_r", 18), construct.BitField("d1_i", 18)) def bin2fp(bits, m = 8, e = 7): if m > 32: raise RuntimeError('Unsupported fixed format: %i.%i' % (m,e)) shift = 32 - m bits = bits << shift m = m + shift e = e + shift return float(numpy.int32(bits)) / (2**e)
construct.Flag('adc_protect_disable'), # 13 construct.Flag('flasher_en'), # 12 construct.Padding(12 - 9 - 1), # 10 - 11 construct.Flag('gbe_enable'), # 9 construct.Flag('gbe_rst'), # 8 construct.Padding(8 - 3 - 1), # 4 - 7 construct.Flag('clr_status'), # 3 construct.Flag('arm'), # 2 construct.Flag('soft_sync'), # 1 construct.Flag('mrst')) # 0 # f-engine status register_fengine_fstatus = construct.BitStruct( 'fstatus0', construct.Padding(32 - 29 - 1), # 30 - 31 construct.BitField("sync_val", 2), # 28 - 29 construct.Padding(28 - 17 - 1), # 18 - 27 construct.Flag('xaui_lnkdn'), # 17 construct.Flag('xaui_over'), # 16 construct.Padding(16 - 6 - 1), # 7 - 15 construct.Flag('dram_err'), # 6 construct.Flag('clk_err'), # 5 construct.Flag('adc_disabled'), # 4 construct.Flag('ct_error'), # 3 construct.Flag('adc_overrange'), # 2 construct.Flag('fft_overrange'), # 1 construct.Flag('quant_overrange')) # 0 # x-engine control register register_xengine_control = construct.BitStruct( 'ctrl',
con = cst.Container # alias HEADER = cst.Struct('pc_header', cst.Magic('\x00'), cst.Const(cst.UBInt8('lines'), 1), cst.UBInt8('address'), cst.Magic('\x03')) SER_STATUS = cst.BitStruct('serst', cst.Magic('\x01\x01\x00'), cst.Flag('schedule_enabled'), cst.Flag('ack_enabled'), cst.Flag('further_pages'), cst.Flag('interrupt_mode'), cst.Magic('\x00')) PAGE_IDX = cst.Bytes('page_num', 3) TEMPO = cst.BitStruct( 'tempo', cst.Magic('\x01\x01'), cst.Enum(cst.BitField('display_ctrl', 2), TIMED=0, FIXED_ON=1, FIXED_OFF=2), cst.Enum(cst.BitField('persist_time', 4), S2=1, S5=2, S10=3, S20=4, S30=5, S45=6, S60=7, S90=8, S120=9)) # TODO: union persist_time with scroll_speed PAGE_FUNC = cst.BitStruct(
brams=['bram_msb','bram_lsb','bram_oob'] tx_snap = 'snap_gbe0_tx' rx_snap = 'snap_gbe3_rx' tx_core_name = 'gbe0' test_core_bram = 'qdrBram' test_QDRReg = 'testQDR' test_fineFFT= 'vals_testQDR' fpga=[] snap_debug='snap_debug' snap_fengine_debug_fine_fft = construct.BitStruct(snap_debug, construct.Padding(128 - (4*31)), construct.BitField("d0_r", 31), construct.BitField("d0_i", 31), construct.BitField("d1_r", 31), construct.BitField("d1_i", 31)) def bin2fp(bits, m = 8, e = 7): if m > 32: raise RuntimeError('Unsupported fixed format: %i.%i' % (m,e)) shift = 32 - m bits = bits << shift m = m + shift e = e + shift return float(numpy.int32(bits)) / (2**e)
payload_len = 128 #how big to make each packet in 64bit words brams = ['bram_msb', 'bram_lsb', 'bram_oob'] tx_snap = 'snap_gbe0_tx' rx_snap = 'snap_gbe3_rx' tx_core_name = 'gbe0' test_core_bram = 'qdrBram' test_QDRReg = 'testQDR' test_fineFFT = 'vals_testQDR' fpga = [] snap_debug = 'snap_debug' snap_fengine_debug_coarse_fft = construct.BitStruct( snap_debug, construct.Padding(128 - (4 * 18)), construct.BitField("d0_r", 18), construct.BitField("d0_i", 18), construct.BitField("d1_r", 18), construct.BitField("d1_i", 18)) # the xaui snap block on the f-engine - this is just after packetisation snap_fengine_xaui = construct.BitStruct( "snap_debug", construct.Padding(128 - 1 - 3 - 1 - 1 - 3 - 64), construct.Flag("link_down"), construct.Padding(3), construct.Flag("mrst"), construct.Padding(1), construct.Flag("eof"), construct.Flag("sync"), construct.Flag("hdr_valid"), construct.BitField("data", 64)) def bin2fp(bits, m=8, e=7): if m > 32: raise RuntimeError('Unsupported fixed format: %i.%i' % (m, e)) shift = 32 - m bits = bits << shift
import construct, corr_functions register_fengine_control = construct.BitStruct( 'feng_ctl', construct.Flag('gbe_gpu_rst'), #31 construct.Flag('gbe_sw_rst'), #30 construct.Flag('loopback_mux_rst'), #29 construct.Flag('cnt_rst'), #28 construct.BitField('fft_preshift', 2), #26-27 construct.BitField('gpio_monsel', 3), #23,24,25 construct.Flag('fft_tvg2'), #22 construct.Flag('fft_tvg1'), #21 construct.Flag('gbe_gpu_disable'), #20 construct.Flag('use_qdr_tvg'), #19 construct.Flag('gbe_sw_disable'), #18 construct.Flag('arm_rst'), #17 construct.Flag('sync_rst'), #16 construct.Flag('arm_noise'), #15 construct.Padding(12), #3-14 construct.Flag('lb_err_cnt_rst'), #2 construct.Padding(2)) #0-1
def ieee(): IEEE = construct.BitStruct("IEEE", construct.BitField("s", 1), construct.BitField("e", 8), construct.BitField("m", 23)) return IEEE
def ibm(): IBM = construct.BitStruct("IBM", construct.BitField("s", 1), construct.BitField("e", 7), construct.BitField("m", 24)) return IBM
def bin2fp(bits, m = 8, e = 7): if m > 32: raise RuntimeError('Unsupported fixed format: %i.%i' % (m,e)) shift = 32 - m bits = bits << shift m = m + shift e = e + shift return float(numpy.int32(bits)) / (2**e) if construct.version[1] <= 6: # f-engine adc control register_fengine_adc_control = construct.BitStruct('adc_ctrl0', construct.Flag('enable'), # 31 Enable input channel on KAT ADC. construct.Padding(32 - 6 - 1), # 6-30 construct.BitField('atten', 6)) # 0-5 KAT ADC channel attenuation setting. # f-engine status register_fengine_fstatus = construct.BitStruct('fstatus0', construct.BitField('coarse_bits', 5), # 27-31 2^x - the number of points in the coarse FFT. construct.BitField('fine_bits', 5), # 22-26 2^y - the number of points in the fine FFT. construct.BitField('sync_val', 2), # 20-21 On which ADC cycle did the sync happen? construct.Padding(2), # 18-19 construct.Flag('xaui_lnkdn'), # 17 The 10GBE link is down. construct.Flag('xaui_over'), # 16 The 10GBE link has overflows. construct.Padding(9), # 7-15 construct.Flag('clk_err'), # 6 The board frequency is calculated out of bounds. construct.Flag('adc_disabled'), # 5 The ADC has been disabled. construct.Flag('ct_error'), # 4 There is a QDR error from the corner-turner. construct.Flag('adc_overrange'), # 3 The ADC is reporting over-ranging. construct.Flag('fine_fft_overrange'), # 2 Not used currently.
construct.Flag('adc_protect_disable'), # 13 construct.Flag('flasher_en'), # 12 construct.Padding(12 - 9 - 1), # 10 - 11 construct.Flag('gbe_enable'), # 9 construct.Flag('gbe_rst'), # 8 construct.Padding(8 - 3 - 1), # 4 - 7 construct.Flag('clr_status'), # 3 construct.Flag('arm'), # 2 construct.Flag('soft_sync'), # 1 construct.Flag('mrst')) # 0 # f-engine status register_fengine_fstatus = construct.BitStruct('fstatus0', construct.Padding(32 - 29 - 1), # 30 - 31 construct.BitField("sync_val", 2), # 28 - 29 construct.Padding(28 - 17 - 1), # 18 - 27 construct.Flag('xaui_lnkdn'), # 17 construct.Flag('xaui_over'), # 16 construct.Padding(16 - 6 - 1), # 7 - 15 construct.Flag('dram_err'), # 6 construct.Flag('clk_err'), # 5 construct.Flag('adc_disabled'), # 4 construct.Flag('ct_error'), # 3 construct.Flag('adc_overrange'), # 2 construct.Flag('fft_overrange'), # 1 construct.Flag('quant_overrange')) # 0 # x-engine control register register_xengine_control = construct.BitStruct('ctrl', construct.Padding(32 - 16 - 1), # 17 - 31
snap_size_adc = 4096 # The ADCs use a different (smaller) snap block coarse_fft_size = 256 # Frequency bins fine_fft_size = 4096 # Frequency bins offset_shift_size = snap_size # For the fine FFT, when the whole thing can't be measured at once. num_offset_shifts = 4 # In case this later needs to be changed, perhaps for a different size fine FFT. # Variables relevant only to the corner turner snaps_per_spectrum = 128 channels_per_snap = 32 words_per_channel = 32 # Bitstruct to control the control register on the ROACH control_reg_bitstruct = construct.BitStruct( 'control_reg', construct.Padding(4), # 28-31 construct.BitField('debug_snap_select', 3), # 25-27 construct.Padding(3), # 22-24 construct.Flag('fine_tvg_en'), # 21 construct.Flag('adc_tvg'), # 20 construct.Flag('fd_fs_tvg'), # 19 construct.Flag('packetiser_tvg'), # 18 construct.Flag('ct_tvg'), # 17 construct.Flag('tvg_en'), # 16 construct.Padding(4), # 12-15 construct.Flag('fancy_en'), # 11 construct.Flag('adc_protect_disable'), # 10 construct.Flag('gbe_enable'), # 09 construct.Flag('gbe_rst'), # 08 construct.Padding(4), # 04-07 construct.Flag('clr_status'), # 03 construct.Flag('arm'), # 02