append esp timestamp and measurement ID to all START messages
This commit is contained in:
parent
bb894b42be
commit
80dc8ef561
33
main/eis4.c
33
main/eis4.c
|
|
@ -12,9 +12,11 @@
|
|||
#include "nvs_flash.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
#define AD5941_EXPECTED_ADIID 0x4144
|
||||
static EISConfig cfg;
|
||||
static uint16_t measurement_counter = 0;
|
||||
static EISPoint results[EIS_MAX_POINTS];
|
||||
static LSVPoint lsv_results[ECHEM_MAX_POINTS];
|
||||
static AmpPoint amp_results[ECHEM_MAX_POINTS];
|
||||
|
|
@ -25,8 +27,10 @@ static void do_sweep(void)
|
|||
{
|
||||
eis_init(&cfg);
|
||||
|
||||
uint32_t ts_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
measurement_counter++;
|
||||
uint32_t n = eis_calc_num_points(&cfg);
|
||||
send_sweep_start(n, cfg.freq_start_hz, cfg.freq_stop_hz);
|
||||
send_sweep_start(n, cfg.freq_start_hz, cfg.freq_stop_hz, ts_ms, measurement_counter);
|
||||
int got = eis_sweep(results, n, send_eis_point);
|
||||
printf("Sweep complete: %d points\n", got);
|
||||
send_sweep_end();
|
||||
|
|
@ -132,8 +136,10 @@ void app_main(void)
|
|||
lsv_cfg.v_start, lsv_cfg.v_stop, lsv_cfg.scan_rate, lsv_cfg.lp_rtia,
|
||||
(unsigned long)max_pts);
|
||||
|
||||
uint32_t ts_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
measurement_counter++;
|
||||
uint32_t n = echem_lsv_calc_steps(&lsv_cfg, max_pts);
|
||||
send_lsv_start(n, lsv_cfg.v_start, lsv_cfg.v_stop);
|
||||
send_lsv_start(n, lsv_cfg.v_start, lsv_cfg.v_stop, ts_ms, measurement_counter);
|
||||
int got = echem_lsv(&lsv_cfg, lsv_results, max_pts, send_lsv_point);
|
||||
printf("LSV complete: %d points\n", got);
|
||||
send_lsv_end();
|
||||
|
|
@ -149,7 +155,11 @@ void app_main(void)
|
|||
printf("Amp: %.0f mV, %.0f ms interval, %.0f s\n",
|
||||
amp_cfg.v_hold, amp_cfg.interval_ms, amp_cfg.duration_s);
|
||||
|
||||
send_amp_start(amp_cfg.v_hold);
|
||||
{
|
||||
uint32_t ts_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
measurement_counter++;
|
||||
send_amp_start(amp_cfg.v_hold, ts_ms, measurement_counter);
|
||||
}
|
||||
int got = echem_amp(&_cfg, amp_results, ECHEM_MAX_POINTS, send_amp_point);
|
||||
printf("Amp complete: %d points\n", got);
|
||||
send_amp_end();
|
||||
|
|
@ -171,7 +181,12 @@ void app_main(void)
|
|||
echem_ph_ocp(&ph_cfg, &ph_result);
|
||||
printf("pH: OCP=%.1f mV, pH=%.2f\n",
|
||||
ph_result.v_ocp_mv, ph_result.ph);
|
||||
send_ph_result(ph_result.v_ocp_mv, ph_result.ph, ph_result.temp_c);
|
||||
{
|
||||
uint32_t ts_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
measurement_counter++;
|
||||
send_ph_result(ph_result.v_ocp_mv, ph_result.ph, ph_result.temp_c,
|
||||
ts_ms, measurement_counter);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -197,8 +212,10 @@ void app_main(void)
|
|||
case CMD_OPEN_CAL: {
|
||||
printf("Open-circuit cal starting\n");
|
||||
eis_init(&cfg);
|
||||
uint32_t ts_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
measurement_counter++;
|
||||
uint32_t n = eis_calc_num_points(&cfg);
|
||||
send_sweep_start(n, cfg.freq_start_hz, cfg.freq_stop_hz);
|
||||
send_sweep_start(n, cfg.freq_start_hz, cfg.freq_stop_hz, ts_ms, measurement_counter);
|
||||
int got = eis_open_cal(results, n, send_eis_point);
|
||||
printf("Open-circuit cal: %d points\n", got);
|
||||
send_sweep_end();
|
||||
|
|
@ -252,7 +269,11 @@ void app_main(void)
|
|||
|
||||
uint32_t n_per = (uint32_t)(cl_cfg.t_meas_ms / 50.0f + 0.5f);
|
||||
if (n_per < 2) n_per = 2;
|
||||
send_cl_start(2 * n_per);
|
||||
{
|
||||
uint32_t ts_ms = (uint32_t)(esp_timer_get_time() / 1000);
|
||||
measurement_counter++;
|
||||
send_cl_start(2 * n_per, ts_ms, measurement_counter);
|
||||
}
|
||||
ClResult cl_result;
|
||||
int got = echem_chlorine(&cl_cfg, cl_results, ECHEM_MAX_POINTS,
|
||||
&cl_result, send_cl_point);
|
||||
|
|
|
|||
|
|
@ -177,14 +177,17 @@ int send_keepalive(void)
|
|||
|
||||
/* ---- outbound: EIS ---- */
|
||||
|
||||
int send_sweep_start(uint32_t num_points, float freq_start, float freq_stop)
|
||||
int send_sweep_start(uint32_t num_points, float freq_start, float freq_stop,
|
||||
uint32_t ts_ms, uint16_t meas_id)
|
||||
{
|
||||
uint8_t sx[20];
|
||||
uint8_t sx[28];
|
||||
uint16_t p = 0;
|
||||
sx[p++] = 0xF0; sx[p++] = 0x7D; sx[p++] = RSP_SWEEP_START;
|
||||
encode_u16((uint16_t)num_points, &sx[p]); p += 3;
|
||||
encode_float(freq_start, &sx[p]); p += 5;
|
||||
encode_float(freq_stop, &sx[p]); p += 5;
|
||||
encode_u32(ts_ms, &sx[p]); p += 5;
|
||||
encode_u16(meas_id, &sx[p]); p += 3;
|
||||
sx[p++] = 0xF7;
|
||||
return send_sysex(sx, p);
|
||||
}
|
||||
|
|
@ -232,14 +235,17 @@ int send_config(const EISConfig *cfg)
|
|||
|
||||
/* ---- outbound: LSV ---- */
|
||||
|
||||
int send_lsv_start(uint32_t num_points, float v_start, float v_stop)
|
||||
int send_lsv_start(uint32_t num_points, float v_start, float v_stop,
|
||||
uint32_t ts_ms, uint16_t meas_id)
|
||||
{
|
||||
uint8_t sx[20];
|
||||
uint8_t sx[28];
|
||||
uint16_t p = 0;
|
||||
sx[p++] = 0xF0; sx[p++] = 0x7D; sx[p++] = RSP_LSV_START;
|
||||
encode_u16((uint16_t)num_points, &sx[p]); p += 3;
|
||||
encode_float(v_start, &sx[p]); p += 5;
|
||||
encode_float(v_stop, &sx[p]); p += 5;
|
||||
encode_u32(ts_ms, &sx[p]); p += 5;
|
||||
encode_u16(meas_id, &sx[p]); p += 3;
|
||||
sx[p++] = 0xF7;
|
||||
return send_sysex(sx, p);
|
||||
}
|
||||
|
|
@ -264,12 +270,14 @@ int send_lsv_end(void)
|
|||
|
||||
/* ---- outbound: Amperometry ---- */
|
||||
|
||||
int send_amp_start(float v_hold)
|
||||
int send_amp_start(float v_hold, uint32_t ts_ms, uint16_t meas_id)
|
||||
{
|
||||
uint8_t sx[12];
|
||||
uint8_t sx[20];
|
||||
uint16_t p = 0;
|
||||
sx[p++] = 0xF0; sx[p++] = 0x7D; sx[p++] = RSP_AMP_START;
|
||||
encode_float(v_hold, &sx[p]); p += 5;
|
||||
encode_u32(ts_ms, &sx[p]); p += 5;
|
||||
encode_u16(meas_id, &sx[p]); p += 3;
|
||||
sx[p++] = 0xF7;
|
||||
return send_sysex(sx, p);
|
||||
}
|
||||
|
|
@ -294,12 +302,14 @@ int send_amp_end(void)
|
|||
|
||||
/* ---- outbound: Chlorine ---- */
|
||||
|
||||
int send_cl_start(uint32_t num_points)
|
||||
int send_cl_start(uint32_t num_points, uint32_t ts_ms, uint16_t meas_id)
|
||||
{
|
||||
uint8_t sx[10];
|
||||
uint8_t sx[18];
|
||||
uint16_t p = 0;
|
||||
sx[p++] = 0xF0; sx[p++] = 0x7D; sx[p++] = RSP_CL_START;
|
||||
encode_u16((uint16_t)num_points, &sx[p]); p += 3;
|
||||
encode_u32(ts_ms, &sx[p]); p += 5;
|
||||
encode_u16(meas_id, &sx[p]); p += 3;
|
||||
sx[p++] = 0xF7;
|
||||
return send_sysex(sx, p);
|
||||
}
|
||||
|
|
@ -349,14 +359,17 @@ int send_ph_cal(float slope, float offset)
|
|||
|
||||
/* ---- outbound: pH ---- */
|
||||
|
||||
int send_ph_result(float v_ocp_mv, float ph, float temp_c)
|
||||
int send_ph_result(float v_ocp_mv, float ph, float temp_c,
|
||||
uint32_t ts_ms, uint16_t meas_id)
|
||||
{
|
||||
uint8_t sx[20];
|
||||
uint8_t sx[28];
|
||||
uint16_t p = 0;
|
||||
sx[p++] = 0xF0; sx[p++] = 0x7D; sx[p++] = RSP_PH_RESULT;
|
||||
encode_float(v_ocp_mv, &sx[p]); p += 5;
|
||||
encode_float(ph, &sx[p]); p += 5;
|
||||
encode_float(temp_c, &sx[p]); p += 5;
|
||||
encode_u32(ts_ms, &sx[p]); p += 5;
|
||||
encode_u16(meas_id, &sx[p]); p += 3;
|
||||
sx[p++] = 0xF7;
|
||||
return send_sysex(sx, p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,29 +113,32 @@ float decode_float(const uint8_t *d);
|
|||
uint16_t decode_u16(const uint8_t *d);
|
||||
|
||||
/* outbound: EIS */
|
||||
int send_sweep_start(uint32_t num_points, float freq_start, float freq_stop);
|
||||
int send_sweep_start(uint32_t num_points, float freq_start, float freq_stop,
|
||||
uint32_t ts_ms, uint16_t meas_id);
|
||||
int send_eis_point(uint16_t index, const EISPoint *pt);
|
||||
int send_sweep_end(void);
|
||||
int send_config(const EISConfig *cfg);
|
||||
|
||||
/* outbound: LSV */
|
||||
int send_lsv_start(uint32_t num_points, float v_start, float v_stop);
|
||||
int send_lsv_start(uint32_t num_points, float v_start, float v_stop,
|
||||
uint32_t ts_ms, uint16_t meas_id);
|
||||
int send_lsv_point(uint16_t index, float v_mv, float i_ua);
|
||||
int send_lsv_end(void);
|
||||
|
||||
/* outbound: Amperometry */
|
||||
int send_amp_start(float v_hold);
|
||||
int send_amp_start(float v_hold, uint32_t ts_ms, uint16_t meas_id);
|
||||
int send_amp_point(uint16_t index, float t_ms, float i_ua);
|
||||
int send_amp_end(void);
|
||||
|
||||
/* outbound: Chlorine */
|
||||
int send_cl_start(uint32_t num_points);
|
||||
int send_cl_start(uint32_t num_points, uint32_t ts_ms, uint16_t meas_id);
|
||||
int send_cl_point(uint16_t index, float t_ms, float i_ua, uint8_t phase);
|
||||
int send_cl_result(float i_free_ua, float i_total_ua);
|
||||
int send_cl_end(void);
|
||||
|
||||
/* outbound: pH */
|
||||
int send_ph_result(float v_ocp_mv, float ph, float temp_c);
|
||||
int send_ph_result(float v_ocp_mv, float ph, float temp_c,
|
||||
uint32_t ts_ms, uint16_t meas_id);
|
||||
|
||||
/* outbound: temperature */
|
||||
int send_temp(float temp_c);
|
||||
|
|
|
|||
Loading…
Reference in New Issue