Skip to content

Commit

Permalink
udriver: add generic writeFloat64 function.
Browse files Browse the repository at this point in the history
And add the specific implementation of the function to the relevant
modules.
  • Loading branch information
ericonr committed Mar 25, 2024
1 parent 1778f5e commit 87b7ea9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
6 changes: 2 additions & 4 deletions utcaApp/src/acq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,14 @@ class Acq: public UDriver {
return asynSuccess;
}

asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
asynStatus writeFloat64Impl(asynUser *, const int function, const int, epicsFloat64 value)
{
const int function = pasynUser->reason;

if (parameters_to_store.count(function)) {
setDoubleParam(function, value);
return asynSuccess;
}

return asynPortDriver::writeFloat64(pasynUser, value);
return asynError;
}
};

Expand Down
7 changes: 1 addition & 6 deletions utcaApp/src/afc_timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,8 @@ class AFCTiming: public UDriver {
return write_params(pasynUser, ctl);
}

asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
asynStatus writeFloat64Impl(asynUser *pasynUser, const int function, const int addr, epicsFloat64 value)
{
int function = pasynUser->reason, addr;
getAddress(pasynUser, &addr);

if (function == p_freq) {
bool rv;
if (addr == 0) rv = ctl.set_rtm_freq(value);
Expand All @@ -150,8 +147,6 @@ class AFCTiming: public UDriver {

setDoubleParam(addr, function, value);
callParamCallbacks(addr);
} else {
return asynPortDriver::writeFloat64(pasynUser, value);
}

return write_params(pasynUser, ctl);
Expand Down
11 changes: 2 additions & 9 deletions utcaApp/src/fofb_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,11 @@ class FofbProcessing: public UDriver {
return write_params(pasynUser, ctl);
}

asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
asynStatus writeFloat64Impl(asynUser *pasynUser, const int function, const int addr, epicsFloat64 value)
{
int function = pasynUser->reason, addr;
getAddress(pasynUser, &addr);

if (function == p_acc_gain) {
if (function == p_acc_gain)
ctl.parameters[addr].acc_gain = value;

} else {
return asynPortDriver::writeFloat64(pasynUser, value);
}

return write_params(pasynUser, ctl);
}

Expand Down
35 changes: 32 additions & 3 deletions utcaApp/src/udriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,17 @@ class UDriver: public asynPortDriver {
throw std::logic_error("this default implementation shouldn't be called");
}

asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value) override final
virtual asynStatus writeFloat64Impl(
[[maybe_unused]] asynUser *pasynUser,
[[maybe_unused]] const int function,
[[maybe_unused]] const int addr,
[[maybe_unused]] epicsFloat64 value)
{
throw std::logic_error("this default implementation shouldn't be called");
}

template <typename T>
asynStatus writeGeneral(asynUser *pasynUser, T value)
{
const int function = pasynUser->reason;
int addr;
Expand All @@ -262,13 +272,22 @@ class UDriver: public asynPortDriver {
getAddress(pasynUser, &addr);
getParamName(function, &param_name);

auto call_write_impl = [this, pasynUser, function, addr, value]() -> asynStatus {
if constexpr (std::is_same_v<T, epicsInt32>)
return writeInt32Impl(pasynUser, function, addr, value);
else if constexpr (std::is_same_v<T, epicsFloat64>)
return writeFloat64Impl(pasynUser, function, addr, value);
else
static_assert(!sizeof(T));
};

/* parameter we don't know about */
if ((unsigned)function >= parameter_props.size())
return call_write_impl();

if (parameter_props.at(function).is_general && addr != 0) {
epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
"writeInt32: %s: general parameter with addr=%d (should be 0)", param_name, addr);
"writeGeneral: %s: general parameter with addr=%d (should be 0)", param_name, addr);

return asynError;
}
Expand All @@ -284,8 +303,18 @@ class UDriver: public asynPortDriver {
fprintf(stderr, "bad decoder_controller write. param: %s. exception: %s\n", param_name, e.what());
}

return writeInt32Impl(pasynUser, function, addr, value);
/* parameters which aren't using generic_decoder_controller */
return call_write_impl();
}

asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value) override final
{
return writeGeneral(pasynUser, value);
}

asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value) override final
{
return writeGeneral(pasynUser, value);
}
};

Expand Down

0 comments on commit 87b7ea9

Please sign in to comment.