/ RNode_Firmware_CE_G2 / esp32_btbufs.py
esp32_btbufs.py
 1  #!/usr/bin/env python3
 2  import sys
 3  import re
 4  
 5  try:
 6      target_path = sys.argv[1]
 7      rxbuf_size = 0; rxbuf_minsize = 6144
 8      txbuf_size = 0; txbuf_minsize = 384
 9      line_index = 0
10      rx_line_index = 0
11      tx_line_index = 0
12      with open(target_path) as sf:
13          for line in sf:
14              line_index += 1
15              if line.startswith("#define RX_QUEUE_SIZE"):
16                  ents = re.sub(" +", " ", line).split(" ")
17                  try:
18                      rxbuf_size = int(ents[2])
19                      rx_line_index = line_index
20                  except Exception as e:
21                      print(f"Could not parse Bluetooth RX_QUEUE_SIZE: {e}")
22  
23              if line.startswith("#define TX_QUEUE_SIZE"):
24                  ents = re.sub(" +", " ", line).split(" ")
25                  try:
26                      txbuf_size = int(ents[2])
27                      tx_line_index = line_index
28                  except Exception as e:
29                      print(f"Could not parse Bluetooth TX_QUEUE_SIZE: {e}")
30  
31              if rxbuf_size != 0 and txbuf_size != 0:
32                  break
33  
34      if rxbuf_size < rxbuf_minsize:
35          print(f"Error: The configured ESP32 Bluetooth RX buffer size is too small, please set it to at least {rxbuf_minsize} and try compiling again.")
36          print(f"The buffer configuration can be modified in line {rx_line_index} of: {target_path}")
37          exit(1)
38  
39      if txbuf_size < txbuf_minsize:
40          print(f"Error: The configured ESP32 Bluetooth TX buffer size is too small, please set it to at least {txbuf_minsize} and try compiling again.")
41          print(f"The buffer configuration can be modified in line {tx_line_index} of: {target_path}")
42          exit(1)
43  
44      exit(0)
45  
46  except Exception as e:
47      print(f"Could not determine ESP32 Bluetooth buffer configuration: {e}")
48      print("Please fix this error and try again")