#!/usr/bin/env python

from gnuradio import gr
#from gnuradio import usrp
from gnuradio import audio

from gnuradio.wxgui import stdgui, scopesink, fftsink
import wx

class bpsk_tx_graph (stdgui.gui_flow_graph):
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__(self, frame, panel, vbox, argv)

	sps = 256
        samp_freq = 8000
	data_rate = 62.5 # 31.25? This looks better

	# file "psk" is a phase shift file created by ascii_varicode.py
	# translating an ascii text file
	src = gr.file_source(gr.sizeof_char,"psk",1)

	bytes_to_syms = gr.bytes_to_syms()

	interp_taps = (1,) * sps
	interp = gr.interp_fir_filter_fff(sps, interp_taps)

	ps_coeffs = gr.firdes_root_raised_cosine ( \
		1,		# gain
		samp_freq,	# 
		data_rate,	# = baud for bpsk
		.36,		# .36 alpha = 1 - 16/25
		255 )		# guess
	pulse_shaper = gr.fir_filter_fff(1,ps_coeffs)

	tone = gr.sig_source_f(samp_freq, gr.GR_SIN_WAVE,1e3,.9,0)
	mixer = gr.multiply_ff()

	dst = audio.sink(samp_freq)


        self.connect(src, bytes_to_syms)
	self.connect(bytes_to_syms, interp)
	self.connect(interp,pulse_shaper)
	self.connect(pulse_shaper,(mixer,0))
	self.connect(tone, (mixer,1))
	self.connect(mixer,dst)

def main ():
    app = stdgui.stdapp(bpsk_tx_graph, "BPSK Tx")
    app.MainLoop()

if __name__ == '__main__':
    main()
