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

Service names #14

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
16a9a33
python shebang
lutherling12 Nov 16, 2017
be286ee
services test program
lutherling12 Nov 16, 2017
f111304
added chaos layer and utilities
lutherling12 Nov 16, 2017
df4fe07
stop sending cats
lutherling12 Nov 16, 2017
59d9d57
Merge branch 'services_test'
lutherling12 Nov 16, 2017
f8f7b92
removed addr from frame header
Zmathue Nov 16, 2017
dced608
Adding fragment culling at egress saturation.
haineb Nov 16, 2017
96768c9
Adding PDU strip/add to ZMQ interfaces.
haineb Nov 16, 2017
e59ff54
Fixing PDU encapsulation type bug.
haineb Nov 16, 2017
e2fa819
Surpressing requires for setup.
haineb Nov 16, 2017
934056e
fixing culling bug.
haineb Nov 17, 2017
2ed4ccc
conflict resolution
lutherling12 Nov 17, 2017
9d0f355
decode and dump mavlink message types
lutherling12 Nov 17, 2017
249260c
conflict res
lutherling12 Nov 17, 2017
5110370
cl args passed correctly
lutherling12 Nov 17, 2017
ae0a8da
Re-enabling RTP. Breaks SITL integration.
haineb Nov 16, 2017
17790f8
Fixed ssrc numbers and timestamp type issues. Also removed upper boun…
cvdario Nov 16, 2017
3effddb
Cleaned up some prints
cvdario Nov 16, 2017
393566f
Resolved rtp handler stripping too much data. Successfully ran contro…
cvdario Nov 16, 2017
abea80f
Postmaster will now drop packets ir RTP seq_num is not valid.
cvdario Nov 16, 2017
41a268f
Access point scanner and visualization stuff.
cvdario Nov 17, 2017
6d23ddf
Kept playing with matplotlib.
cvdario Nov 17, 2017
474f42d
Adding frame level debugging.
haineb Nov 16, 2017
69c17a3
added zmq
Zmathue Nov 17, 2017
194af2b
label services for debugging
lutherling12 Nov 17, 2017
d4d87a0
label services for debugging
lutherling12 Nov 17, 2017
91c2591
Merge branch 'service_names' of https://github.com/lutherling12/ASLHa…
lutherling12 Nov 17, 2017
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
53 changes: 30 additions & 23 deletions apps/netCat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ def __init__(self, img_fp, ip_address='127.0.0.1', port='6127'):
self.pub.bind('tcp://%s:%s' % (self._ip, self._port))

def send(self):
try:
img = Image.open(self._img_file)
img_pickled = pickle.dumps(img)
img = Image.open(self._img_file)
img_pickled = pickle.dumps(img)

print("sending {fp}".format(fp=self._img_file))
self.pub.send(img_pickled)
print("done sending {fp}".format(fp=self._img_file))
except:
print("failed to send")
print("sending {fp}".format(fp=self._img_file))
self.pub.send(img_pickled)
print("done sending {fp}".format(fp=self._img_file))

class netCatReceiver(netCat):
def __init__(self, ip_address='127.0.0.1', port='6127'):
Expand Down Expand Up @@ -63,35 +60,45 @@ def __init__(self):
self.receiver = netCatReceiver()
# usage: netCat.py (image_file)
elif len(sys.argv) == 2:
self.sender = netCatSender(sys.argv[1])
self.sender = netCatSender(img_fp=sys.argv[1])
self.receiver = None
# usage: netCat.py (ip, port)
elif len(sys.argv) == 3:
self.sender = None
self.receiver = netCatReceiver()
self.receiver = netCatReceiver(\
ip_address=sys.argv[1], \
port=sys.argv[2] \
)
# usage: netCat.py (image_file, ip, port)
elif len(sys.argv) == 4:
self.sender = netCatSender(sys.argv[1])
self.sender = netCatSender(\
img_fp=sys.argv[1], \
ip_address=sys.argv[2],\
port=sys.argv[3] \
)
self.receiver = None
else:
print("receive: ./netCat.py \n transmit: ./netCat.py cat_image")


def run(self):
if len(sys.argv) > 1:
self.sender.send()
else:
self.receiver.recv()
while True:
try:
if self.sender is not None:
self.sender.send()
if self.receiver is not None:
self.receiver.recv()
except KeyboardInterrupt:
nc.sit()
break
except:
if self.sender is not None:
print "failed to send"
if self.receive is not None:
print "failed to receive"

def sit(self):
print("good kitty!")

if __name__ == "__main__":
nc = netCatLauncher()
while True:
try:
nc.run()
except KeyboardInterrupt:
# BUG: sender will not call sit() on SIGINT
nc.sit()
break
nc.run()
10 changes: 5 additions & 5 deletions apps/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def run(self):

services = {}
radio = {
'service': Service(portIn = 6126, portOut = 6127),
'service': Service(portIn = 6126, portOut = 6127, name = 'radio'),
'type': 'radio',
'config': None,
}
Expand All @@ -26,7 +26,7 @@ def run(self):
'ssrc': 0,
}
mavlink = {
'service': Service(portIn = 6128, portOut = 6131),
'service': Service(portIn = 6128, portOut = 6131, name = 'gcs?'),
'type': 'client',
'config': mavlink_config,
}
Expand All @@ -37,7 +37,7 @@ def run(self):
'ssrc': 1,
}
cats = {
'service': Service(portIn = 5058, portOut = 5059),
'service': Service(portIn = 5058, portOut = 5059, name = 'cats'),
'type': 'client',
'config': cats_config,
}
Expand All @@ -57,7 +57,7 @@ def run(self):
'ssrc': 0,
}
mavlink = {
'service': Service(portIn = 6130, portOut = 6129),
'service': Service(portIn = 6130, portOut = 6129, name = 'uav?'),
'type': 'client',
'config': mavlink_config,
}
Expand All @@ -68,7 +68,7 @@ def run(self):
'ssrc': 1,
}
cats = {
'service': Service(portIn = 5158, portOut = 5159),
'service': Service(portIn = 5158, portOut = 5159, name = 'cats?'),
'type': 'client',
'config': cats_config,
}
Expand Down
27 changes: 27 additions & 0 deletions asl_sdr_hackfest/pmt_mav_dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pymavlink import mavutil
import pmt
import numpy

class PMT_MAV_dump(object):
# NOTE: default arguments derived from MAVProxy's --master argument
def __init__(self, ip = "127.0.0.1", remote_port = 5760, protocol = 'tcp'):
print ('connecting to %s:%s:%d' % (protocol, ip, remote_port))
self.mc = mavutil.mavlink_connection(device='%s:%s:%d' % (protocol, ip, remote_port), retries = 9000)

# NOTE: have this method invert ZMQ_pub modules' send method
def method(self, pmt_cons):
s = pmt.deserialize_str(pmt_cons)

if pmt.is_pair(s):
car = pmt.car(s)
cdr = pmt.to_python(pmt.cdr(s))
cdr = numpy.getbuffer(cdr)

meta = car
data = self.mc.mav.decode(bytearray(cdr))

# NOTE: to fully parse fields of message use this for reference:
# https://www.samba.org/tridge/UAV/pymavlink/apidocs/classIndex.html
return \
"gr metadata: %s \
message type: %s" % (meta, data.get_type())
39 changes: 27 additions & 12 deletions asl_sdr_hackfest/postmaster.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/python

import threading
import binascii

from asl_sdr_hackfest.service import Service

Expand Down Expand Up @@ -49,14 +52,20 @@ def __init__(self, services_config):
'''

self.frame_rx = NetworkLayerReceiveHandler(output_data_func = self.frameDeframed)
self.frame_tx = NetworkLayerTransmitHandler(output_data_func = self.services['radio']['service'].outputData)
self.frame_tx = NetworkLayerTransmitHandler(output_data_func = self.debugTxCallback)

self.rtp_handler_rx = RTP_Handler()
self.rtp_handler_tx = RTP_Handler()

threading.Thread.__init__(self)


def debugTxCallback(self, data):
print('Transmitting frame:')
print(binascii.hexlify(data))
self.services['radio']['service'].outputData(data)


def run(self):
self.running = True

Expand All @@ -73,10 +82,12 @@ def run(self):
if data is None:
continue
if srv['type'] == 'radio':
print('Receiving frame:')
print(binascii.hexlify(data))
self.frame_rx.ingest_data(data)
elif srv['type'] == 'client':
# rtp_header = self.rtp_handler_tx.tx(srv['config']['ssrc'], 'gsm') # This is a byte array, not a header class
# data = rtp_header + data
rtp_header = self.rtp_handler_tx.tx(srv['config']['ssrc'], 'gsm') # This is a byte array, not a header class
data = rtp_header + data
qos_header = QoS.header_calculate(data) # This is a header class, not a byte array
qos_header.set_priority_code(srv['config']['qos'])
data = qos_header.to_bytearray() + data
Expand All @@ -85,16 +96,20 @@ def run(self):

def frameDeframed(self, data):
cls, data = QoS.header_consume(data)
#rtp_header is an instance of RTP
rtp_header_and_validity, data = self.rtp_handler_rx.header_consume(data)
rtp_header = rtp_header_and_validity[0]
validity = rtp_header_and_validity[1]
# Seq number is valid, process data
if validity:
ssrc = rtp_header.get_ssrc()
for srv in self.services:
srv = self.services[srv]
if srv['type'] == 'client':
conf = srv['config']
if conf is not None and ssrc == conf['ssrc']:
srv['service'].outputData(data)

# rtp_header, data = self.rtp_handler_rx.header_consume(data)
# ssrc = rtp_header.get_ssrc()

for srv in self.services:
srv = self.services[srv]
if srv['type'] == 'client':
# conf = srv['config']
# if conf is not None and ssrc == conf['ssrc']:
srv['service'].outputData(data)


def stop(self):
Expand Down
2 changes: 1 addition & 1 deletion asl_sdr_hackfest/protocols/network_layer_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def egress_cull(self):
if cos > max_cos:
max_cos = cos

for i in reversed(range(0,len(tmp_egress))):
for i in reversed(range(0,len(tmp_egress))):
if to_drop <= 0:
break

Expand Down
2 changes: 1 addition & 1 deletion asl_sdr_hackfest/protocols/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def bin_formater(self, value, length):
return "0b" + f
#if (isinstance(value, str) and (length == 32)):
elif isinstance(value, str):
print("Packed str = ", ("0b" + ''.join('{0:08b}'.format(x, 'b') for x in bytearray(value))))
#print("Packed str = ", ("0b" + ''.join('{0:08b}'.format(x, 'b') for x in bytearray(value))))
return ("0b" + ''.join('{0:08b}'.format(x, 'b') for x in bytearray(value)))
else:
try:
Expand Down
9 changes: 9 additions & 0 deletions asl_sdr_hackfest/protocols/rtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class RTP(Protocol):
#34 : 'h263'
}

# HEADER_SIZE in bits
HEADER_SIZE = 128
# HEADER_LENGTH in bytes
HEADER_LENGTH = 16

def __init__(self, *args, **kwargs):
self.version = kwargs.get('version')
Expand Down Expand Up @@ -50,12 +53,18 @@ def to_bitarray(self):
ba = BitArray(self.TWO2)
ba.append(self.TRUE) if self.padding else ba.append(self.FALSE)
ba.append(self.TRUE) if self.extension else ba.append(self.FALSE)
#print("Format csrc_count")
ba.append(self.bin_formater(self.csrc_count, 4))
ba.append(self.TRUE) if self.marker else ba.append(self.FALSE)
#print("Format payload_type")
ba.append(self.bin_formater(self.payload_type, 7))
#print("Format seq_num")
ba.append(self.bin_formater(self.seq_num, 16))
#print("Format timestamp")
ba.append(self.bin_formater(self.timestamp, 32))
#print("Format ssrc")
ba.append(self.bin_formater(self.ssrc, 32))
#print("Format csrc")
ba.append(self.bin_formater(self.csrc, 32))
return ba

Expand Down
Loading