ESPectre SDK
2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
Toggle main menu visibility
Loading...
Searching...
No Matches
ota_service.h
Go to the documentation of this file.
1
/*
2
* ESPectre - OTA Service
3
*
4
* OTA service boundary used by sensing frontends.
5
*
6
* Author: Francesco Pace <francesco.pace@gmail.com>
7
* SPDX-License-Identifier: GPL-3.0-only
8
* Commercial licensing available under separate agreement; see LICENSING.md.
9
*/
10
#pragma once
11
12
#include <functional>
13
#include <string>
14
15
#include "
espectre_protocol.h
"
16
17
namespace
espectre
{
18
19
/**
20
* The firmware-update seam.
21
*
22
* Implement it to drive updates through your own distribution channel, or use
23
* the shipped `HttpsOtaService` (`ota_service_https.h`), which resolves a
24
* release manifest over HTTPS and applies the image with `esp_https_ota`.
25
* Frontends expose the result over their operational transport and never talk
26
* to the underlying stack themselves. Native uses MQTT for this surface.
27
*
28
* @par Threading
29
* Deliver status and prepare callbacks from `loop()`, never from a private
30
* worker or stack task. The shipped implementation performs network I/O on a
31
* worker, queues progress, and waits for the loop to run the prepare hook
32
* before starting the download.
33
*
34
* @par Operation model
35
* `start_check()` and `start_update()` are asynchronous and mutually
36
* exclusive: only one operation runs at a time, and the second returns false
37
* while the first is in flight. Progress arrives through the status callback,
38
* and `status()` is safe to poll at any time.
39
*/
40
class
IOtaService
{
41
public
:
42
/** Update progressed. The argument is the new status, valid for the call. */
43
using
StatusCallback
= std::function<void(
const
EspectreOtaStatus
&)>;
44
/** Last chance to quiesce before the download starts. See below. */
45
using
PrepareForUpdateCallback
= std::function<void()>;
46
47
virtual
~IOtaService
() =
default
;
48
49
/**
50
* Advance service work from the frontend loop.
51
*
52
* Implementations may do blocking work on a private task, but loop() owns
53
* callback delivery and other interaction with the frontend.
54
*/
55
virtual
void
loop
() = 0;
56
/** Abandon any operation in flight and release resources. Safe to repeat. */
57
virtual
void
shutdown
() = 0;
58
/**
59
* Ask whether a newer release exists, without downloading it.
60
*
61
* @param current_version Version to compare against, normally
62
* `espectre_firmware_version()`. Empty is reported as `"unknown"`.
63
* @return false when an operation is already in flight or the worker cannot
64
* start. True only means the check began; the answer arrives as
65
* `UPDATE_AVAILABLE` or `UP_TO_DATE` through the status callback.
66
*/
67
virtual
bool
start_check
(
const
std::string ¤t_version) = 0;
68
/**
69
* Same as `start_check(current_version)`, with an optional release channel.
70
*
71
* @param current_version Version to compare against, normally
72
* `espectre_firmware_version()`. Empty is reported as `"unknown"`.
73
* @param channel `release`, `preview`, or `develop`. Empty keeps the
74
* implementation default.
75
* @return false when an operation is already in flight, the channel is
76
* invalid, or the worker cannot start.
77
*/
78
virtual
bool
start_check
(
const
std::string ¤t_version,
const
std::string &channel) {
79
if
(!channel.empty()) {
80
return
false
;
81
}
82
return
start_check
(current_version);
83
}
84
/**
85
* Download and apply an update, then schedule the reboot.
86
*
87
* Performs its own check first, so calling `start_check()` beforehand is
88
* optional. The prepare callback fires once the target is resolved and
89
* before the download begins: that is where you call
90
* `RuntimeFrontendController::quiesce_for_ota()` and stop your own traffic.
91
*
92
* @return false when an operation is already in flight or the worker cannot
93
* start. A successful update ends in `REBOOT_SCHEDULED`.
94
*/
95
virtual
bool
start_update
(
const
std::string ¤t_version) = 0;
96
/**
97
* Same as `start_update(current_version)`, with an optional release channel.
98
*
99
* @param current_version Version to compare against, normally
100
* `espectre_firmware_version()`. Empty is reported as `"unknown"`.
101
* @param channel `release`, `preview`, or `develop`. Empty keeps the
102
* implementation default.
103
* @return false when an operation is already in flight, the channel is
104
* invalid, or the worker cannot start.
105
*/
106
virtual
bool
start_update
(
const
std::string ¤t_version,
const
std::string &channel) {
107
if
(!channel.empty()) {
108
return
false
;
109
}
110
return
start_update
(current_version);
111
}
112
/** Current status. Safe to call from any task, including while an update runs. */
113
virtual
EspectreOtaStatus
status
()
const
= 0;
114
/** Install the progress handler. Set it before starting an operation. */
115
virtual
void
set_status_callback
(
StatusCallback
callback) = 0;
116
/** Install the pre-download hook. Set it before calling `start_update()`. */
117
virtual
void
set_prepare_for_update_callback
(
PrepareForUpdateCallback
callback) = 0;
118
};
119
120
}
// namespace espectre
espectre::IOtaService
The firmware-update seam.
Definition
ota_service.h:40
espectre::IOtaService::start_update
virtual bool start_update(const std::string ¤t_version, const std::string &channel)
Same as start_update(current_version), with an optional release channel.
Definition
ota_service.h:106
espectre::IOtaService::set_status_callback
virtual void set_status_callback(StatusCallback callback)=0
Install the progress handler.
espectre::IOtaService::start_check
virtual bool start_check(const std::string ¤t_version)=0
Ask whether a newer release exists, without downloading it.
espectre::IOtaService::loop
virtual void loop()=0
Advance service work from the frontend loop.
espectre::IOtaService::start_update
virtual bool start_update(const std::string ¤t_version)=0
Download and apply an update, then schedule the reboot.
espectre::IOtaService::status
virtual EspectreOtaStatus status() const =0
Current status.
espectre::IOtaService::StatusCallback
std::function< void(const EspectreOtaStatus &)> StatusCallback
Update progressed.
Definition
ota_service.h:43
espectre::IOtaService::shutdown
virtual void shutdown()=0
Abandon any operation in flight and release resources.
espectre::IOtaService::~IOtaService
virtual ~IOtaService()=default
espectre::IOtaService::PrepareForUpdateCallback
std::function< void()> PrepareForUpdateCallback
Last chance to quiesce before the download starts.
Definition
ota_service.h:45
espectre::IOtaService::set_prepare_for_update_callback
virtual void set_prepare_for_update_callback(PrepareForUpdateCallback callback)=0
Install the pre-download hook.
espectre::IOtaService::start_check
virtual bool start_check(const std::string ¤t_version, const std::string &channel)
Same as start_check(current_version), with an optional release channel.
Definition
ota_service.h:78
espectre_protocol.h
Wire types and payload builders for the ESPectre Protocol.
espectre
Definition
espectre_sdk_version.h:62
espectre::EspectreOtaStatus
Full OTA status: state, the versions involved, and the resolved URLs.
Definition
espectre_protocol.h:228
src
cpp
runtime
ota_service.h
Generated by
1.17.0