Last active
January 29, 2022 08:32
-
-
Save lymieux/274e56e3e05b020bd793c4bd5036f171 to your computer and use it in GitHub Desktop.
FRC Radio Flash Util in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket, re, sys | |
class RadioConfig(): | |
def __init__(self): | |
self.team_num = 0 | |
"""1-9999""" | |
self.radio_name = '' | |
"""1-31 char""" | |
self.wpa_key = 0 | |
"""8-30 char""" | |
self.radio_mode = 'AP24' | |
"""['AP24', 'AP5', 'B24', 'B5']""" | |
self.ipaddr = "0.0.0.0" | |
"""must be at 4 octets""" | |
self.firewall = 'N' | |
self.bwlimit = 4000 | |
self.dhcp = '' | |
"""Gets input from user to send to radio""" | |
def config_input(self): | |
"""Get 8 needed inputs""" | |
self.team_num = int(input("Team Number: ")) | |
"""1-9999""" | |
self.radio_name = str(input("Radio Name: ")) | |
"""1-31 char""" | |
self.wpa_key = str(input("WPA Key: ")) | |
"""8-30 char""" | |
self.radio_mode = str(input("Radio Mode: ")) | |
"""['AP24', 'AP5', 'B24', 'B5']""" | |
self.ipaddr = str(input("IP Address: ")) | |
"""must be at 4 octets""" | |
self.firewall = str(input("Firewall?: ")) | |
"""Yes or No""" | |
self.bwlimit = int(input("Bandwidth Limit: ")) | |
"""bytes: usually 4000""" | |
self.dhcp = str(input("DHCP?: ")) | |
"""just do no""" | |
"""Formats inputs for socket push""" | |
def build_cfg_string(self): | |
if self.radio_mode in ['B24', 'B5']: | |
ssid = self.radio_name | |
else: | |
ssid = str(self.team_num) + '_' + self.radio_name | |
self.wpa_key = '' if self.wpa_key == 'opt' else self.wpa_key | |
self.dhcp = 'CLEAR' if self.radio_mode == 'N' else self.dhcp | |
chan24 = '0'; chan5 = '0'; comment = 'Home'; date = '' | |
return f'{str(self.radio_mode)},{str(self.team_num)},{str(ssid)},{self.wpa_key},{str(self.firewall)},{int(self.bwlimit)},{chan24},{chan5},{comment},{date}' | |
# return f'{self.radio_mode},{str(self.team_num)},{ssid},{self.wpa_key},{self.firewall},{self.bwlimit},{self.dhcp},{chan24},{chan5},{comment},{date}' | |
"""Pushes through socket""" | |
def config_radio(self, cfg): | |
print(cfg) | |
try: | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.connect((self.ipaddr, 8888)) | |
lines = s.recv(1000).decode('utf-8').split('\n') | |
print(lines) | |
s.sendall(cfg.encode('utf-8') + b'\n') | |
except Exception as e: | |
print(e) | |
pass | |
if __name__ == '__main__': | |
rc = RadioConfig() | |
rv_config = rc.config_input() | |
# print(vars(rc)) | |
rc.config_radio(rc.build_cfg_string()) | |
import socket | |
HOST = '10.7.8.231' # Standard loopback interface address (localhost) | |
PORT = 8888 # Port to listen on (non-privileged ports are > 1023) | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.bind((HOST, PORT)) | |
s.listen() | |
conn, addr = s.accept() | |
with conn: | |
print('Connected by', addr) | |
while True: | |
data = conn.recv(1024) | |
if not data: | |
break | |
conn.sendall(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment