updated sbmp

master
Ondřej Hruška 9 years ago
parent 7aece2ec1e
commit c0e091945c
  1. 2
      Makefile
  2. 5
      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 $(Q) ./html_build.sh
libesphttpd: libesphttpd/Makefile libesphttpd: libesphttpd/Makefile
$(Q) make -C libesphttpd USE_OPENSDK=$(USE_OPENSDK) $(Q) make -j4 -C libesphttpd USE_OPENSDK=$(USE_OPENSDK)
$(APP_AR): libesphttpd $(OBJ) $(APP_AR): libesphttpd $(OBJ)
$(vecho) "AR $@" $(vecho) "AR $@"

@ -8,6 +8,7 @@ DEFINES = ESPFS_HEATSHRINK HTTPD_MAX_CONNECTIONS=4 __ets__
INCLUDEPATH = . \ INCLUDEPATH = . \
esp_iot_sdk_v1.5.2/include \ esp_iot_sdk_v1.5.2/include \
include \ include \
user \
libesphttpd/include \ libesphttpd/include \
libesphttpd/espfs \ libesphttpd/espfs \
libesphttpd/core \ libesphttpd/core \
@ -131,7 +132,9 @@ HEADERS += \
sbmp/library/payload_parser.h \ sbmp/library/payload_parser.h \
user/sampling.h \ user/sampling.h \
user/page_home.h \ user/page_home.h \
include/sbmp_config.h user/timeout.h \
user/sbmp_config.h \
sbmp/library/sbmp_config.example.h
DISTFILES += \ DISTFILES += \
style.astylerc \ 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) 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 */ /** This is called by the UART rx handler */
@ -30,6 +30,7 @@ void datalink_receive(uint8_t byte)
void FLASH_FN datalinkInit(void) void FLASH_FN datalinkInit(void)
{ {
dlnk_ep = sbmp_ep_init(NULL, NULL, PAYLOAD_BUFFER_LEN, dg_handler, u0_putc); 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); sbmp_ep_enable(dlnk_ep, true);

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

@ -3,16 +3,24 @@
#include <esp8266.h> #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. * @brief Enable malloc if NULL is passed.
@ -26,27 +34,33 @@
*/ */
#define SBMP_USE_MALLOC 1 #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 * @brief Enable logging.
*
* Disabling CRC32 will reduce program size (for small micros).
* If CRC32 is disabled, XOR will be used as the preferred checksum
* method.
* *
* 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 * Disable logging to free up memory taken by the messages.
* supported here, and should start using XOR.
*/ */
#define SBMP_HAS_CRC32 1 #define SBMP_LOGGING 1
/* ---------- MALLOC --------------- */
#define sbmp_malloc(n) os_malloc(n) /**
#define sbmp_free(x) os_free(x) * @brief Enable detailed logging (only for debugging, disable for better performance).
#define sbmp_calloc(n,l) os_zalloc((n)*(l)) */
#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 #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