mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-25 20:28:27 +00:00
Add profiling capability
This commit is contained in:
1 parent
c8105cffba
commit
693316de44
15 files changed
+240
-24
No files matched your search
@@ -12,13 +12,13 @@ static void signal_handler(int signo) {
|
||||
// Mocked device pins
|
||||
static bool s_pins[100];
|
||||
|
||||
void gpio_write(int pin, bool status) {
|
||||
void hal_gpio_write(int pin, bool status) {
|
||||
if (pin >= 0 && pin <= (int) (sizeof(s_pins) / sizeof(s_pins[0]))) {
|
||||
s_pins[pin] = status;
|
||||
}
|
||||
}
|
||||
|
||||
bool gpio_read(int pin) {
|
||||
bool hal_gpio_read(int pin) {
|
||||
return (pin >= 0 && pin <= (int) (sizeof(s_pins) / sizeof(s_pins[0])))
|
||||
? s_pins[pin]
|
||||
: false;
|
||||
|
||||
@@ -46,7 +46,7 @@ static void publish_status(struct mg_connection *c) {
|
||||
struct mg_mqtt_opts pub_opts;
|
||||
memset(&pub_opts, 0, sizeof(pub_opts));
|
||||
pub_opts.topic = pubt;
|
||||
s_device_config.led_status = gpio_read(s_device_config.led_pin);
|
||||
s_device_config.led_status = hal_gpio_read(s_device_config.led_pin);
|
||||
char *device_status_json = mg_mprintf(
|
||||
"{%m:%m,%m:{%m:%m,%m:%s,%m:%hhu,%m:%hhu,%m:%hhu,%m:%M,%m:%M}}",
|
||||
MG_ESC("method"), MG_ESC("status.notify"), MG_ESC("params"),
|
||||
@@ -114,7 +114,7 @@ static void rpc_config_set(struct mg_rpc_req *r) {
|
||||
if (tmp_pin > 0) s_device_config.led_pin = tmp_pin;
|
||||
|
||||
if (tmp_pin > 0 && ok) {
|
||||
gpio_write(s_device_config.led_pin, s_device_config.led_status);
|
||||
hal_gpio_write(s_device_config.led_pin, s_device_config.led_status);
|
||||
}
|
||||
|
||||
mg_rpc_ok(r, "%m", MG_ESC("ok"));
|
||||
@@ -219,7 +219,7 @@ static void timer_fn(void *arg) {
|
||||
.qos = s_qos,
|
||||
.topic = mg_str(status_topic),
|
||||
.version = 4,
|
||||
.keepalive = KEEP_ALIVE_INTERVAL,
|
||||
.keepalive = MQTT_KEEP_ALIVE_INTERVAL,
|
||||
.retain = true,
|
||||
.message = mg_str(msg)};
|
||||
s_conn = mg_mqtt_connect(mgr, g_url, &opts, fn, NULL);
|
||||
@@ -234,9 +234,9 @@ static void timer_keepalive(void *arg) {
|
||||
}
|
||||
|
||||
void web_init(struct mg_mgr *mgr) {
|
||||
int pingreq_interval_ms = KEEP_ALIVE_INTERVAL * 1000 - 500;
|
||||
int pingreq_interval_ms = MQTT_KEEP_ALIVE_INTERVAL * 1000 - 500;
|
||||
if (!g_device_id) generate_device_id();
|
||||
if (!g_root_topic) g_root_topic = DEFAULT_ROOT_TOPIC;
|
||||
if (!g_root_topic) g_root_topic = MQTT_ROOT_TOPIC;
|
||||
s_device_config.log_level = (uint8_t) mg_log_level;
|
||||
|
||||
// Configure JSON-RPC functions we're going to handle
|
||||
|
||||
@@ -13,10 +13,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define DEVICE_ID_LEN 10
|
||||
#define ROOT_TOPIC_LEN 30
|
||||
#define KEEP_ALIVE_INTERVAL 60
|
||||
#define MQTT_KEEP_ALIVE_INTERVAL 60
|
||||
#define MQTT_SERVER_URL "mqtt://broker.hivemq.com:1883"
|
||||
#define DEFAULT_ROOT_TOPIC "topic_mg_device"
|
||||
#define MQTT_ROOT_TOPIC "topic_mg_device"
|
||||
|
||||
extern char *g_url;
|
||||
extern char *g_device_id;
|
||||
@@ -25,8 +24,8 @@ extern char *g_root_topic;
|
||||
void web_init(struct mg_mgr *mgr);
|
||||
void web_destroy();
|
||||
|
||||
void gpio_write(int pin, bool status);
|
||||
bool gpio_read(int pin);
|
||||
void hal_gpio_write(int pin, bool status);
|
||||
bool hal_gpio_read(int pin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user