Index: sources/device/DeviceModels.cpp =================================================================== diff -u -ra5760947d3ed0d2748ba023a1c25e3c6aa0b1de1 -rfb5fdd155c1c6ea42fe1d308f2eed71094f10e5b --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision a5760947d3ed0d2748ba023a1c25e3c6aa0b1de1) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision fb5fdd155c1c6ea42fe1d308f2eed71094f10e5b) @@ -6,8 +6,8 @@ * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file DeviceModels.cpp - * \author (last) Behrouz NematiPour - * \date (last) 18-Jul-2023 + * \author (last) Nico Ramirez + * \date (last) 23-June-2025 * \author (original) Behrouz NematiPour * \date (original) 03-Jun-2021 * @@ -258,6 +258,90 @@ } /*! + * \brief MDeviceWifiInfoResponse::fromByteArray + * \details Checks the response and sets up the model data. + * \param vExitCode - Passed script exit code + * \return true if passed. + */ +bool MDeviceWifiInfoResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) +{ + // initialize data + bool ok = false; + int error = 0; + _data.mCompleted = true; + _data.mAccepted = false; + _data.mReason = Device::DeviceError::eDevice_OK; + + // set as default if the val is invalid. + _data.mWifiInfo = ""; + + // 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_WifiInfo_Error ; goto lApply; } // there still a valid value + + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mMessage = QObject::tr("The WiFi info 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.mWifiInfo= 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; +} + +/*! + * \brief MDeviceConnectWifiResponse::fromByteArray + * \details Checks the response and sets up the model data. + * \param vExitCode - Passed script exit code + * \return true if passed. + */ +bool MDeviceConnectWifiResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) +{ + // initialize data + bool ok = false; + int error = 0; + _data.mCompleted = true; + _data.mAccepted = false; + _data.mReason = Device::DeviceError::eDevice_OK; + + ok = true; + + // 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_ConnectWifi_Error ; goto lApply; } // there still a valid value + + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mMessage = QObject::tr("The WiFi (Dis)Connection 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) +lApply: + 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; +} + +/*! * \brief MDeviceUSBMountResponse::fromByteArray * \details Checks the response and sets up the model data. * \param vExitCode - Passed script exit code