Skip to content

Commit

Permalink
dlog record refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Feb 3, 2020
1 parent 18d1e27 commit c7aa3da
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 273 deletions.
544 changes: 319 additions & 225 deletions src/eez/modules/psu/dlog_record.cpp

Large diffs are not rendered by default.

27 changes: 12 additions & 15 deletions src/eez/modules/psu/dlog_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@
#pragma once

#include <eez/modules/psu/trigger.h>


#include <eez/modules/psu/dlog_view.h>

namespace eez {
namespace psu {
namespace dlog_record {

enum State {
STATE_IDLE,
STATE_INITIATED,
STATE_EXECUTING
};

static const float PERIOD_MIN = 0.005f;
static const float PERIOD_MAX = 120.0f;
static const float PERIOD_DEFAULT = 0.02f;
Expand All @@ -42,33 +34,38 @@ static const float TIME_MAX = 86400000.0f;
static const float TIME_DEFAULT = 60.0f;

extern double g_currentTime;

extern uint32_t g_fileLength;

extern dlog_view::Parameters g_parameters;
extern dlog_view::Parameters g_guiParameters;

extern dlog_view::Recording g_recording;

enum State {
STATE_IDLE,
STATE_INITIATED,
STATE_EXECUTING
};

State getState();
int checkDlogParameters(dlog_view::Parameters &parameters, bool doNotCheckFilePath, bool forTraceUsage);
bool isIdle();
bool isInitiated();
bool isExecuting();
bool isTraceExecuting();

int checkDlogParameters(dlog_view::Parameters &parameters, bool doNotCheckFilePath, bool forTraceUsage);

int initiate();
int initiateTrace();
int startImmediately();
void triggerGenerated();
void toggle();
void abort(bool flush = true);

void tick(uint32_t tick_usec);
void abort();
void reset();

void tick(uint32_t tick_usec);
void log(float *values);

void fileWrite();
void stateTransition(int action, int *perr = nullptr);

const char *getLatestFilePath();

Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/dlog_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static bool g_wasExecuting;

State getState() {
if (g_showLatest) {
if (dlog_record::isExecuting()) {
if (g_wasExecuting) {
return STATE_READY;
}
}
Expand Down Expand Up @@ -751,7 +751,7 @@ void openFile(const char *filePath) {
}

Recording &getRecording() {
return g_showLatest && dlog_record::isExecuting() ? dlog_record::g_recording : g_recording;
return g_showLatest && g_wasExecuting ? dlog_record::g_recording : g_recording;
}

float roundValue(float value) {
Expand Down
28 changes: 14 additions & 14 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4472,7 +4472,7 @@ void data_dlog_toggle_state(data::DataOperationEnum operation, data::Cursor &cur

void data_is_show_live_recording(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
value = &recording == &dlog_record::g_recording;
}
}
Expand Down Expand Up @@ -4606,7 +4606,7 @@ void data_is_single_page_on_stack(data::DataOperationEnum operation, data::Curso
}

void data_recording(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();

if (operation == DATA_OPERATION_YT_DATA_GET_REFRESH_COUNTER) {
value = Value(recording.refreshCounter, VALUE_TYPE_UINT32);
Expand Down Expand Up @@ -4786,7 +4786,7 @@ void data_dlog_overlay(data::DataOperationEnum operation, data::Cursor &cursor,
if (operation == data::DATA_OPERATION_GET_OVERLAY_DATA) {
value = data::Value(&overlay, VALUE_TYPE_POINTER);
} else if (operation == data::DATA_OPERATION_UPDATE_OVERLAY_DATA) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();

int state = 0;
int numVisibleDlogValues = dlog_view::getNumVisibleDlogValues(recording);
Expand Down Expand Up @@ -4835,7 +4835,7 @@ void data_dlog_overlay_over_4(data::DataOperationEnum operation, data::Cursor &c
if (operation == data::DATA_OPERATION_GET_OVERLAY_DATA) {
value = data::Value(&overlay, VALUE_TYPE_POINTER);
} else if (operation == data::DATA_OPERATION_UPDATE_OVERLAY_DATA) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
overlay.state = dlog_view::g_showLegend && !dlog_view::yAxisHasDifferentUnits(recording);

WidgetCursor &widgetCursor = *(WidgetCursor *)value.getVoidPointer();
Expand All @@ -4848,21 +4848,21 @@ void data_dlog_overlay_over_4(data::DataOperationEnum operation, data::Cursor &c

void data_dlog_visible_values(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_COUNT) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
value = getNumVisibleDlogValues(recording);
}
}

void data_dlog_visible_value_label(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
int dlogValueIndex = dlog_view::getDlogValueIndex(recording, !dlog_view::yAxisHasDifferentUnits(recording) ? recording.selectedVisibleValueIndex : cursor.i);
value = Value(dlogValueIndex, VALUE_TYPE_DLOG_VALUE_LABEL);
}
}

void data_dlog_visible_value_div(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
int dlogValueIndex = dlog_view::getDlogValueIndex(recording, !dlog_view::yAxisHasDifferentUnits(recording) ? recording.selectedVisibleValueIndex : cursor.i);

if (operation == data::DATA_OPERATION_GET) {
Expand Down Expand Up @@ -4896,7 +4896,7 @@ void data_dlog_visible_value_div(data::DataOperationEnum operation, data::Cursor
}

void data_dlog_visible_value_offset(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
int dlogValueIndex = dlog_view::getDlogValueIndex(recording, !dlog_view::yAxisHasDifferentUnits(recording) ? recording.selectedVisibleValueIndex : cursor.i);

if (operation == data::DATA_OPERATION_GET) {
Expand Down Expand Up @@ -4929,7 +4929,7 @@ void data_dlog_visible_value_offset(data::DataOperationEnum operation, data::Cur
}

void data_dlog_x_axis_offset(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();

if (operation == data::DATA_OPERATION_GET) {
bool focused = g_focusCursor == cursor && g_focusDataId == DATA_ID_DLOG_X_AXIS_OFFSET;
Expand All @@ -4954,7 +4954,7 @@ void data_dlog_x_axis_offset(data::DataOperationEnum operation, data::Cursor &cu
}

void data_dlog_x_axis_div(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();

if (operation == data::DATA_OPERATION_GET) {
bool focused = g_focusCursor == cursor && g_focusDataId == DATA_ID_DLOG_X_AXIS_DIV;
Expand All @@ -4980,7 +4980,7 @@ void data_dlog_x_axis_div(data::DataOperationEnum operation, data::Cursor &curso

void data_dlog_x_axis_max_value(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();

float maxValue = dlog_view::getDuration(recording);

Expand All @@ -4994,7 +4994,7 @@ void data_dlog_x_axis_max_value(data::DataOperationEnum operation, data::Cursor

void data_dlog_x_axis_max_value_label(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
if (recording.parameters.xAxis.unit == UNIT_SECOND) {
value = "Total duration";
} else {
Expand All @@ -5005,7 +5005,7 @@ void data_dlog_x_axis_max_value_label(data::DataOperationEnum operation, data::C

void data_dlog_visible_value_cursor(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
int dlogValueIndex = dlog_view::getDlogValueIndex(recording, !dlog_view::yAxisHasDifferentUnits(recording) ? recording.selectedVisibleValueIndex : cursor.i);
auto ytDataGetValue = data::ytDataGetGetValueFunc(cursor, DATA_ID_RECORDING);
float max;
Expand Down Expand Up @@ -5046,7 +5046,7 @@ void data_dlog_value_label(data::DataOperationEnum operation, data::Cursor &curs

void data_dlog_value_state(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
dlog_view::Recording &recording = dlog_view::getRecording();
auto &recording = dlog_view::getRecording();
value = cursor.i < recording.parameters.numYAxes ? recording.dlogValues[cursor.i].isVisible : 2;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ uint16_t overrideStyleHook(const WidgetCursor &widgetCursor, uint16_t styleId) {

uint16_t overrideStyleColorHook(const WidgetCursor &widgetCursor, const Style *style) {
if (widgetCursor.widget->type == WIDGET_TYPE_TEXT && (widgetCursor.widget->data == DATA_ID_DLOG_VALUE_LABEL || widgetCursor.widget->data == DATA_ID_DLOG_VISIBLE_VALUE_LABEL)) {
psu::dlog_view::Recording &recording = psu::dlog_view::getRecording();
auto &recording = psu::dlog_view::getRecording();
int dlogValueIndex = psu::dlog_view::getDlogValueIndex(recording, psu::dlog_view::yAxisHasDifferentUnits(recording) ? widgetCursor.cursor.i : recording.selectedVisibleValueIndex);
style = ytDataGetStyle(widgetCursor.cursor, DATA_ID_RECORDING, dlogValueIndex);
}
Expand All @@ -1664,7 +1664,7 @@ uint16_t overrideStyleColorHook(const WidgetCursor &widgetCursor, const Style *s

uint16_t overrideActiveStyleColorHook(const WidgetCursor &widgetCursor, const Style *style) {
if (widgetCursor.widget->type == WIDGET_TYPE_TEXT && (widgetCursor.widget->data == DATA_ID_DLOG_VALUE_LABEL || widgetCursor.widget->data == DATA_ID_DLOG_VISIBLE_VALUE_LABEL)) {
psu::dlog_view::Recording &recording = psu::dlog_view::getRecording();
auto &recording = psu::dlog_view::getRecording();
int dlogValueIndex = psu::dlog_view::getDlogValueIndex(recording, psu::dlog_view::yAxisHasDifferentUnits(recording) ? widgetCursor.cursor.i : recording.selectedVisibleValueIndex);
style = ytDataGetStyle(widgetCursor.cursor, DATA_ID_RECORDING, dlogValueIndex);
}
Expand Down
10 changes: 0 additions & 10 deletions src/eez/modules/psu/scpi/dlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ scpi_result_t scpi_cmd_abortDlog(scpi_t *context) {
}

scpi_result_t scpi_cmd_initiateDlog(scpi_t *context) {
if (!dlog_record::isIdle()) {
SCPI_ErrorPush(context, SCPI_ERROR_CANNOT_CHANGE_TRANSIENT_TRIGGER);
return SCPI_RES_ERR;
}

char filePath[MAX_PATH_LENGTH + 1];
if (!getFilePath(context, filePath, true)) {
return SCPI_RES_ERR;
Expand Down Expand Up @@ -738,11 +733,6 @@ scpi_result_t scpi_cmd_senseDlogTraceYScaleQ(scpi_t *context) {
}

scpi_result_t scpi_cmd_initiateDlogTrace(scpi_t *context) {
if (!dlog_record::isIdle()) {
SCPI_ErrorPush(context, SCPI_ERROR_CANNOT_CHANGE_TRANSIENT_TRIGGER);
return SCPI_RES_ERR;
}

char filePath[MAX_PATH_LENGTH + 1];
if (!getFilePath(context, filePath, true)) {
return SCPI_RES_ERR;
Expand Down
6 changes: 3 additions & 3 deletions src/eez/scpi/scpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ void oneIter() {
eez::psu::sd_card::onSdDetectInterruptHandler();
}
#endif
else if (type == SCPI_QUEUE_MESSAGE_DLOG_FILE_WRITE) {
else if (type == SCPI_QUEUE_MESSAGE_TYPE_DLOG_FILE_WRITE) {
eez::psu::dlog_record::fileWrite();
}
else if (type == SCPI_QUEUE_MESSAGE_DLOG_TOGGLE) {
eez::psu::dlog_record::toggle();
else if (type == SCPI_QUEUE_MESSAGE_TYPE_DLOG_STATE_TRANSITION) {
eez::psu::dlog_record::stateTransition(param);
} else if (type == SCPI_QUEUE_MESSAGE_DLOG_SHOW_FILE) {
eez::psu::dlog_view::openFile(nullptr);
} else if (type == SCPI_QUEUE_MESSAGE_DLOG_LOAD_BLOCK) {
Expand Down
4 changes: 2 additions & 2 deletions src/eez/scpi/scpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ extern osMessageQId g_scpiMessageQueueId;
#define SCPI_QUEUE_MESSAGE_TYPE_SAVE_LIST 1
#define SCPI_QUEUE_MESSAGE_TYPE_DELETE_PROFILE_LISTS 2
#define SCPI_QUEUE_MESSAGE_TYPE_SD_DETECT_IRQ 3
#define SCPI_QUEUE_MESSAGE_DLOG_FILE_WRITE 4
#define SCPI_QUEUE_MESSAGE_DLOG_TOGGLE 5
#define SCPI_QUEUE_MESSAGE_TYPE_DLOG_FILE_WRITE 4
#define SCPI_QUEUE_MESSAGE_TYPE_DLOG_STATE_TRANSITION 5
#define SCPI_QUEUE_MESSAGE_DLOG_SHOW_FILE 6
#define SCPI_QUEUE_MESSAGE_DLOG_LOAD_BLOCK 7
#define SCPI_QUEUE_MESSAGE_ABORT_DOWNLOADING 8
Expand Down

0 comments on commit c7aa3da

Please sign in to comment.