Index: sources/device/DeviceModels.cpp =================================================================== diff -u -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a -r472c10e72a8d278f13d2343f9c81c1def14490ff --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 472c10e72a8d278f13d2343f9c81c1def14490ff) @@ -127,7 +127,7 @@ count = deviceInfo.count(); if ( count ) { if ( count != LEN_COUNT) { - _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp; goto lError; // incorrect response, length + _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp_Len; goto lError; // incorrect response, length } } @@ -150,49 +150,6 @@ } /*! - * \brief MDeviceBrightnessRequest::setBrightnessSysVal - * \details checks for the requested brightness percentage (in range and resolution) - * \return returns device script error enum and is 0 on no error - */ -Device::DeviceError::Scripts_Error_Enum MDeviceBrightnessRequest::setBrightnessSysVal() -{ - // check range(min,max) - quint8 len = UI2HW.size(); - if ( ! len ) { - LOG_DEBUG("Empty UI2HW map"); - return Device::DeviceError::eDevice_Scripts_Error_Unknown; - } - quint8 min = UI2HW.begin() .key(); - quint8 max = (UI2HW.end () - 1).key(); - if ( ! ( min <= _data.mBrightnessPercent && _data.mBrightnessPercent <= max ) ) { - return Device::DeviceError::eDevice_Scripts_Error_OutOfRange; - } - - // check range(resolution) - if ( ! UI2HW.contains(_data.mBrightnessPercent) ) { - return Device::DeviceError::eDevice_Scripts_Error_Incorrect_Req; - } - - _data.mBrightness_val = UI2HW[_data.mBrightnessPercent]; - return Device::DeviceError::eDevice_OK; -} - -/*! - * \brief MDeviceBrightnessResponse::setBrightnessPercent - * \param vSysVal - updated the response with returned brightness system value - * \return returns device script error enum and is 0 on no error - */ -Device::DeviceError::Scripts_Error_Enum MDeviceBrightnessResponse::setBrightnessPercent(quint8 vSysVal) { - if ( ! HW2UI.contains( vSysVal ) ) { - return Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp; - } - - _data.mBrightnessPercent = HW2UI[ vSysVal ]; - return Device::DeviceError::eDevice_OK; -} - - -/*! * \brief MDeviceFactoryResetResponse::fromByteArray * \details Checks the response and sets up the model data. * \param vExitCode - Passed script exit code @@ -264,27 +221,39 @@ //DEBUG qDebug() << __FUNCTION__ << vByteArray; // initialize data + bool ok = false; int error = 0; _data.mCompleted = true; _data.mAccepted = false; + _data.mReason = Device::DeviceError::eDevice_OK; - // check if the vExitCode passed and it has a value other than zero - if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_WifiList_Error; error = *vExitCode; } - else _data.mReason = Device::DeviceError::eDevice_OK; + // set as default if the val is invalid. + _data.mWifiList = ""; - // if vExitCode is not zero go to error since the data is no longer valid - if ( _data.mReason ) goto lError; // non-zero Exit code + // get the value + QString val = vByteArray; + ok = ! val.isNull() && val.isSimpleText(); + // check if the vExitCode passed and it has a value other than zero + if ( ! ok ){ _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp_Type ; goto lError; } // there is not a valid value + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_WifiList_Error ; goto lApply; } // there still a valid value + // Now everything is good to extract the data _data.mAccepted = true; - _data.mWifiList = vByteArray; - _data.mMessage = QObject::tr("The Wifi list scan complete."); goto lOut ; // normal return + _data.mMessage = QObject::tr("The WiFi scan is complete."); goto lApply; // normal return + // apply returned value in case the passed value is valid (type, range) + // regardless of the exit code (success, fail) +lApply: + _data.mWifiList= val; + goto lOut; + + // immediate exit on fail exitcode and invalid returned value. lError: + if ( vExitCode ) error = *vExitCode; _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; lOut: - _data.mCompleted= true; return _data.mAccepted; } @@ -296,24 +265,104 @@ */ bool MDeviceUSBMountResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) { + //DEBUG qDebug() << __FUNCTION__ << vByteArray; + // initialize data - int error = 0; - _data.mAccepted = false; + bool ok = false; + int error = 0; + _data.mCompleted = true; // mark the data as final to be identified by the view. + _data.mAccepted = false; + _data.mReason = Device::DeviceError::eDevice_OK; + // set as default if the val is invalid (min=0). + // N/A + // get the value + ok = true; // check if the vExitCode passed and it has a value other than zero - if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_USBMount_Error; error = *vExitCode; } - else _data.mReason = Device::DeviceError::eDevice_OK; + if ( ! ok ){ _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp_Type ; goto lError ; } // there is not a valid value + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_USBMount_Error ; goto lRevert; } // there still a valid value - // if vExitCode is not zero go to error since the data is no longer valid - if ( _data.mReason ) goto lError; // non-zero Exit code + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mMessage = QObject::tr("The USB (un)mount is complete."); goto lOut ; // normal return + // apply returned value in case the passed value is valid (type, range) + // regardless of the exit code (success, fail) +lRevert: + // N/A + + // immediate exit on fail exitcode and invalid returned value. +lError: + if ( vExitCode ) error = *vExitCode; + _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; + +lOut: + return _data.mAccepted;} + +bool MDeviceBrightnessResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) +{ + //DEBUG qDebug() << __FUNCTION__ << vByteArray; + + // initialize data + bool ok = false; + int error = 0; + _data.mCompleted = true; // mark the data as final to be identified by the view. + _data.mAccepted = false; + _data.mReason = Device::DeviceError::eDevice_OK; + + // set as default if the val is invalid (min=0). + _data.mBrightness = HW2UI.last(); + + // get the value + quint8 val = vByteArray.toUShort(&ok); + + // check if the vExitCode passed and it has a value other than zero + if ( ! ok ){ _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp_Type ; goto lError; } // there is not a valid value + if ( ! HW2UI.contains(val) ){ _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp_Range ; goto lError; } // there is not a valid value + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_Brightness_Error ; goto lApply; } // there still a valid value + // Now everything is good to extract the data _data.mAccepted = true; - _data.mMessage = QObject::tr("The USB (un)mount Command Complete."); goto lOut ; // normal return + _data.mMessage = QObject::tr("The Brightness set is complete."); goto lApply; // normal return + + + // apply returned value in case the passed value is valid (type, range) + // regardless of the exit code (success, fail) +lApply: + _data.mBrightness = HW2UI[val]; + goto lOut; + + // immediate exit on fail exitcode and invalid returned value. lError: + if ( vExitCode ) error = *vExitCode; _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; + lOut: return _data.mAccepted; } + +QByteArray MDeviceBrightnessRequest::toByteArray(Device::DeviceError::Scripts_Error_Enum *vError) +{ + // initialize data + Device::DeviceError::Scripts_Error_Enum error = Device::DeviceError::Scripts_Error_Enum::eDevice_OK; + + /// return QString::number(UI2HW[_data.mBrightness]).toLatin1(); + // set as default if the val is invalid (min=0). + + // get the value + quint8 val = UI2HW.last(); + + // check if the vExitCode passed and it has a value other than zero + if ( ! UI2HW.contains(_data.mBrightness) ){ error = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Req_Range ; goto lError; } // there is not a valid value + + // if no error assign the passed value to val. + val = UI2HW[_data.mBrightness]; + return QString::number(val).toLatin1(); + + // set the error to ok (success), or any error(fail). +lError: + if ( vError && error ) *vError = error; + return ""; +}