Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCPI limit fix for for voltage/current/power #201

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions eez_psu_sketch/scpi_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,22 +427,21 @@ bool get_power_limit_param(scpi_t *context, float &value, const Channel *channel
}

bool get_voltage_limit_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv) {
if (context==NULL || channel==NULL) {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
if (param.special) {
if (channel) {
if (param.tag == SCPI_NUM_MAX) {
value = channel_dispatcher::getUMaxLimit(*channel);
}
else if (param.tag == SCPI_NUM_MIN) {
value = channel_dispatcher::getUMin(*channel);
}
else if (param.tag == SCPI_NUM_DEF) {
value = channel_dispatcher::getUMaxLimit(*channel);
}
else {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
} else {
if (param.tag == SCPI_NUM_MAX) {
value = channel_dispatcher::getUMaxLimit(*channel);
}
else if (param.tag == SCPI_NUM_MIN) {
value = channel_dispatcher::getUMin(*channel);
}
else if (param.tag == SCPI_NUM_DEF) {
value = channel_dispatcher::getUMaxLimit(*channel);
}
else {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
Expand All @@ -455,28 +454,33 @@ bool get_voltage_limit_from_param(scpi_t *context, const scpi_number_t &param, f

value = (float)param.value;

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

return true;
}

bool get_current_limit_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv) {
if (context==NULL || channel==NULL) {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
if (param.special) {
if (param.tag == SCPI_NUM_MAX) {
value = channel_dispatcher::getIMaxLimit(*channel);
}
else if (param.tag == SCPI_NUM_MIN) {
value = channel_dispatcher::getIMax(*channel);
value = channel_dispatcher::getIMin(*channel);
}
else if (param.tag == SCPI_NUM_DEF) {
value = channel_dispatcher::getIMaxLimit(*channel);
}
} else {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
}
else {
if (param.unit != SCPI_UNIT_NONE && param.unit != SCPI_UNIT_AMPER) {
Expand All @@ -485,6 +489,7 @@ bool get_current_limit_from_param(scpi_t *context, const scpi_number_t &param, f
}

value = (float)param.value;

if (value < channel_dispatcher::getIMin(*channel) || value > channel_dispatcher::getIMaxLimit(*channel)) {
SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE);
return false;
Expand All @@ -495,6 +500,10 @@ bool get_current_limit_from_param(scpi_t *context, const scpi_number_t &param, f
}

bool get_power_limit_from_param(scpi_t *context, const scpi_number_t &param, float &value, const Channel *channel, const Channel::Value *cv) {
if (context==NULL || channel==NULL) {
SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
return false;
}
if (param.special) {
if (param.tag == SCPI_NUM_MAX) {
value = channel_dispatcher::getPowerMaxLimit(*channel);
Expand All @@ -507,12 +516,13 @@ bool get_power_limit_from_param(scpi_t *context, const scpi_number_t &param, flo
}
}
else {
if (param.unit != SCPI_UNIT_NONE) {
if (param.unit != SCPI_UNIT_NONE && param.unit != SCPI_UNIT_WATT) {
SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SUFFIX);
return false;
}

value = (float)param.value;

if (value < channel_dispatcher::getPowerMinLimit(*channel) || value > channel_dispatcher::getPowerMaxLimit(*channel)) {
SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE);
return false;
Expand Down