Commit 4911d2db authored by Arnim Läuger's avatar Arnim Läuger
Browse files

Merge pull request #1336 from nodemcu/dev

1.5.1 master drop
parents c8037568 2e109686
...@@ -29,7 +29,7 @@ extern void espconn_kill_oldest_pcb(void); ...@@ -29,7 +29,7 @@ extern void espconn_kill_oldest_pcb(void);
* Returns : none * Returns : none
*******************************************************************************/ *******************************************************************************/
extern void espconn_tcp_disconnect(espconn_msg *pdiscon); extern void espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type);
/****************************************************************************** /******************************************************************************
* FunctionName : espconn_tcp_client * FunctionName : espconn_tcp_client
......
...@@ -789,7 +789,6 @@ ...@@ -789,7 +789,6 @@
#ifndef LWIP_MDNS #ifndef LWIP_MDNS
#define LWIP_MDNS 1 #define LWIP_MDNS 1
#endif #endif
/*
/* /*
---------------------------------- ----------------------------------
---------- DNS options ----------- ---------- DNS options -----------
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
const LOCK_IN_SECTION(".lua_rotable") \ const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map } luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map }
#if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2) #if !defined(LUA_CROSS_COMPILER) && !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2)
# error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)" # error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif #endif
......
#ifndef _NODEMCU_MDNS_H
#define _NODEMCU_MDNS_H
struct nodemcu_mdns_info {
const char *host_name;
const char *host_desc;
const char *service_name;
uint16 service_port;
const char *txt_data[10];
};
void nodemcu_mdns_close(void);
bool nodemcu_mdns_init(struct nodemcu_mdns_info *);
#endif
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#define _ROM_H_ #define _ROM_H_
#include "c_types.h" #include "c_types.h"
#include "ets_sys.h"
// SHA1 is assumed to match the netbsd sha1.h headers // SHA1 is assumed to match the netbsd sha1.h headers
#define SHA1_DIGEST_LENGTH 20 #define SHA1_DIGEST_LENGTH 20
...@@ -44,7 +45,7 @@ extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_ ...@@ -44,7 +45,7 @@ extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_
extern void mem_init(void * start_addr); extern void mem_init(void * start_addr);
// Interrupt Service Routine functions // Interrupt Service Routine functions
typedef void (*ets_isr_fn) (void *arg, uint32_t sp); typedef void (*ets_isr_fn) (void *arg);
extern int ets_isr_attach (unsigned int interrupt, ets_isr_fn, void *arg); extern int ets_isr_attach (unsigned int interrupt, ets_isr_fn, void *arg);
extern void ets_isr_mask (unsigned intr); extern void ets_isr_mask (unsigned intr);
extern void ets_isr_unmask (unsigned intr); extern void ets_isr_unmask (unsigned intr);
...@@ -108,4 +109,45 @@ typedef void (*exception_handler_fn) (struct exception_frame *ef, uint32_t cause ...@@ -108,4 +109,45 @@ typedef void (*exception_handler_fn) (struct exception_frame *ef, uint32_t cause
*/ */
exception_handler_fn _xtos_set_exception_handler (uint32_t cause, exception_handler_fn handler); exception_handler_fn _xtos_set_exception_handler (uint32_t cause, exception_handler_fn handler);
void ets_update_cpu_frequency (uint32_t mhz);
uint32_t ets_get_cpu_frequency (void);
void *ets_memcpy (void *dst, const void *src, size_t n);
void *ets_memmove (void *dst, const void *src, size_t n);
void *ets_memset (void *dst, int c, size_t n);
int ets_memcmp (const void *s1, const void *s2, size_t n);
char *ets_strcpy (char *dst, const char *src);
size_t ets_strlen (const char *s);
int ets_strcmp (const char *s1, const char *s2);
int ets_strncmp (const char *s1, const char *s2, size_t n);
char *ets_strncpy(char *dest, const char *src, size_t n);
char *ets_strstr(const char *haystack, const char *needle);
void ets_delay_us (uint32_t us);
int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void ets_str2macaddr (uint8_t *dst, const char *str);
void ets_timer_disarm (ETSTimer *a);
void ets_timer_setfn (ETSTimer *t, ETSTimerFunc *fn, void *parg);
void Cache_Read_Enable(uint32_t b0, uint32_t b1, uint32_t use_40108000);
void Cache_Read_Disable(void);
void ets_intr_lock(void);
void ets_intr_unlock(void);
void ets_install_putc1(void *routine);
int rand(void);
void srand(unsigned int);
void uart_div_modify(int no, unsigned int freq);
/* Returns 0 on success, 1 on failure */
uint8_t SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
#endif #endif
...@@ -126,6 +126,7 @@ ...@@ -126,6 +126,7 @@
#include <ets_sys.h> #include <ets_sys.h>
#include "rom.h" #include "rom.h"
#include "rtcaccess.h" #include "rtcaccess.h"
#include "user_interface.h"
// Layout of the RTC storage space: // Layout of the RTC storage space:
// //
......
#ifndef _TASK_H_
#define _TASK_H_
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
/* use LOW / MEDIUM / HIGH since it isn't clear from the docs which is higher */
#define TASK_PRIORITY_LOW 0
#define TASK_PRIORITY_MEDIUM 1
#define TASK_PRIORITY_HIGH 2
#define TASK_PRIORITY_COUNT 3
/*
* Signals are a 32-bit number of the form header:14; count:16, priority:2. The header
* is just a fixed fingerprint and the count is allocated serially by the task get_id()
* function.
*/
#define task_post(priority,handle,param) system_os_post(priority, ((handle) | priority), param)
#define task_post_low(handle,param) task_post(TASK_PRIORITY_LOW, handle, param)
#define task_post_medium(handle,param) task_post(TASK_PRIORITY_MEDIUM, handle, param)
#define task_post_high(handle,param) task_post(TASK_PRIORITY_HIGH, handle, param)
#define task_handle_t os_signal_t
#define task_param_t os_param_t
typedef void (*task_callback_t)(task_param_t param, uint8 prio);
bool task_init_handler(uint8 priority, uint8 qlen);
task_handle_t task_get_id(task_callback_t t);
#endif
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
// UCG_DISPLAY_TABLE_ENTRY(ili9163_18x128x128_hw_spi, ucg_dev_ili9163_18x128x128, ucg_ext_ili9163_18) \ // UCG_DISPLAY_TABLE_ENTRY(ili9163_18x128x128_hw_spi, ucg_dev_ili9163_18x128x128, ucg_ext_ili9163_18) \
// UCG_DISPLAY_TABLE_ENTRY(ili9341_18x240x320_hw_spi, ucg_dev_ili9341_18x240x320, ucg_ext_ili9341_18) \ // UCG_DISPLAY_TABLE_ENTRY(ili9341_18x240x320_hw_spi, ucg_dev_ili9341_18x240x320, ucg_ext_ili9341_18) \
// UCG_DISPLAY_TABLE_ENTRY(pcf8833_16x132x132_hw_spi, ucg_dev_pcf8833_16x132x132, ucg_ext_pcf8833_16) \ // UCG_DISPLAY_TABLE_ENTRY(pcf8833_16x132x132_hw_spi, ucg_dev_pcf8833_16x132x132, ucg_ext_pcf8833_16) \
// UCG_DISPLAY_TABLE_ENTRY(seps225_16x128x128_univision_hw_spi, ucg_dev_seps225_16x128x128_univision, ucg_ext_seps225_16) \ // UCG_DISPLAY_TABLE_ENTRY(seps225_16x128x128_uvis_hw_spi, ucg_dev_seps225_16x128x128_univision, ucg_ext_seps225_16) \
// UCG_DISPLAY_TABLE_ENTRY(ssd1351_18x128x128_hw_spi, ucg_dev_ssd1351_18x128x128_ilsoft, ucg_ext_ssd1351_18) \ // UCG_DISPLAY_TABLE_ENTRY(ssd1351_18x128x128_hw_spi, ucg_dev_ssd1351_18x128x128_ilsoft, ucg_ext_ssd1351_18) \
// UCG_DISPLAY_TABLE_ENTRY(ssd1351_18x128x128_ft_hw_spi, ucg_dev_ssd1351_18x128x128_ft, ucg_ext_ssd1351_18) \ // UCG_DISPLAY_TABLE_ENTRY(ssd1351_18x128x128_ft_hw_spi, ucg_dev_ssd1351_18x128x128_ft, ucg_ext_ssd1351_18) \
// UCG_DISPLAY_TABLE_ENTRY(ssd1331_18x96x64_univision_hw_spi, ucg_dev_ssd1331_18x96x64_univision, ucg_ext_ssd1331_18) \ // UCG_DISPLAY_TABLE_ENTRY(ssd1331_18x96x64_uvis_hw_spi, ucg_dev_ssd1331_18x96x64_univision, ucg_ext_ssd1331_18) \
// UCG_DISPLAY_TABLE_ENTRY(st7735_18x128x160_hw_spi, ucg_dev_st7735_18x128x160, ucg_ext_st7735_18) \ // UCG_DISPLAY_TABLE_ENTRY(st7735_18x128x160_hw_spi, ucg_dev_st7735_18x128x160, ucg_ext_st7735_18) \
#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension)
......
...@@ -12,20 +12,28 @@ ...@@ -12,20 +12,28 @@
#define FLASH_AUTOSIZE #define FLASH_AUTOSIZE
#define FLASH_SAFE_API #define FLASH_SAFE_API
// Byte 107 of esp_init_data_default, only one of these 3 can be picked // This adds the asserts in LUA. It also adds some useful extras to the
#define ESP_INIT_DATA_ENABLE_READVDD33 // node module. This is all silent in normal operation and so can be enabled
//#define ESP_INIT_DATA_ENABLE_READADC // without any harm (except for the code size increase and slight slowdown)
//#define ESP_INIT_DATA_FIXED_VDD33_VALUE 33 //#define DEVELOPMENT_TOOLS
#ifdef DEVELOPMENT_TOOLS
extern void luaL_assertfail(const char *file, int line, const char *message);
#define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x))
#endif
// This enables lots of debug output and changes the serial bit rate. This
// is normally only used by hardcore developers
// #define DEVELOP_VERSION // #define DEVELOP_VERSION
#ifdef DEVELOP_VERSION #ifdef DEVELOP_VERSION
#define NODE_DEBUG #define NODE_DEBUG
#define COAP_DEBUG #define COAP_DEBUG
#define BIT_RATE_DEFAULT BIT_RATE_74880
#else
#define BIT_RATE_DEFAULT BIT_RATE_9600
#endif /* DEVELOP_VERSION */ #endif /* DEVELOP_VERSION */
#define BIT_RATE_DEFAULT BIT_RATE_115200
// This enables automatic baud rate detection at startup
#define BIT_RATE_AUTOBAUD
#define NODE_ERROR #define NODE_ERROR
...@@ -41,29 +49,28 @@ ...@@ -41,29 +49,28 @@
#define NODE_ERR #define NODE_ERR
#endif /* NODE_ERROR */ #endif /* NODE_ERROR */
#define GPIO_INTERRUPT_ENABLE
#define GPIO_INTERRUPT_HOOK_ENABLE
// #define GPIO_SAFE_NO_INTR_ENABLE
#define ICACHE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed)) #define ICACHE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
#define ICACHE_STORE_ATTR __attribute__((aligned(4))) #define ICACHE_STORE_ATTR __attribute__((aligned(4)))
#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text"))) #define ICACHE_RAM_ATTR __attribute__((section(".iram0.text")))
#ifdef GPIO_SAFE_NO_INTR_ENABLE
#define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline))
#else
#define NO_INTR_CODE inline
#endif
#define CLIENT_SSL_ENABLE //#define CLIENT_SSL_ENABLE
#define GPIO_INTERRUPT_ENABLE
//#define MD2_ENABLE //#define MD2_ENABLE
#define SHA2_ENABLE #define SHA2_ENABLE
// #define BUILD_WOFS 1
#define BUILD_SPIFFS 1 #define BUILD_SPIFFS 1
#define SPIFFS_CACHE 1 #define SPIFFS_CACHE 1
// #define LUA_NUMBER_INTEGRAL // #define LUA_NUMBER_INTEGRAL
#define LUA_OPTRAM
#ifdef LUA_OPTRAM
#define LUA_OPTIMIZE_MEMORY 2
#else
#define LUA_OPTIMIZE_MEMORY 0
#endif /* LUA_OPTRAM */
#define READLINE_INTERVAL 80 #define READLINE_INTERVAL 80
#define LUA_TASK_PRIO USER_TASK_PRIO_0 #define LUA_TASK_PRIO USER_TASK_PRIO_0
#define LUA_PROCESS_LINE_SIG 2 #define LUA_PROCESS_LINE_SIG 2
...@@ -83,6 +90,23 @@ ...@@ -83,6 +90,23 @@
#define ENDUSER_SETUP_AP_SSID "SetupGadget" #define ENDUSER_SETUP_AP_SSID "SetupGadget"
/*
* A valid hostname only contains alphanumeric and hyphen(-) characters, with no hyphens at first or last char
* if WIFI_STA_HOSTNAME not defined: hostname will default to NODE-xxxxxx (xxxxxx being last 3 octets of MAC address)
* if WIFI_STA_HOSTNAME defined: hostname must only contain alphanumeric characters
* if WIFI_STA_HOSTNAME_APPEND_MAC not defined: Hostname MUST be 32 chars or less
* if WIFI_STA_HOSTNAME_APPEND_MAC defined: Hostname MUST be 26 chars or less, since last 3 octets of MAC address will be appended
* if defined hostname is invalid: hostname will default to NODE-xxxxxx (xxxxxx being last 3 octets of MAC address)
*/
//#define WIFI_STA_HOSTNAME "NodeMCU"
//#define WIFI_STA_HOSTNAME_APPEND_MAC
//#define WIFI_SMART_ENABLE
#define WIFI_STATION_STATUS_MONITOR_ENABLE
#define WIFI_SDK_EVENT_MONITOR_ENABLE
#define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
#define STRBUF_DEFAULT_INCREMENT 32 #define STRBUF_DEFAULT_INCREMENT 32
#endif /* __USER_CONFIG_H__ */ #endif /* __USER_CONFIG_H__ */
...@@ -13,37 +13,51 @@ ...@@ -13,37 +13,51 @@
#ifndef LUA_CROSS_COMPILER #ifndef LUA_CROSS_COMPILER
// The default configuration is designed to run on all ESP modules including the 512 KB modules like ESP-01 and only
// includes general purpose interface modules which require at most two GPIO pins.
// See https://github.com/nodemcu/nodemcu-firmware/pull/1127 for discussions.
// New modules should be disabled by default and added in alphabetical order.
#define LUA_USE_MODULES_ADC #define LUA_USE_MODULES_ADC
//#define LUA_USE_MODULES_AM2320
//#define LUA_USE_MODULES_APA102
#define LUA_USE_MODULES_BIT #define LUA_USE_MODULES_BIT
//#define LUA_USE_MODULES_BMP085 //#define LUA_USE_MODULES_BMP085
#define LUA_USE_MODULES_CJSON //#define LUA_USE_MODULES_BME280
#define LUA_USE_MODULES_COAP //#define LUA_USE_MODULES_CJSON
#define LUA_USE_MODULES_CRYPTO //#define LUA_USE_MODULES_COAP
//#define LUA_USE_MODULES_CRYPTO
#define LUA_USE_MODULES_DHT #define LUA_USE_MODULES_DHT
//#define LUA_USE_MODULES_ENCODER
//#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work. //#define LUA_USE_MODULES_ENDUSER_SETUP // USE_DNS in dhcpserver.h needs to be enabled for this module to work.
#define LUA_USE_MODULES_FILE #define LUA_USE_MODULES_FILE
#define LUA_USE_MODULES_GPIO #define LUA_USE_MODULES_GPIO
//#define LUA_USE_MODULES_HTTP
//#define LUA_USE_MODULES_HX711 //#define LUA_USE_MODULES_HX711
#define LUA_USE_MODULES_I2C #define LUA_USE_MODULES_I2C
//#define LUA_USE_MODULES_MDNS
#define LUA_USE_MODULES_MQTT #define LUA_USE_MODULES_MQTT
#define LUA_USE_MODULES_NET #define LUA_USE_MODULES_NET
#define LUA_USE_MODULES_NODE #define LUA_USE_MODULES_NODE
#define LUA_USE_MODULES_OW #define LUA_USE_MODULES_OW
#define LUA_USE_MODULES_PWM //#define LUA_USE_MODULES_PERF
#define LUA_USE_MODULES_RC //#define LUA_USE_MODULES_PWM
#define LUA_USE_MODULES_RTCFIFO //#define LUA_USE_MODULES_RC
#define LUA_USE_MODULES_RTCMEM //#define LUA_USE_MODULES_ROTARY
#define LUA_USE_MODULES_RTCTIME //#define LUA_USE_MODULES_RTCFIFO
#define LUA_USE_MODULES_SNTP //#define LUA_USE_MODULES_RTCMEM
//#define LUA_USE_MODULES_RTCTIME
//#define LUA_USE_MODULES_SIGMA_DELTA
//#define LUA_USE_MODULES_SNTP
#define LUA_USE_MODULES_SPI #define LUA_USE_MODULES_SPI
//#define LUA_USE_MODULES_STRUCT
#define LUA_USE_MODULES_TMR #define LUA_USE_MODULES_TMR
#define LUA_USE_MODULES_TSL2561 //#define LUA_USE_MODULES_TSL2561
#define LUA_USE_MODULES_U8G //#define LUA_USE_MODULES_U8G
#define LUA_USE_MODULES_UART #define LUA_USE_MODULES_UART
//#define LUA_USE_MODULES_UCG //#define LUA_USE_MODULES_UCG
#define LUA_USE_MODULES_WIFI #define LUA_USE_MODULES_WIFI
//#define LUA_USE_MODULES_WS2801 //#define LUA_USE_MODULES_WS2801
#define LUA_USE_MODULES_WS2812 //#define LUA_USE_MODULES_WS2812
#endif /* LUA_CROSS_COMPILER */ #endif /* LUA_CROSS_COMPILER */
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
#define __USER_VERSION_H__ #define __USER_VERSION_H__
#define NODE_VERSION_MAJOR 1U #define NODE_VERSION_MAJOR 1U
#define NODE_VERSION_MINOR 4U #define NODE_VERSION_MINOR 5U
#define NODE_VERSION_REVISION 0U #define NODE_VERSION_REVISION 1U
#define NODE_VERSION_INTERNAL 0U #define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMCU 1.4.0" #define NODE_VERSION "NodeMCU 1.5.1"
#ifndef BUILD_DATE #ifndef BUILD_DATE
#define BUILD_DATE "20151006" #define BUILD_DATE "unspecified"
#endif #endif
extern char SDK_VERSION[]; extern char SDK_VERSION[];
......
/*
* Copyright (c) 2011-2012, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*/
#ifdef JSON_FORMAT
#include "json/jsonparse.h"
#include "osapi.h"
//#include <stdlib.h>
//#include <string.h>
/*--------------------------------------------------------------------*/
static int ICACHE_FLASH_ATTR
push(struct jsonparse_state *state, char c)
{
state->stack[state->depth] = c;
state->depth++;
state->vtype = 0;
return state->depth < JSONPARSE_MAX_DEPTH;
}
/*--------------------------------------------------------------------*/
static char ICACHE_FLASH_ATTR
pop(struct jsonparse_state *state)
{
if(state->depth == 0) {
return JSON_TYPE_ERROR;
}
state->depth--;
return state->stack[state->depth];
}
/*--------------------------------------------------------------------*/
/* will pass by the value and store the start and length of the value for
atomic types */
/*--------------------------------------------------------------------*/
static void ICACHE_FLASH_ATTR
atomic(struct jsonparse_state *state, char type)
{
char c;
state->vstart = state->pos;
state->vtype = type;
if(type == JSON_TYPE_STRING || type == JSON_TYPE_PAIR_NAME) {
while((c = state->json[state->pos++]) && c != '"') {
if(c == '\\') {
state->pos++; /* skip current char */
}
}
state->vlen = state->pos - state->vstart - 1;
} else if(type == JSON_TYPE_NUMBER) {
do {
c = state->json[state->pos];
if((c < '0' || c > '9') && c != '.') {
c = 0;
} else {
state->pos++;
}
} while(c);
/* need to back one step since first char is already gone */
state->vstart--;
state->vlen = state->pos - state->vstart;
}
/* no other types for now... */
}
/*--------------------------------------------------------------------*/
static void ICACHE_FLASH_ATTR
skip_ws(struct jsonparse_state *state)
{
char c;
while(state->pos < state->len &&
((c = state->json[state->pos]) == ' ' || c == '\n')) {
state->pos++;
}
}
/*--------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsonparse_setup(struct jsonparse_state *state, const char *json, int len)
{
state->json = json;
state->len = len;
state->pos = 0;
state->depth = 0;
state->error = 0;
state->stack[0] = 0;
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_next(struct jsonparse_state *state)
{
char c;
char s;
skip_ws(state);
c = state->json[state->pos];
s = jsonparse_get_type(state);
state->pos++;
switch(c) {
case '{':
push(state, c);
return c;
case '}':
if(s == ':' && state->vtype != 0) {
/* printf("Popping vtype: '%c'\n", state->vtype); */
pop(state);
s = jsonparse_get_type(state);
}
if(s == '{') {
pop(state);
} else {
state->error = JSON_ERROR_SYNTAX;
return JSON_TYPE_ERROR;
}
return c;
case ']':
if(s == '[') {
pop(state);
} else {
state->error = JSON_ERROR_UNEXPECTED_END_OF_ARRAY;
return JSON_TYPE_ERROR;
}
return c;
case ':':
push(state, c);
return c;
case ',':
/* if x:y ... , */
if(s == ':' && state->vtype != 0) {
pop(state);
} else if(s == '[') {
/* ok! */
} else {
state->error = JSON_ERROR_SYNTAX;
return JSON_TYPE_ERROR;
}
return c;
case '"':
if(s == '{' || s == '[' || s == ':') {
atomic(state, c = (s == '{' ? JSON_TYPE_PAIR_NAME : c));
} else {
state->error = JSON_ERROR_UNEXPECTED_STRING;
return JSON_TYPE_ERROR;
}
return c;
case '[':
if(s == '{' || s == '[' || s == ':') {
push(state, c);
} else {
state->error = JSON_ERROR_UNEXPECTED_ARRAY;
return JSON_TYPE_ERROR;
}
return c;
default:
if(s == ':' || s == '[') {
if(c <= '9' && c >= '0') {
atomic(state, JSON_TYPE_NUMBER);
return JSON_TYPE_NUMBER;
}
}
}
return 0;
}
/*--------------------------------------------------------------------*/
/* get the json value of the current position
* works only on "atomic" values such as string, number, null, false, true
*/
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_copy_value(struct jsonparse_state *state, char *str, int size)
{
int i;
char z = 0;
char y = 0;
if(state->vtype == 0) {
return 0;
}
size = size <= state->vlen ? (size - 1) : state->vlen;
for(i = 0; i < size; i++) {
if (y == 0 && state->json[state->vstart + i] == '\\') {
y = 1;
z++;
continue;
}
y = 0;
str[i - z] = state->json[state->vstart + i];
}
str[i - z] = 0;
return state->vtype;
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_get_value_as_int(struct jsonparse_state *state)
{
if(state->vtype != JSON_TYPE_NUMBER) {
return 0;
}
return atoi(&state->json[state->vstart]);
}
/*--------------------------------------------------------------------*/
long ICACHE_FLASH_ATTR
jsonparse_get_value_as_long(struct jsonparse_state *state)
{
if(state->vtype != JSON_TYPE_NUMBER) {
return 0;
}
return atol(&state->json[state->vstart]);
}
/*--------------------------------------------------------------------*/
unsigned long ICACHE_FLASH_ATTR
jsonparse_get_value_as_ulong(struct jsonparse_state *state)
{
if(state->vtype != JSON_TYPE_NUMBER) {
return 0;
}
return strtoul(&state->json[state->vstart], '\0', 0);
}
/*--------------------------------------------------------------------*/
/* strcmp - assume no strange chars that needs to be stuffed in string... */
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_strcmp_value(struct jsonparse_state *state, const char *str)
{
if(state->vtype == 0) {
return -1;
}
return os_strncmp(str, &state->json[state->vstart], state->vlen);
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_get_len(struct jsonparse_state *state)
{
return state->vlen;
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_get_type(struct jsonparse_state *state)
{
if(state->depth == 0) {
return 0;
}
return state->stack[state->depth - 1];
}
/*--------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsonparse_has_next(struct jsonparse_state *state)
{
return state->pos < state->len;
}
/*--------------------------------------------------------------------*/
#endif
/*
* Copyright (c) 2011-2012, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*/
/**
* \file
* JSON output generation
* \author
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#ifdef JSON_FORMAT
//#include "contiki.h"
#include "json/jsontree.h"
#include "json/jsonparse.h"
#include "osapi.h"
//#include <string.h>
#define DEBUG 0
#if DEBUG
//#include <stdio.h>
#define PRINTF(...) os_printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_atom(const struct jsontree_context *js_ctx, const char *text)
{
if(text == NULL) {
js_ctx->putchar('0');
} else {
while(*text != '\0') {
js_ctx->putchar(*text++);
}
}
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_string(const struct jsontree_context *js_ctx, const char *text)
{
js_ctx->putchar('"');
if(text != NULL) {
while(*text != '\0') {
if(*text == '"') {
js_ctx->putchar('\\');
}
js_ctx->putchar(*text++);
}
}
js_ctx->putchar('"');
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_int(const struct jsontree_context *js_ctx, int value)
{
char buf[10];
int l;
if(value < 0) {
js_ctx->putchar('-');
value = -value;
}
l = sizeof(buf) - 1;
do {
buf[l--] = '0' + (value % 10);
value /= 10;
} while(value > 0 && l >= 0);
while(++l < sizeof(buf)) {
js_ctx->putchar(buf[l]);
}
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_write_int_array(const struct jsontree_context *js_ctx, const int *text, uint32 length)
{
uint32 i = 0;
if(text == NULL) {
js_ctx->putchar('0');
} else {
for (i = 0; i < length - 1; i ++) {
jsontree_write_int(js_ctx, *text++);
js_ctx->putchar(',');
}
jsontree_write_int(js_ctx, *text);
}
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_setup(struct jsontree_context *js_ctx, struct jsontree_value *root,
int (* putchar)(int))
{
js_ctx->values[0] = root;
js_ctx->putchar = putchar;
js_ctx->path = 0;
jsontree_reset(js_ctx);
}
/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
jsontree_reset(struct jsontree_context *js_ctx)
{
js_ctx->depth = 0;
js_ctx->index[0] = 0;
}
/*---------------------------------------------------------------------------*/
const char *ICACHE_FLASH_ATTR
jsontree_path_name(const struct jsontree_context *js_ctx, int depth)
{
if(depth < js_ctx->depth && js_ctx->values[depth]->type == JSON_TYPE_OBJECT) {
return ((struct jsontree_object *)js_ctx->values[depth])->
pairs[js_ctx->index[depth]].name;
}
return "";
}
/*---------------------------------------------------------------------------*/
int ICACHE_FLASH_ATTR
jsontree_print_next(struct jsontree_context *js_ctx)
{
struct jsontree_value *v;
int index;
v = js_ctx->values[js_ctx->depth];
/* Default operation after switch is to back up one level */
switch(v->type) {
case JSON_TYPE_OBJECT:
case JSON_TYPE_ARRAY: {
struct jsontree_array *o = (struct jsontree_array *)v;
struct jsontree_value *ov;
index = js_ctx->index[js_ctx->depth];
if(index == 0) {
js_ctx->putchar(v->type);
js_ctx->putchar('\n');
}
if(index >= o->count) {
js_ctx->putchar('\n');
js_ctx->putchar(v->type + 2);
/* Default operation: back up one level! */
break;
}
if(index > 0) {
js_ctx->putchar(',');
js_ctx->putchar('\n');
}
if(v->type == JSON_TYPE_OBJECT) {
jsontree_write_string(js_ctx,
((struct jsontree_object *)o)->pairs[index].name);
js_ctx->putchar(':');
ov = ((struct jsontree_object *)o)->pairs[index].value;
} else {
ov = o->values[index];
}
/* TODO check max depth */
js_ctx->depth++; /* step down to value... */
js_ctx->index[js_ctx->depth] = 0; /* and init index */
js_ctx->values[js_ctx->depth] = ov;
/* Continue on this new level */
return 1;
}
case JSON_TYPE_STRING:
jsontree_write_string(js_ctx, ((struct jsontree_string *)v)->value);
/* Default operation: back up one level! */
break;
case JSON_TYPE_INT:
jsontree_write_int(js_ctx, ((struct jsontree_int *)v)->value);
/* Default operation: back up one level! */
break;
case JSON_TYPE_CALLBACK: { /* pre-formatted json string currently */
struct jsontree_callback *callback;
callback = (struct jsontree_callback *)v;
if(js_ctx->index[js_ctx->depth] == 0) {
/* First call: reset the callback status */
js_ctx->callback_state = 0;
}
if(callback->output == NULL) {
jsontree_write_string(js_ctx, "");
} else if(callback->output(js_ctx)) {
/* The callback wants to output more */
js_ctx->index[js_ctx->depth]++;
return 1;
}
/* Default operation: back up one level! */
break;
}
default:
PRINTF("\nError: Illegal json type:'%c'\n", v->type);
return 0;
}
/* Done => back up one level! */
if(js_ctx->depth > 0) {
js_ctx->depth--;
js_ctx->index[js_ctx->depth]++;
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static struct jsontree_value *ICACHE_FLASH_ATTR
find_next(struct jsontree_context *js_ctx)
{
struct jsontree_value *v;
int index;
do {
v = js_ctx->values[js_ctx->depth];
/* Default operation after switch is to back up one level */
switch(v->type) {
case JSON_TYPE_OBJECT:
case JSON_TYPE_ARRAY: {
struct jsontree_array *o = (struct jsontree_array *)v;
struct jsontree_value *ov;
index = js_ctx->index[js_ctx->depth];
if(index >= o->count) {
/* Default operation: back up one level! */
break;
}
if(v->type == JSON_TYPE_OBJECT) {
ov = ((struct jsontree_object *)o)->pairs[index].value;
} else {
ov = o->values[index];
}
/* TODO check max depth */
js_ctx->depth++; /* step down to value... */
js_ctx->index[js_ctx->depth] = 0; /* and init index */
js_ctx->values[js_ctx->depth] = ov;
/* Continue on this new level */
return ov;
}
default:
/* Default operation: back up one level! */
break;
}
/* Done => back up one level! */
if(js_ctx->depth > 0) {
js_ctx->depth--;
js_ctx->index[js_ctx->depth]++;
} else {
return NULL;
}
} while(1);
}
/*---------------------------------------------------------------------------*/
struct jsontree_value *ICACHE_FLASH_ATTR
jsontree_find_next(struct jsontree_context *js_ctx, int type)
{
struct jsontree_value *v;
while((v = find_next(js_ctx)) != NULL && v->type != type &&
js_ctx->path < js_ctx->depth) {
/* search */
}
js_ctx->callback_state = 0;
return js_ctx->path < js_ctx->depth ? v : NULL;
}
/*---------------------------------------------------------------------------*/
#endif
...@@ -38,7 +38,6 @@ endif ...@@ -38,7 +38,6 @@ endif
INCLUDES := $(INCLUDES) -I $(PDIR)include INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./ INCLUDES += -I ./
INCLUDES += -I ../wofs
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
...@@ -272,7 +272,6 @@ strtoupper(char *p) ...@@ -272,7 +272,6 @@ strtoupper(char *p)
//#include <string.h> //#include <string.h>
//#include <pmon.h> //#include <pmon.h>
#include "c_string.h" #include "c_string.h"
typedef int int32_t;
typedef unsigned int u_int32_t; typedef unsigned int u_int32_t;
typedef unsigned int u_int; typedef unsigned int u_int;
typedef unsigned long u_long; typedef unsigned long u_long;
...@@ -1095,12 +1094,14 @@ exponent(char *p, int exp, int fmtch) ...@@ -1095,12 +1094,14 @@ exponent(char *p, int exp, int fmtch)
#endif /* FLOATINGPT */ #endif /* FLOATINGPT */
void c_sprintf(char *s, char *fmt, ...) int c_sprintf(char *s, const char *fmt, ...)
{ {
int n;
va_list arg; va_list arg;
va_start(arg, fmt); va_start(arg, fmt);
vsprintf(s, fmt, arg); n = vsprintf(s, fmt, arg);
va_end(arg); va_end(arg);
return n;
} }
#endif #endif
...@@ -60,10 +60,10 @@ extern void output_redirect(const char *str); ...@@ -60,10 +60,10 @@ extern void output_redirect(const char *str);
#define c_sprintf os_sprintf #define c_sprintf os_sprintf
#else #else
#include "c_stdarg.h" #include "c_stdarg.h"
void c_sprintf(char* s,char *fmt, ...); int c_sprintf(char* s,const char *fmt, ...);
#endif #endif
// #define c_vsprintf ets_vsprintf #define c_vsprintf ets_vsprintf
#define c_printf(...) do { \ #define c_printf(...) do { \
unsigned char __print_buf[BUFSIZ]; \ unsigned char __print_buf[BUFSIZ]; \
c_sprintf(__print_buf, __VA_ARGS__); \ c_sprintf(__print_buf, __VA_ARGS__); \
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "c_stddef.h" #include "c_stddef.h"
#include "mem.h" #include "mem.h"
#include <stdlib.h>
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
......
#include "c_string.h" #include "c_string.h"
#include "c_stdlib.h"
// const char *c_strstr(const char * __s1, const char * __s2){ // const char *c_strstr(const char * __s1, const char * __s2){
// } // }
...@@ -14,3 +15,115 @@ ...@@ -14,3 +15,115 @@
// int c_strcoll(const char * s1, const char * s2){ // int c_strcoll(const char * s1, const char * s2){
// } // }
//
char *c_strdup(const char *c) {
int len = os_strlen(c) + 1;
char *ret = os_malloc(len);
if (ret) {
memcpy(ret, c, len);
}
return ret;
}
/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
c_strlcpy(char *dst, const char *src, size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t
c_strlcat(char *dst, const char *src, size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}
...@@ -39,5 +39,11 @@ ...@@ -39,5 +39,11 @@
// size_t c_strcspn(const char * s1, const char * s2); // size_t c_strcspn(const char * s1, const char * s2);
// const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/); // const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/);
// int c_strcoll(const char * /*s1*/, const char * /*s2*/); // int c_strcoll(const char * /*s1*/, const char * /*s2*/);
//
extern size_t c_strlcpy(char *dst, const char *src, size_t siz);
extern size_t c_strlcat(char *dst, const char *src, size_t siz);
extern char *c_strdup(const char *src);
#endif /* _C_STRING_H_ */ #endif /* _C_STRING_H_ */
...@@ -15,6 +15,8 @@ ifndef PDIR ...@@ -15,6 +15,8 @@ ifndef PDIR
GEN_LIBS = liblua.a GEN_LIBS = liblua.a
endif endif
STD_CFLAGS=-std=gnu11 -Wimplicit
############################################################# #############################################################
# Configuration i.e. compile options etc. # Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here! # Target specific stuff (defines etc.) goes in here!
...@@ -38,7 +40,6 @@ endif ...@@ -38,7 +40,6 @@ endif
INCLUDES := $(INCLUDES) -I $(PDIR)include INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./ INCLUDES += -I ./
INCLUDES += -I ../wofs
INCLUDES += -I ../spiffs INCLUDES += -I ../spiffs
INCLUDES += -I ../libc INCLUDES += -I ../libc
INCLUDES += -I ../modules INCLUDES += -I ../modules
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment