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

Integration Candidate 20191230 #47

Merged
merged 2 commits into from
Jan 9, 2020
Merged
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
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