Skip to content

Commit

Permalink
Useless pointer checks removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAndi committed Nov 26, 2023
1 parent 144b270 commit 0847882
Showing 1 changed file with 23 additions and 50 deletions.
73 changes: 23 additions & 50 deletions src/Hal/SensorDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,12 @@ bool SensorDataProvider::load()
JsonFile jsonFile(FILESYSTEM);
const size_t JSON_DOC_SIZE = 512U;
DynamicJsonDocument jsonDoc(JSON_DOC_SIZE);
uint8_t sensorIdx = 0U;
const uint8_t SENSOR_CNT = m_impl->getNumSensors();

if (true == jsonFile.load(SENSOR_CALIB_FILE_NAME, jsonDoc))
{
uint8_t sensorIdx = 0U;
const uint8_t SENSOR_CNT = m_impl->getNumSensors();

while(SENSOR_CNT > sensorIdx)
{
ISensor* sensor = m_impl->getSensor(sensorIdx);
Expand Down Expand Up @@ -416,45 +417,23 @@ void SensorDataProvider::channelOffsetToJson(JsonArray& jsonOffset, const ISenso
{
const SensorChannelUInt32* uint32Channel = reinterpret_cast<const SensorChannelUInt32*>(&channel);

if (nullptr == uint32Channel)
{
jsonOffset.add("NaN");
}
else
{
jsonOffset.add(uint32Channel->getOffset());
}
jsonOffset.add(uint32Channel->getOffset());
}
break;

case ISensorChannel::DataType::DATA_TYPE_INT32:
{
const SensorChannelInt32* int32Channel = reinterpret_cast<const SensorChannelInt32*>(&channel);

if (nullptr == int32Channel)
{
jsonOffset.add("NaN");
}
else
{
jsonOffset.add(int32Channel->getOffset());
}

jsonOffset.add(int32Channel->getOffset());
}
break;

case ISensorChannel::DataType::DATA_TYPE_FLOAT32:
{
const SensorChannelFloat32* float32Channel = reinterpret_cast<const SensorChannelFloat32*>(&channel);

if (nullptr == float32Channel)
{
jsonOffset.add("NaN");
}
else
{
jsonOffset.add(float32Channel->getOffset());
}
jsonOffset.add(float32Channel->getOffset());
}
break;

Expand All @@ -479,8 +458,7 @@ void SensorDataProvider::channelOffsetFromJson(ISensorChannel& channel, JsonVari
{
SensorChannelUInt32* uint32Channel = reinterpret_cast<SensorChannelUInt32*>(&channel);

if ((nullptr != uint32Channel) &&
(true == jsonOffset.is<uint32_t>()))
if (true == jsonOffset.is<uint32_t>())
{
uint32Channel->setOffset(jsonOffset.as<uint32_t>());
}
Expand All @@ -491,8 +469,7 @@ void SensorDataProvider::channelOffsetFromJson(ISensorChannel& channel, JsonVari
{
SensorChannelInt32* int32Channel = reinterpret_cast<SensorChannelInt32*>(&channel);

if ((nullptr != int32Channel) &&
(true == jsonOffset.is<int32_t>()))
if (true == jsonOffset.is<int32_t>())
{
int32Channel->setOffset(jsonOffset.as<int32_t>());
}
Expand All @@ -503,8 +480,7 @@ void SensorDataProvider::channelOffsetFromJson(ISensorChannel& channel, JsonVari
{
SensorChannelFloat32* float32Channel = reinterpret_cast<SensorChannelFloat32*>(&channel);

if ((nullptr != float32Channel) &&
(true == jsonOffset.is<float>()))
if (true == jsonOffset.is<float>())
{
float32Channel->setOffset(jsonOffset.as<float>());
}
Expand All @@ -516,6 +492,7 @@ void SensorDataProvider::channelOffsetFromJson(ISensorChannel& channel, JsonVari
break;

default:
/* Not supported. */
break;
}
}
Expand All @@ -532,32 +509,28 @@ void SensorDataProvider::createCalibrationFile()

for(index = 0U; index < defaultValues; ++index)
{
const SensorChannelDefaultValue* value = &sensorChannelDefaultValueList[index];
const SensorChannelDefaultValue* value = &sensorChannelDefaultValueList[index];
ISensor* sensor = getSensor(value->sensorId);

if (nullptr != value)
if (nullptr == sensor)
{
LOG_ERROR("Sensor %u doesn't exists.", value->sensorId);
}
else
{
ISensor* sensor = getSensor(value->sensorId);
ISensorChannel* channel = sensor->getChannel(value->channelId);

if (nullptr == sensor)
if (nullptr == channel)
{
LOG_ERROR("Sensor %u doesn't exists.", value->sensorId);
LOG_ERROR("Sensor %u has no channel %u.", value->sensorId, value->channelId);
}
else
{
ISensorChannel* channel = sensor->getChannel(value->channelId);
DynamicJsonDocument jsonDoc(256U);

if (nullptr == channel)
{
LOG_ERROR("Sensor %u has no channel %u.", value->sensorId, value->channelId);
}
else
if (DeserializationError::Ok == deserializeJson(jsonDoc, value->jsonStrValue))
{
DynamicJsonDocument jsonDoc(256U);

if (DeserializationError::Ok == deserializeJson(jsonDoc, value->jsonStrValue))
{
channelOffsetFromJson(*channel, jsonDoc["offset"]);
}
channelOffsetFromJson(*channel, jsonDoc["offset"]);
}
}
}
Expand Down

0 comments on commit 0847882

Please sign in to comment.