upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/tollgate_client.h
blob: ccee624d33353d938b9c6d077839bcb47ad87e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef TOLLGATE_CLIENT_H
#define TOLLGATE_CLIENT_H

#include "esp_err.h"
#include <stdint.h>
#include <stdbool.h>

#define TG_CLIENT_MAX_GW_IP_LEN       16
#define TG_CLIENT_MAX_MINT_URL        256
#define TG_CLIENT_MAX_METRIC          32

typedef enum {
    TG_CLIENT_IDLE,
    TG_CLIENT_DETECTING,
    TG_CLIENT_NO_TOLLGATE,
    TG_CLIENT_NEEDS_PAY,
    TG_CLIENT_PAYING,
    TG_CLIENT_PAID,
    TG_CLIENT_RENEWING,
    TG_CLIENT_MINING,
    TG_CLIENT_ERROR
} tollgate_client_state_t;

typedef struct {
    bool is_tollgate;
    int price_per_step;
    int step_size_ms;
    char mint_url[TG_CLIENT_MAX_MINT_URL];
    char metric[TG_CLIENT_MAX_METRIC];
    bool mining_available;
    uint16_t mining_port;
} tollgate_discovery_t;

esp_err_t tollgate_client_init(void);

esp_err_t tollgate_client_on_sta_connected(const char *gw_ip_str);

void tollgate_client_on_sta_disconnected(void);

void tollgate_client_tick(void);

tollgate_client_state_t tollgate_client_get_state(void);

const tollgate_discovery_t *tollgate_client_get_discovery(void);

int64_t tollgate_client_get_remaining_ms(void);
int64_t tollgate_client_get_allotment_ms(void);

#endif