python之类似c语言回调函数使用示例
def handle_busy_p():
print("Device is busy (primary)")
# 这里可以添加实际处理逻辑
def handle_wifi_connected():
print("WiFi connection established")
# 这里可以添加实际处理逻辑
urc_table = [
[b"busy p", b"\r\n", handle_busy_p],
[b"WIFI CONNECTED", b"\r\n", handle_wifi_connected],
]
def process_response(response):
for pattern, terminator, callback in urc_table:
if pattern in response:
callback()
return True
return False
# 测试
process_response(b"WIFI CONNECTED\r\n") # 会调用handle_wifi_connected