Skip to content

Commit

Permalink
#46 profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 17, 2020
1 parent 7682b96 commit 0eb36e6
Show file tree
Hide file tree
Showing 11 changed files with 407 additions and 137 deletions.
25 changes: 21 additions & 4 deletions src/eez/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ int Module::getSlotSettingsPageId() {
return PAGE_ID_SLOT_SETTINGS;
}

void Module::getProfileParameters(int channelIndex, uint8_t *buffer) {
void Module::getPowerChannelProfileParameters(int channelIndex, uint8_t *buffer) {
}

void Module::setProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels) {
void Module::setPowerChannelProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels) {
}

bool Module::writeProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer) {
bool Module::writePowerChannelProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer) {
return true;
}

bool Module::readProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer) {
bool Module::readPowerChannelProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer) {
return false;
}

Expand All @@ -153,6 +153,23 @@ float Module::getProfileISet(uint8_t *buffer) {
return NAN;
}

void Module::getProfileParameters(uint8_t *buffer) {
}

void Module::setProfileParameters(uint8_t *buffer, bool mismatch, int recallOptions) {
}

bool Module::writeProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer) {
return true;
}

bool Module::readProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer) {
return true;
}

void Module::resetConfiguration() {
}

int Module::getNumSubchannels() {
return numPowerChannels + numOtherChannels;
}
Expand Down
15 changes: 11 additions & 4 deletions src/eez/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,21 @@ struct Module {
virtual int getChannelSettingsPageId();
virtual int getSlotSettingsPageId();

virtual void getProfileParameters(int channelIndex, uint8_t *buffer);
virtual void setProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels);
virtual bool writeProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer);
virtual bool readProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer);
virtual void getPowerChannelProfileParameters(int channelIndex, uint8_t *buffer);
virtual void setPowerChannelProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels);
virtual bool writePowerChannelProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer);
virtual bool readPowerChannelProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer);
virtual bool getProfileOutputEnable(uint8_t *buffer);
virtual float getProfileUSet(uint8_t *buffer);
virtual float getProfileISet(uint8_t *buffer);

virtual void getProfileParameters(uint8_t *buffer);
virtual void setProfileParameters(uint8_t *buffer, bool mismatch, int recallOptions);
virtual bool writeProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer);
virtual bool readProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer);

virtual void resetConfiguration();

virtual int getNumSubchannels();
virtual bool isValidSubchannelIndex(int subchannelIndex);
virtual int getSubchannelIndexFromRelativeChannelIndex(int relativeChannelIndex);
Expand Down
36 changes: 18 additions & 18 deletions src/eez/modules/dib-dcm224/dib-dcm224.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,10 @@ struct DcmModule : public PsuModule {
bool counterphaseDithering;
};

void getProfileParameters(int channelIndex, uint8_t *buffer) override;
void setProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels) override;
bool writeProfileProperties(profile::WriteContext &ctx, const uint8_t *buffer) override;
bool readProfileProperties(profile::ReadContext &ctx, uint8_t *buffer) override;
void getPowerChannelProfileParameters(int channelIndex, uint8_t *buffer) override;
void setPowerChannelProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels) override;
bool writePowerChannelProfileProperties(profile::WriteContext &ctx, const uint8_t *buffer) override;
bool readPowerChannelProfileProperties(profile::ReadContext &ctx, uint8_t *buffer) override;
};

void DcmChannel::init() {
Expand Down Expand Up @@ -670,10 +670,10 @@ void DcmChannel::tickSpecific(uint32_t tickCount) {
#endif
}

void DcmModule::getProfileParameters(int channelIndex, uint8_t *buffer) {
void DcmModule::getPowerChannelProfileParameters(int channelIndex, uint8_t *buffer) {
assert(sizeof(DcmProfileParameters) < MAX_CHANNEL_PARAMETERS_SIZE);

PsuModule::getProfileParameters(channelIndex, buffer);
PsuModule::getPowerChannelProfileParameters(channelIndex, buffer);

auto &channel = (DcmChannel &)Channel::get(channelIndex);
auto parameters = (DcmProfileParameters *)buffer;
Expand All @@ -686,8 +686,8 @@ void DcmModule::getProfileParameters(int channelIndex, uint8_t *buffer) {
parameters->counterphaseDithering = counterphaseDithering;
}

void DcmModule::setProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels) {
PsuModule::setProfileParameters(channelIndex, buffer, mismatch, recallOptions, numTrackingChannels);
void DcmModule::setPowerChannelProfileParameters(int channelIndex, uint8_t *buffer, bool mismatch, int recallOptions, int &numTrackingChannels) {
PsuModule::setPowerChannelProfileParameters(channelIndex, buffer, mismatch, recallOptions, numTrackingChannels);

auto &channel = (DcmChannel &)Channel::get(channelIndex);
auto parameters = (DcmProfileParameters *)buffer;
Expand All @@ -704,8 +704,8 @@ void DcmModule::setProfileParameters(int channelIndex, uint8_t *buffer, bool mis
}
}

bool DcmModule::writeProfileProperties(profile::WriteContext &ctx, const uint8_t *buffer) {
if (!PsuModule::writeProfileProperties(ctx, buffer)) {
bool DcmModule::writePowerChannelProfileProperties(profile::WriteContext &ctx, const uint8_t *buffer) {
if (!PsuModule::writePowerChannelProfileProperties(ctx, buffer)) {
return false;
}

Expand All @@ -721,19 +721,19 @@ bool DcmModule::writeProfileProperties(profile::WriteContext &ctx, const uint8_t
return true;
}

bool DcmModule::readProfileProperties(profile::ReadContext &ctx, uint8_t *buffer) {
if (PsuModule::readProfileProperties(ctx, buffer)) {
bool DcmModule::readPowerChannelProfileProperties(profile::ReadContext &ctx, uint8_t *buffer) {
if (PsuModule::readPowerChannelProfileProperties(ctx, buffer)) {
return true;
}

auto parameters = (DcmProfileParameters *)buffer;

READ_PROPERTY(dcmVersion, parameters->dcmVersion);
READ_PROPERTY(pwmEnabled, parameters->pwmEnabled);
READ_PROPERTY(pwmFrequency, parameters->pwmFrequency);
READ_PROPERTY(pwmDuty, parameters->pwmDuty);
READ_PROPERTY(counterphaseFrequency, parameters->counterphaseFrequency);
READ_PROPERTY(counterphaseDithering, parameters->counterphaseDithering);
READ_PROPERTY("dcmVersion", parameters->dcmVersion);
READ_PROPERTY("pwmEnabled", parameters->pwmEnabled);
READ_PROPERTY("pwmFrequency", parameters->pwmFrequency);
READ_PROPERTY("pwmDuty", parameters->pwmDuty);
READ_PROPERTY("counterphaseFrequency", parameters->counterphaseFrequency);
READ_PROPERTY("counterphaseDithering", parameters->counterphaseDithering);

return false;
}
Expand Down
133 changes: 116 additions & 17 deletions src/eez/modules/dib-smx46/dib-smx46.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

Expand All @@ -33,6 +34,7 @@
#include "eez/gui/document.h"
#include <eez/modules/psu/timer.h>
#include "eez/modules/psu/psu.h"
#include "eez/modules/psu/profile.h"
#include "eez/modules/psu/event_queue.h"
#include "eez/modules/psu/calibration.h"
#include "eez/modules/psu/gui/psu.h"
Expand Down Expand Up @@ -94,7 +96,7 @@ struct Smx46Module : public Module {
uint32_t routes = 0;

char xLabels[NUM_COLUMNS][MAX_LABEL_LENGTH + 1];
char yLabels[NUM_COLUMNS][MAX_LABEL_LENGTH + 1];
char yLabels[NUM_ROWS][MAX_LABEL_LENGTH + 1];

float dac1 = 0.0f;
float dac2 = 0.0f;
Expand Down Expand Up @@ -127,17 +129,7 @@ struct Smx46Module : public Module {
numPowerChannels = 0;
numOtherChannels = 2 + 1 + NUM_ROWS * NUM_COLUMNS;

for (int i = 0; i < NUM_COLUMNS; i++) {
xLabels[i][0] = 'X';
xLabels[i][1] = '1' + i;
xLabels[i][2] = 0;
}

for (int i = 0; i < NUM_ROWS; i++) {
yLabels[i][0] = 'Y';
yLabels[i][1] = '1' + i;
yLabels[i][2] = 0;
}
resetConfiguration();

auto data = (FromMasterToSlave *)output;
data->routes = 0xFFFFFFFF;
Expand All @@ -152,6 +144,9 @@ struct Smx46Module : public Module {
Module::boot();

loadRelayCylces();

calibrationEnabled[0] = persist_conf::isChannelCalibrationEnabled(slotIndex, 0);
calibrationEnabled[1] = persist_conf::isChannelCalibrationEnabled(slotIndex, 1);
}

Module *createModule() override {
Expand Down Expand Up @@ -292,10 +287,116 @@ struct Smx46Module : public Module {
return PAGE_ID_DIB_SMX46_SLOT_VIEW_MICRO;
}

struct ProfileParameters {
uint32_t routes;
char xLabels[NUM_COLUMNS][MAX_LABEL_LENGTH + 1];
char yLabels[NUM_ROWS][MAX_LABEL_LENGTH + 1];
float dac1;
float dac2;
bool relayOn;
};

int getSlotSettingsPageId() override {
return getTestResult() == TEST_OK ? PAGE_ID_DIB_SMX46_SETTINGS : PAGE_ID_SLOT_SETTINGS;
}

void getProfileParameters(uint8_t *buffer) override {
assert(sizeof(ProfileParameters) < MAX_CHANNEL_PARAMETERS_SIZE);

auto parameters = (ProfileParameters *)buffer;

parameters->routes = routes;
memcpy(&parameters->xLabels[0][0], &xLabels[0][0], sizeof(xLabels));
memcpy(&parameters->yLabels[0][0], &yLabels[0][0], sizeof(yLabels));
parameters->dac1 = dac1;
parameters->dac2 = dac2;
parameters->relayOn = relayOn;
}

void setProfileParameters(uint8_t *buffer, bool mismatch, int recallOptions) override {
auto parameters = (ProfileParameters *)buffer;

routes = parameters->routes;
memcpy(&xLabels[0][0], &parameters->xLabels[0][0], sizeof(xLabels));
memcpy(&yLabels[0][0], &parameters->yLabels[0][0], sizeof(yLabels));
dac1 = parameters->dac1;
dac2 = parameters->dac2;
relayOn = parameters->relayOn;
}

bool writeProfileProperties(psu::profile::WriteContext &ctx, const uint8_t *buffer) override {
auto parameters = (const ProfileParameters *)buffer;

WRITE_PROPERTY("routes", (unsigned int)parameters->routes);

for (int i = 0; i < NUM_COLUMNS; i++) {
char propName[16];
sprintf(propName, "xLabel%d", i+1);
WRITE_PROPERTY(propName, parameters->xLabels[i]);
}

for (int i = 0; i < NUM_ROWS; i++) {
char propName[16];
sprintf(propName, "yLabel%d", i+1);
WRITE_PROPERTY(propName, parameters->yLabels[i]);
}

WRITE_PROPERTY("dac1", parameters->dac1);
WRITE_PROPERTY("dac2", parameters->dac2);

WRITE_PROPERTY("relayOn", parameters->relayOn);

return true;
}

bool readProfileProperties(psu::profile::ReadContext &ctx, uint8_t *buffer) override {
auto parameters = (ProfileParameters *)buffer;

unsigned int routes;
READ_PROPERTY("routes", routes);
parameters->routes = routes;

for (int i = 0; i < NUM_COLUMNS; i++) {
char propName[16];
sprintf(propName, "xLabel%d", i+1);
READ_STRING_PROPERTY(propName, parameters->xLabels[i], MAX_LABEL_LENGTH);
}

for (int i = 0; i < NUM_ROWS; i++) {
char propName[16];
sprintf(propName, "yLabel%d", i+1);
READ_STRING_PROPERTY(propName, parameters->yLabels[i], MAX_LABEL_LENGTH);
}

READ_PROPERTY("dac1", parameters->dac1);
READ_PROPERTY("dac2", parameters->dac2);

READ_PROPERTY("relayOn", parameters->relayOn);

return true;
}

void resetConfiguration() {
routes = 0;

for (int i = 0; i < NUM_COLUMNS; i++) {
xLabels[i][0] = 'X';
xLabels[i][1] = '1' + i;
xLabels[i][2] = 0;
}

for (int i = 0; i < NUM_ROWS; i++) {
yLabels[i][0] = 'Y';
yLabels[i][1] = '1' + i;
yLabels[i][2] = 0;
}

dac1 = 0.0f;
dac2 = 0.0f;

relayOn = false;
}

bool isValidSubchannelIndex(int subchannelIndex) override {
subchannelIndex++;
return subchannelIndex == 1 || subchannelIndex == 2 || subchannelIndex == 3 ||
Expand Down Expand Up @@ -498,9 +599,10 @@ struct Smx46Module : public Module {
return subchannelIndex < 2 && calibrationEnabled[subchannelIndex];
}

void enableVoltageCalibration(int subchannelIndex, bool enable) override {
void enableVoltageCalibration(int subchannelIndex, bool enabled) override {
if (subchannelIndex < 2) {
calibrationEnabled[subchannelIndex] = enable;
calibrationEnabled[subchannelIndex] = enabled;
persist_conf::saveCalibrationEnabledFlag(slotIndex, subchannelIndex, enabled);
}
}

Expand Down Expand Up @@ -771,7 +873,6 @@ void data_dib_smx46_relay_on(DataOperationEnum operation, Cursor cursor, Value &

void data_dib_smx46_signal_relay_cycles(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
int slotIndex = cursor / (NUM_COLUMNS * NUM_ROWS);
int i = cursor % (NUM_COLUMNS * NUM_ROWS);
int x = i % NUM_COLUMNS;
int y = i / NUM_COLUMNS;
Expand Down Expand Up @@ -814,7 +915,6 @@ void onSetLabel(char *value) {

void action_dib_smx46_edit_x_label() {
int cursor = getFoundWidgetAtDown().cursor;
int slotIndex = cursor / NUM_COLUMNS;
int i = cursor % NUM_COLUMNS;
ConfigureRoutesPage *page = (ConfigureRoutesPage *)getPage(PAGE_ID_DIB_SMX46_CONFIGURE_ROUTES);
g_labelPointer = &page->xLabels[i][0];
Expand All @@ -823,7 +923,6 @@ void action_dib_smx46_edit_x_label() {

void action_dib_smx46_edit_y_label() {
int cursor = getFoundWidgetAtDown().cursor;
int slotIndex = cursor / NUM_ROWS;
int i = cursor % NUM_ROWS;
ConfigureRoutesPage *page = (ConfigureRoutesPage *)getPage(PAGE_ID_DIB_SMX46_CONFIGURE_ROUTES);
g_labelPointer = &page->yLabels[i][0];
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ void Channel::updateAllChannels() {
for (int i = 0; i < CH_NUM; ++i) {
Channel &channel = Channel::get(i);
if (channel.isOk()) {
channel.doCalibrationEnable(persist_conf::isChannelCalibrationEnabled(channel) && channel.isCalibrationExists());
channel.doCalibrationEnable(persist_conf::isChannelCalibrationEnabled(channel.slotIndex, channel.subchannelIndex) && channel.isCalibrationExists());
channel.setVoltage(channel.u.set);
channel.setCurrent(channel.i.set);
}
Expand Down Expand Up @@ -1136,7 +1136,7 @@ void Channel::calibrationEnable(bool enabled) {
if (enabled != isCalibrationEnabled()) {
doCalibrationEnable(enabled);
event_queue::pushChannelEvent((enabled ? event_queue::EVENT_INFO_CH_CALIBRATION_ENABLED : event_queue::EVENT_WARNING_CH_CALIBRATION_DISABLED), channelIndex);
persist_conf::saveCalibrationEnabledFlag(*this, enabled);
persist_conf::saveCalibrationEnabledFlag(slotIndex, subchannelIndex, enabled);
}
}

Expand Down
Loading

0 comments on commit 0eb36e6

Please sign in to comment.