Commit d77666c0 authored by sergio's avatar sergio Committed by Terry Ellison
Browse files

trailing spaces cleanup (#2659)

parent d7583040
......@@ -42,7 +42,7 @@
* This file is part of the lwIP TCP/IP stack.
*
*/
#include "lwip/opt.h"
#if LWIP_ARP || LWIP_ETHERNET
......@@ -82,7 +82,7 @@ const struct eth_addr ethzero = {{0,0,0,0,0,0}};
/** the time an ARP entry stays pending after first request,
* for ARP_TMR_INTERVAL = 5000, this is
* (2 * 5) seconds = 10 seconds.
*
*
* @internal Keep this number at least 2, otherwise it might
* run out instantly if the timeout occurs directly after a request.
*/
......@@ -185,7 +185,7 @@ free_entry(int i)
free_etharp_q(arp_table[i].q);
arp_table[i].q = NULL;
}
/* recycle entry for re-use */
/* recycle entry for re-use */
arp_table[i].state = ETHARP_STATE_EMPTY;
#if ETHARP_SUPPORT_STATIC_ENTRIES
arp_table[i].static_entry = 0;
......@@ -248,14 +248,14 @@ etharp_tmr(void)
/**
* Search the ARP table for a matching or new entry.
*
*
* If an IP address is given, return a pending or stable ARP entry that matches
* the address. If no match is found, create a new entry with this address set,
* but in state ETHARP_EMPTY. The caller must check and possibly change the
* state of the returned entry.
*
*
* If ipaddr is NULL, return a initialized new entry in state ETHARP_EMPTY.
*
*
* In all cases, attempt to create new entries from an empty entry. If no
* empty entries are available and ETHARP_FLAG_TRY_HARD flag is set, recycle
* old entries. Heuristic choose the least important entry for recycling.
......@@ -263,7 +263,7 @@ etharp_tmr(void)
* @param ipaddr IP address to find in ARP cache, or to add if not found.
* @param flags @see definition of ETHARP_FLAG_*
* @param netif netif related to this address (used for NETIF_HWADDRHINT)
*
*
* @return The ARP entry index that matched or is created, ERR_MEM if no
* entry is found or could be recycled.
*/
......@@ -342,7 +342,7 @@ find_entry(ip_addr_t *ipaddr, u8_t flags)
}
}
/* { we have no match } => try to create a new entry */
/* don't create new entry, only search? */
if (((flags & ETHARP_FLAG_FIND_ONLY) != 0) ||
/* or no empty entry found and not allowed to recycle? */
......@@ -350,15 +350,15 @@ find_entry(ip_addr_t *ipaddr, u8_t flags)
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: no empty entry found and not allowed to recycle\n"));
return (s8_t)ERR_MEM;
}
/* b) choose the least destructive entry to recycle:
* 1) empty entry
* 2) oldest stable entry
* 3) oldest pending entry without queued packets
* 4) oldest pending entry with queued packets
*
*
* { ETHARP_FLAG_TRY_HARD is set at this point }
*/
*/
/* 1) empty entry available? */
if (empty < ARP_TABLE_SIZE) {
......@@ -439,7 +439,7 @@ etharp_send_ip(struct netif *netif, struct pbuf *p, struct eth_addr *src, struct
*
* If a pending entry is resolved, any queued packets will be sent
* at this point.
*
*
* @param netif netif related to this entry (used for NETIF_ADDRHINT)
* @param ipaddr IP address of the inserted ARP entry.
* @param ethaddr Ethernet address of the inserted ARP entry.
......@@ -680,7 +680,7 @@ etharp_ip_input(struct netif *netif, struct pbuf *p)
#endif /* ETHARP_TRUST_IP_MAC */
/**
* Responds to ARP requests to us. Upon ARP replies to us, add entry to cache
* Responds to ARP requests to us. Upon ARP replies to us, add entry to cache
* send out queued IP packets. Updates cache with snooped address pairs.
*
* Should be called for incoming ARP packets. The pbuf in the argument
......@@ -821,7 +821,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
* don't do flip-flop here... do a copy here.
* otherwise, we need to handle existing pbuf->eb in ieee80211_output.c
*/
q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
if (q != NULL) {
pbuf_copy(q, p);
......@@ -878,13 +878,13 @@ etharp_output_to_arp_index(struct netif *netif, struct pbuf *q, u8_t arp_idx)
/* if arp table entry is about to expire: re-request it,
but only if its state is ETHARP_STATE_STABLE to prevent flooding the
network with ARP requests if this address is used frequently. */
if ((arp_table[arp_idx].state == ETHARP_STATE_STABLE) &&
if ((arp_table[arp_idx].state == ETHARP_STATE_STABLE) &&
(arp_table[arp_idx].ctime >= ARP_AGE_REREQUEST_USED)) {
if (etharp_request(netif, &arp_table[arp_idx].ipaddr) == ERR_OK) {
arp_table[arp_idx].state = ETHARP_STATE_STABLE_REREQUESTING;
}
}
return etharp_send_ip(netif, q, (struct eth_addr*)(netif->hwaddr),
&arp_table[arp_idx].ethaddr);
}
......@@ -1016,11 +1016,11 @@ etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
* is sent for the given address. The packet is queued on this entry.
*
* If the IP address was already stable in the cache, and a packet is
* given, it is directly sent and no ARP request is sent out.
*
* given, it is directly sent and no ARP request is sent out.
*
* If the IP address was already stable in the cache, and no packet is
* given, an ARP request is sent out.
*
*
* @param netif The lwIP network interface on which ipaddr
* must be queried for.
* @param ipaddr The IP address to be resolved.
......@@ -1105,7 +1105,7 @@ etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q)
struct pbuf *p;
int copy_needed = 0;
/* IF q includes a PBUF_REF, PBUF_POOL or PBUF_RAM, we have no choice but
* to copy the whole queue into a new PBUF_RAM (see bug #11400)
* to copy the whole queue into a new PBUF_RAM (see bug #11400)
* PBUF_ROMs can be left as they are, since ROM must not get changed. */
p = q;
while (p) {
......@@ -1258,7 +1258,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
#endif /* LWIP_AUTOIP */
ETHADDR16_COPY(&ethhdr->src, ethsrc_addr);
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
* structure packing. */
* structure packing. */
IPADDR2_COPY(&hdr->sipaddr, ipsrc_addr);
IPADDR2_COPY(&hdr->dipaddr, ipdst_addr);
......@@ -1377,7 +1377,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
ip_input(p, netif);
}
break;
case PP_HTONS(ETHTYPE_ARP):
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
goto free_and_return;
......
......@@ -25,7 +25,7 @@ endif
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
DEFINES +=
DEFINES +=
#CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal
#############################################################
......
......@@ -25,13 +25,13 @@ void *espconn_memcpy(void *dst, const void *src, size_t size, char *file, int li
{
char *psrc = NULL;
char *pdst = NULL;
if(NULL == dst || NULL == src)
{
return NULL;
}
//os_printf("%s %d %p %p %d\n",file, line, dst, src, size);
if((src < dst) && (char *)src + size > (char *)dst)
if((src < dst) && (char *)src + size > (char *)dst)
{
psrc = (char *)src + size - 1;
pdst = (char *)dst + size - 1;
......@@ -49,7 +49,7 @@ void *espconn_memcpy(void *dst, const void *src, size_t size, char *file, int li
*pdst++ = *psrc++;
}
}
return dst;
}
......
......@@ -25,7 +25,7 @@ endif
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
......
......@@ -112,16 +112,16 @@ bool mbedtls_load_default_obj(uint32 flash_sector, int obj_type, const unsigned
}else{
format_type = ESPCONN_FORMAT_DER;
}
if (format_type == ESPCONN_FORMAT_PEM){
length += 1;
}
}
mbedtls_write = mbedtls_parame_new(length);
if (mbedtls_write){
os_memcpy(mbedtls_write->parame_data, load_buf, length);
if (format_type == ESPCONN_FORMAT_PEM)
mbedtls_write->parame_data[length - 1] = '\0';
mbedtls_write->parame_data[length - 1] = '\0';
}
}
......@@ -129,10 +129,10 @@ bool mbedtls_load_default_obj(uint32 flash_sector, int obj_type, const unsigned
mbedtls_load_flag = true;
mbedtls_write->parame_type = obj_type;
mbedtls_write->parame_sec = flash_sector;
if (obj_type == ESPCONN_PK){
def_private_key = mbedtls_write;
if (obj_type == ESPCONN_PK){
def_private_key = mbedtls_write;
} else{
def_certificate = mbedtls_write;
def_certificate = mbedtls_write;
}
}
return mbedtls_load_flag;
......@@ -144,12 +144,12 @@ static unsigned char* mbedtls_get_default_obj(uint32 *sec, uint32 type, uint32 *
unsigned char *parame_data = NULL;
pmbedtls_parame mbedtls_obj = NULL;
if (type == ESPCONN_PK){
mbedtls_obj = def_private_key;
if (type == ESPCONN_PK){
mbedtls_obj = def_private_key;
} else{
mbedtls_obj = def_certificate;
mbedtls_obj = def_certificate;
}
if (mbedtls_obj->parame_sec != 0){
#define DATA_OFFSET 4
uint32 data_len = mbedtls_obj->parame_datalen;
......@@ -163,15 +163,15 @@ static unsigned char* mbedtls_get_default_obj(uint32 *sec, uint32 type, uint32 *
if ((char*)os_strstr(parame_data, begin) != NULL){
data_len ++;
parame_data[data_len - 1] = '\0';
}
}
}
*len = data_len;
} else{
parame_data = mbedtls_obj->parame_data;
*len = mbedtls_obj->parame_datalen;
}
*sec = mbedtls_obj->parame_sec;
*sec = mbedtls_obj->parame_sec;
return parame_data;
}
......@@ -250,10 +250,10 @@ static void mbedtls_espconn_free(pmbedtls_espconn *mbedtlsconn)
{
lwIP_ASSERT(mbedtlsconn);
lwIP_ASSERT(*mbedtlsconn);
os_free((*mbedtlsconn)->proto.tcp);
(*mbedtlsconn)->proto.tcp = NULL;
os_free((*mbedtlsconn));
*mbedtlsconn = NULL;
}
......@@ -293,7 +293,7 @@ static pmbedtls_msg mbedtls_msg_new(void)
mbedtls_net_init(&msg->listen_fd);
mbedtls_net_init(&msg->fd);
mbedtls_ssl_init(&msg->ssl);
mbedtls_ssl_config_init(&msg->conf);
mbedtls_ssl_config_init(&msg->conf);
mbedtls_ctr_drbg_init(&msg->ctr_drbg);
mbedtls_entropy_init(&msg->entropy);
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) && defined(SSL_MAX_FRAGMENT_LENGTH_CODE)
......@@ -337,7 +337,7 @@ static void mbedtls_msg_server_step(pmbedtls_msg msg)
mbedtls_ssl_config_init(&msg->conf);
mbedtls_ctr_drbg_init(&msg->ctr_drbg);
mbedtls_entropy_init(&msg->entropy);
}
}
}
static void mbedtls_msg_free(pmbedtls_msg *msg)
......@@ -464,7 +464,7 @@ static void mbedtls_fail_info(espconn_msg *pinfo, int ret)
pinfo->pespconn->state = ESPCONN_CLOSE;
mbedtls_net_free(&TLSmsg->fd);
exit:
return;
}
......@@ -490,7 +490,7 @@ exit:
static int mbedtls_hanshake_finished(mbedtls_msg *msg)
{
lwIP_ASSERT(msg);
int ret = ERR_OK;
int ret = ERR_OK;
const size_t len = MBEDTLS_SSL_OUTBUFFER_LEN;
mbedtls_ssl_context *ssl = &msg->ssl;
......@@ -501,7 +501,7 @@ static int mbedtls_hanshake_finished(mbedtls_msg *msg)
ssl->out_buf = (unsigned char*)os_zalloc(len);
lwIP_REQUIRE_ACTION(ssl->out_buf, exit, ret = MBEDTLS_ERR_SSL_ALLOC_FAILED);
ssl->out_ctr = ssl->out_buf;
ssl->out_hdr = ssl->out_buf + 8;
ssl->out_len = ssl->out_buf + 11;
......@@ -577,8 +577,8 @@ static void espconn_close_internal(void *arg, netconn_event event_type)
os_free(pssl_recon);
pssl_recon = NULL;
}
espconn_kill_oldest_pcb();
espconn_kill_oldest_pcb();
switch (event_type){
case NETCONN_EVENT_ERROR:
if (hs_status == ESPCONN_OK)
......@@ -714,7 +714,7 @@ again:
ret = mbedtls_ssl_conf_own_cert(&msg->conf, &msg->psession->clicert, &msg->psession->pkey);
break;
}
exit:
exit:
os_free(load_buf);
os_free(pfile_param);
if (ret < 0){
......@@ -752,7 +752,7 @@ static bool mbedtls_msg_config(mbedtls_msg *msg)
lwIP_REQUIRE_NOERROR(ret, exit);
if (auth_type == MBEDTLS_SSL_IS_SERVER){
uint32 flash_sector = 0;
uint32 flash_sector = 0;
/*Load the certificate*/
unsigned int def_certificate_len = 0;unsigned char *def_certificate = NULL;
def_certificate = (unsigned char *)mbedtls_get_default_obj(&flash_sector,ESPCONN_CERT_OWN, &def_certificate_len);
......@@ -811,7 +811,7 @@ static bool mbedtls_msg_config(mbedtls_msg *msg)
}
mbedtls_ssl_conf_rng(&msg->conf, mbedtls_ctr_drbg_random, &msg->ctr_drbg);
mbedtls_ssl_conf_dbg(&msg->conf, mbedtls_dbg, NULL);
ret = mbedtls_ssl_setup(&msg->ssl, &msg->conf);
lwIP_REQUIRE_NOERROR(ret, exit);
......@@ -857,7 +857,7 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
} else{
break;
}
}
}
} while(1);
os_free(TheadBuff);
TheadBuff = NULL;
......@@ -883,11 +883,11 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
getpeername(TLSmsg->fd.fd, (struct sockaddr*)&name, &name_len);
Threadmsg->pcommon.remote_port = htons(name.sin_port);
os_memcpy(Threadmsg->pcommon.remote_ip, &name.sin_addr.s_addr, 4);
espconn->proto.tcp->remote_port = htons(name.sin_port);
os_memcpy(espconn->proto.tcp->remote_ip, &name.sin_addr.s_addr, 4);
espconn_copy_partial(accept_conn, espconn);
espconn_copy_partial(accept_conn, espconn);
/*insert the node to the active connection list*/
espconn_list_creat(&plink_active, Threadmsg);
......@@ -904,7 +904,7 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
lwIP_REQUIRE_NOERROR(ret, exit);
}
}
system_soft_wdt_stop();
uint8 cpu_freq;
cpu_freq = system_get_cpu_freq();
......@@ -936,7 +936,7 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
mbedtls_hanshake_finished(TLSmsg);
#endif
system_restoreclock();
TLSmsg->SentFnFlag = true;
ESPCONN_EVENT_CONNECTED(Threadmsg->pespconn);
} else{
......@@ -955,7 +955,7 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
exit:
if (ret != ESPCONN_OK){
mbedtls_fail_info(Threadmsg, ret);
mbedtls_fail_info(Threadmsg, ret);
if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY){
Threadmsg->hs_status = ESPCONN_OK;
}
......@@ -977,7 +977,7 @@ int __attribute__((weak)) mbedtls_parse_thread(int socket, int event, int error)
int out_msglen = TLSmsg->ssl.out_msglen + 5;
if (Threadmsg->pcommon.write_flag)
TLSmsg->record.record_len += error;
if (TLSmsg->record.record_len == out_msglen){
TLSmsg->record.record_len = 0;
Threadmsg->pcommon.write_flag = false;
......@@ -1023,13 +1023,13 @@ mbedtls_thread(os_event_t *events)
break;
}
}
if (active_flag){
/*remove the node from the active connection list*/
espconn_list_delete(&plink_active, Threadmsg);
if (TLSmsg->listen_fd.fd != -1){
mbedtls_msg_server_step(TLSmsg);
espconn_copy_partial(Threadmsg->preverse, Threadmsg->pespconn);
espconn_copy_partial(Threadmsg->preverse, Threadmsg->pespconn);
mbedtls_espconn_free(&Threadmsg->pespconn);
} else{
mbedtls_msg_free(&TLSmsg);
......@@ -1077,7 +1077,7 @@ sint8 espconn_ssl_client(struct espconn *espconn)
espconn->proto.tcp->remote_ip[2],espconn->proto.tcp->remote_ip[3]);
server_name = ipaddr_ntoa(&ipaddr);
server_port = (const char *)sys_itoa(espconn->proto.tcp->remote_port);
/*start the connection*/
ret = mbedtls_net_connect(&mbedTLSMsg->fd, server_name, server_port, MBEDTLS_NET_PROTO_TCP);
lwIP_REQUIRE_NOERROR_ACTION(ret, exit, ret = ESPCONN_MEM);
......@@ -1116,7 +1116,7 @@ sint8 espconn_ssl_server(struct espconn *espconn)
if (plink_server != NULL)
return ESPCONN_INPROGRESS;
lwIP_REQUIRE_ACTION(espconn, exit, ret = ESPCONN_ARG);
/*Creates a new server control message*/
pserver = (espconn_msg *) os_zalloc( sizeof(espconn_msg));
......@@ -1124,7 +1124,7 @@ sint8 espconn_ssl_server(struct espconn *espconn)
mbedTLSMsg = mbedtls_msg_new();
lwIP_REQUIRE_ACTION(mbedTLSMsg, exit, ret = ESPCONN_MEM);
server_port = (const char *)sys_itoa(espconn->proto.tcp->local_port);
server_port = (const char *)sys_itoa(espconn->proto.tcp->local_port);
/*start the connection*/
ret = mbedtls_net_bind(&mbedTLSMsg->listen_fd, NULL, server_port, MBEDTLS_NET_PROTO_TCP);
lwIP_REQUIRE_NOERROR_ACTION(ret, exit, ret = ESPCONN_MEM);
......@@ -1176,7 +1176,7 @@ sint8 espconn_ssl_delete(struct espconn *pdeletecon)
os_free(pdelete_msg);
pdelete_msg = NULL;
plink_server = pdelete_msg;
mbedtls_parame_free(&def_private_key);
mbedtls_parame_free(&def_private_key);
mbedtls_parame_free(&def_certificate);
return ESPCONN_OK;
} else {
......@@ -1196,7 +1196,7 @@ sint8 espconn_ssl_delete(struct espconn *pdeletecon)
void espconn_ssl_sent(void *arg, uint8 *psent, uint16 length)
{
espconn_msg *Threadmsg = arg;
uint16 out_msglen = length;
uint16 out_msglen = length;
int ret = ESPCONN_OK;
lwIP_ASSERT(Threadmsg);
lwIP_ASSERT(psent);
......@@ -1215,13 +1215,13 @@ void espconn_ssl_sent(void *arg, uint8 *psent, uint16 length)
Threadmsg->pcommon.cntr = length - ret;
} else{
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE || ret == 0) {
} else{
mbedtls_fail_info(Threadmsg, ret);
mbedtls_fail_info(Threadmsg, ret);
ets_post(lwIPThreadPrio, NETCONN_EVENT_CLOSE,(uint32)Threadmsg);
}
}
}
/******************************************************************************
......
......@@ -54,14 +54,14 @@ unsigned int max_content_len = ESPCONN_SECURE_DEFAULT_SIZE;
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR
espconn_secure_connect(struct espconn *espconn)
{
{
struct ip_addr ipaddr;
struct ip_info ipinfo;
uint8 connect_status = 0;
uint16 current_size = 0;
if (espconn == NULL || espconn ->type != ESPCONN_TCP)
return ESPCONN_ARG;
if (wifi_get_opmode() == ESPCONN_STA){
wifi_get_ip_info(STA_NETIF, &ipinfo);
if (ipinfo.ip.addr == 0) {
......@@ -122,7 +122,7 @@ espconn_secure_disconnect(struct espconn *espconn)
if (value){
if (pnode->pespconn->state == ESPCONN_CLOSE)
return ESPCONN_INPROGRESS;
espconn_ssl_disconnect(pnode);
return ESPCONN_OK;
}
......@@ -193,7 +193,7 @@ espconn_secure_accept(struct espconn *espconn)
bool ICACHE_FLASH_ATTR espconn_secure_set_size(uint8 level, uint16 size)
{
size = (size < 4096) ? 4096 : size;
if (level >= ESPCONN_MAX || level <= ESPCONN_IDLE)
return false;
......@@ -379,7 +379,7 @@ sint8 ICACHE_FLASH_ATTR espconn_secure_delete(struct espconn *espconn)
{
sint8 error = ESPCONN_OK;
error = espconn_ssl_delete(espconn);
return error;
}
......@@ -390,8 +390,8 @@ bool espconn_secure_obj_load(int obj_type, uint32 flash_sector, uint16 length)
if (obj_type != ESPCONN_PK && obj_type != ESPCONN_CERT_OWN)
return false;
return mbedtls_load_default_obj(flash_sector, obj_type, NULL, length);
return mbedtls_load_default_obj(flash_sector, obj_type, NULL, length);
}
#endif
......@@ -124,7 +124,7 @@ static void free_netconn(lwIP_netconn *netconn)
{
ringbuf_free(&netconn->readbuf);
}
os_free(netconn);
netconn = NULL;
}
......@@ -184,11 +184,11 @@ static err_t recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
lwIP_netconn *newconn = arg;
err = ESP_OK;
lwIP_REQUIRE_ACTION(newconn, exit, err = ESP_ARG);
if (p!= NULL)
{
struct pbuf *pthis = NULL;
if (newconn->readbuf != NULL)
{
for (pthis = p; pthis != NULL; pthis = pthis->next)
......@@ -197,16 +197,16 @@ static err_t recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
ringbuf_memcpy_into(newconn->readbuf, pthis->payload, pthis->len);
tcp_recved(newconn->tcp, pthis->len);
newconn->state = NETCONN_STATE_ESTABLISHED;
lwIP_EVENT_PARSE(find_socket(newconn), ERR_OK);
lwIP_EVENT_PARSE(find_socket(newconn), ERR_OK);
}
pbuf_free(p);
}
else
{
{
tcp_recved(newconn->tcp, p->tot_len);
pbuf_free(p);
err = ERR_MEM;
}
}
}
else
{
......@@ -228,14 +228,14 @@ static err_t sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
{
lwIP_netconn *conn = arg;
lwIP_ASSERT(conn);
conn->state = NETCONN_STATE_ESTABLISHED;
lwIP_EVENT_THREAD(find_socket(conn), NETCONN_EVENT_SEND, len);
conn->state = NETCONN_STATE_ESTABLISHED;
lwIP_EVENT_THREAD(find_socket(conn), NETCONN_EVENT_SEND, len);
return ERR_OK;
}
static void err_tcp(void *arg, err_t err)
{
lwIP_netconn *conn = arg;
lwIP_netconn *conn = arg;
lwIP_ASSERT(conn);
conn->state = NETCONN_STATE_ERROR;
ESP_LOG("%s %d %p\n",__FILE__, __LINE__, conn->tcp);
......@@ -256,7 +256,7 @@ static void err_tcp(void *arg, err_t err)
default:
break;
}
lwIP_EVENT_PARSE(find_socket(conn), err);
return;
}
......@@ -710,7 +710,7 @@ int lwip_send(int s, const void *data, size_t size, int flags)
{
return -1;
}
if (tcp_sndbuf(sock->conn->tcp) < size)
{
bytes_used = tcp_sndbuf(sock->conn->tcp);
......@@ -735,9 +735,9 @@ int lwip_send(int s, const void *data, size_t size, int flags)
{
Err = tcp_output(sock->conn->tcp);
} else{
size = Err;
size = Err;
}
return size;
}
......@@ -794,7 +794,7 @@ int lwip_write(int s, const void *data, size_t size)
{
switch (sock->conn->state)
{
case NETCONN_STATE_ESTABLISHED:
case NETCONN_STATE_ESTABLISHED:
return lwip_send(s, data, size, 0);
default:
return -1;
......
......@@ -25,7 +25,7 @@ endif
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
......
......@@ -25,7 +25,7 @@ endif
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
......
......@@ -24,7 +24,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
......
......@@ -14,7 +14,7 @@ static int adc_sample( lua_State* L )
MOD_CHECK_ID( adc, id );
unsigned val = 0xFFFF & system_adc_read();
lua_pushinteger( L, val );
return 1;
return 1;
}
// Lua: readvdd33()
......
......@@ -60,7 +60,7 @@ static int adxl345_read(lua_State* L) {
for (i=0; i<5; i++) {
data[i] = platform_i2c_recv_byte(adxl345_i2c_id, 1);
}
data[5] = platform_i2c_recv_byte(adxl345_i2c_id, 0);
platform_i2c_send_stop(adxl345_i2c_id);
......
......@@ -115,7 +115,7 @@ static int am2320_read(lua_State* L)
uint16_t rh;
uint16_t temp;
} nfo;
ret = _read(am2320_i2c_id, &nfo, sizeof(nfo)-2, 0x00);
if(ret)
return luaL_error(L, "transmission error");
......
......@@ -29,7 +29,7 @@ typedef size_t lua_UInteger;
ARITHMETIC_SHIFT does not truncate its left-hand operand, so that
the sign bits are not removed and right shift work properly.
*/
#define MONADIC(name, op) \
static int bit_ ## name(lua_State *L) { \
lua_pushinteger(L, op TOBIT(L, 1)); \
......@@ -80,7 +80,7 @@ static int bit_isset( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned pos = ( unsigned )luaL_checkinteger( L, 2 );
lua_pushboolean( L, val & ( 1 << pos ) ? 1 : 0 );
return 1;
}
......@@ -90,17 +90,17 @@ static int bit_isclear( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned pos = ( unsigned )luaL_checkinteger( L, 2 );
lua_pushboolean( L, val & ( 1 << pos ) ? 0 : 1 );
return 1;
}
// Lua: res = set( value, pos1, pos2, ... )
static int bit_set( lua_State* L )
{
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned total = lua_gettop( L ), i;
for( i = 2; i <= total; i ++ )
val |= 1 << ( unsigned )luaL_checkinteger( L, i );
lua_pushinteger( L, ( lua_Integer )val );
......@@ -112,11 +112,11 @@ static int bit_clear( lua_State* L )
{
lua_UInteger val = ( lua_UInteger )luaL_checkinteger( L, 1 );
unsigned total = lua_gettop( L ), i;
for( i = 2; i <= total; i ++ )
val &= ~( 1 << ( unsigned )luaL_checkinteger( L, i ) );
lua_pushinteger( L, ( lua_Integer )val );
return 1;
return 1;
}
static const LUA_REG_TYPE bit_map[] = {
......
......@@ -185,7 +185,7 @@ static const LUA_REG_TYPE bloom_map[] = {
};
LUALIB_API int bloom_open(lua_State *L) {
luaL_rometatable(L, "bloom.filter", (void *)bloom_filter_map);
luaL_rometatable(L, "bloom.filter", (void *)bloom_filter_map);
return 1;
}
......
// ***************************************************************************
// BMP280 module for ESP8266 with nodeMCU
//
//
// Written by Lukas Voborsky, @voborsky
//
//
// MIT license, http://opensource.org/licenses/MIT
// ***************************************************************************
......@@ -154,56 +154,56 @@ static uint8_t r8u(uint8_t reg) {
return ret[0];
}
// Returns temperature in DegC, resolution is 0.01 DegC. Output value of “5123” equals 51.23 DegC.
// t_fine carries fine temperature as global value
// Returns temperature in DegC, resolution is 0.01 DegC. Output value of “5123” equals 51.23 DegC.
// t_fine carries fine temperature as global value
static BME280_S32_t bme280_compensate_T(BME280_S32_t adc_T) {
BME280_S32_t var1, var2, T;
var1 = ((((adc_T>>3) - ((BME280_S32_t)bme280_data.dig_T1<<1))) * ((BME280_S32_t)bme280_data.dig_T2)) >> 11;
var2 = (((((adc_T>>4) - ((BME280_S32_t)bme280_data.dig_T1)) * ((adc_T>>4) - ((BME280_S32_t)bme280_data.dig_T1))) >> 12) *
((BME280_S32_t)bme280_data.dig_T3)) >> 14;
bme280_t_fine = var1 + var2;
T = (bme280_t_fine * 5 + 128) >> 8;
return T;
BME280_S32_t var1, var2, T;
var1 = ((((adc_T>>3) - ((BME280_S32_t)bme280_data.dig_T1<<1))) * ((BME280_S32_t)bme280_data.dig_T2)) >> 11;
var2 = (((((adc_T>>4) - ((BME280_S32_t)bme280_data.dig_T1)) * ((adc_T>>4) - ((BME280_S32_t)bme280_data.dig_T1))) >> 12) *
((BME280_S32_t)bme280_data.dig_T3)) >> 14;
bme280_t_fine = var1 + var2;
T = (bme280_t_fine * 5 + 128) >> 8;
return T;
}
// Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits).
// Output value of “24674867” represents 24674867/256 = 96386.2 Pa = 963.862 hPa
// Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits).
// Output value of “24674867” represents 24674867/256 = 96386.2 Pa = 963.862 hPa
static BME280_U32_t bme280_compensate_P(BME280_S32_t adc_P) {
BME280_S64_t var1, var2, p;
var1 = ((BME280_S64_t)bme280_t_fine) - 128000;
var2 = var1 * var1 * (BME280_S64_t)bme280_data.dig_P6;
var2 = var2 + ((var1*(BME280_S64_t)bme280_data.dig_P5)<<17);
var2 = var2 + (((BME280_S64_t)bme280_data.dig_P4)<<35);
var1 = ((var1 * var1 * (BME280_S64_t)bme280_data.dig_P3)>>8) + ((var1 * (BME280_S64_t)bme280_data.dig_P2)<<12);
var1 = (((((BME280_S64_t)1)<<47)+var1))*((BME280_S64_t)bme280_data.dig_P1)>>33;
if (var1 == 0) {
return 0; // avoid exception caused by division by zero
}
p = 1048576-adc_P;
p = (((p<<31)-var2)*3125)/var1;
var1 = (((BME280_S64_t)bme280_data.dig_P9) * (p>>13) * (p>>13)) >> 25;
var2 = (((BME280_S64_t)bme280_data.dig_P8) * p) >> 19;
p = ((p + var1 + var2) >> 8) + (((BME280_S64_t)bme280_data.dig_P7)<<4);
BME280_S64_t var1, var2, p;
var1 = ((BME280_S64_t)bme280_t_fine) - 128000;
var2 = var1 * var1 * (BME280_S64_t)bme280_data.dig_P6;
var2 = var2 + ((var1*(BME280_S64_t)bme280_data.dig_P5)<<17);
var2 = var2 + (((BME280_S64_t)bme280_data.dig_P4)<<35);
var1 = ((var1 * var1 * (BME280_S64_t)bme280_data.dig_P3)>>8) + ((var1 * (BME280_S64_t)bme280_data.dig_P2)<<12);
var1 = (((((BME280_S64_t)1)<<47)+var1))*((BME280_S64_t)bme280_data.dig_P1)>>33;
if (var1 == 0) {
return 0; // avoid exception caused by division by zero
}
p = 1048576-adc_P;
p = (((p<<31)-var2)*3125)/var1;
var1 = (((BME280_S64_t)bme280_data.dig_P9) * (p>>13) * (p>>13)) >> 25;
var2 = (((BME280_S64_t)bme280_data.dig_P8) * p) >> 19;
p = ((p + var1 + var2) >> 8) + (((BME280_S64_t)bme280_data.dig_P7)<<4);
p = (p * 10) >> 8;
return (BME280_U32_t)p;
}
// Returns humidity in %RH as unsigned 32 bit integer in Q22.10 format (22 integer and 10 fractional bits).
// Output value of “47445” represents 47445/1024 = 46.333 %RH
return (BME280_U32_t)p;
}
// Returns humidity in %RH as unsigned 32 bit integer in Q22.10 format (22 integer and 10 fractional bits).
// Output value of “47445” represents 47445/1024 = 46.333 %RH
static BME280_U32_t bme280_compensate_H(BME280_S32_t adc_H) {
BME280_S32_t v_x1_u32r;
v_x1_u32r = (bme280_t_fine - ((BME280_S32_t)76800));
v_x1_u32r = (((((adc_H << 14) - (((BME280_S32_t)bme280_data.dig_H4) << 20) - (((BME280_S32_t)bme280_data.dig_H5) * v_x1_u32r)) +
((BME280_S32_t)16384)) >> 15) * (((((((v_x1_u32r * ((BME280_S32_t)bme280_data.dig_H6)) >> 10) * (((v_x1_u32r *
((BME280_S32_t)bme280_data.dig_H3)) >> 11) + ((BME280_S32_t)32768))) >> 10) + ((BME280_S32_t)2097152)) *
((BME280_S32_t)bme280_data.dig_H2) + 8192) >> 14));
v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) * ((BME280_S32_t)bme280_data.dig_H1)) >> 4));
v_x1_u32r = (v_x1_u32r < 0 ? 0 : v_x1_u32r);
v_x1_u32r = (v_x1_u32r > 419430400 ? 419430400 : v_x1_u32r);
BME280_S32_t v_x1_u32r;
v_x1_u32r = (bme280_t_fine - ((BME280_S32_t)76800));
v_x1_u32r = (((((adc_H << 14) - (((BME280_S32_t)bme280_data.dig_H4) << 20) - (((BME280_S32_t)bme280_data.dig_H5) * v_x1_u32r)) +
((BME280_S32_t)16384)) >> 15) * (((((((v_x1_u32r * ((BME280_S32_t)bme280_data.dig_H6)) >> 10) * (((v_x1_u32r *
((BME280_S32_t)bme280_data.dig_H3)) >> 11) + ((BME280_S32_t)32768))) >> 10) + ((BME280_S32_t)2097152)) *
((BME280_S32_t)bme280_data.dig_H2) + 8192) >> 14));
v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) * ((BME280_S32_t)bme280_data.dig_H1)) >> 4));
v_x1_u32r = (v_x1_u32r < 0 ? 0 : v_x1_u32r);
v_x1_u32r = (v_x1_u32r > 419430400 ? 419430400 : v_x1_u32r);
v_x1_u32r = v_x1_u32r>>12;
return (BME280_U32_t)((v_x1_u32r * 1000)>>10);
}
return (BME280_U32_t)((v_x1_u32r * 1000)>>10);
}
static double ln(double x) {
double y = (x-1)/(x+1);
......@@ -238,14 +238,14 @@ static int bme280_lua_setup(lua_State* L) {
bme280_mode = (!lua_isnumber(L, 4)?BME280_NORMAL_MODE:(luaL_checkinteger(L, 4)&bit2)) // 4-th parameter: power mode
| ((!lua_isnumber(L, 2)?BME280_OVERSAMP_16X:(luaL_checkinteger(L, 2)&bit3)) << 2) // 2-nd parameter: pressure oversampling
| ((!lua_isnumber(L, 1)?BME280_OVERSAMP_16X:(luaL_checkinteger(L, 1)&bit3)) << 5); // 1-st parameter: temperature oversampling
bme280_ossh = (!lua_isnumber(L, 3))?BME280_OVERSAMP_16X:(luaL_checkinteger(L, 3)&bit3); // 3-rd parameter: humidity oversampling
config = ((!lua_isnumber(L, 5)?BME280_STANDBY_TIME_20_MS:(luaL_checkinteger(L, 5)&bit3))<< 5) // 5-th parameter: inactive duration in normal mode
| ((!lua_isnumber(L, 6)?BME280_FILTER_COEFF_16:(luaL_checkinteger(L, 6)&bit3)) << 2); // 6-th parameter: IIR filter
full_init = !lua_isnumber(L, 7)?1:lua_tointeger(L, 7); // 7-th parameter: init the chip too
NODE_DBG("mode: %x\nhumidity oss: %x\nconfig: %x\n", bme280_mode, bme280_ossh, config);
bme280_i2c_addr = BME280_I2C_ADDRESS1;
platform_i2c_send_start(bme280_i2c_id);
ack = platform_i2c_send_address(bme280_i2c_id, bme280_i2c_addr, PLATFORM_I2C_DIRECTION_TRANSMITTER);
......@@ -265,7 +265,7 @@ static int bme280_lua_setup(lua_State* L) {
uint8_t chipid = r8u(BME280_REGISTER_CHIPID);
NODE_DBG("chip_id: %x\n", chipid);
bme280_isbme = (chipid == 0x60);
#define r16uLE_buf(reg) (uint16_t)((reg[1] << 8) | reg[0])
#define r16sLE_buf(reg) (int16_t)(r16uLE_buf(reg))
uint8_t buf[18], *reg;
......@@ -289,7 +289,7 @@ static int bme280_lua_setup(lua_State* L) {
bme280_data.dig_P8 = r16sLE_buf(reg); reg+=2;
bme280_data.dig_P9 = r16sLE_buf(reg);
// NODE_DBG("dig_P: %d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", bme280_data.dig_P1, bme280_data.dig_P2, bme280_data.dig_P3, bme280_data.dig_P4, bme280_data.dig_P5, bme280_data.dig_P6, bme280_data.dig_P7, bme280_data.dig_P8, bme280_data.dig_P9);
if (full_init) w8u(BME280_REGISTER_CONFIG, config);
if (bme280_isbme) {
bme280_data.dig_H1 = r8u(BME280_REGISTER_DIG_H1);
......@@ -310,7 +310,7 @@ static int bme280_lua_setup(lua_State* L) {
#undef r16uLE_buf
#undef r16sLE_buf
if (full_init) w8u(BME280_REGISTER_CONTROL, bme280_mode);
return 1;
}
......@@ -326,12 +326,12 @@ static void bme280_readoutdone (void *arg)
static int bme280_lua_startreadout(lua_State* L) {
uint32_t delay;
if (lua_isnumber(L, 1)) {
delay = luaL_checkinteger(L, 1);
if (!delay) {delay = BME280_SAMPLING_DELAY;} // if delay is 0 then set the default delay
}
if (!lua_isnoneornil(L, 2)) {
lua_pushvalue(L, 2);
lua_connected_readout_ref = luaL_ref(L, LUA_REGISTRYINDEX);
......
// ***************************************************************************
// Port of BMP680 module for ESP8266 with nodeMCU
//
//
// Written by Lukas Voborsky, @voborsky
// ***************************************************************************
......@@ -31,7 +31,7 @@ static uint8 os_hum = 0; // stores humidity oversampling settings
static uint16_t heatr_dur;
static int8_t amb_temp = 23; //DEFAULT_AMBIENT_TEMP;
static uint32_t bme680_h = 0;
static uint32_t bme680_h = 0;
static double bme680_hc = 1.0;
// return 0 if good
......@@ -263,7 +263,7 @@ uint16_t calc_dur()
uint32_t tph_dur; /* Calculate in us */
/* TPH measurement duration */
tph_dur = ((uint32_t) (os_temp + os_pres + os_hum) * UINT32_C(1963));
tph_dur += UINT32_C(477 * 4); /* TPH switching duration */
tph_dur += UINT32_C(477 * 5); /* Gas measurement duration */
......@@ -329,7 +329,7 @@ static int bme680_lua_setup(lua_State* L) {
r8u_n(BME680_COEFF_ADDR1, BME680_COEFF_ADDR1_LEN, buff);
r8u_n(BME680_COEFF_ADDR2, BME680_COEFF_ADDR2_LEN, &buff[BME680_COEFF_ADDR1_LEN]);
reg = buff + 1;
reg = buff + 1;
bme680_data.par_t2 = r16sLE_buf(reg); reg+=2; // #define BME680_T3_REG (3)
bme680_data.par_t3 = (int8_t) reg[0]; reg+=2; // #define BME680_P1_LSB_REG (5)
bme680_data.par_p1 = r16uLE_buf(reg); reg+=2; // #define BME680_P2_LSB_REG (7)
......@@ -354,21 +354,21 @@ static int bme680_lua_setup(lua_State* L) {
bme680_data.par_t1 = r16uLE_buf(reg); reg+=2; // #define BME680_GH2_LSB_REG (35)
bme680_data.par_gh2 = r16sLE_buf(reg); reg+=2; // #define BME680_GH1_REG (37)
bme680_data.par_gh1 = reg[0]; reg++; // #define BME680_GH3_REG (38)
bme680_data.par_gh3 = reg[0];
bme680_data.par_gh3 = reg[0];
#undef r16uLE_buf
#undef r16sLE_buf
/* Other coefficients */
bme680_data.res_heat_range = ((r8u(BME680_ADDR_RES_HEAT_RANGE_ADDR) & BME680_RHRANGE_MSK) / 16);
bme680_data.res_heat_val = (int8_t) r8u(BME680_ADDR_RES_HEAT_VAL_ADDR);
bme680_data.range_sw_err = ((int8_t) r8u(BME680_ADDR_RANGE_SW_ERR_ADDR) & (int8_t) BME680_RSERROR_MSK) / 16;
NODE_DBG("par_T: %d\t%d\t%d\n", bme680_data.par_t1, bme680_data.par_t2, bme680_data.par_t3);
NODE_DBG("par_P: %d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", bme680_data.par_p1, bme680_data.par_p2, bme680_data.par_p3, bme680_data.par_p4, bme680_data.par_p5, bme680_data.par_p6, bme680_data.par_p7, bme680_data.par_p8, bme680_data.par_p9, bme680_data.par_p10);
NODE_DBG("par_H: %d\t%d\t%d\t%d\t%d\t%d\t%d\n", bme680_data.par_h1, bme680_data.par_h2, bme680_data.par_h3, bme680_data.par_h4, bme680_data.par_h5, bme680_data.par_h6, bme680_data.par_h7);
NODE_DBG("par_GH: %d\t%d\t%d\n", bme680_data.par_gh1, bme680_data.par_gh2, bme680_data.par_gh3);
NODE_DBG("res_heat_range, res_heat_val, range_sw_err: %d\t%d\t%d\n", bme680_data.res_heat_range, bme680_data.res_heat_val, bme680_data.range_sw_err);
uint8_t full_init = !lua_isnumber(L, 7)?1:lua_tointeger(L, 7); // 7-th parameter: init the chip too
if (full_init) {
uint8_t filter;
......@@ -380,22 +380,22 @@ static int bme680_lua_setup(lua_State* L) {
os_temp = (!lua_isnumber(L, 1)?BME680_OS_2X:(luaL_checkinteger(L, 1)&bit3)); // 1-st parameter: temperature oversampling
os_pres = (!lua_isnumber(L, 2)?BME680_OS_16X:(luaL_checkinteger(L, 2)&bit3)); // 2-nd parameter: pressure oversampling
os_hum = (!lua_isnumber(L, 3))?BME680_OS_1X:(luaL_checkinteger(L, 3)&bit3);
bme680_mode = BME680_SLEEP_MODE | (os_pres << 2) | (os_temp << 5);
bme680_mode = BME680_SLEEP_MODE | (os_pres << 2) | (os_temp << 5);
os_hum = os_hum; // 3-rd parameter: humidity oversampling
filter = ((!lua_isnumber(L, 6)?BME680_FILTER_SIZE_31:(luaL_checkinteger(L, 6)&bit3)) << 2); // 6-th parameter: IIR filter
NODE_DBG("mode: %x\nhumidity oss: %x\nconfig: %x\n", bme680_mode, os_hum, filter);
heatr_dur = (!lua_isnumber(L, 5)?DEFAULT_HEATER_DUR:(luaL_checkinteger(L, 5))); // 5-th parameter: heater duration
w8u(BME680_GAS_WAIT0_ADDR, calc_heater_dur(heatr_dur));
w8u(BME680_RES_HEAT0_ADDR, calc_heater_res((!lua_isnumber(L, 4)?DEFAULT_HEATER_TEMP:(luaL_checkinteger(L, 4))))); // 4-th parameter: heater temperature
w8u(BME680_CONF_ODR_FILT_ADDR, BME680_SET_BITS_POS_0(r8u(BME680_CONF_ODR_FILT_ADDR), BME680_FILTER, filter)); // #define BME680_CONF_ODR_FILT_ADDR UINT8_C(0x75)
// set heater on
// set heater on
w8u(BME680_CONF_HEAT_CTRL_ADDR, BME680_SET_BITS_POS_0(r8u(BME680_CONF_HEAT_CTRL_ADDR), BME680_HCTRL, 1));
w8u(BME680_CONF_T_P_MODE_ADDR, bme680_mode);
w8u(BME680_CONF_OS_H_ADDR, BME680_SET_BITS_POS_0(r8u(BME680_CONF_OS_H_ADDR), BME680_OSH, os_hum));
w8u(BME680_CONF_ODR_RUN_GAS_NBC_ADDR, 1 << 4 | 0 & bit3);
......@@ -417,12 +417,12 @@ static void bme280_readoutdone (void *arg)
static int bme680_lua_startreadout(lua_State* L) {
uint32_t delay;
if (lua_isnumber(L, 1)) {
delay = luaL_checkinteger(L, 1);
if (!delay) {delay = calc_dur();} // if delay is 0 then set the default delay
}
if (!lua_isnoneornil(L, 2)) {
lua_pushvalue(L, 2);
lua_connected_readout_ref = luaL_ref(L, LUA_REGISTRYINDEX);
......@@ -432,7 +432,7 @@ static int bme680_lua_startreadout(lua_State* L) {
w8u(BME680_CONF_OS_H_ADDR, os_hum);
w8u(BME680_CONF_T_P_MODE_ADDR, (bme680_mode & 0xFC) | BME680_FORCED_MODE);
NODE_DBG("control old: %x, control: %x, delay: %d\n", bme680_mode, (bme680_mode & 0xFC) | BME680_FORCED_MODE, delay);
if (lua_connected_readout_ref != LUA_NOREF) {
......@@ -455,7 +455,7 @@ static int bme680_lua_read(lua_State* L) {
uint16_t adc_hum;
uint16_t adc_gas_res;
uint8_t status;
uint32_t qfe;
uint8_t calc_qnh = lua_isnumber(L, 1);
......@@ -468,9 +468,9 @@ static int bme680_lua_read(lua_State* L) {
adc_temp = (uint32_t) (((uint32_t) buff[5] * 4096) | ((uint32_t) buff[6] * 16) | ((uint32_t) buff[7] / 16));
adc_hum = (uint16_t) (((uint32_t) buff[8] * 256) | (uint32_t) buff[9]);
adc_gas_res = (uint16_t) ((uint32_t) buff[13] * 4 | (((uint32_t) buff[14]) / 64));
gas_range = buff[14] & BME680_GAS_RANGE_MSK;
status |= buff[14] & BME680_GASM_VALID_MSK;
status |= buff[14] & BME680_HEAT_STAB_MSK;
NODE_DBG("status, new_data, gas_range, gasm_valid: 0x%x, 0x%x, 0x%x, 0x%x\n", status, status & BME680_NEW_DATA_MSK, buff[14] & BME680_GAS_RANGE_MSK, buff[14] & BME680_GASM_VALID_MSK);
......
......@@ -105,7 +105,7 @@ static int coap_create( lua_State* L, const char* mt )
pesp_conn->reverse = cud;
NODE_DBG("coap_create is called.\n");
return 1;
return 1;
}
// Lua: server:delete()
......@@ -138,7 +138,7 @@ static int coap_delete( lua_State* L, const char* mt )
}
NODE_DBG("coap_delete is called.\n");
return 0;
return 0;
}
// Lua: server:listen( port, ip )
......@@ -187,7 +187,7 @@ static int coap_start( lua_State* L, const char* mt )
NODE_DBG("Coap Server started on port: %d\n", port);
NODE_DBG("coap_start is called.\n");
return 0;
return 0;
}
// Lua: server:close()
......@@ -215,14 +215,14 @@ static int coap_close( lua_State* L, const char* mt )
}
NODE_DBG("coap_close is called.\n");
return 0;
return 0;
}
// Lua: server/client:on( "method", function(s) )
static int coap_on( lua_State* L, const char* mt )
{
NODE_DBG("coap_on is called.\n");
return 0;
return 0;
}
static void coap_response_handler(void *arg, char *pdata, unsigned short len)
......@@ -405,8 +405,8 @@ static int coap_request( lua_State* L, coap_method_t m )
if( ESPCONN_OK != con){
NODE_DBG("Connect to host. code:%d\n", con);
// coap_delete_pdu(pdu);
}
// else
}
// else
{
coap_tid_t tid = COAP_INVALID_TID;
if (pdu->pkt->hdr.t == COAP_TYPE_CON){
......@@ -425,7 +425,7 @@ static int coap_request( lua_State* L, coap_method_t m )
c_free((void *)uri);
NODE_DBG("coap_request is called.\n");
return 0;
return 0;
}
extern coap_luser_entry *variable_entry;
......@@ -459,13 +459,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar )
return luaL_error(L, "not enough memory");
h->next = NULL;
h->name = NULL;
}
}
h->name = name;
h->content_type = content_type;
NODE_DBG("coap_regist is called.\n");
return 0;
return 0;
}
// Lua: s = coap.createServer(function(conn))
......@@ -576,7 +576,7 @@ static const LUA_REG_TYPE coap_client_map[] = {
{ LNILKEY, LNILVAL }
};
static const LUA_REG_TYPE coap_map[] =
static const LUA_REG_TYPE coap_map[] =
{
{ LSTRKEY( "Server" ), LFUNCVAL( coap_createServer ) },
{ LSTRKEY( "Client" ), LFUNCVAL( coap_createClient ) },
......@@ -595,8 +595,8 @@ static const LUA_REG_TYPE coap_map[] =
int luaopen_coap( lua_State *L )
{
endpoint_setup();
luaL_rometatable(L, "coap_server", (void *)coap_server_map); // create metatable for coap_server
luaL_rometatable(L, "coap_client", (void *)coap_client_map); // create metatable for coap_client
luaL_rometatable(L, "coap_server", (void *)coap_server_map); // create metatable for coap_server
luaL_rometatable(L, "coap_client", (void *)coap_client_map); // create metatable for coap_client
return 0;
}
......
......@@ -46,12 +46,12 @@ static int crypto_sha1( lua_State* L )
#ifdef LUA_USE_MODULES_ENCODER
static int call_encoder( lua_State* L, const char *function ) {
if (lua_gettop(L) != 1) {
if (lua_gettop(L) != 1) {
luaL_error(L, "%s must have one argument", function);
}
lua_getfield(L, LUA_GLOBALSINDEX, "encoder");
if (!lua_istable(L, -1) && !lua_isrotable(L, -1)) { // also need table just in case encoder has been overloaded
luaL_error(L, "Cannot find encoder.%s", function);
luaL_error(L, "Cannot find encoder.%s", function);
}
lua_getfield(L, -1, function);
lua_insert(L, 1); //move function below the argument
......@@ -60,11 +60,11 @@ static int call_encoder( lua_State* L, const char *function ) {
return 1;
}
static int crypto_base64_encode (lua_State* L) {
return call_encoder(L, "toBase64");
static int crypto_base64_encode (lua_State* L) {
return call_encoder(L, "toBase64");
}
static int crypto_hex_encode (lua_State* L) {
return call_encoder(L, "toHex");
static int crypto_hex_encode (lua_State* L) {
return call_encoder(L, "toHex");
}
#else
static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
......
......@@ -74,7 +74,7 @@ static int ds18b20_lua_setup(lua_State *L) {
if (!lua_isnumber(L, 1) || lua_isnumber(L, 1) == 0) {
return luaL_error(L, "wrong 1-wire pin");
}
ds18b20_bus_pin = luaL_checkinteger(L, 1);
MOD_CHECK_ID(ow, ds18b20_bus_pin);
onewire_init(ds18b20_bus_pin);
......@@ -94,25 +94,25 @@ static int ds18b20_lua_setting(lua_State *L) {
if (!lua_istable(L, 1) || !lua_isnumber(L, 2)) {
return luaL_error(L, "wrong arg range");
}
ds18b20_device_res = luaL_checkinteger(L, 2);
if (!((ds18b20_device_res == 9) || (ds18b20_device_res == 10) || (ds18b20_device_res == 11) || (ds18b20_device_res == 12))) {
return luaL_error(L, "Invalid argument: resolution");
}
// no change to th and tl setting
ds18b20_device_conf[0] = DS18B20_EEPROM_TH;
ds18b20_device_conf[1] = DS18B20_EEPROM_TL;
ds18b20_device_conf[2] = ((ds18b20_device_res - 9) << 5) + 0x1F;
uint8_t table_len = lua_objlen(L, 1);
const char *str[table_len];
const char *sep = ":";
uint8_t string_index = 0;
lua_pushnil(L);
while (lua_next(L, -3)) {
str[string_index] = lua_tostring(L, -1);
......@@ -120,7 +120,7 @@ static int ds18b20_lua_setting(lua_State *L) {
string_index++;
}
lua_pop(L, 1);
for (uint8_t i = 0; i < string_index; i++) {
for (uint8_t j = 0; j < 8; j++) {
ds18b20_device_rom[j] = strtoul(str[i], NULL, 16);
......@@ -130,10 +130,10 @@ static int ds18b20_lua_setting(lua_State *L) {
}
ds18b20_set_device(ds18b20_device_rom);
}
// set conversion delay once to max if sensors with higher resolution still on the bus
ds18b20_device_res = 12;
return 0;
}
......@@ -142,16 +142,16 @@ static int ds18b20_lua_setting(lua_State *L) {
// Reads sensor values from all devices
// Lua: ds18b20.read(function(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) print(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) end, ROM[, FAMILY])
static int ds18b20_lua_read(lua_State *L) {
luaL_argcheck(L, (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION), 1, "Must be function");
lua_pushvalue(L, 1);
ds18b20_timer_ref = luaL_ref(L, LUA_REGISTRYINDEX);
if (!lua_istable(L, 2)) {
return luaL_error(L, "wrong arg range");
}
if (lua_isnumber(L, 3)) {
ds18b20_device_family = luaL_checkinteger(L, 3);
onewire_target_search(ds18b20_bus_pin, ds18b20_device_family);
......@@ -159,10 +159,10 @@ static int ds18b20_lua_read(lua_State *L) {
} else {
ds18b20_table_offset = -2;
}
lua_pushvalue(L, 2);
ds18b20_table_ref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushnil(L);
if (lua_next(L, ds18b20_table_offset)) {
lua_pop(L, 2);
......@@ -170,9 +170,9 @@ static int ds18b20_lua_read(lua_State *L) {
} else {
ds18b20_device_search = 1;
}
os_timer_disarm(&ds18b20_timer);
// perform a temperature conversion for all sensors and set timer
onewire_reset(ds18b20_bus_pin);
onewire_write(ds18b20_bus_pin, DS18B20_ROM_SKIP, 0);
......@@ -181,7 +181,7 @@ static int ds18b20_lua_read(lua_State *L) {
SWTIMER_REG_CB(ds18b20_lua_readoutdone, SWTIMER_DROP);
//The function ds18b20_lua_readoutdone reads the temperature from the sensor(s) after a set amount of time depending on temperature resolution
//MY guess: If this timer manages to get suspended before it fires and the temperature data is time sensitive then resulting data would be invalid and should be discarded
switch (ds18b20_device_res) {
case (9):
os_timer_arm(&ds18b20_timer, 95, 0);
......@@ -203,58 +203,58 @@ static int ds18b20_read_device(uint8_t *ds18b20_device_rom) {
int16_t ds18b20_raw_temp;
if (onewire_crc8(ds18b20_device_rom,7) == ds18b20_device_rom[7]) {
onewire_reset(ds18b20_bus_pin);
onewire_select(ds18b20_bus_pin, ds18b20_device_rom);
onewire_write(ds18b20_bus_pin, DS18B20_FUNC_POWER_READ, 0);
if (onewire_read(ds18b20_bus_pin)) ds18b20_device_par = 0;
else ds18b20_device_par = 1;
onewire_reset(ds18b20_bus_pin);
onewire_select(ds18b20_bus_pin, ds18b20_device_rom);
onewire_write(ds18b20_bus_pin, DS18B20_FUNC_SCRATCH_READ, 0);
onewire_read_bytes(ds18b20_bus_pin, ds18b20_device_scratchpad, 9);
if (onewire_crc8(ds18b20_device_scratchpad,8) == ds18b20_device_scratchpad[8]) {
lua_rawgeti(L, LUA_REGISTRYINDEX, ds18b20_timer_ref);
lua_pushinteger(L, ds18b20_device_index);
lua_pushfstring(L, "%d:%d:%d:%d:%d:%d:%d:%d", ds18b20_device_rom[0], ds18b20_device_rom[1], ds18b20_device_rom[2], ds18b20_device_rom[3], ds18b20_device_rom[4], ds18b20_device_rom[5], ds18b20_device_rom[6], ds18b20_device_rom[7]);
ds18b20_device_scratchpad_conf = (ds18b20_device_scratchpad[4] >> 5) + 9;
ds18b20_raw_temp = ((ds18b20_device_scratchpad[1] << 8) | ds18b20_device_scratchpad[0]);
ds18b20_device_scratchpad_temp = (double)ds18b20_raw_temp / 16;
ds18b20_device_scratchpad_temp_dec = (ds18b20_raw_temp - (ds18b20_raw_temp / 16 * 16)) * 1000 / 16;
if (ds18b20_device_scratchpad_conf >= ds18b20_device_res) {
ds18b20_device_res = ds18b20_device_scratchpad_conf;
}
lua_pushinteger(L, ds18b20_device_scratchpad_conf);
lua_pushnumber(L, ds18b20_device_scratchpad_temp);
lua_pushinteger(L, ds18b20_device_scratchpad_temp_dec);
lua_pushinteger(L, ds18b20_device_par);
lua_pcall(L, 6, 0, 0);
ds18b20_device_index++;
}
}
}
static int ds18b20_lua_readoutdone(void) {
lua_State *L = lua_getstate();
os_timer_disarm(&ds18b20_timer);
ds18b20_device_index = 1;
// set conversion delay to min and change it after finding the sensor with the highest resolution setting
ds18b20_device_res = 9;
if (ds18b20_device_search) {
// iterate through all sensors on the bus and read temperature, resolution and parasitc settings
while (onewire_search(ds18b20_bus_pin, ds18b20_device_rom)) {
......@@ -263,12 +263,12 @@ static int ds18b20_lua_readoutdone(void) {
} else {
lua_rawgeti(L, LUA_REGISTRYINDEX, ds18b20_table_ref);
uint8_t table_len = lua_objlen(L, -1);
const char *str[table_len];
const char *sep = ":";
uint8_t string_index = 0;
lua_pushnil(L);
while (lua_next(L, -2)) {
str[string_index] = lua_tostring(L, -1);
......@@ -276,7 +276,7 @@ static int ds18b20_lua_readoutdone(void) {
string_index++;
}
lua_pop(L, 1);
for (uint8_t i = 0; i < string_index; i++) {
for (uint8_t j = 0; j < 8; j++) {
ds18b20_device_rom[j] = strtoul(str[i], NULL, 16);
......@@ -287,10 +287,10 @@ static int ds18b20_lua_readoutdone(void) {
ds18b20_read_device(ds18b20_device_rom);
}
}
luaL_unref(L, LUA_REGISTRYINDEX, ds18b20_table_ref);
ds18b20_table_ref = LUA_NOREF;
luaL_unref(L, LUA_REGISTRYINDEX, ds18b20_timer_ref);
ds18b20_timer_ref = LUA_NOREF;
}
......
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