Created
June 23, 2018 04:45
-
-
Save apullin/72887a4cf4903841ab672f488cdc781e to your computer and use it in GitHub Desktop.
Python code to start & stop Bluetooth carrier TX for bt_mfg_test app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/anaconda3/bin/python | |
import serial | |
import sys | |
import ctypes | |
def tone(ser, frequency, power, onoff = True): | |
if (frequency < 2402) or (frequency > 2480): | |
print("Frequency must be between 2402-2480 Mhz") | |
if type(frequency) != int: | |
print("Frequency must be an integer") | |
cmd = [0x01, 0x014, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] | |
if onoff: | |
cmd[4] = 0 | |
else: | |
cmd[4] = 1 | |
cmd[5] = frequency-2400 | |
cmd[6] = 0 | |
cmd[7] = 0 | |
if onoff: | |
cmd[8] = 8 | |
else: | |
cmd[8] = 0 | |
cmd[9] = ctypes.c_uint8( power ).value | |
ser.write(cmd) | |
res = ser.read(7) | |
print(res) | |
def tone_all_off(ser): | |
cmd = [ int(x,16) for x in "01 14 fc 07 01 02 00 00 00 00 00".split(" ") ] | |
ser.write(cmd) | |
res = ser.read(7) | |
print(res) | |
def main(): | |
if len(sys.argv) != 5: | |
print("Bad arguments") | |
print("Usage: mbt_tone <COMxx|/dev/...> <onoff> <frequency> <power>") | |
sys.exit(-1) | |
COMPORT = sys.argv[1] | |
onoff = int(sys.argv[2]) | |
frequency = int(sys.argv[3]) | |
power = int(sys.argv[4]) | |
print("Opening serial...") | |
try: | |
ser = serial.Serial(port = "/dev/tty.usbserial-A12TT9R4", baudrate = 115200, rtscts = False, timeout=1) | |
except Exception: | |
print("Error:") | |
print(Exception) | |
sys.exit(-1) | |
if frequency == 0: | |
tone_all_off(ser) | |
else: | |
tone( ser, frequency, power, int(onoff) ) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment