Skip to content

Commit

Permalink
Make various src/app code compile with -Wconversion
Browse files Browse the repository at this point in the history
We don't actually enable -Wconversion for this code yet, because it's
compiled directly into example apps, so we would need to enable
-Wconversion for those, and they aren't quite there.
  • Loading branch information
bzbarsky-apple committed Nov 5, 2020
1 parent 99aaed7 commit e2d95d4
Show file tree
Hide file tree
Showing 27 changed files with 202 additions and 171 deletions.
2 changes: 1 addition & 1 deletion examples/wifi-echo/server/esp32/main/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -14601,7 +14601,7 @@ void emberAfIasZoneClusterServerManufacturerSpecificAttributeChangedCallback(uin
* @param message The message that was sent Ver.: always
* @param status The status of the sent message Ver.: always
*/
void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination,
void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination,
EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message,
EmberStatus status);
/** @brief IAS Zone Cluster Server Pre Attribute Changed
Expand Down
21 changes: 11 additions & 10 deletions src/app/clusters/barrier-control-server/barrier-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void emAfPluginBarrierControlServerIncrementEvents(uint8_t endpoint, bool open,
{
if (READBIT(mask, bit))
{
EmberAfAttributeId attributeId = baseEventAttributeId + bit;
EmberAfAttributeId attributeId = static_cast<EmberAfAttributeId>(baseEventAttributeId + bit);
uint16_t events;
EmberAfStatus status = emberAfReadServerAttribute(endpoint, ZCL_BARRIER_CONTROL_CLUSTER_ID, attributeId,
(uint8_t *) &events, sizeof(events));
Expand Down Expand Up @@ -203,15 +203,15 @@ static uint8_t getCurrentPosition(uint8_t endpoint)
// open so that we don't leave the barrier open when it should be closed.
uint8_t currentPositionFromAttribute = emAfPluginBarrierControlServerGetBarrierPosition(endpoint);
return ((currentPositionFromAttribute == EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN)
? EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN
? static_cast<uint8_t>(EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_OPEN)
: currentPositionFromAttribute);
}

static uint32_t calculateDelayMs(uint8_t endpoint, uint8_t targetPosition, bool * opening)
{
uint8_t currentPosition = emAfPluginBarrierControlServerGetBarrierPosition(endpoint);
*opening = targetPosition > currentPosition;
uint8_t positionDelta = (*opening ? targetPosition - currentPosition : currentPosition - targetPosition);
uint8_t currentPosition = emAfPluginBarrierControlServerGetBarrierPosition(endpoint);
*opening = targetPosition > currentPosition;
uint8_t positionDelta = static_cast<uint8_t>(*opening ? targetPosition - currentPosition : currentPosition - targetPosition);
uint16_t openOrClosePeriodDs = getOpenOrClosePeriod(endpoint, *opening);
uint32_t openOrClosePeriodMs = openOrClosePeriodDs * MILLISECOND_TICKS_PER_DECISECOND;

Expand All @@ -228,7 +228,7 @@ static uint32_t calculateDelayMs(uint8_t endpoint, uint8_t targetPosition, bool
}
}

void emberAfBarrierControlClusterServerTickCallback(uint8_t endpoint)
void emberAfBarrierControlClusterServerTickCallback(CHIPEndpointId endpoint)
{
if (state.currentPosition == state.targetPosition)
{
Expand All @@ -254,10 +254,11 @@ void emberAfBarrierControlClusterServerTickCallback(uint8_t endpoint)
emAfPluginBarrierControlServerIncrementEvents(endpoint, false, false);
}
}
emAfPluginBarrierControlServerSetBarrierPosition(endpoint,
(emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint)
? state.currentPosition
: EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN));
emAfPluginBarrierControlServerSetBarrierPosition(
endpoint,
(emAfPluginBarrierControlServerIsPartialBarrierSupported(endpoint)
? state.currentPosition
: static_cast<uint8_t>(EMBER_ZCL_BARRIER_CONTROL_BARRIER_POSITION_UNKNOWN)));
setMovingState(
endpoint,
(state.increasing ? EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_OPENING : EMBER_ZCL_BARRIER_CONTROL_MOVING_STATE_CLOSING));
Expand Down
22 changes: 11 additions & 11 deletions src/app/clusters/color-control-server/color-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ static uint8_t addSaturation(uint8_t saturation1, uint8_t saturation2)
uint16_t saturation16;

saturation16 = ((uint16_t) saturation1);
saturation16 += ((uint16_t) saturation2);
saturation16 = static_cast<uint16_t>(saturation16 + static_cast<uint16_t>(saturation2));

if (saturation16 > MAX_SATURATION_VALUE)
{
Expand All @@ -794,7 +794,7 @@ static uint8_t subtractSaturation(uint8_t saturation1, uint8_t saturation2)
return 0;
}

return saturation1 - saturation2;
return static_cast<uint8_t>(saturation1 - saturation2);
}

// any time we call a hue or saturation transition, we need to assume certain
Expand Down Expand Up @@ -1256,11 +1256,11 @@ bool emberAfColorControlClusterStepColorTemperatureCallback(uint8_t stepMode, ui
colorTempTransitionState.currentValue = readColorTemperature(endpoint);
if (stepMode == MOVE_MODE_UP)
{
colorTempTransitionState.finalValue = readColorTemperature(endpoint) + stepSize;
colorTempTransitionState.finalValue = static_cast<uint16_t>(readColorTemperature(endpoint) + stepSize);
}
else
{
colorTempTransitionState.finalValue = readColorTemperature(endpoint) - stepSize;
colorTempTransitionState.finalValue = static_cast<uint16_t>(readColorTemperature(endpoint) - stepSize);
}
colorTempTransitionState.stepsRemaining = transitionTime;
colorTempTransitionState.stepsTotal = transitionTime;
Expand Down Expand Up @@ -1395,7 +1395,7 @@ static void handleModeSwitch(uint8_t endpoint, uint8_t newColorMode)
writeColorMode(endpoint, newColorMode);
}

colorModeTransition = (newColorMode << 4) + oldColorMode;
colorModeTransition = static_cast<uint8_t>((newColorMode << 4) + oldColorMode);

// Note: It may be OK to not do anything here.
switch (colorModeTransition)
Expand Down Expand Up @@ -1433,11 +1433,11 @@ static uint8_t addHue(uint8_t hue1, uint8_t hue2)
uint16_t hue16;

hue16 = ((uint16_t) hue1);
hue16 += ((uint16_t) hue2);
hue16 = static_cast<uint16_t>(hue16 + static_cast<uint16_t>(hue2));

if (hue16 > MAX_HUE_VALUE)
{
hue16 -= MAX_HUE_VALUE;
hue16 = static_cast<uint16_t>(hue16 - MAX_HUE_VALUE);
}

return ((uint8_t) hue16);
Expand All @@ -1450,10 +1450,10 @@ static uint8_t subtractHue(uint8_t hue1, uint8_t hue2)
hue16 = ((uint16_t) hue1);
if (hue2 > hue1)
{
hue16 += MAX_HUE_VALUE;
hue16 = static_cast<uint16_t>(hue16 + MAX_HUE_VALUE);
}

hue16 -= ((uint16_t) hue2);
hue16 = static_cast<uint16_t>(hue16 - static_cast<uint16_t>(hue2));

return ((uint8_t) hue16);
}
Expand Down Expand Up @@ -1580,14 +1580,14 @@ static bool computeNewColor16uValue(Color16uTransitionState * p)
newValue32u = ((uint32_t)(p->finalValue - p->initialValue));
newValue32u *= ((uint32_t)(p->stepsRemaining));
newValue32u /= ((uint32_t)(p->stepsTotal));
p->currentValue = p->finalValue - ((uint16_t)(newValue32u));
p->currentValue = static_cast<uint16_t>(p->finalValue - static_cast<uint16_t>(newValue32u));
}
else
{
newValue32u = ((uint32_t)(p->initialValue - p->finalValue));
newValue32u *= ((uint32_t)(p->stepsRemaining));
newValue32u /= ((uint32_t)(p->stepsTotal));
p->currentValue = p->finalValue + ((uint16_t)(newValue32u));
p->currentValue = static_cast<uint16_t>(p->finalValue + static_cast<uint16_t>(newValue32u));
}

if (p->stepsRemaining == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool emberAfPluginDoorLockServerGetLogEntry(uint16_t * entryId, EmberAfPluginDoo

if (!ENTRY_ID_IS_VALID(*entryId))
{
*entryId = MOST_RECENT_ENTRY_ID();
*entryId = static_cast<uint16_t>(MOST_RECENT_ENTRY_ID());
}
assert(ENTRY_ID_IS_VALID(*entryId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static EmberAfPluginDoorLockServerUser rfidUserTable[EMBER_AF_PLUGIN_DOOR_LOCK_S
// This is the current number of invalid PIN/RFID's in a row.
static uint8_t wrongCodeEntryCount = 0;

bool emAfPluginDoorLockServerCheckForSufficientSpace(uint8_t spaceReq, uint8_t spaceAvail)
bool emAfPluginDoorLockServerCheckForSufficientSpace(uint16_t spaceReq, uint8_t spaceAvail)
{
if (spaceReq > spaceAvail)
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ typedef struct
// space available (spaceAvail) and if so it will send a DefaultResponse
// command with the status of EMBER_ZCL_STATUS_INSUFFICIENT_SPACE and return
// false. Otherwise, it will return true.
bool emAfPluginDoorLockServerCheckForSufficientSpace(uint8_t spaceReq, uint8_t spaceAvail);
bool emAfPluginDoorLockServerCheckForSufficientSpace(uint16_t spaceReq, uint8_t spaceAvail);
#endif

// Critical Message Queue
Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/groups-server/groups-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool emberAfGroupsClusterGetGroupMembershipCallback(uint8_t groupCount, uint8_t
{
list[listLen] = LOW_BYTE(entry.groupId);
list[listLen + 1] = HIGH_BYTE(entry.groupId);
listLen += 2;
listLen = static_cast<uint8_t>(listLen + 2);
count++;
}
}
Expand All @@ -245,7 +245,7 @@ bool emberAfGroupsClusterGetGroupMembershipCallback(uint8_t groupCount, uint8_t
{
list[listLen] = LOW_BYTE(groupId);
list[listLen + 1] = HIGH_BYTE(groupId);
listLen += 2;
listLen = static_cast<uint8_t>(listLen + 2);
count++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ias-zone-server/ias-zone-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ void emberAfPluginIasZoneServerPrintQueueConfig(void)
// destination when the destination is the only router the node is joined to.
// In that case, the command will never have been sent, as the device will have
// had no router by which to send the command.
void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint16_t indexOrDestination,
void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, uint64_t indexOrDestination,
EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message,
EmberStatus status)
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/identify/identify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void emberAfIdentifyClusterServerTickCallback(uint8_t endpoint)
// This tick writes the new attribute, which will trigger the Attribute
// Changed callback below, which in turn will schedule or cancel the tick.
// Because of this, the tick does not have to be scheduled here.
writeIdentifyTime(endpoint, (identifyTime == 0 ? 0 : identifyTime - 1));
writeIdentifyTime(endpoint, static_cast<uint16_t>(identifyTime == 0 ? 0 : identifyTime - 1));
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ extern "C" void emberAfLevelControlClusterServerTickCallback(uint8_t endpoint)
}
else
{
writeRemainingTime(endpoint, state->transitionTimeMs - state->elapsedTimeMs);
writeRemainingTime(endpoint, static_cast<uint16_t>(state->transitionTimeMs - state->elapsedTimeMs));
schedule(endpoint, state->eventDurationMs);
}
}
Expand Down Expand Up @@ -514,12 +514,12 @@ static void moveToLevelHandler(uint8_t commandId, uint8_t level, uint16_t transi
goto send_default_response;
}
state->increasing = true;
actualStepSize = state->moveToLevel - currentLevel;
actualStepSize = static_cast<uint8_t>(state->moveToLevel - currentLevel);
}
else
{
state->increasing = false;
actualStepSize = currentLevel - state->moveToLevel;
actualStepSize = static_cast<uint8_t>(currentLevel - state->moveToLevel);
}

// If the Transition time field takes the value 0xFFFF, then the time taken
Expand Down Expand Up @@ -623,7 +623,7 @@ static void moveHandler(uint8_t commandId, uint8_t moveMode, uint8_t rate, uint8
case EMBER_ZCL_MOVE_MODE_UP:
state->increasing = true;
state->moveToLevel = MAX_LEVEL;
difference = MAX_LEVEL - currentLevel;
difference = static_cast<uint8_t>(MAX_LEVEL - currentLevel);
break;
case EMBER_ZCL_MOVE_MODE_DOWN:
state->increasing = false;
Expand Down Expand Up @@ -737,11 +737,11 @@ static void stepHandler(uint8_t commandId, uint8_t stepMode, uint8_t stepSize, u
if (MAX_LEVEL - currentLevel < stepSize)
{
state->moveToLevel = MAX_LEVEL;
actualStepSize = (MAX_LEVEL - currentLevel);
actualStepSize = static_cast<uint8_t>(MAX_LEVEL - currentLevel);
}
else
{
state->moveToLevel = currentLevel + stepSize;
state->moveToLevel = static_cast<uint8_t>(currentLevel + stepSize);
}
break;
case EMBER_ZCL_STEP_MODE_DOWN:
Expand All @@ -753,7 +753,7 @@ static void stepHandler(uint8_t commandId, uint8_t stepMode, uint8_t stepSize, u
}
else
{
state->moveToLevel = currentLevel - stepSize;
state->moveToLevel = static_cast<uint8_t>(currentLevel - stepSize);
}
break;
default:
Expand Down
15 changes: 8 additions & 7 deletions src/app/clusters/scenes-client/scenes-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand
// the payload if the status is SUCCESS.
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
uint16_t extensionFieldSetsLen = (emberAfCurrentCommand()->bufLen -
(emberAfCurrentCommand()->payloadStartIndex + sizeof(status) + sizeof(groupId) +
sizeof(sceneId) + sizeof(transitionTime) + emberAfStringLength(sceneName) + 1));
uint16_t extensionFieldSetsLen =
static_cast<uint16_t>(emberAfCurrentCommand()->bufLen -
(emberAfCurrentCommand()->payloadStartIndex + sizeof(status) + sizeof(groupId) + sizeof(sceneId) +
sizeof(transitionTime) + emberAfStringLength(sceneName) + 1));
uint16_t extensionFieldSetsIndex = 0;

emberAfScenesClusterPrint(", 0x%2x, \"", transitionTime);
Expand All @@ -134,9 +135,9 @@ bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand
{
EmberAfClusterId clusterId;
uint8_t length;
clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
extensionFieldSetsIndex += 2;
length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
clusterId = emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
extensionFieldSetsIndex = static_cast<uint16_t>(extensionFieldSetsIndex + 2);
length = emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
extensionFieldSetsIndex++;
emberAfScenesClusterPrint(" [0x%2x 0x%x ", clusterId, length);
if (extensionFieldSetsIndex + length <= extensionFieldSetsLen)
Expand All @@ -145,7 +146,7 @@ bool emberAfPluginScenesClientParseViewSceneResponse(const EmberAfClusterCommand
}
emberAfScenesClusterPrint("]");
emberAfScenesClusterFlush();
extensionFieldSetsIndex += length;
extensionFieldSetsIndex = static_cast<uint16_t>(extensionFieldSetsIndex + length);
}
}

Expand Down
Loading

0 comments on commit e2d95d4

Please sign in to comment.