├── .gitignore ├── CHANGELOG ├── LICENSE ├── Makefile ├── README.md ├── app ├── .gitignore ├── Makefile ├── crypto │ ├── Makefile │ ├── digests.c │ ├── digests.h │ ├── sha2.c │ └── sha2.h ├── dns │ ├── Makefile │ ├── dns.c │ └── dns.h ├── driver │ ├── Makefile │ ├── gpio16.c │ ├── readline.c │ ├── rfm69.c │ ├── spi.c │ └── uart_interrupt.c ├── http │ ├── Makefile │ ├── app.c │ ├── app.h │ ├── cgi.c │ ├── cgi.h │ ├── cgi_console.c │ ├── cgi_console.h │ ├── cgi_fs.c │ ├── cgi_fs.h │ ├── cgi_menu.c │ ├── cgi_menu.h │ ├── cgi_rfm69.c │ ├── cgi_rfm69.h │ ├── cgi_wifi.c │ ├── cgi_wifi.h │ ├── http.h │ ├── http_client.c │ ├── http_client.h │ ├── http_helper.c │ ├── http_helper.h │ ├── http_parser.c │ ├── http_parser.h │ ├── http_process.c │ ├── http_process.h │ ├── http_server.c │ ├── http_server.h │ ├── http_websocket_server.c │ ├── http_websocket_server.h │ ├── websocket.c │ ├── websocket.h │ ├── ws_app.c │ └── ws_app.h ├── include │ ├── arch │ │ ├── cc.h │ │ ├── perf.h │ │ └── sys_arch.h │ ├── driver │ │ ├── gpio16.h │ │ ├── rfm69.h │ │ ├── rfm69_register.h │ │ ├── spi.h │ │ ├── spi_register.h │ │ ├── uart.h │ │ └── uart_register.h │ ├── json │ │ └── cJSON.h │ ├── lwip │ │ ├── api.h │ │ ├── api_msg.h │ │ ├── app │ │ │ ├── dhcpserver.h │ │ │ ├── espconn.h │ │ │ ├── espconn_tcp.h │ │ │ ├── espconn_udp.h │ │ │ └── ping.h │ │ ├── arch.h │ │ ├── autoip.h │ │ ├── debug.h │ │ ├── def.h │ │ ├── dhcp.h │ │ ├── dns.h │ │ ├── err.h │ │ ├── icmp.h │ │ ├── igmp.h │ │ ├── inet.h │ │ ├── inet_chksum.h │ │ ├── init.h │ │ ├── ip.h │ │ ├── ip_addr.h │ │ ├── ip_frag.h │ │ ├── mdns.h │ │ ├── mem.h │ │ ├── memp.h │ │ ├── memp_std.h │ │ ├── netbuf.h │ │ ├── netdb.h │ │ ├── netif.h │ │ ├── netifapi.h │ │ ├── opt.h │ │ ├── pbuf.h │ │ ├── puck_def.h │ │ ├── raw.h │ │ ├── sio.h │ │ ├── snmp.h │ │ ├── snmp_asn1.h │ │ ├── snmp_msg.h │ │ ├── snmp_structs.h │ │ ├── sntp.h │ │ ├── sockets.h │ │ ├── stats.h │ │ ├── sys.h │ │ ├── tcp.h │ │ ├── tcp_impl.h │ │ ├── tcpip.h │ │ ├── timers.h │ │ └── udp.h │ ├── lwipopts.h │ ├── netif │ │ ├── etharp.h │ │ ├── if_llc.h │ │ ├── ppp_oe.h │ │ └── wlan_lwip_if.h │ ├── rom.h │ ├── rtc │ │ ├── rtcaccess.h │ │ ├── rtcfifo.h │ │ ├── rtctime.h │ │ └── rtctime_internal.h │ ├── sections.h │ └── user_config.h ├── json │ ├── Makefile │ └── cJSON.c ├── libc │ ├── Makefile │ ├── c_ctype.c │ ├── c_ctype.h │ ├── c_errno.h │ ├── c_fcntl.h │ ├── c_float.h │ ├── c_limits.h │ ├── c_locale.h │ ├── c_math.c │ ├── c_math.h │ ├── c_signal.h │ ├── c_stdarg.h │ ├── c_stddef.h │ ├── c_stdint.h │ ├── c_stdio.c │ ├── c_stdio.h │ ├── c_stdlib.c │ └── c_stdlib.h ├── lwip │ ├── Makefile │ ├── api │ │ ├── Makefile │ │ ├── api_lib.c │ │ ├── api_msg.c │ │ ├── err.c │ │ ├── netbuf.c │ │ ├── netdb.c │ │ ├── netifapi.c │ │ ├── sockets.c │ │ └── tcpip.c │ ├── app │ │ ├── Makefile │ │ ├── dhcpserver.c │ │ ├── espconn.c │ │ ├── espconn_mdns.c │ │ ├── espconn_tcp.c │ │ ├── espconn_udp.c │ │ ├── netio.c │ │ └── ping.c │ ├── core │ │ ├── Makefile │ │ ├── def.c │ │ ├── dhcp.c │ │ ├── dns.c │ │ ├── init.c │ │ ├── ipv4 │ │ │ ├── Makefile │ │ │ ├── autoip.c │ │ │ ├── icmp.c │ │ │ ├── igmp.c │ │ │ ├── inet.c │ │ │ ├── inet_chksum.c │ │ │ ├── ip.c │ │ │ ├── ip_addr.c │ │ │ └── ip_frag.c │ │ ├── mdns.c │ │ ├── mem.c │ │ ├── memp.c │ │ ├── netif.c │ │ ├── pbuf.c │ │ ├── raw.c │ │ ├── sntp.c │ │ ├── stats.c │ │ ├── sys.c │ │ ├── sys_arch.c │ │ ├── tcp.c │ │ ├── tcp_in.c │ │ ├── tcp_out.c │ │ ├── timers.c │ │ └── udp.c │ └── netif │ │ ├── Makefile │ │ └── etharp.c ├── mqtt │ ├── Makefile │ ├── app.c │ ├── app.h │ ├── mqtt.c │ ├── mqtt.h │ ├── mqtt_api.h │ ├── mqtt_config.h │ ├── mqtt_helper.h │ ├── mqtt_msg.c │ ├── mqtt_msg.h │ ├── mqtt_queue.c │ ├── mqtt_queue.h │ ├── proto.c │ ├── proto.h │ ├── ringbuf.c │ ├── ringbuf.h │ ├── typedef.h │ ├── utils.c │ └── utils.h ├── platform │ ├── Makefile │ ├── common.c │ ├── common.h │ ├── config.c │ ├── config.h │ ├── cpu_esp8266.h │ ├── event.c │ ├── event.h │ ├── flash_api.c │ ├── flash_api.h │ ├── flash_fs.c │ ├── flash_fs.h │ ├── led.c │ ├── led.h │ ├── platform.c │ └── platform.h ├── rfm │ ├── Makefile │ ├── app.c │ ├── app.h │ ├── radiohandler.c │ ├── radiohandler.h │ ├── rfm.h │ ├── rfm_parser.c │ └── rfm_parser.h ├── smart │ ├── Makefile │ ├── smart.c │ └── smart.h ├── spiffs │ ├── Makefile │ ├── docs │ │ ├── IMPLEMENTING │ │ ├── INTEGRATION │ │ ├── TECH_SPEC │ │ └── TODO │ ├── spiffs.c │ ├── spiffs.h │ ├── spiffs_cache.c │ ├── spiffs_check.c │ ├── spiffs_config.h │ ├── spiffs_gc.c │ ├── spiffs_hydrogen.c │ ├── spiffs_nucleus.c │ ├── spiffs_nucleus.h │ └── test │ │ ├── esp-ginx-fs-test.c │ │ ├── main.c │ │ ├── params_test.h │ │ ├── test_bugreports.c │ │ ├── test_check.c │ │ ├── test_dev.c │ │ ├── test_hydrogen.c │ │ ├── test_spiffs.c │ │ ├── test_spiffs.h │ │ ├── testrunner.c │ │ ├── testrunner.h │ │ └── testsuites.c ├── user │ ├── Makefile │ ├── user_exceptions.c │ ├── user_exceptions.h │ └── user_main.c └── util │ ├── Makefile │ ├── base64.c │ ├── base64.h │ ├── bitwise_utils.c │ ├── bitwise_utils.h │ ├── cbuff.c │ ├── cbuff.h │ ├── linked_list.c │ ├── linked_list.h │ ├── netutil.c │ └── netutil.h ├── bin └── .gitignore ├── doc ├── console.png ├── filesys.png ├── ota.png └── uploader.png ├── ld ├── defsym.rom ├── eagle.app.v6.ld └── eagle.rom.addr.v6.ld ├── lib ├── libat.a ├── libcrypto.a ├── libespnow.a ├── libjson.a ├── liblwip.a ├── liblwip_536.a ├── libmain.a ├── libmesh.a ├── libnet80211.a ├── libphy.a ├── libpp.a ├── libpwm.a ├── libsmartconfig.a ├── libssl.a ├── libupgrade.a ├── libwpa.a ├── libwpa2.a └── libwps.a ├── sdk-overrides └── include │ ├── c_types.h │ ├── mem.h │ └── osapi.h └── tools ├── .gitattributes ├── esptool.py ├── makefile.sh └── spiffy-compressor ├── .gitignore ├── README.md ├── html ├── console.js ├── favicon.ico ├── filesys.css ├── filesys.js ├── fw.css ├── fw.js ├── head.load.min.js ├── index.html ├── ki-ex.js ├── ki.min.js ├── min.css ├── style.css ├── upload.js └── wifi │ ├── icons.png │ └── wifi.js ├── spiffy ├── makefile └── src │ ├── main.c │ ├── spiffs.h │ ├── spiffs_cache.c │ ├── spiffs_check.c │ ├── spiffs_config.h │ ├── spiffs_gc.c │ ├── spiffs_hydrogen.c │ ├── spiffs_nucleus.c │ └── spiffs_nucleus.h └── utils ├── htmlcompressor-1.5.3.jar └── yuicompressor-2.4.8.jar /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | firmware/ 3 | fw/ 4 | espfs/mkespfsimage/*.o 5 | espfs/mkespfsimage/mkespfsimage 6 | webpages.espfs 7 | espfs/espfstest/*.o 8 | espfs/espfstest/espfstest 9 | *.DS_Store 10 | html_compressed/ 11 | yui 12 | *~ 13 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | *.output* 2 | *mapfile* 3 | !.gitignore 4 | *.tmp.section* 5 | -------------------------------------------------------------------------------- /app/crypto/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = libcrypto.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | ############################################################# 29 | # Recursion Magic - Don't touch this!! 30 | # 31 | # Each subtree potentially has an include directory 32 | # corresponding to the common APIs applicable to modules 33 | # rooted at that subtree. Accordingly, the INCLUDE PATH 34 | # of a module can only contain the include directories up 35 | # its parent path, and not its siblings 36 | # 37 | # Required for each makefile to inherit from the parent 38 | # 39 | 40 | INCLUDES := $(INCLUDES) -I $(PDIR)include 41 | INCLUDES += -I ./ 42 | INCLUDES += -I ../libc 43 | PDIR := ../$(PDIR) 44 | sinclude $(PDIR)Makefile 45 | -------------------------------------------------------------------------------- /app/crypto/digests.h: -------------------------------------------------------------------------------- 1 | #ifndef _CRYPTO_DIGESTS_H_ 2 | #define _CRYPTO_DIGESTS_H_ 3 | 4 | #include 5 | 6 | typedef void (*create_ctx_fn)(void *ctx); 7 | typedef void (*update_ctx_fn)(void *ctx, const uint8_t *msg, int len); 8 | typedef void (*finalize_ctx_fn)(uint8_t *digest, void *ctx); 9 | 10 | /** 11 | * Description of a message digest mechanism. 12 | * 13 | * Typical usage (if not using the crypto_xxxx() functions below): 14 | * digest_mech_info_t *mi = crypto_digest_mech (chosen_algorithm); 15 | * void *ctx = os_malloc (mi->ctx_size); 16 | * mi->create (ctx); 17 | * mi->update (ctx, data, len); 18 | * ... 19 | * uint8_t *digest = os_malloc (mi->digest_size); 20 | * mi->finalize (digest, ctx); 21 | * ... 22 | * os_free (ctx); 23 | * os_free (digest); 24 | */ 25 | typedef struct 26 | { 27 | /* Note: All entries are 32bit to enable placement using ICACHE_RODATA_ATTR.*/ 28 | const char * name; 29 | create_ctx_fn create; 30 | update_ctx_fn update; 31 | finalize_ctx_fn finalize; 32 | uint32_t ctx_size; 33 | uint32_t digest_size; 34 | uint32_t block_size; 35 | } digest_mech_info_t; 36 | 37 | 38 | /** 39 | * Looks up the mech data for a specified digest algorithm. 40 | * @param mech The name of the algorithm, e.g. "MD5", "SHA256" 41 | * @returns The mech data, or null if the mech is unknown. 42 | */ 43 | const digest_mech_info_t *crypto_digest_mech (const char *mech); 44 | 45 | /** 46 | * Wrapper function for performing a one-in-all hashing operation. 47 | * @param mi A mech from @c crypto_digest_mech(). A null pointer @c mi 48 | * is harmless, but will of course result in an error return. 49 | * @param data The data to create a digest for. 50 | * @param data_len Number of bytes at @c data to digest. 51 | * @param digest Output buffer, must be at least @c mi->digest_size in size. 52 | * @return 0 on success, non-zero on error. 53 | */ 54 | int crypto_hash (const digest_mech_info_t *mi, const char *data, size_t data_len, uint8_t *digest); 55 | 56 | 57 | /** 58 | * Generate a HMAC signature. 59 | * @param mi A mech from @c crypto_digest_mech(). A null pointer @c mi 60 | * is harmless, but will of course result in an error return. 61 | * @param data The data to generate a signature for. 62 | * @param data_len Number of bytes at @c data to process. 63 | * @param key The key to use. 64 | * @param key_len Number of bytes the @c key comprises. 65 | * @param digest Output buffer, must be at least @c mi->digest_size in size. 66 | * @return 0 on success, non-zero on error. 67 | */ 68 | int crypto_hmac (const digest_mech_info_t *mi, const char *data, size_t data_len, const char *key, size_t key_len, uint8_t *digest); 69 | 70 | /** 71 | * Perform ASCII Hex encoding. Does not null-terminate the buffer. 72 | * 73 | * @param bin The buffer to ascii-hex encode. 74 | * @param bin_len Number of bytes in @c bin to encode. 75 | * @param outbuf Output buffer, must be at least @c bin_len*2 bytes in size. 76 | * Note that in-place encoding is supported, and as such 77 | * bin==outbuf is safe, provided the buffer is large enough. 78 | */ 79 | void crypto_encode_asciihex (const char *bin, size_t bin_len, char *outbuf); 80 | 81 | 82 | /** Text string "0123456789abcdef" */ 83 | const char crypto_hexbytes[17]; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /app/crypto/sha2.h: -------------------------------------------------------------------------------- 1 | #ifndef __SHA2_H__ 2 | #define __SHA2_H__ 3 | 4 | #include 5 | 6 | /************************************************************************** 7 | * SHA256/384/512 declarations 8 | **************************************************************************/ 9 | 10 | #define SHA256_BLOCK_LENGTH 64 11 | #define SHA256_DIGEST_LENGTH 32 12 | 13 | typedef struct 14 | { 15 | uint32_t state[8]; 16 | uint64_t bitcount; 17 | uint8_t buffer[SHA256_BLOCK_LENGTH]; 18 | } SHA256_CTX; 19 | 20 | 21 | void SHA256_Init(SHA256_CTX *); 22 | void SHA256_Update(SHA256_CTX *, const uint8_t *msg, size_t len); 23 | void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*); 24 | 25 | #define SHA384_BLOCK_LENGTH 128 26 | #define SHA384_DIGEST_LENGTH 48 27 | 28 | typedef struct 29 | { 30 | uint64_t state[8]; 31 | uint64_t bitcount[2]; 32 | uint8_t buffer[SHA384_BLOCK_LENGTH]; 33 | } SHA384_CTX; 34 | 35 | void SHA384_Init(SHA384_CTX*); 36 | void SHA384_Update(SHA384_CTX*, const uint8_t *msg, size_t len); 37 | void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*); 38 | 39 | #define SHA512_BLOCK_LENGTH 128 40 | #define SHA512_DIGEST_LENGTH 64 41 | typedef SHA384_CTX SHA512_CTX; 42 | 43 | void SHA512_Init(SHA512_CTX*); 44 | void SHA512_Update(SHA512_CTX*, const uint8_t *msg, size_t len); 45 | void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /app/dns/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = dns.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | ############################################################# 29 | # Recursion Magic - Don't touch this!! 30 | # 31 | # Each subtree potentially has an include directory 32 | # corresponding to the common APIs applicable to modules 33 | # rooted at that subtree. Accordingly, the INCLUDE PATH 34 | # of a module can only contain the include directories up 35 | # its parent path, and not its siblings 36 | # 37 | # Required for each makefile to inherit from the parent 38 | # 39 | 40 | INCLUDES := $(INCLUDES) -I $(PDIR)include 41 | INCLUDES += -I ./ 42 | INCLUDES += -I ../libc 43 | PDIR := ../$(PDIR) 44 | sinclude $(PDIR)Makefile 45 | -------------------------------------------------------------------------------- /app/dns/dns.h: -------------------------------------------------------------------------------- 1 | #ifndef DNS_H 2 | #define DNS_H 3 | 4 | void ICACHE_FLASH_ATTR init_dns(); 5 | 6 | #endif -------------------------------------------------------------------------------- /app/driver/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = libdriver.a 16 | endif 17 | 18 | EXTRA_CCFLAGS += -DRFM69_FREQ=$(RFM69_FREQ) -DRFM69_NET_ID=$(RFM69_NET_ID) \ 19 | -DRFM69_NODE_ID=$(RFM69_NODE_ID) -DRFM69_IS_HW=$(RFM69_IS_HW) \ 20 | -DRFM69_ENCRYPT_KEY=$(RFM69_ENCRYPT_KEY) -DRFM_INTR_PIN=$(RFM_INTR_PIN) 21 | 22 | ############################################################# 23 | # Configuration i.e. compile options etc. 24 | # Target specific stuff (defines etc.) goes in here! 25 | # Generally values applying to a tree are captured in the 26 | # makefile at its root level - these are then overridden 27 | # for a subtree within the makefile rooted therein 28 | # 29 | #DEFINES += 30 | # STD_CFLAGS=-std=gnu11 -Wimplicit 31 | 32 | ############################################################# 33 | # Recursion Magic - Don't touch this!! 34 | # 35 | # Each subtree potentially has an include directory 36 | # corresponding to the common APIs applicable to modules 37 | # rooted at that subtree. Accordingly, the INCLUDE PATH 38 | # of a module can only contain the include directories up 39 | # its parent path, and not its siblings 40 | # 41 | # Required for each makefile to inherit from the parent 42 | # 43 | 44 | INCLUDES := $(INCLUDES) -I $(PDIR)include 45 | INCLUDES += -I ./ 46 | INCLUDES += -I ../platform 47 | INCLUDES += -I ../rfm 48 | INCLUDES += -I ../util 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | -------------------------------------------------------------------------------- /app/driver/readline.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "osapi.h" 4 | #include "driver/uart.h" 5 | #include "c_types.h" 6 | 7 | LOCAL os_timer_t readline_timer; 8 | 9 | // UartDev is defined and initialized in rom code. 10 | extern UartDevice UartDev; 11 | 12 | #define uart_putc uart0_putc 13 | 14 | bool uart_getc(char *c){ 15 | RcvMsgBuff *pRxBuff = &(UartDev.rcv_buff); 16 | if(pRxBuff->pWritePos == pRxBuff->pReadPos){ // empty 17 | return false; 18 | } 19 | // ETS_UART_INTR_DISABLE(); 20 | ETS_INTR_LOCK(); 21 | *c = (char)*(pRxBuff->pReadPos); 22 | if (pRxBuff->pReadPos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) { 23 | pRxBuff->pReadPos = pRxBuff->pRcvMsgBuff ; 24 | } else { 25 | pRxBuff->pReadPos++; 26 | } 27 | // ETS_UART_INTR_ENABLE(); 28 | ETS_INTR_UNLOCK(); 29 | return true; 30 | } 31 | 32 | #if 0 33 | int readline4lua(const char *prompt, char *buffer, int length){ 34 | char ch; 35 | int line_position; 36 | 37 | start: 38 | /* show prompt */ 39 | uart0_sendStr(prompt); 40 | 41 | line_position = 0; 42 | os_memset(buffer, 0, length); 43 | while (1) 44 | { 45 | while (uart_getc(&ch)) 46 | { 47 | /* handle CR key */ 48 | if (ch == '\r') 49 | { 50 | char next; 51 | if (uart_getc(&next)) 52 | ch = next; 53 | } 54 | /* backspace key */ 55 | else if (ch == 0x7f || ch == 0x08) 56 | { 57 | if (line_position > 0) 58 | { 59 | uart_putc(0x08); 60 | uart_putc(' '); 61 | uart_putc(0x08); 62 | line_position--; 63 | } 64 | buffer[line_position] = 0; 65 | continue; 66 | } 67 | /* EOF(ctrl+d) */ 68 | else if (ch == 0x04) 69 | { 70 | if (line_position == 0) 71 | /* No input which makes lua interpreter close */ 72 | return 0; 73 | else 74 | continue; 75 | } 76 | 77 | /* end of line */ 78 | if (ch == '\r' || ch == '\n') 79 | { 80 | buffer[line_position] = 0; 81 | uart_putc('\n'); 82 | if (line_position == 0) 83 | { 84 | /* Get a empty line, then go to get a new line */ 85 | goto start; 86 | } 87 | else 88 | { 89 | return line_position; 90 | } 91 | } 92 | 93 | /* other control character or not an acsii character */ 94 | if (ch < 0x20 || ch >= 0x80) 95 | { 96 | continue; 97 | } 98 | 99 | /* echo */ 100 | uart_putc(ch); 101 | buffer[line_position] = ch; 102 | ch = 0; 103 | line_position++; 104 | 105 | /* it's a large line, discard it */ 106 | if (line_position >= length) 107 | line_position = 0; 108 | } 109 | } 110 | } 111 | #endif 112 | -------------------------------------------------------------------------------- /app/http/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = http.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | EXTRA_CCFLAGS += \ 29 | -DATMEGA_FLASH_ADDR0=$(ATMEGA_FLASH_ADDR0) 30 | 31 | 32 | ############################################################# 33 | # Recursion Magic - Don't touch this!! 34 | # 35 | # Each subtree potentially has an include directory 36 | # corresponding to the common APIs applicable to modules 37 | # rooted at that subtree. Accordingly, the INCLUDE PATH 38 | # of a module can only contain the include directories up 39 | # its parent path, and not its siblings 40 | # 41 | # Required for each makefile to inherit from the parent 42 | #INCLUDES += -I ../libc 43 | #INCLUDES += -I ../spiffs 44 | 45 | INCLUDES := $(INCLUDES) -I $(PDIR)include 46 | INCLUDES += -I ./ 47 | INCLUDES += -I ../libc 48 | INCLUDES += -I ../platform 49 | INCLUDES += -I ../spiffs 50 | INCLUDES += -I ../ 51 | PDIR := ../$(PDIR) 52 | sinclude $(PDIR)Makefile 53 | -------------------------------------------------------------------------------- /app/http/app.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | #include "user_interface.h" 11 | #include "c_types.h" 12 | #include "espconn.h" 13 | #include "mem.h" 14 | #include "osapi.h" 15 | 16 | #include "cgi.h" 17 | #include "cgi_menu.h" 18 | #include "cgi_wifi.h" 19 | #include "cgi_console.h" 20 | #include "cgi_fs.h" 21 | #include "cgi_rfm69.h" 22 | #include "user_config.h" 23 | #include "http_server.h" 24 | #include "ws_app.h" 25 | 26 | #define HTTP_PORT 80 27 | 28 | static http_server_url api_urls[]= 29 | {//-------URL----------------------CGI------------- ARGUMENT-------METHOD-------------FLAGS----- 30 | {"/menu", http_menu_api_get, NULL, HTTP_GET, NEED_BODY}, 31 | {"/console/clear", http_console_api_clear, NULL, HTTP_POST, NO_FLAG}, 32 | {"/console", http_console_api, NULL, HTTP_POST, NEED_BODY}, 33 | {"/fs*", http_fs_api, NULL, HTTP_ANY_METHOD, NO_FLAG}, 34 | {"/rfm69/resetvals", http_rfm69_api_resetvals, NULL, HTTP_POST, NO_FLAG}, 35 | {"/rfm69/status", http_rfm69_api_status, NULL, HTTP_POST, NO_FLAG}, 36 | {"/rfm69/update", http_rfm69_api_update, NULL, HTTP_POST, NO_FLAG}, 37 | {"/wifi/connect", http_wifi_api_connect_ap, NULL, HTTP_POST, NEED_BODY}, 38 | {"/wifi/dc", http_wifi_api_disconnect, NULL, HTTP_POST, NO_FLAG}, 39 | {"/wifi/info", http_wifi_api_get_info, NULL, HTTP_POST, NEED_BODY}, 40 | {"/wifi/status", http_wifi_api_get_status, NULL, HTTP_POST, NO_FLAG}, 41 | {"/wifi/scan", http_wifi_api_scan, NULL, HTTP_POST, NO_FLAG}, 42 | {NULL, NULL, NULL, HTTP_ANY_METHOD, NO_FLAG}, 43 | }; 44 | 45 | static url_rewrite rewrites[]= 46 | {//----PATH---------REWRITE------- 47 | {"/" ,"/index.html"}, 48 | {NULL ,NULL} 49 | }; 50 | 51 | void init_http_server() 52 | { 53 | //general max tcp conns 54 | espconn_tcp_set_max_con(20); 55 | 56 | http_server_init(); 57 | http_server_bind_domain(INTERFACE_DOMAIN); 58 | http_server_enable_captive_portal(); 59 | http_server_enable_cors(); 60 | http_server_rewrite(rewrites); 61 | http_server_bind_urls((http_server_url *)&api_urls); 62 | http_server_start(); 63 | 64 | //ws 65 | init_ws_server(); 66 | } 67 | -------------------------------------------------------------------------------- /app/http/app.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | #ifndef __HTTP_H 11 | #define __HTTP_H 12 | 13 | void ICACHE_FLASH_ATTR init_http_server(); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /app/http/cgi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef CGI_H 12 | #define CGI_H 13 | 14 | #include "http.h" 15 | 16 | struct cgi_transmit_arg{ 17 | cgi_struct previous_cgi; 18 | 19 | uint8_t *data; 20 | uint8_t *dataPos; 21 | uint16_t len; 22 | }; 23 | 24 | int cgi_transmit(http_connection *connData); 25 | int cgi_cors(http_connection *connData); 26 | int cgi_url_rewrite(http_connection *connData); 27 | int cgi_redirect(http_connection *connData); 28 | int cgi_check_host(http_connection *connData); 29 | int cgi_enforce_method(http_connection *connData); 30 | int cgi_enforce_body(http_connection *connData); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /app/http/cgi_console.h: -------------------------------------------------------------------------------- 1 | #ifndef CGI_CONSOLE_H 2 | #define CGI_CONSOLE_H 3 | 4 | #define BUF_MAX (128) 5 | 6 | 7 | typedef enum { 8 | cons_start_t, 9 | cons_pwr_t, 10 | cons_to_node_t, 11 | cons_disp_t, 12 | } cons_method_t; 13 | 14 | typedef enum { 15 | power_on_btn, //0 16 | power_off_btn, 17 | } console_btn_t; 18 | 19 | int http_console_api(http_connection *c); 20 | int http_console_api_clear(http_connection *c); 21 | int http_console_api_rfm69_info(http_connection *c); 22 | 23 | int http_console_api_server(http_connection *c); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /app/http/cgi_fs.h: -------------------------------------------------------------------------------- 1 | #ifndef CGI_FS_H 2 | #define CGI_FS_H 3 | 4 | #define CGI_FS_EOF (1<<1) 5 | #define CGI_FS_STATICFS (1<<2) //>>3 == 0 6 | #define CGI_FS_DYNFS (1<<3) //>>3 == 1 7 | 8 | #define CGI_PAR_GETFS(x) (x & (1>>3)) 9 | 10 | typedef struct { 11 | size_t size; 12 | uint8_t flags; 13 | char * name; //ptr to const chars 14 | int pix; 15 | } CGI_SPIFFS_ENTRY; 16 | 17 | typedef struct { 18 | CGI_SPIFFS_ENTRY *file; 19 | uint32_t readPos; 20 | uint8_t fs_flags; 21 | } CGI_FILE_STATE_T; 22 | 23 | typedef struct 24 | { 25 | uint8_t api_state; 26 | CGI_FILE_STATE_T *f; 27 | char *buff; 28 | } cgi_fs_state; 29 | 30 | typedef struct { 31 | uint8_t state; 32 | char * bStr; 33 | char * filename; 34 | int total_size; 35 | int seq; 36 | } api_cgi_upload_status; 37 | 38 | int http_static_api(http_connection *c); 39 | int http_fs_api(http_connection *c); 40 | 41 | int http_fs_api_list(http_connection *c); 42 | int http_fs_api_rename(http_connection *c); 43 | int http_fs_api_delete(http_connection *c); 44 | int http_fs_api_download(http_connection *c); 45 | int http_fs_api_upload(http_connection *c); 46 | int http_fs_api_fw(http_connection *c); 47 | 48 | int http_fs_api_uploadfile(http_connection *c); 49 | 50 | char * getFilename(char * buff); 51 | char * getDataBegin(char * buff); 52 | char * getBoundaryStr(char * buff); 53 | int checkForLastPkt(char * buff, char * boundStr); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /app/http/cgi_menu.c: -------------------------------------------------------------------------------- 1 | /* 2 | Menu and general index CGI routines 3 | */ 4 | #include "user_interface.h" 5 | #include "osapi.h" 6 | #include "mem.h" 7 | #include "platform.h" 8 | #include "user_config.h" 9 | 10 | #include "cgi.h" 11 | #include "http.h" 12 | #include "http_parser.h" 13 | #include "http_server.h" 14 | #include "http_process.h" 15 | #include "http_helper.h" 16 | #include "http_client.h" 17 | #include "json/cJSON.h" 18 | 19 | #include "cgi_menu.h" 20 | 21 | extern char *esp_rfm69_version; // in user_main.c 22 | 23 | int http_menu_api_get(http_connection *c) { 24 | CGI_MENU_DBG("http_menu_api_get\n"); 25 | //wait for whole body 26 | if(c->state state state and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef CGI_WIFI_H 12 | #define CGI_WIFI_H 13 | 14 | int http_wifi_api_get_info(http_connection *c); 15 | int http_wifi_api_get_status(http_connection *c); 16 | int http_wifi_api_scan(http_connection *c); 17 | int http_wifi_api_connect_ap(http_connection *c); 18 | int http_wifi_api_disconnect(http_connection *c); 19 | int http_wifi_api_check_internet(http_connection *c); 20 | #endif 21 | -------------------------------------------------------------------------------- /app/http/http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef __HTTP_H 12 | #define __HTTP_H 13 | 14 | #define HTTP_BUFFER_SIZE 1460 // Let's keep it close the TCP MTU (maximum transmit unit) ( 1460 on this lwip ) 15 | //so we will send a whole packet per time 16 | #define MAX_HEADERS 10 17 | #define URL_MAX_SIZE 256 18 | 19 | #define HTTP_CGI_ARG_FS0 1 //default - load from FS0/semi-static 20 | #define HTTP_CGI_ARG_FS1 2 21 | 22 | #include "http_parser.h" 23 | #include "espconn.h" 24 | #include "user_interface.h" 25 | #include "lwip/ip_addr.h" 26 | 27 | typedef struct http_connection http_connection; 28 | typedef int (*http_callback)(http_connection *c); //callback function 29 | typedef int (*cgi_execute_function)(http_connection *c); //cgi execute function 30 | 31 | typedef struct { 32 | const char * key; 33 | char * value; 34 | uint8_t save; 35 | } header; 36 | 37 | typedef struct { 38 | uint8_t *buffer; 39 | uint8_t *bufferPos; 40 | header headers[MAX_HEADERS]; 41 | } http_buffer; 42 | 43 | typedef struct { 44 | cgi_execute_function execute; 45 | 46 | http_callback function; 47 | 48 | void *data; 49 | const void *argument; 50 | uint8_t done; 51 | 52 | uint32_t flags; 53 | 54 | } cgi_struct; 55 | 56 | struct http_connection { 57 | 58 | uint8_t type; 59 | 60 | struct espconn *espConnection; 61 | 62 | struct espconn client_connection; 63 | esp_tcp client_tcp; 64 | ip_addr_t host_ip; 65 | os_timer_t timeout_timer; 66 | enum http_method method; 67 | char * request_body; 68 | 69 | struct http_parser parser; 70 | struct http_parser_settings parser_settings; 71 | 72 | uint8_t state; 73 | 74 | char url[URL_MAX_SIZE]; 75 | struct http_parser_url url_parsed; 76 | 77 | //headers 78 | header headers[MAX_HEADERS]; 79 | 80 | //body 81 | struct { 82 | uint8_t save; 83 | char *data; 84 | size_t len; 85 | } body; 86 | 87 | cgi_struct cgi; 88 | 89 | http_buffer output; 90 | 91 | //websocket related 92 | uint8_t handshake_ok; 93 | 94 | void *reverse; 95 | }; 96 | 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /app/http/http_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef __HTTP_CLIENT_H 12 | #define __HTTP_CLIENT_H 13 | 14 | 15 | 16 | http_connection * http_client_new(http_callback callback); 17 | int http_client_open_url(http_connection *c,char *url); 18 | 19 | int http_client_GET(http_connection *c,char *url); 20 | int http_client_POST(http_connection *c,char *url); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /app/http/http_process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef http_server_h 12 | #define http_server_h 13 | 14 | #include "http_parser.h" 15 | 16 | #define HTTPD_CGI_MORE 0 //when we want to lock cgi on that function 17 | #define HTTPD_CGI_DONE 1 18 | #define HTTPD_CGI_NOTFOUND 2 //not found on that cgi 19 | #define HTTPD_CGI_AUTHENTICATED 2 //for now 20 | #define HTTPD_CGI_NEXT_RULE 3 //allow other cgi to execute 21 | 22 | #define HTTPD_STATE_ON_URL 0 23 | #define HTTPD_STATE_ON_STATUS 1 24 | #define HTTPD_STATE_HEADERS_END 2 25 | #define HTTPD_STATE_ON_BODY 3 26 | #define HTTPD_STATE_BODY_END 4 27 | #define HTTPD_STATE_WS_DATA 5 28 | #define HTTPD_STATE_WS_DATA_SENT 6 29 | #define HTTPD_STATE_WS_CLIENT_DISCONNECT 7 30 | 31 | //client 32 | #define HTTP_CLIENT_CGI_MORE 0 33 | #define HTTP_CLIENT_CGI_DONE 1 34 | 35 | #define HTTP_CLIENT_DNS_FOUND 100 36 | #define HTTP_CLIENT_DNS_NOT_FOUND 101 37 | #define HTTP_CLIENT_CONNECT_OK 200 38 | #define HTTP_CLIENT_CONNECT_FAIL 201 39 | #define HTTP_CLIENT_REQUEST_HEADERS_SENT 202 40 | #define HTTP_CLIENT_REQUEST_BODY_SENT 203 41 | 42 | //ws 43 | #define HTTP_WS_CGI_MORE 0 44 | #define HTTP_WS_CGI_DONE 1 45 | 46 | #define MAX_CONNECTIONS 8 47 | 48 | #include "http.h" 49 | 50 | int http_transmit(http_connection *c); 51 | int http_write(http_connection *c,const char * message); 52 | int http_nwrite(http_connection *c,const char * message,size_t size); 53 | 54 | void http_process_free_connection(http_connection *conn); 55 | 56 | 57 | char * http_url_get_path(http_connection *c); 58 | char * http_url_get_host(http_connection *c); 59 | char * http_url_get_query(http_connection *c); 60 | char * http_url_get_query_param(http_connection *c,char* param); 61 | 62 | void http_parse_url(http_connection *c); 63 | http_connection * http_new_connection(uint8_t in,struct espconn *conn); 64 | void http_execute_cgi(http_connection *conn); 65 | 66 | 67 | void http_use_multipart_body(http_connection *conn); 68 | void http_set_save_header(http_connection *conn,const char* header); 69 | void http_set_save_body(http_connection *conn); 70 | header * http_get_header(http_connection *conn,const char* header); 71 | 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /app/http/http_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Israel Lot and Jeroen Domburg 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If we meet some day, and you think this stuff is 7 | * worth it, you can buy us a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | #ifndef __HTTP_SERVER_H 12 | #define __HTTP_SERVER_H 13 | 14 | #include "http.h" 15 | 16 | #define ANY_HOST NULL 17 | #define HTTP_ANY_METHOD -1 18 | #define NO_FLAG 0 19 | 20 | #define NEED_POST 1<<0 21 | #define NEED_GET 1<<1 22 | #define NEED_BODY 1<<2 23 | 24 | //A struct describing an url and how it should be processed 25 | typedef struct { 26 | const char *url; 27 | http_callback cgiFunction; 28 | const void *cgiArgument; 29 | enum http_method method; 30 | uint32_t flags; 31 | } http_server_url; 32 | 33 | typedef struct{ 34 | char * match_url; 35 | char * rewrite_url; 36 | }url_rewrite; 37 | 38 | typedef struct { 39 | 40 | //Listening connection data 41 | struct espconn server_conn; 42 | esp_tcp server_tcp; 43 | 44 | http_server_url **urls; 45 | 46 | const char * host_domain; 47 | int port; 48 | 49 | uint8_t enable_captive; 50 | uint8_t enable_cors; 51 | 52 | url_rewrite * rewrites; 53 | int rewrite_count; 54 | 55 | } http_server_config; 56 | 57 | int http_server_cgi_execute(http_connection * conn); 58 | void http_server_rewrite(url_rewrite *rewrites); 59 | 60 | void http_server_init(); 61 | void http_server_bind_port(int port); 62 | void http_server_bind_domain(const char * domain); 63 | void http_server_bind_urls(http_server_url *urls); 64 | void http_server_enable_captive_portal(); 65 | void http_server_enable_cors(); 66 | void http_server_start(); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /app/http/http_websocket_server.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_WS_SERVER_H 2 | #define __HTTP_WS_SERVER_H 3 | 4 | 5 | typedef struct { 6 | 7 | //Listening connection data 8 | struct espconn server_conn; 9 | esp_tcp server_tcp; 10 | 11 | const char * host_domain; 12 | int port; 13 | 14 | 15 | } http_ws_config; 16 | 17 | void http_ws_push_bin(http_connection *c,char *msg,size_t msgLen); 18 | void http_ws_push_text(http_connection *c,char *msg,size_t msgLen); 19 | void http_ws_server_init(); 20 | void http_ws_server_start(); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /app/http/websocket.h: -------------------------------------------------------------------------------- 1 | #ifndef __WEBSOCKET_H 2 | #define __WEBSOCKET_H 3 | 4 | typedef void (*write_function)(const char *data,size_t len,void * arg); //callback function 5 | 6 | enum ws_frame_type { 7 | WS_CONTINUATION=0x00, 8 | WS_TEXT =0x01, 9 | WS_BINARY =0x02, 10 | WS_PING =0x09, 11 | WS_PONG =0x0A, 12 | WS_CLOSE =0x08, 13 | WS_INVALID =0xFF 14 | }; 15 | 16 | typedef struct { 17 | uint8_t FIN; 18 | uint8_t MASKED; 19 | enum ws_frame_type TYPE; 20 | 21 | uint64_t SIZE; 22 | char * DATA; 23 | } ws_frame; 24 | 25 | void ws_parse_frame(ws_frame *frame,char * data,size_t dataLen); 26 | void ws_output_frame(ws_frame *frame,enum ws_frame_type type,char * payload,size_t payloadSize); 27 | void ws_write_frame(ws_frame *frame,write_function w,void *arg); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /app/http/ws_app.h: -------------------------------------------------------------------------------- 1 | #ifndef __WS_APP_H 2 | #define __WS_APP_H 3 | 4 | #define BUF_MAX (128) 5 | #define WS_FS_BUF_MAX (256) 6 | 7 | void init_ws_server(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /app/include/arch/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | */ 34 | #ifndef __PERF_H__ 35 | #define __PERF_H__ 36 | 37 | #define PERF_START /* null definition */ 38 | #define PERF_STOP(x) /* null definition */ 39 | 40 | #endif /* __PERF_H__ */ 41 | -------------------------------------------------------------------------------- /app/include/arch/sys_arch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/include/arch/sys_arch.h -------------------------------------------------------------------------------- /app/include/driver/gpio16.h: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for GPIO 3 | Official repository: https://github.com/CHERTS/esp8266-gpio16 4 | 5 | Copyright (C) 2015 Mikhail Grigorev (CHERTS) 6 | 7 | Pin number: 8 | ----------- 9 | Pin 0 = GPIO16 10 | Pin 1 = GPIO5 11 | Pin 2 = GPIO4 12 | Pin 3 = GPIO0 13 | Pin 4 = GPIO2 14 | Pin 5 = GPIO14 15 | Pin 6 = GPIO12 16 | Pin 7 = GPIO13 17 | Pin 8 = GPIO15 18 | Pin 9 = GPIO3 19 | Pin 10 = GPIO1 20 | Pin 11 = GPIO9 21 | Pin 12 = GPIO10 22 | */ 23 | 24 | #ifndef __GPIO16_H__ 25 | #define __GPIO16_H__ 26 | #include "gpio.h" 27 | 28 | #define GPIO_PIN_NUM 13 29 | 30 | #ifndef GPIO_INTERRUPT_ENABLE 31 | #define GPIO_INTERRUPT_ENABLE 1 32 | #endif 33 | 34 | #define GPIO_FLOAT 0 35 | #define GPIO_PULLUP 1 36 | #define GPIO_PULLDOWN 2 37 | 38 | #define GPIO_INPUT 0 39 | #define GPIO_OUTPUT 1 40 | #define GPIO_INT 2 41 | 42 | /* GPIO interrupt handler */ 43 | #ifdef GPIO_INTERRUPT_ENABLE 44 | typedef void (* gpio_intr_handler)(unsigned pin, unsigned level); 45 | #endif 46 | 47 | void gpio16_output_conf(void); 48 | void gpio16_output_set(uint8 value); 49 | void gpio16_input_conf(void); 50 | uint8 gpio16_input_get(void); 51 | int set_gpio_mode(unsigned pin, unsigned mode, unsigned pull); 52 | int gpio_write(unsigned pin, unsigned level); 53 | int gpio_read(unsigned pin); 54 | #ifdef GPIO_INTERRUPT_ENABLE 55 | void gpio_intr_attach(gpio_intr_handler cb); 56 | int gpio_intr_deattach(unsigned pin); 57 | int gpio_intr_init(unsigned pin, GPIO_INT_TYPE type); 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /app/include/driver/rfm69.h: -------------------------------------------------------------------------------- 1 | #ifndef RFM69_H 2 | #define RFM69_H 3 | #include "rfm.h" 4 | 5 | #define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2 bytes crc) 6 | #define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access 7 | 8 | // available frequency bands 9 | #define RF69_315MHZ 31 // non trivial values to avoid misconfiguration 10 | #define RF69_433MHZ 43 11 | #define RF69_868MHZ 86 12 | #define RF69_915MHZ 91 13 | 14 | #define null 0 15 | #define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value 16 | #define RF69_BROADCAST_ADDR 255 17 | #define RF69_CSMA_LIMIT_MS 1000 18 | #define RF69_CSMA_LIMIT_US 1000000UL 19 | #define RF69_TX_LIMIT_MS 1000 20 | #define RF69_FSTEP 61.03515625 // == FXOSC / 2^19 = 32MHz / 2^19 (p13 in datasheet) 21 | 22 | #define RFM69_CTL_SENDACK 0x80 23 | #define RFM69_CTL_REQACK 0x40 24 | 25 | const uint8_t CONFIG[24][2]; 26 | 27 | rfm_retcode_t rfm69_spi_init(void); 28 | rfm_retcode_t rfm69_init(RFM_Handle *handle, uint8_t ID, uint8_t networkID); 29 | 30 | bool rfm69_receiveDone(); 31 | void rfm69_receiveBegin(); 32 | void rfm69_setMode(RFM69_OP_MODE newMode); 33 | bool rfm69_canSend(); 34 | bool rfm69_ACKRequested(); 35 | void rfm69_sendACK(); 36 | void rfm69_setFrequency(uint32_t freqHz); 37 | void rfm69_setEncryptKey(char* key); 38 | void rfm69_sleep(); 39 | 40 | void rfm69_setHighPowerRegs(bool onOff); 41 | void rfm69_setHighPower(bool onOFF); // has to be called after initialize() for RFM69HW -def onOFF=true 42 | int16_t rfm69_readRSSI(bool forceTrigger); //def forceTrigger=false 43 | void rfm69_setAddress(uint8_t addr); 44 | 45 | void rfm69_setNetwork(uint8_t networkID); 46 | void rfm69_setPowerLevel(uint8_t level); // reduce/increase transmit power level 47 | /* 48 | uint8_t readTemperature(uint8_t calFactor); // get CMOS temperature (8bit) -def calFactor=0 49 | void rcCalibration(); // calibrate the internal RC oscillator for use in wide temperature variations - see datasheet section [4.3.5. RC Timer Accuracy] 50 | */ 51 | void rfm69_writeToFIFO32(uint8* outbuf, uint8_t datalen); 52 | uint8_t ICACHE_RAM_ATTR rfm69_readReg(uint8_t regAddr); 53 | void ICACHE_RAM_ATTR rfm69_writeReg(uint8_t regAddr, uint8_t value); 54 | // uint8_t rfm69_readReg(uint8_t regAddr); 55 | // void rfm69_writeReg(uint8_t regAddr, uint8_t value); 56 | uint32_t ICACHE_RAM_ATTR rfm69_readReg32(uint8_t regAddr); 57 | void rfm69_readAllRegs(); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /app/include/driver/spi.h: -------------------------------------------------------------------------------- 1 | #ifndef SPI_APP_H 2 | #define SPI_APP_H 3 | 4 | #include "spi_register.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | #include "uart.h" 8 | #include "os_type.h" 9 | 10 | /*SPI number define*/ 11 | #define SPI 0 12 | #define HSPI 1 13 | 14 | #define SPI_CLK_USE_DIV 0 15 | #define SPI_CLK_80MHZ_NODIV 1 16 | 17 | #define SPI_BYTE_ORDER_HIGH_TO_LOW 1 18 | #define SPI_BYTE_ORDER_LOW_TO_HIGH 0 19 | 20 | #ifndef CPU_CLK_FREQ //Should already be defined in eagle_soc.h 21 | #define CPU_CLK_FREQ 80*1000000 22 | #endif 23 | 24 | //Define some default SPI clock settings 25 | #define SPI_CLK_PREDIV 10 26 | #define SPI_CLK_CNTDIV 2 27 | #define SPI_CLK_FREQ CPU_CLK_FREQ/(SPI_CLK_PREDIV*SPI_CLK_CNTDIV) // 80 / 20 = 4 MHz 28 | 29 | void spi_init(uint8 spi_no); 30 | void spi_init_gpio(uint8 spi_no, uint8 sysclk_as_spiclk); 31 | void spi_clock(uint8 spi_no, uint16 prediv, uint8 cntdiv); 32 | void spi_tx_byte_order(uint8 spi_no, uint8 byte_order); 33 | void spi_rx_byte_order(uint8 spi_no, uint8 byte_order); 34 | uint32 ICACHE_RAM_ATTR spi_transaction(uint8 spi_no, uint32 addr_bits, uint32 addr_data, uint32 dout_bits, uint32 dout_data, uint32 din_bits, uint32 dummy_bits); 35 | 36 | //Expansion Macros 37 | #define spi_busy(spi_no) READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR 38 | 39 | #define spi_txd(spi_no, bits, data) spi_transaction(spi_no, 0, 0, bits, (uint32) data, 0, 0) 40 | #define spi_tx8(spi_no, data) spi_transaction(spi_no, 0, 0, 8, (uint32) data, 0, 0) 41 | #define spi_tx16(spi_no, data) spi_transaction(spi_no, 0, 0, 16, (uint32) data, 0, 0) 42 | #define spi_tx32(spi_no, data) spi_transaction(spi_no, 0, 0, 32, (uint32) data, 0, 0) 43 | 44 | #define spi_rxd(spi_no, bits) spi_transaction(spi_no, 0, 0, 0, 0, bits, 0) 45 | #define spi_rx8(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 8, 0) 46 | #define spi_rx16(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 16, 0) 47 | #define spi_rx32(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 32, 0) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /app/include/driver/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef UART_APP_H 2 | #define UART_APP_H 3 | 4 | #include "uart_register.h" 5 | #include "eagle_soc.h" 6 | #include "c_types.h" 7 | #include "os_type.h" 8 | 9 | typedef void (*uart0_data_received_callback_t)(uint8_t *data,int len); 10 | 11 | #define UART0 0 12 | #define UART1 1 13 | 14 | #define UART_HW_RTS 0 // set 1: enable uart hw flow control RTS, PIN MTDO, FOR UART0 15 | #define UART_HW_CTS 0 // set1: enable uart hw flow contrl CTS , PIN MTCK, FOR UART0 16 | 17 | #define RX_BUFF_SIZE 0x100 18 | #define TX_BUFF_SIZE 100 19 | #define UART_FIFO_LEN 128 //define the tx fifo length 20 | 21 | #define UART_TX_EMPTY_THRESH_VAL 0x10 22 | 23 | typedef enum { 24 | FIVE_BITS = 0x0, 25 | SIX_BITS = 0x1, 26 | SEVEN_BITS = 0x2, 27 | EIGHT_BITS = 0x3 28 | } UartBitsNum4Char; 29 | 30 | typedef enum { 31 | ONE_STOP_BIT = 0, 32 | ONE_HALF_STOP_BIT = BIT2, 33 | TWO_STOP_BIT = BIT2 34 | } UartStopBitsNum; 35 | 36 | typedef enum { 37 | NONE_BITS = 0, 38 | ODD_BITS = 0, 39 | EVEN_BITS = BIT4 40 | } UartParityMode; 41 | 42 | typedef enum { 43 | STICK_PARITY_DIS = 0, 44 | STICK_PARITY_EN = BIT3 | BIT5 45 | } UartExistParity; 46 | 47 | typedef enum { 48 | BIT_RATE_300 = 300, 49 | BIT_RATE_600 = 600, 50 | BIT_RATE_1200 = 1200, 51 | BIT_RATE_2400 = 2400, 52 | BIT_RATE_4800 = 4800, 53 | BIT_RATE_9600 = 9600, 54 | BIT_RATE_19200 = 19200, 55 | BIT_RATE_38400 = 38400, 56 | BIT_RATE_57600 = 57600, 57 | BIT_RATE_74880 = 74880, 58 | BIT_RATE_115200 = 115200, 59 | BIT_RATE_230400 = 230400, 60 | BIT_RATE_256000 = 256000, 61 | BIT_RATE_460800 = 460800, 62 | BIT_RATE_921600 = 921600, 63 | BIT_RATE_1843200 = 1843200, 64 | BIT_RATE_3686400 = 3686400, 65 | } UartBautRate; 66 | 67 | typedef enum { 68 | NONE_CTRL, 69 | HARDWARE_CTRL, 70 | XON_XOFF_CTRL 71 | } UartFlowCtrl; 72 | 73 | typedef enum { 74 | EMPTY, 75 | UNDER_WRITE, 76 | WRITE_OVER 77 | } RcvMsgBuffState; 78 | 79 | typedef struct { 80 | uint32 RcvBuffSize; 81 | uint8 *pRcvMsgBuff; 82 | uint8 *pWritePos; 83 | uint8 *pReadPos; 84 | uint8 TrigLvl; //JLU: may need to pad 85 | 86 | RcvMsgBuffState BuffState; 87 | } RcvMsgBuff; 88 | 89 | typedef struct { 90 | uint32 TrxBuffSize; 91 | uint8 *pTrxBuff; 92 | } TrxMsgBuff; 93 | 94 | typedef enum { 95 | BAUD_RATE_DET, 96 | WAIT_SYNC_FRM, 97 | SRCH_MSG_HEAD, 98 | RCV_MSG_BODY, 99 | RCV_ESC_CHAR, 100 | } RcvMsgState; 101 | 102 | typedef struct { 103 | UartBautRate baut_rate; 104 | UartBitsNum4Char data_bits; 105 | UartExistParity exist_parity; 106 | UartParityMode parity; // chip size in byte 107 | UartStopBitsNum stop_bits; 108 | UartFlowCtrl flow_ctrl; 109 | RcvMsgBuff rcv_buff; 110 | TrxMsgBuff trx_buff; 111 | RcvMsgState rcv_state; 112 | int received; 113 | int buff_uart_no; //indicate which uart use tx/rx buffer 114 | } UartDevice; 115 | 116 | 117 | void uart_config(uint8_t uart_no); 118 | void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); 119 | void uart_write_string(uint8_t uart,const char *s); 120 | void uart_write(uint8_t uart,uint8_t *data,int len); 121 | void uart_write_char(uint8_t uart,char c); 122 | 123 | void uart_clear_data_callback(); 124 | void uart_register_data_callback(uart0_data_received_callback_t callback); 125 | #endif 126 | -------------------------------------------------------------------------------- /app/include/lwip/app/dhcpserver.h: -------------------------------------------------------------------------------- 1 | #ifndef __DHCPS_H__ 2 | #define __DHCPS_H__ 3 | 4 | #define USE_DNS 5 | 6 | typedef struct dhcps_state{ 7 | sint16_t state; 8 | } dhcps_state; 9 | 10 | // ����dhcpclient�Զ����һ��DHCP msg�ṹ�� 11 | typedef struct dhcps_msg { 12 | uint8_t op, htype, hlen, hops; 13 | uint8_t xid[4]; 14 | uint16_t secs, flags; 15 | uint8_t ciaddr[4]; 16 | uint8_t yiaddr[4]; 17 | uint8_t siaddr[4]; 18 | uint8_t giaddr[4]; 19 | uint8_t chaddr[16]; 20 | uint8_t sname[64]; 21 | uint8_t file[128]; 22 | uint8_t options[312]; 23 | }dhcps_msg; 24 | 25 | #ifndef LWIP_OPEN_SRC 26 | struct dhcps_lease { 27 | bool enable; 28 | struct ip_addr start_ip; 29 | struct ip_addr end_ip; 30 | }; 31 | 32 | enum dhcps_offer_option{ 33 | OFFER_START = 0x00, 34 | OFFER_ROUTER = 0x01, 35 | OFFER_END 36 | }; 37 | #endif 38 | 39 | struct dhcps_pool{ 40 | struct ip_addr ip; 41 | uint8 mac[6]; 42 | uint32 lease_timer; 43 | }; 44 | 45 | typedef struct _list_node{ 46 | void *pnode; 47 | struct _list_node *pnext; 48 | }list_node; 49 | 50 | extern uint32 dhcps_lease_time; 51 | #define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0 52 | #define DHCPS_MAX_LEASE 0x64 53 | #define BOOTP_BROADCAST 0x8000 54 | 55 | #define DHCP_REQUEST 1 56 | #define DHCP_REPLY 2 57 | #define DHCP_HTYPE_ETHERNET 1 58 | #define DHCP_HLEN_ETHERNET 6 59 | #define DHCP_MSG_LEN 236 60 | 61 | #define DHCPS_SERVER_PORT 67 62 | #define DHCPS_CLIENT_PORT 68 63 | 64 | #define DHCPDISCOVER 1 65 | #define DHCPOFFER 2 66 | #define DHCPREQUEST 3 67 | #define DHCPDECLINE 4 68 | #define DHCPACK 5 69 | #define DHCPNAK 6 70 | #define DHCPRELEASE 7 71 | 72 | #define DHCP_OPTION_SUBNET_MASK 1 73 | #define DHCP_OPTION_ROUTER 3 74 | #define DHCP_OPTION_DNS_SERVER 6 75 | #define DHCP_OPTION_REQ_IPADDR 50 76 | #define DHCP_OPTION_LEASE_TIME 51 77 | #define DHCP_OPTION_MSG_TYPE 53 78 | #define DHCP_OPTION_SERVER_ID 54 79 | #define DHCP_OPTION_INTERFACE_MTU 26 80 | #define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31 81 | #define DHCP_OPTION_BROADCAST_ADDRESS 28 82 | #define DHCP_OPTION_REQ_LIST 55 83 | #define DHCP_OPTION_END 255 84 | 85 | //#define USE_CLASS_B_NET 1 86 | #define DHCPS_DEBUG 0 87 | #define MAX_STATION_NUM 8 88 | 89 | #define DHCPS_STATE_OFFER 1 90 | #define DHCPS_STATE_DECLINE 2 91 | #define DHCPS_STATE_ACK 3 92 | #define DHCPS_STATE_NAK 4 93 | #define DHCPS_STATE_IDLE 5 94 | #define DHCPS_STATE_RELEASE 6 95 | 96 | #define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0) 97 | 98 | void dhcps_start(struct ip_info *info); 99 | void dhcps_stop(void); 100 | 101 | #endif 102 | 103 | -------------------------------------------------------------------------------- /app/include/lwip/app/espconn_tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESPCONN_TCP_H__ 2 | #define __ESPCONN_TCP_H__ 3 | 4 | #ifndef ESPCONN_TCP_DEBUG 5 | #define ESPCONN_TCP_DEBUG LWIP_DBG_OFF 6 | #endif 7 | #include "lwip/app/espconn.h" 8 | 9 | #ifndef ESPCONN_TCP_TIMER 10 | #define ESPCONN_TCP_TIMER 40 11 | #endif 12 | 13 | #define espconn_keepalive_enable(pcb) ((pcb)->so_options |= SOF_KEEPALIVE) 14 | #define espconn_keepalive_disable(pcb) ((pcb)->so_options &= ~SOF_KEEPALIVE) 15 | 16 | /****************************************************************************** 17 | * FunctionName : espconn_kill_oldest_pcb 18 | * Description : A oldest incoming connection has been killed. 19 | * Parameters : none 20 | * Returns : none 21 | *******************************************************************************/ 22 | 23 | extern void espconn_kill_oldest_pcb(void); 24 | 25 | /****************************************************************************** 26 | * FunctionName : espconn_tcp_disconnect 27 | * Description : A new incoming connection has been disconnected. 28 | * Parameters : espconn -- the espconn used to disconnect with host 29 | * Returns : none 30 | *******************************************************************************/ 31 | 32 | extern void espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type); 33 | 34 | /****************************************************************************** 35 | * FunctionName : espconn_tcp_client 36 | * Description : Initialize the client: set up a connect PCB and bind it to 37 | * the defined port 38 | * Parameters : espconn -- the espconn used to build client 39 | * Returns : none 40 | *******************************************************************************/ 41 | 42 | extern sint8 espconn_tcp_client(struct espconn* espconn); 43 | 44 | /****************************************************************************** 45 | * FunctionName : espconn_tcp_server 46 | * Description : Initialize the server: set up a listening PCB and bind it to 47 | * the defined port 48 | * Parameters : espconn -- the espconn used to build server 49 | * Returns : none 50 | *******************************************************************************/ 51 | 52 | extern sint8 espconn_tcp_server(struct espconn *espconn); 53 | 54 | #endif /* __CLIENT_TCP_H__ */ 55 | 56 | -------------------------------------------------------------------------------- /app/include/lwip/app/espconn_udp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESPCONN_UDP_H__ 2 | #define __ESPCONN_UDP_H__ 3 | 4 | #ifndef ESPCONN_UDP_DEBUG 5 | #define ESPCONN_UDP_DEBUG LWIP_DBG_OFF 6 | #endif 7 | 8 | #include "lwip/app/espconn.h" 9 | 10 | /****************************************************************************** 11 | * FunctionName : espconn_udp_client 12 | * Description : Initialize the client: set up a PCB and bind it to the port 13 | * Parameters : pespconn -- the espconn used to build client 14 | * Returns : none 15 | *******************************************************************************/ 16 | 17 | extern sint8 espconn_udp_client(struct espconn *pespconn); 18 | 19 | /****************************************************************************** 20 | * FunctionName : espconn_udp_disconnect 21 | * Description : A new incoming connection has been disconnected. 22 | * Parameters : espconn -- the espconn used to disconnect with host 23 | * Returns : none 24 | *******************************************************************************/ 25 | 26 | extern void espconn_udp_disconnect(espconn_msg *pdiscon); 27 | 28 | /****************************************************************************** 29 | * FunctionName : espconn_udp_server 30 | * Description : Initialize the server: set up a PCB and bind it to the port 31 | * Parameters : pespconn -- the espconn used to build server 32 | * Returns : none 33 | *******************************************************************************/ 34 | 35 | extern sint8 espconn_udp_server(struct espconn *espconn); 36 | 37 | /****************************************************************************** 38 | * FunctionName : espconn_udp_sent 39 | * Description : sent data for client or server 40 | * Parameters : void *arg -- client or server to send 41 | * uint8* psent -- Data to send 42 | * uint16 length -- Length of data to send 43 | * Returns : none 44 | *******************************************************************************/ 45 | 46 | extern err_t espconn_udp_sent(void *arg, uint8 *psent, uint16 length); 47 | 48 | /****************************************************************************** 49 | * FunctionName : espconn_udp_sendto 50 | * Description : sent data for UDP 51 | * Parameters : void *arg -- UDP to send 52 | * uint8* psent -- Data to send 53 | * uint16 length -- Length of data to send 54 | * Returns : return espconn error code. 55 | * - ESPCONN_OK. Successful. No error occured. 56 | * - ESPCONN_MEM. Out of memory. 57 | * - ESPCONN_RTE. Could not find route to destination address. 58 | * - More errors could be returned by lower protocol layers. 59 | *******************************************************************************/ 60 | extern err_t espconn_udp_sendto(void *arg, uint8 *psent, uint16 length); 61 | 62 | #endif /* __ESPCONN_UDP_H__ */ 63 | 64 | 65 | -------------------------------------------------------------------------------- /app/include/lwip/app/ping.h: -------------------------------------------------------------------------------- 1 | #ifndef __PING_H__ 2 | #define __PING_H__ 3 | #include "lwip/ip_addr.h" 4 | #include "lwip/icmp.h" 5 | /** 6 | * PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used 7 | */ 8 | #ifndef PING_USE_SOCKETS 9 | #define PING_USE_SOCKETS LWIP_SOCKET 10 | #endif 11 | 12 | /** 13 | * PING_DEBUG: Enable debugging for PING. 14 | */ 15 | #ifndef PING_DEBUG 16 | #define PING_DEBUG LWIP_DBG_OFF 17 | #endif 18 | 19 | /** ping receive timeout - in milliseconds */ 20 | #ifndef PING_RCV_TIMEO 21 | #define PING_RCV_TIMEO 1000 22 | #endif 23 | 24 | /** ping delay - in milliseconds */ 25 | #ifndef PING_COARSE 26 | #define PING_COARSE 1000 27 | #endif 28 | 29 | /** ping identifier - must fit on a u16_t */ 30 | #ifndef PING_ID 31 | #define PING_ID 0xAFAF 32 | #endif 33 | 34 | /** ping additional data size to include in the packet */ 35 | #ifndef PING_DATA_SIZE 36 | #define PING_DATA_SIZE 32 37 | #endif 38 | 39 | /** ping result action - no default action */ 40 | #ifndef PING_RESULT 41 | #define PING_RESULT(ping_ok) 42 | #endif 43 | 44 | #define DEFAULT_PING_MAX_COUNT 4 45 | #define PING_TIMEOUT_MS 1000 46 | 47 | typedef void (* ping_recv_function)(void* arg, void *pdata); 48 | typedef void (* ping_sent_function)(void* arg, void *pdata); 49 | 50 | struct ping_option{ 51 | uint32 count; 52 | uint32 ip; 53 | uint32 coarse_time; 54 | ping_recv_function recv_function; 55 | ping_sent_function sent_function; 56 | void* reverse; 57 | }; 58 | 59 | struct ping_msg{ 60 | struct ping_option *ping_opt; 61 | struct raw_pcb *ping_pcb; 62 | uint32 ping_start; 63 | uint32 ping_sent; 64 | uint32 timeout_count; 65 | uint32 max_count; 66 | uint32 sent_count; 67 | uint32 coarse_time; 68 | }; 69 | 70 | struct ping_resp{ 71 | uint32 total_count; 72 | uint32 resp_time; 73 | uint32 seqno; 74 | uint32 timeout_count; 75 | uint32 bytes; 76 | uint32 total_bytes; 77 | uint32 total_time; 78 | sint8 ping_err; 79 | }; 80 | 81 | bool ping_start(struct ping_option *ping_opt); 82 | bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv); 83 | bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent); 84 | 85 | #endif /* __PING_H__ */ 86 | -------------------------------------------------------------------------------- /app/include/lwip/err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_ERR_H__ 33 | #define __LWIP_ERR_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/arch.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** Define LWIP_ERR_T in cc.h if you want to use 43 | * a different type for your platform (must be signed). */ 44 | #ifdef LWIP_ERR_T 45 | typedef LWIP_ERR_T err_t; 46 | #else /* LWIP_ERR_T */ 47 | typedef s8_t err_t; 48 | #endif /* LWIP_ERR_T*/ 49 | 50 | /* Definitions for error constants. */ 51 | 52 | #define ERR_OK 0 /* No error, everything OK. */ 53 | #define ERR_MEM -1 /* Out of memory error. */ 54 | #define ERR_BUF -2 /* Buffer error. */ 55 | #define ERR_TIMEOUT -3 /* Timeout. */ 56 | #define ERR_RTE -4 /* Routing problem. */ 57 | #define ERR_INPROGRESS -5 /* Operation in progress */ 58 | #define ERR_VAL -6 /* Illegal value. */ 59 | #define ERR_WOULDBLOCK -7 /* Operation would block. */ 60 | 61 | #define ERR_IS_FATAL(e) ((e) < ERR_WOULDBLOCK) 62 | 63 | #define ERR_ABRT -8 /* Connection aborted. */ 64 | #define ERR_RST -9 /* Connection reset. */ 65 | #define ERR_CLSD -10 /* Connection closed. */ 66 | #define ERR_CONN -11 /* Not connected. */ 67 | 68 | #define ERR_ARG -12 /* Illegal argument. */ 69 | 70 | #define ERR_USE -13 /* Address in use. */ 71 | 72 | #define ERR_IF -14 /* Low-level netif error */ 73 | #define ERR_ISCONN -15 /* Already connected. */ 74 | 75 | 76 | #ifdef LWIP_DEBUG 77 | extern const char *lwip_strerr(err_t err)ICACHE_FLASH_ATTR; 78 | #else 79 | #define lwip_strerr(x) "" 80 | #endif /* LWIP_DEBUG */ 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif /* __LWIP_ERR_H__ */ 87 | -------------------------------------------------------------------------------- /app/include/lwip/icmp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/include/lwip/icmp.h -------------------------------------------------------------------------------- /app/include/lwip/inet_chksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INET_CHKSUM_H__ 33 | #define __LWIP_INET_CHKSUM_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #include "lwip/pbuf.h" 38 | #include "lwip/ip_addr.h" 39 | 40 | /** Swap the bytes in an u16_t: much like htons() for little-endian */ 41 | #ifndef SWAP_BYTES_IN_WORD 42 | #if LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) 43 | /* little endian and PLATFORM_BYTESWAP defined */ 44 | #define SWAP_BYTES_IN_WORD(w) LWIP_PLATFORM_HTONS(w) 45 | #else /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) */ 46 | /* can't use htons on big endian (or PLATFORM_BYTESWAP not defined)... */ 47 | #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8) 48 | #endif /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)*/ 49 | #endif /* SWAP_BYTES_IN_WORD */ 50 | 51 | /** Split an u32_t in two u16_ts and add them up */ 52 | #ifndef FOLD_U32T 53 | #define FOLD_U32T(u) (((u) >> 16) + ((u) & 0x0000ffffUL)) 54 | #endif 55 | 56 | #if LWIP_CHECKSUM_ON_COPY 57 | /** Function-like macro: same as MEMCPY but returns the checksum of copied data 58 | as u16_t */ 59 | #ifndef LWIP_CHKSUM_COPY 60 | #define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len) 61 | #ifndef LWIP_CHKSUM_COPY_ALGORITHM 62 | #define LWIP_CHKSUM_COPY_ALGORITHM 1 63 | #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 64 | #endif /* LWIP_CHKSUM_COPY */ 65 | #else /* LWIP_CHECKSUM_ON_COPY */ 66 | #define LWIP_CHKSUM_COPY_ALGORITHM 0 67 | #endif /* LWIP_CHECKSUM_ON_COPY */ 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | u16_t inet_chksum(void *dataptr, u16_t len)ICACHE_FLASH_ATTR; 74 | u16_t inet_chksum_pbuf(struct pbuf *p)ICACHE_FLASH_ATTR; 75 | u16_t inet_chksum_pseudo(struct pbuf *p, 76 | ip_addr_t *src, ip_addr_t *dest, 77 | u8_t proto, u16_t proto_len)ICACHE_FLASH_ATTR; 78 | u16_t inet_chksum_pseudo_partial(struct pbuf *p, 79 | ip_addr_t *src, ip_addr_t *dest, 80 | u8_t proto, u16_t proto_len, u16_t chksum_len)ICACHE_FLASH_ATTR; 81 | #if LWIP_CHKSUM_COPY_ALGORITHM 82 | u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len)ICACHE_FLASH_ATTR; 83 | #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __LWIP_INET_H__ */ 90 | 91 | -------------------------------------------------------------------------------- /app/include/lwip/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INIT_H__ 33 | #define __LWIP_INIT_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** X.x.x: Major version of the stack */ 42 | #define LWIP_VERSION_MAJOR 1U 43 | /** x.X.x: Minor version of the stack */ 44 | #define LWIP_VERSION_MINOR 4U 45 | /** x.x.X: Revision of the stack */ 46 | #define LWIP_VERSION_REVISION 0U 47 | /** For release candidates, this is set to 1..254 48 | * For official releases, this is set to 255 (LWIP_RC_RELEASE) 49 | * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */ 50 | #define LWIP_VERSION_RC 2U 51 | 52 | /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ 53 | #define LWIP_RC_RELEASE 255U 54 | /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */ 55 | #define LWIP_RC_DEVELOPMENT 0U 56 | 57 | #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) 58 | #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) 59 | #define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) 60 | 61 | /** Provides the version of the stack */ 62 | #define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \ 63 | LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC) 64 | 65 | /* Modules initialization */ 66 | void lwip_init(void) ICACHE_FLASH_ATTR; 67 | //void lwip_init(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __LWIP_INIT_H__ */ 74 | -------------------------------------------------------------------------------- /app/include/lwip/ip_frag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Jani Monoses 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_IP_FRAG_H__ 34 | #define __LWIP_IP_FRAG_H__ 35 | 36 | #include "lwip/opt.h" 37 | #include "lwip/err.h" 38 | #include "lwip/pbuf.h" 39 | #include "lwip/netif.h" 40 | #include "lwip/ip_addr.h" 41 | #include "lwip/ip.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #if IP_REASSEMBLY 48 | /* The IP reassembly timer interval in milliseconds. */ 49 | #define IP_TMR_INTERVAL 1000 50 | 51 | /* IP reassembly helper struct. 52 | * This is exported because memp needs to know the size. 53 | */ 54 | struct ip_reassdata { 55 | struct ip_reassdata *next; 56 | struct pbuf *p; 57 | struct ip_hdr iphdr; 58 | u16_t datagram_len; 59 | u8_t flags; 60 | u8_t timer; 61 | }; 62 | 63 | void ip_reass_init(void)ICACHE_FLASH_ATTR; 64 | void ip_reass_tmr(void)ICACHE_FLASH_ATTR; 65 | struct pbuf * ip_reass(struct pbuf *p)ICACHE_FLASH_ATTR; 66 | #endif /* IP_REASSEMBLY */ 67 | 68 | #if IP_FRAG 69 | #if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF 70 | /** A custom pbuf that holds a reference to another pbuf, which is freed 71 | * when this custom pbuf is freed. This is used to create a custom PBUF_REF 72 | * that points into the original pbuf. */ 73 | struct pbuf_custom_ref { 74 | /** 'base class' */ 75 | struct pbuf_custom pc; 76 | /** pointer to the original pbuf that is referenced */ 77 | struct pbuf *original; 78 | }; 79 | #endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ 80 | 81 | err_t ip_frag(struct pbuf *p, struct netif *netif, ip_addr_t *dest)ICACHE_FLASH_ATTR; 82 | #endif /* IP_FRAG */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* __LWIP_IP_FRAG_H__ */ 89 | -------------------------------------------------------------------------------- /app/include/lwip/netif.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/include/lwip/netif.h -------------------------------------------------------------------------------- /app/include/lwip/puck_def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * puck_def.h 3 | * 4 | * Created on: Jul 22, 2010 5 | * Author: dtoma 6 | */ 7 | 8 | #ifndef PUCK_DEF_H_ 9 | #define PUCK_DEF_H_ 10 | 11 | 12 | 13 | #define INSTRUMENT_PORT 8760 14 | 15 | #define INSTRUMENT_LENGTH 80 16 | 17 | #define MDNS_NAME_LENGTH 68 //68 18 | 19 | char* PUCK_SERVICE = NULL; 20 | //#define PUCK_SERVICE "_Escpressif._tcp.local" 21 | #define DNS_SD_SERVICE "_services._dns-sd._udp.local" 22 | #define SERVICE_DESCRIPTION "PUCK PROTOCOL" 23 | #define PUCK_SERVICE_LENGTH 30 24 | 25 | #define UUID_LEN 16 26 | #define DS_VERS_LEN 2 27 | #define DS_SIZE_LEN 2 28 | #define MAN_ID_LEN 4 29 | #define MAN_MODEL_LEN 2 30 | #define MAN_VERS_LEN 2 31 | #define SER_NUM_LEN 4 32 | #define NAME_LEN 64 33 | #define PUCK_DATASHEET_SIZE 96 34 | 35 | #define UUID_OFFSET 0 36 | #define DS_VERS_OFFSET UUID_LEN + UUID_OFFSET 37 | #define DS_SIZE_OFFSET DS_VERS_LEN + DS_VERS_OFFSET 38 | #define MAN_ID_OFFSET DS_SIZE_LEN + DS_SIZE_OFFSET 39 | #define MAN_MODEL_OFFSET MAN_ID_LEN + MAN_ID_OFFSET 40 | #define MAN_VERS_OFFSET MAN_MODEL_LEN + MAN_MODEL_OFFSET 41 | #define SER_NUM_OFFSET MAN_VERS_LEN + MAN_VERS_OFFSET 42 | #define NAME_OFFSET SER_NUM_LEN + SER_NUM_OFFSET 43 | 44 | #endif /* __PUCK_DEF_H__ */ 45 | -------------------------------------------------------------------------------- /app/include/lwip/sntp.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_SNTP_H 2 | #define LWIP_SNTP_H 3 | 4 | #include "lwip/opt.h" 5 | #include "lwip/ip_addr.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /** The maximum number of SNTP servers that can be set */ 12 | #ifndef SNTP_MAX_SERVERS 13 | #define SNTP_MAX_SERVERS 3 14 | #endif 15 | 16 | /** Set this to 1 to implement the callback function called by dhcp when 17 | * NTP servers are received. */ 18 | #ifndef SNTP_GET_SERVERS_FROM_DHCP 19 | #define SNTP_GET_SERVERS_FROM_DHCP 0//LWIP_DHCP_GET_NTP_SRV 20 | #endif 21 | 22 | /* Set this to 1 to support DNS names (or IP address strings) to set sntp servers */ 23 | #ifndef SNTP_SERVER_DNS 24 | #define SNTP_SERVER_DNS 1 25 | #endif 26 | 27 | /** One server address/name can be defined as default if SNTP_SERVER_DNS == 1: 28 | * #define SNTP_SERVER_ADDRESS "pool.ntp.org" 29 | */ 30 | uint32 sntp_get_current_timestamp(); 31 | char* sntp_get_real_time(long t); 32 | 33 | void sntp_init(void); 34 | void sntp_stop(void); 35 | 36 | sint8 sntp_get_timezone(void); 37 | bool sntp_set_timezone(sint8 timezone); 38 | void sntp_setserver(u8_t idx, ip_addr_t *addr); 39 | ip_addr_t sntp_getserver(u8_t idx); 40 | 41 | #if SNTP_SERVER_DNS 42 | void sntp_setservername(u8_t idx, char *server); 43 | char *sntp_getservername(u8_t idx); 44 | #endif /* SNTP_SERVER_DNS */ 45 | 46 | #if SNTP_GET_SERVERS_FROM_DHCP 47 | void sntp_servermode_dhcp(int set_servers_from_dhcp); 48 | #else /* SNTP_GET_SERVERS_FROM_DHCP */ 49 | #define sntp_servermode_dhcp(x) 50 | #endif /* SNTP_GET_SERVERS_FROM_DHCP */ 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* LWIP_SNTP_H */ 57 | -------------------------------------------------------------------------------- /app/include/lwip/timers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * Simon Goldschmidt 31 | * 32 | */ 33 | #ifndef __LWIP_TIMERS_H__ 34 | #define __LWIP_TIMERS_H__ 35 | 36 | #include "lwip/opt.h" 37 | 38 | /* Timers are not supported when NO_SYS==1 and NO_SYS_NO_TIMERS==1 */ 39 | #define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) 40 | 41 | #if LWIP_TIMERS 42 | 43 | #include "lwip/err.h" 44 | #include "lwip/sys.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #ifndef LWIP_DEBUG_TIMERNAMES 51 | #ifdef LWIP_DEBUG 52 | #define LWIP_DEBUG_TIMERNAMES SYS_DEBUG 53 | #else /* LWIP_DEBUG */ 54 | #define LWIP_DEBUG_TIMERNAMES 0 55 | #endif /* LWIP_DEBUG*/ 56 | #endif 57 | 58 | /** Function prototype for a timeout callback function. Register such a function 59 | * using sys_timeout(). 60 | * 61 | * @param arg Additional argument to pass to the function - set up by sys_timeout() 62 | */ 63 | typedef void (* sys_timeout_handler)(void *arg); 64 | 65 | struct sys_timeo { 66 | struct sys_timeo *next; 67 | u32_t time; 68 | sys_timeout_handler h; 69 | void *arg; 70 | #if LWIP_DEBUG_TIMERNAMES 71 | const char* handler_name; 72 | #endif /* LWIP_DEBUG_TIMERNAMES */ 73 | }; 74 | 75 | void sys_timeouts_init(void)ICACHE_FLASH_ATTR; 76 | 77 | #if LWIP_DEBUG_TIMERNAMES 78 | void sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)ICACHE_FLASH_ATTR; 79 | #define sys_timeout(msecs, handler, arg) sys_timeout_debug(msecs, handler, arg, #handler) 80 | #else /* LWIP_DEBUG_TIMERNAMES */ 81 | void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)ICACHE_FLASH_ATTR; 82 | #endif /* LWIP_DEBUG_TIMERNAMES */ 83 | 84 | void sys_untimeout(sys_timeout_handler handler, void *arg)ICACHE_FLASH_ATTR; 85 | #if NO_SYS 86 | void sys_check_timeouts(void)ICACHE_FLASH_ATTR; 87 | void sys_restart_timeouts(void)ICACHE_FLASH_ATTR; 88 | #else /* NO_SYS */ 89 | void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg); 90 | #endif /* NO_SYS */ 91 | 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* LWIP_TIMERS */ 98 | #endif /* __LWIP_TIMERS_H__ */ 99 | -------------------------------------------------------------------------------- /app/include/netif/wlan_lwip_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef _WLAN_LWIP_IF_H_ 7 | #define _WLAN_LWIP_IF_H_ 8 | 9 | #define LWIP_IF0_PRIO 28 10 | #define LWIP_IF1_PRIO 29 11 | 12 | enum { 13 | SIG_LWIP_RX = 0, 14 | }; 15 | 16 | struct netif * eagle_lwip_if_alloc(struct ieee80211_conn *conn, const uint8 *macaddr, struct ip_info *info); 17 | struct netif * eagle_lwip_getif(uint8 index); 18 | 19 | #ifndef IOT_SIP_MODE 20 | sint8 ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb); 21 | #else 22 | sint8 ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb); 23 | #endif 24 | 25 | #endif /* _WLAN_LWIP_IF_H_ */ 26 | -------------------------------------------------------------------------------- /app/include/rtc/rtcaccess.h: -------------------------------------------------------------------------------- 1 | #ifndef RTC_ACCESS_H 2 | #define RTC_ACCESS_H 3 | 4 | #include 5 | 6 | #define RTC_MMIO_BASE 0x60000700 7 | #define RTC_USER_MEM_BASE 0x60001200 8 | #define RTC_USER_MEM_NUM_DWORDS 128 9 | #define RTC_TARGET_ADDR 0x04 10 | #define RTC_COUNTER_ADDR 0x1c 11 | 12 | static inline uint32_t rtc_mem_read(uint32_t addr) 13 | { 14 | return ((uint32_t*)RTC_USER_MEM_BASE)[addr]; 15 | } 16 | 17 | static inline void rtc_mem_write(uint32_t addr, uint32_t val) 18 | { 19 | ((uint32_t*)RTC_USER_MEM_BASE)[addr]=val; 20 | } 21 | 22 | static inline uint64_t rtc_make64(uint32_t high, uint32_t low) 23 | { 24 | return (((uint64_t)high)<<32)|low; 25 | } 26 | 27 | static inline uint64_t rtc_mem_read64(uint32_t addr) 28 | { 29 | return rtc_make64(rtc_mem_read(addr+1),rtc_mem_read(addr)); 30 | } 31 | 32 | static inline void rtc_mem_write64(uint32_t addr, uint64_t val) 33 | { 34 | rtc_mem_write(addr+1,val>>32); 35 | rtc_mem_write(addr,val&0xffffffff); 36 | } 37 | 38 | static inline void rtc_memw(void) 39 | { 40 | asm volatile ("memw"); 41 | } 42 | 43 | static inline void rtc_reg_write(uint32_t addr, uint32_t val) 44 | { 45 | rtc_memw(); 46 | addr+=RTC_MMIO_BASE; 47 | *((volatile uint32_t*)addr)=val; 48 | rtc_memw(); 49 | } 50 | 51 | static inline uint32_t rtc_reg_read(uint32_t addr) 52 | { 53 | addr+=RTC_MMIO_BASE; 54 | rtc_memw(); 55 | return *((volatile uint32_t*)addr); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /app/include/rtc/rtctime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Dius Computing Pty Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * - Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the 13 | * distribution. 14 | * - Neither the name of the copyright holders nor the names of 15 | * its contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 23 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * @author Johny Mattsson 32 | */ 33 | #ifndef _RTCTIME_H_ 34 | #define _RTCTIME_H_ 35 | 36 | /* We don't want to expose the raw rtctime interface as it is heavily 37 | * 'static inline' and used by a few things, so instead we wrap the 38 | * relevant functions and expose these instead, through the rtctime.c module. 39 | */ 40 | 41 | #include 42 | #include "sections.h" 43 | 44 | #ifndef _RTCTIME_INTERNAL_H_ 45 | struct rtc_timeval 46 | { 47 | uint32_t tv_sec; 48 | uint32_t tv_usec; 49 | }; 50 | #endif 51 | 52 | void TEXT_SECTION_ATTR rtctime_early_startup (void); 53 | void rtctime_late_startup (void); 54 | void rtctime_gettimeofday (struct rtc_timeval *tv); 55 | void rtctime_settimeofday (const struct rtc_timeval *tv); 56 | bool rtctime_have_time (void); 57 | void rtctime_deep_sleep_us (uint32_t us); 58 | void rtctime_deep_sleep_until_aligned_us (uint32_t align_us, uint32_t min_us); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /app/include/sections.h: -------------------------------------------------------------------------------- 1 | #ifndef _SECTIONS_H_ 2 | #define _SECTIONS_H_ 3 | 4 | #define TEXT_SECTION_ATTR __attribute__((section(".text"))) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/json/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = libjson.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | STD_CFLAGS=-std=gnu11 -Wimplicit 30 | 31 | ############################################################# 32 | # Recursion Magic - Don't touch this!! 33 | # 34 | # Each subtree potentially has an include directory 35 | # corresponding to the common APIs applicable to modules 36 | # rooted at that subtree. Accordingly, the INCLUDE PATH 37 | # of a module can only contain the include directories up 38 | # its parent path, and not its siblings 39 | # 40 | # Required for each makefile to inherit from the parent 41 | # 42 | 43 | INCLUDES := $(INCLUDES) -I $(PDIR)include 44 | INCLUDES += -I ./ 45 | INCLUDES += -I ../libc 46 | PDIR := ../$(PDIR) 47 | sinclude $(PDIR)Makefile 48 | -------------------------------------------------------------------------------- /app/libc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = liblibc.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | ############################################################# 29 | # Recursion Magic - Don't touch this!! 30 | # 31 | # Each subtree potentially has an include directory 32 | # corresponding to the common APIs applicable to modules 33 | # rooted at that subtree. Accordingly, the INCLUDE PATH 34 | # of a module can only contain the include directories up 35 | # its parent path, and not its siblings 36 | # 37 | # Required for each makefile to inherit from the parent 38 | # 39 | 40 | INCLUDES := $(INCLUDES) -I $(PDIR)include 41 | INCLUDES += -I ./ 42 | PDIR := ../$(PDIR) 43 | sinclude $(PDIR)Makefile 44 | -------------------------------------------------------------------------------- /app/libc/c_ctype.c: -------------------------------------------------------------------------------- 1 | #include "c_ctype.h" 2 | #include "c_types.h" 3 | 4 | // int isalnum(int c){} 5 | // int isalpha(int c){} 6 | // int iscntrl(int c){} 7 | // int isdigit(int c){} 8 | // // int isgraph(int c){} 9 | // int islower(int c){} 10 | // int isprint(int c){} 11 | // int ispunct(int c){} 12 | // int isspace(int c){} 13 | // int isupper(int c){} 14 | // int isxdigit(int c){} 15 | // int tolower(int c){} 16 | // int toupper(int c){} 17 | -------------------------------------------------------------------------------- /app/libc/c_ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_CTYPE_H_ 2 | #define _C_CTYPE_H_ 3 | 4 | #if 0 5 | int isalnum(int); 6 | int isalpha(int); 7 | int iscntrl(int); 8 | int isdigit(int); 9 | // int isgraph(int); 10 | int islower(int); 11 | int isprint(int); 12 | int ispunct(int); 13 | int isspace(int); 14 | int isupper(int); 15 | int isxdigit(int); 16 | int tolower(int); 17 | int toupper(int); 18 | 19 | #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L 20 | // int isblank(int); 21 | #endif 22 | 23 | #ifndef __STRICT_ANSI__ 24 | // int isascii(int); 25 | // int toascii(int); 26 | #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a') 27 | #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A') 28 | #endif 29 | 30 | #define _U 01 31 | #define _L 02 32 | #define _N 04 33 | #define _S 010 34 | #define _P 020 35 | #define _C 040 36 | #define _X 0100 37 | #define _B 0200 38 | 39 | /* For C++ backward-compatibility only. */ 40 | // extern char _ctype_[]; 41 | #endif 42 | #endif /* _C_CTYPE_H_ */ 43 | -------------------------------------------------------------------------------- /app/libc/c_errno.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_errno_h 2 | #define __c_errno_h 3 | 4 | #include 5 | // #ifndef errno 6 | // extern int errno; 7 | // #endif 8 | 9 | // #define EDOM 1 10 | // #define ERANGE 2 11 | // #define EILSEQ 4 12 | // #define ESIGNUM 3 13 | // #define EINVAL 5 14 | // #define ENOMEM 6 15 | 16 | #endif 17 | 18 | /* end of c_errno.h */ 19 | 20 | -------------------------------------------------------------------------------- /app/libc/c_fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_fcntl_h 2 | #define __c_fcntl_h 3 | 4 | #include 5 | 6 | #endif 7 | 8 | /* end of c_fcntl.h */ 9 | 10 | -------------------------------------------------------------------------------- /app/libc/c_float.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_float_h 2 | #define __c_float_h 3 | 4 | #define DBL_EPSILON 2.2204460492503131E-16 5 | 6 | #endif 7 | 8 | /* end of c_float.h */ 9 | -------------------------------------------------------------------------------- /app/libc/c_limits.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_limits_h 2 | #define __c_limits_h 3 | 4 | #include 5 | #if 0 6 | #define CHAR_BIT 8 7 | /* max number of bits for smallest object that is not a bit-field (byte) */ 8 | #define SCHAR_MIN (-128) 9 | /* mimimum value for an object of type signed char */ 10 | #define SCHAR_MAX 127 11 | /* maximum value for an object of type signed char */ 12 | #define UCHAR_MAX 255 13 | /* maximum value for an object of type unsigned char */ 14 | #ifdef __FEATURE_SIGNED_CHAR 15 | #define CHAR_MIN (-128) 16 | /* minimum value for an object of type char */ 17 | #define CHAR_MAX 127 18 | /* maximum value for an object of type char */ 19 | #else 20 | #define CHAR_MIN 0 21 | /* minimum value for an object of type char */ 22 | #define CHAR_MAX 255 23 | /* maximum value for an object of type char */ 24 | #endif 25 | 26 | #define SHRT_MIN (-0x8000) 27 | /* minimum value for an object of type short int */ 28 | #define SHRT_MAX 0x7fff 29 | /* maximum value for an object of type short int */ 30 | #define USHRT_MAX 65535 31 | /* maximum value for an object of type unsigned short int */ 32 | #define INT_MIN (~0x7fffffff) /* -2147483648 and 0x80000000 are unsigned */ 33 | /* minimum value for an object of type int */ 34 | #define INT_MAX 0x7fffffff 35 | /* maximum value for an object of type int */ 36 | #define UINT_MAX 0xffffffffU 37 | /* maximum value for an object of type unsigned int */ 38 | #define LONG_MIN (~0x7fffffffL) 39 | /* minimum value for an object of type long int */ 40 | #define LONG_MAX 0x7fffffffL 41 | /* maximum value for an object of type long int */ 42 | #define ULONG_MAX 0xffffffffUL 43 | /* maximum value for an object of type unsigned long int */ 44 | #if !defined(__STRICT_ANSI__) || (defined(__STDC_VERSION__) && 199901L <= __STDC_VERSION__) 45 | #define LLONG_MIN (~0x7fffffffffffffffLL) 46 | /* minimum value for an object of type long long int */ 47 | #define LLONG_MAX 0x7fffffffffffffffLL 48 | /* maximum value for an object of type long long int */ 49 | #define ULLONG_MAX 0xffffffffffffffffULL 50 | /* maximum value for an object of type unsigned long int */ 51 | #endif 52 | 53 | #endif 54 | 55 | #endif 56 | 57 | /* end of c_limits.h */ 58 | 59 | -------------------------------------------------------------------------------- /app/libc/c_locale.h: -------------------------------------------------------------------------------- 1 | /* 2 | c_locale.h 3 | Values appropriate for the formatting of monetary and other 4 | numberic quantities. 5 | */ 6 | 7 | #ifndef _C_LOCALE_H_ 8 | #define _C_LOCALE_H_ 9 | 10 | #include 11 | 12 | #if 0 13 | #ifndef NULL 14 | #define NULL 0 15 | #endif 16 | 17 | #define LC_ALL 0 18 | #define LC_COLLATE 1 19 | #define LC_CTYPE 2 20 | #define LC_MONETARY 3 21 | #define LC_NUMERIC 4 22 | #define LC_TIME 5 23 | #define LC_MESSAGES 6 24 | 25 | struct lconv 26 | { 27 | char *decimal_point; 28 | char *thousands_sep; 29 | char *grouping; 30 | char *int_curr_symbol; 31 | char *currency_symbol; 32 | char *mon_decimal_point; 33 | char *mon_thousands_sep; 34 | char *mon_grouping; 35 | char *positive_sign; 36 | char *negative_sign; 37 | char int_frac_digits; 38 | char frac_digits; 39 | char p_cs_precedes; 40 | char p_sep_by_space; 41 | char n_cs_precedes; 42 | char n_sep_by_space; 43 | char p_sign_posn; 44 | char n_sign_posn; 45 | char int_n_cs_precedes; 46 | char int_n_sep_by_space; 47 | char int_n_sign_posn; 48 | char int_p_cs_precedes; 49 | char int_p_sep_by_space; 50 | char int_p_sign_posn; 51 | }; 52 | 53 | #ifndef _REENT_ONLY 54 | // char *setlocale(int category, const char *locale); 55 | struct lconv *localeconv(void); 56 | #endif 57 | 58 | // struct _reent; 59 | // char *_setlocale_r(struct _reent *, int category, const char *locale); 60 | // struct lconv *_localeconv_r(struct _reent *); 61 | #endif 62 | #endif /* _C_LOCALE_H_ */ 63 | -------------------------------------------------------------------------------- /app/libc/c_math.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_MATH_H_ 2 | #define _C_MATH_H_ 3 | #include 4 | 5 | double floor(double); 6 | double pow(double, double); 7 | 8 | #if 0 9 | #ifndef HUGE_VAL 10 | #define HUGE_VAL (1.0e99) 11 | #endif 12 | 13 | #ifndef HUGE_VALF 14 | #define HUGE_VALF (1.0e999999999F) 15 | #endif 16 | 17 | #if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE) 18 | #define HUGE_VALL (1.0e999999999L) 19 | #endif 20 | 21 | #if !defined(INFINITY) 22 | #define INFINITY (HUGE_VALF) 23 | #endif 24 | 25 | 26 | /* Reentrant ANSI C functions. */ 27 | 28 | #ifndef __math_68881 29 | // double atan(double); 30 | // double cos(double); 31 | // double sin(double); 32 | // double tan(double); 33 | // double tanh(double); 34 | // double frexp(double, int *); 35 | // double modf(double, double *); 36 | // double ceil(double); 37 | // double fabs(double); 38 | // double floor(double); 39 | #endif /* ! defined (__math_68881) */ 40 | 41 | /* Non reentrant ANSI C functions. */ 42 | 43 | #ifndef _REENT_ONLY 44 | #ifndef __math_68881 45 | // double acos(double); 46 | // double asin(double); 47 | // double atan2(double, double); 48 | // double cosh(double); 49 | // double sinh(double); 50 | // double exp(double); 51 | // double ldexp(double, int); 52 | // double log(double); 53 | // double log10(double); 54 | // double pow(double, double); 55 | // double sqrt(double); 56 | // double fmod(double, double); 57 | #endif /* ! defined (__math_68881) */ 58 | #endif /* ! defined (_REENT_ONLY) */ 59 | 60 | #endif 61 | 62 | #endif /* _MATH_H_ */ 63 | -------------------------------------------------------------------------------- /app/libc/c_signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_SIGNAL_H_ 2 | #define _C_SIGNAL_H_ 3 | 4 | #include 5 | 6 | #endif /* _C_SIGNAL_H_ */ 7 | -------------------------------------------------------------------------------- /app/libc/c_stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stdarg_h 2 | #define __c_stdarg_h 3 | 4 | #if defined(__GNUC__) 5 | 6 | #include 7 | 8 | #else 9 | 10 | typedef char * va_list; 11 | 12 | #define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1)) 13 | 14 | #define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v)) 15 | #define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t))) 16 | #define va_end(ap) (ap = (va_list)0) 17 | 18 | #endif 19 | 20 | #endif 21 | 22 | /* end of c_stdarg.h */ 23 | -------------------------------------------------------------------------------- /app/libc/c_stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stddef_h 2 | #define __c_stddef_h 3 | 4 | typedef signed int ptrdiff_t; 5 | 6 | #if !defined(__offsetof) 7 | #define __offsetof(s, m) (size_t)&(((s *)0)->m) 8 | #endif 9 | 10 | #if !defined(__size_t) 11 | #define __size_t 1 12 | typedef unsigned int size_t; /* others (e.g. ) also define */ 13 | /* the unsigned integral type of the result of the sizeof operator. */ 14 | #endif 15 | 16 | #undef NULL /* others (e.g. ) also define */ 17 | #define NULL 0 18 | /* null pointer constant. */ 19 | 20 | #endif 21 | 22 | /* end of c_stddef.h */ 23 | 24 | -------------------------------------------------------------------------------- /app/libc/c_stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_STDIO_H_ 2 | #define _C_STDIO_H_ 3 | 4 | #define __need_size_t 5 | 6 | #include "c_stddef.h" 7 | #include "osapi.h" 8 | // #include "driver/uart.h" 9 | 10 | // #define __need___va_list 11 | //#include "c_stdarg.h" 12 | 13 | //struct __sFILE{ 14 | // int _r; /* read space left for getc() */ 15 | // int _w; /* write space left for putc() */ 16 | //}; 17 | // typedef struct __sFILE __FILE; 18 | // typedef __FILE FILE; 19 | 20 | extern int c_stdin; 21 | extern int c_stdout; 22 | extern int c_stderr; 23 | 24 | // #define _IOFBF 0 /* setvbuf should set fully buffered */ 25 | // #define _IOLBF 1 /* setvbuf should set line buffered */ 26 | // #define _IONBF 2 /* setvbuf should set unbuffered */ 27 | 28 | // #ifndef NULL 29 | // #define NULL 0 30 | // #endif 31 | 32 | #define EOF (-1) 33 | 34 | #ifdef __BUFSIZ__ 35 | #define BUFSIZ __BUFSIZ__ 36 | #else 37 | #define BUFSIZ 1024 38 | #endif 39 | 40 | #ifndef SEEK_SET 41 | #define SEEK_SET 0 /* set file offset to offset */ 42 | #endif 43 | #ifndef SEEK_CUR 44 | #define SEEK_CUR 1 /* set file offset to current plus offset */ 45 | #endif 46 | #ifndef SEEK_END 47 | #define SEEK_END 2 /* set file offset to EOF plus offset */ 48 | #endif 49 | 50 | // #define c_malloc os_malloc 51 | // #define c_zalloc os_zalloc 52 | // #define c_free os_free 53 | 54 | extern void output_redirect(const char *str); 55 | #define c_puts output_redirect 56 | 57 | // #define c_printf os_printf 58 | // int c_printf(const char *c, ...); 59 | #if defined( LUA_NUMBER_INTEGRAL ) 60 | #define c_sprintf os_sprintf 61 | #else 62 | #include "c_stdarg.h" 63 | void c_sprintf(char* s,char *fmt, ...); 64 | #endif 65 | 66 | // #define c_vsprintf ets_vsprintf 67 | #define c_printf(...) do { \ 68 | unsigned char __print_buf[BUFSIZ]; \ 69 | c_sprintf(__print_buf, __VA_ARGS__); \ 70 | c_puts(__print_buf); \ 71 | } while(0) 72 | 73 | // #define c_getc ets_getc 74 | // #define c_getchar ets_getc 75 | // note: contact esp to ensure the real getchar function.. 76 | 77 | // FILE *c_fopen(const char *_name, const char *_type); 78 | // FILE *c_freopen(const char *, const char *, FILE *); 79 | // FILE *c_tmpfile(void); 80 | 81 | // int c_putchar(int); 82 | // int c_printf(const char *, ...); 83 | // int c_sprintf(char *, const char *, ...); 84 | // int c_getc(FILE *); 85 | 86 | // int c_ungetc(int, FILE *); 87 | 88 | // int c_fprintf(FILE *, const char *, ...); 89 | // int c_fscanf(FILE *, const char *, ...); 90 | // int c_fclose(FILE *); 91 | // int c_fflush(FILE *); 92 | // int c_setvbuf(FILE *, char *, int, size_t); 93 | // void c_clearerr(FILE *); 94 | // int c_fseek(FILE *, long, int); 95 | // long c_ftell( FILE *); 96 | // int c_fputs(const char *, FILE *); 97 | // char *c_fgets(char *, int, FILE *); 98 | // size_t c_fread(void *, size_t _size, size_t _n, FILE *); 99 | // size_t c_fwrite(const void * , size_t _size, size_t _n, FILE *); 100 | // int c_feof(FILE *); 101 | // int c_ferror(FILE *); 102 | 103 | #endif /* _C_STDIO_H_ */ 104 | -------------------------------------------------------------------------------- /app/libc/c_stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_stdlib.h 3 | * 4 | * Definitions for common types, variables, and functions. 5 | */ 6 | 7 | #ifndef _C_STDLIB_H_ 8 | #define _C_STDLIB_H_ 9 | 10 | #include "c_stddef.h" 11 | #include "mem.h" 12 | 13 | #define EXIT_FAILURE 1 14 | #define EXIT_SUCCESS 0 15 | 16 | #define __INT_MAX__ 2147483647 17 | #undef __RAND_MAX 18 | #if __INT_MAX__ == 32767 19 | #define __RAND_MAX 32767 20 | #else 21 | #define __RAND_MAX 0x7fffffff 22 | #endif 23 | #define RAND_MAX __RAND_MAX 24 | 25 | #ifndef mem_realloc 26 | #define mem_realloc pvPortRealloc 27 | #endif 28 | #ifndef os_realloc 29 | #define os_realloc(p, s) mem_realloc((p), (s)) 30 | #endif 31 | 32 | #define c_free os_free 33 | #define c_malloc os_malloc 34 | #define c_zalloc os_zalloc 35 | #define c_realloc os_realloc 36 | 37 | #define c_abs abs 38 | #define c_atoi atoi 39 | //#define c_strtod strtod 40 | #define c_strtol strtol 41 | #define c_strtoul strtoul 42 | 43 | // int c_abs(int); 44 | 45 | // void c_exit(int); 46 | 47 | // c_getenv() get env "LUA_INIT" string for lua initialization. 48 | // const char *c_getenv(const char *__string); 49 | 50 | // void *c_malloc(size_t __size); 51 | // void *c_zalloc(size_t __size); 52 | // void c_free(void *); 53 | 54 | // int c_rand(void); 55 | // void c_srand(unsigned int __seed); 56 | 57 | // int c_atoi(const char *__nptr); 58 | double c_strtod(const char *__n, char **__end_PTR); 59 | // // long c_strtol(const char *__n, char **__end_PTR, int __base); 60 | // unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base); 61 | // // long long c_strtoll(const char *__n, char **__end_PTR, int __base); 62 | 63 | #endif /* _C_STDLIB_H_ */ 64 | -------------------------------------------------------------------------------- /app/lwip/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | UP_EXTRACT_DIR = .. 16 | GEN_LIBS = liblwip.a 17 | COMPONENTS_liblwip = api/liblwipapi.a \ 18 | app/liblwipapp.a \ 19 | core/liblwipcore.a \ 20 | core/ipv4/liblwipipv4.a \ 21 | netif/liblwipnetif.a 22 | endif 23 | 24 | 25 | ############################################################# 26 | # Configuration i.e. compile options etc. 27 | # Target specific stuff (defines etc.) goes in here! 28 | # Generally values applying to a tree are captured in the 29 | # makefile at its root level - these are then overridden 30 | # for a subtree within the makefile rooted therein 31 | # 32 | #DEFINES += 33 | 34 | ############################################################# 35 | # Recursion Magic - Don't touch this!! 36 | # 37 | # Each subtree potentially has an include directory 38 | # corresponding to the common APIs applicable to modules 39 | # rooted at that subtree. Accordingly, the INCLUDE PATH 40 | # of a module can only contain the include directories up 41 | # its parent path, and not its siblings 42 | # 43 | # Required for each makefile to inherit from the parent 44 | # 45 | 46 | INCLUDES := $(INCLUDES) -I $(PDIR)include 47 | INCLUDES += -I ./ 48 | PDIR := ../$(PDIR) 49 | sinclude $(PDIR)Makefile 50 | 51 | -------------------------------------------------------------------------------- /app/lwip/api/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = liblwipapi.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | 30 | ############################################################# 31 | # Recursion Magic - Don't touch this!! 32 | # 33 | # Each subtree potentially has an include directory 34 | # corresponding to the common APIs applicable to modules 35 | # rooted at that subtree. Accordingly, the INCLUDE PATH 36 | # of a module can only contain the include directories up 37 | # its parent path, and not its siblings 38 | # 39 | # Required for each makefile to inherit from the parent 40 | # 41 | 42 | INCLUDES := $(INCLUDES) -I $(PDIR)include 43 | INCLUDES += -I ./ 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | -------------------------------------------------------------------------------- /app/lwip/api/err.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Error Management module 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/err.h" 40 | 41 | #ifdef LWIP_DEBUG 42 | 43 | static const char *err_strerr[] = { 44 | "Ok.", /* ERR_OK 0 */ 45 | "Out of memory error.", /* ERR_MEM -1 */ 46 | "Buffer error.", /* ERR_BUF -2 */ 47 | "Timeout.", /* ERR_TIMEOUT -3 */ 48 | "Routing problem.", /* ERR_RTE -4 */ 49 | "Operation in progress.", /* ERR_INPROGRESS -5 */ 50 | "Illegal value.", /* ERR_VAL -6 */ 51 | "Operation would block.", /* ERR_WOULDBLOCK -7 */ 52 | "Connection aborted.", /* ERR_ABRT -8 */ 53 | "Connection reset.", /* ERR_RST -9 */ 54 | "Connection closed.", /* ERR_CLSD -10 */ 55 | "Not connected.", /* ERR_CONN -11 */ 56 | "Illegal argument.", /* ERR_ARG -12 */ 57 | "Address in use.", /* ERR_USE -13 */ 58 | "Low-level netif error.", /* ERR_IF -14 */ 59 | "Already connected.", /* ERR_ISCONN -15 */ 60 | }; 61 | 62 | /** 63 | * Convert an lwip internal error to a string representation. 64 | * 65 | * @param err an lwip internal err_t 66 | * @return a string representation for err 67 | */ 68 | const char * 69 | lwip_strerr(err_t err) 70 | { 71 | return err_strerr[-err]; 72 | 73 | } 74 | 75 | #endif /* LWIP_DEBUG */ 76 | -------------------------------------------------------------------------------- /app/lwip/api/netbuf.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/lwip/api/netbuf.c -------------------------------------------------------------------------------- /app/lwip/api/tcpip.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/lwip/api/tcpip.c -------------------------------------------------------------------------------- /app/lwip/app/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = liblwipapp.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | 30 | ############################################################# 31 | # Recursion Magic - Don't touch this!! 32 | # 33 | # Each subtree potentially has an include directory 34 | # corresponding to the common APIs applicable to modules 35 | # rooted at that subtree. Accordingly, the INCLUDE PATH 36 | # of a module can only contain the include directories up 37 | # its parent path, and not its siblings 38 | # 39 | # Required for each makefile to inherit from the parent 40 | # 41 | 42 | INCLUDES := $(INCLUDES) -I $(PDIR)include 43 | INCLUDES += -I ./ 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | -------------------------------------------------------------------------------- /app/lwip/core/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = liblwipcore.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | 30 | ############################################################# 31 | # Recursion Magic - Don't touch this!! 32 | # 33 | # Each subtree potentially has an include directory 34 | # corresponding to the common APIs applicable to modules 35 | # rooted at that subtree. Accordingly, the INCLUDE PATH 36 | # of a module can only contain the include directories up 37 | # its parent path, and not its siblings 38 | # 39 | # Required for each makefile to inherit from the parent 40 | # 41 | 42 | INCLUDES := $(INCLUDES) -I $(PDIR)include 43 | INCLUDES += -I ./ 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | -------------------------------------------------------------------------------- /app/lwip/core/def.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Common functions used throughout the stack. 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Simon Goldschmidt 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | #include "lwip/def.h" 41 | 42 | /** 43 | * These are reference implementations of the byte swapping functions. 44 | * Again with the aim of being simple, correct and fully portable. 45 | * Byte swapping is the second thing you would want to optimize. You will 46 | * need to port it to your architecture and in your cc.h: 47 | * 48 | * #define LWIP_PLATFORM_BYTESWAP 1 49 | * #define LWIP_PLATFORM_HTONS(x) 50 | * #define LWIP_PLATFORM_HTONL(x) 51 | * 52 | * Note ntohs() and ntohl() are merely references to the htonx counterparts. 53 | */ 54 | 55 | #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) 56 | 57 | /** 58 | * Convert an u16_t from host- to network byte order. 59 | * 60 | * @param n u16_t in host byte order 61 | * @return n in network byte order 62 | */ 63 | u16_t 64 | lwip_htons(u16_t n) 65 | { 66 | return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); 67 | } 68 | 69 | /** 70 | * Convert an u16_t from network- to host byte order. 71 | * 72 | * @param n u16_t in network byte order 73 | * @return n in host byte order 74 | */ 75 | u16_t 76 | lwip_ntohs(u16_t n) 77 | { 78 | return lwip_htons(n); 79 | } 80 | 81 | /** 82 | * Convert an u32_t from host- to network byte order. 83 | * 84 | * @param n u32_t in host byte order 85 | * @return n in network byte order 86 | */ 87 | u32_t 88 | lwip_htonl(u32_t n) 89 | { 90 | return ((n & 0xff) << 24) | 91 | ((n & 0xff00) << 8) | 92 | ((n & 0xff0000UL) >> 8) | 93 | ((n & 0xff000000UL) >> 24); 94 | } 95 | 96 | /** 97 | * Convert an u32_t from network- to host byte order. 98 | * 99 | * @param n u32_t in network byte order 100 | * @return n in host byte order 101 | */ 102 | u32_t 103 | lwip_ntohl(u32_t n) 104 | { 105 | return lwip_htonl(n); 106 | } 107 | 108 | #endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ 109 | -------------------------------------------------------------------------------- /app/lwip/core/ipv4/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = liblwipipv4.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | 30 | ############################################################# 31 | # Recursion Magic - Don't touch this!! 32 | # 33 | # Each subtree potentially has an include directory 34 | # corresponding to the common APIs applicable to modules 35 | # rooted at that subtree. Accordingly, the INCLUDE PATH 36 | # of a module can only contain the include directories up 37 | # its parent path, and not its siblings 38 | # 39 | # Required for each makefile to inherit from the parent 40 | # 41 | 42 | INCLUDES := $(INCLUDES) -I $(PDIR)include 43 | INCLUDES += -I ./ 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | -------------------------------------------------------------------------------- /app/lwip/core/ipv4/icmp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/lwip/core/ipv4/icmp.c -------------------------------------------------------------------------------- /app/lwip/core/ipv4/inet.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Functions common to all TCP/IPv4 modules, such as the byte order functions. 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/inet.h" 42 | 43 | -------------------------------------------------------------------------------- /app/lwip/core/sys.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * lwIP Operating System abstraction 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/sys.h" 42 | 43 | /* Most of the functions defined in sys.h must be implemented in the 44 | * architecture-dependent file sys_arch.c */ 45 | 46 | #if !NO_SYS 47 | 48 | /** 49 | * Sleep for some ms. Timeouts are NOT processed while sleeping. 50 | * 51 | * @param ms number of milliseconds to sleep 52 | */ 53 | void 54 | sys_msleep(u32_t ms) 55 | { 56 | if (ms > 0) { 57 | sys_sem_t delaysem; 58 | err_t err = sys_sem_new(&delaysem, 0); 59 | if (err == ERR_OK) { 60 | sys_arch_sem_wait(&delaysem, ms); 61 | sys_sem_free(&delaysem); 62 | } 63 | } 64 | } 65 | 66 | #endif /* !NO_SYS */ 67 | -------------------------------------------------------------------------------- /app/lwip/core/sys_arch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2010 - 2011 espressif system 3 | */ 4 | 5 | #include "c_types.h" 6 | #include "ets_sys.h" 7 | #include "osapi.h" 8 | #include "os_type.h" 9 | 10 | #include "lwip/opt.h" 11 | #include "lwip/sys.h" 12 | 13 | #include "eagle_soc.h" 14 | -------------------------------------------------------------------------------- /app/lwip/netif/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = liblwipnetif.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | 30 | ############################################################# 31 | # Recursion Magic - Don't touch this!! 32 | # 33 | # Each subtree potentially has an include directory 34 | # corresponding to the common APIs applicable to modules 35 | # rooted at that subtree. Accordingly, the INCLUDE PATH 36 | # of a module can only contain the include directories up 37 | # its parent path, and not its siblings 38 | # 39 | # Required for each makefile to inherit from the parent 40 | # 41 | 42 | INCLUDES := $(INCLUDES) -I $(PDIR)include 43 | INCLUDES += -I ./ 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | -------------------------------------------------------------------------------- /app/mqtt/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = mqtt.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | EXTRA_CCFLAGS += \ 29 | -DMQTT_SUB_COUNT=$(MQTT_SUB_COUNT) \ 30 | -DMQTT_SUB_TOPIC1="$(MQTT_SUB_TOPIC1)" -DMQTT_SUB_TOPIC2="$(MQTT_SUB_TOPIC2)" \ 31 | -DMQTT_PUB_COUNT=$(MQTT_PUB_COUNT) \ 32 | -DMQTT_PUB_TOPIC1="$(MQTT_PUB_TOPIC1)" \ 33 | -DMQTT_HOST_NAME="$(MQTT_HOST_NAME)" -DMQTT_USE_IP=$(MQTT_USE_IP) \ 34 | -DDEFAULT_MQTT_IP="$(DEFAULT_MQTT_IP)" 35 | 36 | 37 | ############################################################# 38 | # Recursion Magic - Don't touch this!! 39 | # 40 | # Each subtree potentially has an include directory 41 | # corresponding to the common APIs applicable to modules 42 | # rooted at that subtree. Accordingly, the INCLUDE PATH 43 | # of a module can only contain the include directories up 44 | # its parent path, and not its siblings 45 | # 46 | # Required for each makefile to inherit from the parent 47 | # 48 | 49 | INCLUDES := $(INCLUDES) -I $(PDIR)include 50 | INCLUDES += -I ./ 51 | INCLUDES += -I ../libc 52 | INCLUDES += -I ../ 53 | PDIR := ../$(PDIR) 54 | sinclude $(PDIR)Makefile 55 | -------------------------------------------------------------------------------- /app/mqtt/app.h: -------------------------------------------------------------------------------- 1 | #ifndef __MQTT_APP_H 2 | #define __MQTT_APP_H 3 | 4 | void mqtt_app_init(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/mqtt/mqtt_api.h: -------------------------------------------------------------------------------- 1 | #ifndef __MQTT_API_H 2 | #define __MQTT_API_H 3 | 4 | // #define MQTT_EXPECT_IP 5 | 6 | #ifdef MQTT_EXPECT_IP 7 | #define DEFAULT_MQTT_EXPECT_IP 0.0.0.0 8 | #endif 9 | 10 | #define NULL_STR "null" 11 | 12 | /* MQTT-Related Structures */ 13 | typedef struct 14 | { 15 | uint8_t topic_offset; //length of sub topic 16 | char * topic; 17 | } USER_TOPIC_T; 18 | 19 | typedef struct 20 | { 21 | char * mqtt_host; //MQTT host IP 22 | USER_TOPIC_T** subs; //list of sub topics 23 | USER_TOPIC_T** pubs; //list of pub topics 24 | 25 | } USER_MQTT_T; 26 | 27 | void mqtt_app_init(char * ip); 28 | 29 | int set_mqtt_host(char * host); 30 | 31 | bool mqttIsConnected(); 32 | void mqtt_setconn(uint8_t state); 33 | 34 | void mqtt_app_update_handle(USER_MQTT_T * user_mqtt_ptr); 35 | void mqtt_app_update_topics(); 36 | 37 | bool mqtt_api_pub(unsigned topicNum, char * msg, int len); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /app/mqtt/mqtt_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __MQTT_CONFIG_H__ 2 | #define __MQTT_CONFIG_H__ 3 | 4 | // #define CFG_HOLDER 0x00FF55A4 /* Change this value to load default configurations */ 5 | // #define CFG_LOCATION 0x3C /* Please don't change or if you know what you doing */ 6 | // #define MQTT_SSL_ENABLE 7 | 8 | /*DEFAULT CONFIGURATIONS*/ 9 | 10 | #define MQTT_PORT 1883 11 | #define MQTT_BUF_SIZE 1440 12 | #define MQTT_BUF_USABLE 1432 //guess? 13 | 14 | #define MQTT_KEEPALIVE 20 /*second*/ 15 | #define MQTT_SEND_TIMOUT 5 16 | 17 | #define MQTT_MAX_TOPIC_LEN 25 18 | 19 | // #define MQTT_CLIENT_ID "DVES_%08X" 20 | #define MQTT_USER "DVES_USER" 21 | #define MQTT_PASS "DVES_PASS" 22 | 23 | #define MQTT_RECONNECT_TIMEOUT 5 /*second*/ 24 | 25 | #define DEFAULT_SECURITY 0 26 | #define QUEUE_BUFFER_SIZE 1440 27 | 28 | #define PROTOCOL_NAMEv31 /*MQTT version 3.1 compatible with Mosquitto v0.15*/ 29 | //PROTOCOL_NAMEv311 /*MQTT version 3.11 compatible with https://eclipse.org/paho/clients/testing/*/ 30 | 31 | #endif // __MQTT_CONFIG_H__ 32 | -------------------------------------------------------------------------------- /app/mqtt/mqtt_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef __MQTT_HELPER_H__ 2 | #define __MQTT_HELPER_H__ 3 | 4 | #define MAX_BRIDGE_STRLEN 124 //includes stubs for samples, events, meta 5 | 6 | #define MAX_SAMPLE_STRLEN 82 //exluding anything after value colon 7 | #define MAX_EVENT_STRLEN 80 //exluding anything after data colon 8 | #define MAX_META_STRLEN 79 //exluding anything after data colon 9 | 10 | 11 | /* MQTT Pub/Sub topics 12 | * Pubs: All are /frames. Server will know from device_id key 13 | * Subs: Each attached device subs to /frames/%id% 14 | */ 15 | #define MQTT_PUBSUB_PREFIX "/frames" 16 | 17 | /* COMMON KEY STRINGS 18 | * Strings used for both API -> Device and Device -> API 19 | */ 20 | #define KEYSTR_DATETIME "ts" // epoch timestamp 21 | #define KEYSTR_DEVICE_ID "device_id" // unique id 22 | 23 | /* Keys inside various arrays */ 24 | #define KEYSTR_DATA "data" 25 | #define KEYSTR_SAMPLE_VALUE "value" 26 | 27 | 28 | #endif // __MQTT_HELPER_H__ 29 | -------------------------------------------------------------------------------- /app/mqtt/mqtt_queue.c: -------------------------------------------------------------------------------- 1 | /* str_queue.c 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #include "mqtt_queue.h" 31 | 32 | #include "user_interface.h" 33 | #include "osapi.h" 34 | #include "os_type.h" 35 | #include "mem.h" 36 | #include "proto.h" 37 | void QUEUE_Init(QUEUE *queue, int bufferSize) 38 | { 39 | queue->buf = (uint8_t*)os_zalloc(bufferSize); 40 | RINGBUF_Init(&queue->rb, queue->buf, bufferSize); 41 | } 42 | int32_t QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len) 43 | { 44 | return PROTO_AddRb(&queue->rb, buffer, len); 45 | } 46 | int32_t QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen) 47 | { 48 | 49 | return PROTO_ParseRb(&queue->rb, buffer, len, maxLen); 50 | } 51 | 52 | BOOL QUEUE_IsEmpty(QUEUE *queue) 53 | { 54 | if(queue->rb.fill_cnt<=0) 55 | return TRUE; 56 | return FALSE; 57 | } 58 | -------------------------------------------------------------------------------- /app/mqtt/mqtt_queue.h: -------------------------------------------------------------------------------- 1 | /* str_queue.h -- 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef USER_QUEUE_H_ 32 | #define USER_QUEUE_H_ 33 | #include "os_type.h" 34 | #include "ringbuf.h" 35 | typedef struct { 36 | uint8_t *buf; 37 | RINGBUF rb; 38 | } QUEUE; 39 | 40 | void QUEUE_Init(QUEUE *queue, int bufferSize); 41 | int32_t QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len); 42 | int32_t QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen); 43 | BOOL QUEUE_IsEmpty(QUEUE *queue); 44 | #endif /* USER_QUEUE_H_ */ 45 | -------------------------------------------------------------------------------- /app/mqtt/proto.c: -------------------------------------------------------------------------------- 1 | #include "proto.h" 2 | #include "ringbuf.h" 3 | I8 PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize) 4 | { 5 | parser->buf = buf; 6 | parser->bufSize = bufSize; 7 | parser->dataLen = 0; 8 | parser->callback = completeCallback; 9 | parser->isEsc = 0; 10 | return 0; 11 | } 12 | 13 | I8 PROTO_ParseByte(PROTO_PARSER *parser, U8 value) 14 | { 15 | switch(value){ 16 | case 0x7D: 17 | parser->isEsc = 1; 18 | break; 19 | 20 | case 0x7E: 21 | parser->dataLen = 0; 22 | parser->isEsc = 0; 23 | parser->isBegin = 1; 24 | break; 25 | 26 | case 0x7F: 27 | if (parser->callback != NULL) 28 | parser->callback(); 29 | parser->isBegin = 0; 30 | return 0; 31 | break; 32 | 33 | default: 34 | if(parser->isBegin == 0) break; 35 | 36 | if(parser->isEsc){ 37 | value ^= 0x20; 38 | parser->isEsc = 0; 39 | } 40 | 41 | if(parser->dataLen < parser->bufSize) 42 | parser->buf[parser->dataLen++] = value; 43 | 44 | break; 45 | } 46 | return -1; 47 | } 48 | 49 | I8 PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len) 50 | { 51 | while(len--) 52 | PROTO_ParseByte(parser, *buf++); 53 | 54 | return 0; 55 | } 56 | I16 PROTO_ParseRb(RINGBUF* rb, U8 *bufOut, U16* len, U16 maxBufLen) 57 | { 58 | U8 c; 59 | 60 | PROTO_PARSER proto; 61 | PROTO_Init(&proto, NULL, bufOut, maxBufLen); 62 | while(RINGBUF_Get(rb, &c) == 0){ 63 | if(PROTO_ParseByte(&proto, c) == 0){ 64 | *len = proto.dataLen; 65 | return 0; 66 | } 67 | } 68 | return -1; 69 | } 70 | I16 PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize) 71 | { 72 | U16 i = 2; 73 | U16 len = *(U16*) packet; 74 | 75 | if (bufSize < 1) return -1; 76 | 77 | *buf++ = 0x7E; 78 | bufSize--; 79 | 80 | while (len--) { 81 | switch (*packet) { 82 | case 0x7D: 83 | case 0x7E: 84 | case 0x7F: 85 | if (bufSize < 2) return -1; 86 | *buf++ = 0x7D; 87 | *buf++ = *packet++ ^ 0x20; 88 | i += 2; 89 | bufSize -= 2; 90 | break; 91 | default: 92 | if (bufSize < 1) return -1; 93 | *buf++ = *packet++; 94 | i++; 95 | bufSize--; 96 | break; 97 | } 98 | } 99 | 100 | if (bufSize < 1) return -1; 101 | *buf++ = 0x7F; 102 | 103 | return i; 104 | } 105 | 106 | I16 PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len) 107 | { 108 | U16 i = 2; 109 | if(RINGBUF_Put(rb, 0x7E) == -1) return -1; 110 | while (len--) { 111 | switch (*packet) { 112 | case 0x7D: 113 | case 0x7E: 114 | case 0x7F: 115 | if(RINGBUF_Put(rb, 0x7D) == -1) return -1; 116 | if(RINGBUF_Put(rb, *packet++ ^ 0x20) == -1) return -1; 117 | i += 2; 118 | break; 119 | default: 120 | if(RINGBUF_Put(rb, *packet++) == -1) return -1; 121 | i++; 122 | break; 123 | } 124 | } 125 | if(RINGBUF_Put(rb, 0x7F) == -1) return -1; 126 | 127 | return i; 128 | } 129 | -------------------------------------------------------------------------------- /app/mqtt/proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: proto.h 3 | * Author: ThuHien 4 | * 5 | * Created on November 23, 2012, 8:57 AM 6 | */ 7 | 8 | #ifndef _PROTO_H_ 9 | #define _PROTO_H_ 10 | #include 11 | #include "typedef.h" 12 | #include "ringbuf.h" 13 | 14 | typedef void(PROTO_PARSE_CALLBACK)(); 15 | 16 | typedef struct{ 17 | U8 *buf; 18 | U16 bufSize; 19 | U16 dataLen; 20 | U8 isEsc; 21 | U8 isBegin; 22 | PROTO_PARSE_CALLBACK* callback; 23 | }PROTO_PARSER; 24 | 25 | I8 PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize); 26 | I8 PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len); 27 | I16 PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize); 28 | I16 PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len); 29 | I8 PROTO_ParseByte(PROTO_PARSER *parser, U8 value); 30 | I16 PROTO_ParseRb(RINGBUF *rb, U8 *bufOut, U16* len, U16 maxBufLen); 31 | #endif 32 | -------------------------------------------------------------------------------- /app/mqtt/ringbuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Ring Buffer library 4 | */ 5 | 6 | #include "ringbuf.h" 7 | 8 | 9 | /** 10 | * \brief init a RINGBUF object 11 | * \param r pointer to a RINGBUF object 12 | * \param buf pointer to a byte array 13 | * \param size size of buf 14 | * \return 0 if successfull, otherwise failed 15 | */ 16 | I16 RINGBUF_Init(RINGBUF *r, U8* buf, I32 size) 17 | { 18 | if(r == NULL || buf == NULL || size < 2) return -1; 19 | 20 | r->p_o = r->p_r = r->p_w = buf; 21 | r->fill_cnt = 0; 22 | r->size = size; 23 | 24 | return 0; 25 | } 26 | /** 27 | * \brief put a character into ring buffer 28 | * \param r pointer to a ringbuf object 29 | * \param c character to be put 30 | * \return 0 if successfull, otherwise failed 31 | */ 32 | I16 RINGBUF_Put(RINGBUF *r, U8 c) 33 | { 34 | if(r->fill_cnt>=r->size)return -1; // ring buffer is full, this should be atomic operation 35 | 36 | 37 | r->fill_cnt++; // increase filled slots count, this should be atomic operation 38 | 39 | 40 | *r->p_w++ = c; // put character into buffer 41 | 42 | if(r->p_w >= r->p_o + r->size) // rollback if write pointer go pass 43 | r->p_w = r->p_o; // the physical boundary 44 | 45 | return 0; 46 | } 47 | /** 48 | * \brief get a character from ring buffer 49 | * \param r pointer to a ringbuf object 50 | * \param c read character 51 | * \return 0 if successfull, otherwise failed 52 | */ 53 | I16 RINGBUF_Get(RINGBUF *r, U8* c) 54 | { 55 | if(r->fill_cnt<=0)return -1; // ring buffer is empty, this should be atomic operation 56 | 57 | 58 | r->fill_cnt--; // decrease filled slots count 59 | 60 | 61 | *c = *r->p_r++; // get the character out 62 | 63 | if(r->p_r >= r->p_o + r->size) // rollback if write pointer go pass 64 | r->p_r = r->p_o; // the physical boundary 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /app/mqtt/ringbuf.h: -------------------------------------------------------------------------------- 1 | #ifndef _RING_BUF_H_ 2 | #define _RING_BUF_H_ 3 | 4 | #include 5 | #include 6 | #include "typedef.h" 7 | 8 | typedef struct{ 9 | U8* p_o; /**< Original pointer */ 10 | U8* volatile p_r; /**< Read pointer */ 11 | U8* volatile p_w; /**< Write pointer */ 12 | volatile I32 fill_cnt; /**< Number of filled slots */ 13 | I32 size; /**< Buffer size */ 14 | }RINGBUF; 15 | 16 | I16 RINGBUF_Init(RINGBUF *r, U8* buf, I32 size); 17 | I16 RINGBUF_Put(RINGBUF *r, U8 c); 18 | I16 RINGBUF_Get(RINGBUF *r, U8* c); 19 | #endif 20 | -------------------------------------------------------------------------------- /app/mqtt/typedef.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Standard Types definition 4 | */ 5 | 6 | #ifndef _TYPE_DEF_H_ 7 | #define _TYPE_DEF_H_ 8 | 9 | typedef char I8; 10 | typedef unsigned char U8; 11 | typedef short I16; 12 | typedef unsigned short U16; 13 | typedef long I32; 14 | typedef unsigned long U32; 15 | typedef unsigned long long U64; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /app/mqtt/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | #include "c_types.h" 5 | 6 | uint32_t UTILS_Atoh(const int8_t *s); 7 | uint8_t UTILS_StrToIP(const int8_t* str, void *ip); 8 | uint8_t UTILS_IsIPV4 (int8_t *str); 9 | #endif 10 | -------------------------------------------------------------------------------- /app/platform/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = libplatform.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | EXTRA_CCFLAGS += \ 29 | -DPING_RATE=$(PING_RATE) -DDEFAULT_MQTT_IP=$(DEFAULT_MQTT_IP) \ 30 | -DATMEGA_FLASH_MAX=$(ATMEGA_FLASH_MAX) -DRFM69_NODE_ID=$(RFM69_NODE_ID) \ 31 | -DRFM69_ENCRYPT_KEY=$(RFM69_ENCRYPT_KEY) -DRFM69_NET_ID=$(RFM69_NET_ID) \ 32 | -DRFM69_FREQ=$(RFM69_FREQ) -DRFM69_DEV_ID=$(RFM69_DEV_ID) \ 33 | -DSTA_PASS="$(STA_PASS)" -DSTA_SSID="$(STA_SSID)" \ 34 | -DVERSION="$(VERSION)" \ 35 | -DMQTT_HOST_NAME="$(MQTT_HOST_NAME)" -DMQTT_ENABLE=$(MQTT_ENABLE) \ 36 | -DMQTT_USE_IP=$(MQTT_USE_IP) 37 | 38 | ############################################################# 39 | # Recursion Magic - Don't touch this!! 40 | # 41 | # Each subtree potentially has an include directory 42 | # corresponding to the common APIs applicable to modules 43 | # rooted at that subtree. Accordingly, the INCLUDE PATH 44 | # of a module can only contain the include directories up 45 | # its parent path, and not its siblings 46 | # 47 | # Required for each makefile to inherit from the parent 48 | # 49 | 50 | INCLUDES := $(INCLUDES) -I $(PDIR)include 51 | INCLUDES += -I ./ 52 | INCLUDES += -I ../libc 53 | INCLUDES += -I ../spiffs 54 | INCLUDES += -I ../mqtt 55 | INCLUDES += -I ../ 56 | PDIR := ../$(PDIR) 57 | sinclude $(PDIR)Makefile 58 | -------------------------------------------------------------------------------- /app/platform/common.h: -------------------------------------------------------------------------------- 1 | // Common platform functions 2 | 3 | #ifndef __COMMON_H__ 4 | #define __COMMON_H__ 5 | 6 | #include "platform.h" 7 | 8 | // Functions exported by the common platform layer 9 | void cmn_platform_init(void); 10 | 11 | // Timer-specific functions 12 | 13 | // System timer generic implemenation 14 | 15 | // Filesystem-related functions 16 | 17 | #endif // #ifndef __COMMON_H__ 18 | -------------------------------------------------------------------------------- /app/platform/config.h: -------------------------------------------------------------------------------- 1 | // Common platform functions 2 | 3 | #ifndef __CONFIG_H__ 4 | #define __CONFIG_H__ 5 | 6 | #define MAGIC_NUM 0x1234 7 | 8 | typedef struct { 9 | uint8_t bridgeId; 10 | uint8_t deviceId; 11 | uint8_t netId; 12 | uint8_t freq; 13 | char key[17]; //hashable 14 | uint8_t block[3]; 15 | uint32_t magic; 16 | } RFM_CONF_T; 17 | 18 | typedef struct { 19 | char ssid[32]; //hashable 20 | char pass[64]; //hashable 21 | uint32_t magic; 22 | } WIFI_CONF_T; 23 | 24 | typedef struct { 25 | uint32_t endpt; 26 | char urlprefix[24];//hashable 27 | char urldomain[16];//hashable 28 | uint32_t magic; 29 | } HTTP_CONF_T; 30 | 31 | typedef enum { 32 | rfm_conf_type, 33 | wifi_conf_type, 34 | http_conf_type 35 | } config_type_t; 36 | 37 | int open_config_fd(config_type_t type, char rw); 38 | 39 | int fill_Rfm_Struct(void * root, void* conf, int fd); 40 | int fill_Wifi_Struct(void * root, void* conf, int fd); 41 | int fill_Http_Struct(void * root, void* conf, int fd); 42 | 43 | 44 | // RFM69 Configuration methods 45 | // RFM_CONF_T* get_rfm_conf(void); 46 | // WIFI_CONF_T* get_wifi_conf(void); 47 | // HTTP_CONF_T* get_http_conf(void); 48 | int get_config_ptr(void * conf, config_type_t type); 49 | 50 | int read_conf_from_fs(config_type_t type); 51 | 52 | // int read_rfmconf(int fd, char * jsonStr); 53 | // int read_wificonf(int fd, char * jsonStr); 54 | // int read_httpconf(int fd, char * jsonStr); 55 | int write_config_to_fs(void * conf, config_type_t type); 56 | 57 | // Timer-specific functions 58 | 59 | // System timer generic implemenation 60 | 61 | // Filesystem-related functions 62 | 63 | #endif // #ifndef __COMMON_H__ 64 | -------------------------------------------------------------------------------- /app/platform/cpu_esp8266.h: -------------------------------------------------------------------------------- 1 | #ifndef __CPU_ESP8266_H__ 2 | #define __CPU_ESP8266_H__ 3 | 4 | #include "os_type.h" 5 | #include "spi_flash.h" 6 | #include "user_config.h" 7 | #include "flash_api.h" 8 | 9 | #if defined(FLASH_512K) 10 | #define FLASH_SEC_NUM 0x80 // 4MByte: 0x400, 2MByte: 0x200, 1MByte: 0x100, 512KByte: 0x80 11 | #elif defined(FLASH_1M) 12 | #define FLASH_SEC_NUM 0x100 13 | #elif defined(FLASH_2M) 14 | #define FLASH_SEC_NUM 0x200 15 | #elif defined(FLASH_4M) 16 | #define FLASH_SEC_NUM 0x400 17 | #elif defined(FLASH_8M) 18 | #define FLASH_SEC_NUM 0x800 19 | #elif defined(FLASH_16M) 20 | #define FLASH_SEC_NUM 0x1000 21 | #elif defined(FLASH_AUTOSIZE) 22 | #if defined(FLASH_SAFE_API) 23 | #define FLASH_SEC_NUM (flash_safe_get_sec_num()) 24 | #else 25 | #define FLASH_SEC_NUM (flash_rom_get_sec_num()) 26 | #endif // defined(FLASH_SAFE_API) 27 | #else 28 | #define FLASH_SEC_NUM 0x80 29 | #endif 30 | #define SYS_PARAM_SEC_NUM 4 31 | #define SYS_PARAM_SEC_START (FLASH_SEC_NUM - SYS_PARAM_SEC_NUM) 32 | 33 | 34 | #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE 35 | // #define INTERNAL_FLASH_SECTOR_ARRAY { 0x4000, 0x4000, 0x4000, 0x4000, 0x10000, 0x20000, 0x20000, 0x20000, 0x20000, 0x20000 } 36 | #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4 37 | #define INTERNAL_FLASH_READ_UNIT_SIZE 4 38 | 39 | #define INTERNAL_FLASH_SIZE ( (SYS_PARAM_SEC_START) * INTERNAL_FLASH_SECTOR_SIZE ) 40 | #define INTERNAL_FLASH_MAPPED_ADDRESS 0x40200000 41 | 42 | #if defined(FLASH_SAFE_API) 43 | #define flash_write flash_safe_write 44 | #define flash_erase flash_safe_erase_sector 45 | #define flash_read flash_safe_read 46 | #else 47 | #define flash_write spi_flash_write 48 | #define flash_erase spi_flash_erase_sector 49 | #define flash_read spi_flash_read 50 | #endif // defined(FLASH_SAFE_API) 51 | 52 | #define CACHE_FLASH_CTRL_REG 0x3ff0000c 53 | #define CACHE_FLASH_ACTIVE 0x00000100 54 | #define CACHE_FLASH_MAPPED0 0x02000000 55 | #define CACHE_FLASH_MAPPED1 0x00010000 56 | 57 | #endif // #ifndef __CPU_ESP8266_H__ 58 | -------------------------------------------------------------------------------- /app/platform/event.h: -------------------------------------------------------------------------------- 1 | #ifndef __EVENT_H 2 | #define __EVENT_H 3 | 4 | uint8_t wifiStatus_mq; 5 | uint8_t lastwifiStatus_mq; 6 | 7 | enum { wifiIsDisconnected, wifiIsConnected, wifiGotIP }; 8 | enum { rfm_unknown, rfm_timed_out, rfm_connected }; 9 | 10 | typedef void(*WifiStateChangeCb)(uint8_t wifiStatus); 11 | 12 | 13 | void statusWifiUpdate(uint8_t state); 14 | void statusRfmUpdate(uint8_t state); 15 | 16 | void user_event_init(); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /app/platform/led.c: -------------------------------------------------------------------------------- 1 | #include "user_config.h" 2 | #include "led.h" 3 | #include "c_stdio.h" 4 | #include "c_stdlib.h" 5 | #include "c_types.h" 6 | #include "user_interface.h" 7 | 8 | #include "driver/gpio16.h" 9 | 10 | #define WIFI_LED_PIN_NUM 3 //GPIO0 11 | #define RFM_LED_PIN_NUM 1 //GPIO5 12 | 13 | // Timers 14 | static ETSTimer wifiLedTimer; 15 | static ETSTimer rfmLedTimer; 16 | 17 | static uint8_t wifiLedState = 0; 18 | static uint8_t rfmLedState = 0; 19 | 20 | 21 | // Set the LED on or off, respecting the defined polarity 22 | static void setLed(int on, int8_t pin) 23 | { 24 | if (pin < 0) return; // disabled 25 | // LED is active-low 26 | if (on) { gpio_write(pin, on); } 27 | else { gpio_write(pin, 0); } 28 | } 29 | 30 | // Timer callback to update WiFi status LED 31 | static void wifiLedTimerCb(void *v) 32 | { 33 | int time = 1000; 34 | #if 0 35 | if (wifiState == wifi_gotip) 36 | { 37 | // connected, all is good, solid light with a short dark blip every 3 seconds 38 | wifiLedState = 1; 39 | time = 15000; 40 | } 41 | else if (wifiState == wifi_isconn) 42 | { 43 | // waiting for DHCP, go on/off every second 44 | wifiLedState = 1 - wifiLedState; 45 | time = 1000; 46 | } 47 | else 48 | { 49 | // not connected 50 | switch (wifi_get_opmode()) 51 | { 52 | case 1: // STA 53 | wifiLedState = 0; 54 | break; 55 | case 2: // AP 56 | wifiLedState = 1-wifiLedState; 57 | time = wifiLedState ? 50 : 1950; 58 | break; 59 | case 3: // STA+AP 60 | wifiLedState = 1-wifiLedState; 61 | time = wifiLedState ? 50 : 950; 62 | break; 63 | } 64 | } 65 | #endif 66 | setLed(wifiLedState, WIFI_LED_PIN_NUM); 67 | os_timer_arm(&wifiLedTimer, time, 0); 68 | } 69 | 70 | // Timer callback to update RFM69 status LED 71 | static void rfmLedTimerCb(void *v) 72 | { 73 | int time = 1000; 74 | #if 0 75 | if (rfmState == rfm_unknown) 76 | { 77 | // connected, all is good, solid light with a short dark blip every 3 seconds 78 | rfmLedState = 1-rfmLedState; 79 | time = rfmLedState ? 2900 : 1200; 80 | } 81 | else if (rfmState == rfm_connected) 82 | { 83 | // waiting for DHCP, go on/off every second 84 | rfmLedState = 1; 85 | time = 10001; 86 | } 87 | else 88 | { 89 | // not connected 90 | rfmLedState = 1-rfmLedState; 91 | time = rfmLedState ? 950 : 1950; 92 | } 93 | #endif 94 | setLed(rfmLedState, RFM_LED_PIN_NUM); 95 | os_timer_arm(&rfmLedTimer, time, 0); 96 | } 97 | 98 | void ledInit(void) 99 | { 100 | STATUS_DBG("CONN led=%d\n", 1); 101 | 102 | os_timer_disarm(&wifiLedTimer); 103 | os_timer_setfn(&wifiLedTimer, wifiLedTimerCb, NULL); 104 | os_timer_arm(&wifiLedTimer, 2003, 0); 105 | 106 | os_timer_disarm(&rfmLedTimer); 107 | os_timer_setfn(&rfmLedTimer, rfmLedTimerCb, NULL); 108 | os_timer_arm(&rfmLedTimer, 5517, 0); 109 | 110 | } 111 | -------------------------------------------------------------------------------- /app/platform/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H__ 2 | #define __LED_H__ 3 | #include "c_types.h" 4 | 5 | void ledInit(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /app/platform/platform.c: -------------------------------------------------------------------------------- 1 | // Platform-dependent functions 2 | #include "platform.h" 3 | #include "common.h" 4 | #include "c_stdio.h" 5 | #include "c_stdlib.h" 6 | #include "gpio.h" 7 | #include "user_interface.h" 8 | #include "driver/uart.h" 9 | 10 | void output_redirect(const char *str){ 11 | 12 | #ifdef DEVELOP_VERSION 13 | uart_write_string(0,str); 14 | #endif 15 | } 16 | 17 | int platform_init() 18 | { 19 | cmn_platform_init(); 20 | // All done 21 | return PLATFORM_OK; 22 | } 23 | 24 | // **************************************************************************** 25 | // UART 26 | // TODO: Support timeouts. 27 | 28 | // Send: version with and without mux 29 | void platform_uart_send( unsigned id, u8 data) 30 | { 31 | uart_write_char(id, data); 32 | } 33 | 34 | // **************************************************************************** 35 | // Flash access functions 36 | 37 | /* 38 | * Assumptions: 39 | * > toaddr is INTERNAL_FLASH_WRITE_UNIT_SIZE aligned 40 | * > size is a multiple of INTERNAL_FLASH_WRITE_UNIT_SIZE 41 | */ 42 | uint32_t platform_s_flash_write( const void *from, uint32_t toaddr, uint32_t size ) 43 | { 44 | SpiFlashOpResult r; 45 | const uint32_t blkmask = INTERNAL_FLASH_WRITE_UNIT_SIZE - 1; 46 | uint32_t *apbuf = NULL; 47 | uint32_t fromaddr = (uint32_t)from; 48 | if( (fromaddr & blkmask ) || (fromaddr >= INTERNAL_FLASH_MAPPED_ADDRESS)) { 49 | apbuf = (uint32_t *)c_malloc(size); 50 | if(!apbuf) 51 | return 0; 52 | memcpy(apbuf, from, size); 53 | } 54 | system_soft_wdt_feed (); 55 | r = flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size); 56 | if(apbuf) 57 | c_free(apbuf); 58 | if(SPI_FLASH_RESULT_OK == r) 59 | return size; 60 | else{ 61 | NODE_ERR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr); 62 | return 0; 63 | } 64 | } 65 | 66 | /* 67 | * Assumptions: 68 | * > fromaddr is INTERNAL_FLASH_READ_UNIT_SIZE aligned 69 | * > size is a multiple of INTERNAL_FLASH_READ_UNIT_SIZE 70 | */ 71 | uint32_t platform_s_flash_read( void *to, uint32_t fromaddr, uint32_t size ) 72 | { 73 | if (size==0) 74 | return 0; 75 | 76 | SpiFlashOpResult r; 77 | system_soft_wdt_feed (); 78 | 79 | const uint32_t blkmask = (INTERNAL_FLASH_READ_UNIT_SIZE - 1); 80 | if( ((uint32_t)to) & blkmask ) 81 | { 82 | uint32_t size2=size-INTERNAL_FLASH_READ_UNIT_SIZE; 83 | uint32* to2=(uint32*)((((uint32_t)to)&(~blkmask))+INTERNAL_FLASH_READ_UNIT_SIZE); 84 | r = flash_read(fromaddr, to2, size2); 85 | if(SPI_FLASH_RESULT_OK == r) 86 | { 87 | os_memmove(to,to2,size2); 88 | char back[ INTERNAL_FLASH_READ_UNIT_SIZE ] __attribute__ ((aligned(INTERNAL_FLASH_READ_UNIT_SIZE))); 89 | r=flash_read(fromaddr+size2,(uint32*)back,INTERNAL_FLASH_READ_UNIT_SIZE); 90 | os_memcpy((uint8_t*)to+size2,back,INTERNAL_FLASH_READ_UNIT_SIZE); 91 | } 92 | } 93 | else 94 | r = flash_read(fromaddr, (uint32 *)to, size); 95 | 96 | if(SPI_FLASH_RESULT_OK == r) 97 | return size; 98 | else{ 99 | NODE_ERR( "ERROR in flash_read: r=%d at %08X\n", ( int )r, ( unsigned )fromaddr); 100 | return 0; 101 | } 102 | } 103 | 104 | int platform_flash_erase_sector( uint32_t sector_id ) 105 | { 106 | system_soft_wdt_feed (); 107 | return flash_erase( sector_id ) == SPI_FLASH_RESULT_OK ? PLATFORM_OK : PLATFORM_ERR; 108 | } 109 | 110 | uint32_t platform_flash_mapped2phys (uint32_t mapped_addr) 111 | { 112 | uint32_t cache_ctrl = READ_PERI_REG(CACHE_FLASH_CTRL_REG); 113 | if (!(cache_ctrl & CACHE_FLASH_ACTIVE)) 114 | return -1; 115 | bool b0 = (cache_ctrl & CACHE_FLASH_MAPPED0) ? 1 : 0; 116 | bool b1 = (cache_ctrl & CACHE_FLASH_MAPPED1) ? 1 : 0; 117 | uint32_t meg = (b1 << 1) | b0; 118 | return mapped_addr - INTERNAL_FLASH_MAPPED_ADDRESS + meg * 0x100000; 119 | } 120 | -------------------------------------------------------------------------------- /app/rfm/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = rfm.a 16 | endif 17 | 18 | STD_CFLAGS=-std=gnu11 -Wimplicit 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | #DEFINES += 28 | EXTRA_CCFLAGS += \ 29 | -DPING_RATE=$(PING_RATE) -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \ 30 | -DRFM69_NODE_ID=$(RFM69_NODE_ID) -DRFM69_NET_ID=$(RFM69_NET_ID) \ 31 | -DRFM69_FREQ=$(RFM69_FREQ) -DRFM69_DEV_ID=$(RFM69_DEV_ID) \ 32 | -DMQTT_ENABLE=$(MQTT_ENABLE) 33 | 34 | ############################################################# 35 | # Recursion Magic - Don't touch this!! 36 | # 37 | # Each subtree potentially has an include directory 38 | # corresponding to the common APIs applicable to modules 39 | # rooted at that subtree. Accordingly, the INCLUDE PATH 40 | # of a module can only contain the include directories up 41 | # its parent path, and not its siblings 42 | # 43 | # Required for each makefile to inherit from the parent 44 | # 45 | 46 | INCLUDES := $(INCLUDES) -I $(PDIR)include 47 | INCLUDES += -I ./ 48 | INCLUDES += -I ../libc 49 | INCLUDES += -I ../ 50 | PDIR := ../$(PDIR) 51 | sinclude $(PDIR)Makefile 52 | -------------------------------------------------------------------------------- /app/rfm/app.c: -------------------------------------------------------------------------------- 1 | #include "user_interface.h" 2 | #include "c_types.h" 3 | #include "c_stdio.h" 4 | #include "mem.h" 5 | #include "osapi.h" 6 | 7 | #include "user_config.h" 8 | #include "platform/config.h" 9 | #include "driver/rfm69.h" 10 | #include "radiohandler.h" 11 | #include "util/cbuff.h" 12 | 13 | /* RX Buffer Size - 128 == 2+ packets */ 14 | #define RFM_RX_BUFFSIZE 128 15 | 16 | /* TX Buffer Size - 256 == 4+ packets */ 17 | #define RFM_TX_BUFFSIZE 256 18 | 19 | static RFM_Handle rfm_handle_base; 20 | 21 | CBUFFOBJ rxBuffObj; 22 | CBUFF rxBuff[RFM_RX_BUFFSIZE]; 23 | 24 | CBUFFOBJ txBuffObj; 25 | CBUFF txBuff[RFM_TX_BUFFSIZE]; 26 | 27 | bool init_rfm_handler() 28 | { 29 | int ret = 0; 30 | RFM_Handle * rfm_ptr = &rfm_handle_base; 31 | cbuffInit(); 32 | 33 | memset(rfm_ptr, 0, sizeof(rfm_handle_base)); 34 | 35 | rfm_handle_base.rxBuffNum = cbuffCreate(rxBuff, RFM_RX_BUFFSIZE, &rxBuffObj); 36 | rfm_handle_base.txBuffNum = cbuffCreate(txBuff, RFM_TX_BUFFSIZE, &txBuffObj); 37 | 38 | if (rfm_handle_base.rxBuffNum == 0 || rfm_handle_base.txBuffNum == 0) { 39 | NODE_ERR("Error creating rfm cbuff(s)\n"); 40 | } else { 41 | NODE_DBG("cbuff tx Id=%d, rx = %d\n", rfm_handle_base.txBuffNum, rfm_handle_base.rxBuffNum); 42 | } 43 | 44 | uint8_t thisNodeId, thisNetId; 45 | RFM_CONF_T dummy; 46 | RFM_CONF_T * rfmConfPtr = &dummy; 47 | ret = get_config_ptr((void *)rfmConfPtr, rfm_conf_type); 48 | if (ret > 0) 49 | { 50 | NODE_DBG("Loaded rfm info: Id=%d, netId = %d\n", rfmConfPtr->bridgeId, rfmConfPtr->netId); 51 | thisNodeId = rfmConfPtr->bridgeId; 52 | thisNetId = rfmConfPtr->netId; 53 | } else { 54 | thisNodeId = RFM69_NODE_ID; 55 | thisNetId = RFM69_NET_ID; 56 | NODE_DBG("Error loading rfm.conf\n"); 57 | } 58 | 59 | // rfm_handle_base.msgCb = rfm_callback; 60 | rfm_handle_base.nodeId = thisNodeId; 61 | rfm_handle_base.msgCb = NULL; 62 | rfm_handle_base.state = RFM_IDLE; 63 | rfm_handle_base.keepAliveTick = 20; //20 ms default 64 | rfm_handle_base.sendTimeout = 1000; //1 sec default 65 | rfm_handle_base.options = RFM_OUTPUT_ALL; 66 | 67 | ret = rfm69_spi_init(); 68 | if (ret == RFM_SPI_OK) 69 | { 70 | NODE_DBG("RFM69 SPI Initialized\n"); 71 | ret = rfm69_init(rfm_ptr, thisNodeId, thisNetId); 72 | if (ret == RFM_INIT_OK) 73 | { 74 | NODE_DBG("RFM69 listening on address %d...\n", thisNodeId); 75 | radioHandlerInit(rfm_ptr); 76 | return true; 77 | } 78 | } 79 | 80 | NODE_DBG("Error: RFM init returned %d\n", ret); 81 | return false; 82 | } 83 | -------------------------------------------------------------------------------- /app/rfm/app.h: -------------------------------------------------------------------------------- 1 | #ifndef __RFM_H 2 | #define __RFM_H 3 | 4 | bool init_rfm_handler(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/rfm/radiohandler.h: -------------------------------------------------------------------------------- 1 | #ifndef RADIOHANDLER_H 2 | #define RADIOHANDLER_H 3 | 4 | #include "user_config.h" 5 | #include "osapi.h" 6 | #include "rfm.h" 7 | #include "rfm_parser.h" 8 | 9 | #define BUF_MAX (128) //max size of console.html log 10 | 11 | typedef struct { 12 | uint16_t freq; 13 | int16_t rssi; 14 | int16_t batt; 15 | uint8_t axis; 16 | uint32_t totalct; 17 | } RadioStatus; 18 | 19 | enum { radioUnknown, radioIsDisconnected, radioIsConnected}; 20 | uint8_t radioState; 21 | 22 | char console_buf[BUF_MAX]; 23 | int console_wr; 24 | int console_rd; 25 | int console_pos; 26 | 27 | void console_write_char(char c); 28 | void console_write_string(char* buff, int len); 29 | 30 | // void generateRfmTxMsg(int toId, int requestAck, void* data, int len); 31 | void generateRfmTxMsg(int toId, void* data, int len, bool requestAck, bool sendACK); 32 | void disableSendTimers(); 33 | 34 | void rfm_begin_ota(char * binName, uint8_t nid); 35 | void rfm_end_ota(); 36 | 37 | void process_rfm_ota_msg(RFM_Handle * r); 38 | void generate_next_OTA_msg(); 39 | 40 | void rfmSendTimerCb(void *v); 41 | void radioHandlerInit(RFM_Handle * r); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /app/rfm/rfm.h: -------------------------------------------------------------------------------- 1 | #ifndef __RFM_H 2 | #define __RFM_H 3 | 4 | #include "c_types.h" 5 | #include "osapi.h" 6 | #include "ets_sys.h" 7 | #include "user_interface.h" 8 | 9 | #define RFM_OUTPUT_ALL (1<<7) 10 | #define RFM_PROMISCUOUS (1<<6) 11 | 12 | #define RF69_MAX_DATA_LEN 61 13 | 14 | /* callback function (currently unused) */ 15 | typedef void (*RfmMsgCallback)(uint32_t *args); 16 | 17 | void rfm_set_promiscuous(bool onoff); 18 | void rfm_toggle_all_output(void); 19 | 20 | /* Various init return codes */ 21 | typedef enum { 22 | RFM_INVALID, 23 | RFM_SPI_OK, 24 | RFM_INIT_OK, 25 | RFM_KEY_OK, 26 | RFM_GPIO_SET_INTR_ERR, 27 | RFM_GPIO_SET_ERR, 28 | RFM_SPI_ERR, 29 | RFM_INV_KEY_LEN, 30 | RFM_KEY_ERR 31 | } rfm_retcode_t; 32 | 33 | /* RFM69 driver operating modes */ 34 | typedef enum { 35 | RF69_OP_SLEEP, // XTAL OFF 36 | RF69_OP_STANDBY, // XTAL ON 37 | RF69_OP_SYNTH, // PLL ON 38 | RF69_OP_RX, // RX MODE 39 | RF69_OP_TX, // TX MODE 40 | RF69_OP_NONE // NONE 41 | } RFM69_OP_MODE; 42 | 43 | /* Simplifies accessing pkt headers */ 44 | typedef union { 45 | uint32 data; 46 | struct { 47 | uint8 CTLBYTE; 48 | uint8 SENDERID; 49 | uint8 TARGETID; 50 | uint8 PAYLOADLEN; 51 | } get; 52 | } RFM_HEADER_T; 53 | 54 | /* App state */ 55 | typedef enum { 56 | RFM_IDLE, 57 | RFM_RX_BUFF_READY, 58 | RFM_TX_BEGIN, 59 | RFM_TX_WAIT, 60 | RFM_FIFO_WRITE, 61 | RFM_TX_SENT, 62 | RFM_ERROR 63 | } RFM_APP_STATE; 64 | 65 | /* OTA state */ 66 | typedef enum { 67 | RFM_OTA_IDLE, 68 | RFM_OTA_INIT, 69 | RFM_OTA_NEXT, 70 | RFM_OTA_LAST, 71 | RFM_OTA_DONE, 72 | RFM_OTA_ERROR 73 | } RFM_OTA_STATE; 74 | 75 | /* Driver structure 76 | * Contains almost everything needed by driver to operate * 77 | * with the expection of rx buffer aka PAYLOAD which is shared * 78 | * and located in RFM_Handle struct. OUTBUFF is present instead of * 79 | * using txbuff to allow for send retries without having to roll back * 80 | * txbuff, as a retry is a fairly common occurence. */ 81 | typedef struct { 82 | RFM69_OP_MODE curr_mode; 83 | RFM69_OP_MODE next_mode; //TODO use this to impl. timers 84 | 85 | uint8_t DATALEN; 86 | uint8_t SENDERID; 87 | uint8_t TARGETID; // should match ress 88 | uint8_t PAYLOADLEN; 89 | uint8_t ACK_REQUESTED; 90 | uint8_t ACK_RECEIVED; // should be polled immediately after sending a packet with ACK request 91 | int16_t RSSI; 92 | 93 | uint8_t OUTBUFF[66]; // Contains entire packet (data+headers) 94 | uint8_t OUTBUFFLEN; // Length of entire packet, including payloadlen, so this 95 | // should always be == OUTBUFF[0] + 1 96 | } RFM69_DRIVER; 97 | 98 | /* OTA structure 99 | * Contains OTA Update info, including SPIFFS object and * 100 | * with the expection of rx buffer aka PAYLOAD which is shared * 101 | * and located in RFM_Handle struct. OUTBUFF is present instead of * 102 | * using txbuff to allow for send retries without having to roll back * 103 | * txbuff, as a retry is a fairly common occurence. */ 104 | typedef struct { 105 | uint8_t state; 106 | uint8_t outBuffFilled; 107 | uint8_t nodeid; 108 | uint8_t isEOF; 109 | uint8_t retries; 110 | uint16_t seq; 111 | uint16_t prevSeq; 112 | uint32_t timeout; 113 | uint32_t fsPos; 114 | struct fs_file_st * fs_st; 115 | uint8_t fs_buff[256]; 116 | } RFM69_OTA_T; 117 | 118 | /* Handle structure 119 | * Main data structure for driver */ 120 | typedef struct { 121 | RFM_APP_STATE state; 122 | RFM69_DRIVER driver; 123 | RFM69_OTA_T * ota; 124 | uint8_t nodeId; 125 | uint32_t options; 126 | //RfmFwCallback fwCb; 127 | RfmMsgCallback msgCb; 128 | os_timer_t tickTimer; 129 | uint32_t keepAliveTick; 130 | uint32_t sendTimeout; 131 | int error_msg; 132 | 133 | /* Cbuff refs */ 134 | unsigned int txBuffNum; 135 | unsigned int rxBuffNum; 136 | } RFM_Handle; 137 | 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /app/rfm/rfm_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef RFM_PARSER_H 2 | #define RFM_PARSER_H 3 | #include "c_types.h" 4 | #include "rfm.h" 5 | #include "radiohandler.h" 6 | 7 | typedef void (*live_data_callback)(int x, int y, int z); //callback function 8 | 9 | void live_data_register_listener(live_data_callback f); 10 | 11 | void live_event(uint32 stamp, uint8* buf, int len); 12 | void default_event(uint32 stamp, uint8* buf, int len); 13 | 14 | uint8_t serverCodeLUT(char fn_type, uint8_t indexedVal); 15 | 16 | void process_rfm_msg(RFM_Handle *rfm, uint32 stamp); 17 | 18 | extern uint8_t rfm_queue_t; 19 | int txTotal; 20 | int rxTotal; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /app/smart/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = smart.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | ############################################################# 29 | # Recursion Magic - Don't touch this!! 30 | # 31 | # Each subtree potentially has an include directory 32 | # corresponding to the common APIs applicable to modules 33 | # rooted at that subtree. Accordingly, the INCLUDE PATH 34 | # of a module can only contain the include directories up 35 | # its parent path, and not its siblings 36 | # 37 | # Required for each makefile to inherit from the parent 38 | # 39 | 40 | INCLUDES := $(INCLUDES) -I $(PDIR)include 41 | INCLUDES += -I ./ 42 | INCLUDES += -I ../libc 43 | PDIR := ../$(PDIR) 44 | sinclude $(PDIR)Makefile 45 | -------------------------------------------------------------------------------- /app/smart/smart.h: -------------------------------------------------------------------------------- 1 | #ifndef _SMART_H 2 | #define _SMART_H 1 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | #define MAX_CHANNEL 14 8 | 9 | #define TYPE_SUBTYPE_QOS_DATA 0x88 10 | #define TYPE_SUBTYPE_MASK 0xFC 11 | 12 | #define NO_RETRY 0x41 13 | #define DS_RETRY_MASK 0x4B 14 | 15 | #define BSSID_ADDR 4 16 | #define SOURCE_ADDR 10 17 | #define DEST_ADDR 16 18 | #define ADDR_LENGTH 6 19 | #define ADDR_MATCH_START (SOURCE_ADDR) 20 | #define ADDR_MATCH_LENGTH (ADDR_LENGTH*2) 21 | 22 | #define SEQ_ADDR 22 23 | #define SEQ_LEN 2 24 | #define SEQ_MAX 0x1000 25 | 26 | #define BASE_LENGTH 82 27 | 28 | 29 | #define SSID_FLAG 1399 30 | #define PWD_FLAG 1459 31 | #define L_FLAG 28 32 | #define C_FLAG 593 33 | #define SEP_1 3 34 | #define SEP_2 23 35 | #define SEP_3 24 36 | #define SEP_4 25 37 | #define SEP_5 26 38 | #define SEP_NUM 2 39 | 40 | #define NIBBLE_PER_BYTE 2 41 | 42 | #define SEP_1_INDEX 2 43 | 44 | #if(SEP_1_INDEX==0) 45 | #define FLAG_NUM (SEP_NUM+1) 46 | #elif(SEP_1_INDEX==2) 47 | #define FLAG_NUM (SEP_NUM+2) 48 | #endif 49 | #define FLAG_MATCH_NUM (FLAG_NUM-1) // only need to match 2 or 3 byte to increase speed. 50 | 51 | // #define TI_SMARTCONFIG 1 52 | 53 | #define SSID_NIBBLE_MAX (32*NIBBLE_PER_BYTE) 54 | #define PWD_NIBBLE_MAX (64*NIBBLE_PER_BYTE) 55 | #define SSID_BIT_MAX (SSID_NIBBLE_MAX/8) 56 | #define PWD_BIT_MAX (PWD_NIBBLE_MAX/8) 57 | 58 | #define TIME_OUT_PER_CHANNEL (30*1000) 59 | 60 | #define STATION_CHECK_TIME (2*1000) 61 | 62 | struct RxControl{ 63 | signed rssi:8;//表示该包的信号强度 64 | unsigned rate:4; 65 | unsigned is_group:1; 66 | unsigned:1; 67 | unsigned sig_mode:2;//表示该包是否是11n 的包,0 表示非11n,非0 表示11n 68 | unsigned legacy_length:12;//如果不是11n 的包,它表示包的长度 69 | unsigned damatch0:1; 70 | unsigned damatch1:1; 71 | unsigned bssidmatch0:1; 72 | unsigned bssidmatch1:1; 73 | unsigned MCS:7;//如果是11n 的包,它表示包的调制编码序列,有效值:0-76 74 | unsigned CWB:1;//如果是11n 的包,它表示是否为HT40 的包 75 | unsigned HT_length:16;//如果是11n 的包,它表示包的长度 76 | unsigned Smoothing:1; 77 | unsigned Not_Sounding:1; 78 | unsigned:1; 79 | unsigned Aggregation:1; 80 | unsigned STBC:2; 81 | unsigned FEC_CODING:1;//如果是11n 的包,它表示是否为LDPC 的包 82 | unsigned SGI:1; 83 | unsigned rxend_state:8; 84 | unsigned ampdu_cnt:8; 85 | unsigned channel:4;//表示该包所在的信道 86 | unsigned:12; 87 | }; 88 | 89 | struct sniffer_buf{ 90 | struct RxControl rx_ctrl; // 12-bytes 91 | u8 buf[48];//包含ieee80211 包头 92 | u16 cnt;//包的个数 93 | u16 len[1];//包的长度 94 | }; 95 | 96 | struct _my_addr_map { 97 | uint8 addr[ADDR_LENGTH*3]; 98 | uint8_t addr_len; 99 | uint16_t base_len; 100 | int16_t flag[FLAG_NUM]; 101 | // flag[0]: SEP_1, flag[1]: SEP_2, flag[1]: SSID_FLAG. SEP followed by SSID_FLAG formed flag[] 102 | // if flag[i]==0, means skip this flag match, eg. SSID_FLAG, 0, SEP_1, SEP_2 103 | uint8_t flag_match_num; 104 | int16_t cur_base_seq; 105 | int8_t base_seq_valid; 106 | int8_t ssid_len; 107 | int8_t pwd_len; 108 | }; 109 | 110 | typedef struct _my_addr_map smart_addr_map; 111 | 112 | typedef void (* smart_succeed)(void *arg); 113 | 114 | void smart_begin(int chnl, smart_succeed s, void *arg); 115 | void station_check_connect(bool smart); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /app/spiffs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = spiffs.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | EXTRA_CCFLAGS += \ 27 | -DSPIFFS_ADDR=$(SPIFFS_ADDR) 28 | 29 | ############################################################# 30 | # Recursion Magic - Don't touch this!! 31 | # 32 | # Each subtree potentially has an include directory 33 | # corresponding to the common APIs applicable to modules 34 | # rooted at that subtree. Accordingly, the INCLUDE PATH 35 | # of a module can only contain the include directories up 36 | # its parent path, and not its siblings 37 | # 38 | # Required for each makefile to inherit from the parent 39 | # 40 | 41 | INCLUDES := $(INCLUDES) -I $(PDIR)include 42 | INCLUDES += -I ./ 43 | INCLUDES += -I ../libc 44 | INCLUDES += -I ../platform 45 | PDIR := ../$(PDIR) 46 | sinclude $(PDIR)Makefile 47 | -------------------------------------------------------------------------------- /app/spiffs/docs/IMPLEMENTING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/app/spiffs/docs/IMPLEMENTING -------------------------------------------------------------------------------- /app/spiffs/docs/TODO: -------------------------------------------------------------------------------- 1 | * When mending lost pages, also see if they fit into length specified in object index header -------------------------------------------------------------------------------- /app/spiffs/test/esp-ginx-fs-test.c: -------------------------------------------------------------------------------- 1 | const char *t_file_list[] = 2 | { 3 | "index.html", 4 | "ui.js", 5 | "favicon.ico", 6 | "console.html", 7 | "console.js", 8 | "log.html", 9 | "wifi.html", 10 | "wifi.js", 11 | "icons.png", 12 | "style.css", 13 | "pure.css" 14 | }; 15 | 16 | //put this in the heap timer or similar to check file output. prints bytes 17 | static int fsCheckCount = -1; 18 | 19 | fsCheckCount++; 20 | 21 | if ( fsCheckCount > 10) { return;} 22 | int i; 23 | int test_fd = fs_open(t_file_list[fsCheckCount], SPIFFS_RDONLY); 24 | 25 | if (test_fd < 0) 26 | { 27 | NODE_DBG("bad file? %s \n",t_file_list[fsCheckCount]); 28 | test_fd = 0; 29 | } else { 30 | int ret = -1; 31 | int res = 0; 32 | 33 | NODE_DBG(" %s OK \n",t_file_list[fsCheckCount]); 34 | 35 | //seek to eof 36 | res = fs_seek(test_fd, 0, FS_SEEK_END); 37 | if (res < 0) { fs_close(test_fd); } 38 | NODE_DBG("fs_seek res = %d\n", res); 39 | 40 | //get size 41 | int size = res; 42 | 43 | if (res < 1460) 44 | { 45 | size = res; 46 | } 47 | 48 | //reset cursor 49 | res = fs_seek(test_fd, 0, FS_SEEK_SET); 50 | if (res < 0) { fs_close(test_fd); test_fd = 0; NODE_DBG("\t\tres = %d\n", res); } 51 | fs_close(test_fd); 52 | 53 | int toRead = size; 54 | 55 | test_fd = fs_open(t_file_list[fsCheckCount], SPIFFS_RDONLY); 56 | if (test_fd < 0) 57 | { 58 | NODE_DBG("bad file? %s \n",t_file_list[fsCheckCount]); 59 | test_fd = 0; 60 | return; 61 | } 62 | 63 | while (toRead > 0) 64 | { 65 | int len = 1460; 66 | if (toRead < 1460) 67 | { 68 | len = toRead; 69 | } 70 | 71 | NODE_DBG("Read len = %d\n", len); 72 | // if (len%4 > 0) { len+= (4-(len%4)); } 73 | // NODE_DBG("Read fixed = %d\n", len); 74 | char * tbuff = (char*)os_zalloc(len+1); 75 | tbuff[len] = 0; 76 | 77 | //read 78 | ret = fs_read(test_fd, tbuff, len); 79 | if (ret < 0) { fs_close(test_fd); NODE_DBG("err reading 1st\n"); fs_close(test_fd); break; } 80 | NODE_DBG("Begin data:\n"); 81 | for (i=0;i 3 | 4 | int main(int argc, char **args) { 5 | run_tests(argc, args); 6 | exit(EXIT_SUCCESS); 7 | } 8 | -------------------------------------------------------------------------------- /app/spiffs/test/params_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * params_test.h 3 | * 4 | * Created on: May 26, 2013 5 | * Author: petera 6 | */ 7 | 8 | #ifndef PARAMS_TEST_H_ 9 | #define PARAMS_TEST_H_ 10 | 11 | // total emulated spi flash size 12 | #define PHYS_FLASH_SIZE (16*1024*1024) 13 | // spiffs file system size 14 | #define SPIFFS_FLASH_SIZE (2*1024*1024) 15 | // spiffs file system offset in emulated spi flash 16 | #define SPIFFS_PHYS_ADDR (4*1024*1024) 17 | 18 | #define SECTOR_SIZE 65536 19 | #define LOG_BLOCK (SECTOR_SIZE*2) 20 | #define LOG_PAGE (SECTOR_SIZE/256) 21 | 22 | #define FD_BUF_SIZE 64*6 23 | #define CACHE_BUF_SIZE (LOG_PAGE + 32)*8 24 | 25 | #define ASSERT(c, m) real_assert((c),(m), __FILE__, __LINE__); 26 | 27 | typedef signed int s32_t; 28 | typedef unsigned int u32_t; 29 | typedef signed short s16_t; 30 | typedef unsigned short u16_t; 31 | typedef signed char s8_t; 32 | typedef unsigned char u8_t; 33 | 34 | void real_assert(int c, const char *n, const char *file, int l); 35 | 36 | #endif /* PARAMS_TEST_H_ */ 37 | -------------------------------------------------------------------------------- /app/spiffs/test/test_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * test_dev.c 3 | * 4 | * Created on: Jul 14, 2013 5 | * Author: petera 6 | */ 7 | 8 | 9 | #include "testrunner.h" 10 | #include "test_spiffs.h" 11 | #include "spiffs_nucleus.h" 12 | #include "spiffs.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | SUITE(dev_tests) 21 | void setup() { 22 | _setup(); 23 | } 24 | void teardown() { 25 | _teardown(); 26 | } 27 | 28 | TEST(interrupted_write) { 29 | char *name = "interrupt"; 30 | char *name2 = "interrupt2"; 31 | int res; 32 | spiffs_file fd; 33 | 34 | const u32_t sz = SPIFFS_CFG_LOG_PAGE_SZ(FS)*8; 35 | u8_t *buf = malloc(sz); 36 | memrand(buf, sz); 37 | 38 | printf(" create reference file\n"); 39 | fd = SPIFFS_open(FS, name, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); 40 | TEST_CHECK(fd > 0); 41 | clear_flash_ops_log(); 42 | res = SPIFFS_write(FS, fd, buf, sz); 43 | TEST_CHECK(res >= 0); 44 | SPIFFS_close(FS, fd); 45 | 46 | u32_t written = get_flash_ops_log_write_bytes(); 47 | printf(" written bytes: %i\n", written); 48 | 49 | 50 | printf(" create error file\n"); 51 | fd = SPIFFS_open(FS, name2, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0); 52 | TEST_CHECK(fd > 0); 53 | clear_flash_ops_log(); 54 | invoke_error_after_write_bytes(written/2, 0); 55 | res = SPIFFS_write(FS, fd, buf, sz); 56 | SPIFFS_close(FS, fd); 57 | TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_TEST); 58 | 59 | clear_flash_ops_log(); 60 | 61 | #if SPIFFS_CACHE 62 | // delete all cache 63 | spiffs_cache *cache = spiffs_get_cache(FS); 64 | cache->cpage_use_map = 0; 65 | #endif 66 | 67 | 68 | printf(" read error file\n"); 69 | fd = SPIFFS_open(FS, name2, SPIFFS_RDONLY, 0); 70 | TEST_CHECK(fd > 0); 71 | 72 | spiffs_stat s; 73 | res = SPIFFS_fstat(FS, fd, &s); 74 | TEST_CHECK(res >= 0); 75 | printf(" file size: %i\n", s.size); 76 | 77 | if (s.size > 0) { 78 | u8_t *buf2 = malloc(s.size); 79 | res = SPIFFS_read(FS, fd, buf2, s.size); 80 | TEST_CHECK(res >= 0); 81 | 82 | u32_t ix = 0; 83 | for (ix = 0; ix < s.size; ix += 16) { 84 | int i; 85 | printf(" "); 86 | for (i = 0; i < 16; i++) { 87 | printf("%02x", buf[ix+i]); 88 | } 89 | printf(" "); 90 | for (i = 0; i < 16; i++) { 91 | printf("%02x", buf2[ix+i]); 92 | } 93 | printf("\n"); 94 | } 95 | free(buf2); 96 | } 97 | SPIFFS_close(FS, fd); 98 | 99 | 100 | printf(" FS check\n"); 101 | SPIFFS_check(FS); 102 | 103 | printf(" read error file again\n"); 104 | fd = SPIFFS_open(FS, name2, SPIFFS_APPEND | SPIFFS_RDWR, 0); 105 | TEST_CHECK(fd > 0); 106 | res = SPIFFS_fstat(FS, fd, &s); 107 | TEST_CHECK(res >= 0); 108 | printf(" file size: %i\n", s.size); 109 | printf(" write file\n"); 110 | res = SPIFFS_write(FS, fd, buf, sz); 111 | TEST_CHECK(res >= 0); 112 | SPIFFS_close(FS, fd); 113 | 114 | free(buf); 115 | 116 | return TEST_RES_OK; 117 | 118 | } TEST_END(interrupted_write) 119 | 120 | SUITE_END(dev_tests) 121 | -------------------------------------------------------------------------------- /app/spiffs/test/test_spiffs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * test_spiffs.h 3 | * 4 | * Created on: Jun 19, 2013 5 | * Author: petera 6 | */ 7 | 8 | #ifndef TEST_SPIFFS_H_ 9 | #define TEST_SPIFFS_H_ 10 | 11 | #include "spiffs.h" 12 | 13 | #define FS &__fs 14 | 15 | extern spiffs __fs; 16 | 17 | 18 | #define CHECK(r) if (!(r)) return -1; 19 | #define CHECK_RES(r) if (r < 0) return -1; 20 | #define FS_PURE_DATA_PAGES(fs) \ 21 | ((fs)->cfg.phys_size / (fs)->cfg.log_page_size - (fs)->block_count * SPIFFS_OBJ_LOOKUP_PAGES(fs)) 22 | #define FS_PURE_DATA_SIZE(fs) \ 23 | FS_PURE_DATA_PAGES(fs) * SPIFFS_DATA_PAGE_SIZE(fs) 24 | 25 | typedef enum { 26 | EMPTY, 27 | SMALL, 28 | MEDIUM, 29 | LARGE, 30 | } tfile_size; 31 | 32 | typedef enum { 33 | UNTAMPERED, 34 | APPENDED, 35 | MODIFIED, 36 | REWRITTEN, 37 | } tfile_type; 38 | 39 | typedef enum { 40 | SHORT = 4, 41 | NORMAL = 20, 42 | LONG = 100, 43 | } tfile_life; 44 | 45 | typedef struct { 46 | tfile_size tsize; 47 | tfile_type ttype; 48 | tfile_life tlife; 49 | } tfile_conf; 50 | 51 | typedef struct { 52 | int state; 53 | spiffs_file fd; 54 | tfile_conf cfg; 55 | char name[32]; 56 | } tfile; 57 | 58 | 59 | void fs_reset(); 60 | void fs_reset_specific(u32_t phys_addr, u32_t phys_size, 61 | u32_t phys_sector_size, 62 | u32_t log_block_size, u32_t log_page_size); 63 | int read_and_verify(char *name); 64 | int read_and_verify_fd(spiffs_file fd, char *name); 65 | void dump_page(spiffs *fs, spiffs_page_ix p); 66 | void hexdump(u32_t addr, u32_t len); 67 | char *make_test_fname(const char *name); 68 | void clear_test_path(); 69 | void area_write(u32_t addr, u8_t *buf, u32_t size); 70 | void area_read(u32_t addr, u8_t *buf, u32_t size); 71 | void dump_erase_counts(spiffs *fs); 72 | void dump_flash_access_stats(); 73 | void set_flash_ops_log(int enable); 74 | void clear_flash_ops_log(); 75 | u32_t get_flash_ops_log_read_bytes(); 76 | u32_t get_flash_ops_log_write_bytes(); 77 | void invoke_error_after_read_bytes(u32_t b, char once_only); 78 | void invoke_error_after_write_bytes(u32_t b, char once_only); 79 | 80 | void memrand(u8_t *b, int len); 81 | int test_create_file(char *name); 82 | int test_create_and_write_file(char *name, int size, int chunk_size); 83 | void _setup(); 84 | void _setup_test_only(); 85 | void _teardown(); 86 | u32_t tfile_get_size(tfile_size s); 87 | int run_file_config(int cfg_count, tfile_conf* cfgs, int max_runs, int max_concurrent_files, int dbg); 88 | 89 | 90 | #endif /* TEST_SPIFFS_H_ */ 91 | -------------------------------------------------------------------------------- /app/spiffs/test/testrunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * testrunner.h 3 | * 4 | * Created on: Jun 19, 2013 5 | * Author: petera 6 | */ 7 | 8 | /* 9 | 10 | SUITE(mysuite) 11 | 12 | void setup(test *t) {} 13 | 14 | void teardown(test *t) {} 15 | 16 | TEST(mytest) { 17 | printf("mytest runs now..\n"); 18 | return 0; 19 | } TEST_END(mytest) 20 | 21 | SUITE_END(mysuite) 22 | 23 | 24 | 25 | SUITE(mysuite2) 26 | 27 | void setup(test *t) {} 28 | 29 | void teardown(test *t) {} 30 | 31 | TEST(mytest2a) { 32 | printf("mytest2a runs now..\n"); 33 | return 0; 34 | } TEST_END(mytest2a) 35 | 36 | TEST(mytest2b) { 37 | printf("mytest2b runs now..\n"); 38 | return 0; 39 | } TEST_END(mytest2b) 40 | 41 | SUITE_END(mysuite2) 42 | 43 | 44 | 45 | void add_suites() { 46 | ADD_SUITE(mysuite); 47 | ADD_SUITE(mysuite2); 48 | } 49 | */ 50 | 51 | #ifndef TESTS_H_ 52 | #define TESTS_H_ 53 | 54 | #define TEST_RES_OK 0 55 | #define TEST_RES_FAIL -1 56 | #define TEST_RES_ASSERT -2 57 | 58 | struct test_s; 59 | 60 | typedef int (*test_f)(struct test_s *t); 61 | 62 | typedef struct test_s { 63 | test_f f; 64 | char name[256]; 65 | void *data; 66 | void (*setup)(struct test_s *t); 67 | void (*teardown)(struct test_s *t); 68 | struct test_s *_next; 69 | } test; 70 | 71 | typedef struct test_res_s { 72 | char name[256]; 73 | struct test_res_s *_next; 74 | } test_res; 75 | 76 | #define TEST_CHECK(x) if (!(x)) { \ 77 | printf(" TEST FAIL %s:%i\n", __FILE__, __LINE__); \ 78 | goto __fail_stop; \ 79 | } 80 | #define TEST_ASSERT(x) if (!(x)) { \ 81 | printf(" TEST ASSERT %s:%i\n", __FILE__, __LINE__); \ 82 | goto __fail_assert; \ 83 | } 84 | 85 | #define DBGT(...) printf(__VA_ARGS__) 86 | 87 | #define str(s) #s 88 | 89 | #define SUITE(sui) \ 90 | extern void __suite_##sui() { 91 | #define SUITE_END(sui) \ 92 | } 93 | #define ADD_SUITE(sui) \ 94 | __suite_##sui(); 95 | #define TEST(tf) \ 96 | int tf(struct test_s *t) { do 97 | #define TEST_END(tf) \ 98 | while(0); \ 99 | __fail_stop: return TEST_RES_FAIL; \ 100 | __fail_assert: return TEST_RES_ASSERT; \ 101 | } \ 102 | add_test(tf, str(tf), setup, teardown); 103 | 104 | 105 | void add_suites(); 106 | void test_init(void (*on_stop)(test *t)); 107 | void add_test(test_f f, char *name, void (*setup)(test *t), void (*teardown)(test *t)); 108 | void run_tests(int argc, char **args); 109 | 110 | #endif /* TESTS_H_ */ 111 | -------------------------------------------------------------------------------- /app/spiffs/test/testsuites.c: -------------------------------------------------------------------------------- 1 | /* 2 | * testsuites.c 3 | * 4 | * Created on: Jun 19, 2013 5 | * Author: petera 6 | */ 7 | 8 | #include "testrunner.h" 9 | 10 | void add_suites() { 11 | //ADD_SUITE(dev_tests); 12 | ADD_SUITE(check_tests); 13 | ADD_SUITE(hydrogen_tests) 14 | ADD_SUITE(bug_tests) 15 | } 16 | -------------------------------------------------------------------------------- /app/user/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = libuser.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | EXTRA_CCFLAGS += \ 27 | -DVERSION="$(VERSION)" -DSTA_PASS="$(STA_PASS)" -DSTA_SSID="$(STA_SSID)" \ 28 | -DMQTT_ENABLE=$(MQTT_ENABLE) 29 | 30 | 31 | ############################################################# 32 | # Recursion Magic - Don't touch this!! 33 | # 34 | # Each subtree potentially has an include directory 35 | # corresponding to the common APIs applicable to modules 36 | # rooted at that subtree. Accordingly, the INCLUDE PATH 37 | # of a module can only contain the include directories up 38 | # its parent path, and not its siblings 39 | # 40 | # Required for each makefile to inherit from the parent 41 | # 42 | # 43 | # 44 | 45 | INCLUDES := $(INCLUDES) -I $(PDIR)include 46 | INCLUDES += -I ./ 47 | INCLUDES += -I ../../include/ets 48 | INCLUDES += -I ../libc 49 | INCLUDES += -I ../platform 50 | INCLUDES += -I ../http 51 | INCLUDES += -I ../dns 52 | INCLUDES += -I ../mqtt 53 | INCLUDES += -I ../rfm 54 | INCLUDES += -I ../spiffs 55 | INCLUDES += -I ../ 56 | PDIR := ../$(PDIR) 57 | sinclude $(PDIR)Makefile 58 | -------------------------------------------------------------------------------- /app/user/user_exceptions.h: -------------------------------------------------------------------------------- 1 | #include "sections.h" 2 | #include "rom.h" 3 | #include 4 | 5 | void load_non_32_wide_handler (struct exception_frame *ef, uint32_t cause) TEXT_SECTION_ATTR; 6 | -------------------------------------------------------------------------------- /app/util/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | GEN_LIBS = util.a 16 | endif 17 | 18 | ############################################################# 19 | # Configuration i.e. compile options etc. 20 | # Target specific stuff (defines etc.) goes in here! 21 | # Generally values applying to a tree are captured in the 22 | # makefile at its root level - these are then overridden 23 | # for a subtree within the makefile rooted therein 24 | # 25 | #DEFINES += 26 | STD_CFLAGS=-std=gnu11 -Wimplicit 27 | 28 | ############################################################# 29 | # Recursion Magic - Don't touch this!! 30 | # 31 | # Each subtree potentially has an include directory 32 | # corresponding to the common APIs applicable to modules 33 | # rooted at that subtree. Accordingly, the INCLUDE PATH 34 | # of a module can only contain the include directories up 35 | # its parent path, and not its siblings 36 | # 37 | # Required for each makefile to inherit from the parent 38 | # 39 | 40 | INCLUDES := $(INCLUDES) -I $(PDIR)include 41 | INCLUDES += -I ./ 42 | INCLUDES += -I ../libc 43 | PDIR := ../$(PDIR) 44 | sinclude $(PDIR)Makefile 45 | -------------------------------------------------------------------------------- /app/util/bitwise_utils.c: -------------------------------------------------------------------------------- 1 | #include "c_types.h" 2 | 3 | #include "bitwise_utils.h" 4 | 5 | uint8_t Byte_GetHighestOrderBit(uint8_t input) 6 | { 7 | uint8_t output = 0; 8 | while (input >>= 1) { 9 | output++; 10 | } 11 | return output; 12 | } 13 | -------------------------------------------------------------------------------- /app/util/bitwise_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Various utils related to bit manipulation. 3 | */ 4 | #ifndef BITWISE_UTILS_H 5 | #define BITWISE_UTILS 6 | 7 | /* Returns highest set '1' for the input byte */ 8 | uint8_t Byte_GetHighestOrderBit(uint8_t input); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /app/util/linked_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: LinkedList.h 3 | * Author: me_000 4 | * 5 | * Created on 6 de Julho de 2015, 15:21 6 | */ 7 | 8 | #ifndef LINKEDLIST_H 9 | #define LINKEDLIST_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | 16 | /** 17 | * The Node struct, 18 | * contains item and the pointers that point to previous node/next node. 19 | */ 20 | typedef struct node { 21 | void* item; 22 | // previous node 23 | struct node* prev; 24 | // next node 25 | struct node* next; 26 | } node; 27 | 28 | 29 | 30 | /** 31 | * The LinkedList struct, contains the pointers that 32 | * point to first node and last node, the size of the LinkedList, 33 | * and the function pointers. 34 | */ 35 | typedef struct linked_list { 36 | node* head; 37 | node* tail; 38 | // size of this LinkedList 39 | int size; 40 | } linked_list; 41 | 42 | void list_add_first (linked_list* _this, void* item); 43 | void list_add_last (linked_list* _this, void* item); 44 | void list_add (linked_list* _this, void* item, int position); 45 | void list_insert_before (linked_list* _this, node* previous_node, node* new_node); 46 | void* list_get (linked_list* _this, int position); 47 | void* list_get_first (linked_list* _this); 48 | void* list_get_last (linked_list* _this); 49 | void* list_remove_node(linked_list* _this, node *node_to_remove); 50 | void* list_remove (linked_list* _this, int position); 51 | void* list_remove_first (linked_list* _this); 52 | void* list_remove_last (linked_list* _this); 53 | linked_list* create_linked_list (); 54 | void init_linked_list(linked_list *list); 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* LINKEDLIST_H */ 62 | 63 | -------------------------------------------------------------------------------- /app/util/netutil.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Net Utilities: Header 4 | * 5 | *******************************************************************************/ 6 | /******************************************************************************* 7 | *Application-level interface for accessing various net-related utlities. 8 | *******************************************************************************/ 9 | #ifndef NETUTIL_h 10 | #define NETUTIL_h 11 | 12 | #include "espconn.h" 13 | 14 | typedef enum { 15 | PING_SEQ_INVALID, 16 | PING_SEQ_READY, 17 | PING_SEQ_STARTED, 18 | PING_SEQ_DONE, 19 | } ping_state_t; 20 | 21 | /* Struct for accessing ping response data */ 22 | typedef struct { 23 | uint8_t state; 24 | uint8_t success; 25 | uint8_t error; 26 | uint8_t expected; 27 | 28 | uint32_t avg_time; 29 | 30 | } PING_RESP_T; 31 | 32 | /******************************************************************************* 33 | * netutil_ping_ip_string: 34 | * Description: Pings an IP 35 | * Parameters: 36 | * - ip: String representation of IP Address 37 | * - appresp: Pointer to app-level ping response data to print out 38 | * Returns: PING_RESP_T - pointer to struct containing response info/metrics 39 | *******************************************************************************/ 40 | void netutil_ping_ip_string(const char * ip, void * appresp); 41 | void netutil_nslookup(const char *domain, dns_found_callback ns_cb); 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | *.S 3 | *.dump 4 | *.bin 5 | *.bin_rep 6 | !.gitignore 7 | !blank.bin 8 | !esp_init_data_default.bin 9 | -------------------------------------------------------------------------------- /doc/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/doc/console.png -------------------------------------------------------------------------------- /doc/filesys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/doc/filesys.png -------------------------------------------------------------------------------- /doc/ota.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/doc/ota.png -------------------------------------------------------------------------------- /doc/uploader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/doc/uploader.png -------------------------------------------------------------------------------- /ld/defsym.rom: -------------------------------------------------------------------------------- 1 | --defsym=strcmp=ets_strcmp 2 | --defsym=strcpy=ets_strcpy 3 | --defsym=strlen=ets_strlen 4 | --defsym=strncmp=ets_strncmp 5 | --defsym=strncpy=ets_strncpy 6 | --defsym=strstr=ets_strstr 7 | --defsym=memcmp=ets_memcmp 8 | --defsym=memcpy=ets_memcpy 9 | --defsym=memmove=ets_memmove 10 | --defsym=memset=ets_memset 11 | -------------------------------------------------------------------------------- /lib/libat.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libat.a -------------------------------------------------------------------------------- /lib/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libcrypto.a -------------------------------------------------------------------------------- /lib/libespnow.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libespnow.a -------------------------------------------------------------------------------- /lib/libjson.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libjson.a -------------------------------------------------------------------------------- /lib/liblwip.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/liblwip.a -------------------------------------------------------------------------------- /lib/liblwip_536.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/liblwip_536.a -------------------------------------------------------------------------------- /lib/libmain.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libmain.a -------------------------------------------------------------------------------- /lib/libmesh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libmesh.a -------------------------------------------------------------------------------- /lib/libnet80211.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libnet80211.a -------------------------------------------------------------------------------- /lib/libphy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libphy.a -------------------------------------------------------------------------------- /lib/libpp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libpp.a -------------------------------------------------------------------------------- /lib/libpwm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libpwm.a -------------------------------------------------------------------------------- /lib/libsmartconfig.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libsmartconfig.a -------------------------------------------------------------------------------- /lib/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libssl.a -------------------------------------------------------------------------------- /lib/libupgrade.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libupgrade.a -------------------------------------------------------------------------------- /lib/libwpa.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libwpa.a -------------------------------------------------------------------------------- /lib/libwpa2.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libwpa2.a -------------------------------------------------------------------------------- /lib/libwps.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/lib/libwps.a -------------------------------------------------------------------------------- /sdk-overrides/include/c_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _OVERRIDE_C_TYPES_H_ 2 | #define _OVERRIDE_C_TYPES_H_ 3 | 4 | #include_next "c_types.h" 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /sdk-overrides/include/mem.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDK_OVERRIDE_MEM_H_ 2 | #define _SDK_OVERRIDE_MEM_H_ 3 | 4 | void *pvPortMalloc (size_t sz, const char *, unsigned); 5 | void vPortFree (void *p, const char *, unsigned); 6 | void *pvPortZalloc (size_t sz, const char *, unsigned); 7 | void *pvPortRealloc (void *p, size_t n, const char *, unsigned); 8 | 9 | #include_next "mem.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /sdk-overrides/include/osapi.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDK_OVERRIDE_OSAPI_H_ 2 | #define _SDK_OVERRIDE_OSAPI_H_ 3 | 4 | #include "rom.h" 5 | void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer); 6 | 7 | int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 8 | int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 9 | 10 | #include_next "osapi.h" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tools/.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | *.css text eol=lf 3 | *.html text eol=lf 4 | *.js text eol=lf 5 | *.json text eol=lf 6 | *.less text eol=lf 7 | *.md text eol=lf 8 | *.svg text eol=lf 9 | *.yml text eol=lf 10 | *.py text eol=lf 11 | *.sh text eol=lf 12 | -------------------------------------------------------------------------------- /tools/makefile.sh: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Generate the certificates and keys for encrypt. 4 | # 5 | 6 | # set default cert for use in the client 7 | xxd -i client.cer | sed -e \ 8 | "s/client_cer/default_certificate/" > cert.h 9 | # set default key for use in the server 10 | xxd -i server.key_1024 | sed -e \ 11 | "s/server_key_1024/default_private_key/" > private_key.h 12 | -------------------------------------------------------------------------------- /tools/spiffy-compressor/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | *.exe 7 | *.d 8 | 9 | # Precompiled Headers 10 | *.gch 11 | *.pch 12 | 13 | # Libraries 14 | *.lib 15 | *.a 16 | *.la 17 | *.lo 18 | 19 | # Shared objects (inc. Windows DLLs) 20 | *.dll 21 | *.so 22 | *.so.* 23 | *.dylib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | *.i*86 30 | *.x86_64 31 | *.hex 32 | 33 | # Debug files 34 | *.dSYM/ 35 | html_compressed/ 36 | -------------------------------------------------------------------------------- /tools/spiffy-compressor/README.md: -------------------------------------------------------------------------------- 1 | spiffy 2 | ====== 3 | 4 | execute: make spiffy_img.o 5 | 6 | Build a [spiffs](https://github.com/pellepl/spiffs) file system binary for embedding/writing 7 | onto the [Sming](https://github.com/anakod/Sming) ESP8266 spiffs file system. 8 | This code forked from https://github.com/xlfe/spiffy and changed for bigger fs and file sizes and stability. 9 | 10 | ### What is it 11 | 12 | spiffy builds a binary spiffs image for you to write_flash to a esp8266 runing Sming so you can 13 | get all the files onto your cool IoT device in one fell swoop. 14 | 15 | ### usage 16 | Basic usage is "spiffy 196608 webFiles" after build. You can build spiffy like this. 17 | 18 | #### Clone the repo and build spiffy 19 | 20 | ```bash 21 | git clone https://github.com/alonewolfx2/spiffy.git 22 | cd spiffy 23 | make 24 | ``` 25 | 26 | #### create a folder with the webFiles you'd like to embed 27 | 28 | #### run spiffy to build the rom 29 | 30 | ```bash 31 | C:\Users\Suskun\Documents\GitHub\spiffy\build>spiffy 196608 webFiles 32 | Creating rom spiff_rom.bin of size 196608 bytes 33 | Adding files in directory webFiles 34 | Unable to read file . 35 | Unable to read file .. 36 | bootstrap.css.gz added to spiffs (15615 bytes) 37 | index.html added to spiffs (12466 bytes) 38 | jquery.js.gz added to spiffs (30153 bytes) 39 | settings.html added to spiffs (4210 bytes) 40 | style.css added to spiffs (7710 bytes) 41 | wifi-sprites.png added to spiffs (1769 bytes) 42 | 43 | ``` 44 | 45 | #### Done! 46 | -------------------------------------------------------------------------------- /tools/spiffy-compressor/html/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/tools/spiffy-compressor/html/favicon.ico -------------------------------------------------------------------------------- /tools/spiffy-compressor/html/fw.css: -------------------------------------------------------------------------------- 1 | #sp-fw h2 { 2 | font: 400 25px/1.5 Helvetica, Verdana, sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | } 6 | 7 | #sp-fw ul { 8 | list-style-type: none; 9 | margin: 0; 10 | padding: 0; 11 | } 12 | 13 | #sp-fw li { 14 | font: 200 20px/1.5 Helvetica, Verdana, sans-serif; 15 | border-bottom: 1px solid #ccc; 16 | } 17 | 18 | #sp-fw li:last-child { 19 | border: none; 20 | } 21 | 22 | #sp-fw li a { 23 | text-decoration: none; 24 | color: #0d0d48; 25 | display: block; 26 | width: 16em; 27 | 28 | -webkit-transition: font-size 0.3s ease, background-color 0.3s ease; 29 | -moz-transition: font-size 0.3s ease, background-color 0.3s ease; 30 | -o-transition: font-size 0.3s ease, background-color 0.3s ease; 31 | -ms-transition: font-size 0.3s ease, background-color 0.3s ease; 32 | transition: font-size 0.3s ease, background-color 0.3s ease; 33 | } 34 | 35 | #sp-fw li:hover { 36 | font-size: 30px; 37 | background: #f6f6f6; 38 | } 39 | 40 | #sp-fw li.fwsel { 41 | background: rgba(41, 0, 255, 0.28); 42 | height: 3em; 43 | } 44 | 45 | #sp-fw li.fwsel label.sellabel { 46 | display:inline-block; 47 | font-size: .8em; 48 | } 49 | 50 | #sp-fw li label.sellabel { 51 | display: none; 52 | } 53 | 54 | #fwul-span label, 55 | #fwul-span a.btn { 56 | margin: 2em; 57 | display: inline-block; 58 | width: 2em; 59 | float: left; 60 | position: relative; 61 | margin-left: 3px; 62 | text-align: center; 63 | padding: 20px; 64 | left: 45%; 65 | } 66 | -------------------------------------------------------------------------------- /tools/spiffy-compressor/html/fw.js: -------------------------------------------------------------------------------- 1 | 2 | var nid = 0; 3 | $("#fwul-span").hide(); 4 | $("#fwid-span").hide(); 5 | 6 | function getSize(aname) { 7 | var sz = 0; 8 | fwlist.forEach(function(el, i) { 9 | if (el == aname) 10 | { 11 | sz = fwszlist[i]; 12 | } 13 | }); 14 | return sz; 15 | } 16 | 17 | function fwConfirm() { 18 | if (nid > 0) 19 | { 20 | var fname = $('#fwlabel').text(); 21 | var r = confirm('Update Node #'+nid+' with '+fname+'?'); 22 | if (r == true) { 23 | $.ajax('http://10.42.0.81/fs?file='+fname+'&action=fw&nid='+nid).done( function() { 24 | console.log('ok!'); 25 | }); 26 | } else { 27 | console.log('confirm abort'); 28 | } 29 | } 30 | return false; 31 | } 32 | 33 | function makefwhtml() { 34 | fwlist.forEach(function(el, index) { 35 | var mkli = $.mk("li"); 36 | $(mkli).attr('id', 'fwfno-'+index); 37 | var mka = $.mk("a"); 38 | var mklb = $.mk("label"); 39 | 40 | $(mklb).text('size: ' + getSize(el)); 41 | $(mklb).addClass('sellabel'); 42 | 43 | $(mka).attr('href', '#'); 44 | $(mka).text(el); 45 | 46 | $(mkli).append($(mka)); 47 | $(mkli).append($(mklb)); 48 | $("#fw-list").append($(mkli)); 49 | }); 50 | 51 | 52 | $('li[id|=fwfno').each(function (elem, i) { 53 | $(elem).on('click', function() { 54 | $('li[id|=fwfno').each(function (el2, i2) { 55 | $(el2).attr('class', ''); 56 | }); 57 | $(this).addClass('fwsel'); 58 | $('#fwlabel').text(fwlist[i]); 59 | $("#fwid-span").show(); 60 | $("#fwul-span").show(); 61 | }); 62 | }); 63 | 64 | 65 | $('#fw-idtxt').on('keyup', function(e) { 66 | e.preventDefault(); 67 | if (!(this.value.match(/^[0-9]{0,3}$/))) { 68 | this.value = ''; 69 | $('#fwul-btn').attr('disabled',''); 70 | nid = 0; 71 | return; 72 | } else { 73 | var outVal = parseInt(this.value, 10); 74 | if ((outVal>=1) && (outVal<=255)) { 75 | nid = outVal; 76 | $('#fwul-btn').removeAttr('disabled'); 77 | } else { 78 | this.value = ''; 79 | nid = 0; 80 | $('#fwul-btn').attr('disabled',''); 81 | return; 82 | } 83 | } 84 | }); 85 | } 86 | 87 | function loadfwList() { 88 | $.ajax('/fs?file=list&action=list', function(data) { 89 | var resp = JSON.parse(data) 90 | resp.items.forEach(function(elm, ind) { 91 | var nm = elm.name.split('.')[1]; 92 | if (nm == 'bin') 93 | { 94 | fwlist.push(elm.name); 95 | fwszlist.push(elm.size); 96 | } 97 | }); 98 | }).done(function () { 99 | }); 100 | } 101 | 102 | $(function(){ 103 | fwlist = []; 104 | fwszlist = []; 105 | loadfwList(); 106 | window.setTimeout(makefwhtml,250); 107 | }) 108 | -------------------------------------------------------------------------------- /tools/spiffy-compressor/html/ki.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * ki.js v1.1.0 - 2015-10-06 3 | * Copyright (c) 2015 Denis Ciccale (@tdecs) 4 | * Released under MIT license 5 | */ 6 | !function(a,b,c,d){function e(c){b.push.apply(this,c&&c.nodeType?[c]:""+c===c?a.querySelectorAll(c):d)}$=function(b){return/^f/.test(typeof b)?/c/.test(a.readyState)?b():$(a).on("DOMContentLoaded",b):new e(b)},$[c]=e[c]=$.fn=e.fn={length:0,on:function(a,b){return this.each(function(c){c.addEventListener(a,b)})},off:function(a,b){return this.each(function(c){c.removeEventListener(a,b)})},each:function(a,c){return b.forEach.call(this,a,c),this},splice:b.splice}}(document,[],"prototype"); -------------------------------------------------------------------------------- /tools/spiffy-compressor/html/min.css: -------------------------------------------------------------------------------- 1 | body,textarea,input,select{background:0;border-radius:0;font:16px sans-serif;margin:0}.addon,.btn-sm,.nav,textarea,input,select{outline:0;font-size:14px}.smooth{transition:all .2s}.btn,.nav a{text-decoration:none}.container{margin:0 20px;width:auto}@media(min-width:1310px){.container{margin:auto;width:1270px}}.btn,h2{font-size:2em}h1{font-size:3em}.btn{background:#999;border-radius:6px;border:0;color:#fff;cursor:pointer;display:inline-block;margin:2px 0;padding:12px 30px 14px}.btn:hover{background:#888}.btn:active,.btn:focus{background:#777}.btn-a{background:#0ae}.btn-a:hover{background:#09d}.btn-a:active,.btn-a:focus{background:#08b}.btn-b{background:#3c5}.btn-b:hover{background:#2b4}.btn-b:active,.btn-b:focus{background:#2a4}.btn-c{background:#d33}.btn-c:hover{background:#c22}.btn-c:active,.btn-c:focus{background:#b22}.btn-sm{border-radius:4px;padding:10px 14px 11px}label>*{display:inline}form>*{display:block;margin-bottom:10px}textarea,input,select{border:1px solid #ccc;padding:8px}textarea:focus,input:focus,select:focus{border-color:#5ab}textarea,input[type=text]{-webkit-appearance:none;width:13em;outline:0}.addon{box-shadow:0 0 0 1px #ccc;padding:8px 12px}.nav,.nav .current,.nav a:hover{background:#000;color:#fff}.nav{height:24px;padding:11px 0 15px}.nav a{color:#aaa;padding-right:1em;position:relative;top:-1px}.nav .pagename{font-size:22px;top:1px}.btn.btn-close{background:#000;float:right;font-size:25px;margin:-54px 7px;display:none}@media(max-width:500px){.btn.btn-close{display:block}.nav{overflow:hidden}.pagename{margin-top:-11px}.nav:active,.nav:focus{height:auto}.nav div:before{background:#000;border-bottom:10px double;border-top:3px solid;content:'';float:right;height:4px;position:relative;right:3px;top:14px;width:20px}.nav a{display:block;padding:.5em 0;width:50%}}.table th,.table td{padding:.5em;text-align:left}.table tbody>:nth-child(2n-1){background:#ddd}.ico{font:33px Arial Unicode MS,Lucida Sans Unicode}.row{margin:1% 0;overflow:auto}.col{float:left}.table,.c12{width:100%}.c11{width:91.66%}.c10{width:83.33%}.c9{width:75%}.c8{width:66.66%}.c7{width:58.33%}.c6{width:50%}.c5{width:41.66%}.c4{width:33.33%}.c3{width:25%}.c2{width:16.66%}.c1{width:8.33%}@media(max-width:870px){.row .col{width:100%}} -------------------------------------------------------------------------------- /tools/spiffy-compressor/html/wifi/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/tools/spiffy-compressor/html/wifi/icons.png -------------------------------------------------------------------------------- /tools/spiffy-compressor/spiffy/makefile: -------------------------------------------------------------------------------- 1 | # --------------- Spiffy options --------------- 2 | 3 | # If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed 4 | # with gzip before added to the espfs image and will be served with gzip Content-Encoding header. 5 | # This could speed up the downloading of these files, but might break compatibility with older 6 | # web browsers not supporting gzip encoding because Accept-Encoding is simply ignored. 7 | # Enable this option if you have large static files to serve (for e.g. JQuery, Twitter bootstrap) 8 | # If you have text based static files with different extensions what you want to serve compressed 9 | # then you will need to add the extension to the following places: 10 | # - Add the extension to this Makefile at the webpages.espfs target to the find command 11 | # - Add the extension to the gzippedFileTypes array in the user/httpd.c file 12 | # 13 | # Adding JPG or PNG files (and any other compressed formats) is not recommended, because GZIP 14 | # compression does not work effectively on compressed files. 15 | 16 | #Static gzipping is disabled by default. 17 | # GZIP_COMPRESSION = $(GZIP_COMPRESSION) 18 | SPIFFY_OUTPUT ?= 0 19 | # VERBOSE=1 20 | 21 | #default Endpoint 22 | 23 | # Build time Wifi Cfg 24 | STA_SSID ?= STA_SSID 25 | STA_PASS ?= STA_PASS 26 | 27 | ############ 28 | # 29 | # OUTPUT 30 | # 31 | ############ 32 | BINARY = spiffy 33 | 34 | ############ 35 | # 36 | # Paths 37 | # 38 | ############ 39 | 40 | sourcedir = src 41 | builddir = build 42 | BUILD_BASE = build 43 | 44 | 45 | ############# 46 | # 47 | # Build tools 48 | # 49 | ############# 50 | 51 | CC = gcc $(COMPILEROPTIONS) 52 | LD = ld 53 | GDB = gdb 54 | OBJCOPY = objcopy 55 | OBJDUMP = objdump 56 | MKDIR = mkdir -p 57 | 58 | 59 | ############### 60 | # 61 | # Files and libs 62 | # 63 | ############### 64 | 65 | FLAGS += -DCONFIG_BUILD_SPIFFS -I.. -std=gnu99 -lz 66 | CFILES = main.c 67 | CFILES += spiffs_nucleus.c 68 | CFILES += spiffs_gc.c 69 | CFILES += spiffs_hydrogen.c 70 | CFILES += spiffs_cache.c 71 | CFILES += spiffs_check.c 72 | 73 | INCLUDE_DIRECTIVES = -I./${sourcedir} 74 | COMPILEROPTIONS = $(INCLUDE_DIRECTIVES) 75 | 76 | # ifeq ($(GZIP_COMPRESSION),1) 77 | # CCFLAGS ?= -DGZIP_COMPRESSION=$(GZIP_COMPRESSION) 78 | # endif 79 | 80 | ifeq ($(SPIFFY_OUTPUT),1) 81 | CCFLAGS ?= -DSPIFFY_DEBUG 82 | endif 83 | 84 | CCFLAGS += -DSTA_PASS=$(STA_PASS) -DSTA_SSID=$(STA_SSID) 85 | 86 | 87 | V ?= $(VERBOSE) 88 | ifeq ("$(V)","1") 89 | Q := 90 | vecho := @true 91 | else 92 | Q := @ 93 | vecho := @echo 94 | endif 95 | 96 | 97 | ############ 98 | # 99 | # Tasks 100 | # 101 | ############ 102 | 103 | vpath %.c ${sourcedir} ${sourcedir}/default ${sourcedir}/test 104 | 105 | OBJFILES = $(CFILES:%.c=${builddir}/%.o) 106 | 107 | DEPFILES = $(CFILES:%.c=${builddir}/%.d) 108 | 109 | ALLOBJFILES += $(OBJFILES) 110 | 111 | DEPENDENCIES = $(DEPFILES) 112 | 113 | # link object files, create binary 114 | $(BINARY): $(ALLOBJFILES) 115 | @echo "... linking" 116 | @${CC} $(LINKEROPTIONS) -o ${builddir}/$(BINARY) $(ALLOBJFILES) $(LIBS) -lz 117 | 118 | -include $(DEPENDENCIES) 119 | 120 | # compile c filesf 121 | $(OBJFILES) : ${builddir}/%.o:%.c 122 | $(vecho) "... compile $@" 123 | @${CC} ${CCFLAGS} -g -c -o $@ $< 124 | 125 | # make dependencies 126 | $(DEPFILES) : ${builddir}/%.d:%.c 127 | @echo "... depend $@"; \ 128 | rm -f $@; \ 129 | ${CC} $(COMPILEROPTIONS) -M $< > $@.$$$$; \ 130 | sed 's,\($*\)\.o[ :]*, ${builddir}/\1.o $@ : ,g' < $@.$$$$ > $@; \ 131 | rm -f $@.$$$$ 132 | 133 | all: mkdirs $(BINARY) 134 | 135 | mkdirs: 136 | -@${MKDIR} ${builddir} 137 | 138 | 139 | clean: 140 | @echo ... removing build files in ${builddir} 141 | @rm -f ${builddir}/*.o 142 | @rm -f ${builddir}/*.d 143 | @rm -f ${builddir}/*.elf 144 | @rm -f ${builddir}/spiffy 145 | @rm -f ${builddir}/spiffy.exe 146 | -------------------------------------------------------------------------------- /tools/spiffy-compressor/utils/htmlcompressor-1.5.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/tools/spiffy-compressor/utils/htmlcompressor-1.5.3.jar -------------------------------------------------------------------------------- /tools/spiffy-compressor/utils/yuicompressor-2.4.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/someburner/esp-rfm69/d689bdb8f677ed05177a70cc95defceb540ddad8/tools/spiffy-compressor/utils/yuicompressor-2.4.8.jar --------------------------------------------------------------------------------