Skip to content
Snippets Groups Projects
Commit 1796e5fa authored by Marco Filho's avatar Marco Filho
Browse files

Improve status checking

Now if API returns a bad status, asyn knows about it.
parent b959f593
1 merge request!7Major refactor
...@@ -29,6 +29,7 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) { ...@@ -29,6 +29,7 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) {
int tmp_val; int tmp_val;
bool tmp_val_bool; bool tmp_val_bool;
uint8_t tmp_val_uint8; uint8_t tmp_val_uint8;
vmmStatus result = vmmSuccess;
int param_index = 0, hyb_index, vmm_index; int param_index = 0, hyb_index, vmm_index;
if (function < FIRST_VMM_PARAM) { if (function < FIRST_VMM_PARAM) {
...@@ -36,16 +37,14 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) { ...@@ -36,16 +37,14 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) {
} }
if (function == vmmRegBankVersion) { if (function == vmmRegBankVersion) {
vmmStatus result = this->pVmmAPI->getRegBankVersion(val); result = this->pVmmAPI->getRegBankVersion(val);
if (result != vmmSuccess) status = asynError;
*value = val; *value = val;
goto endOfReadInt32; goto endOfReadInt32;
} }
if (function == vmmIsAcquiring_) { if (function == vmmIsAcquiring_) {
vmmStatus result = this->pVmmAPI->isAcquiring(tmp_val_bool); result = this->pVmmAPI->isAcquiring(tmp_val_bool);
printf("Is acquiring: %d\n", tmp_val_bool); printf("Is acquiring: %d\n", tmp_val_bool);
if (result != vmmSuccess) status = asynError;
*value = tmp_val_bool; *value = tmp_val_bool;
goto endOfReadInt32; goto endOfReadInt32;
} }
...@@ -53,42 +52,42 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) { ...@@ -53,42 +52,42 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) {
//Search for parameter in all parameter vectors. If found, execute correct function for specific hybrid. //Search for parameter in all parameter vectors. If found, execute correct function for specific hybrid.
param_index = VecUtils::getIndex(vmmHybSkew_, function); param_index = VecUtils::getIndex(vmmHybSkew_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->getSkew(param_index, tmp_val_uint8); result = this->pVmmAPI->getSkew(param_index, tmp_val_uint8);
*value = tmp_val_uint8; *value = tmp_val_uint8;
goto endOfReadInt32; goto endOfReadInt32;
} }
param_index = VecUtils::getIndex(vmmHybLinkStatus_, function); param_index = VecUtils::getIndex(vmmHybLinkStatus_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->checkLinkStatus(param_index, tmp_val); result = this->pVmmAPI->checkLinkStatus(param_index, tmp_val);
*value = tmp_val; *value = tmp_val;
goto endOfReadInt32; goto endOfReadInt32;
} }
param_index = VecUtils::getIndex(vmmHybWidth_, function); param_index = VecUtils::getIndex(vmmHybWidth_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->getWidth(param_index, tmp_val_uint8); result = this->pVmmAPI->getWidth(param_index, tmp_val_uint8);
*value = tmp_val_uint8; *value = tmp_val_uint8;
goto endOfReadInt32; goto endOfReadInt32;
} }
param_index = VecUtils::getIndex(vmmHybPolarity_, function); param_index = VecUtils::getIndex(vmmHybPolarity_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->getHybPolarity(param_index, tmp_val_bool); result = this->pVmmAPI->getHybPolarity(param_index, tmp_val_bool);
*value = tmp_val_bool; *value = tmp_val_bool;
goto endOfReadInt32; goto endOfReadInt32;
} }
param_index = VecUtils::getIndex(vmmADCIDX_, function, hyb_index, vmm_index); param_index = VecUtils::getIndex(vmmADCIDX_, function, hyb_index, vmm_index);
if (param_index == 0) { if (param_index == 0) {
this->pVmmAPI->getADCIdx(hyb_index, vmm_index, tmp_val); result = this->pVmmAPI->getADCIdx(hyb_index, vmm_index, tmp_val);
*value = tmp_val; *value = tmp_val;
goto endOfReadInt32; goto endOfReadInt32;
} }
param_index = VecUtils::getIndex(vmmADCVAL_, function, hyb_index, vmm_index); param_index = VecUtils::getIndex(vmmADCVAL_, function, hyb_index, vmm_index);
if (param_index == 0) { if (param_index == 0) {
this->pVmmAPI->readADC(hyb_index, vmm_index, tmp_val); result = this->pVmmAPI->readADC(hyb_index, vmm_index, tmp_val);
*value = tmp_val; *value = tmp_val;
goto endOfReadInt32; goto endOfReadInt32;
} }
...@@ -101,11 +100,17 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) { ...@@ -101,11 +100,17 @@ asynStatus VMMTbl::readInt32(asynUser *pasynUser, epicsInt32 *value) {
*value = 0; *value = 0;
return asynError; return asynError;
} }
if (result != vmmSuccess) {
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
"%s:%s: Failed to adequately read parameter: %d.\n",
driverName, __FUNCTION__, function);
status = asynError;
}
setIntegerParam(function, *value); setIntegerParam(function, *value);
callParamCallbacks(); callParamCallbacks();
return asynSuccess; return status;
} }
...@@ -114,33 +119,32 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value, ...@@ -114,33 +119,32 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value,
int *eomReason) int *eomReason)
{ {
int status = asynSuccess; asynStatus status = asynSuccess;
vmmStatus result;
int function = pasynUser->reason; int function = pasynUser->reason;
std::string read = ""; std::string read = "";
/* If this parameter belongs to a base class call its method */ /* If this parameter belongs to a base class call its method */
if (function < FIRST_VMM_PARAM) { if (function < FIRST_VMM_PARAM) {
status = asynPortDriver::readOctet(pasynUser, value, nChars, nActual, return asynPortDriver::readOctet(pasynUser, value, nChars, nActual, eomReason);
eomReason);
return (asynStatus)status;
} }
//Search for parameter in all parameter vectors. If found, execute correct function for specific hybrid. //Search for parameter in all parameter vectors. If found, execute correct function for specific hybrid.
int param_index = VecUtils::getIndex(vmmHybFwVersion_, function); int param_index = VecUtils::getIndex(vmmHybFwVersion_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->readFwVersion(param_index, read); result = this->pVmmAPI->readFwVersion(param_index, read);
goto endOfReadOctet; goto endOfReadOctet;
} }
param_index = VecUtils::getIndex(vmmHybId_, function); param_index = VecUtils::getIndex(vmmHybId_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->readIDChip(param_index, read); result = this->pVmmAPI->readIDChip(param_index, read);
goto endOfReadOctet; goto endOfReadOctet;
} }
param_index = VecUtils::getIndex(vmmHybGeoPos_, function); param_index = VecUtils::getIndex(vmmHybGeoPos_, function);
if (param_index >= 0) { if (param_index >= 0) {
this->pVmmAPI->readGeoPos(param_index, read); result = this->pVmmAPI->readGeoPos(param_index, read);
goto endOfReadOctet; goto endOfReadOctet;
} }
...@@ -150,6 +154,12 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value, ...@@ -150,6 +154,12 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value,
*nActual = 1; *nActual = 1;
return asynError; return asynError;
} }
if (result != vmmSuccess) {
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
"%s:%s: Failed to adequately read parameter: %d.\n",
driverName, __FUNCTION__, function);
status = asynError;
}
size_t copy_size = std::min(read.size(), nChars); size_t copy_size = std::min(read.size(), nChars);
strncpy(value, read.c_str(), copy_size); strncpy(value, read.c_str(), copy_size);
setStringParam(function, value); setStringParam(function, value);
...@@ -158,7 +168,7 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value, ...@@ -158,7 +168,7 @@ asynStatus VMMTbl::readOctet(asynUser *pasynUser, char *value,
*eomReason = ASYN_EOM_END; *eomReason = ASYN_EOM_END;
callParamCallbacks(); callParamCallbacks();
return asynSuccess; return status;
} }
...@@ -266,7 +276,7 @@ asynStatus VMMTbl::createEpicsParams() { ...@@ -266,7 +276,7 @@ asynStatus VMMTbl::createEpicsParams() {
asynStatus VMMTbl::writeInt32(asynUser *pasynUser, epicsInt32 value) { asynStatus VMMTbl::writeInt32(asynUser *pasynUser, epicsInt32 value) {
asynStatus status = asynSuccess; asynStatus status = asynSuccess;
vmmStatus vmm_stat; vmmStatus vmm_stat = vmmSuccess;
bool is_acquiring; bool is_acquiring;
int function = pasynUser->reason; int function = pasynUser->reason;
int param_index = 0, hyb_index, vmm_index; int param_index = 0, hyb_index, vmm_index;
...@@ -293,28 +303,24 @@ asynStatus VMMTbl::writeInt32(asynUser *pasynUser, epicsInt32 value) { ...@@ -293,28 +303,24 @@ asynStatus VMMTbl::writeInt32(asynUser *pasynUser, epicsInt32 value) {
param_index = VecUtils::getIndex(vmmHybSkew_, function); param_index = VecUtils::getIndex(vmmHybSkew_, function);
if (param_index >= 0) { if (param_index >= 0) {
vmm_stat = this->pVmmAPI->setSkew(param_index, value); vmm_stat = this->pVmmAPI->setSkew(param_index, value);
if (vmm_stat != vmmSuccess) status = asynError;
goto endOfWriteInt32; goto endOfWriteInt32;
} }
param_index = VecUtils::getIndex(vmmHybWidth_, function); param_index = VecUtils::getIndex(vmmHybWidth_, function);
if (param_index >= 0) { if (param_index >= 0) {
vmm_stat = this->pVmmAPI->setWidth(param_index, value); vmm_stat = this->pVmmAPI->setWidth(param_index, value);
if (vmm_stat != vmmSuccess) status = asynError;
goto endOfWriteInt32; goto endOfWriteInt32;
} }
param_index = VecUtils::getIndex(vmmHybPolarity_, function); param_index = VecUtils::getIndex(vmmHybPolarity_, function);
if (param_index >= 0) { if (param_index >= 0) {
vmm_stat = this->pVmmAPI->setHybPolarity(param_index, value); vmm_stat = this->pVmmAPI->setHybPolarity(param_index, value);
if (vmm_stat != vmmSuccess) status = asynError;
goto endOfWriteInt32; goto endOfWriteInt32;
} }
param_index = VecUtils::getIndex(vmmADCIDX_, function, hyb_index, vmm_index); param_index = VecUtils::getIndex(vmmADCIDX_, function, hyb_index, vmm_index);
if (param_index == 0) { if (param_index == 0) {
vmm_stat = this->pVmmAPI->setADCIdx(hyb_index, vmm_index, value); vmm_stat = this->pVmmAPI->setADCIdx(hyb_index, vmm_index, value);
if (vmm_stat != vmmSuccess) status = asynError;
goto endOfWriteInt32; goto endOfWriteInt32;
} }
...@@ -322,6 +328,7 @@ asynStatus VMMTbl::writeInt32(asynUser *pasynUser, epicsInt32 value) { ...@@ -322,6 +328,7 @@ asynStatus VMMTbl::writeInt32(asynUser *pasynUser, epicsInt32 value) {
if (param_index < 0) { if (param_index < 0) {
status = asynError; status = asynError;
} }
if (vmm_stat != vmmSuccess) status = asynError;
setIntegerParam(function, value); setIntegerParam(function, value);
callParamCallbacks(); callParamCallbacks();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment