updated sbmp

master
Ondřej Hruška 8 years ago
parent 7aece2ec1e
commit c0e091945c
  1. 2
      Makefile
  2. 17
      esp_meas.pro
  3. 2
      sbmp
  4. 3
      user/datalink.c
  5. 19
      user/sampling.c
  6. 54
      user/sbmp_config.h
  7. 15
      user/timeout.h

@ -200,7 +200,7 @@ html:
$(Q) ./html_build.sh
libesphttpd: libesphttpd/Makefile
$(Q) make -C libesphttpd USE_OPENSDK=$(USE_OPENSDK)
$(Q) make -j4 -C libesphttpd USE_OPENSDK=$(USE_OPENSDK)
$(APP_AR): libesphttpd $(OBJ)
$(vecho) "AR $@"

@ -8,6 +8,7 @@ DEFINES = ESPFS_HEATSHRINK HTTPD_MAX_CONNECTIONS=4 __ets__
INCLUDEPATH = . \
esp_iot_sdk_v1.5.2/include \
include \
user \
libesphttpd/include \
libesphttpd/espfs \
libesphttpd/core \
@ -52,9 +53,9 @@ SOURCES += \
user/datalink.c \
user/serial.c \
user/uptime.c \
sbmp/library/payload_parser.c \
user/sampling.c \
user/page_home.c
sbmp/library/payload_parser.c \
user/sampling.c \
user/page_home.c
HEADERS += \
include/uart_hw.h \
@ -128,10 +129,12 @@ HEADERS += \
user/serial.h \
libesphttpd/include/logging.h \
user/uptime.h \
sbmp/library/payload_parser.h \
user/sampling.h \
user/page_home.h \
include/sbmp_config.h
sbmp/library/payload_parser.h \
user/sampling.h \
user/page_home.h \
user/timeout.h \
user/sbmp_config.h \
sbmp/library/sbmp_config.example.h
DISTFILES += \
style.astylerc \

@ -1 +1 @@
Subproject commit 32258ec164775a543486c8e6827c500d1626fb48
Subproject commit 6495ad6474dbd7a5e7198fbb998a247efed368a2

@ -17,7 +17,7 @@ static void FLASH_FN u0_putc(uint8_t c)
static void FLASH_FN dg_handler(SBMP_Datagram *dg)
{
dbg("[SBMP] Datagram received, type %d", dg->type);
dbg("[SBMP] Datagram received, type %d, session %d", dg->type, dg->session);
}
/** This is called by the UART rx handler */
@ -30,6 +30,7 @@ void datalink_receive(uint8_t byte)
void FLASH_FN datalinkInit(void)
{
dlnk_ep = sbmp_ep_init(NULL, NULL, PAYLOAD_BUFFER_LEN, dg_handler, u0_putc);
sbmp_ep_init_listeners(dlnk_ep, NULL, 4);
sbmp_ep_enable(dlnk_ep, true);

@ -3,6 +3,7 @@
#include "datalink.h"
#include "sampling.h"
#include "timeout.h"
// The buffer is big enough for 256 data bytes - 4*64
@ -37,6 +38,7 @@ typedef struct {
static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram *dg, void **obj)
{
bool suc = false;
dbg("Received msg in session %d, dg type %d", dg->session, dg->type);
DataReadState *state = *obj;
@ -47,7 +49,6 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
*obj = state;
}
PayloadParser pp;
switch (dg->type) {
case DG_BULK_OFFER:// Data ready notification
@ -61,7 +62,7 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
dbg("Total bytes: %d", state->total);
sbmp_bulk_request(ep, state->pos, CHUNK_LEN, dg->session); // 64 floats in one message
retry_until_timeout(10, sbmp_bulk_request(ep, state->pos, CHUNK_LEN, dg->session));
break;
case DG_BULK_DATA: // data received
@ -83,11 +84,12 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
// make sure the peer has freed the buffer
// (may be waiting for us if we wanted to re-read something)
sbmp_bulk_abort(ep, dg->session);
retry_until_timeout(10, sbmp_bulk_abort(ep, dg->session));
goto cleanup;
} else {
// read next part
sbmp_bulk_request(ep, state->pos, CHUNK_LEN, dg->session);
retry_until_timeout(10, sbmp_bulk_request(ep, state->pos, CHUNK_LEN, dg->session));
}
break;
@ -130,10 +132,11 @@ static bool FLASH_FN meas_request_data(uint16_t count)
// start a message
uint16_t sesn;
bool suc = sbmp_ep_start_message(dlnk_ep, DG_REQUEST_CAPTURE, sizeof(uint16_t), &sesn);
if (!suc) return false;
if (!suc) goto fail;
// register the session listener
sbmp_ep_add_listener(dlnk_ep, sesn, request_data_sesn_listener, NULL);
suc = sbmp_ep_add_listener(dlnk_ep, sesn, request_data_sesn_listener, NULL);
if (!suc) goto fail;
// request N values
sbmp_ep_send_u16(dlnk_ep, count);
@ -143,6 +146,10 @@ static bool FLASH_FN meas_request_data(uint16_t count)
acquire_session = sesn;
return true;
fail:
os_timer_disarm(&prSampleAbortTimer);
return false;
}

@ -3,16 +3,24 @@
#include <esp8266.h>
/* --- Configuration ------------------- */
/* ---------- CRC32 ---------------- */
/**
* @brief Enable logging.
* @brief Add support for CRC32
*
* Logging functions are WEAK stubs in sbmp_logging.
* Disabling CRC32 will reduce program size (for small micros).
* If CRC32 is disabled, XOR will be used as the preferred checksum
* method.
*
* Disable logging to free up memory taken by the messages.
* Received CRC32'd messages will be accepted without checking.
*
* If handshake is used, the peer will detect that CRC32 is not
* supported here, and should start using XOR.
*/
#define SBMP_LOGGING 1
#define SBMP_HAS_CRC32 1
/* ---------- MALLOC --------------- */
/**
* @brief Enable malloc if NULL is passed.
@ -26,27 +34,33 @@
*/
#define SBMP_USE_MALLOC 1
// those will be used if malloc is enabled
#define sbmp_malloc(n) os_malloc(n)
#define sbmp_free(x) os_free(x)
#define sbmp_calloc(n,l) os_zalloc((n)*(l))
/* ---------- LOGGING -------------- */
/**
* @brief Add support for CRC32
*
* Disabling CRC32 will reduce program size (for small micros).
* If CRC32 is disabled, XOR will be used as the preferred checksum
* method.
* @brief Enable logging.
*
* Received CRC32'd messages will be accepted without checking.
* Logging functions are WEAK stubs in sbmp_logging.
*
* If handshake is used, the peer will detect that CRC32 is not
* supported here, and should start using XOR.
* Disable logging to free up memory taken by the messages.
*/
#define SBMP_HAS_CRC32 1
/* ---------- MALLOC --------------- */
#define SBMP_LOGGING 1
#define sbmp_malloc(n) os_malloc(n)
#define sbmp_free(x) os_free(x)
#define sbmp_calloc(n,l) os_zalloc((n)*(l))
/**
* @brief Enable detailed logging (only for debugging, disable for better performance).
*/
#define SBMP_DEBUG 1
/* ------------------------------------- */
// here are the actual logging functions
#define sbmp_error(fmt, ...) (SBMP_DEBUG||SBMP_LOGGING ? os_printf("\x1b[31;1m[SBMP][E] "fmt"\x1b[0m\n", ##__VA_ARGS__) : 0)
#define sbmp_warn(fmt, ...) (SBMP_DEBUG||SBMP_LOGGING ? os_printf("\x1b[33;1m[SBMP][E] "fmt"\x1b[0m\n", ##__VA_ARGS__) : 0)
#define sbmp_info(fmt, ...) (SBMP_DEBUG||SBMP_LOGGING ? os_printf("\x1b[32m[SBMP][i] "fmt"\x1b[0m\n", ##__VA_ARGS__) : 0)
#define sbmp_dbg(fmt, ...) (SBMP_DEBUG ? os_printf("[SBMP][ ] "fmt"\n", ##__VA_ARGS__) : 0)
#endif // SBMP_CONFIG_H

@ -0,0 +1,15 @@
#ifndef TIMEOUT_H
#define TIMEOUT_H
#include <esp8266.h>
#define until_timeout(to_ms) for(uint32_t _utmeo = system_get_time(); system_get_time() - _utmeo < ((to_ms)*1000);)
/** Retry a call until a timeout. Variable 'suc' is set to the return value. Must be defined. */
#define retry_until_timeout(to_ms, call) \
until_timeout(to_ms) { \
suc = call; \
if (suc) break; \
}
#endif // TIMEOUT_H
Loading…
Cancel
Save