'append answer from pcb in while loop
upper_bound = 0x1200
lower_bound = 0x0
msg_to_send = rcvD.all_strck.MxFEAxiRegMsg.copy()
modem_snr_list = []
while True:
modem_snr_list.clear()
running_value = (upper_bound + lower_bound) // 2
msg_to_send["data"] = running_value
# rcvD.send_the_message("MxFEAxiRegMsg", rcvD.all_strck.MxFEAxiRegMsg)
rcvD.send_the_message("MxFEAxiRegMsg", msg_to_send)
time.sleep(2)
fm.rcv_the_packets(wait_for_optcode=38)
fm.rcv_the_packets(wait_for_optcode=90)
modem_sync = rcvD.all_strck.modemParamMsg["modemSync"]
modem_freq = rcvD.all_strck.modemParamMsg["modemEstFreq"]
modem_snr = rcvD.all_strck.modemParamMsg["modemSnr"]
modem_snr_list.append(modem_snr)
average_snr = sum(modem_snr_list) / len(modem_snr_list)
print(f"modem snr list is {modem_snr_list}\n modem snr average is {average_snr}")
sent_pack = rcvD.all_strck.dataStatusRepMsg["sentMsgCnt"]
receive_pack = rcvD.all_strck.dataStatusRepMsg["rcvMsgCnt"]
print(
f"msg_sent: {msg_to_send} \n running_value: {running_value}\n upper_bound: {upper_bound}\n lower_bound: {lower_bound}\n modem_snr: {modem_snr}\n modem_freq: {modem_freq}\n modem_sync: {modem_sync}\n "
f"sent_packets: {sent_pack}\n receive_packets: {receive_pack}")
if -1 < modem_snr < 1 and modem_sync and modem_freq < 1000 and sent_pack == receive_pack:
break
if modem_snr < -1:
lower_bound = running_value + 1
if modem_snr > 1:
upper_bound = running_value - 1
if upper_bound < lower_bound:
print("FAIL")
exit(1)
Hi all, I need to catch the answer from PCB(opcode 38) because of timing I prefer to send a data(msg_sent) than to do some list that appends received data, calculate the average, and after all this proceed to the if statements(instead of modem_snr will be average_snr), after that if I need to back to while to fix data, I will need to clear the previous list and repeat the circle.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
