Skip to content

Commit 598fe0b

Browse files
authored
Merge branch 'master' into camera-webrtc-server
2 parents ef3f049 + 6ffcd19 commit 598fe0b

31 files changed

+4996
-689
lines changed

docs/issue_triage.md

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ types or functionality) as well as individual examples.
137137
| `examples/rvc-app` | | UNMAINTAINED |
138138
| `examples/smoke-co-alarm-app` | | UNMAINTAINED |
139139
| `examples/temperature-measurement-app` | | UNMAINTAINED |
140+
| `examples/terms-and-conditions-app` | James Swan | |
140141
| `examples/thermostat` | | UNMAINTAINED |
141142
| `examples/thread-br-app` | | UNMAINTAINED |
142143
| `examples/tv-app` | Chris DeCenzo, Lazar Kovacic | |

examples/platform/silabs/provision/ProvisionStorageCustom.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
#include "ProvisionStorage.h"
17+
#include <ProvisionStorage.h>
1818
#include <algorithm>
1919
#include <lib/support/CodeUtils.h>
2020
#include <string.h>

examples/platform/silabs/provision/ProvisionStorageDefault.cpp

+26-16
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,35 @@ CHIP_ERROR ErasePage(uint32_t addr)
7070
return chip::DeviceLayer::Silabs::GetPlatform().FlashErasePage(addr);
7171
}
7272

73-
CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
73+
size_t RoundNearest(size_t n, size_t multiple)
7474
{
75-
return chip::DeviceLayer::Silabs::GetPlatform().FlashWritePage(addr, data, size);
75+
return (n % multiple) > 0 ? n + (multiple - n % multiple) : n;
7676
}
7777

78-
size_t RoundNearest(size_t n, size_t multiple)
78+
/**
79+
* Writes "size" bytes to the flash page. The data is padded with 0xff
80+
* up to the nearest 32-bit boundary.
81+
*/
82+
CHIP_ERROR WritePage(uint32_t addr, const uint8_t * data, size_t size)
7983
{
80-
return (n % multiple) > 0 ? n + (multiple - n % multiple) : n;
84+
// The flash driver fails if the size is not a multiple of 4 (32-bits)
85+
size_t size_32 = RoundNearest(size, 4);
86+
if (size_32 == size)
87+
{
88+
// The given data is already aligned to 32-bit
89+
return chip::DeviceLayer::Silabs::GetPlatform().FlashWritePage(addr, data, size);
90+
}
91+
else
92+
{
93+
// Create a temporary buffer, and pad it with "0xff"
94+
uint8_t * p = static_cast<uint8_t *>(Platform::MemoryAlloc(size_32));
95+
VerifyOrReturnError(p != nullptr, CHIP_ERROR_INTERNAL);
96+
memcpy(p, data, size);
97+
memset(p + size, 0xff, size_32 - size);
98+
CHIP_ERROR err = chip::DeviceLayer::Silabs::GetPlatform().FlashWritePage(addr, p, size_32);
99+
Platform::MemoryFree(p);
100+
return err;
101+
}
81102
}
82103

83104
CHIP_ERROR WriteFile(Storage & store, SilabsConfig::Key offset_key, SilabsConfig::Key size_key, const ByteSpan & value)
@@ -89,17 +110,7 @@ CHIP_ERROR WriteFile(Storage & store, SilabsConfig::Key offset_key, SilabsConfig
89110
ReturnErrorOnFailure(ErasePage(base_addr));
90111
}
91112

92-
memcpy(Storage::aux_buffer, value.data(), value.size());
93-
if (value.size() < Storage::kArgumentSizeMax)
94-
{
95-
memset(Storage::aux_buffer + value.size(), 0xff, Storage::kArgumentSizeMax - value.size());
96-
}
97-
98-
ChipLogProgress(DeviceLayer, "WriteFile, addr:0x%06x+%03u, size:%u", (unsigned) base_addr, (unsigned) sCredentialsOffset,
99-
(unsigned) value.size());
100-
// ChipLogByteSpan(DeviceLayer, ByteSpan(value.data(), value.size() < kDebugLength ? value.size() : kDebugLength));
101-
102-
ReturnErrorOnFailure(WritePage(base_addr + sCredentialsOffset, Storage::aux_buffer, Storage::kArgumentSizeMax));
113+
ReturnErrorOnFailure(WritePage(base_addr + sCredentialsOffset, value.data(), value.size()));
103114

104115
// Store file offset
105116
ReturnErrorOnFailure(SilabsConfig::WriteConfigValue(offset_key, (uint32_t) sCredentialsOffset));
@@ -119,7 +130,6 @@ CHIP_ERROR ReadFileByOffset(Storage & store, const char * description, uint32_t
119130
ByteSpan span(address, size);
120131
ChipLogProgress(DeviceLayer, "%s, addr:0x%06x+%03u, size:%u", description, (unsigned) base_addr, (unsigned) offset,
121132
(unsigned) size);
122-
// ChipLogByteSpan(DeviceLayer, ByteSpan(span.data(), span.size() < kDebugLength ? span.size() : kDebugLength));
123133
return CopySpanToMutableSpan(span, value);
124134
}
125135

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
17+
# The location of the build configuration file.
18+
buildconfig = "${build_root}/config/BUILDCONFIG.gn"
19+
20+
# CHIP uses angle bracket includes.
21+
check_system_includes = true
22+
23+
default_args = {
24+
import("//args.gni")
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("${chip_root}/build/chip/tools.gni")
17+
import("${chip_root}/src/app/common_flags.gni")
18+
19+
executable("chip-terms-and-conditions-app") {
20+
sources = [ "main.cpp" ]
21+
22+
deps = [
23+
"${chip_root}/examples/platform/linux:app-main",
24+
"${chip_root}/examples/terms-and-conditions-app/terms-and-conditions-common",
25+
]
26+
27+
output_dir = root_out_dir
28+
}
29+
30+
group("default") {
31+
deps = [ ":chip-terms-and-conditions-app" ]
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("${chip_root}/config/standalone/args.gni")
17+
18+
chip_terms_and_conditions_required = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../build_overrides
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
19+
#include <AppMain.h>
20+
#include <app/server/TermsAndConditionsManager.h>
21+
#include <app/server/TermsAndConditionsProvider.h>
22+
23+
using namespace chip;
24+
using namespace chip::ArgParser;
25+
26+
static uint16_t sTcMinRequiredVersion = 0;
27+
static uint16_t sTcRequiredAcknowledgements = 0;
28+
29+
static OptionDef sTermsAndConditionsOptions[] = {
30+
{ "tc-min-required-version", kArgumentRequired, 'm' },
31+
{ "tc-required-acknowledgements", kArgumentRequired, 'r' },
32+
{ nullptr },
33+
};
34+
35+
static const char * const sTermsAndConditionsOptionHelp =
36+
"-m, --tc-min-required-version <number>\n Configure the minimum required TC version.\n\n"
37+
"-r, --tc-required-acknowledgements <number (bitfield)>\n Configure the required TC acknowledgements.\n\n";
38+
39+
static bool HandleOption(const char * progName, OptionSet * optSet, int id, const char * name, const char * arg)
40+
{
41+
switch (id)
42+
{
43+
case 'm':
44+
sTcMinRequiredVersion = static_cast<uint16_t>(atoi(arg));
45+
break;
46+
case 'r':
47+
sTcRequiredAcknowledgements = static_cast<uint16_t>(atoi(arg));
48+
break;
49+
default:
50+
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", progName, name);
51+
return false;
52+
}
53+
54+
return true;
55+
}
56+
57+
static OptionSet sTermsAndConditionsCmdLineOptions = {
58+
HandleOption,
59+
sTermsAndConditionsOptions,
60+
"TERMS AND CONDITIONS OPTIONS",
61+
sTermsAndConditionsOptionHelp,
62+
};
63+
64+
void ApplicationInit()
65+
{
66+
const app::TermsAndConditions termsAndConditions = app::TermsAndConditions(sTcRequiredAcknowledgements, sTcMinRequiredVersion);
67+
PersistentStorageDelegate & persistentStorageDelegate = Server::GetInstance().GetPersistentStorage();
68+
app::TermsAndConditionsManager::GetInstance()->Init(&persistentStorageDelegate, MakeOptional(termsAndConditions));
69+
}
70+
71+
void ApplicationShutdown() {}
72+
73+
int main(int argc, char * argv[])
74+
{
75+
if (ChipLinuxAppInit(argc, argv, &sTermsAndConditionsCmdLineOptions) != 0)
76+
{
77+
return -1;
78+
}
79+
80+
ChipLinuxAppMainLoop();
81+
return 0;
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
import("${chip_root}/src/app/chip_data_model.gni")
18+
19+
chip_data_model("terms-and-conditions-common") {
20+
zap_file = "terms-and-conditions-app.zap"
21+
is_server = true
22+
}

0 commit comments

Comments
 (0)