• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://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, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include <array>
16 
17 #include "pw_assert/check.h"
18 #include "pw_bloat/bloat_this_binary.h"
19 #include "pw_log/log.h"
20 #include "pw_sys_io/sys_io.h"
21 
22 namespace {
23 
24 struct BasicPacket {
25   static constexpr uint32_t kMagic = 0x8badf00d;
26 
BasicPacket__anonbe2bbd850111::BasicPacket27   constexpr BasicPacket(uint32_t addr, uint64_t data)
28       : magic(kMagic), address(addr), payload(data) {}
29 
30   uint32_t magic;
31   uint32_t address;
32   uint64_t payload;
33 };
34 
35 }  // namespace
36 
main()37 int main() {
38   pw::bloat::BloatThisBinary();
39 
40   // Ensure we are paying the cost for log and assert.
41   BasicPacket packet(0x1, 0x2);
42   PW_CHECK_UINT_EQ(packet.magic, BasicPacket::kMagic, "Some CHECK logic");
43   PW_LOG_INFO("Packet has address %u", static_cast<unsigned>(packet.address));
44   PW_LOG_INFO("pw_StatusString %s", pw::OkStatus().str());
45 
46   std::array<std::byte, sizeof(BasicPacket)> packet_buffer;
47   pw::sys_io::ReadBytes(packet_buffer).IgnoreError();
48   pw::sys_io::WriteBytes(packet_buffer).IgnoreError();
49 
50   return static_cast<int>(packet.payload);
51 }
52