/ RNode_Firmware_CE_G2 / patch_rnodeconf_g2.py
patch_rnodeconf_g2.py
1 #!/usr/bin/env python3 2 """ 3 Patch script to add Station G2 support to locally installed rnodeconf 4 This modifies the installed rnodeconf.py to recognize Station G2 devices 5 """ 6 7 import os 8 import sys 9 10 11 def patch_rnodeconf(): 12 """Add Station G2 support to the installed rnodeconf module""" 13 try: 14 # Try to import RNS to get the rnodeconf path 15 import RNS.Utilities.rnodeconf as rnodeconf_module 16 17 rnodeconf_path = rnodeconf_module.__file__ 18 19 print(f"Found rnodeconf at: {rnodeconf_path}") 20 21 # Read the current file 22 with open(rnodeconf_path, "r") as f: 23 content = f.read() 24 25 # Check if Station G2 is already added 26 if "PRODUCT_STATION_G2" in content: 27 print("Station G2 support already present in rnodeconf") 28 return True 29 30 # Make backup 31 backup_path = rnodeconf_path + ".backup" 32 with open(backup_path, "w") as f: 33 f.write(content) 34 print(f"Created backup at: {backup_path}") 35 36 # Apply patches 37 38 # 1. Add ROM constants after existing products 39 product_insertion_point = "PRODUCT_XIAO_S3 = 0xEB" 40 if product_insertion_point in content: 41 content = content.replace( 42 product_insertion_point, 43 product_insertion_point + "\n PRODUCT_STATION_G2 = 0x60", 44 ) 45 46 # Add model constant after existing models 47 model_insertion_point = ( 48 "MODEL_DD = 0xDD # Xiao ESP32S3 with Wio-SX1262 module, 868 MHz" 49 ) 50 if model_insertion_point in content: 51 content = content.replace( 52 model_insertion_point, 53 model_insertion_point + "\n MODEL_62 = 0x62", 54 ) 55 56 # 2. Add to products dictionary 57 products_insertion_point = ( 58 'ROM.PRODUCT_XIAO_S3: "Seeed XIAO ESP32S3 Wio-SX1262",' 59 ) 60 if products_insertion_point in content: 61 content = content.replace( 62 products_insertion_point, 63 products_insertion_point 64 + '\n ROM.PRODUCT_STATION_G2: "Station G2",', 65 ) 66 67 # 3. Add to models dictionary 68 models_insertion_point = '0xDD: [850000000, 950000000, 22, "850 - 950 MHz", "rnode_firmware_xiao_esp32s3.zip", "SX1262"],' 69 if models_insertion_point in content: 70 content = content.replace( 71 models_insertion_point, 72 models_insertion_point 73 + '\n 0x62: [902000000, 928000000, 37, "902 - 928 MHz (Station G2, 5W)", "rnode_firmware_station_g2.zip", "SX1262"],', 74 ) 75 76 # Write the modified content 77 with open(rnodeconf_path, "w") as f: 78 f.write(content) 79 80 print("Successfully patched rnodeconf with Station G2 support") 81 print("Added:") 82 print(" - PRODUCT_STATION_G2 = 0x60") 83 print(" - MODEL_62 = 0x62") 84 print(" - Product name mapping") 85 print(" - Model capabilities (902-928 MHz, 37 dBm max, SX1262)") 86 return True 87 88 except ImportError: 89 print("ERROR: RNS module not found. Is rnodeconf installed?") 90 return False 91 except Exception as e: 92 print(f"ERROR patching rnodeconf: {e}") 93 return False 94 95 96 if __name__ == "__main__": 97 if patch_rnodeconf(): 98 print("\nTo provision a Station G2 with blank EEPROM:") 99 print(" rnodeconf /dev/ttyACM0 -r --product 60 --model 62 --hwrev 1") 100 print("\nTo verify after provisioning:") 101 print(" rnodeconf /dev/ttyACM0 -i") 102 else: 103 sys.exit(1)