UpgradeOutputStream.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * UpgradeOutputStream.h
8  *
9  *
10 */
11 
12 #pragma once
13 
14 #include <Ota/Upgrader.h>
15 #include <Storage/Partition.h>
17 
18 namespace Ota
19 {
24 {
25 public:
27 
33  : partition(partition), maxLength(std::min(storage_size_t(maxLength ?: 0x1000000), partition.size()))
34  {
35  }
36 
38  {
39  close();
40  }
41 
42  size_t write(const uint8_t* data, size_t size) override;
43 
44  StreamType getStreamType() const override
45  {
46  return eSST_File;
47  }
48 
49  uint16_t readMemoryBlock(char* data, int bufSize) override
50  {
51  return 0;
52  }
53 
54  bool seek(int len) override
55  {
56  return false;
57  }
58 
59  int available() override
60  {
61  return written;
62  }
63 
64  bool isFinished() override
65  {
66  return true;
67  }
68 
69  virtual bool close();
70 
71  size_t getStartAddress() const
72  {
73  return partition.address();
74  }
75 
76  size_t getMaxLength() const
77  {
78  return maxLength;
79  }
80 
81 protected:
84  bool initialized{false};
85  size_t written{0}; // << the number of written bytes
86  size_t maxLength{0}; // << maximum allowed length
87 
88 protected:
89  virtual bool init();
90 };
91 
92 } // namespace Ota
uint32_t storage_size_t
Definition: Components/Storage/src/include/Storage/Types.h:19
ESP32 OTA Upgrader implementation.
Definition: IdfUpgrader.h:23
Write-only stream type used during firmware upgrade.
Definition: UpgradeOutputStream.h:24
size_t getMaxLength() const
Definition: UpgradeOutputStream.h:76
bool isFinished() override
Check if all data has been read.
Definition: UpgradeOutputStream.h:64
size_t maxLength
Definition: UpgradeOutputStream.h:86
size_t written
Definition: UpgradeOutputStream.h:85
size_t getStartAddress() const
Definition: UpgradeOutputStream.h:71
UpgradeOutputStream(Partition partition, size_t maxLength=0)
Construct a stream for the given partition.
Definition: UpgradeOutputStream.h:32
size_t write(const uint8_t *data, size_t size) override
Write chars to stream.
bool initialized
Definition: UpgradeOutputStream.h:84
StreamType getStreamType() const override
Get the stream type.
Definition: UpgradeOutputStream.h:44
uint16_t readMemoryBlock(char *data, int bufSize) override
Read a block of memory.
Definition: UpgradeOutputStream.h:49
Partition partition
Definition: UpgradeOutputStream.h:83
virtual ~UpgradeOutputStream()
Definition: UpgradeOutputStream.h:37
OtaUpgrader ota
Definition: UpgradeOutputStream.h:82
int available() override
Return the total length of the stream.
Definition: UpgradeOutputStream.h:59
bool seek(int len) override
Move read cursor.
Definition: UpgradeOutputStream.h:54
Base class for read/write stream.
Definition: ReadWriteStream.h:20
Represents a flash partition.
Definition: Partition.h:86
storage_size_t address() const
Obtain partition starting address.
Definition: Partition.h:335
StreamType
Data stream type.
Definition: DataSourceStream.h:25
@ eSST_File
< Memory stream where data can be safely written to.
Definition: DataSourceStream.h:30
Definition: IdfUpgrader.h:18