Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #199

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/CSPHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def getCSPHandler(addr, interface, device, hmacKey, xteaKey, protocol = None, us
elif protocol == "UHF":
return UHF_CSPHandler(addr, interface, device, hmacKey, xteaKey, useFec)
else:
raise ValueError("Protocol {} does not exist for CSP handlers".format(protocol))
raise ValueError(f"Protocol {protocol} does not exist for CSP handlers")

class CSPHandler(object):
__instance = None
Expand All @@ -45,7 +45,7 @@ def __new__(cls, addr, interface, device, hmacKey, xteaKey, useFec):
def __init__(self, addr, interface, device, hmacKey, xteaKey, useFec):
self.connectionManager = ConnectionManager()
self.usingFec = useFec
self.myAddr = addr;
self.myAddr = addr
self.numberOfBuffers = 100
self.bufferSize = 1024 #This is max size of an incoming packet
libcsp.init(self.myAddr, 'GroundStation', 'model', '1.2.3', self.numberOfBuffers, self.bufferSize)
Expand All @@ -55,20 +55,20 @@ def __init__(self, addr, interface, device, hmacKey, xteaKey, useFec):
self.interfaceName = ""
if interface == 'uart':
self.ser = self._uart(device)
elif interface == 'uhf' or interface == "sdr":
elif interface in ('uhf', "sdr"):
self._uhf(device, libcsp.SDR_UHF_GNURADIO_BAUD)
elif interface == 'sband':
self._sband()
elif interface == 'dummy':
self.interfaceName = "dummy"
return # Skip libcsp initialization when using dummy responses
else:
raise ValueError("Interface {} does not exist".format(interface))
raise ValueError(f"Interface {interface} does not exist")


stringBuild = ""
for node in SatelliteNodes:
stringBuild = stringBuild + " {} {}, ".format(node[2], self.interfaceName)
stringBuild = f"{stringBuild} {node[2]} {self.interfaceName}, "
libcsp.rtable_load(stringBuild)

libcsp.route_start_task()
Expand All @@ -84,7 +84,7 @@ def receive(self, server, port, timeout):
packet = libcsp.read(conn, timeout)
data = None
if packet is None:
raise Exception("No packet received after {} seconds".format(timeout // 1000))
raise Exception(f"No packet received after {timeout // 1000} seconds")
data = packetUtils.breakPacket(packet)
libcsp.buffer_free(packet)
return data
Expand Down
22 changes: 11 additions & 11 deletions src/GNURadioHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ class GNURadioHandler:

def __init__(self):
self.server = ServerProxy('http://localhost:8080')
self.mode_dict = {0: [1200, 600],
1: [2400, 600],
2: [4800, 1200],
3: [9600, 2400],
4: [9600, 4800],
5: [19200, 4800],
6: [19200, 9600],
7: [19200, 19200]}
self.mode_dict = {
0: [1200, 600],
1: [2400, 600],
2: [4800, 1200],
3: [9600, 2400],
4: [9600, 4800],
5: [19200, 4800],
6: [19200, 9600],
7: [19200, 19200]
}


def setBaudRate(self, baud):
Expand Down Expand Up @@ -41,9 +43,7 @@ def getFSKDevHz(self):
return self.server.get_fsk_dev()

def getUHF_RFMode(self):
current_rf_config = []
current_rf_config.append(self.getBaudRate())
current_rf_config.append(self.getFSKDevHz())
current_rf_config = [self.getBaudRate(), self.getFSKDevHz()]
for key, value in self.mode_dict.items():
if value == current_rf_config:
return key
16 changes: 6 additions & 10 deletions src/beaconDecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,22 @@ def beaconBase64Decode(self):
def beaconParseData(self):
packet_num_offset = 4
beacon_ID = 99
beacon_port = 1
beacon_port = 1

try:
if self.decoded_data[packet_num_offset] == 1:
self.decoded_data[:0] = (1).to_bytes(1,'big')
return self.parser.parseReturnValue(beacon_ID, beacon_port, self.decoded_data)
elif self.decoded_data[packet_num_offset] == 2:
self.decoded_data[:0] = (2).to_bytes(1,'big')
if self.decoded_data[packet_num_offset] in {1, 2}:
self.decoded_data[:0] = self.decoded_data[packet_num_offset].to_bytes(1,'big')
return self.parser.parseReturnValue(beacon_ID, beacon_port, self.decoded_data)
else:
print("Invalid beacon packet number")
except:
except Exception:
print("Unable to parse packet data")
return None

if __name__ == '__main__':
decoder = beaconDecoder()
while True:
beacon = decoder.beaconRunDecoder()
if beacon:
if beacon := decoder.beaconRunDecoder():
print("----------Beacon Received:----------")
for key, value in beacon.items():
print("{} : {}".format(key, value))
print(f"{key} : {value}")
6 changes: 3 additions & 3 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@

class cli(GroundStation):
def run(self):
while(1):
while 1:
inStr = self.inputHandler.getInput("to send: ")
try:
transactObj = self.interactive.getTransactionObject(inStr, self.networkManager)
ret = transactObj.execute()
print()
if type(ret) == dict:
for key, value in ret.items():
print("{} : {}".format(key, value))
print(f"{key} : {value}")
elif type(ret) == list:
for r in ret:
for key, value in r.items():
print("{} : {}".format(key, value))
print(f"{key} : {value}")
else:
print(repr(ret)) # last, try to find a representation
print()
Expand Down
2 changes: 1 addition & 1 deletion src/connectionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
def getConn(self, server, port):
if server not in self.server_connection or port not in self.server_connection[server]:
try:
if server == 4 or server == 5 or server == 6: # I hate this
if server in (4, 5, 6):
conn = libcsp.connect(libcsp.CSP_PRIO_NORM, server, port, 1000, libcsp.CSP_O_CRC32)
else:
conn = libcsp.connect(libcsp.CSP_PRIO_NORM, server, port, 1000000000, libcsp.CSP_SO_HMACREQ | libcsp.CSP_SO_CRC32REQ | libcsp.CSP_SO_XTEAREQ)
Expand Down
6 changes: 4 additions & 2 deletions src/docGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
'''


'''
* @file docGen.py
* @author Andrew Rooney
Expand All @@ -30,15 +32,15 @@
subservice = services[serv]['subservice']
supported = services[serv]['supports']
for subName in subservice.keys():
f.write(serv + '.' + subName + ':\n')
f.write(f'{serv}.{subName}' + ':\n')

sub = subservice[subName]
subport = sub['subPort'] if 'subPort' in sub else None
inoutInfo = sub['inoutInfo']

args = 'None' if inoutInfo['args'] is None else repr(inoutInfo['args'])
returns = 'None' if inoutInfo['returns'] is None else repr(inoutInfo['returns'])
info = 'None' if not 'what' in sub else sub['what']
info = 'None' if 'what' not in sub else sub['what']
f.write(
'\t\tAbout: ' + info + '\n'
'\t\tSupports: ' + ', '.join(supported) + '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/dummyUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def generateFakeHKDict():
"""
fake_hk = services['HOUSEKEEPING']['subservice']['GET_HK']['inoutInfo']['returns'].copy()

fake_string = 'Test String!'
# Replace data types with values
for key in fake_hk:
fake_uint = random.randint(0, 255)
fake_int = random.randint(-128, 127)
fake_float = random.uniform(-128.0, 127.0)
fake_string = 'Test String!'
if 'B' in fake_hk[key] or 'u' in fake_hk[key] or 'V' in fake_hk[key]:
fake_hk[key] = fake_uint
elif 'b' in fake_hk[key] or 'i' in fake_hk[key]:
Expand Down
8 changes: 4 additions & 4 deletions src/embedCSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self, commandList, data):
self.schedParse = ScheduleParser()
self.data = data
self.cmdList = commandList
self.cmds = list()
self.schedule = list()
self.cmds = []
self.schedule = []

def embedCSP(self):
self._buildCommandList()
Expand All @@ -38,15 +38,15 @@ def embedCSP(self):

def _buildCommandList(self):
if len(self.cmdList) > 0:
for i in range(0, len(self.cmdList)):
for i in range(len(self.cmdList)):
# parse the time and command, then embed the command as a CSP packet
cmd = self.schedParse.parseCmd(self.cmdList[i])
command = self.inputParse.parseInput(cmd['op'])
command['first'] = cmd['first']
command['repeat'] = cmd['repeat']
command['last'] = cmd['last']
# append the list
print("Command: {}".format(command))
print(f"Command: {command}")
self.schedule.append(command)

def _buildEmbeddedPacket(self):
Expand Down
Loading