{"schema":"libjg2-1",
"vpath":"/git/",
"avatar":"/git/avatar/",
"alang":"",
"gen_ut":1731846295,
"reponame":"libwebsockets",
"desc":"libwebsockets lightweight C networking library",
"owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets",
"f":3,
"items": [
{"schema":"libjg2-1",
"cid":"91608babb1cd862a824bd1f5519ecf0f",
"oid":{ "oid": "6328231f2aa628632344d96a58e25c3b194af506", "alias": [ "refs/heads/main"]},"blobname": "minimal-examples/embedded/esp32/esp-wrover-kit/main/lws-minimal-esp32.c", "blob": "/*\n * lws-minimal-esp32\n *\n * Written in 2010-2022 by Andy Green \u003candy@warmcat.com\u003e\n *\n * This file is made available under the Creative Commons CC0 1.0\n * Universal Public Domain Dedication.\n *\n * Configured for ESP32 WROVER KIT\n *\n * What should be notable about this is there are no esp-idf apis used here or\n * any related files, despite we are running on top of stock esp-idf.\n */\n\n#define LWIP_PROVIDE_ERRNO 1\n#define _ESP_PLATFORM_ERRNO_H_\n\n#include \u003cstdio.h\u003e\n#include \u0022sdkconfig.h\u0022\n#include \u0022freertos/FreeRTOS.h\u0022\n#include \u0022freertos/task.h\u0022\n\n#include \u003cdriver/gpio.h\u003e\n\n#include \u003clibwebsockets.h\u003e\n\nstruct lws_context *context;\nextern struct lws_led_state *lls;\nextern lws_display_state_t lds;\nextern struct lws_button_state *bcs;\nextern lws_netdev_instance_wifi_t *wnd;\n\nlws_sorted_usec_list_t\t\tsul_pass;\n\nextern int init_plat_devices(struct lws_context *);\n\nstatic const uint8_t logo[] \u003d {\n#include \u0022cat-565.h\u0022\n};\n\n#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY)\n#include \u0022static-policy.h\u0022\n#else\n#include \u0022policy.h\u0022\n#endif\n\nstatic uint8_t flip;\n\n\ntypedef struct myss {\n\tstruct lws_ss_handle \t\t*ss;\n\tvoid\t\t\t\t*opaque_data;\n\t/* ... application specific state ... */\n\n\tsize_t\t\t\t\tamount;\n\n} myss_t;\n\n/*\n * When we're actually happy we passed, we schedule the actual pass\n * string to happen a few seconds later, so we can observe what the\n * code did after the pass.\n */\n\nstatic void\ncompletion_sul_cb(lws_sorted_usec_list_t *sul)\n{\n\t/*\n\t * In CI, we use sai-expect to look for this\n\t * string for success\n\t */\n\n\tlwsl_notice(\u0022Completed: PASS\u005cn\u0022);\n}\n\nstatic int\nmyss_rx(void *userobj, const uint8_t *buf, size_t len, int flags)\n{\n\tmyss_t *m \u003d (myss_t *)userobj;\n\n\tlwsl_user(\u0022%s: len %d, flags: %d\u005cn\u0022, __func__, (int)len, flags);\n//\tlwsl_hexdump_info(buf, len);\n\tm-\u003eamount +\u003d len;\n\n\tif (flags \u0026 LWSSS_FLAG_EOM) {\n\n\t\t/*\n\t\t * If we received the whole message, for our example it means\n\t\t * we are done.\n\t\t *\n\t\t * Howevere we want to record what happened after we received\n\t\t * the last bit so we can see anything unexpected coming. So\n\t\t * wait 5s before sending the PASS magic.\n\t\t */\n\n\t\tlwsl_notice(\u0022%s: received %u bytes, passing in 10s\u005cn\u0022,\n\t\t\t __func__, (unsigned int)m-\u003eamount);\n\n\t\tlws_sul_schedule(context, 0, \u0026sul_pass, completion_sul_cb,\n\t\t\t\t 5 * LWS_US_PER_SEC);\n\n\t\treturn LWSSSSRET_DESTROY_ME;\n\t}\n\n\treturn 0;\n}\n\nstatic int\nmyss_state(void *userobj, void *sh, lws_ss_constate_t state,\n\t lws_ss_tx_ordinal_t ack)\n{\n\tmyss_t *m \u003d (myss_t *)userobj;\n\n\tlwsl_user(\u0022%s: %s, ord 0x%x\u005cn\u0022, __func__, lws_ss_state_name(state),\n\t\t (unsigned int)ack);\n\n\tswitch (state) {\n\tcase LWSSSCS_CREATING:\n\t\treturn lws_ss_client_connect(m-\u003ess);\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn 0;\n}\n\nstatic const lws_ss_info_t ssi \u003d {\n\t.handle_offset\t\t\t\u003d offsetof(myss_t, ss),\n\t.opaque_user_data_offset\t\u003d offsetof(myss_t, opaque_data),\n\t.rx\t\t\t\t\u003d myss_rx,\n\t.state\t\t\t\t\u003d myss_state,\n\t.user_alloc\t\t\t\u003d sizeof(myss_t),\n\t.streamtype\t\t\t\u003d \u0022test_stream\u0022,\n};\n\nstatic const lws_led_sequence_def_t *seqs[] \u003d {\n\t\u0026lws_pwmseq_static_on,\n\t\u0026lws_pwmseq_static_off,\n\t\u0026lws_pwmseq_sine_endless_slow,\n\t\u0026lws_pwmseq_sine_endless_fast,\n};\n\nstatic int\nsmd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, void *buf,\n size_t len)\n{\n\n\tif (!lws_json_simple_strcmp(buf, len, \u0022\u005c\u0022src\u005c\u0022:\u0022, \u0022bc/user\u0022) \u0026\u0026\n\t !lws_json_simple_strcmp(buf, len, \u0022\u005c\u0022event\u005c\u0022:\u0022, \u0022click\u0022)) {\n\t\tlws_led_transition(lls, \u0022blue\u0022, seqs[flip \u0026 3],\n\t\t\t\t \u0026lws_pwmseq_linear_wipe);\n\t\tflip++;\n\t}\n\n\tlwsl_hexdump_notice(buf, len);\n\n\tif ((_class \u0026 LWSSMDCL_SYSTEM_STATE) \u0026\u0026\n\t !lws_json_simple_strcmp(buf, len, \u0022\u005c\u0022state\u005c\u0022:\u0022, \u0022OPERATIONAL\u0022)) {\n\n\t\t/* create the secure stream */\n\n\t\tlwsl_notice(\u0022%s: creating test secure stream\u005cn\u0022, __func__);\n\n\t\tif (lws_ss_create(context, 0, \u0026ssi, NULL, NULL, NULL, NULL)) {\n\t\t\tlwsl_err(\u0022%s: failed to create secure stream\u005cn\u0022,\n\t\t\t\t __func__);\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tif (_class \u0026 LWSSMDCL_INTERACTION)\n\t\t/*\n\t\t * Any kind of user interaction brings the display back up and\n\t\t * resets the dimming / blanking timers\n\t\t */\n\t\tlws_display_state_active(\u0026lds);\n\n\treturn 0;\n}\n\nvoid \napp_main(void)\n{\n\tstruct lws_context_creation_info *info;\n\tlws_box_t box \u003d { {0,0}, {0,0}, {320,0}, {240,0} };\n\n\tlws_set_log_level(1024 | 15, NULL);\n\n lws_netdev_plat_init();\n lws_netdev_plat_wifi_init();\n\n info \u003d malloc(sizeof(*info));\n if (!info)\n \tgoto spin;\n\n\tmemset(info, 0, sizeof(*info));\n\n\tlwsl_notice(\u0022LWS test for Espressif ESP32 WROVER KIT\u005cn\u0022);\n\n#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY)\n\tinfo-\u003epss_policies_json\t\t\u003d ss_policy;\n#else\n\tinfo-\u003epss_policies\t\t\u003d \u0026_ss_static_policy_entry;\n#endif\n\tinfo-\u003eoptions\t\t\t\u003d LWS_SERVER_OPTION_EXPLICIT_VHOSTS |\n\t\t\t\t\t LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;\n\tinfo-\u003eport\t\t\t\u003d CONTEXT_PORT_NO_LISTEN;\n\tinfo-\u003eearly_smd_cb\t\t\u003d smd_cb;\n\tinfo-\u003eearly_smd_class_filter\t\u003d LWSSMDCL_INTERACTION |\n\t\t\t\t\t LWSSMDCL_SYSTEM_STATE |\n\t\t\t\t\t LWSSMDCL_NETWORK;\n\tinfo-\u003esmd_ttl_us\t\t\u003d 20 * LWS_USEC_PER_SEC; /* we can spend a long time in display */\n\n\tcontext \u003d lws_create_context(info);\n\tif (!context) {\n\t\tlwsl_err(\u0022lws init failed\u005cn\u0022);\n\t\tgoto spin;\n\t}\n\n\t/*\n\t * We don't need this after context creation... things it pointed to\n\t * still need to exist though since the context copied the pointers.\n\t */\n\n\tfree(info);\n\n\t/* devices and init are in devices.c */\n\n\tif (init_plat_devices(context))\n\t\tgoto spin;\n\n\t/* put the cat picture up there and enable the backlight */\n\n\tlds.disp-\u003eblit(\u0026lds, logo, \u0026box, NULL);\n\tlws_display_state_active(\u0026lds);\n\n\t/* the lws event loop */\n\n\tdo {\n\t\ttaskYIELD();\n\t\tlws_service(context, 0);\n\t} while (1);\n\n\tlwsl_notice(\u0022%s: exited event loop\u005cn\u0022, __func__);\n\n\nspin:\n\tvTaskDelay(10);\n\ttaskYIELD();\n\tgoto spin;\n}\n","s":{"c":1731846295,"u": 857}}
],"g": 3379,"chitpc": 0,"ehitpc": 0,"indexed":0
,
"ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}