init
This commit is contained in:
commit
f0839115c9
12 changed files with 29566 additions and 0 deletions
2
.clangd
Normal file
2
.clangd
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
CompileFlags:
|
||||||
|
CompilationDatabase: builddir/
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
builddir
|
||||||
|
|
||||||
|
subprojects/*
|
||||||
|
!subprojects/*.wrap
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Definition
|
||||||
|
Tag are AS IS an e-paper which displays price, ... etc
|
||||||
|
Peer are AS IS an remote ESP32 that control a tag or tags
|
||||||
|
|
||||||
|
|
2
justfile
Normal file
2
justfile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
build:
|
||||||
|
meson compile -C ./builddir/
|
35
meshtalos.cpp
Normal file
35
meshtalos.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include <meshtalos.hpp>
|
||||||
|
|
||||||
|
namespace meshtalos {
|
||||||
|
extern "C" {
|
||||||
|
static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||||
|
if (ev == MG_EV_HTTP_MSG) { // New HTTP request received
|
||||||
|
struct mg_http_message *hm =
|
||||||
|
(struct mg_http_message *)ev_data; // Parsed HTTP request
|
||||||
|
if (mg_match(hm->uri, mg_str("/api/hello"), NULL)) { // REST API call?
|
||||||
|
|
||||||
|
mg_http_reply(c, 200, "", "{%m:%d}\n", MG_ESC("status"),
|
||||||
|
1); // Yes. Respond JSON
|
||||||
|
} else {
|
||||||
|
struct mg_http_serve_opts opts = {.root_dir = ".", .fs = &mg_fs_posix};
|
||||||
|
mg_http_serve_dir(c, hm, &opts); // For all other URLs, Serve static files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Meshtalos::Meshtalos(lfs_t *lfs) : _lfs(lfs) {
|
||||||
|
number = 6;
|
||||||
|
mg_mgr_init(&_mgr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Meshtalos::listen() {
|
||||||
|
mg_http_listen(&_mgr, ("http://" + listen_address).c_str(), ev_handler, NULL);
|
||||||
|
for (;;) {
|
||||||
|
mg_mgr_poll(&_mgr, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Meshtalos::get_number() const { return number; }
|
||||||
|
|
||||||
|
} // namespace meshtalos
|
38
meshtalos.hpp
Normal file
38
meshtalos.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
|
#ifdef BUILDING_MESHTALOS
|
||||||
|
#define MESHTALOS_PUBLIC __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define MESHTALOS_PUBLIC __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifdef BUILDING_MESHTALOS
|
||||||
|
#define MESHTALOS_PUBLIC __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define MESHTALOS_PUBLIC
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "./mongoose.h"
|
||||||
|
#include <lfs.h>
|
||||||
|
|
||||||
|
namespace meshtalos {
|
||||||
|
|
||||||
|
// Ciallo~(∠・ω< )⌒☆
|
||||||
|
class MESHTALOS_PUBLIC Meshtalos {
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string listen_address = "0.0.0.0:8080";
|
||||||
|
lfs_t *_lfs;
|
||||||
|
Meshtalos(lfs_t *lfs = NULL);
|
||||||
|
void listen();
|
||||||
|
int get_number() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct mg_mgr _mgr;
|
||||||
|
|
||||||
|
int number;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace meshtalos
|
11
meshtalos_test.cpp
Normal file
11
meshtalos_test.cpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include "./meshtalos.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc != 1) {
|
||||||
|
std::cout << argv[0] << " takes no arguments.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
meshtalos::Meshtalos c;
|
||||||
|
c.listen();
|
||||||
|
}
|
52
meson.build
Normal file
52
meson.build
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
project(
|
||||||
|
'MESHTalos',
|
||||||
|
['cpp','c'],
|
||||||
|
version : '0.1',
|
||||||
|
meson_version : '>= 1.3.0',
|
||||||
|
default_options : ['warning_level=3', 'cpp_std=c++20', 'c_std=gnu11'],
|
||||||
|
)
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
dependency('littlefs')
|
||||||
|
]
|
||||||
|
|
||||||
|
# These arguments are only used to build the shared library
|
||||||
|
# not the executables that use the library.
|
||||||
|
lib_args = ['-DBUILDING_MESHTALOS']
|
||||||
|
|
||||||
|
lib = library(
|
||||||
|
'meshtalos',
|
||||||
|
'meshtalos.cpp',
|
||||||
|
'./mongoose.c',
|
||||||
|
install : true,
|
||||||
|
cpp_shared_args : lib_args,
|
||||||
|
gnu_symbol_visibility : 'hidden',
|
||||||
|
dependencies : dependencies,
|
||||||
|
)
|
||||||
|
|
||||||
|
test_exe = executable(
|
||||||
|
'meshtalos_test',
|
||||||
|
'meshtalos_test.cpp',
|
||||||
|
dependencies : dependencies,
|
||||||
|
link_with : lib,
|
||||||
|
)
|
||||||
|
test('meshtalos', test_exe)
|
||||||
|
|
||||||
|
# Make this library usable as a Meson subproject.
|
||||||
|
meshtalos_dep = declare_dependency(
|
||||||
|
include_directories : include_directories('.'),
|
||||||
|
dependencies : dependencies,
|
||||||
|
link_with : lib,
|
||||||
|
)
|
||||||
|
meson.override_dependency('MESHTalos', meshtalos_dep)
|
||||||
|
|
||||||
|
# Make this library usable from the system's
|
||||||
|
# package manager.
|
||||||
|
install_headers('meshtalos.hpp', subdir : 'meshtalos')
|
||||||
|
|
||||||
|
pkg_mod = import('pkgconfig')
|
||||||
|
pkg_mod.generate(
|
||||||
|
lib,
|
||||||
|
description : 'Meson sample project.',
|
||||||
|
subdirs : 'meshtalos',
|
||||||
|
)
|
25608
mongoose.c
Normal file
25608
mongoose.c
Normal file
File diff suppressed because it is too large
Load diff
3781
mongoose.h
Normal file
3781
mongoose.h
Normal file
File diff suppressed because it is too large
Load diff
15
storage.hpp
Normal file
15
storage.hpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct TagInfo {
|
||||||
|
char *name;
|
||||||
|
uint32_t price;
|
||||||
|
int32_t sale; // unit is percent, rounded
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Peer {
|
||||||
|
char peer_id[6];
|
||||||
|
uint64_t last_online;
|
||||||
|
std::vector<TagInfo> tags;
|
||||||
|
};
|
13
subprojects/littlefs.wrap
Normal file
13
subprojects/littlefs.wrap
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[wrap-file]
|
||||||
|
directory = littlefs-2.11.0
|
||||||
|
source_url = https://github.com/littlefs-project/littlefs/archive/refs/tags/v2.11.0.tar.gz
|
||||||
|
source_filename = littlefs-2.11.0.tar.gz
|
||||||
|
source_hash = 54ed6382d75cbd4898fa89ddc0db7bf82abadfd8b209e12950cb10a05a6dc424
|
||||||
|
patch_filename = littlefs_2.11.0-1_patch.zip
|
||||||
|
patch_url = https://wrapdb.mesonbuild.com/v2/littlefs_2.11.0-1/get_patch
|
||||||
|
patch_hash = a6e963fda9547db589e9ac7b5fcc6a5fd3553a59efe32ac7053e2d0a1053331b
|
||||||
|
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/littlefs_2.11.0-1/littlefs-2.11.0.tar.gz
|
||||||
|
wrapdb_version = 2.11.0-1
|
||||||
|
|
||||||
|
[provide]
|
||||||
|
littlefs = littlefs_dep
|
Loading…
Add table
Reference in a new issue