# -*- coding: utf-8 -*-
"""

@author: David S. De Lorenzo

Start/stop the HackRF One, using hard-coded RF & IF gain settings

Important:  You must run this from a GNURadio Command Prompt!!

"""


import time
import hackrf


# Hard-code the device ID
DEVICE_ID = '0000000000000000a06063c82416705f'
# DEVICE_ID = '0000000000000000a06063c824237e5f'
# DEVICE_ID = '0000000000000000f75461dc2684a9c3'


# Hard-code the interference type
INTERFERENCE_TYPE = 'CW'
# INTERFERENCE_TYPE = 'GAUSSIAN_RFI_1MHz'
# INTERFERENCE_TYPE = 'GAUSSIAN_RFI_2MHz'
# INTERFERENCE_TYPE = 'GAUSSIAN_RFI_5MHz'
# INTERFERENCE_TYPE = 'BANDLIMITED_RFI_400kHz'
# INTERFERENCE_TYPE = 'BANDLIMITED_RFI_1MHz'
# INTERFERENCE_TYPE = 'BANDLIMITED_RFI_2MHz'
# INTERFERENCE_TYPE = 'PULSED_RFI_1msec'
# INTERFERENCE_TYPE = 'PULSED_RFI_20msec'
# INTERFERENCE_TYPE = 'PULSED_RFI_500msec'


# Hard-code the center frequency
CENTER_FREQ_MHz = 1575.42


# Set the RF gain to 0 or 14
RF_GAIN = 14


# Set the IF gain in the range 1 to 47
IF_GAIN_dB = 30


def main():

    print('\nSTARTING TEST!!!\n')

    # Connect to the HackRF One
    hack_rf = hackrf.device_connect(DEVICE_ID, INTERFERENCE_TYPE)
    hack_rf.start()

    # Turn on the RF source
    hack_rf.set_center_freq_MHz(CENTER_FREQ_MHz)
    hack_rf.set_rf_gain_dB(RF_GAIN)
    hack_rf.set_if_gain_dB(IF_GAIN_dB)
    hack_rf.set_on_or_off(True)

    time.sleep(1)
    input('\n\nPress <Enter> to halt jamming...')

    # Turn off the RF source
    hack_rf.turn_signal_off()

    # Disconnect from the HackRF One
    hack_rf.stop()
    hack_rf.wait()

    print('\n\nTEST FINISHED!!!\n')


if __name__ == '__main__':
    main()
