Commit fa7cf878 authored by zeroday's avatar zeroday
Browse files

Merge pull request #287 from nodemcu/dev

Dev merge to master
parents 6c8cace9 1652df50
#include "c_string.h"
#include "c_stdlib.h"
#include "node.h"
static inline coap_queue_t *
coap_malloc_node(void) {
return (coap_queue_t *)c_zalloc(sizeof(coap_queue_t));
}
void coap_free_node(coap_queue_t *node) {
c_free(node);
}
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
coap_queue_t *p, *q;
if ( !queue || !node )
return 0;
/* set queue head if empty */
if ( !*queue ) {
*queue = node;
return 1;
}
/* replace queue head if PDU's time is less than head's time */
q = *queue;
if (node->t < q->t) {
node->next = q;
*queue = node;
q->t -= node->t; /* make q->t relative to node->t */
return 1;
}
/* search for right place to insert */
do {
node->t -= q->t; /* make node-> relative to q->t */
p = q;
q = q->next;
} while (q && q->t <= node->t);
/* insert new item */
if (q) {
q->t -= node->t; /* make q->t relative to node->t */
}
node->next = q;
p->next = node;
return 1;
}
int coap_delete_node(coap_queue_t *node) {
if ( !node )
return 0;
coap_delete_pdu(node->pdu);
coap_free_node(node);
return 1;
}
void coap_delete_all(coap_queue_t *queue) {
if ( !queue )
return;
coap_delete_all( queue->next );
coap_delete_node( queue );
}
coap_queue_t * coap_new_node(void) {
coap_queue_t *node;
node = coap_malloc_node();
if ( ! node ) {
return NULL;
}
c_memset(node, 0, sizeof(*node));
return node;
}
coap_queue_t * coap_peek_next( coap_queue_t *queue ) {
if ( !queue )
return NULL;
return queue;
}
coap_queue_t * coap_pop_next( coap_queue_t **queue ) { // this function is called inside timeout callback only.
coap_queue_t *next;
if ( !(*queue) )
return NULL;
next = *queue;
*queue = (*queue)->next;
// if (queue) {
// queue->t += next->t;
// }
next->next = NULL;
return next;
}
int coap_remove_node( coap_queue_t **queue, const coap_tid_t id){
coap_queue_t *p, *q, *node;
if ( !queue )
return 0;
if ( !*queue ) // if empty
return 0;
q = *queue;
if (q->id == id) {
node = q;
*queue = q->next;
node->next = NULL;
if(*queue){
(*queue)->t += node->t;
}
coap_delete_node(node);
return 1;
}
/* search for right node to remove */
while (q && q->id != id) {
p = q;
q = q->next;
}
/* find the node */
if (q) {
node = q; /* save the node */
p->next = q->next; /* remove the node */
q = q->next;
node->next = NULL;
if (q) // add node->t to the node after.
{
q->t += node->t;
}
coap_delete_node(node);
return 1;
}
return 0;
}
#ifndef _NODE_H
#define _NODE_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include "hash.h"
#include "pdu.h"
struct coap_queue_t;
typedef uint32_t coap_tick_t;
/*
1. queue(first)->t store when to send PDU for the next time, it's a base(absolute) time
2. queue->next->t store the delta between time and base-time. queue->next->t = timeout + now - basetime
3. node->next->t store the delta between time and previous->t. node->next->t = timeout + now - node->t - basetime
4. time to fire: 10, 15, 18, 25
node->t: 10, 5, 3, 7
*/
typedef struct coap_queue_t {
struct coap_queue_t *next;
coap_tick_t t; /**< when to send PDU for the next time */
unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */
unsigned int timeout; /**< the randomized timeout value */
coap_tid_t id; /**< unique transaction id */
// coap_packet_t *pkt;
coap_pdu_t *pdu; /**< the CoAP PDU to send */
struct espconn *pconn;
} coap_queue_t;
void coap_free_node(coap_queue_t *node);
/** Adds node to given queue, ordered by node->t. */
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node);
/** Destroys specified node. */
int coap_delete_node(coap_queue_t *node);
/** Removes all items from given queue and frees the allocated storage. */
void coap_delete_all(coap_queue_t *queue);
/** Creates a new node suitable for adding to the CoAP sendqueue. */
coap_queue_t *coap_new_node(void);
coap_queue_t *coap_pop_next( coap_queue_t **queue );
int coap_remove_node( coap_queue_t **queue, const coap_tid_t id);
#ifdef __cplusplus
}
#endif
#endif
#include "c_stdlib.h"
#include "pdu.h"
coap_pdu_t * coap_new_pdu(void) {
coap_pdu_t *pdu = NULL;
pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t));
if(!pdu){
NODE_DBG("coap_new_pdu malloc error.\n");
return NULL;
}
pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE);
if(!pdu->scratch.p){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu);
return NULL;
}
pdu->scratch.len = MAX_REQ_SCRATCH_SIZE;
pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t));
if(!pdu->pkt){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->scratch.p);
c_free(pdu);
return NULL;
}
pdu->pkt->content.p = NULL;
pdu->pkt->content.len = 0;
pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
if(!pdu->msg.p){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->pkt);
c_free(pdu->scratch.p);
c_free(pdu);
return NULL;
}
pdu->msg.len = MAX_REQUEST_SIZE;
return pdu;
}
void coap_delete_pdu(coap_pdu_t *pdu){
if(!pdu)
return;
if(pdu->scratch.p){
c_free(pdu->scratch.p);
pdu->scratch.p = NULL;
pdu->scratch.len = 0;
}
if(pdu->pkt){
c_free(pdu->pkt);
pdu->pkt = NULL;
}
if(pdu->msg.p){
c_free(pdu->msg.p);
pdu->msg.p = NULL;
pdu->msg.len = 0;
}
c_free(pdu);
pdu = NULL;
}
#ifndef _PDU_H
#define _PDU_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include "coap.h"
/** Header structure for CoAP PDUs */
typedef struct {
coap_rw_buffer_t scratch;
coap_packet_t *pkt;
coap_rw_buffer_t msg; /**< the CoAP msg to send */
} coap_pdu_t;
coap_pdu_t *coap_new_pdu(void);
void coap_delete_pdu(coap_pdu_t *pdu);
#ifdef __cplusplus
}
#endif
#endif
/* str.c -- strings to be used in the CoAP library
*
* Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#include "c_stdlib.h"
#include "c_types.h"
#include "str.h"
str * coap_new_string(size_t size) {
str *s = (str *)c_malloc(sizeof(str) + size + 1);
if ( !s ) {
return NULL;
}
c_memset(s, 0, sizeof(str));
s->s = ((unsigned char *)s) + sizeof(str);
return s;
}
void coap_delete_string(str *s) {
c_free(s);
}
/* str.h -- strings to be used in the CoAP library
*
* Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#ifndef _COAP_STR_H_
#define _COAP_STR_H_
#include "c_string.h"
typedef struct {
size_t length; /* length of string */
unsigned char *s; /* string data */
} str;
#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
/**
* Returns a new string object with at least size bytes storage
* allocated. The string must be released using coap_delete_string();
*/
str *coap_new_string(size_t size);
/** Deletes the given string and releases any memory allocated. */
void coap_delete_string(str *);
#endif /* _COAP_STR_H_ */
/* uri.c -- helper functions for URI treatment
*/
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "c_ctype.h"
#include "coap.h"
#include "uri.h"
#ifndef assert
// #warning "assertions are disabled"
# define assert(x) do { \
if(!x) NODE_ERR("uri.c assert!\n"); \
} while (0)
#endif
/**
* A length-safe version of strchr(). This function returns a pointer
* to the first occurrence of @p c in @p s, or @c NULL if not found.
*
* @param s The string to search for @p c.
* @param len The length of @p s.
* @param c The character to search.
*
* @return A pointer to the first occurence of @p c, or @c NULL
* if not found.
*/
static inline unsigned char *
strnchr(unsigned char *s, size_t len, unsigned char c) {
while (len && *s++ != c)
--len;
return len ? s : NULL;
}
int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
unsigned char *p, *q;
int secure = 0, res = 0;
if (!str_var || !uri)
return -1;
c_memset(uri, 0, sizeof(coap_uri_t));
uri->port = COAP_DEFAULT_PORT;
/* search for scheme */
p = str_var;
if (*p == '/') {
q = p;
goto path;
}
q = (unsigned char *)COAP_DEFAULT_SCHEME;
while (len && *q && tolower(*p) == *q) {
++p; ++q; --len;
}
/* If q does not point to the string end marker '\0', the schema
* identifier is wrong. */
if (*q) {
res = -1;
goto error;
}
/* There might be an additional 's', indicating the secure version: */
if (len && (secure = tolower(*p) == 's')) {
++p; --len;
}
q = (unsigned char *)"://";
while (len && *q && tolower(*p) == *q) {
++p; ++q; --len;
}
if (*q) {
res = -2;
goto error;
}
/* p points to beginning of Uri-Host */
q = p;
if (len && *p == '[') { /* IPv6 address reference */
++p;
while (len && *q != ']') {
++q; --len;
}
if (!len || *q != ']' || p == q) {
res = -3;
goto error;
}
COAP_SET_STR(&uri->host, q - p, p);
++q; --len;
} else { /* IPv4 address or FQDN */
while (len && *q != ':' && *q != '/' && *q != '?') {
*q = tolower(*q);
++q;
--len;
}
if (p == q) {
res = -3;
goto error;
}
COAP_SET_STR(&uri->host, q - p, p);
}
/* check for Uri-Port */
if (len && *q == ':') {
p = ++q;
--len;
while (len && isdigit(*q)) {
++q;
--len;
}
if (p < q) { /* explicit port number given */
int uri_port = 0;
while (p < q)
uri_port = uri_port * 10 + (*p++ - '0');
uri->port = uri_port;
}
}
path: /* at this point, p must point to an absolute path */
if (!len)
goto end;
if (*q == '/') {
p = ++q;
--len;
while (len && *q != '?') {
++q;
--len;
}
if (p < q) {
COAP_SET_STR(&uri->path, q - p, p);
p = q;
}
}
/* Uri_Query */
if (len && *p == '?') {
++p;
--len;
COAP_SET_STR(&uri->query, len, p);
len = 0;
}
end:
return len ? -1 : 0;
error:
return res;
}
/**
* Calculates decimal value from hexadecimal ASCII character given in
* @p c. The caller must ensure that @p c actually represents a valid
* heaxdecimal character, e.g. with isxdigit(3).
*
* @hideinitializer
*/
#define hexchar_to_dec(c) ((c) & 0x40 ? ((c) & 0x0F) + 9 : ((c) & 0x0F))
/**
* Decodes percent-encoded characters while copying the string @p seg
* of size @p length to @p buf. The caller of this function must
* ensure that the percent-encodings are correct (i.e. the character
* '%' is always followed by two hex digits. and that @p buf provides
* sufficient space to hold the result. This function is supposed to
* be called by make_decoded_option() only.
*
* @param seg The segment to decode and copy.
* @param length Length of @p seg.
* @param buf The result buffer.
*/
void decode_segment(const unsigned char *seg, size_t length, unsigned char *buf) {
while (length--) {
if (*seg == '%') {
*buf = (hexchar_to_dec(seg[1]) << 4) + hexchar_to_dec(seg[2]);
seg += 2; length -= 2;
} else {
*buf = *seg;
}
++buf; ++seg;
}
}
/**
* Runs through the given path (or query) segment and checks if
* percent-encodings are correct. This function returns @c -1 on error
* or the length of @p s when decoded.
*/
int check_segment(const unsigned char *s, size_t length) {
size_t n = 0;
while (length) {
if (*s == '%') {
if (length < 2 || !(isxdigit(s[1]) && isxdigit(s[2])))
return -1;
s += 2;
length -= 2;
}
++s; ++n; --length;
}
return n;
}
/**
* Writes a coap option from given string @p s to @p buf. @p s should
* point to a (percent-encoded) path or query segment of a coap_uri_t
* object. The created option will have type @c 0, and the length
* parameter will be set according to the size of the decoded string.
* On success, this function returns the option's size, or a value
* less than zero on error. This function must be called from
* coap_split_path_impl() only.
*
* @param s The string to decode.
* @param length The size of the percent-encoded string @p s.
* @param buf The buffer to store the new coap option.
* @param buflen The maximum size of @p buf.
*
* @return The option's size, or @c -1 on error.
*
* @bug This function does not split segments that are bigger than 270
* bytes.
*/
int make_decoded_option(const unsigned char *s, size_t length,
unsigned char *buf, size_t buflen) {
int res;
size_t written;
if (!buflen) {
NODE_DBG("make_decoded_option(): buflen is 0!\n");
return -1;
}
res = check_segment(s, length);
if (res < 0)
return -1;
/* write option header using delta 0 and length res */
// written = coap_opt_setheader(buf, buflen, 0, res);
written = coap_buildOptionHeader(0, res, buf, buflen);
assert(written <= buflen);
if (!written) /* encoding error */
return -1;
buf += written; /* advance past option type/length */
buflen -= written;
if (buflen < (size_t)res) {
NODE_DBG("buffer too small for option\n");
return -1;
}
decode_segment(s, length, buf);
return written + res;
}
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
typedef void (*segment_handler_t)(unsigned char *, size_t, void *);
/**
* Splits the given string into segments. You should call one of the
* macros coap_split_path() or coap_split_query() instead.
*
* @param parse_iter The iterator used for tokenizing.
* @param h A handler that is called with every token.
* @param data Opaque data that is passed to @p h when called.
*
* @return The number of characters that have been parsed from @p s.
*/
size_t coap_split_path_impl(coap_parse_iterator_t *parse_iter,
segment_handler_t h, void *data) {
unsigned char *seg;
size_t length;
assert(parse_iter);
assert(h);
length = parse_iter->n;
while ( (seg = coap_parse_next(parse_iter)) ) {
/* any valid path segment is handled here: */
h(seg, parse_iter->segment_length, data);
}
return length - (parse_iter->n - parse_iter->segment_length);
}
struct pkt_scr {
coap_packet_t *pkt;
coap_rw_buffer_t *scratch;
int n;
};
void write_option(unsigned char *s, size_t len, void *data) {
struct pkt_scr *state = (struct pkt_scr *)data;
int res;
assert(state);
/* skip empty segments and those that consist of only one or two dots */
if (memcmp(s, "..", min(len,2)) == 0)
return;
res = check_segment(s, len);
if (res < 0){
NODE_DBG("not a valid segment\n");
return;
}
if (state->scratch->len < (size_t)res) {
NODE_DBG("buffer too small for option\n");
return;
}
decode_segment(s, len, state->scratch->p);
if (res > 0) {
state->pkt->opts[state->pkt->numopts].buf.p = state->scratch->p;
state->pkt->opts[state->pkt->numopts].buf.len = res;
state->scratch->p += res;
state->scratch->len -= res;
state->pkt->numopts++;
state->n++;
}
}
int coap_split_path(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsigned char *s, size_t length) {
struct pkt_scr tmp = { pkt, scratch, 0 };
coap_parse_iterator_t pi;
coap_parse_iterator_init((unsigned char *)s, length,
'/', (unsigned char *)"?#", 2, &pi);
coap_split_path_impl(&pi, write_option, &tmp);
int i;
for(i=0;i<tmp.n;i++){
pkt->opts[pkt->numopts - i - 1].num = COAP_OPTION_URI_PATH;
}
return tmp.n;
}
int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsigned char *s, size_t length) {
struct pkt_scr tmp = { pkt, scratch, 0 };
coap_parse_iterator_t pi;
coap_parse_iterator_init((unsigned char *)s, length,
'&', (unsigned char *)"#", 1, &pi);
coap_split_path_impl(&pi, write_option, &tmp);
int i;
for(i=0;i<tmp.n;i++){
pkt->opts[pkt->numopts - i - 1].num = COAP_OPTION_URI_QUERY;
}
return tmp.n;
}
#define URI_DATA(uriobj) ((unsigned char *)(uriobj) + sizeof(coap_uri_t))
coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) {
unsigned char *result;
result = (unsigned char *)c_malloc(length + 1 + sizeof(coap_uri_t));
if (!result)
return NULL;
c_memcpy(URI_DATA(result), uri, length);
URI_DATA(result)[length] = '\0'; /* make it zero-terminated */
if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
c_free(result);
return NULL;
}
return (coap_uri_t *)result;
}
/* iterator functions */
coap_parse_iterator_t * coap_parse_iterator_init(unsigned char *s, size_t n,
unsigned char separator,
unsigned char *delim, size_t dlen,
coap_parse_iterator_t *pi) {
assert(pi);
assert(separator);
pi->separator = separator;
pi->delim = delim;
pi->dlen = dlen;
pi->pos = s;
pi->n = n;
pi->segment_length = 0;
return pi;
}
unsigned char * coap_parse_next(coap_parse_iterator_t *pi) {
unsigned char *p;
if (!pi)
return NULL;
/* proceed to the next segment */
pi->n -= pi->segment_length;
pi->pos += pi->segment_length;
pi->segment_length = 0;
/* last segment? */
if (!pi->n || strnchr(pi->delim, pi->dlen, *pi->pos)) {
pi->pos = NULL;
return NULL;
}
/* skip following separator (the first segment might not have one) */
if (*pi->pos == pi->separator) {
++pi->pos;
--pi->n;
}
p = pi->pos;
while (pi->segment_length < pi->n && *p != pi->separator &&
!strnchr(pi->delim, pi->dlen, *p)) {
++p;
++pi->segment_length;
}
if (!pi->n) {
pi->pos = NULL;
pi->segment_length = 0;
}
return pi->pos;
}
/* uri.h -- helper functions for URI treatment
*
* Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#ifndef _COAP_URI_H_
#define _COAP_URI_H_
#define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */
#define COAP_DEFAULT_PORT 5683
#include "str.h"
/** Representation of parsed URI. Components may be filled from a
* string with coap_split_uri() and can be used as input for
* option-creation functions. */
typedef struct {
str host; /**< host part of the URI */
unsigned short port; /**< The port in host byte order */
str path; /**< Beginning of the first path segment.
Use coap_split_path() to create Uri-Path options */
str query; /**< The query part if present */
} coap_uri_t;
/**
* Creates a new coap_uri_t object from the specified URI. Returns the new
* object or NULL on error. The memory allocated by the new coap_uri_t
* must be released using coap_free().
* @param uri The URI path to copy.
* @para length The length of uri.
*
* @return New URI object or NULL on error.
*/
coap_uri_t *coap_new_uri(const unsigned char *uri, unsigned int length);
/**
* @defgroup uri_parse URI Parsing Functions
*
* CoAP PDUs contain normalized URIs with their path and query split into
* multiple segments. The functions in this module help splitting strings.
* @{
*/
/**
* Iterator to for tokenizing a URI path or query. This structure must
* be initialized with coap_parse_iterator_init(). Call
* coap_parse_next() to walk through the tokens.
*
* @code
* unsigned char *token;
* coap_parse_iterator_t pi;
* coap_parse_iterator_init(uri.path.s, uri.path.length, '/', "?#", 2, &pi);
*
* while ((token = coap_parse_next(&pi))) {
* ... do something with token ...
* }
* @endcode
*/
typedef struct {
size_t n; /**< number of remaining characters in buffer */
unsigned char separator; /**< segment separators */
unsigned char *delim; /**< delimiters where to split the string */
size_t dlen; /**< length of separator */
unsigned char *pos; /**< current position in buffer */
size_t segment_length; /**< length of current segment */
} coap_parse_iterator_t;
/**
* Initializes the given iterator @p pi.
*
* @param s The string to tokenize.
* @param n The length of @p s.
* @param separator The separator character that delimits tokens.
* @param delim A set of characters that delimit @s.
* @param dlen The length of @p delim.
* @param pi The iterator object to initialize.
*
* @return The initialized iterator object @p pi.
*/
coap_parse_iterator_t *
coap_parse_iterator_init(unsigned char *s, size_t n,
unsigned char separator,
unsigned char *delim, size_t dlen,
coap_parse_iterator_t *pi);
/**
* Updates the iterator @p pi to point to the next token. This
* function returns a pointer to that token or @c NULL if no more
* tokens exist. The contents of @p pi will be updated. In particular,
* @c pi->segment_length specifies the length of the current token, @c
* pi->pos points to its beginning.
*
* @param pi The iterator to update.
*
* @return The next token or @c NULL if no more tokens exist.
*/
unsigned char *coap_parse_next(coap_parse_iterator_t *pi);
/**
* Parses a given string into URI components. The identified syntactic
* components are stored in the result parameter @p uri. Optional URI
* components that are not specified will be set to { 0, 0 }, except
* for the port which is set to @c COAP_DEFAULT_PORT. This function
* returns @p 0 if parsing succeeded, a value less than zero
* otherwise.
*
* @param str_var The string to split up.
* @param len The actual length of @p str_var
* @param uri The coap_uri_t object to store the result.
* @return @c 0 on success, or < 0 on error.
*
* @note The host name part will be converted to lower case by this
* function.
*/
int
coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri);
/**
* Splits the given URI path into segments. Each segment is preceded
* by an option pseudo-header with delta-value 0 and the actual length
* of the respective segment after percent-decoding.
*
* @param s The path string to split.
* @param length The actual length of @p s.
* @param buf Result buffer for parsed segments.
* @param buflen Maximum length of @p buf. Will be set to the actual number
* of bytes written into buf on success.
*
* @return The number of segments created or @c -1 on error.
*/
#if 0
int coap_split_path(const unsigned char *s, size_t length,
unsigned char *buf, size_t *buflen);
#else
int
coap_split_path(coap_rw_buffer_t *scratch, coap_packet_t *pkt,
const unsigned char *s, size_t length);
#endif
/**
* Splits the given URI query into segments. Each segment is preceded
* by an option pseudo-header with delta-value 0 and the actual length
* of the respective query term.
*
* @param s The query string to split.
* @param length The actual length of @p s.
* @param buf Result buffer for parsed segments.
* @param buflen Maximum length of @p buf. Will be set to the actual number
* of bytes written into buf on success.
*
* @return The number of segments created or @c -1 on error.
*
* @bug This function does not reserve additional space for delta > 12.
*/
#if 0
int coap_split_query(const unsigned char *s, size_t length,
unsigned char *buf, size_t *buflen);
#else
int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt,
const unsigned char *s, size_t length);
#endif
/** @} */
#endif /* _COAP_URI_H_ */
#ifndef __U8G_CONFIG_H__
#define __U8G_CONFIG_H__
// Configure U8glib fonts
// add a U8G_FONT_TABLE_ENTRY for each font you want to compile into the image
#define U8G_FONT_TABLE_ENTRY(font)
#define U8G_FONT_TABLE \
U8G_FONT_TABLE_ENTRY(font_6x10) \
U8G_FONT_TABLE_ENTRY(font_chikita)
#undef U8G_FONT_TABLE_ENTRY
// Enable display drivers
#define U8G_SSD1306_128x64_I2C
#define U8G_SSD1306_128x64_SPI
// untested
#undef U8G_PCD8544_84x48
#endif /* __U8G_CONFIG_H__ */
#ifndef __USER_CONFIG_H__ #ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__ #define __USER_CONFIG_H__
#define NODE_VERSION_MAJOR 0U
#define NODE_VERSION_MINOR 9U
#define NODE_VERSION_REVISION 5U
#define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMCU 0.9.5"
#define BUILD_DATE "build 20150213"
// #define DEVKIT_VERSION_0_9 1 // define this only if you use NodeMCU devkit v0.9 // #define DEVKIT_VERSION_0_9 1 // define this only if you use NodeMCU devkit v0.9
// #define FLASH_512K // #define FLASH_512K
...@@ -18,6 +10,7 @@ ...@@ -18,6 +10,7 @@
// #define FLASH_8M // #define FLASH_8M
// #define FLASH_16M // #define FLASH_16M
#define FLASH_AUTOSIZE #define FLASH_AUTOSIZE
#define FLASH_SAFE_API
// #define DEVELOP_VERSION // #define DEVELOP_VERSION
#define FULL_VERSION_FOR_USER #define FULL_VERSION_FOR_USER
...@@ -25,6 +18,7 @@ ...@@ -25,6 +18,7 @@
#ifdef DEVELOP_VERSION #ifdef DEVELOP_VERSION
#define NODE_DEBUG #define NODE_DEBUG
#define COAP_DEBUG
#endif /* DEVELOP_VERSION */ #endif /* DEVELOP_VERSION */
#define NODE_ERROR #define NODE_ERROR
...@@ -51,32 +45,6 @@ ...@@ -51,32 +45,6 @@
// #define BUILD_WOFS 1 // #define BUILD_WOFS 1
#define BUILD_SPIFFS 1 #define BUILD_SPIFFS 1
#define LUA_USE_MODULES
#ifdef LUA_USE_MODULES
#define LUA_USE_MODULES_NODE
#define LUA_USE_MODULES_FILE
#define LUA_USE_MODULES_GPIO
#define LUA_USE_MODULES_WIFI
#define LUA_USE_MODULES_NET
#define LUA_USE_MODULES_PWM
#define LUA_USE_MODULES_I2C
#define LUA_USE_MODULES_SPI
#define LUA_USE_MODULES_TMR
#define LUA_USE_MODULES_ADC
#define LUA_USE_MODULES_UART
#define LUA_USE_MODULES_OW
#define LUA_USE_MODULES_BIT
#define LUA_USE_MODULES_MQTT
// #define LUA_USE_MODULES_WS2812 // TODO: put this device specific module to device driver section.
#endif /* LUA_USE_MODULES */
// TODO: put device specific module to device driver section.
#ifdef LUA_USE_DEVICE_DRIVER
#define LUA_USE_DEVICE_WS2812
#endif /* LUA_USE_DEVICE_DRIVER */
// #define LUA_NUMBER_INTEGRAL // #define LUA_NUMBER_INTEGRAL
#define LUA_OPTRAM #define LUA_OPTRAM
......
#ifndef __USER_MODULES_H__
#define __USER_MODULES_H__
#define LUA_USE_BUILTIN_STRING // for string.xxx()
#define LUA_USE_BUILTIN_TABLE // for table.xxx()
#define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx()
#define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work
// #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work
// #define LUA_USE_BUILTIN_OS // for os.xxx(), not work
// #define LUA_USE_BUILTIN_DEBUG // for debug.xxx(), not work
#define LUA_USE_MODULES
#ifdef LUA_USE_MODULES
#define LUA_USE_MODULES_NODE
#define LUA_USE_MODULES_FILE
#define LUA_USE_MODULES_GPIO
#define LUA_USE_MODULES_WIFI
#define LUA_USE_MODULES_NET
#define LUA_USE_MODULES_PWM
#define LUA_USE_MODULES_I2C
#define LUA_USE_MODULES_SPI
#define LUA_USE_MODULES_TMR
#define LUA_USE_MODULES_ADC
#define LUA_USE_MODULES_UART
#define LUA_USE_MODULES_OW
#define LUA_USE_MODULES_BIT
#define LUA_USE_MODULES_MQTT
#define LUA_USE_MODULES_COAP
#define LUA_USE_MODULES_U8G
#define LUA_USE_MODULES_WS2812
#endif /* LUA_USE_MODULES */
#endif /* __USER_MODULES_H__ */
#ifndef __USER_VERSION_H__
#define __USER_VERSION_H__
#define NODE_VERSION_MAJOR 0U
#define NODE_VERSION_MINOR 9U
#define NODE_VERSION_REVISION 5U
#define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMCU 0.9.5"
#define BUILD_DATE "build 20150315"
#endif /* __USER_VERSION_H__ */
...@@ -63,7 +63,7 @@ int c_stderr = 1001; ...@@ -63,7 +63,7 @@ int c_stderr = 1001;
#define ENDIAN_LITTLE 1234 #define ENDIAN_LITTLE 1234
#define ENDIAN_BIG 4321 #define ENDIAN_BIG 4321
#define ENDIAN_PDP 3412 #define ENDIAN_PDP 3412
#define ENDIAN ENDIAN_BIG #define ENDIAN ENDIAN_LITTLE
/* $Id: strichr.c,v 1.1.1.1 2006/08/23 17:03:06 pefo Exp $ */ /* $Id: strichr.c,v 1.1.1.1 2006/08/23 17:03:06 pefo Exp $ */
......
...@@ -698,6 +698,8 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) { ...@@ -698,6 +698,8 @@ LUALIB_API int luaL_loadfsfile (lua_State *L, const char *filename) {
lf.f = fs_open(filename, FS_RDONLY); lf.f = fs_open(filename, FS_RDONLY);
if (lf.f < FS_OPEN_OK) return errfsfile(L, "open", fnameindex); if (lf.f < FS_OPEN_OK) 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 = fs_getc(lf.f);
if (c == '#') { /* Unix exec. file? */ if (c == '#') { /* Unix exec. file? */
lf.extraline = 1; lf.extraline = 1;
......
...@@ -324,36 +324,36 @@ const LUA_REG_TYPE math_map[] = { ...@@ -324,36 +324,36 @@ const LUA_REG_TYPE math_map[] = {
#endif #endif
#else #else
{LSTRKEY("abs"), LFUNCVAL(math_abs)}, {LSTRKEY("abs"), LFUNCVAL(math_abs)},
{LSTRKEY("acos"), LFUNCVAL(math_acos)}, // {LSTRKEY("acos"), LFUNCVAL(math_acos)},
{LSTRKEY("asin"), LFUNCVAL(math_asin)}, // {LSTRKEY("asin"), LFUNCVAL(math_asin)},
{LSTRKEY("atan2"), LFUNCVAL(math_atan2)}, // {LSTRKEY("atan2"), LFUNCVAL(math_atan2)},
{LSTRKEY("atan"), LFUNCVAL(math_atan)}, // {LSTRKEY("atan"), LFUNCVAL(math_atan)},
{LSTRKEY("ceil"), LFUNCVAL(math_ceil)}, {LSTRKEY("ceil"), LFUNCVAL(math_ceil)},
{LSTRKEY("cosh"), LFUNCVAL(math_cosh)}, // {LSTRKEY("cosh"), LFUNCVAL(math_cosh)},
{LSTRKEY("cos"), LFUNCVAL(math_cos)}, // {LSTRKEY("cos"), LFUNCVAL(math_cos)},
{LSTRKEY("deg"), LFUNCVAL(math_deg)}, // {LSTRKEY("deg"), LFUNCVAL(math_deg)},
{LSTRKEY("exp"), LFUNCVAL(math_exp)}, // {LSTRKEY("exp"), LFUNCVAL(math_exp)},
{LSTRKEY("floor"), LFUNCVAL(math_floor)}, {LSTRKEY("floor"), LFUNCVAL(math_floor)},
{LSTRKEY("fmod"), LFUNCVAL(math_fmod)}, // {LSTRKEY("fmod"), LFUNCVAL(math_fmod)},
#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_MOD) #if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_MOD)
{LSTRKEY("mod"), LFUNCVAL(math_fmod)}, {LSTRKEY("mod"), LFUNCVAL(math_fmod)},
#endif #endif
{LSTRKEY("frexp"), LFUNCVAL(math_frexp)}, // {LSTRKEY("frexp"), LFUNCVAL(math_frexp)},
{LSTRKEY("ldexp"), LFUNCVAL(math_ldexp)}, // {LSTRKEY("ldexp"), LFUNCVAL(math_ldexp)},
{LSTRKEY("log10"), LFUNCVAL(math_log10)}, // {LSTRKEY("log10"), LFUNCVAL(math_log10)},
{LSTRKEY("log"), LFUNCVAL(math_log)}, // {LSTRKEY("log"), LFUNCVAL(math_log)},
{LSTRKEY("max"), LFUNCVAL(math_max)}, {LSTRKEY("max"), LFUNCVAL(math_max)},
{LSTRKEY("min"), LFUNCVAL(math_min)}, {LSTRKEY("min"), LFUNCVAL(math_min)},
{LSTRKEY("modf"), LFUNCVAL(math_modf)}, // {LSTRKEY("modf"), LFUNCVAL(math_modf)},
{LSTRKEY("pow"), LFUNCVAL(math_pow)}, {LSTRKEY("pow"), LFUNCVAL(math_pow)},
{LSTRKEY("rad"), LFUNCVAL(math_rad)}, // {LSTRKEY("rad"), LFUNCVAL(math_rad)},
{LSTRKEY("random"), LFUNCVAL(math_random)}, {LSTRKEY("random"), LFUNCVAL(math_random)},
{LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)}, {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
{LSTRKEY("sinh"), LFUNCVAL(math_sinh)}, // {LSTRKEY("sinh"), LFUNCVAL(math_sinh)},
{LSTRKEY("sin"), LFUNCVAL(math_sin)}, // {LSTRKEY("sin"), LFUNCVAL(math_sin)},
{LSTRKEY("sqrt"), LFUNCVAL(math_sqrt)}, {LSTRKEY("sqrt"), LFUNCVAL(math_sqrt)},
{LSTRKEY("tanh"), LFUNCVAL(math_tanh)}, // {LSTRKEY("tanh"), LFUNCVAL(math_tanh)},
{LSTRKEY("tan"), LFUNCVAL(math_tan)}, // {LSTRKEY("tan"), LFUNCVAL(math_tan)},
#if LUA_OPTIMIZE_MEMORY > 0 #if LUA_OPTIMIZE_MEMORY > 0
{LSTRKEY("pi"), LNUMVAL(PI)}, {LSTRKEY("pi"), LNUMVAL(PI)},
{LSTRKEY("huge"), LNUMVAL(HUGE_VAL)}, {LSTRKEY("huge"), LNUMVAL(HUGE_VAL)},
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define LNUMKEY LRO_NUMKEY #define LNUMKEY LRO_NUMKEY
#define LNILKEY LRO_NILKEY #define LNILKEY LRO_NILKEY
#define LFUNCVAL LRO_FUNCVAL #define LFUNCVAL LRO_FUNCVAL
#define LUDATA LRO_LUDATA
#define LNUMVAL LRO_NUMVAL #define LNUMVAL LRO_NUMVAL
#define LROVAL LRO_ROVAL #define LROVAL LRO_ROVAL
#define LNILVAL LRO_NILVAL #define LNILVAL LRO_NILVAL
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
/* Macros one can use to define rotable entries */ /* Macros one can use to define rotable entries */
#ifndef LUA_PACK_VALUE #ifndef LUA_PACK_VALUE
#define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION} #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION}
#define LRO_LUDATA(v) {{.p = v}, LUA_TLIGHTUSERDATA}
#define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER} #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
#define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE} #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE}
#define LRO_NILVAL {{.p = NULL}, LUA_TNIL} #define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
...@@ -18,10 +19,12 @@ ...@@ -18,10 +19,12 @@
#define LRO_NUMVAL(v) {.value.n = v} #define LRO_NUMVAL(v) {.value.n = v}
#ifdef ELUA_ENDIAN_LITTLE #ifdef ELUA_ENDIAN_LITTLE
#define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}} #define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}}
#define LRO_LUDATA(v) {{(int)v, add_sig(LUA_TLIGHTUSERDATA)}}
#define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}} #define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}}
#define LRO_NILVAL {{0, add_sig(LUA_TNIL)}} #define LRO_NILVAL {{0, add_sig(LUA_TNIL)}}
#else // #ifdef ELUA_ENDIAN_LITTLE #else // #ifdef ELUA_ENDIAN_LITTLE
#define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}} #define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}}
#define LRO_LUDATA(v) {{add_sig(LUA_TLIGHTUSERDATA), (int)v}}
#define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}} #define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}}
#define LRO_NILVAL {{add_sig(LUA_TNIL), 0}} #define LRO_NILVAL {{add_sig(LUA_TNIL), 0}}
#endif // #ifdef ELUA_ENDIAN_LITTLE #endif // #ifdef ELUA_ENDIAN_LITTLE
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "c_stdlib.h" #include "c_stdlib.h"
#include "c_string.h" #include "c_string.h"
#include "flash_fs.h" #include "flash_fs.h"
#include "user_version.h"
#define lua_c #define lua_c
......
...@@ -542,7 +542,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length); ...@@ -542,7 +542,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
/* /*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/ */
#define LUAL_BUFFERSIZE (BUFSIZ*4) #define LUAL_BUFFERSIZE ((BUFSIZ)*4)
/* }================================================================== */ /* }================================================================== */
......
...@@ -24,17 +24,17 @@ LUALIB_API int (luaopen_table) (lua_State *L); ...@@ -24,17 +24,17 @@ LUALIB_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io" #define LUA_IOLIBNAME "io"
LUALIB_API int (luaopen_io) (lua_State *L); LUALIB_API int (luaopen_io) (lua_State *L);
// #define LUA_OSLIBNAME "os" #define LUA_OSLIBNAME "os"
// LUALIB_API int (luaopen_os) (lua_State *L); LUALIB_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string" #define LUA_STRLIBNAME "string"
LUALIB_API int (luaopen_string) (lua_State *L); LUALIB_API int (luaopen_string) (lua_State *L);
// #define LUA_MATHLIBNAME "math" #define LUA_MATHLIBNAME "math"
// LUALIB_API int (luaopen_math) (lua_State *L); LUALIB_API int (luaopen_math) (lua_State *L);
// #define LUA_DBLIBNAME "debug" #define LUA_DBLIBNAME "debug"
// LUALIB_API int (luaopen_debug) (lua_State *L); LUALIB_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package" #define LUA_LOADLIBNAME "package"
LUALIB_API int (luaopen_package) (lua_State *L); LUALIB_API int (luaopen_package) (lua_State *L);
......
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