Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
7b83bbb2
Commit
7b83bbb2
authored
Oct 01, 2016
by
Arnim Läuger
Committed by
GitHub
Oct 01, 2016
Browse files
Merge pull request #1519 from nodemcu/dev
Next 1.5.4.1 master drop
parents
8e48483c
d96d7f23
Changes
134
Show whitespace changes
Inline
Side-by-side
app/http/httpclient.c
View file @
7b83bbb2
...
...
@@ -20,6 +20,8 @@
#include "httpclient.h"
#include "stdlib.h"
#define REDIRECTION_FOLLOW_MAX 20
/* Internal state. */
typedef
struct
request_args_t
{
char
*
hostname
;
...
...
@@ -31,6 +33,7 @@ typedef struct request_args_t {
char
*
post_data
;
char
*
buffer
;
int
buffer_size
;
int
redirect_follow_count
;
int
timeout
;
os_timer_t
timeout_timer
;
http_callback_t
callback_handle
;
...
...
@@ -181,7 +184,6 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
HTTPCLIENT_DEBUG
(
"Connected
\n
"
);
struct
espconn
*
conn
=
(
struct
espconn
*
)
arg
;
request_args_t
*
req
=
(
request_args_t
*
)
conn
->
reverse
;
int
len
;
espconn_regist_recvcb
(
conn
,
http_receive_callback
);
espconn_regist_sentcb
(
conn
,
http_send_callback
);
...
...
@@ -198,37 +200,55 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
req
->
headers
[
0
]
=
'\0'
;
}
char
buf
[
69
+
strlen
(
req
->
method
)
+
strlen
(
req
->
path
)
+
strlen
(
req
->
hostname
)
+
strlen
(
req
->
headers
)
+
strlen
(
post_headers
)];
char
ua_header
[
32
]
=
""
;
int
ua_len
=
0
;
if
(
os_strstr
(
req
->
headers
,
"User-Agent:"
)
==
NULL
&&
os_strstr
(
req
->
headers
,
"user-agent:"
)
==
NULL
)
{
os_sprintf
(
ua_header
,
"User-Agent: %s
\r\n
"
,
"ESP8266"
);
ua_len
=
strlen
(
ua_header
);
}
char
host_header
[
32
]
=
""
;
int
host_len
=
0
;
if
(
os_strstr
(
req
->
headers
,
"Host:"
)
==
NULL
&&
os_strstr
(
req
->
headers
,
"host:"
)
==
NULL
)
{
if
((
req
->
port
==
80
)
||
((
req
->
port
==
443
)
&&
(
req
->
secure
)))
{
len
=
os_sprintf
(
buf
,
"%s %s HTTP/1.1
\r\n
"
"Host: %s
\r\n
"
"Connection: close
\r\n
"
"User-Agent: ESP8266
\r\n
"
"%s"
"%s"
"
\r\n
"
,
req
->
method
,
req
->
path
,
req
->
hostname
,
req
->
headers
,
post_headers
);
}
else
{
len
=
os_sprintf
(
buf
,
os_sprintf
(
host_header
,
"Host: %s
\r\n
"
,
req
->
hostname
);
}
else
{
os_sprintf
(
host_header
,
"Host: %s:%d
\r\n
"
,
req
->
hostname
,
req
->
port
);
}
host_len
=
strlen
(
host_header
);
}
char
buf
[
69
+
strlen
(
req
->
method
)
+
strlen
(
req
->
path
)
+
host_len
+
strlen
(
req
->
headers
)
+
ua_len
+
strlen
(
post_headers
)];
int
len
=
os_sprintf
(
buf
,
"%s %s HTTP/1.1
\r\n
"
"Host: %s:%d
\r\n
"
"%s"
// Host (if not provided in the headers from Lua)
"Connection: close
\r\n
"
"User-Agent: ESP8266
\r\n
"
"%s"
"%s"
"%s"
// Headers from Lua (optional)
"%s"
// User-Agent (if not provided in the headers from Lua)
"%s"
// Content-Length
"
\r\n
"
,
req
->
method
,
req
->
path
,
req
->
hostname
,
req
->
port
,
req
->
headers
,
post_headers
);
}
if
(
req
->
secure
)
req
->
method
,
req
->
path
,
host_header
,
req
->
headers
,
ua_header
,
post_headers
);
if
(
req
->
secure
)
{
espconn_secure_send
(
conn
,
(
uint8_t
*
)
buf
,
len
);
}
else
{
espconn_send
(
conn
,
(
uint8_t
*
)
buf
,
len
);
if
(
req
->
headers
!=
NULL
)
}
if
(
req
->
headers
!=
NULL
)
{
os_free
(
req
->
headers
);
}
req
->
headers
=
NULL
;
HTTPCLIENT_DEBUG
(
"Sending request header
\n
"
);
}
...
...
@@ -290,6 +310,71 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
else
{
http_status
=
atoi
(
req
->
buffer
+
strlen
(
version_1_0
)
);
char
*
locationOffset
=
(
char
*
)
os_strstr
(
req
->
buffer
,
"Location:"
);
if
(
locationOffset
==
NULL
)
{
locationOffset
=
(
char
*
)
os_strstr
(
req
->
buffer
,
"location:"
);
}
if
(
locationOffset
!=
NULL
&&
http_status
>=
300
&&
http_status
<=
308
)
{
if
(
req
->
redirect_follow_count
<
REDIRECTION_FOLLOW_MAX
)
{
locationOffset
+=
strlen
(
"location:"
);
while
(
*
locationOffset
==
' '
)
{
// skip url leading white-space
locationOffset
++
;
}
char
*
locationOffsetEnd
=
(
char
*
)
os_strstr
(
locationOffset
,
"
\r\n
"
);
if
(
locationOffsetEnd
==
NULL
)
{
HTTPCLIENT_DEBUG
(
"Found Location header but was incomplete
\n
"
);
http_status
=
-
1
;
}
else
{
*
locationOffsetEnd
=
'\0'
;
req
->
redirect_follow_count
++
;
// Check if url is absolute
bool
url_has_protocol
=
os_strncmp
(
locationOffset
,
"http://"
,
strlen
(
"http://"
)
)
==
0
||
os_strncmp
(
locationOffset
,
"https://"
,
strlen
(
"https://"
)
)
==
0
;
if
(
url_has_protocol
)
{
http_request
(
locationOffset
,
req
->
method
,
req
->
headers
,
req
->
post_data
,
req
->
callback_handle
,
req
->
redirect_follow_count
);
}
else
{
if
(
os_strncmp
(
locationOffset
,
"/"
,
1
)
==
0
)
{
// relative and full path
http_raw_request
(
req
->
hostname
,
req
->
port
,
req
->
secure
,
req
->
method
,
locationOffset
,
req
->
headers
,
req
->
post_data
,
req
->
callback_handle
,
req
->
redirect_follow_count
);
}
else
{
// relative and relative path
// find last /
const
char
*
pathFolderEnd
=
strrchr
(
req
->
path
,
'/'
);
int
pathFolderLength
=
pathFolderEnd
-
req
->
path
;
pathFolderLength
++
;
// use the '/'
int
locationLength
=
strlen
(
locationOffset
);
locationLength
++
;
// use the '\0'
// append pathFolder with given relative path
char
*
completeRelativePath
=
(
char
*
)
os_malloc
(
pathFolderLength
+
locationLength
);
os_memcpy
(
completeRelativePath
,
req
->
path
,
pathFolderLength
);
os_memcpy
(
completeRelativePath
+
pathFolderLength
,
locationOffset
,
locationLength
);
http_raw_request
(
req
->
hostname
,
req
->
port
,
req
->
secure
,
req
->
method
,
completeRelativePath
,
req
->
headers
,
req
->
post_data
,
req
->
callback_handle
,
req
->
redirect_follow_count
);
os_free
(
completeRelativePath
);
}
}
http_free_req
(
req
);
espconn_delete
(
conn
);
os_free
(
conn
);
return
;
}
}
else
{
HTTPCLIENT_DEBUG
(
"Too many redirections
\n
"
);
http_status
=
-
1
;
}
}
else
{
body
=
(
char
*
)
os_strstr
(
req
->
buffer
,
"
\r\n\r\n
"
);
if
(
NULL
==
body
)
{
...
...
@@ -313,6 +398,7 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
}
}
}
}
if
(
req
->
callback_handle
!=
NULL
)
/* Callback is optional. */
{
req
->
callback_handle
(
body
,
http_status
,
req
->
buffer
);
...
...
@@ -391,7 +477,6 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
if
(
req
->
secure
)
{
espconn_secure_set_size
(
ESPCONN_CLIENT
,
5120
);
/* set SSL buffer size */
espconn_secure_connect
(
conn
);
}
else
...
...
@@ -402,7 +487,7 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
}
void
ICACHE_FLASH_ATTR
http_raw_request
(
const
char
*
hostname
,
int
port
,
bool
secure
,
const
char
*
method
,
const
char
*
path
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
)
void
ICACHE_FLASH_ATTR
http_raw_request
(
const
char
*
hostname
,
int
port
,
bool
secure
,
const
char
*
method
,
const
char
*
path
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
,
int
redirect_follow_count
)
{
HTTPCLIENT_DEBUG
(
"DNS request
\n
"
);
...
...
@@ -419,6 +504,7 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s
req
->
buffer
[
0
]
=
'\0'
;
/* Empty string. */
req
->
callback_handle
=
callback_handle
;
req
->
timeout
=
HTTP_REQUEST_TIMEOUT_MS
;
req
->
redirect_follow_count
=
redirect_follow_count
;
ip_addr_t
addr
;
err_t
error
=
espconn_gethostbyname
(
(
struct
espconn
*
)
req
,
/* It seems we don't need a real espconn pointer here. */
...
...
@@ -451,7 +537,7 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s
* <host> can be a hostname or an IP address
* <port> is optional
*/
void
ICACHE_FLASH_ATTR
http_request
(
const
char
*
url
,
const
char
*
method
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
)
void
ICACHE_FLASH_ATTR
http_request
(
const
char
*
url
,
const
char
*
method
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
,
int
redirect_follow_count
)
{
/*
* FIXME: handle HTTP auth with http://user:pass@host/
...
...
@@ -524,7 +610,7 @@ void ICACHE_FLASH_ATTR http_request( const char * url, const char * method, cons
HTTPCLIENT_DEBUG
(
"port=%d
\n
"
,
port
);
HTTPCLIENT_DEBUG
(
"method=%s
\n
"
,
method
);
HTTPCLIENT_DEBUG
(
"path=%s
\n
"
,
path
);
http_raw_request
(
hostname
,
port
,
secure
,
method
,
path
,
headers
,
post_data
,
callback_handle
);
http_raw_request
(
hostname
,
port
,
secure
,
method
,
path
,
headers
,
post_data
,
callback_handle
,
redirect_follow_count
);
}
...
...
@@ -535,25 +621,25 @@ void ICACHE_FLASH_ATTR http_request( const char * url, const char * method, cons
*/
void
ICACHE_FLASH_ATTR
http_post
(
const
char
*
url
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
)
{
http_request
(
url
,
"POST"
,
headers
,
post_data
,
callback_handle
);
http_request
(
url
,
"POST"
,
headers
,
post_data
,
callback_handle
,
0
);
}
void
ICACHE_FLASH_ATTR
http_get
(
const
char
*
url
,
const
char
*
headers
,
http_callback_t
callback_handle
)
{
http_request
(
url
,
"GET"
,
headers
,
NULL
,
callback_handle
);
http_request
(
url
,
"GET"
,
headers
,
NULL
,
callback_handle
,
0
);
}
void
ICACHE_FLASH_ATTR
http_delete
(
const
char
*
url
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
)
{
http_request
(
url
,
"DELETE"
,
headers
,
post_data
,
callback_handle
);
http_request
(
url
,
"DELETE"
,
headers
,
post_data
,
callback_handle
,
0
);
}
void
ICACHE_FLASH_ATTR
http_put
(
const
char
*
url
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
)
{
http_request
(
url
,
"PUT"
,
headers
,
post_data
,
callback_handle
);
http_request
(
url
,
"PUT"
,
headers
,
post_data
,
callback_handle
,
0
);
}
...
...
app/http/httpclient.h
View file @
7b83bbb2
...
...
@@ -51,15 +51,15 @@ typedef void (* http_callback_t)(char * response_body, int http_status, char * f
/*
* Call this function to skip URL parsing if the arguments are already in separate variables.
*/
void
ICACHE_FLASH_ATTR
http_raw_request
(
const
char
*
hostname
,
int
port
,
bool
secure
,
const
char
*
method
,
const
char
*
path
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
);
void
ICACHE_FLASH_ATTR
http_raw_request
(
const
char
*
hostname
,
int
port
,
bool
secure
,
const
char
*
method
,
const
char
*
path
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
,
int
redirect_follow_count
);
/*
* Request data from URL use custom method.
* The data should be encoded as any format.
* Try:
* http_request("http://httpbin.org/post", "OPTIONS", "Content-type: text/plain", "Hello world", http_callback_example);
* http_request("http://httpbin.org/post", "OPTIONS", "Content-type: text/plain", "Hello world", http_callback_example
, 0
);
*/
void
ICACHE_FLASH_ATTR
http_request
(
const
char
*
url
,
const
char
*
method
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
);
void
ICACHE_FLASH_ATTR
http_request
(
const
char
*
url
,
const
char
*
method
,
const
char
*
headers
,
const
char
*
post_data
,
http_callback_t
callback_handle
,
int
redirect_follow_count
);
/*
* Post data to a web form.
...
...
app/include/driver/spi.h
View file @
7b83bbb2
...
...
@@ -11,6 +11,9 @@
#define SPI 0
#define HSPI 1
#define SPI_ORDER_LSB 0
#define SPI_ORDER_MSB 1
//lcd drive function
...
...
@@ -18,7 +21,13 @@ void spi_lcd_mode_init(uint8 spi_no);
void
spi_lcd_9bit_write
(
uint8
spi_no
,
uint8
high_bit
,
uint8
low_8bit
);
//spi master init funtion
uint32_t
spi_set_clkdiv
(
uint8
spi_no
,
uint32_t
clock_div
);
void
spi_master_init
(
uint8
spi_no
,
unsigned
cpol
,
unsigned
cpha
,
uint32_t
clock_div
);
void
spi_mast_byte_order
(
uint8
spi_no
,
uint8
order
);
// blocked buffer write
void
spi_mast_blkset
(
uint8
spi_no
,
size_t
bitlen
,
const
uint8
*
data
);
// blocked buffer read
void
spi_mast_blkget
(
uint8
spi_no
,
size_t
bitlen
,
uint8
*
data
);
// fill MOSI buffer
void
spi_mast_set_mosi
(
uint8
spi_no
,
uint16
offset
,
uint8
bitlen
,
uint32
data
);
// retrieve data from MISO buffer
...
...
app/include/driver/uart.h
View file @
7b83bbb2
...
...
@@ -108,5 +108,6 @@ void uart0_putc(const char c);
void
uart0_tx_buffer
(
uint8
*
buf
,
uint16
len
);
void
uart_setup
(
uint8
uart_no
);
STATUS
uart_tx_one_char
(
uint8
uart
,
uint8
TxChar
);
void
uart_set_alt_output_uart0
(
void
(
*
fn
)(
char
));
#endif
app/include/fatfs_config.h
0 → 100644
View file @
7b83bbb2
#ifndef __FATFS_CONFIG_H__
#define __FATFS_CONFIG_H__
// don't redefine the PARTITION type
#ifndef _FATFS
typedef
struct
{
BYTE
pd
;
/* Physical drive number */
BYTE
pt
;
/* Partition: 0:Auto detect, 1-4:Forced partition) */
}
PARTITION
;
#endif
// Table to map physical drive & partition to a logical volume.
// The first value is the physical drive and contains the GPIO pin for SS/CS of the SD card (default pin 8)
// The second value is the partition number.
#define NUM_LOGICAL_DRIVES 4
PARTITION
VolToPart
[
NUM_LOGICAL_DRIVES
]
=
{
{
8
,
1
},
/* Logical drive "0:" ==> SS pin 8, 1st partition */
{
8
,
2
},
/* Logical drive "1:" ==> SS pin 8, 2st partition */
{
8
,
3
},
/* Logical drive "2:" ==> SS pin 8, 3st partition */
{
8
,
4
}
/* Logical drive "3:" ==> SS pin 8, 4st partition */
};
#endif
/* __FATFS_CONFIG_H__ */
app/include/lwip/app/dhcpserver.h
View file @
7b83bbb2
#ifndef __DHCPS_H__
#define __DHCPS_H__
#include "lwipopts.h"
#define USE_DNS
typedef
struct
dhcps_state
{
...
...
@@ -19,7 +21,9 @@ typedef struct dhcps_msg {
uint8_t
chaddr
[
16
];
uint8_t
sname
[
64
];
uint8_t
file
[
128
];
uint8_t
options
[
312
];
// Recommendation from Espressif:
// To avoid crash in DHCP big packages modify option length from 312 to MTU - IPHEAD(20) - UDPHEAD(8) - DHCPHEAD(236).
uint8_t
options
[
IP_FRAG_MAX_MTU
-
20
-
8
-
236
];
}
dhcps_msg
;
#ifndef LWIP_OPEN_SRC
...
...
app/include/lwip/udp.h
View file @
7b83bbb2
...
...
@@ -156,6 +156,11 @@ void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_
#define udp_init()
/* Compatibility define, not init needed. */
#ifndef UDP_LOCAL_PORT_RANGE_START
#define UDP_LOCAL_PORT_RANGE_START 4096
#define UDP_LOCAL_PORT_RANGE_END 0x7fff
#endif
#if UDP_DEBUG
void
udp_debug_print
(
struct
udp_hdr
*
udphdr
)
ICACHE_FLASH_ATTR
;
#else
...
...
app/include/user_config.h
View file @
7b83bbb2
#ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__
// #define DEVKIT_VERSION_0_9 1 // define this only if you use NodeMCU devkit v0.9
// #define FLASH_512K
// #define FLASH_1M
// #define FLASH_2M
...
...
@@ -62,13 +60,22 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define NO_INTR_CODE inline
#endif
// SSL buffer size used only for espconn-layer secure connections.
// See https://github.com/nodemcu/nodemcu-firmware/issues/1457 for conversation details.
#define SSL_BUFFER_SIZE 5120
//#define CLIENT_SSL_ENABLE
//#define MD2_ENABLE
#define SHA2_ENABLE
#define BUILD_SPIFFS
1
#define BUILD_SPIFFS
#define SPIFFS_CACHE 1
//#define BUILD_FATFS
// maximum length of a filename
#define FS_OBJ_NAME_LEN 31
// Uncomment this next line for fastest startup
// It reduces the format time dramatically
// #define SPIFFS_MAX_FILESYSTEM_SIZE 32768
...
...
@@ -87,18 +94,6 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define LUA_PROCESS_LINE_SIG 2
#define LUA_OPTIMIZE_DEBUG 2
#ifdef DEVKIT_VERSION_0_9
#define KEYLED_INTERVAL 80
#define KEY_SHORT_MS 200
#define KEY_LONG_MS 3000
#define KEY_SHORT_COUNT (KEY_SHORT_MS / READLINE_INTERVAL)
#define KEY_LONG_COUNT (KEY_LONG_MS / READLINE_INTERVAL)
#define LED_HIGH_COUNT_DEFAULT 10
#define LED_LOW_COUNT_DEFAULT 0
#endif
#define ENDUSER_SETUP_AP_SSID "SetupGadget"
/*
...
...
app/include/user_modules.h
View file @
7b83bbb2
...
...
@@ -31,6 +31,7 @@
//#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_FILE
//#define LUA_USE_MODULES_GDBSTUB
#define LUA_USE_MODULES_GPIO
//#define LUA_USE_MODULES_HMC5883L
//#define LUA_USE_MODULES_HTTP
...
...
@@ -61,6 +62,7 @@
//#define LUA_USE_MODULES_U8G
#define LUA_USE_MODULES_UART
//#define LUA_USE_MODULES_UCG
//#define LUA_USE_MODULES_WEBSOCKET
#define LUA_USE_MODULES_WIFI
//#define LUA_USE_MODULES_WS2801
//#define LUA_USE_MODULES_WS2812
...
...
app/libc/c_math.c
View file @
7b83bbb2
...
...
@@ -4,7 +4,7 @@
double
floor
(
double
x
)
{
return
(
double
)
(
x
<
0
.
f
?
(((
int
)
x
)
-
1
)
:
((
int
)
x
));
return
(
double
)
(
x
<
0
.
f
?
((
int
)
x
==
x
?
x
:
(((
int
)
x
)
-
1
)
)
:
((
int
)
x
));
}
#define MAXEXP 2031
/* (MAX_EXP * 16) - 1 */
...
...
@@ -59,6 +59,7 @@ double pow(double x, double y)
{
double
frexp
(),
g
,
ldexp
(),
r
,
u1
,
u2
,
v
,
w
,
w1
,
w2
,
y1
,
y2
,
z
;
int
iw1
,
m
,
p
;
bool
flipsignal
=
false
;
if
(
y
==
0
.
0
)
return
(
1
.
0
);
...
...
@@ -67,7 +68,7 @@ double pow(double x, double y)
if
(
x
==
0
.
0
)
{
if
(
y
>
0
.
0
)
return
(
x
)
;
return
0
.
0
;
//cmemsg(FP_POWO, &y);
//return(HUGE);
}
...
...
@@ -75,6 +76,11 @@ double pow(double x, double y)
{
//cmemsg(FP_POWN, &x);
x
=
-
x
;
if
(
y
!=
(
int
)
y
)
{
// if y is fractional, then this woud result in a complex number
return
NAN
;
}
flipsignal
=
((
int
)
y
)
&
1
;
}
}
g
=
frexp
(
x
,
&
m
);
...
...
@@ -125,7 +131,8 @@ double pow(double x, double y)
p
=
16
*
m
-
iw1
;
z
=
((((((
q7
*
w2
+
q6
)
*
w2
+
q5
)
*
w2
+
q4
)
*
w2
+
q3
)
*
w2
+
q2
)
*
w2
+
q1
)
*
w2
;
z
=
a1
[
p
]
+
a1
[
p
]
*
z
;
return
(
ldexp
(
z
,
m
));
double
res
=
ldexp
(
z
,
m
);
return
flipsignal
?
-
res
:
res
;
}
#if 0
...
...
app/lua/lauxlib.c
View file @
7b83bbb2
...
...
@@ -13,7 +13,7 @@
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#ifndef LUA_CROSS_COMPILER
#include "
flash_
fs.h"
#include "
v
fs.h"
#else
#endif
...
...
@@ -671,8 +671,8 @@ static const char *getFSF (lua_State *L, void *ud, size_t *size) {
return
"
\n
"
;
}
if
(
fs_eof
(
lf
->
f
))
return
NULL
;
*
size
=
fs_read
(
lf
->
f
,
lf
->
buff
,
sizeof
(
lf
->
buff
));
if
(
v
fs_eof
(
lf
->
f
))
return
NULL
;
*
size
=
v
fs_read
(
lf
->
f
,
lf
->
buff
,
sizeof
(
lf
->
buff
));
return
(
*
size
>
0
)
?
lf
->
buff
:
NULL
;
}
...
...
@@ -697,29 +697,29 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) {
}
else
{
lua_pushfstring
(
L
,
"@%s"
,
filename
);
lf
.
f
=
fs_open
(
filename
,
FS_RDONLY
);
if
(
lf
.
f
<
FS_OPEN_OK
)
return
errfsfile
(
L
,
"open"
,
fnameindex
);
lf
.
f
=
v
fs_open
(
filename
,
"r"
);
if
(
!
lf
.
f
)
return
errfsfile
(
L
,
"open"
,
fnameindex
);
}
// if(fs_size(lf.f)>LUAL_BUFFERSIZE)
// return luaL_error(L, "file is too big");
c
=
fs_getc
(
lf
.
f
);
c
=
v
fs_getc
(
lf
.
f
);
if
(
c
==
'#'
)
{
/* Unix exec. file? */
lf
.
extraline
=
1
;
while
((
c
=
fs_getc
(
lf
.
f
))
!=
EOF
&&
c
!=
'\n'
)
;
/* skip first line */
if
(
c
==
'\n'
)
c
=
fs_getc
(
lf
.
f
);
while
((
c
=
v
fs_getc
(
lf
.
f
))
!=
VFS_
EOF
&&
c
!=
'\n'
)
;
/* skip first line */
if
(
c
==
'\n'
)
c
=
v
fs_getc
(
lf
.
f
);
}
if
(
c
==
LUA_SIGNATURE
[
0
]
&&
filename
)
{
/* binary file? */
fs_close
(
lf
.
f
);
lf
.
f
=
fs_open
(
filename
,
FS_RDONLY
);
/* reopen in binary mode */
if
(
lf
.
f
<
FS_OPEN_OK
)
return
errfsfile
(
L
,
"reopen"
,
fnameindex
);
v
fs_close
(
lf
.
f
);
lf
.
f
=
v
fs_open
(
filename
,
"r"
);
/* reopen in binary mode */
if
(
!
lf
.
f
)
return
errfsfile
(
L
,
"reopen"
,
fnameindex
);
/* skip eventual `#!...' */
while
((
c
=
fs_getc
(
lf
.
f
))
!=
EOF
&&
c
!=
LUA_SIGNATURE
[
0
])
;
while
((
c
=
v
fs_getc
(
lf
.
f
))
!=
VFS_
EOF
&&
c
!=
LUA_SIGNATURE
[
0
])
;
lf
.
extraline
=
0
;
}
fs_ungetc
(
c
,
lf
.
f
);
v
fs_ungetc
(
c
,
lf
.
f
);
status
=
lua_load
(
L
,
getFSF
,
&
lf
,
lua_tostring
(
L
,
-
1
));
if
(
filename
)
fs_close
(
lf
.
f
);
/* close file (even in case of errors) */
if
(
filename
)
v
fs_close
(
lf
.
f
);
/* close file (even in case of errors) */
lua_remove
(
L
,
fnameindex
);
return
status
;
}
...
...
app/lua/liolib.c
View file @
7b83bbb2
...
...
@@ -9,7 +9,7 @@
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "
flash_
fs.h"
#include "
v
fs.h"
#define liolib_c
#define LUA_LIB
...
...
@@ -39,7 +39,7 @@ static const int liolib_keys[] = {(int)&luaL_callmeta, (int)&luaL_typerror, (int
static
const
char
*
const
fnames
[]
=
{
"input"
,
"output"
};
static
int
pushresult
(
lua_State
*
L
,
int
i
,
const
char
*
filename
)
{
int
en
=
fs_erro
r
(
0
);
/* calls to Lua API may change this value */
int
en
=
v
fs_
f
err
n
o
(
0
);
/* calls to Lua API may change this value */
if
(
i
)
{
lua_pushboolean
(
L
,
1
);
return
1
;
...
...
@@ -57,7 +57,7 @@ static int pushresult (lua_State *L, int i, const char *filename) {
static
void
fileerror
(
lua_State
*
L
,
int
arg
,
const
char
*
filename
)
{
lua_pushfstring
(
L
,
"%s: err(%d)"
,
filename
,
fs_erro
r
(
0
));
lua_pushfstring
(
L
,
"%s: err(%d)"
,
filename
,
v
fs_
f
err
n
o
(
0
));
luaL_argerror
(
L
,
arg
,
lua_tostring
(
L
,
-
1
));
}
...
...
@@ -130,7 +130,7 @@ static int io_pclose (lua_State *L) {
*/
static
int
io_fclose
(
lua_State
*
L
)
{
int
*
p
=
tofilep
(
L
);
int
ok
=
(
fs_close
(
*
p
)
==
0
);
int
ok
=
(
v
fs_close
(
*
p
)
==
0
);
*
p
=
FS_OPEN_OK
-
1
;
return
pushresult
(
L
,
ok
,
NULL
);
}
...
...
@@ -149,7 +149,7 @@ static int aux_close (lua_State *L) {
lua_pushliteral
(
L
,
"cannot close standard file"
);
return
2
;
}
int
ok
=
(
fs_close
(
*
p
)
==
0
);
int
ok
=
(
v
fs_close
(
*
p
)
==
0
);
*
p
=
FS_OPEN_OK
-
1
;
return
pushresult
(
L
,
ok
,
NULL
);
#endif
...
...
@@ -187,7 +187,7 @@ static int io_open (lua_State *L) {
const
char
*
filename
=
luaL_checkstring
(
L
,
1
);
const
char
*
mode
=
luaL_optstring
(
L
,
2
,
"r"
);
int
*
pf
=
newfile
(
L
);
*
pf
=
fs_open
(
filename
,
fs_
mode
2flag
(
mode
)
);
*
pf
=
v
fs_open
(
filename
,
mode
);
return
(
*
pf
==
FS_OPEN_OK
-
1
)
?
pushresult
(
L
,
0
,
filename
)
:
1
;
}
...
...
@@ -201,7 +201,7 @@ static int io_popen (lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
int *pf = newfile(L);
*pf = lua_popen(L, filename, fs_mode2flag(mode));
*pf = lua_popen(L, filename, fs_mode2flag
s
(mode));
return (*pf == FS_OPEN_OK - 1) ? pushresult(L, 0, filename) : 1;
}
...
...
@@ -230,7 +230,7 @@ static int g_iofile (lua_State *L, int f, const char *mode) {
const
char
*
filename
=
lua_tostring
(
L
,
1
);
if
(
filename
)
{
int
*
pf
=
newfile
(
L
);
*
pf
=
fs_open
(
filename
,
fs_
mode
2flag
(
mode
)
);
*
pf
=
v
fs_open
(
filename
,
mode
);
if
(
*
pf
==
FS_OPEN_OK
-
1
)
fileerror
(
L
,
1
,
filename
);
}
...
...
@@ -282,7 +282,7 @@ static int io_lines (lua_State *L) {
else
{
const
char
*
filename
=
luaL_checkstring
(
L
,
1
);
int
*
pf
=
newfile
(
L
);
*
pf
=
fs_open
(
filename
,
FS_RDONLY
);
*
pf
=
v
fs_open
(
filename
,
"r"
);
if
(
*
pf
==
FS_OPEN_OK
-
1
)
fileerror
(
L
,
1
,
filename
);
aux_lines
(
L
,
lua_gettop
(
L
),
1
);
...
...
@@ -312,8 +312,8 @@ static int read_number (lua_State *L, int f) {
#endif
static
int
test_eof
(
lua_State
*
L
,
int
f
)
{
int
c
=
fs_getc
(
f
);
fs_ungetc
(
c
,
f
);
int
c
=
v
fs_getc
(
f
);
v
fs_ungetc
(
c
,
f
);
lua_pushlstring
(
L
,
NULL
,
0
);
return
(
c
!=
EOF
);
}
...
...
@@ -347,7 +347,7 @@ static int read_line (lua_State *L, int f) {
signed
char
c
=
EOF
;
int
i
=
0
;
do
{
c
=
(
signed
char
)
fs_getc
(
f
);
c
=
(
signed
char
)
v
fs_getc
(
f
);
if
(
c
==
EOF
){
break
;
}
...
...
@@ -377,7 +377,7 @@ static int read_chars (lua_State *L, int f, size_t n) {
do
{
char
*
p
=
luaL_prepbuffer
(
&
b
);
if
(
rlen
>
n
)
rlen
=
n
;
/* cannot read more than asked */
nr
=
fs_read
(
f
,
p
,
rlen
);
nr
=
v
fs_read
(
f
,
p
,
rlen
);
luaL_addsize
(
&
b
,
nr
);
n
-=
nr
;
/* still have to read `n' chars */
}
while
(
n
>
0
&&
nr
==
rlen
);
/* until end of count or eof */
...
...
@@ -390,7 +390,7 @@ static int g_read (lua_State *L, int f, int first) {
int
nargs
=
lua_gettop
(
L
)
-
1
;
int
success
;
int
n
;
fs_clearerr
(
f
);
//v
fs_clearerr(f);
if
(
nargs
==
0
)
{
/* no arguments? */
success
=
read_line
(
L
,
f
);
n
=
first
+
1
;
/* to return 1 result */
...
...
@@ -425,7 +425,7 @@ static int g_read (lua_State *L, int f, int first) {
}
}
}
if
(
fs_erro
r
(
f
))
if
(
v
fs_
f
err
n
o
(
f
))
return
pushresult
(
L
,
0
,
NULL
);
if
(
!
success
)
{
lua_pop
(
L
,
1
);
/* remove last result */
...
...
@@ -453,8 +453,8 @@ static int io_readline (lua_State *L) {
return
0
;
}
sucess
=
read_line
(
L
,
*
pf
);
if
(
fs_erro
r
(
*
pf
))
return
luaL_error
(
L
,
"err(%d)"
,
fs_erro
r
(
*
pf
));
if
(
v
fs_
f
err
n
o
(
*
pf
))
return
luaL_error
(
L
,
"err(%d)"
,
v
fs_
f
err
n
o
(
*
pf
));
if
(
sucess
)
return
1
;
else
{
/* EOF */
if
(
lua_toboolean
(
L
,
lua_upvalueindex
(
2
)))
{
/* generator created file? */
...
...
@@ -484,7 +484,7 @@ static int g_write (lua_State *L, int f, int arg) {
{
size_t
l
;
const
char
*
s
=
luaL_checklstring
(
L
,
arg
,
&
l
);
status
=
status
&&
(
fs_write
(
f
,
s
,
l
)
==
l
);
status
=
status
&&
(
v
fs_write
(
f
,
s
,
l
)
==
l
);
}
}
return
pushresult
(
L
,
status
,
NULL
);
...
...
@@ -502,16 +502,16 @@ static int f_write (lua_State *L) {
static
int
f_seek
(
lua_State
*
L
)
{
static
const
int
mode
[]
=
{
FS_SEEK_SET
,
FS_SEEK_CUR
,
FS_SEEK_END
};
static
const
int
mode
[]
=
{
V
FS_SEEK_SET
,
V
FS_SEEK_CUR
,
V
FS_SEEK_END
};
static
const
char
*
const
modenames
[]
=
{
"set"
,
"cur"
,
"end"
,
NULL
};
int
f
=
tofile
(
L
);
int
op
=
luaL_checkoption
(
L
,
2
,
"cur"
,
modenames
);
long
offset
=
luaL_optlong
(
L
,
3
,
0
);
op
=
fs_seek
(
f
,
offset
,
mode
[
op
]);
op
=
v
fs_
l
seek
(
f
,
offset
,
mode
[
op
]);
if
(
op
)
return
pushresult
(
L
,
0
,
NULL
);
/* error */
else
{
lua_pushinteger
(
L
,
fs_tell
(
f
));
lua_pushinteger
(
L
,
v
fs_tell
(
f
));
return
1
;
}
}
...
...
@@ -530,12 +530,12 @@ static int f_setvbuf (lua_State *L) {
static
int
io_flush
(
lua_State
*
L
)
{
return
pushresult
(
L
,
fs_flush
(
getiofile
(
L
,
IO_OUTPUT
))
==
0
,
NULL
);
return
pushresult
(
L
,
v
fs_flush
(
getiofile
(
L
,
IO_OUTPUT
))
==
0
,
NULL
);
}
static
int
f_flush
(
lua_State
*
L
)
{
return
pushresult
(
L
,
fs_flush
(
tofile
(
L
))
==
0
,
NULL
);
return
pushresult
(
L
,
v
fs_flush
(
tofile
(
L
))
==
0
,
NULL
);
}
#undef MIN_OPT_LEVEL
...
...
app/lua/loadlib.c
View file @
7b83bbb2
...
...
@@ -19,7 +19,7 @@
#include C_HEADER_FCNTL
#ifndef LUA_CROSS_COMPILER
#include "
flash_
fs.h"
#include "
v
fs.h"
#endif
#include "lauxlib.h"
...
...
@@ -340,9 +340,9 @@ static int readable (const char *filename) {
}
#else
static
int
readable
(
const
char
*
filename
)
{
int
f
=
fs_open
(
filename
,
FS_RDONLY
);
/* try to open file */
if
(
f
<
FS_OPEN_OK
)
return
0
;
/* open failed */
fs_close
(
f
);
int
f
=
v
fs_open
(
filename
,
"r"
);
/* try to open file */
if
(
!
f
)
return
0
;
/* open failed */
v
fs_close
(
f
);
return
1
;
}
#endif
...
...
app/lua/lua.c
View file @
7b83bbb2
...
...
@@ -9,7 +9,7 @@
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "
flash_fs
.h"
#include "
user_interface
.h"
#include "user_version.h"
#include "driver/readline.h"
#include "driver/uart.h"
...
...
app/lua/lvm.c
View file @
7b83bbb2
...
...
@@ -759,7 +759,6 @@ void luaV_execute (lua_State *L, int nexeccalls) {
fixedstack
(
L
);
if
(
n
==
0
)
{
n
=
cast_int
(
L
->
top
-
ra
)
-
1
;
L
->
top
=
L
->
ci
->
top
;
}
if
(
c
==
0
)
c
=
cast_int
(
*
pc
++
);
runtime_check
(
L
,
ttistable
(
ra
));
...
...
@@ -772,6 +771,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
setobj2t
(
L
,
luaH_setnum
(
L
,
h
,
last
--
),
val
);
luaC_barriert
(
L
,
h
,
val
);
}
L
->
top
=
L
->
ci
->
top
;
unfixedstack
(
L
);
continue
;
}
...
...
app/lwip/core/dns.c
View file @
7b83bbb2
...
...
@@ -254,8 +254,16 @@ dns_init()
LWIP_ASSERT
(
"For implicit initialization to work, DNS_STATE_UNUSED needs to be 0"
,
DNS_STATE_UNUSED
==
0
);
/* initialize DNS client */
udp_bind
(
dns_pcb
,
IP_ADDR_ANY
,
0
);
/* PR #1324 */
/* initialize DNS client, try to get RFC 5452 random source port */
u16_t
port
=
UDP_LOCAL_PORT_RANGE_START
+
(
os_random
()
%
(
UDP_LOCAL_PORT_RANGE_END
-
UDP_LOCAL_PORT_RANGE_START
));
for
(;;)
{
if
(
udp_bind
(
dns_pcb
,
IP_ADDR_ANY
,
port
)
==
ERR_OK
)
break
;
LWIP_ASSERT
(
"Unable to get a PCB for DNS"
,
port
!=
0
);
port
=
0
;
// try again with random source
}
/* END PR #1324 */
udp_recv
(
dns_pcb
,
dns_recv
,
NULL
);
/* initialize default DNS primary server */
...
...
app/lwip/core/udp.c
View file @
7b83bbb2
...
...
@@ -758,10 +758,6 @@ udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
/* no port specified? */
if
(
port
==
0
)
{
#ifndef UDP_LOCAL_PORT_RANGE_START
#define UDP_LOCAL_PORT_RANGE_START 4096
#define UDP_LOCAL_PORT_RANGE_END 0x7fff
#endif
port
=
UDP_LOCAL_PORT_RANGE_START
;
ipcb
=
udp_pcbs
;
while
((
ipcb
!=
NULL
)
&&
(
port
!=
UDP_LOCAL_PORT_RANGE_END
))
{
...
...
app/modules/Makefile
View file @
7b83bbb2
...
...
@@ -52,7 +52,9 @@ INCLUDES += -I ../spiffs
INCLUDES
+=
-I
../smart
INCLUDES
+=
-I
../cjson
INCLUDES
+=
-I
../dhtlib
INCLUDES
+=
-I
../fatfs
INCLUDES
+=
-I
../http
INCLUDES
+=
-I
../websocket
PDIR
:=
../
$(PDIR)
sinclude
$(PDIR)Makefile
app/modules/bme280.c
View file @
7b83bbb2
...
...
@@ -304,7 +304,7 @@ static int bme280_lua_init(lua_State* L) {
static
void
bme280_readoutdone
(
void
*
arg
)
{
NODE_DBG
(
"timer out
\n
"
);
lua_State
*
L
=
arg
;
lua_State
*
L
=
lua_getstate
()
;
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
lua_connected_readout_ref
);
lua_call
(
L
,
0
,
0
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
lua_connected_readout_ref
);
...
...
app/modules/cjson.c
View file @
7b83bbb2
...
...
@@ -1617,8 +1617,6 @@ static const LUA_REG_TYPE cjson_map[] = {
int
luaopen_cjson
(
lua_State
*
L
)
{
cjson_mem_setlua
(
L
);
/* Initialise number conversions */
// fpconv_init(); // not needed for a specific cpu.
if
(
-
1
==
cfg_init
(
&
_cfg
)){
...
...
Prev
1
2
3
4
5
6
7
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment