Skip to content

Commit

Permalink
CCB 20191218: Merge #41
Browse files Browse the repository at this point in the history
Fix #35 
Reviewed and approved at 2019-12-18 CCB
  • Loading branch information
skliper authored Dec 30, 2019
2 parents adad5ac + b5050a9 commit de8c151
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
4 changes: 2 additions & 2 deletions GroundSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, parent=None):
def closeEvent(self, evnt):
if self.RoutingService:
self.RoutingService.stop()
print "Stopped routing service"
print ("Stopped routing service")

super(GroundSystem, self).closeEvent(evnt)

Expand All @@ -70,7 +70,7 @@ def getSelectedSpacecraftName(self):
# Display popup with error
#
def DisplayErrorMessage(self, message):
print message
print (message)
alert = QtGui.QMessageBox()
alert.setText(message)
alert.setIcon(QtGui.QMessageBox.Warning)
Expand Down
77 changes: 44 additions & 33 deletions RoutingService.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,55 @@ def run(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.bind(('', udpRecvPort))

# Wait for UDP messages
while True:
try:
# Receive message
datagram, host = self.sock.recvfrom(4096) # buffer size is 1024 bytes

# Ignore datagram if it is not long enough (doesnt contain tlm header?)
if len(datagram) < 6:
continue

# Read host address
hostIpAddress = host[0]

#
# Add Host to the list if not already in list
#
if not any(hostIpAddress in s for s in self.ipAddressesList):
hostName = "Spacecraft" + str(len(self.spacecraftNames))
print "Detected " + hostName + " at " + hostIpAddress
self.ipAddressesList.append(hostIpAddress);
self.spacecraftNames.append(hostName)
self.emit(self.signalUpdateIpList, hostIpAddress, hostName)

# Forward the message using zeroMQ
name = self.spacecraftNames[self.ipAddressesList.index(hostIpAddress)]
self.forwardMessage(datagram, name)

# Handle errors
except socket.error, v:
print 'Ignored socket error.'
sleep(1)
print ('Attempting to wait for UDP messages')

socketErrorCount = 0
while socketErrorCount < 5:

# Wait for UDP messages
while True:
try:
# Receive message
datagram, host = self.sock.recvfrom(4096) # buffer size is 1024 bytes

print ('length datagram: %d' % len(datagram))

# Ignore datagram if it is not long enough (doesnt contain tlm header?)
if len(datagram) < 6:
continue

# Read host address
hostIpAddress = host[0]

#
# Add Host to the list if not already in list
#
if not any(hostIpAddress in s for s in self.ipAddressesList):
hostName = 'Spacecraft' + str(len(self.spacecraftNames))
my_hostName_as_bytes = str.encode(hostName)
print ("Detected " + hostName + " at " + hostIpAddress)
self.ipAddressesList.append(hostIpAddress);
self.spacecraftNames.append(my_hostName_as_bytes)
self.emit(self.signalUpdateIpList, hostIpAddress, my_hostName_as_bytes)

# Forward the message using zeroMQ
name = self.spacecraftNames[self.ipAddressesList.index(hostIpAddress)]
self.forwardMessage(datagram, name)

# Handle errors
except socket.error as v:
print ('Ignored socket error for attempt %s' % socketErrorCount)
socketErrorCount = socketErrorCount + 1
sleep(1)

# Apply header using hostname and packet id and send msg using zeroMQ
def forwardMessage(self, datagram, hostName):
# Forward message to channel GroundSystem.<Hostname>.<pktId>
pktId = self.getPktId(datagram)
header = "GroundSystem." + hostName + ".TelemetryPackets." + pktId
self.publisher.send_multipart([header, datagram])
my_decoded_hostName = hostName.decode()
header = "GroundSystem." + my_decoded_hostName + ".TelemetryPackets." + pktId
my_header_as_bytes = str.encode(header)
self.publisher.send_multipart([my_header_as_bytes, datagram])
#print header


Expand Down

0 comments on commit de8c151

Please sign in to comment.