Skip to content

Commit

Permalink
Introducing CLI tv-casting-app
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Aug 5, 2021
1 parent 017daa6 commit 5c5b357
Show file tree
Hide file tree
Showing 37 changed files with 12,440 additions and 55 deletions.
15 changes: 15 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
enable_linux_tv_app_build =
enable_default_builds && (host_os == "linux" || host_os == "mac")

# Build the Linux tv casting app example.
enable_linux_tv_casting_app_build =
enable_default_builds && (host_os == "linux" || host_os == "mac")

# Build the Linux bridge app example.
enable_linux_bridge_app_build =
enable_default_builds && (host_os == "linux" || host_os == "mac")
Expand Down Expand Up @@ -338,6 +342,14 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
}
}

if (enable_linux_tv_casting_app_build) {
group("linux_tv_casting_app") {
deps = [
"${chip_root}/examples/tv-casting-app/linux(${standalone_toolchain})",
]
}
}

if (enable_linux_bridge_app_build) {
group("linux_bridge_app") {
deps =
Expand Down Expand Up @@ -435,6 +447,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
if (enable_linux_tv_app_build) {
deps += [ ":linux_tv_app" ]
}
if (enable_linux_tv_casting_app_build) {
deps += [ ":linux_tv_app" ]
}
if (enable_linux_bridge_app_build) {
deps += [ ":linux_bridge_app" ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,7 @@ void DiscoverCommissionersCommand::Shutdown()
if (commissioner != nullptr)
{
printf("Discovered Commisioner #%d\n", ++commissionerCount);
if (strcmp(commissioner->deviceName, "") != 0)
{
printf("Device Name: %s\n", commissioner->deviceName);
}
if (commissioner->vendorId > 0)
{
printf("Vendor ID: %d\n", commissioner->vendorId);
}
if (commissioner->productId > 0)
{
printf("Product ID: %d\n", commissioner->productId);
}
if (commissioner->deviceType > 0)
{
printf("Device Type: %d\n", commissioner->deviceType);
}
if (commissioner->longDiscriminator > 0)
{
printf("Long Discriminator: %d\n", commissioner->longDiscriminator);
}
if (!commissioner->IsHost(""))
{
printf("Hostname: %s\n", commissioner->hostName);
}
if (commissioner->numIPs > 0)
{
printf("Number of IP addresses: %d. IP Adddress(es): ", commissioner->numIPs);
for (int j = 0; j < commissioner->numIPs; j++)
{
char ipAddress[Inet::kMaxIPAddressStringLength];
printf("%s, ", commissioner->ipAddress[j].ToString(ipAddress, sizeof(ipAddress)));
}
printf("\n");
}

commissioner->Print();
printf("\n");
}
}
Expand Down
25 changes: 25 additions & 0 deletions examples/tv-casting-app/linux/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
import("//args.gni")
}
42 changes: 42 additions & 0 deletions examples/tv-casting-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${chip_root}/build/chip/tools.gni")

assert(chip_build_tools)

executable("chip-tv-casting-app") {
sources = [
"${chip_root}/examples/tv-casting-app/tv-casting-common/include/CHIPProjectAppConfig.h",
"main.cpp",
]

deps = [
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/examples/tv-casting-app/tv-casting-common",
"${chip_root}/src/lib",
"${chip_root}/third_party/inipp",
]

cflags = [ "-Wconversion" ]

output_dir = root_out_dir
}

group("linux") {
deps = [ ":chip-tv-casting-app" ]
}
23 changes: 23 additions & 0 deletions examples/tv-casting-app/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2020 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from generic_node_image
RUN apt-get install -y libglib2.0
COPY out/debug/chip-tv-casting-app /usr/bin/
COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh", "server"]
53 changes: 53 additions & 0 deletions examples/tv-casting-app/linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CHIP TV Casting App Example

This is a CHIP TV Casting app that can be used to cast content to a TV. This app
discovers TVs on the local network that act as commissioners, lets the user
select one, sends the TV a User Directed Commissioning request, enters
commisioning mode, advertises itself as a Commissionable Node and gets
commissioned. Then it allows the user to send CHIP ContentLauncher commands to
the TV.

<hr>

- [CHIP TV Casting App Example](#chip-tv-casting-app-example)
- [Building](#building)
- [Running the Complete Example on Linux](#running-the-complete-example-on-linux)

<hr>

<a name="building"></a>

## Building

- Install tool chain

$ sudo apt-get install git gcc g++ python pkg-config libssl-dev libdbus-1-dev libglib2.0-dev ninja-build python3-venv python3-dev unzip

- Build the example application:

$ cd ~/connectedhomeip/examples/tv-casting-app/linux
$ git submodule update --init
$ source third_party/connectedhomeip/scripts/activate.sh
$ gn gen out/debug
$ ninja -C out/debug

- To delete generated executable, libraries and object files use:

$ cd ~/connectedhomeip/examples/tv-casting-app/linux
$ rm -rf out/

<a name="running-the-complete-example-on-linux"></a>

## Running the Complete Example on Linux

- Pre-requisite: Build and run the tv-app

$ cd ~/connectedhomeip/examples/tv-app/linux
$ sudo out/debug/chip-tv-app

- Run the tv-casting-app

$ cd ~/connectedhomeip/examples/tv-casting-app/linux
$ sudo out/debug/chip-tv-casting-app

Follow the on-screen prompts on the tv-casting-app console
25 changes: 25 additions & 0 deletions examples/tv-casting-app/linux/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

import("${chip_root}/config/standalone/args.gni")

chip_device_project_config_include = "<CHIPProjectAppConfig.h>"
chip_project_config_include = "<CHIPProjectAppConfig.h>"
chip_system_project_config_include = "<SystemProjectConfig.h>"

chip_project_config_include_dirs =
[ "${chip_root}/examples/tv-casting-app/tv-casting-common/include" ]
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
1 change: 1 addition & 0 deletions examples/tv-casting-app/linux/build_overrides
29 changes: 29 additions & 0 deletions examples/tv-casting-app/linux/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -ex

service dbus start
sleep 1
/usr/sbin/otbr-agent -I wpan0 spinel+hdlc+uart:///dev/ttyUSB0 &
sleep 1
ot-ctl panid 0x1234
ot-ctl ifconfig up
ot-ctl thread start

chip-tv-casting-app
107 changes: 107 additions & 0 deletions examples/tv-casting-app/linux/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <controller/CHIPCommissionableNodeController.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>

using namespace chip;

#define TV_DEVICE_TYPE 35

CHIP_ERROR RunTimedEventLoop(uint32_t aDelayMilliseconds)
{
System::Timer * timer = nullptr;
if (DeviceLayer::SystemLayer.NewTimer(timer) == CHIP_NO_ERROR)
{
timer->Start(
aDelayMilliseconds,
[](System::Layer *, void *, CHIP_ERROR err) {
DeviceLayer::PlatformMgr().StopEventLoopTask();
DeviceLayer::PlatformMgr().Shutdown();
},
nullptr);
}
else
{
return CHIP_ERROR_INTERNAL;
}
DeviceLayer::PlatformMgr().RunEventLoop();
return CHIP_NO_ERROR;
}

void printOnboardingPayload(chip::SetupPayload payload)
{
printf("Onboarding Payload::\n");
printf("PIN: %d\n", payload.setUpPINCode);
printf("Discriminator: %d\n", payload.discriminator);
printf("Vendor ID: %d\n", payload.vendorID);
printf("Product ID: %d\n", payload.productID);
}

int main(int argc, char * argv[])
{
CHIP_ERROR err = CHIP_NO_ERROR;
int commissionerCount = 0, selectedCommissioner = CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES;
chip::Controller::CommissionableNodeController mCommissionableNodeController;
Mdns::DiscoveryFilter filter(Mdns::DiscoveryFilterType::kDeviceType, TV_DEVICE_TYPE);
chip::SetupPayload payload;
SuccessOrExit(chip::Platform::MemoryInit());
SuccessOrExit(chip::DeviceLayer::PlatformMgr().InitChipStack());

// Discover commissioner TVs
SuccessOrExit(mCommissionableNodeController.DiscoverCommissioners(filter));
SuccessOrExit(RunTimedEventLoop(2 * 1000));

// Display discovered commissioner TVs
for (int i = 0; i < CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES; i++)
{
const Mdns::DiscoveredNodeData * commissioner = mCommissionableNodeController.GetDiscoveredCommissioner(i);
if (commissioner != nullptr)
{
printf("Discovered Commisioner #%d\n", ++commissionerCount);
commissioner->Print();
printf("\n");
}
}
printf("%d commissioner(s) discovered\n", commissionerCount);

// Accept user selection for commissioner TV
VerifyOrExit(commissionerCount > 0, err = CHIP_NO_ERROR);
printf("Choose a commissioner TV (by number# above) to request commissioning from: ");
scanf("%d", &selectedCommissioner);

// Initiate commissionning with selected commissioner TV
SuccessOrExit(chip::DeviceLayer::PlatformMgr().InitChipStack());
SuccessOrExit(mCommissionableNodeController.RequestCommissioning(selectedCommissioner));
SuccessOrExit(mCommissionableNodeController.GetOnboardingPayload(payload));
printOnboardingPayload(payload);
SuccessOrExit(RunTimedEventLoop(3 * 60 * 1000));

// TBD: Implement casting to TV

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Failed to run TV Casting App:: %s", ErrorStr(err));
// End the program with non zero error code to indicate an error.
return 1;
}
return 0;
}
1 change: 1 addition & 0 deletions examples/tv-casting-app/linux/third_party/connectedhomeip
Loading

0 comments on commit 5c5b357

Please sign in to comment.