1 // Copyright 2022 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_transfer/transfer.h"
16
17 #include "pw_assert/check.h"
18 #include "pw_log/log.h"
19 #include "pw_status/try.h"
20 #include "pw_transfer/internal/chunk.h"
21
22 namespace pw::transfer {
23
HandleChunk(ConstByteSpan message,internal::TransferType type)24 void TransferService::HandleChunk(ConstByteSpan message,
25 internal::TransferType type) {
26 internal::Chunk chunk;
27 if (Status status = internal::DecodeChunk(message, chunk); !status.ok()) {
28 PW_LOG_ERROR("Failed to decode transfer chunk: %d", status.code());
29 return;
30 }
31
32 if (chunk.IsInitialChunk()) {
33 // TODO(frolv): Right now, transfer ID and handler ID are the same thing.
34 // The transfer ID should be made into a unique session ID instead.
35 thread_.StartServerTransfer(type,
36 chunk.transfer_id,
37 chunk.transfer_id,
38 max_parameters_,
39 chunk_timeout_,
40 max_retries_);
41 }
42
43 thread_.ProcessServerChunk(message);
44 }
45
46 } // namespace pw::transfer
47