Update Zephyr examples

This commit is contained in:
Sergio R. Caprile committed 2022-10-06 17:30:27 -03:00
1 parent 9c60a1bc10
commit d846e67ec1
28 files changed
+26641 -73

No files matched your search

+21 -4
View File
@@ -32,19 +32,20 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
} else if (ev == MG_EV_WS_MSG) {
// Got websocket frame. Received data is wm->data. Echo it back!
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
MG_INFO(("Got wm: %p, data: %p, %d = %*.s", wm, wm->data.ptr, wm->data.len, wm->data.len, wm->data.ptr));
mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT);
}
(void) fn_data;
}
// We have no valid system time(), and we need it for TLS. Implement it
time_t time(time_t *tp) {
time_t t = s_boot_timestamp + k_uptime_get() / 1000;
// example system time()-like function
time_t ourtime(time_t *tp) {
time_t t = s_boot_timestamp + mg_millis() / 1000;
if (tp != NULL) *tp = t;
return t;
}
// SNTP callback. Modifies s_boot_timestamp, to make time() correct
// SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct
static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_SNTP_TIME) {
int64_t t = *(int64_t *) ev_data;
@@ -62,7 +63,23 @@ static void timer_fn(void *arg) {
if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn);
}
// Zephyr: Define a semaphore and network management callback to be able to wait
// until our IP address is ready. The main function will start and block on this
// semaphore until this event handler releases it when the network is ready
K_SEM_DEFINE(run, 0, 1);
static void zeh(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
struct net_if *iface) {
if (mgmt_event == NET_EVENT_L4_CONNECTED) k_sem_give(&run);
}
int main(int argc, char *argv[]) {
// Zephyr: Register the network management callback and block on the semaphore
struct net_mgmt_event_callback ncb;
net_mgmt_init_event_callback(&ncb, zeh, NET_EVENT_L4_CONNECTED);
net_mgmt_add_event_callback(&ncb);
k_sem_take(&run, K_FOREVER);
struct mg_mgr mgr;
mg_mgr_init(&mgr);
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff