rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
wa_send.h
1/*
2 * One file off the card, a piece at a time.
3 *
4 * The size is taken before the first byte goes, so the response can say how
5 * long it is (Content-Length); the file then has to deliver exactly that.
6 * A read error, or a file that ends early or runs long -- a card pulled part
7 * way -- ends the transfer as failed, and the response is cut off there: a
8 * browser reports a download shorter than announced as failed.
9 *
10 * No piece is larger than the caller's buffer; nothing holds the whole file.
11 *
12 * Pure C, no ESP-IDF (Espressif Internet-of-Things Development Framework).
13 *
14 * SPDX-License-Identifier: MIT
15 */
16
17#ifndef RCBENCH_WA_SEND_H
18#define RCBENCH_WA_SEND_H
19
20#include <stdbool.h>
21#include <stdint.h>
22
23#include "wa_walk.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
30#define WA_SEND_CHUNK 4096u
31
32typedef struct {
33 const wa_fs_t *fs;
34 void *file;
35 uint64_t size;
36 uint64_t sent;
37 bool failed;
38} wa_send_t;
39
41bool wa_send_begin(wa_send_t *s, const wa_fs_t *fs, const char *path,
42 uint64_t size);
43
49int32_t wa_send_next(wa_send_t *s, uint8_t *buf, uint32_t cap);
50
52void wa_send_end(wa_send_t *s);
53
54/*
55 * The connection a response goes out on.
56 *
57 * A piece is offered to put(), which queues what fits and never waits. When
58 * nothing fits, wait() waits for room for at most a slice. A transfer ends
59 * when the receiver closes or the connection fails, when stop() says so,
60 * and when the receiver takes nothing for WA_SEND_QUIET_MS: a receiver that
61 * stops reading without closing would otherwise hold the server, which
62 * answers one request at a time, for as long as it stays.
63 */
64
66#define WA_SEND_QUIET_MS 30000u
68#define WA_SEND_SLICE_MS 250u
69
71typedef enum {
72 WA_WAIT_READY = 0,
73 WA_WAIT_IDLE,
74 WA_WAIT_GONE,
75} wa_wait_t;
76
77typedef struct {
80 int32_t (*put)(void *ctx, const uint8_t *p, uint32_t n);
82 wa_wait_t (*wait)(void *ctx, uint32_t ms);
84 bool (*stop)(void *ctx);
86 uint32_t (*now_ms)(void *ctx);
87 void *ctx;
88} wa_sink_t;
89
91typedef enum {
92 WA_SEND_DONE = 0,
93 WA_SEND_GONE,
94 WA_SEND_QUIET,
95 WA_SEND_STOPPED,
96 WA_SEND_READ_FAILED,
97} wa_send_res_t;
98
100wa_send_res_t wa_sink_all(const wa_sink_t *k, const void *data, uint32_t n);
101
107wa_send_res_t wa_send_run(wa_send_t *s, uint8_t *buf, uint32_t cap,
108 const wa_sink_t *k);
109
111const char *wa_send_res_name(wa_send_res_t r);
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif /* RCBENCH_WA_SEND_H */
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
#define k
Short name for kst_panel_k inside the overlay's seven files.
Definition kst_panel_int.h:238
Definition wa_walk.h:53
Definition wa_send.h:32
uint64_t size
Definition wa_send.h:35
Definition wa_send.h:77
wa_wait_t(*) wait(void *ctx, uint32_t ms)
Definition wa_send.h:82
int32_t(*) put(void *ctx, const uint8_t *p, uint32_t n)
Definition wa_send.h:80
uint32_t(*) now_ms(void *ctx)
Definition wa_send.h:86
bool(*) stop(void *ctx)
Definition wa_send.h:84
Every file and folder on the card, one at a time.