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

Improve is 05 control #701

Open
wants to merge 2 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
39 changes: 24 additions & 15 deletions utilities/is-05-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,38 @@ optional arguments:
--version VERSION Version of IS-05 API of DuT
-s, --sender Configure NMOS Sender
-r, --receiver Configure NMOS Receiver
--request REQUEST JSON data to be sent in the request to configure
sender
--sdp SDP SDP file to be sent in the request to configure
receiver
--request REQUEST JSON data to be sent in the request to configure sender
--sdp SDP SDP file to be queried from a Sender (write) or be sent to a Receiver (read)
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explanation of --sdp is a bit hard to understand... maybe:

Suggested change
--request REQUEST JSON data to be sent in the request to configure sender
--sdp SDP SDP file to be queried from a Sender (write) or be sent to a Receiver (read)
--request REQUEST Input JSON file for PATCH /staged request to the Sender
--sdp SDP Input SDP file for PATCH /staged request to the Receiver, or
Output SDP file for GET /transportfile response from the Sender

-u UUID, --uuid UUID UUID of resource to be configured
```

Example call to change receiver
Inside the script the IS-05 device can be controlled with the following keys
```
python3 is05Control.py --ip <hostname or IP> --port <IS-05 Port> --version <IS-05 Version> --receiver --uuid <Receiver ID> --request tune-receiver-to-reference.json --sdp video-1080i-7.sdp
Press 'e' to set master_enable True
Press 'd' to set master_enable False
Press 'c' to set a valid config on a Sender or a Receiver
Press 'u' to set a dummy config on a Sender or a Receiver
Press '7' to set 2022-7 Sender to dummy config
Press 's' to get SDP file (and save to "./latest.sdp" from a Sender)
Waiting for input...
```

Example call to enable sender
## Example: create a media connection

1. Connect to a sender:

```
python3 is05Control.py --ip <hostname or IP> --port <IS-05 Port> --version <IS-05 Version> --sender --uuid <Sender ID> --request sender-to-20-1080i-7.json
python3 is05Control.py --ip <hostname or IP> --port <IS-05 Port> --version <IS-05 Version> --sender --uuid <Sender ID> --request sender-to-20-1080i-7.json --sdp new.sdp
```

Inside the script the IS-05 device can be controlled with the following keys
2. Enable (`e`)
3. Push a valid RTP config (`c`)
4. Save SDP file (`s`)
Comment on lines +56 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial nit: seems a bit inconsistent to use parentheses and backticks for the commands here but single quote marks above?

5. Connect to a receiver:

```
Press 'e' to set master_enable True
Press 'd' to set master_enable False
Press 'c' to set Sender or Receiver to valid config
Press 'u' to set Sender or Receiver to dummy config
Press '7' to set 2022-7 Sender to dummy config
Waiting for input...
python3 is05Control.py --ip <hostname or IP> --port <IS-05 Port> --version <IS-05 Version> --receiver --uuid <Receiver ID> --sdp new.sdp
```

6. Enable (`e`)
7. Push the new SDP (`c`)
88 changes: 61 additions & 27 deletions utilities/is-05-control/is05Control.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def set_master_enable(url, state):
}
}

send_request(url, body)
send_patch_request(url, body)


def configure_sender(url, config):
print('Configuring Sender')
send_request(url, config)
send_patch_request(url, config)


def configure_receiver(url, sender_id, sdp_data):
Expand All @@ -111,23 +111,43 @@ def configure_receiver(url, sender_id, sdp_data):
print("Using SDP file")
body["transport_file"] = {"data": sdp_data, "type": "application/sdp"}

send_request(url, body)
send_patch_request(url, body)

def send_get_request(url):
try:
response = requests.get(url, timeout=2)
if response.status_code in [200]:
print("Successful GET request\n")
rep=response.headers['content-type']
if 'json' in rep:
return response.json()
elif 'sdp' in rep:
return response.text
else:
print(response)
return response
else:
print("GET Request Failed\n")
print(response.status_code)
print(response.text)
except Exception as e:
print(" * ERROR: Unable to get data to {}".format(url))
print(e)

def send_request(url, body):
def send_patch_request(url, body):
try:
response = requests.patch(url, timeout=2, json=body)
if response.status_code in [200]:
print("Successful request")
print("Successful PATCH request. Response body:\n")
print(json.dumps(response.json(), indent=4))
else:
print("Request Failed")
print("PATCH Request Failed\n")
print(response.status_code)
print(response.text)
except Exception as e:
print(" * ERROR: Unable to patch data to {}".format(url))
print(e)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", required=True, help="IP address or Hostname of DuT")
Expand All @@ -136,22 +156,22 @@ def send_request(url, body):
parser.add_argument("-s", "--sender", action="store_true", help="Configure NMOS Sender")
parser.add_argument("-r", "--receiver", action="store_true", help="Configure NMOS Receiver")
parser.add_argument("--request", help="JSON data to be sent in the request to configure sender")
parser.add_argument("--sdp", help="SDP file to be sent in the request to configure receiver")
parser.add_argument("--sdp", help="SDP file to be queried from a Sender (write) or be sent to a Receiver (read)")
Comment on lines 158 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Comment in the README.md)

parser.add_argument("-u", "--uuid", required=True, help="UUID of resource to be configured")
args = parser.parse_args()

# Configure for Sender or Receiver
if args.sender:
print("Configuring NMOS Sender using IS-05")
url = "http://{}:{}/x-nmos/connection/{}/single/senders/{}/staged".format(
url = "http://{}:{}/x-nmos/connection/{}/single/senders/{}".format(
args.ip,
args.port,
args.version,
args.uuid
)
elif args.receiver:
print("Configuring NMOS Receiver using IS-05")
url = "http://{}:{}/x-nmos/connection/{}/single/receivers/{}/staged".format(
url = "http://{}:{}/x-nmos/connection/{}/single/receivers/{}".format(
args.ip,
args.port,
args.version,
Expand All @@ -162,6 +182,8 @@ def send_request(url, body):
sys.exit()

print(url)
url_staged = url + '/staged'
url_transport = url + '/transportfile'

# Read PATCH request JSON
if args.request:
Expand All @@ -172,14 +194,8 @@ def send_request(url, body):
print("Request file \"{}\" does not exist".format(args.request))
sys.exit()

# Read SDP file
if args.sdp:
if os.path.exists(args.sdp):
with open(args.sdp, "r") as sdp_file:
sdp_payload = sdp_file.read()
else:
print("SDP file \"{}\" does not exist".format(args.sdp))
sys.exit()
# Check SDP file
sdp_filename = args.sdp if args.sdp else "latest.sdp"

# Read dummy SDP file
with open("dummy-sdp.sdp", "r") as sdp_file:
Expand All @@ -188,32 +204,50 @@ def send_request(url, body):
while(True):
print('\nPress \'e\' to set master_enable True')
print('Press \'d\' to set master_enable False')
print('Press \'c\' to set Sender or Receiver to valid config')
print('Press \'u\' to set Sender or Receiver to dummy config')
print('Press \'c\' to set a valid config on a Sender or a Receiver')
print('Press \'u\' to set a dummy config on a Sender or a Receiver')
print('Press \'7\' to set 2022-7 Sender to dummy config')
print('Press \'s\' to get SDP file (and save to "./{}" from a Sender)'.format(sdp_filename))

print('Waiting for input...\n')
# Check for escape character
ch = getch()
if ch in [b'\x03', b'q', '\x03', 'q', 'Q']:
break

# Reload

if ch == 'e':
set_master_enable(url, True)
set_master_enable(url_staged, True)
elif ch == 'd':
set_master_enable(url, False)
set_master_enable(url_staged, False)
elif ch == 'c':
if args.sender:
configure_sender(url, request_payload)
configure_sender(url_staged, request_payload)
else:
configure_receiver(url, "1e1c78ae-1dd2-11b2-8044-cc988b8696a2", sdp_payload)
if os.path.exists(sdp_filename):
with open(sdp_filename, "r") as sdp_file:
sdp_payload = sdp_file.read()
configure_receiver(url_staged, "1e1c78ae-1dd2-11b2-8044-cc988b8696a2", sdp_payload)
else:
print("SDP file not found: {}".format(sdp_filename))
elif ch == 'u':
if args.sender:
configure_sender(url, dummy_data)
configure_sender(url_staged, dummy_data)
else:
configure_receiver(url, "xxxxxxxx-1dd2-xxxx-8044-cc988b8696a2", dummy_sdp_payload)
configure_receiver(url_staged, "aaaaaaaa-1dd2-11b2-8044-cc988b8696a2", dummy_sdp_payload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it was expecting that no-one validated the sender_id! Good change!

elif ch == '7':
if args.sender:
configure_sender(url, dummy_data_7)
configure_sender(url_staged, dummy_data_7)
elif ch == 's':
if args.sender:
sdp = send_get_request(url_transport)
print(sdp)
with open(sdp_filename, "w") as sdp_file:
sdp_file.write(sdp)
print("----------------------> Saved to ./{}".format(sdp_filename))
else:
rep = send_get_request(url_staged)
print(rep ["transport_file"]["data"])

print('Escape character found')