Skip to content

Commit

Permalink
optimise(debug): Updated at_net_debug.py script
Browse files Browse the repository at this point in the history
- Added netif tx error print
- Fixed two log output errors
- Fixed parsing errors caused by duplicate lines in sdkconfig
  • Loading branch information
ustccw committed Mar 27, 2024
1 parent 05ade88 commit cf37b85
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tools/at_net_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def ESP_LOGE(x):
uint16_t id = *(icmp + 4); id <<= 8; id += *(icmp + 5);
uint16_t seq = *(icmp + 6); seq <<= 8; seq += *(icmp + 7);
if (tx) {
ESP_LOGI("udp-tx", "%s, IPL:%u, ID:0x%x, S:%u PDL:%u", (type == 8) ? "Echo" : "Echo Reply", ip_tlen, id, seq, icmp_dlen);
ESP_LOGI("icmp-tx", "%s, IPL:%u, ID:0x%x, S:%u PDL:%u", (type == 8) ? "Echo" : "Echo Reply", ip_tlen, id, seq, icmp_dlen);
} else {
ESP_LOGI("udp-rx", "%s, IPL:%u, ID:0x%x, S:%u PDL:%u", (type == 8) ? "Echo" : "Echo Reply", ip_tlen, id, seq, icmp_dlen);
ESP_LOGI("icmp-rx", "%s, IPL:%u, ID:0x%x, S:%u PDL:%u", (type == 8) ? "Echo" : "Echo Reply", ip_tlen, id, seq, icmp_dlen);
}
}
break;
Expand All @@ -193,6 +193,14 @@ def ESP_LOGE(x):
at_print_pkt_info(p, true);
"""

# Find the entry of netif tx returns
at_net_tx_ret_pos_pattern = 'if (ret == ESP_OK) {'
at_net_tx_ret_caller = """
if (ret != ESP_OK) {
ESP_LOGE("@@if-tx", "netif tx error, tot_len:%d len:%d ret: %d", q->tot_len, q->len, ret);
}
"""

# Find the entry of incoming packets
at_net_rx_pos_pattern = '/* full packet send to tcpip_thread to process */'
at_net_rx_caller = """
Expand All @@ -211,9 +219,17 @@ def at_update_args_if_sdkconfig(args):
args.no_udp = True
args.no_icmp = True

data = '[saved-args]'
with args.sdkconfig as f:
data = data + f.read()
data = f.read()

# remove the duplicate lines
dup_data = data.split('\n')
uni_data = []
for item in dup_data:
if item not in uni_data or item.startswith('#'):
uni_data.append(item)
data = '\n'.join(uni_data)
data = '[saved-args]' + data

import configparser
config = configparser.ConfigParser()
Expand Down Expand Up @@ -295,6 +311,10 @@ def at_patch_net_debug_snippet(args):
raise Exception('No TX caller entry found.')
data = data[:pos] + at_net_tx_caller + '\n ' + data[pos:]

pos = data.find(at_net_tx_ret_pos_pattern)
if pos > 0:
data = data[:pos] + at_net_tx_ret_caller + '\n ' + data[pos:]

# add rx caller of at_print_pkt_info()
pos = data.find(at_net_rx_pos_pattern)
if pos < 0:
Expand Down

0 comments on commit cf37b85

Please sign in to comment.