Formatting
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -56,8 +56,8 @@ enum json_token_type {
|
||||
* `json_scanf()` with the format specifier `%T`.
|
||||
*/
|
||||
struct json_token {
|
||||
const char *ptr; /* Points to the beginning of the value */
|
||||
int len; /* Value length */
|
||||
const char * ptr; /* Points to the beginning of the value */
|
||||
int len; /* Value length */
|
||||
enum json_token_type type; /* Type of the token, possible values are above */
|
||||
};
|
||||
|
||||
@ -65,8 +65,8 @@ struct json_token {
|
||||
{ 0, 0, JSON_TYPE_INVALID }
|
||||
|
||||
/* Error codes */
|
||||
#define JSON_STRING_INVALID -1
|
||||
#define JSON_STRING_INCOMPLETE -2
|
||||
#define JSON_STRING_INVALID -1
|
||||
#define JSON_STRING_INCOMPLETE -2
|
||||
|
||||
/*
|
||||
* Callback-based SAX-like API.
|
||||
@ -88,7 +88,7 @@ struct json_token {
|
||||
* - type: JSON_TYPE_OBJECT_START, name: "2", path: ".bar[2]", value: NULL
|
||||
* - type: JSON_TYPE_TRUE, name: "baz", path: ".bar[2].baz", value: "true"
|
||||
* - type: JSON_TYPE_OBJECT_END, name: NULL, path: ".bar[2]", value: "{ \"baz\":
|
||||
*true }"
|
||||
* true }"
|
||||
* - type: JSON_TYPE_ARRAY_END, name: NULL, path: ".bar", value: "[ 1, 2, {
|
||||
*\"baz\": true } ]"
|
||||
* - type: JSON_TYPE_OBJECT_END, name: NULL, path: "", value: "{ \"foo\": 123,
|
||||
@ -114,13 +114,13 @@ struct json_out {
|
||||
int (*printer)(struct json_out *, const char *str, size_t len);
|
||||
union {
|
||||
struct {
|
||||
char *buf;
|
||||
char * buf;
|
||||
size_t size;
|
||||
size_t len;
|
||||
} buf;
|
||||
} buf;
|
||||
void *data;
|
||||
FILE *fp;
|
||||
} u;
|
||||
} u;
|
||||
};
|
||||
|
||||
extern int json_printer_buf(struct json_out *, const char *, size_t);
|
||||
@ -132,11 +132,11 @@ extern int json_printer_file(struct json_out *, const char *, size_t);
|
||||
{ buf, len, 0 } \
|
||||
} \
|
||||
}
|
||||
#define JSON_OUT_FILE(fp) \
|
||||
{ \
|
||||
json_printer_file, { \
|
||||
{ (char *) fp, 0, 0 } \
|
||||
} \
|
||||
#define JSON_OUT_FILE(fp) \
|
||||
{ \
|
||||
json_printer_file, { \
|
||||
{ (char *)fp, 0, 0 } \
|
||||
} \
|
||||
}
|
||||
|
||||
typedef int (*json_printf_callback_t)(struct json_out *, va_list *ap);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "test.h"
|
||||
|
||||
int test_failures=0;
|
||||
int assert_count=0;
|
||||
int test_failures = 0;
|
||||
int assert_count = 0;
|
||||
|
||||
uint32_t mqtt_pub_count;
|
||||
uint32_t mqtt_sub_count;
|
||||
|
@ -10,22 +10,23 @@ bool mgos_gpio_set_mode(int pin, enum mgos_gpio_mode mode) {
|
||||
}
|
||||
|
||||
void mgos_gpio_write(int pin, bool level) {
|
||||
LOG(LL_INFO, ("Setting pin=%d to %s", pin, level?"HIGH":"LOW"));
|
||||
LOG(LL_INFO, ("Setting pin=%d to %s", pin, level ? "HIGH" : "LOW"));
|
||||
}
|
||||
|
||||
bool mgos_gpio_set_button_handler(int pin, enum mgos_gpio_pull_type pull_type, enum mgos_gpio_int_mode int_mode, int debounce_ms, mgos_gpio_int_handler_f cb, void *arg) {
|
||||
s_handler_cb = cb;
|
||||
s_handler_cb = cb;
|
||||
s_handler_cb_arg = arg;
|
||||
|
||||
return true;
|
||||
(void) debounce_ms;
|
||||
(void) int_mode;
|
||||
(void) pull_type;
|
||||
(void) pin;
|
||||
|
||||
(void)debounce_ms;
|
||||
(void)int_mode;
|
||||
(void)pull_type;
|
||||
(void)pin;
|
||||
}
|
||||
|
||||
void mgos_gpio_inject(int pin) {
|
||||
if (s_handler_cb)
|
||||
if (s_handler_cb) {
|
||||
s_handler_cb(pin, s_handler_cb_arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,18 +4,18 @@
|
||||
#include "mgos.h"
|
||||
|
||||
enum mgos_gpio_mode {
|
||||
MGOS_GPIO_MODE_INPUT = 0, /* input mode */
|
||||
MGOS_GPIO_MODE_OUTPUT = 1 /* output mode */
|
||||
MGOS_GPIO_MODE_INPUT = 0, /* input mode */
|
||||
MGOS_GPIO_MODE_OUTPUT = 1 /* output mode */
|
||||
};
|
||||
|
||||
enum mgos_gpio_pull_type {
|
||||
MGOS_GPIO_PULL_NONE = 0,
|
||||
MGOS_GPIO_PULL_UP = 1, /* pin is pilled to the high voltage */
|
||||
MGOS_GPIO_PULL_DOWN = 2 /* pin is pulled to the low voltage */
|
||||
MGOS_GPIO_PULL_UP = 1, /* pin is pilled to the high voltage */
|
||||
MGOS_GPIO_PULL_DOWN = 2 /* pin is pulled to the low voltage */
|
||||
};
|
||||
|
||||
enum mgos_gpio_int_mode {
|
||||
MGOS_GPIO_INT_NONE = 0,
|
||||
MGOS_GPIO_INT_NONE = 0,
|
||||
MGOS_GPIO_INT_EDGE_POS = 1, /* positive edge */
|
||||
MGOS_GPIO_INT_EDGE_NEG = 2, /* negative edge */
|
||||
MGOS_GPIO_INT_EDGE_ANY = 3, /* any edge - positive or negative */
|
||||
|
@ -8,36 +8,41 @@ int _mgos_timers = 0;
|
||||
int log_print_prefix(enum cs_log_level l, const char *func, const char *file) {
|
||||
char ll_str[6];
|
||||
|
||||
switch(l) {
|
||||
case LL_ERROR:
|
||||
strncpy(ll_str, "ERROR", sizeof(ll_str));
|
||||
break;
|
||||
case LL_WARN:
|
||||
strncpy(ll_str, "WARN", sizeof(ll_str));
|
||||
break;
|
||||
case LL_INFO:
|
||||
strncpy(ll_str, "INFO", sizeof(ll_str));
|
||||
break;
|
||||
case LL_DEBUG:
|
||||
strncpy(ll_str, "DEBUG", sizeof(ll_str));
|
||||
break;
|
||||
case LL_VERBOSE_DEBUG:
|
||||
strncpy(ll_str, "VERB", sizeof(ll_str));
|
||||
break;
|
||||
default: // LL_NONE
|
||||
return 0;
|
||||
switch (l) {
|
||||
case LL_ERROR:
|
||||
strncpy(ll_str, "ERROR", sizeof(ll_str));
|
||||
break;
|
||||
|
||||
case LL_WARN:
|
||||
strncpy(ll_str, "WARN", sizeof(ll_str));
|
||||
break;
|
||||
|
||||
case LL_INFO:
|
||||
strncpy(ll_str, "INFO", sizeof(ll_str));
|
||||
break;
|
||||
|
||||
case LL_DEBUG:
|
||||
strncpy(ll_str, "DEBUG", sizeof(ll_str));
|
||||
break;
|
||||
|
||||
case LL_VERBOSE_DEBUG:
|
||||
strncpy(ll_str, "VERB", sizeof(ll_str));
|
||||
break;
|
||||
|
||||
default: // LL_NONE
|
||||
return 0;
|
||||
}
|
||||
printf ("%-5s %-15s %-40s| ", ll_str, file, func);
|
||||
printf("%-5s %-15s %-40s| ", ll_str, file, func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mgos_timer_id mgos_set_timer(int msecs, int flags, timer_callback cb, void *cb_arg) {
|
||||
_mgos_timers++;
|
||||
LOG(LL_INFO, ("Installing timer -- %d timers currently installed", _mgos_timers));
|
||||
(void) msecs;
|
||||
(void) flags;
|
||||
(void) cb;
|
||||
(void) cb_arg;
|
||||
(void)msecs;
|
||||
(void)flags;
|
||||
(void)cb;
|
||||
(void)cb_arg;
|
||||
|
||||
return _mgos_timers;
|
||||
}
|
||||
@ -45,17 +50,17 @@ mgos_timer_id mgos_set_timer(int msecs, int flags, timer_callback cb, void *cb_a
|
||||
void mgos_clear_timer(mgos_timer_id id) {
|
||||
_mgos_timers--;
|
||||
LOG(LL_INFO, ("Clearing timer -- %d timers currently installed", _mgos_timers));
|
||||
(void) id;
|
||||
(void)id;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
double mg_time() {
|
||||
return (float) time(NULL);
|
||||
return (float)time(NULL);
|
||||
}
|
||||
|
||||
double mgos_uptime() {
|
||||
return (double) time(NULL);
|
||||
return (double)time(NULL);
|
||||
}
|
||||
|
||||
char *mgos_sys_ro_vars_get_mac_address() {
|
||||
|
@ -8,32 +8,32 @@
|
||||
#include <time.h>
|
||||
#include "mongoose/mongoose.h"
|
||||
|
||||
#define MGOS_APP "unittest"
|
||||
#define MGOS_APP "unittest"
|
||||
|
||||
// mgos_log
|
||||
enum cs_log_level {
|
||||
LL_NONE = -1,
|
||||
LL_ERROR = 0,
|
||||
LL_WARN = 1,
|
||||
LL_INFO = 2,
|
||||
LL_DEBUG = 3,
|
||||
LL_NONE = -1,
|
||||
LL_ERROR = 0,
|
||||
LL_WARN = 1,
|
||||
LL_INFO = 2,
|
||||
LL_DEBUG = 3,
|
||||
LL_VERBOSE_DEBUG = 4,
|
||||
|
||||
_LL_MIN = -2,
|
||||
_LL_MAX = 5,
|
||||
_LL_MIN = -2,
|
||||
_LL_MAX = 5,
|
||||
};
|
||||
|
||||
int log_print_prefix(enum cs_log_level l, const char *func, const char *file);
|
||||
|
||||
#define LOG(l, x) \
|
||||
do { \
|
||||
if (log_print_prefix(l, __func__, __FILE__)) printf x; \
|
||||
printf("\r\n"); \
|
||||
#define LOG(l, x) \
|
||||
do { \
|
||||
if (log_print_prefix(l, __func__, __FILE__)) { printf x; } \
|
||||
printf("\r\n"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
// mgos_timer
|
||||
#define MGOS_TIMER_REPEAT 1
|
||||
#define MGOS_TIMER_REPEAT 1
|
||||
typedef uintptr_t mgos_timer_id;
|
||||
typedef void (*timer_callback)(void *param);
|
||||
|
||||
|
@ -1,35 +1,35 @@
|
||||
#include "mgos.h"
|
||||
#include "mgos_mqtt.h"
|
||||
|
||||
uint32_t mqtt_pub_count=0;
|
||||
uint32_t mqtt_sub_count=0;
|
||||
uint32_t mqtt_pub_count = 0;
|
||||
uint32_t mqtt_sub_count = 0;
|
||||
|
||||
static sub_handler_t s_handler;
|
||||
static void *s_handler_ud;
|
||||
static void * s_handler_ud;
|
||||
|
||||
static mg_event_handler_t s_global_handler;
|
||||
static void *s_global_handler_ud;
|
||||
|
||||
void mgos_mqtt_pub(char *t, char *m, int m_len, int flags, bool persist) {
|
||||
LOG(LL_INFO, ("Sending topic='%s' msg='%s' persist=%s", t, m, persist?"ON":"OFF"));
|
||||
LOG(LL_INFO, ("Sending topic='%s' msg='%s' persist=%s", t, m, persist ? "ON" : "OFF"));
|
||||
mqtt_pub_count++;
|
||||
}
|
||||
|
||||
void mgos_mqtt_sub(char *t, sub_handler_t cb, void *ud) {
|
||||
LOG(LL_INFO, ("Subscribing to topic='%s'", t));
|
||||
s_handler = cb;
|
||||
s_handler = cb;
|
||||
s_handler_ud = ud;
|
||||
}
|
||||
|
||||
void mgos_mqtt_inject(char *topic, char *msg) {
|
||||
LOG(LL_INFO, ("Injecting topic='%s' msg='%s'", topic, msg));
|
||||
mqtt_sub_count++;
|
||||
if (s_handler)
|
||||
if (s_handler) {
|
||||
s_handler(NULL, topic, strlen(topic), msg, strlen(msg), s_handler_ud);
|
||||
}
|
||||
}
|
||||
|
||||
void mgos_mqtt_add_global_handler(mqtt_event_handler_t handler, void *ud) {
|
||||
s_global_handler = handler;
|
||||
s_global_handler = handler;
|
||||
s_global_handler_ud = ud;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ typedef void (*sub_handler_t)(struct mg_connection *nc, const char *topic,
|
||||
void *ud);
|
||||
|
||||
typedef void (*mqtt_event_handler_t)(struct mg_connection *nc, int ev,
|
||||
void *ev_data, void *user_data);
|
||||
void *ev_data, void *user_data);
|
||||
|
||||
void mgos_mqtt_pub(char *t, char *m, int m_len, int flags, bool persist);
|
||||
void mgos_mqtt_sub(char *t, sub_handler_t cb, void *ud);
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#define MGOS_NET_IF_WIFI_STA 0
|
||||
#define MGOS_NET_IF_WIFI_AP 1
|
||||
#define MGOS_NET_IF_WIFI_STA 0
|
||||
#define MGOS_NET_IF_WIFI_AP 1
|
||||
|
||||
enum mgos_net_if_type {
|
||||
MGOS_NET_IF_TYPE_WIFI,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,13 +10,13 @@
|
||||
extern int test_failures;
|
||||
extern int assert_count;
|
||||
|
||||
#define ASSERT(expr, errstr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
LOG(LL_ERROR, ("ASSERT FAIL: "errstr)); \
|
||||
test_failures++; \
|
||||
} \
|
||||
assert_count++; \
|
||||
#define ASSERT(expr, errstr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
LOG(LL_ERROR, ("ASSERT FAIL: "errstr)); \
|
||||
test_failures++; \
|
||||
} \
|
||||
assert_count++; \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
@ -5,5 +5,3 @@ int test_buttons() {
|
||||
channel_init("testdata/testconfig1.json");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user