minor improvement..

master
Ondřej Hruška 9 years ago
parent f286b4adb6
commit 8d4ebe71fb
  1. 2
      esp_meas.pro.user
  2. 5
      user/page_waveform.c
  3. 46
      user/sampling.c
  4. 5
      user/sampling.h

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.1, 2016-04-05T14:38:12. --> <!-- Written by QtCreator 3.6.1, 2016-04-05T20:46:29. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

@ -101,11 +101,12 @@ static int FLASH_FN tplSamplesJSON(MEAS_FORMAT fmt, HttpdConnData *connData, cha
// 10 secs or 100 ms - longer wait for intial data. // 10 secs or 100 ms - longer wait for intial data.
int timeout = (st->done_count == 0 ? (int)meas_estimate_duration(st->total_count, st->freq): SAMP_READOUT_TMEO); int timeout = (st->done_count == 0 ? (int)meas_estimate_duration(st->total_count, st->freq): SAMP_RD_TMEO_TOTAL);
dbg("Chunk read total timeout = %d ms", timeout);
for (int i = 0; i < timeout*100; i++) { for (int i = 0; i < timeout*100; i++) {
uart_poll(); uart_poll();
if (meas_chunk_ready() || meas_is_closed()) break; // We have some data! --- or transaction aborted by peer :( if (meas_chunk_ready() || meas_is_closed()) break; // We have some data! --- or transaction aborted by peer :(
os_delay_us(10); // 1 ms os_delay_us(10);
system_soft_wdt_feed(); // Feed the dog, or it'll bite. system_soft_wdt_feed(); // Feed the dog, or it'll bite.
} }
chunk = meas_get_chunk(&chunk_len); chunk = meas_get_chunk(&chunk_len);

@ -11,9 +11,13 @@
// the FIFO has 128 bytes, and should accomodate ideally the whole frame. // the FIFO has 128 bytes, and should accomodate ideally the whole frame.
#define CHUNK_LEN 100 #define CHUNK_LEN 100
static void setReadoutTmeoTimer(int ms);
// Only one readout can happen at a time. // Only one readout can happen at a time.
static struct { static struct {
bool waiting_for_measure; /*!< Still waiting for first data packet */
bool pending; /*!< Flag that data is currently being read */ bool pending; /*!< Flag that data is currently being read */
uint16_t sesn; /*!< SBMP session of the readout sequence */ uint16_t sesn; /*!< SBMP session of the readout sequence */
bool chunk_ready; /*!< Chunk was received and is ready for reading */ bool chunk_ready; /*!< Chunk was received and is ready for reading */
@ -21,6 +25,7 @@ static struct {
uint16_t received_chunk_size; /*!< Size of the chunk in latest_chunk_copy */ uint16_t received_chunk_size; /*!< Size of the chunk in latest_chunk_copy */
// the readout state // the readout state
uint8_t retry_count;
uint32_t pos; uint32_t pos;
uint32_t total; uint32_t total;
ETSTimer abortTimer; ETSTimer abortTimer;
@ -39,7 +44,7 @@ bool FLASH_FN meas_is_closed(void)
uint32_t FLASH_FN meas_estimate_duration(uint32_t count, uint32_t freq) uint32_t FLASH_FN meas_estimate_duration(uint32_t count, uint32_t freq)
{ {
return (uint32_t)((count*1000.0f) / freq) + 1000; return (uint32_t)((count*1000.0f) / freq) + SAMP_RD_TMEO_TOTAL;
} }
@ -48,13 +53,30 @@ uint32_t FLASH_FN meas_estimate_duration(uint32_t count, uint32_t freq)
static void FLASH_FN abortTimerCb(void *arg) static void FLASH_FN abortTimerCb(void *arg)
{ {
(void)arg; (void)arg;
warn("Sampling aborted due to timeout.");
// try to abort the readout if (rd.waiting_for_measure) {
sbmp_bulk_abort(dlnk_ep, rd.sesn); error("Sampling aborted due to timeout.");
// release resources and stop // try to abort the readout
meas_close(); sbmp_bulk_abort(dlnk_ep, rd.sesn);
// release resources and stop
meas_close();
} else {
warn("Data chunk not rx in time");
// data chunk not received in time (may be lost ?)
if (rd.retry_count < SAMP_RD_RETRY_COUNT) {
rd.retry_count++;
dbg("Requesting again (try %d of %d).", rd.retry_count, SAMP_RD_RETRY_COUNT);
setReadoutTmeoTimer(SAMP_RD_TMEO); // re-start the timer
sbmp_bulk_request(dlnk_ep, rd.pos, CHUNK_LEN, rd.sesn);
} else {
error("Retry count exhausted!");
meas_close();
}
}
} }
static void FLASH_FN setReadoutTmeoTimer(int ms) static void FLASH_FN setReadoutTmeoTimer(int ms)
@ -80,6 +102,7 @@ void FLASH_FN meas_request_next_chunk(void)
{ {
if (!rd.pending) return; if (!rd.pending) return;
rd.chunk_ready = false; // invalidate the current chunk, so waiting for chunk is possible. rd.chunk_ready = false; // invalidate the current chunk, so waiting for chunk is possible.
rd.retry_count = 0; // reset retry counter
sbmp_bulk_request(dlnk_ep, rd.pos, CHUNK_LEN, rd.sesn); sbmp_bulk_request(dlnk_ep, rd.pos, CHUNK_LEN, rd.sesn);
} }
@ -89,6 +112,8 @@ bool FLASH_FN meas_chunk_ready(void)
return rd.pending && rd.chunk_ready; return rd.pending && rd.chunk_ready;
} }
/** /**
* @brief Get received chunk. NULL if none. * @brief Get received chunk. NULL if none.
* *
@ -149,6 +174,7 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
rd.pos = 0; rd.pos = 0;
rd.total = pp_u32(&pp); rd.total = pp_u32(&pp);
rd.waiting_for_measure = false; // "pending" flag remains set
// --- here start the user data (common) --- // --- here start the user data (common) ---
rd.stats.count = pp_u32(&pp); rd.stats.count = pp_u32(&pp);
@ -163,9 +189,10 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
} }
// renew the timeout // renew the timeout
setReadoutTmeoTimer(SAMP_READOUT_TMEO); setReadoutTmeoTimer(SAMP_RD_TMEO);
// request first chunk // request first chunk
rd.retry_count = 0;
sbmp_bulk_request(ep, rd.pos, CHUNK_LEN, dg->session); sbmp_bulk_request(ep, rd.pos, CHUNK_LEN, dg->session);
break; break;
@ -176,11 +203,12 @@ static void FLASH_FN request_data_sesn_listener(SBMP_Endpoint *ep, SBMP_Datagram
memcpy(rd.received_chunk, dg->payload, dg->length); memcpy(rd.received_chunk, dg->payload, dg->length);
rd.chunk_ready = true; rd.chunk_ready = true;
rd.received_chunk_size = dg->length; rd.received_chunk_size = dg->length;
rd.retry_count = 0;
// move the pointer for next request // move the pointer for next request
rd.pos += dg->length; rd.pos += dg->length;
setReadoutTmeoTimer(SAMP_READOUT_TMEO); // timeout to retrieve the data & ask for more setReadoutTmeoTimer(SAMP_RD_TMEO); // timeout to retrieve the data & ask for more
// --- Now we wait for the CGI func to retrieve the chunk and send it to the browser. --- // --- Now we wait for the CGI func to retrieve the chunk and send it to the browser. ---
@ -229,6 +257,7 @@ bool FLASH_FN meas_request_data(MEAS_FORMAT format, uint16_t count, uint32_t fre
rd.total = 0; rd.total = 0;
rd.pending = true; rd.pending = true;
rd.format = format; rd.format = format;
rd.retry_count = 0;
memset(&rd.stats, 0, sizeof(MeasStats)); // clear the stats obj memset(&rd.stats, 0, sizeof(MeasStats)); // clear the stats obj
// start the abort timer - timeout // start the abort timer - timeout
@ -248,6 +277,7 @@ bool FLASH_FN meas_request_data(MEAS_FORMAT format, uint16_t count, uint32_t fre
} }
rd.sesn = sesn; rd.sesn = sesn;
rd.waiting_for_measure = true; // waiting for acquisition module to start sending data
// request N values // request N values
sbmp_ep_send_u16(dlnk_ep, count); sbmp_ep_send_u16(dlnk_ep, count);

@ -5,7 +5,10 @@
#include <httpd.h> #include <httpd.h>
#include "datalink.h" #include "datalink.h"
#define SAMP_READOUT_TMEO 500 // ms
#define SAMP_RD_TMEO 300
#define SAMP_RD_RETRY_COUNT 3
#define SAMP_RD_TMEO_TOTAL (SAMP_RD_TMEO*SAMP_RD_RETRY_COUNT+200)
typedef struct { typedef struct {
uint32_t count; uint32_t count;

Loading…
Cancel
Save