1 // Copyright 2020 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 "pw_hdlc/rpc_packets.h" 16 17 #include "pw_status/try.h" 18 #include "pw_sys_io/sys_io.h" 19 20 namespace pw::hdlc { 21 ReadAndProcessPackets(rpc::Server & server,span<std::byte> decode_buffer,unsigned rpc_address)22Status ReadAndProcessPackets(rpc::Server& server, 23 span<std::byte> decode_buffer, 24 unsigned rpc_address) { 25 Decoder decoder(decode_buffer); 26 27 while (true) { 28 std::byte data; 29 PW_TRY(sys_io::ReadByte(&data)); 30 31 if (auto result = decoder.Process(data); result.ok()) { 32 Frame& frame = result.value(); 33 if (frame.address() == rpc_address) { 34 server.ProcessPacket(frame.data()) 35 .IgnoreError(); // TODO(b/242598609): Handle Status properly 36 } 37 } 38 } 39 } 40 41 } // namespace pw::hdlc 42