Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a faster PER test #482

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/scripts/plot_per_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
fig.tight_layout()
plt.subplots_adjust(bottom=0.1)
'''
#title = f'packet len: {packetLen}\nphy: {phy_str[phy]}\ntxPower:{txPower}'

title = f'packet len: {packetLen}, txPower: 0.7 dBm\nphy: {phy_str[phy]}'
if axs.ndim == 1:
axs[col].set_title(title, fontdict={'fontsize': 6, 'fontweight': 'medium'})
Expand All @@ -177,15 +177,24 @@
if p[i] > SPEC:
#print(f'{a[i]}, {p[i]}')
if axs.ndim == 1:
axs[row].axvline(x=a[i], color='r', linestyle=':', linewidth=0.5)
axs[row].text(a[i], p[i], f' {p[i]}% @ {a[i]} dBm', horizontalalignment='left',
axs[col].axvline(x=a[i], color='r', linestyle=':', linewidth=0.5)
axs[col].text(a[i], p[i], f' {p[i]}% @ {a[i]} dBm', horizontalalignment='left',
verticalalignment='center', fontsize=3)
else:
axs[row, col].axvline(x=a[i], color='r', linestyle=':', linewidth=0.5)
axs[row, col].text(a[i], p[i], f' {p[i]}% @ {a[i]} dBm', horizontalalignment='left',
verticalalignment='center', fontsize=3)
break

# mark the last point
i = -1
if axs.ndim == 1:
axs[col].text(a[i], p[i], f' {p[i]}% @ {a[i]} dBm', horizontalalignment='left',
verticalalignment='center', fontsize=3)
else:
axs[row, col].text(a[i], p[i], f' {p[i]}% @ {a[i]} dBm', horizontalalignment='left',
verticalalignment='center', fontsize=3)

# note
fig.text(.5, .01, f'Run on all data channels (no advertising channels).\n{args.desc}', ha='center',
fontdict={"fontsize": 5})
Expand Down Expand Up @@ -257,6 +266,11 @@
verticalalignment='center', fontsize=8)
break

# mark the last point
i = -1
plt.text(a[i], p[i], f' {p[i]}% @ {a[i]} dBm', horizontalalignment='left',
verticalalignment='center', fontsize=8)

# resize the figure to match the aspect ratio of the Axes
fig.set_size_inches(7, 8, forward=True)
#fig.text(.5, .10, args.desc, ha='center', fontdict={"fontsize": 12})
Expand Down
72 changes: 40 additions & 32 deletions Tools/Bluetooth/conn_sweep.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,27 @@ def run_script_reset_board(sh_file):
parser.add_argument('--brd2_reset', default="", help="script file to reset board2")
parser.add_argument('--retry_limit', default=3, help="limit of retry times after fail")
parser.add_argument('--short', action='store_true', help="shorter test")
parser.add_argument('--chip', default="", help="DUT chip")
parser.add_argument('--min_pwrs', default="90,90,90,90", help="abs min power")

args = parser.parse_args()

print("--------------------------------------------------------------------------------------------")
pprint(vars(args))

# default minimum power
min_pwrs = [90, 90, 90, 90] # for PHY 1, 2, 3, 4

temp = args.min_pwrs.replace(" ", "")
pwrs = temp.split(",")
if len(pwrs) == 4:
min_pwrs = [int(x) for x in pwrs]
print(f'abs min pwr for each PHY: {min_pwrs}')

packetLengths = args.pktlen.strip().split(",")
phys = args.phys.strip().split(",")
txPowers = args.txpows.strip().split(",")

if args.attens is None:
if int(args.step) == 0 or int(args.step) == -1:
attens = [20, 70]
else:
attens = list(range(20, 90, int(args.step)))

# Add the max attenuation
if int(args.step) != -1:
attens.append(90)
else:
temp = args.attens.replace(" ", "")
attens = temp.split(",")
attens = [float(x) for x in attens]

print("slaveSerial :", args.slaveSerial)
print("masterSerial :", args.masterSerial)
print("slave TRACE :", args.stp)
Expand All @@ -141,7 +138,6 @@ def run_script_reset_board(sh_file):
print("delay :", args.delay)
print("packetLengths :", packetLengths)
print("phys :", phys)
print("attens :", attens)
print("txPowers :", txPowers)
print("PER limit :", args.limit)

Expand All @@ -165,6 +161,23 @@ def run_script_reset_board(sh_file):

testing = 1
for packetLen, phy, txPower in itertools.product(packetLengths, phys, txPowers):

if args.attens is None:
if int(args.step) == 0 or int(args.step) == -1:
attens = [20, 70]
else:
attens = list(range(20, min_pwrs[int(phy)-1], int(args.step)))

# Add the max attenuation
if int(args.step) != -1:
attens.append(min_pwrs[int(phy)-1])
else:
temp = args.attens.replace(" ", "")
attens = temp.split(",")
attens = [float(x) for x in attens]

print(f'attens: {attens}')

if args.short:
for atten in attens:
per_100 = 0
Expand Down Expand Up @@ -248,24 +261,22 @@ def run_script_reset_board(sh_file):
start_secs = time.time()

print('\n-----------------------------------------------------------------------------------------')
print(f'packetLen: {packetLen}, phy: {phy}, atten: {atten}, txPower: {txPower}, testing point: {testing}')
print(f'{args.chip} - packetLen: {packetLen}, phy: {phy}, atten: {atten}, txPower: {txPower}, testing point: {testing}')
print('-------------------------------------------------------------------------------------------')

print(f"\nSet the requested attenuation: {atten}.")
if rf_switch:
set_val = atten + float(args.loss)
mini_RCDAT = mini_RCDAT_USB(Namespace(atten=set_val))

print("\nSleep 1 second")
sleep(1)
sleep(0.1)

print("\nReset the packet stats.")
hciSlave.cmdFunc(Namespace(cmd="0102FF00"), timeout=10.0)
hciMaster.cmdFunc(Namespace(cmd="0102FF00"), timeout=10.0)

print("\nSlave listenFunc")
hciSlave.listenFunc(Namespace(time=1, stats="False"))
print(f'used {(time.time() - start_secs):.0f} secs.')

print("\nMaster listenFunc")
hciMaster.listenFunc(Namespace(time=1, stats="False"))
Expand All @@ -281,26 +292,27 @@ def run_script_reset_board(sh_file):
perMaster = hciMaster.connStatsFunc(None)

print("\nSlave collects results.")
perSlave = hciSlave.connStatsFunc(None)

print("\n\nperMaster : ", perMaster)
print("perSlave : ", perSlave)
perSlave = hciSlave.connStatsFunc(None)

reset_master = False
if perMaster is None:
print("perMaster is None. Reset the master.")
reset_master = True
elif perMaster >= 99.99:
print("perMaster invalid. Reset the master.")
print(f"perMaster {perMaster}% invalid. Reset the master.")
reset_master = True
else:
print(f"\n\nperMaster : {perMaster:.2f} %")

reset_slave = False
if perSlave is None:
print("perSlave is None. Flash the slave.")
reset_slave = True
elif perSlave >= 99.99:
print("perSlave invalid. Flash the slave.")
print(f"perSlave {perSlave}% invalid. Flash the slave.")
reset_slave = True
else:
print(f"perSlave : {perSlave:.2f} %")

if reset_slave or reset_master:
run_script_reset_board(args.brd1_reset)
Expand All @@ -326,7 +338,7 @@ def run_script_reset_board(sh_file):
perMax = perMaster
if perSlave > perMax:
perMax = perSlave
print("\nperMax : ", perMax)
print(f"\nperMax : {perMax:.2f} %")

break # no retry

Expand All @@ -342,13 +354,9 @@ def run_script_reset_board(sh_file):
# Save the results to file
results.write(str(packetLen)+","+str(phy)+",-"+str(atten)+","+str(txPower)+","+str(perMaster)+","+str(perSlave)+"\n")
end_secs = time.time()
print(f'\nTotally used {(end_secs - start_secs):.0f} seconds for this point.')
print(f'\nTotally used time for this point (secs): {(end_secs - start_secs):.0f}')

if testing >= RESET_CNT:
testing = RESET_CNT
need_to_setup = True
else:
testing += 1
testing += 1

else: # original method
for atten in attens:
Expand Down