|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2024 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +#include <AppMain.h> |
| 19 | +#include <app-common/zap-generated/ids/Clusters.h> |
| 20 | +#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h> |
| 21 | +#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h> |
| 22 | +#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.h> |
| 23 | +#include <lib/support/logging/CHIPLogging.h> |
| 24 | +#include <platform/KvsPersistentStorageDelegate.h> |
| 25 | + |
| 26 | +using namespace chip; |
| 27 | +using namespace chip::app; |
| 28 | +using namespace chip::app::Clusters; |
| 29 | +using namespace chip::app::Clusters::ValveConfigurationAndControl; |
| 30 | +namespace { |
| 31 | +class PrintOnlyDelegate : public NonLevelControlDelegate |
| 32 | +{ |
| 33 | +public: |
| 34 | + PrintOnlyDelegate(EndpointId endpoint) : mEndpoint(endpoint) {} |
| 35 | + CHIP_ERROR HandleOpenValve(ValveStateEnum & currentState, BitMask<ValveFaultBitmap> & valveFault) override |
| 36 | + { |
| 37 | + ChipLogProgress(NotSpecified, "VALVE IS OPENING!!!!!"); |
| 38 | + state = ValveStateEnum::kOpen; |
| 39 | + currentState = state; |
| 40 | + return CHIP_NO_ERROR; |
| 41 | + } |
| 42 | + ValveStateEnum GetCurrentValveState() override { return state; } |
| 43 | + CHIP_ERROR HandleCloseValve(ValveStateEnum & currentState, BitMask<ValveFaultBitmap> & valveFault) override |
| 44 | + { |
| 45 | + ChipLogProgress(NotSpecified, "VALVE IS CLOSING!!!!!"); |
| 46 | + state = ValveStateEnum::kClosed; |
| 47 | + currentState = state; |
| 48 | + return CHIP_NO_ERROR; |
| 49 | + } |
| 50 | + |
| 51 | +private: |
| 52 | + ValveStateEnum state = ValveStateEnum::kClosed; |
| 53 | + EndpointId mEndpoint; |
| 54 | +}; |
| 55 | + |
| 56 | +class NonLevelValveEndpoint |
| 57 | +{ |
| 58 | +public: |
| 59 | + NonLevelValveEndpoint(EndpointId endpoint) : |
| 60 | + mEndpoint(endpoint), mContext(mEndpoint, storage), mDelegate(mEndpoint), mLogic(mDelegate, mContext), |
| 61 | + mInterface(mEndpoint, mLogic) |
| 62 | + {} |
| 63 | + CHIP_ERROR Init() |
| 64 | + { |
| 65 | + ReturnErrorOnFailure(mLogic.Init(kConformance, kInitParams)); |
| 66 | + ReturnErrorOnFailure(mInterface.Init()); |
| 67 | + return CHIP_NO_ERROR; |
| 68 | + } |
| 69 | + |
| 70 | +private: |
| 71 | + const ClusterConformance kConformance = { |
| 72 | + .featureMap = 0, .supportsDefaultOpenLevel = false, .supportsValveFault = false, .supportsLevelStep = false |
| 73 | + }; |
| 74 | + const ClusterInitParameters kInitParams = { .currentState = DataModel::MakeNullable(ValveStateEnum::kClosed), |
| 75 | + .currentLevel = DataModel::NullNullable, |
| 76 | + .valveFault = 0, |
| 77 | + .levelStep = 1 }; |
| 78 | + EndpointId mEndpoint; |
| 79 | + KvsPersistentStorageDelegate storage; |
| 80 | + MatterContext mContext; |
| 81 | + PrintOnlyDelegate mDelegate; |
| 82 | + ClusterLogic mLogic; |
| 83 | + Interface mInterface; |
| 84 | +}; |
| 85 | + |
| 86 | +NonLevelValveEndpoint ep1(1); |
| 87 | +NonLevelValveEndpoint ep2(2); |
| 88 | +NonLevelValveEndpoint ep3(3); |
| 89 | +NonLevelValveEndpoint ep4(4); |
| 90 | +NonLevelValveEndpoint ep5(5); |
| 91 | +NonLevelValveEndpoint ep6(6); |
| 92 | +} // namespace |
| 93 | + |
| 94 | +void ApplicationInit() |
| 95 | +{ |
| 96 | + ChipLogError(NotSpecified, "App init!!!"); |
| 97 | + ep1.Init(); |
| 98 | + ep2.Init(); |
| 99 | + ep3.Init(); |
| 100 | + ep4.Init(); |
| 101 | + ep5.Init(); |
| 102 | + ep6.Init(); |
| 103 | +} |
| 104 | + |
| 105 | +void ApplicationShutdown() |
| 106 | +{ |
| 107 | + ChipLogDetail(NotSpecified, "ApplicationShutdown()"); |
| 108 | +} |
| 109 | + |
| 110 | +int main(int argc, char * argv[]) |
| 111 | +{ |
| 112 | + if (ChipLinuxAppInit(argc, argv) != 0) |
| 113 | + { |
| 114 | + return -1; |
| 115 | + } |
| 116 | + |
| 117 | + ChipLinuxAppMainLoop(); |
| 118 | + return 0; |
| 119 | +} |
0 commit comments