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
Hide whitespace changes
Inline
Side-by-side
app/http/httpclient.c
View file @
7b83bbb2
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
#include "httpclient.h"
#include "httpclient.h"
#include "stdlib.h"
#include "stdlib.h"
#define REDIRECTION_FOLLOW_MAX 20
/* Internal state. */
/* Internal state. */
typedef
struct
request_args_t
{
typedef
struct
request_args_t
{
char
*
hostname
;
char
*
hostname
;
...
@@ -31,6 +33,7 @@ typedef struct request_args_t {
...
@@ -31,6 +33,7 @@ typedef struct request_args_t {
char
*
post_data
;
char
*
post_data
;
char
*
buffer
;
char
*
buffer
;
int
buffer_size
;
int
buffer_size
;
int
redirect_follow_count
;
int
timeout
;
int
timeout
;
os_timer_t
timeout_timer
;
os_timer_t
timeout_timer
;
http_callback_t
callback_handle
;
http_callback_t
callback_handle
;
...
@@ -181,7 +184,6 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
...
@@ -181,7 +184,6 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
HTTPCLIENT_DEBUG
(
"Connected
\n
"
);
HTTPCLIENT_DEBUG
(
"Connected
\n
"
);
struct
espconn
*
conn
=
(
struct
espconn
*
)
arg
;
struct
espconn
*
conn
=
(
struct
espconn
*
)
arg
;
request_args_t
*
req
=
(
request_args_t
*
)
conn
->
reverse
;
request_args_t
*
req
=
(
request_args_t
*
)
conn
->
reverse
;
int
len
;
espconn_regist_recvcb
(
conn
,
http_receive_callback
);
espconn_regist_recvcb
(
conn
,
http_receive_callback
);
espconn_regist_sentcb
(
conn
,
http_send_callback
);
espconn_regist_sentcb
(
conn
,
http_send_callback
);
...
@@ -198,39 +200,57 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
...
@@ -198,39 +200,57 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
req
->
headers
[
0
]
=
'\0'
;
req
->
headers
[
0
]
=
'\0'
;
}
}
char
buf
[
69
+
strlen
(
req
->
method
)
+
strlen
(
req
->
path
)
+
strlen
(
req
->
hostname
)
+
char
ua_header
[
32
]
=
""
;
strlen
(
req
->
headers
)
+
strlen
(
post_headers
)];
int
ua_len
=
0
;
if
(
os_strstr
(
req
->
headers
,
"User-Agent:"
)
==
NULL
&&
os_strstr
(
req
->
headers
,
"user-agent:"
)
==
NULL
)
if
((
req
->
port
==
80
)
||
((
req
->
port
==
443
)
&&
(
req
->
secure
)))
{
{
os_sprintf
(
ua_header
,
"User-Agent: %s
\r\n
"
,
"ESP8266"
);
len
=
os_sprintf
(
buf
,
ua_len
=
strlen
(
ua_header
);
"%s %s HTTP/1.1
\r\n
"
}
"Host: %s
\r\n
"
"Connection: close
\r\n
"
char
host_header
[
32
]
=
""
;
"User-Agent: ESP8266
\r\n
"
int
host_len
=
0
;
"%s"
if
(
os_strstr
(
req
->
headers
,
"Host:"
)
==
NULL
&&
os_strstr
(
req
->
headers
,
"host:"
)
==
NULL
)
"%s"
{
"
\r\n
"
,
if
((
req
->
port
==
80
)
||
((
req
->
port
==
443
)
&&
(
req
->
secure
)))
req
->
method
,
req
->
path
,
req
->
hostname
,
req
->
headers
,
post_headers
);
{
}
else
{
os_sprintf
(
host_header
,
"Host: %s
\r\n
"
,
req
->
hostname
);
len
=
os_sprintf
(
buf
,
}
"%s %s HTTP/1.1
\r\n
"
else
"Host: %s:%d
\r\n
"
{
"Connection: close
\r\n
"
os_sprintf
(
host_header
,
"Host: %s:%d
\r\n
"
,
req
->
hostname
,
req
->
port
);
"User-Agent: ESP8266
\r\n
"
}
"%s"
host_len
=
strlen
(
host_header
);
"%s"
}
"
\r\n
"
,
req
->
method
,
req
->
path
,
req
->
hostname
,
req
->
port
,
req
->
headers
,
post_headers
);
char
buf
[
69
+
strlen
(
req
->
method
)
+
strlen
(
req
->
path
)
+
host_len
+
}
strlen
(
req
->
headers
)
+
ua_len
+
strlen
(
post_headers
)];
if
(
req
->
secure
)
int
len
=
os_sprintf
(
buf
,
espconn_secure_send
(
conn
,
(
uint8_t
*
)
buf
,
len
);
"%s %s HTTP/1.1
\r\n
"
else
"%s"
// Host (if not provided in the headers from Lua)
espconn_send
(
conn
,
(
uint8_t
*
)
buf
,
len
);
"Connection: close
\r\n
"
if
(
req
->
headers
!=
NULL
)
"%s"
// Headers from Lua (optional)
os_free
(
req
->
headers
);
"%s"
// User-Agent (if not provided in the headers from Lua)
req
->
headers
=
NULL
;
"%s"
// Content-Length
HTTPCLIENT_DEBUG
(
"Sending request header
\n
"
);
"
\r\n
"
,
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
)
{
os_free
(
req
->
headers
);
}
req
->
headers
=
NULL
;
HTTPCLIENT_DEBUG
(
"Sending request header
\n
"
);
}
}
static
void
http_free_req
(
request_args_t
*
req
)
static
void
http_free_req
(
request_args_t
*
req
)
...
@@ -290,26 +310,92 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
...
@@ -290,26 +310,92 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
else
else
{
{
http_status
=
atoi
(
req
->
buffer
+
strlen
(
version_1_0
)
);
http_status
=
atoi
(
req
->
buffer
+
strlen
(
version_1_0
)
);
body
=
(
char
*
)
os_strstr
(
req
->
buffer
,
"
\r\n\r\n
"
);
char
*
locationOffset
=
(
char
*
)
os_strstr
(
req
->
buffer
,
"Location:"
);
if
(
NULL
==
body
)
{
if
(
locationOffset
==
NULL
)
{
/* Find missing body */
locationOffset
=
(
char
*
)
os_strstr
(
req
->
buffer
,
"location:"
);
HTTPCLIENT_DEBUG
(
"Body shouldn't be NULL
\n
"
);
/* To avoid NULL body */
body
=
""
;
}
else
{
/* Skip CR & LF */
body
=
body
+
4
;
}
}
if
(
os_strstr
(
req
->
buffer
,
"Transfer-Encoding: chunked"
)
)
if
(
locationOffset
!=
NULL
&&
http_status
>=
300
&&
http_status
<=
308
)
{
{
if
(
req
->
redirect_follow_count
<
REDIRECTION_FOLLOW_MAX
)
{
int
body_size
=
req
->
buffer_size
-
(
body
-
req
->
buffer
);
locationOffset
+=
strlen
(
"location:"
);
char
chunked_decode_buffer
[
body_size
];
os_memset
(
chunked_decode_buffer
,
0
,
body_size
);
while
(
*
locationOffset
==
' '
)
{
// skip url leading white-space
/* Chuncked data */
locationOffset
++
;
http_chunked_decode
(
body
,
chunked_decode_buffer
);
}
os_memcpy
(
body
,
chunked_decode_buffer
,
body_size
);
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
)
{
/* Find missing body */
HTTPCLIENT_DEBUG
(
"Body shouldn't be NULL
\n
"
);
/* To avoid NULL body */
body
=
""
;
}
else
{
/* Skip CR & LF */
body
=
body
+
4
;
}
if
(
os_strstr
(
req
->
buffer
,
"Transfer-Encoding: chunked"
)
)
{
int
body_size
=
req
->
buffer_size
-
(
body
-
req
->
buffer
);
char
chunked_decode_buffer
[
body_size
];
os_memset
(
chunked_decode_buffer
,
0
,
body_size
);
/* Chuncked data */
http_chunked_decode
(
body
,
chunked_decode_buffer
);
os_memcpy
(
body
,
chunked_decode_buffer
,
body_size
);
}
}
}
}
}
}
}
...
@@ -391,7 +477,6 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
...
@@ -391,7 +477,6 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
if
(
req
->
secure
)
if
(
req
->
secure
)
{
{
espconn_secure_set_size
(
ESPCONN_CLIENT
,
5120
);
/* set SSL buffer size */
espconn_secure_connect
(
conn
);
espconn_secure_connect
(
conn
);
}
}
else
else
...
@@ -402,7 +487,7 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
...
@@ -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
"
);
HTTPCLIENT_DEBUG
(
"DNS request
\n
"
);
...
@@ -419,6 +504,7 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s
...
@@ -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
->
buffer
[
0
]
=
'\0'
;
/* Empty string. */
req
->
callback_handle
=
callback_handle
;
req
->
callback_handle
=
callback_handle
;
req
->
timeout
=
HTTP_REQUEST_TIMEOUT_MS
;
req
->
timeout
=
HTTP_REQUEST_TIMEOUT_MS
;
req
->
redirect_follow_count
=
redirect_follow_count
;
ip_addr_t
addr
;
ip_addr_t
addr
;
err_t
error
=
espconn_gethostbyname
(
(
struct
espconn
*
)
req
,
/* It seems we don't need a real espconn pointer here. */
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
...
@@ -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
* <host> can be a hostname or an IP address
* <port> is optional
* <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/
* 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
...
@@ -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
(
"port=%d
\n
"
,
port
);
HTTPCLIENT_DEBUG
(
"method=%s
\n
"
,
method
);
HTTPCLIENT_DEBUG
(
"method=%s
\n
"
,
method
);
HTTPCLIENT_DEBUG
(
"path=%s
\n
"
,
path
);
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
...
@@ -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
)
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
)
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
)
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
)
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
...
@@ -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.
* 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.
* Request data from URL use custom method.
* The data should be encoded as any format.
* The data should be encoded as any format.
* Try:
* 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.
* Post data to a web form.
...
...
app/include/driver/spi.h
View file @
7b83bbb2
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
#define SPI 0
#define SPI 0
#define HSPI 1
#define HSPI 1
#define SPI_ORDER_LSB 0
#define SPI_ORDER_MSB 1
//lcd drive function
//lcd drive function
...
@@ -18,7 +21,13 @@ void spi_lcd_mode_init(uint8 spi_no);
...
@@ -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
);
void
spi_lcd_9bit_write
(
uint8
spi_no
,
uint8
high_bit
,
uint8
low_8bit
);
//spi master init funtion
//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_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
// fill MOSI buffer
void
spi_mast_set_mosi
(
uint8
spi_no
,
uint16
offset
,
uint8
bitlen
,
uint32
data
);
void
spi_mast_set_mosi
(
uint8
spi_no
,
uint16
offset
,
uint8
bitlen
,
uint32
data
);
// retrieve data from MISO buffer
// retrieve data from MISO buffer
...
...
app/include/driver/uart.h
View file @
7b83bbb2
...
@@ -108,5 +108,6 @@ void uart0_putc(const char c);
...
@@ -108,5 +108,6 @@ void uart0_putc(const char c);
void
uart0_tx_buffer
(
uint8
*
buf
,
uint16
len
);
void
uart0_tx_buffer
(
uint8
*
buf
,
uint16
len
);
void
uart_setup
(
uint8
uart_no
);
void
uart_setup
(
uint8
uart_no
);
STATUS
uart_tx_one_char
(
uint8
uart
,
uint8
TxChar
);
STATUS
uart_tx_one_char
(
uint8
uart
,
uint8
TxChar
);
void
uart_set_alt_output_uart0
(
void
(
*
fn
)(
char
));
#endif
#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__
#ifndef __DHCPS_H__
#define __DHCPS_H__
#define __DHCPS_H__
#include "lwipopts.h"
#define USE_DNS
#define USE_DNS
typedef
struct
dhcps_state
{
typedef
struct
dhcps_state
{
...
@@ -19,7 +21,9 @@ typedef struct dhcps_msg {
...
@@ -19,7 +21,9 @@ typedef struct dhcps_msg {
uint8_t
chaddr
[
16
];
uint8_t
chaddr
[
16
];
uint8_t
sname
[
64
];
uint8_t
sname
[
64
];
uint8_t
file
[
128
];
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
;
}
dhcps_msg
;
#ifndef LWIP_OPEN_SRC
#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_
...
@@ -156,6 +156,11 @@ void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_
#define udp_init()
/* Compatibility define, not init needed. */
#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
#if UDP_DEBUG
void
udp_debug_print
(
struct
udp_hdr
*
udphdr
)
ICACHE_FLASH_ATTR
;
void
udp_debug_print
(
struct
udp_hdr
*
udphdr
)
ICACHE_FLASH_ATTR
;
#else
#else
...
...
app/include/user_config.h
View file @
7b83bbb2
#ifndef __USER_CONFIG_H__
#ifndef __USER_CONFIG_H__
#define __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_512K
// #define FLASH_1M
// #define FLASH_1M
// #define FLASH_2M
// #define FLASH_2M
...
@@ -62,13 +60,22 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
...
@@ -62,13 +60,22 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define NO_INTR_CODE inline
#define NO_INTR_CODE inline
#endif
#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 CLIENT_SSL_ENABLE
//#define MD2_ENABLE
//#define MD2_ENABLE
#define SHA2_ENABLE
#define SHA2_ENABLE
#define BUILD_SPIFFS
1
#define BUILD_SPIFFS
#define SPIFFS_CACHE 1
#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
// Uncomment this next line for fastest startup
// It reduces the format time dramatically
// It reduces the format time dramatically
// #define SPIFFS_MAX_FILESYSTEM_SIZE 32768
// #define SPIFFS_MAX_FILESYSTEM_SIZE 32768
...
@@ -87,18 +94,6 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
...
@@ -87,18 +94,6 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define LUA_PROCESS_LINE_SIG 2
#define LUA_PROCESS_LINE_SIG 2
#define LUA_OPTIMIZE_DEBUG 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"
#define ENDUSER_SETUP_AP_SSID "SetupGadget"
/*
/*
...
...
app/include/user_modules.h
View file @
7b83bbb2
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
//#define LUA_USE_MODULES_ENCODER
//#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_GDBSTUB
#define LUA_USE_MODULES_GPIO
#define LUA_USE_MODULES_GPIO
//#define LUA_USE_MODULES_HMC5883L
//#define LUA_USE_MODULES_HMC5883L
//#define LUA_USE_MODULES_HTTP
//#define LUA_USE_MODULES_HTTP
...
@@ -61,6 +62,7 @@
...
@@ -61,6 +62,7 @@
//#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_WEBSOCKET
#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
...
...
app/libc/c_math.c
View file @
7b83bbb2
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
double
floor
(
double
x
)
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 */
#define MAXEXP 2031
/* (MAX_EXP * 16) - 1 */
...
@@ -59,6 +59,7 @@ double pow(double x, double y)
...
@@ -59,6 +59,7 @@ double pow(double x, double y)
{
{
double
frexp
(),
g
,
ldexp
(),
r
,
u1
,
u2
,
v
,
w
,
w1
,
w2
,
y1
,
y2
,
z
;
double
frexp
(),
g
,
ldexp
(),
r
,
u1
,
u2
,
v
,
w
,
w1
,
w2
,
y1
,
y2
,
z
;
int
iw1
,
m
,
p
;
int
iw1
,
m
,
p
;
bool
flipsignal
=
false
;
if
(
y
==
0
.
0
)
if
(
y
==
0
.
0
)
return
(
1
.
0
);
return
(
1
.
0
);
...
@@ -67,7 +68,7 @@ double pow(double x, double y)
...
@@ -67,7 +68,7 @@ double pow(double x, double y)
if
(
x
==
0
.
0
)
if
(
x
==
0
.
0
)
{
{
if
(
y
>
0
.
0
)
if
(
y
>
0
.
0
)
return
(
x
)
;
return
0
.
0
;
//cmemsg(FP_POWO, &y);
//cmemsg(FP_POWO, &y);
//return(HUGE);
//return(HUGE);
}
}
...
@@ -75,6 +76,11 @@ double pow(double x, double y)
...
@@ -75,6 +76,11 @@ double pow(double x, double y)
{
{
//cmemsg(FP_POWN, &x);
//cmemsg(FP_POWN, &x);
x
=
-
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
);
g
=
frexp
(
x
,
&
m
);
...
@@ -125,7 +131,8 @@ double pow(double x, double y)
...
@@ -125,7 +131,8 @@ double pow(double x, double y)
p
=
16
*
m
-
iw1
;
p
=
16
*
m
-
iw1
;
z
=
((((((
q7
*
w2
+
q6
)
*
w2
+
q5
)
*
w2
+
q4
)
*
w2
+
q3
)
*
w2
+
q2
)
*
w2
+
q1
)
*
w2
;
z
=
((((((
q7
*
w2
+
q6
)
*
w2
+
q5
)
*
w2
+
q4
)
*
w2
+
q3
)
*
w2
+
q2
)
*
w2
+
q1
)
*
w2
;
z
=
a1
[
p
]
+
a1
[
p
]
*
z
;
z
=
a1
[
p
]
+
a1
[
p
]
*
z
;
return
(
ldexp
(
z
,
m
));
double
res
=
ldexp
(
z
,
m
);
return
flipsignal
?
-
res
:
res
;
}
}
#if 0
#if 0
...
...
app/lua/lauxlib.c
View file @
7b83bbb2
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#include C_HEADER_STDLIB
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#include C_HEADER_STRING
#ifndef LUA_CROSS_COMPILER
#ifndef LUA_CROSS_COMPILER
#include "
flash_
fs.h"
#include "
v
fs.h"
#else
#else
#endif
#endif
...
@@ -671,8 +671,8 @@ static const char *getFSF (lua_State *L, void *ud, size_t *size) {
...
@@ -671,8 +671,8 @@ static const char *getFSF (lua_State *L, void *ud, size_t *size) {
return
"
\n
"
;
return
"
\n
"
;
}
}
if
(
fs_eof
(
lf
->
f
))
return
NULL
;
if
(
v
fs_eof
(
lf
->
f
))
return
NULL
;
*
size
=
fs_read
(
lf
->
f
,
lf
->
buff
,
sizeof
(
lf
->
buff
));
*
size
=
v
fs_read
(
lf
->
f
,
lf
->
buff
,
sizeof
(
lf
->
buff
));
return
(
*
size
>
0
)
?
lf
->
buff
:
NULL
;
return
(
*
size
>
0
)
?
lf
->
buff
:
NULL
;
}
}
...
@@ -697,29 +697,29 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) {
...
@@ -697,29 +697,29 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) {
}
}
else
{
else
{
lua_pushfstring
(
L
,
"@%s"
,
filename
);
lua_pushfstring
(
L
,
"@%s"
,
filename
);
lf
.
f
=
fs_open
(
filename
,
FS_RDONLY
);
lf
.
f
=
v
fs_open
(
filename
,
"r"
);
if
(
lf
.
f
<
FS_OPEN_OK
)
return
errfsfile
(
L
,
"open"
,
fnameindex
);
if
(
!
lf
.
f
)
return
errfsfile
(
L
,
"open"
,
fnameindex
);
}
}
// if(fs_size(lf.f)>LUAL_BUFFERSIZE)
// if(fs_size(lf.f)>LUAL_BUFFERSIZE)
// return luaL_error(L, "file is too big");
// return luaL_error(L, "file is too big");
c
=
fs_getc
(
lf
.
f
);
c
=
v
fs_getc
(
lf
.
f
);
if
(
c
==
'#'
)
{
/* Unix exec. file? */
if
(
c
==
'#'
)
{
/* Unix exec. file? */
lf
.
extraline
=
1
;
lf
.
extraline
=
1
;
while
((
c
=
fs_getc
(
lf
.
f
))
!=
EOF
&&
c
!=
'\n'
)
;
/* skip first line */
while
((
c
=
v
fs_getc
(
lf
.
f
))
!=
VFS_
EOF
&&
c
!=
'\n'
)
;
/* skip first line */
if
(
c
==
'\n'
)
c
=
fs_getc
(
lf
.
f
);
if
(
c
==
'\n'
)
c
=
v
fs_getc
(
lf
.
f
);
}
}
if
(
c
==
LUA_SIGNATURE
[
0
]
&&
filename
)
{
/* binary file? */
if
(
c
==
LUA_SIGNATURE
[
0
]
&&
filename
)
{
/* binary file? */
fs_close
(
lf
.
f
);
v
fs_close
(
lf
.
f
);
lf
.
f
=
fs_open
(
filename
,
FS_RDONLY
);
/* reopen in binary mode */
lf
.
f
=
v
fs_open
(
filename
,
"r"
);
/* reopen in binary mode */
if
(
lf
.
f
<
FS_OPEN_OK
)
return
errfsfile
(
L
,
"reopen"
,
fnameindex
);
if
(
!
lf
.
f
)
return
errfsfile
(
L
,
"reopen"
,
fnameindex
);
/* skip eventual `#!...' */
/* 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
;
lf
.
extraline
=
0
;
}
}
fs_ungetc
(
c
,
lf
.
f
);
v
fs_ungetc
(
c
,
lf
.
f
);
status
=
lua_load
(
L
,
getFSF
,
&
lf
,
lua_tostring
(
L
,
-
1
));
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
);
lua_remove
(
L
,
fnameindex
);
return
status
;
return
status
;
}
}
...
...
app/lua/liolib.c
View file @
7b83bbb2
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include "c_stdio.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "c_string.h"
#include "
flash_
fs.h"
#include "
v
fs.h"
#define liolib_c
#define liolib_c
#define LUA_LIB
#define LUA_LIB
...
@@ -39,7 +39,7 @@ static const int liolib_keys[] = {(int)&luaL_callmeta, (int)&luaL_typerror, (int
...
@@ -39,7 +39,7 @@ static const int liolib_keys[] = {(int)&luaL_callmeta, (int)&luaL_typerror, (int
static
const
char
*
const
fnames
[]
=
{
"input"
,
"output"
};
static
const
char
*
const
fnames
[]
=
{
"input"
,
"output"
};
static
int
pushresult
(
lua_State
*
L
,
int
i
,
const
char
*
filename
)
{
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
)
{
if
(
i
)
{
lua_pushboolean
(
L
,
1
);
lua_pushboolean
(
L
,
1
);
return
1
;
return
1
;
...
@@ -57,7 +57,7 @@ static int pushresult (lua_State *L, int i, const char *filename) {
...
@@ -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
)
{
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
));
luaL_argerror
(
L
,
arg
,
lua_tostring
(
L
,
-
1
));
}
}
...
@@ -130,7 +130,7 @@ static int io_pclose (lua_State *L) {
...
@@ -130,7 +130,7 @@ static int io_pclose (lua_State *L) {
*/
*/
static
int
io_fclose
(
lua_State
*
L
)
{
static
int
io_fclose
(
lua_State
*
L
)
{
int
*
p
=
tofilep
(
L
);
int
*
p
=
tofilep
(
L
);
int
ok
=
(
fs_close
(
*
p
)
==
0
);
int
ok
=
(
v
fs_close
(
*
p
)
==
0
);
*
p
=
FS_OPEN_OK
-
1
;
*
p
=
FS_OPEN_OK
-
1
;
return
pushresult
(
L
,
ok
,
NULL
);
return
pushresult
(
L
,
ok
,
NULL
);
}
}
...
@@ -149,7 +149,7 @@ static int aux_close (lua_State *L) {
...
@@ -149,7 +149,7 @@ static int aux_close (lua_State *L) {
lua_pushliteral
(
L
,
"cannot close standard file"
);
lua_pushliteral
(
L
,
"cannot close standard file"
);
return
2
;
return
2
;
}
}
int
ok
=
(
fs_close
(
*
p
)
==
0
);
int
ok
=
(
v
fs_close
(
*
p
)
==
0
);
*
p
=
FS_OPEN_OK
-
1
;
*
p
=
FS_OPEN_OK
-
1
;
return
pushresult
(
L
,
ok
,
NULL
);
return
pushresult
(
L
,
ok
,
NULL
);
#endif
#endif
...
@@ -187,7 +187,7 @@ static int io_open (lua_State *L) {
...
@@ -187,7 +187,7 @@ static int io_open (lua_State *L) {
const
char
*
filename
=
luaL_checkstring
(
L
,
1
);
const
char
*
filename
=
luaL_checkstring
(
L
,
1
);
const
char
*
mode
=
luaL_optstring
(
L
,
2
,
"r"
);
const
char
*
mode
=
luaL_optstring
(
L
,
2
,
"r"
);
int
*
pf
=
newfile
(
L
);
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
;
return
(
*
pf
==
FS_OPEN_OK
-
1
)
?
pushresult
(
L
,
0
,
filename
)
:
1
;
}
}
...
@@ -201,7 +201,7 @@ static int io_popen (lua_State *L) {
...
@@ -201,7 +201,7 @@ static int io_popen (lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
const char *mode = luaL_optstring(L, 2, "r");
int *pf = newfile(L);
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;
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) {
...
@@ -230,7 +230,7 @@ static int g_iofile (lua_State *L, int f, const char *mode) {
const
char
*
filename
=
lua_tostring
(
L
,
1
);
const
char
*
filename
=
lua_tostring
(
L
,
1
);
if
(
filename
)
{
if
(
filename
)
{
int
*
pf
=
newfile
(
L
);
int
*
pf
=
newfile
(
L
);
*
pf
=
fs_open
(
filename
,
fs_
mode
2flag
(
mode
)
);
*
pf
=
v
fs_open
(
filename
,
mode
);
if
(
*
pf
==
FS_OPEN_OK
-
1
)
if
(
*
pf
==
FS_OPEN_OK
-
1
)
fileerror
(
L
,
1
,
filename
);
fileerror
(
L
,
1
,
filename
);
}
}
...
@@ -282,7 +282,7 @@ static int io_lines (lua_State *L) {
...
@@ -282,7 +282,7 @@ static int io_lines (lua_State *L) {
else
{
else
{
const
char
*
filename
=
luaL_checkstring
(
L
,
1
);
const
char
*
filename
=
luaL_checkstring
(
L
,
1
);
int
*
pf
=
newfile
(
L
);
int
*
pf
=
newfile
(
L
);
*
pf
=
fs_open
(
filename
,
FS_RDONLY
);
*
pf
=
v
fs_open
(
filename
,
"r"
);
if
(
*
pf
==
FS_OPEN_OK
-
1
)
if
(
*
pf
==
FS_OPEN_OK
-
1
)
fileerror
(
L
,
1
,
filename
);
fileerror
(
L
,
1
,
filename
);
aux_lines
(
L
,
lua_gettop
(
L
),
1
);
aux_lines
(
L
,
lua_gettop
(
L
),
1
);
...
@@ -312,8 +312,8 @@ static int read_number (lua_State *L, int f) {
...
@@ -312,8 +312,8 @@ static int read_number (lua_State *L, int f) {
#endif
#endif
static
int
test_eof
(
lua_State
*
L
,
int
f
)
{
static
int
test_eof
(
lua_State
*
L
,
int
f
)
{
int
c
=
fs_getc
(
f
);
int
c
=
v
fs_getc
(
f
);
fs_ungetc
(
c
,
f
);
v
fs_ungetc
(
c
,
f
);
lua_pushlstring
(
L
,
NULL
,
0
);
lua_pushlstring
(
L
,
NULL
,
0
);
return
(
c
!=
EOF
);
return
(
c
!=
EOF
);
}
}
...
@@ -347,7 +347,7 @@ static int read_line (lua_State *L, int f) {
...
@@ -347,7 +347,7 @@ static int read_line (lua_State *L, int f) {
signed
char
c
=
EOF
;
signed
char
c
=
EOF
;
int
i
=
0
;
int
i
=
0
;
do
{
do
{
c
=
(
signed
char
)
fs_getc
(
f
);
c
=
(
signed
char
)
v
fs_getc
(
f
);
if
(
c
==
EOF
){
if
(
c
==
EOF
){
break
;
break
;
}
}
...
@@ -377,7 +377,7 @@ static int read_chars (lua_State *L, int f, size_t n) {
...
@@ -377,7 +377,7 @@ static int read_chars (lua_State *L, int f, size_t n) {
do
{
do
{
char
*
p
=
luaL_prepbuffer
(
&
b
);
char
*
p
=
luaL_prepbuffer
(
&
b
);
if
(
rlen
>
n
)
rlen
=
n
;
/* cannot read more than asked */
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
);
luaL_addsize
(
&
b
,
nr
);
n
-=
nr
;
/* still have to read `n' chars */
n
-=
nr
;
/* still have to read `n' chars */
}
while
(
n
>
0
&&
nr
==
rlen
);
/* until end of count or eof */
}
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) {
...
@@ -390,7 +390,7 @@ static int g_read (lua_State *L, int f, int first) {
int
nargs
=
lua_gettop
(
L
)
-
1
;
int
nargs
=
lua_gettop
(
L
)
-
1
;
int
success
;
int
success
;
int
n
;
int
n
;
fs_clearerr
(
f
);
//v
fs_clearerr(f);
if
(
nargs
==
0
)
{
/* no arguments? */
if
(
nargs
==
0
)
{
/* no arguments? */
success
=
read_line
(
L
,
f
);
success
=
read_line
(
L
,
f
);
n
=
first
+
1
;
/* to return 1 result */
n
=
first
+
1
;
/* to return 1 result */
...
@@ -425,7 +425,7 @@ static int g_read (lua_State *L, int f, int first) {
...
@@ -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
);
return
pushresult
(
L
,
0
,
NULL
);
if
(
!
success
)
{
if
(
!
success
)
{
lua_pop
(
L
,
1
);
/* remove last result */
lua_pop
(
L
,
1
);
/* remove last result */
...
@@ -453,8 +453,8 @@ static int io_readline (lua_State *L) {
...
@@ -453,8 +453,8 @@ static int io_readline (lua_State *L) {
return
0
;
return
0
;
}
}
sucess
=
read_line
(
L
,
*
pf
);
sucess
=
read_line
(
L
,
*
pf
);
if
(
fs_erro
r
(
*
pf
))
if
(
v
fs_
f
err
n
o
(
*
pf
))
return
luaL_error
(
L
,
"err(%d)"
,
fs_erro
r
(
*
pf
));
return
luaL_error
(
L
,
"err(%d)"
,
v
fs_
f
err
n
o
(
*
pf
));
if
(
sucess
)
return
1
;
if
(
sucess
)
return
1
;
else
{
/* EOF */
else
{
/* EOF */
if
(
lua_toboolean
(
L
,
lua_upvalueindex
(
2
)))
{
/* generator created file? */
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) {
...
@@ -484,7 +484,7 @@ static int g_write (lua_State *L, int f, int arg) {
{
{
size_t
l
;
size_t
l
;
const
char
*
s
=
luaL_checklstring
(
L
,
arg
,
&
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
);
return
pushresult
(
L
,
status
,
NULL
);
...
@@ -502,16 +502,16 @@ static int f_write (lua_State *L) {
...
@@ -502,16 +502,16 @@ static int f_write (lua_State *L) {
static
int
f_seek
(
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
};
static
const
char
*
const
modenames
[]
=
{
"set"
,
"cur"
,
"end"
,
NULL
};
int
f
=
tofile
(
L
);
int
f
=
tofile
(
L
);
int
op
=
luaL_checkoption
(
L
,
2
,
"cur"
,
modenames
);
int
op
=
luaL_checkoption
(
L
,
2
,
"cur"
,
modenames
);
long
offset
=
luaL_optlong
(
L
,
3
,
0
);
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
)
if
(
op
)
return
pushresult
(
L
,
0
,
NULL
);
/* error */
return
pushresult
(
L
,
0
,
NULL
);
/* error */
else
{
else
{
lua_pushinteger
(
L
,
fs_tell
(
f
));
lua_pushinteger
(
L
,
v
fs_tell
(
f
));
return
1
;
return
1
;
}
}
}
}
...
@@ -530,12 +530,12 @@ static int f_setvbuf (lua_State *L) {
...
@@ -530,12 +530,12 @@ static int f_setvbuf (lua_State *L) {
static
int
io_flush
(
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
)
{
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
#undef MIN_OPT_LEVEL
...
...
app/lua/loadlib.c
View file @
7b83bbb2
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#include C_HEADER_FCNTL
#include C_HEADER_FCNTL
#ifndef LUA_CROSS_COMPILER
#ifndef LUA_CROSS_COMPILER
#include "
flash_
fs.h"
#include "
v
fs.h"
#endif
#endif
#include "lauxlib.h"
#include "lauxlib.h"
...
@@ -340,9 +340,9 @@ static int readable (const char *filename) {
...
@@ -340,9 +340,9 @@ static int readable (const char *filename) {
}
}
#else
#else
static
int
readable
(
const
char
*
filename
)
{
static
int
readable
(
const
char
*
filename
)
{
int
f
=
fs_open
(
filename
,
FS_RDONLY
);
/* try to open file */
int
f
=
v
fs_open
(
filename
,
"r"
);
/* try to open file */
if
(
f
<
FS_OPEN_OK
)
return
0
;
/* open failed */
if
(
!
f
)
return
0
;
/* open failed */
fs_close
(
f
);
v
fs_close
(
f
);
return
1
;
return
1
;
}
}
#endif
#endif
...
...
app/lua/lua.c
View file @
7b83bbb2
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include "c_stdio.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "c_string.h"
#include "
flash_fs
.h"
#include "
user_interface
.h"
#include "user_version.h"
#include "user_version.h"
#include "driver/readline.h"
#include "driver/readline.h"
#include "driver/uart.h"
#include "driver/uart.h"
...
...
app/lua/lvm.c
View file @
7b83bbb2
...
@@ -759,7 +759,6 @@ void luaV_execute (lua_State *L, int nexeccalls) {
...
@@ -759,7 +759,6 @@ void luaV_execute (lua_State *L, int nexeccalls) {
fixedstack
(
L
);
fixedstack
(
L
);
if
(
n
==
0
)
{
if
(
n
==
0
)
{
n
=
cast_int
(
L
->
top
-
ra
)
-
1
;
n
=
cast_int
(
L
->
top
-
ra
)
-
1
;
L
->
top
=
L
->
ci
->
top
;
}
}
if
(
c
==
0
)
c
=
cast_int
(
*
pc
++
);
if
(
c
==
0
)
c
=
cast_int
(
*
pc
++
);
runtime_check
(
L
,
ttistable
(
ra
));
runtime_check
(
L
,
ttistable
(
ra
));
...
@@ -772,6 +771,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
...
@@ -772,6 +771,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
setobj2t
(
L
,
luaH_setnum
(
L
,
h
,
last
--
),
val
);
setobj2t
(
L
,
luaH_setnum
(
L
,
h
,
last
--
),
val
);
luaC_barriert
(
L
,
h
,
val
);
luaC_barriert
(
L
,
h
,
val
);
}
}
L
->
top
=
L
->
ci
->
top
;
unfixedstack
(
L
);
unfixedstack
(
L
);
continue
;
continue
;
}
}
...
...
app/lwip/core/dns.c
View file @
7b83bbb2
...
@@ -254,8 +254,16 @@ dns_init()
...
@@ -254,8 +254,16 @@ dns_init()
LWIP_ASSERT
(
"For implicit initialization to work, DNS_STATE_UNUSED needs to be 0"
,
LWIP_ASSERT
(
"For implicit initialization to work, DNS_STATE_UNUSED needs to be 0"
,
DNS_STATE_UNUSED
==
0
);
DNS_STATE_UNUSED
==
0
);
/* initialize DNS client */
/* PR #1324 */
udp_bind
(
dns_pcb
,
IP_ADDR_ANY
,
0
);
/* 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
);
udp_recv
(
dns_pcb
,
dns_recv
,
NULL
);
/* initialize default DNS primary server */
/* 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)
...
@@ -758,10 +758,6 @@ udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
/* no port specified? */
/* no port specified? */
if
(
port
==
0
)
{
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
;
port
=
UDP_LOCAL_PORT_RANGE_START
;
ipcb
=
udp_pcbs
;
ipcb
=
udp_pcbs
;
while
((
ipcb
!=
NULL
)
&&
(
port
!=
UDP_LOCAL_PORT_RANGE_END
))
{
while
((
ipcb
!=
NULL
)
&&
(
port
!=
UDP_LOCAL_PORT_RANGE_END
))
{
...
...
app/modules/Makefile
View file @
7b83bbb2
...
@@ -52,7 +52,9 @@ INCLUDES += -I ../spiffs
...
@@ -52,7 +52,9 @@ INCLUDES += -I ../spiffs
INCLUDES
+=
-I
../smart
INCLUDES
+=
-I
../smart
INCLUDES
+=
-I
../cjson
INCLUDES
+=
-I
../cjson
INCLUDES
+=
-I
../dhtlib
INCLUDES
+=
-I
../dhtlib
INCLUDES
+=
-I
../fatfs
INCLUDES
+=
-I
../http
INCLUDES
+=
-I
../http
INCLUDES
+=
-I
../websocket
PDIR
:=
../
$(PDIR)
PDIR
:=
../
$(PDIR)
sinclude
$(PDIR)Makefile
sinclude
$(PDIR)Makefile
app/modules/bme280.c
View file @
7b83bbb2
...
@@ -304,7 +304,7 @@ static int bme280_lua_init(lua_State* L) {
...
@@ -304,7 +304,7 @@ static int bme280_lua_init(lua_State* L) {
static
void
bme280_readoutdone
(
void
*
arg
)
static
void
bme280_readoutdone
(
void
*
arg
)
{
{
NODE_DBG
(
"timer out
\n
"
);
NODE_DBG
(
"timer out
\n
"
);
lua_State
*
L
=
arg
;
lua_State
*
L
=
lua_getstate
()
;
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
lua_connected_readout_ref
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
lua_connected_readout_ref
);
lua_call
(
L
,
0
,
0
);
lua_call
(
L
,
0
,
0
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
lua_connected_readout_ref
);
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[] = {
...
@@ -1617,8 +1617,6 @@ static const LUA_REG_TYPE cjson_map[] = {
int
luaopen_cjson
(
lua_State
*
L
)
int
luaopen_cjson
(
lua_State
*
L
)
{
{
cjson_mem_setlua
(
L
);
/* Initialise number conversions */
/* Initialise number conversions */
// fpconv_init(); // not needed for a specific cpu.
// fpconv_init(); // not needed for a specific cpu.
if
(
-
1
==
cfg_init
(
&
_cfg
)){
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