Skip to content

Commit

Permalink
#46
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 18, 2020
1 parent cd10081 commit 2bd2602
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 106 deletions.
50 changes: 34 additions & 16 deletions src/eez/modules/psu/channel_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ float getUSet(const Channel &channel) {
return channel.u.set;
}

float getUSet(const Channel *channel, int slotIndex, int subchannelIndex) {
float getUSet(int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return getUSet(*channel);
}
Expand Down Expand Up @@ -512,13 +513,31 @@ float getUMin(const Channel &channel) {
return channel.u.min;
}

float getUMin(int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return getUMin(*channel);
}

return getVoltageMinValue(slotIndex, subchannelIndex);
}

float getUDef(const Channel &channel) {
if (channel.channelIndex < 2 && g_couplingType == COUPLING_TYPE_SERIES) {
return Channel::get(0).u.def + Channel::get(1).u.def;
}
return channel.u.def;
}

float getUDef(int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return getUDef(*channel);
}

return getVoltageMinValue(slotIndex, subchannelIndex);
}

float getUMax(const Channel &channel) {
if (channel.channelIndex < 2 && g_couplingType == COUPLING_TYPE_SERIES) {
return 2 * MIN(Channel::get(0).u.max, Channel::get(1).u.max);
Expand All @@ -539,7 +558,8 @@ float getUMax(const Channel &channel) {
return channel.u.max;
}

float getUMax(const Channel *channel, int slotIndex, int subchannelIndex) {
float getUMax(int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return getUMax(*channel);
}
Expand Down Expand Up @@ -764,7 +784,8 @@ float getISet(const Channel &channel) {
return channel.i.set;
}

float getISet(const Channel *channel, int slotIndex, int subchannelIndex) {
float getISet(int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return getISet(*channel);
}
Expand Down Expand Up @@ -829,7 +850,8 @@ float getIMaxLimit(const Channel &channel) {
return channel.getMaxCurrentLimit();
}

float getIMaxLimit(const Channel *channel, int slotIndex, int subchannelIndex) {
float getIMaxLimit(int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return getIMaxLimit(*channel);
}
Expand Down Expand Up @@ -2140,7 +2162,8 @@ bool setVoltage(int slotIndex, int subchannelIndex, float value, int *err) {
return g_slots[slotIndex]->setVoltage(subchannelIndex, value, err);
}

void getVoltageStepValues(Channel *channel, int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode) {
void getVoltageStepValues(int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
channel->getVoltageStepValues(stepValues, calibrationMode);
} else {
Expand All @@ -2149,14 +2172,11 @@ void getVoltageStepValues(Channel *channel, int slotIndex, int subchannelIndex,
}

float getVoltageResolution(int slotIndex, int subchannelIndex) {
return g_slots[slotIndex]->getVoltageResolution(subchannelIndex);
}

float getVoltageResolution(Channel *channel, int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return channel->getVoltageResolution();
} else {
return getVoltageResolution(slotIndex, subchannelIndex);
return g_slots[slotIndex]->getVoltageResolution(subchannelIndex);
}
}

Expand All @@ -2176,7 +2196,8 @@ bool setCurrent(int slotIndex, int subchannelIndex, float value, int *err) {
return g_slots[slotIndex]->setCurrent(subchannelIndex, value, err);
}

void getCurrentStepValues(Channel *channel, int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode) {
void getCurrentStepValues(int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
channel->getCurrentStepValues(stepValues, calibrationMode);
} else {
Expand All @@ -2185,14 +2206,11 @@ void getCurrentStepValues(Channel *channel, int slotIndex, int subchannelIndex,
}

float getCurrentResolution(int slotIndex, int subchannelIndex) {
return g_slots[slotIndex]->getCurrentResolution(subchannelIndex);
}

float getCurrentResolution(Channel *channel, int slotIndex, int subchannelIndex) {
Channel *channel = Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (channel) {
return channel->getCurrentResolution();
} else {
return getCurrentResolution(slotIndex, subchannelIndex);
return g_slots[slotIndex]->getCurrentResolution(subchannelIndex);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/eez/modules/psu/channel_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ float getValuePrecision(const Channel &channel, Unit unit, float value);
float roundChannelValue(const Channel &channel, Unit unit, float value);

float getUSet(const Channel &channel);
float getUSet(const Channel *channel, int slotIndex, int subchannelIndex);
float getUSet(int slotIndex, int subchannelIndex);
float getUSetUnbalanced(const Channel &channel);
float getUMon(const Channel &channel);
float getUMonLast(const Channel &channel);
Expand All @@ -57,9 +57,11 @@ float getUMonDacLast(const Channel &channel);
float getULimit(const Channel &channel);
float getUMaxLimit(const Channel &channel);
float getUMin(const Channel &channel);
float getUMin(int slotIndex, int subchannelIndex);
float getUDef(const Channel &channel);
float getUDef(int slotIndex, int subchannelIndex);
float getUMax(const Channel &channel);
float getUMax(const Channel *channel, int slotIndex, int subchannelIndex);
float getUMax(int slotIndex, int subchannelIndex);
float getUMaxOvpLimit(const Channel &channel);
float getUMaxOvpLevel(const Channel &channel);
float getUProtectionLevel(const Channel &channel);
Expand All @@ -73,14 +75,14 @@ void setOvpLevel(Channel &channel, float level);
void setOvpDelay(Channel &channel, float delay);

float getISet(const Channel &channel);
float getISet(const Channel *channel, int slotIndex, int subchannelIndex);
float getISet(int slotIndex, int subchannelIndex);
float getISetUnbalanced(const Channel &channel);
float getIMon(const Channel &channel);
float getIMonLast(const Channel &channel);
float getIMonDac(const Channel &channel);
float getILimit(const Channel &channel);
float getIMaxLimit(const Channel &channel);
float getIMaxLimit(const Channel *channel, int slotIndex, int subchannelIndex);
float getIMaxLimit(int slotIndex, int subchannelIndex);
float getIMin(const Channel &channel);
float getIDef(const Channel &channel);
float getIMax(const Channel &channel);
Expand Down Expand Up @@ -196,17 +198,15 @@ bool routeClose(ChannelList channelList, int *err);

bool getVoltage(int slotIndex, int subchannelIndex, float &value, int *err);
bool setVoltage(int slotIndex, int subchannelIndex, float value, int *err);
void getVoltageStepValues(Channel *channel, int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode);
void getVoltageStepValues(int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode);
float getVoltageResolution(int slotIndex, int subchannelIndex);
float getVoltageResolution(Channel *channel, int slotIndex, int subchannelIndex);
float getVoltageMinValue(int slotIndex, int subchannelIndex);
float getVoltageMaxValue(int slotIndex, int subchannelIndex);

bool getCurrent(int slotIndex, int subchannelIndex, float &value, int *err);
bool setCurrent(int slotIndex, int subchannelIndex, float value, int *err);
void getCurrentStepValues(Channel *channel, int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode);
void getCurrentStepValues(int slotIndex, int subchannelIndex, StepValues *stepValues, bool calibrationMode);
float getCurrentResolution(int slotIndex, int subchannelIndex);
float getCurrentResolution(Channel *channel, int slotIndex, int subchannelIndex);
float getCurrentMinValue(int slotIndex, int subchannelIndex);
float getCurrentMaxValue(int slotIndex, int subchannelIndex);

Expand Down
20 changes: 10 additions & 10 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,9 +2163,9 @@ void data_calibration_point_set_value(DataOperationEnum operation, Cursor cursor
data_keypad_text(operation, cursor, value);
} else {
if (editPage->getCalibrationValueType() == CALIBRATION_VALUE_U) {
value = MakeValue(channel_dispatcher::getUSet(channel, slotIndex, subchannelIndex), UNIT_VOLT);
value = MakeValue(channel_dispatcher::getUSet(slotIndex, subchannelIndex), UNIT_VOLT);
} else {
value = MakeValue(channel_dispatcher::getISet(channel, slotIndex, subchannelIndex), UNIT_AMPER);
value = MakeValue(channel_dispatcher::getISet(slotIndex, subchannelIndex), UNIT_AMPER);
}
}
} else if (operation == DATA_OPERATION_GET_MIN) {
Expand All @@ -2176,9 +2176,9 @@ void data_calibration_point_set_value(DataOperationEnum operation, Cursor cursor
}
} else if (operation == DATA_OPERATION_GET_MAX) {
if (editPage->getCalibrationValueType() == CALIBRATION_VALUE_U) {
value = MakeValue(channel_dispatcher::getUMax(channel, slotIndex, subchannelIndex), UNIT_VOLT);
value = MakeValue(channel_dispatcher::getUMax(slotIndex, subchannelIndex), UNIT_VOLT);
} else {
value = MakeValue(channel_dispatcher::getIMaxLimit(channel, slotIndex, subchannelIndex), UNIT_AMPER);
value = MakeValue(channel_dispatcher::getIMaxLimit(slotIndex, subchannelIndex), UNIT_AMPER);
}
} else if (operation == DATA_OPERATION_GET_NAME) {
value = editPage->getCalibrationValueType() == CALIBRATION_VALUE_U ? "Voltage" : "Current";
Expand All @@ -2188,15 +2188,15 @@ void data_calibration_point_set_value(DataOperationEnum operation, Cursor cursor
value = channel ? 1 : 0;
} else if (operation == DATA_OPERATION_GET_ENCODER_STEP_VALUES) {
if (editPage->getCalibrationValueType() == CALIBRATION_VALUE_U) {
channel_dispatcher::getVoltageStepValues(channel, slotIndex, subchannelIndex, value.getStepValues(), true);
channel_dispatcher::getVoltageStepValues(slotIndex, subchannelIndex, value.getStepValues(), true);
} else {
channel_dispatcher::getCurrentStepValues(channel, slotIndex, subchannelIndex, value.getStepValues(), true);
channel_dispatcher::getCurrentStepValues(slotIndex, subchannelIndex, value.getStepValues(), true);
}
} else if (operation == DATA_OPERATION_GET_ENCODER_PRECISION) {
if (editPage->getCalibrationValueType() == CALIBRATION_VALUE_U) {
value = MakeValue(channel_dispatcher::getVoltageResolution(channel, slotIndex, subchannelIndex) / 10, UNIT_VOLT);
value = MakeValue(channel_dispatcher::getVoltageResolution(slotIndex, subchannelIndex) / 10, UNIT_VOLT);
} else {
value = MakeValue(channel_dispatcher::getCurrentResolution(channel, slotIndex, subchannelIndex) / 10, UNIT_AMPER);
value = MakeValue(channel_dispatcher::getCurrentResolution(slotIndex, subchannelIndex) / 10, UNIT_AMPER);
}
} else if (operation == DATA_OPERATION_SET) {
editPage->setDacValue(value.getFloat());
Expand Down Expand Up @@ -2233,9 +2233,9 @@ void data_calibration_point_measured_value(DataOperationEnum operation, Cursor c
}
} else if (operation == DATA_OPERATION_GET_MAX) {
if (editPage->getCalibrationValueType() == CALIBRATION_VALUE_U) {
value = MakeValue(channel_dispatcher::getUMax(channel, slotIndex, subchannelIndex) + 1.0f, UNIT_VOLT);
value = MakeValue(channel_dispatcher::getUMax(slotIndex, subchannelIndex) + 1.0f, UNIT_VOLT);
} else {
value = MakeValue(channel_dispatcher::getIMaxLimit(channel, slotIndex, subchannelIndex) + 0.5f, UNIT_AMPER);
value = MakeValue(channel_dispatcher::getIMaxLimit(slotIndex, subchannelIndex) + 0.5f, UNIT_AMPER);
}
} else if (operation == DATA_OPERATION_GET_NAME) {
value = editPage->getCalibrationValueType() == CALIBRATION_VALUE_U ? "Voltage" : "Current";
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/scpi/outp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ scpi_result_t scpi_cmd_outputDelayDurationQ(scpi_t *context) {
return SCPI_RES_ERR;
}

return get_source_value(context, *channel, UNIT_SECOND, channel->outputDelayDuration, OUTPUT_DELAY_DURATION_MIN_VALUE, OUTPUT_DELAY_DURATION_MAX_VALUE, OUTPUT_DELAY_DURATION_DEF_VALUE);
return get_source_value(context, UNIT_SECOND, channel->outputDelayDuration, OUTPUT_DELAY_DURATION_MIN_VALUE, OUTPUT_DELAY_DURATION_MAX_VALUE, OUTPUT_DELAY_DURATION_DEF_VALUE);
}

} // namespace scpi
Expand Down
59 changes: 30 additions & 29 deletions src/eez/modules/psu/scpi/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,17 @@ bool get_voltage_param(scpi_t *context, float &value, const Channel *channel,
return false;
}

return get_voltage_from_param(context, param, value, channel, cv);
return get_voltage_from_param(context, param, value, channel->slotIndex, channel->subchannelIndex, cv);
}

bool get_voltage_param(scpi_t *context, float &value, int slotIndex, int subchannelIndex,
const Channel::Value *cv) {
scpi_number_t param;
if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &param, true)) {
return false;
}

return get_voltage_from_param(context, param, value, slotIndex, subchannelIndex, cv);
}

bool get_voltage_protection_level_param(scpi_t *context, float &value, float min, float max,
Expand Down Expand Up @@ -435,28 +445,22 @@ bool get_duration_param(scpi_t *context, float &value, float min, float max, flo
return get_duration_from_param(context, param, value, min, max, def);
}

bool get_voltage_from_param(scpi_t *context, const scpi_number_t &param, float &value,
const Channel *channel, const Channel::Value *cv) {
bool get_voltage_from_param(scpi_t *context, const scpi_number_t &param, float &value, int slotIndex, int subchannelIndex, const Channel::Value *cv) {
if (param.special) {
if (channel) {
if (param.content.tag == SCPI_NUM_MAX) {
value = channel_dispatcher::getUMax(*channel);
} else if (param.content.tag == SCPI_NUM_MIN) {
value = channel_dispatcher::getUMin(*channel);
} else if (param.content.tag == SCPI_NUM_DEF) {
value = channel_dispatcher::getUDef(*channel);
} else if (param.content.tag == SCPI_NUM_UP && cv) {
value = cv->set + cv->step;
if (value > channel_dispatcher::getUMax(*channel))
value = channel_dispatcher::getUMax(*channel);
} else if (param.content.tag == SCPI_NUM_DOWN && cv) {
value = cv->set - cv->step;
if (value < channel_dispatcher::getUMin(*channel))
value = channel_dispatcher::getUMin(*channel);
} else {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
if (param.content.tag == SCPI_NUM_MAX) {
value = channel_dispatcher::getUMax(slotIndex, subchannelIndex);
} else if (param.content.tag == SCPI_NUM_MIN) {
value = channel_dispatcher::getUMin(slotIndex, subchannelIndex);
} else if (param.content.tag == SCPI_NUM_DEF) {
value = channel_dispatcher::getUDef(slotIndex, subchannelIndex);
} else if (param.content.tag == SCPI_NUM_UP && cv) {
value = cv->set + cv->step;
if (value > channel_dispatcher::getUMax(slotIndex, subchannelIndex))
value = channel_dispatcher::getUMax(slotIndex, subchannelIndex);
} else if (param.content.tag == SCPI_NUM_DOWN && cv) {
value = cv->set - cv->step;
if (value < channel_dispatcher::getUMin(slotIndex, subchannelIndex))
value = channel_dispatcher::getUMin(slotIndex, subchannelIndex);
} else {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
Expand All @@ -469,12 +473,9 @@ bool get_voltage_from_param(scpi_t *context, const scpi_number_t &param, float &

value = (float)param.content.value;

if (channel) {
if (value < channel_dispatcher::getUMin(*channel) ||
value > channel_dispatcher::getUMax(*channel)) {
SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE);
return false;
}
if (value < channel_dispatcher::getUMin(slotIndex, subchannelIndex) || value > channel_dispatcher::getUMax(slotIndex, subchannelIndex)) {
SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE);
return false;
}
}

Expand Down Expand Up @@ -765,7 +766,7 @@ bool get_power_limit_from_param(scpi_t *context, const scpi_number_t &param, flo
return true;
}

scpi_result_t result_float(scpi_t *context, Channel *channel, float value, Unit unit) {
scpi_result_t result_float(scpi_t *context, float value, Unit unit) {
char buffer[32] = { 0 };
strcatFloat(buffer, value);
SCPI_ResultCharacters(context, buffer, strlen(buffer));
Expand Down
7 changes: 4 additions & 3 deletions src/eez/modules/psu/scpi/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ bool checkPowerChannel(scpi_t *context, int channelIndex);
bool param_temp_sensor(scpi_t *context, int32_t &sensor);

bool get_voltage_param(scpi_t *context, float &value, const Channel *channel, const Channel::Value *cv);
bool get_voltage_param(scpi_t *context, float &value, int slotIndex, int subchannelIndex, const Channel::Value *cv);
bool get_voltage_protection_level_param(scpi_t *context, float &value, float min, float max, float def);
bool get_current_param(scpi_t *context, float &value, const Channel *channel, const Channel::Value *cv);
bool get_power_param(scpi_t *context, float &value, float min, float max, float def);
bool get_temperature_param(scpi_t *context, float &value, float min, float max, float def);
bool get_duration_param(scpi_t *context, float &value, float min, float max, float def);

bool get_voltage_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv);
bool get_voltage_from_param(scpi_t *context, const scpi_number_t &param, float &value, int slotIndex, int subchannelIndex, const Channel::Value *cv);
bool get_voltage_protection_level_from_param(scpi_t *context, const scpi_number_t &param, float &value, float min, float max, float def);
bool get_current_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv);
bool get_power_from_param(scpi_t *context, const scpi_number_t &param, float &value, float min, float max, float def);
Expand All @@ -64,9 +65,9 @@ bool get_voltage_limit_from_param(scpi_t *context, const scpi_number_t &param, f
bool get_current_limit_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv);
bool get_power_limit_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv);

scpi_result_t get_source_value(scpi_t *context, Channel &channel, Unit unit, float value, float min, float max, float def);
scpi_result_t get_source_value(scpi_t *context, Unit unit, float value, float min, float max, float def);

scpi_result_t result_float(scpi_t *context, Channel *channel, float value, Unit unit);
scpi_result_t result_float(scpi_t *context, float value, Unit unit);
bool get_profile_location_param(scpi_t *context, int &location, bool all_locations = false);

void outputOnTime(scpi_t* context, uint32_t time);
Expand Down
Loading

0 comments on commit 2bd2602

Please sign in to comment.