/* * * 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. */ #include #include "CHIPDeviceManager.h" #include "DeviceCallbacks.h" #include "chip_porting.h" #include #include #include #include #include #include #include #include #include using chip::ByteSpan; using chip::EndpointId; using chip::FabricIndex; using chip::NodeId; using chip::OnDeviceConnected; using chip::OnDeviceConnectionFailure; using chip::PeerId; using chip::Server; using chip::VendorId; using chip::Callback::Callback; using chip::System::Layer; using chip::Transport::PeerAddress; using namespace chip::Messaging; using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands; using namespace ::chip; using namespace ::chip::DeviceManager; using namespace ::chip::DeviceLayer; namespace { // Network Commissioning constexpr EndpointId kNetworkCommissioningEndpointMain = 0; constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE; app::Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */, &(NetworkCommissioning::AmebaWiFiDriver::GetInstance())); } // namespace void NetWorkCommissioningInstInit() { sWiFiNetworkCommissioningInstance.Init(); // We only have network commissioning on endpoint 0. emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); } static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; static void InitServer(intptr_t context) { // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); NetWorkCommissioningInstInit(); } extern "C" void ChipTest(void) { ChipLogProgress(SoftwareUpdate, "ota-requestor!"); CHIP_ERROR err = CHIP_NO_ERROR; initPref(); CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); err = deviceMgr.Init(&EchoCallbacks); if (err != CHIP_NO_ERROR) { ChipLogError(DeviceLayer, "DeviceManagerInit() - ERROR!\r\n"); } else { ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n"); } chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0); }