Skip to content

Commit

Permalink
Merge branch 'master' into ncs202use
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple authored Jul 29, 2022
2 parents 2fd9ac7 + cd9a857 commit f4a9237
Show file tree
Hide file tree
Showing 33 changed files with 624 additions and 172 deletions.
12 changes: 12 additions & 0 deletions examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,18 @@ void * bridge_polling_thread(void * context)
// TC-ACT-2.2 step 3i, add "Turn off Room 1 renamed lights"
action3.setIsVisible(true);
}

// Commands used for the Bridged Device Basic Information test plan
if (ch == 'u')
{
// TC-BRBINFO-2.2 step 2 "Set reachable to false"
TempSensor1.SetReachable(false);
}
if (ch == 'v')
{
// TC-BRBINFO-2.2 step 2 "Set reachable to true"
TempSensor1.SetReachable(true);
}
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/chef/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ executable("${sample_name}") {

sources += [
"${chip_root}/examples/platform/linux/Rpc.cpp",
"${dir_pigweed}/targets/host/system_rpc_server.cc",
"${chip_root}/examples/platform/linux/system_rpc_server.cc",
]

deps += [
Expand Down
5 changes: 5 additions & 0 deletions examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ if (efr32_board == "BRD4166A" || efr32_board == "BRD4180A") {

# WiFi settings
if (chip_enable_wifi) {
# disabling LCD for MG24 for wifi
if (efr32_board == "BRD4186A" || efr32_board == "BRD4187A") {
show_qr_code = false
disable_lcd = true
}
wifi_sdk_dir = "${chip_root}/third_party/silabs/matter_support/matter/wifi"
efr32_lwip_defs = [ "LWIP_NETIF_API=1" ]
efr32_lwip_defs += [
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ executable("chip-lighting-app") {

sources += [
"${chip_root}/examples/platform/linux/Rpc.cpp",
"${dir_pigweed}/targets/host/system_rpc_server.cc",
"${chip_root}/examples/platform/linux/system_rpc_server.cc",
]

deps += [
Expand Down
8 changes: 0 additions & 8 deletions examples/lighting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#include <lib/support/logging/CHIPLogging.h>
#include <platform/Linux/NetworkCommissioningDriver.h>

#if defined(PW_RPC_ENABLED)
#include "Rpc.h"
#endif // PW_RPC_ENABLED

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
Expand Down Expand Up @@ -79,10 +75,6 @@ void ApplicationInit()

int main(int argc, char * argv[])
{
#if PW_RPC_ENABLED
chip::rpc::Init();
#endif

if (ChipLinuxAppInit(argc, argv) != 0)
{
return -1;
Expand Down
118 changes: 118 additions & 0 deletions examples/platform/linux/system_rpc_server.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
*
* Copyright (c) 2021 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.
*
* This file is a fork from: third_party/pigweed/repo/targets/host/system_rpc_server.cc
* But changes the disconnect behaviour from closing and returning, to awaiting a
* reconnection.
*/

#include <cstddef>
#include <cstdint>
#include <cstdio>

#include "pw_assert/check.h"
#include "pw_hdlc/rpc_channel.h"
#include "pw_hdlc/rpc_packets.h"
#include "pw_log/log.h"
#include "pw_rpc_system_server/rpc_server.h"
#include "pw_stream/socket_stream.h"

namespace pw::rpc::system_server {
namespace {

constexpr size_t kMaxTransmissionUnit = 512;
uint16_t socket_port = 33000;

stream::SocketStream socket_stream;

hdlc::RpcChannelOutput hdlc_channel_output(socket_stream, hdlc::kDefaultRpcAddress, "HDLC channel");
Channel channels[] = { rpc::Channel::Create<1>(&hdlc_channel_output) };
rpc::Server server(channels);

} // namespace

void set_socket_port(uint16_t new_socket_port)
{
socket_port = new_socket_port;
}

int GetServerSocketFd()
{
return socket_stream.connection_fd();
}

void Init()
{
log_basic::SetOutput([](std::string_view log) {
std::fprintf(stderr, "%.*s\n", static_cast<int>(log.size()), log.data());
hdlc::WriteUIFrame(1, as_bytes(span(log)), socket_stream).IgnoreError(); // TODO(pwbug/387): Handle Status properly
});

PW_LOG_INFO("Starting pw_rpc server on port %d", socket_port);
PW_CHECK_OK(socket_stream.Serve(socket_port));
}

rpc::Server & Server()
{
return server;
}

Status Start()
{
// Declare a buffer for decoding incoming HDLC frames.
std::array<std::byte, kMaxTransmissionUnit> input_buffer;
hdlc::Decoder decoder(input_buffer);

while (true)
{
std::array<std::byte, kMaxTransmissionUnit> data;
auto ret_val = socket_stream.Read(data);
if (!ret_val.ok())
{
if (ret_val.status() == Status::OutOfRange())
{
// An out of range status indicates the remote end has disconnected.
// Start to serve the connection again, which will allow another
// remote to connect.
PW_CHECK_OK(socket_stream.Serve(socket_port));
}
continue;
}

for (std::byte byte : ret_val.value())
{
auto result = decoder.Process(byte);
if (!result.ok())
{
// Non-OK means there isn't a complete packet yet, or there was some
// other issue. Wait for more bytes that form a complete packet.
continue;
}
hdlc::Frame & frame = result.value();
if (frame.address() != hdlc::kDefaultRpcAddress)
{
// Wrong address; ignore the packet for now. In the future, this branch
// could expand to add packet routing or metrics.
continue;
}

server.ProcessPacket(frame.data(), hdlc_channel_output).IgnoreError();
}
}
}

} // namespace pw::rpc::system_server
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import com.matter.tv.server.R;
import com.matter.tv.server.tvapp.AppPlatformShellCommands;

/**
* A simple {@link Fragment} subclass. Use the {@link TerminalFragment#newInstance} factory method
Expand All @@ -16,9 +18,23 @@
public class TerminalFragment extends Fragment {

private EditText terminalText;
private TextView terminalUsageDescription;
private AppPlatformShellCommands shellCommands;

private static String TERMINAL_INSTRUCTIONS =
"add <vid> [<pid>] Add app with given vendor ID [1, 2, 9050]. Usage: app add 9050\r\n"
+ "remove <endpoint> Remove app at given endpoint [6, 7, etc]. Usage: app remove 6\r\n"
+ "setpin <endpoint> <pincode> Set pincode for app with given endpoint ID. Usage: app setpin 6 34567890\r\n"
+ "commission <udc-entry> Commission given udc-entry using given pincode from corresponding app. Usage:"
+ "app commission 0\r\n"
+ "add-admin-vendor <vid> Add vendor ID to list which will receive admin privileges. Usage: app "
+ "add-admin-vendor 65521\r\n"
+ "print-app-access Print all ACLs for app platform fabric. Usage: app print-app-access\r\n"
+ "remove-app-access Remove all ACLs for app platform fabric. Usage: app remove-app-access\r\n";

public TerminalFragment() {
// Required empty public constructor
shellCommands = new AppPlatformShellCommands();
}

/**
Expand Down Expand Up @@ -51,16 +67,20 @@ public void onResume() {
super.onResume();

terminalText = getView().findViewById(R.id.terminalTxt);
terminalUsageDescription = getView().findViewById(R.id.terminalDescriptionTxt);
terminalUsageDescription.setText(TERMINAL_INSTRUCTIONS);

getView()
.findViewById(R.id.OkBtn)
.setOnClickListener(
v -> {
String message = terminalText.getText().toString();

String response = shellCommands.OnExecuteCommand(message.split(" "));

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

builder.setMessage(message).setTitle("Response").create().show();
builder.setMessage(response).setTitle("Response").create().show();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

<TextView
android:id="@+id/terminalDescriptionTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/OkBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="20dp" />


</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions examples/tv-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ shared_library("jni") {
"include/target-navigator/TargetNavigatorManager.h",
"java/AppImpl.cpp",
"java/AppImpl.h",
"java/AppPlatformShellCommands-JNI.cpp",
"java/AppPlatformShellCommands-JNI.h",
"java/ChannelManager.cpp",
"java/ChannelManager.h",
"java/ClusterChangeAttribute.cpp",
Expand Down Expand Up @@ -105,6 +107,7 @@ android_library("java") {
]

sources = [
"java/src/com/matter/tv/server/tvapp/AppPlatformShellCommands.java",
"java/src/com/matter/tv/server/tvapp/ChannelInfo.java",
"java/src/com/matter/tv/server/tvapp/ChannelLineupInfo.java",
"java/src/com/matter/tv/server/tvapp/ChannelManager.java",
Expand Down
1 change: 0 additions & 1 deletion examples/tv-app/android/java/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ CHIP_ERROR InitVideoPlayerPlatform(JNIMyUserPrompter * userPrompter, jobject con
// supported clusters so that ZAP will generated the requisite code.
ChipLogDetail(DeviceLayer, "TV App: Disabling Fixed Content App Endpoints");
emberAfEndpointEnableDisable(3, false);

return CHIP_NO_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/AppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
protected:
std::vector<ContentAppImpl *> mContentApps{
new ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "20202021", nullptr),
new ContentAppImpl("Vendor2", 65520, "exampleString", 32768, "Version2", "20202021", nullptr),
new ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021", nullptr),
new ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021", nullptr),
new ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021", nullptr)
};
Expand Down
Loading

0 comments on commit f4a9237

Please sign in to comment.